~singpolyma/cheogram-android

8f4c146c5561e1e319747910bf864fb47a6a7a6e — Stephen Paul Weber 1 year, 3 months ago 17aa2ae
Allow tor in sticker pack download
M src/cheogram/java/com/cheogram/android/DownloadDefaultStickers.java => src/cheogram/java/com/cheogram/android/DownloadDefaultStickers.java +5 -1
@@ 42,6 42,7 @@ import eu.siacs.conversations.crypto.axolotl.SQLiteAxolotlStore;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.http.HttpConnectionManager;
import eu.siacs.conversations.persistance.DatabaseBackend;
import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.utils.Compatibility;


@@ 55,7 56,7 @@ public class DownloadDefaultStickers extends Service {
	private DatabaseBackend mDatabaseBackend;
	private NotificationManager notificationManager;
	private File mStickerDir;
	private OkHttpClient http = new OkHttpClient();
	private OkHttpClient http = null;
	private HashSet<Uri> pendingPacks = new HashSet<Uri>();

	@Override


@@ 67,6 68,9 @@ public class DownloadDefaultStickers extends Service {

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		if (http == null) {
			http = HttpConnectionManager.newBuilder(intent.getBooleanExtra("tor", getResources().getBoolean(R.bool.use_tor))).build();
		}
		synchronized(pendingPacks) {
			pendingPacks.add(intent.getData() == null ? Uri.parse("https://stickers.cheogram.com/index.json") : intent.getData());
		}

M src/main/java/eu/siacs/conversations/http/HttpConnectionManager.java => src/main/java/eu/siacs/conversations/http/HttpConnectionManager.java +1 -5
@@ 131,13 131,9 @@ public class HttpConnectionManager extends AbstractConnectionManager {
    OkHttpClient buildHttpClient(final HttpUrl url, final Account account, int readTimeout, boolean interactive) {
        final String slotHostname = url.host();
        final boolean onionSlot = slotHostname.endsWith(".onion");
        final OkHttpClient.Builder builder = OK_HTTP_CLIENT.newBuilder();
        builder.writeTimeout(30, TimeUnit.SECONDS);
        final OkHttpClient.Builder builder = newBuilder(mXmppConnectionService.useTorToConnect() || account.isOnion() || onionSlot);
        builder.readTimeout(readTimeout, TimeUnit.SECONDS);
        setupTrustManager(builder, interactive);
        if (mXmppConnectionService.useTorToConnect() || account.isOnion() || onionSlot) {
            builder.proxy(HttpConnectionManager.getProxy()).build();
        }
        return builder.build();
    }


M src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java => src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java +1 -0
@@ 385,6 385,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio

    private void downloadStickers() {
        Intent intent = new Intent(this, DownloadDefaultStickers.class);
        intent.putExtra("tor", xmppConnectionService.useTorToConnect());
        ContextCompat.startForegroundService(this, intent);
        displayToast("Sticker download started");
        showDialogsIfMainIsOverview();

M src/main/java/eu/siacs/conversations/ui/SettingsActivity.java => src/main/java/eu/siacs/conversations/ui/SettingsActivity.java +1 -0
@@ 639,6 639,7 @@ public class SettingsActivity extends XmppActivity implements OnSharedPreference

    private void downloadStickers() {
        Intent intent = new Intent(this, DownloadDefaultStickers.class);
        intent.putExtra("tor", xmppConnectionService.useTorToConnect());
        ContextCompat.startForegroundService(this, intent);
        displayToast("Sticker download started");
    }

M src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java => src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java +2 -0
@@ 7,6 7,7 @@ import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.Toast;


@@ 127,6 128,7 @@ public class UriHandlerActivity extends AppCompatActivity {
    private void downloadStickers() {
        Intent intent = new Intent(this, DownloadDefaultStickers.class);
        intent.setData(stickers);
        intent.putExtra("tor", PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("use_tor", getResources().getBoolean(R.bool.use_tor)));
        ContextCompat.startForegroundService(this, intent);
        Toast.makeText(this, "Sticker download started", Toast.LENGTH_SHORT).show();
        finish();