Allow tor / i2p in sticker pack download

This commit is contained in:
Arne 2023-05-23 13:13:12 +02:00
parent e7514bf363
commit 73a3aa289f
5 changed files with 13 additions and 6 deletions

View file

@ -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)), intent.getBooleanExtra("i2p", getResources().getBoolean(R.bool.use_i2p))).build();
}
synchronized(pendingPacks) {
pendingPacks.add(intent.getData() == null ? Uri.parse("https://stickers.cheogram.com/index.json") : intent.getData());
}

View file

@ -131,13 +131,9 @@ public class HttpConnectionManager extends AbstractConnectionManager {
final String slotHostname = url.host();
final boolean onionSlot = slotHostname.endsWith(".onion");
final boolean I2PSlot = slotHostname.endsWith(".i2p");
final OkHttpClient.Builder builder = OK_HTTP_CLIENT.newBuilder();
builder.writeTimeout(30, TimeUnit.SECONDS);
final OkHttpClient.Builder builder = newBuilder(mXmppConnectionService.useTorToConnect() || account.isOnion() || onionSlot , mXmppConnectionService.useI2PToConnect() || account.isI2P() || I2PSlot);
builder.readTimeout(readTimeout, TimeUnit.SECONDS);
setupTrustManager(builder, interactive);
if (mXmppConnectionService.useTorToConnect() || account.isOnion() || onionSlot || mXmppConnectionService.useI2PToConnect() || account.isI2P() || I2PSlot) {
builder.proxy(HttpConnectionManager.getProxy(I2PSlot)).build();
}
return builder.build();
}

View file

@ -583,6 +583,8 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
private void downloadStickers() {
Intent intent = new Intent(this, DownloadDefaultStickers.class);
intent.putExtra("tor", xmppConnectionService.useTorToConnect());
intent.putExtra("i2p", xmppConnectionService.useI2PToConnect());
ContextCompat.startForegroundService(this, intent);
displayToast("Sticker download started");
showDialogsIfMainIsOverview();

View file

@ -803,6 +803,8 @@ public class SettingsActivity extends XmppActivity implements OnSharedPreference
private void downloadStickers() {
Intent intent = new Intent(this, DownloadDefaultStickers.class);
intent.putExtra("tor", xmppConnectionService.useTorToConnect());
intent.putExtra("i2p", xmppConnectionService.useI2PToConnect());
ContextCompat.startForegroundService(this, intent);
displayToast("Sticker download started");
}

View file

@ -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,8 @@ 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)));
intent.putExtra("i2p", PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("use_i2p", getResources().getBoolean(R.bool.use_i2p)));
ContextCompat.startForegroundService(this, intent);
Toast.makeText(this, "Sticker download started", Toast.LENGTH_SHORT).show();
finish();