fix orbot detection

This commit is contained in:
Daniel Gultsch 2022-07-09 14:45:59 +02:00
parent 2364d7c46d
commit e455ed4f1a
2 changed files with 24 additions and 16 deletions

View file

@ -51,6 +51,8 @@
<queries>
<package android:name="org.sufficientlysecure.keychain" />
<package android:name="org.torproject.android" />
<intent>
<action android:name="eu.siacs.conversations.location.request" />
</intent>
@ -62,15 +64,15 @@
<application
android:allowBackup="true"
android:fullBackupContent="@xml/backup_content"
android:appCategory="social"
android:fullBackupContent="@xml/backup_content"
android:hardwareAccelerated="true"
android:icon="@mipmap/new_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:networkSecurityConfig="@xml/network_security_configuration"
android:requestLegacyExternalStorage="true"
android:preserveLegacyExternalStorage="true"
android:requestLegacyExternalStorage="true"
android:theme="@style/ConversationsTheme"
tools:replace="android:label"
tools:targetApi="q">

View file

@ -6,41 +6,47 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.widget.Toast;
import eu.siacs.conversations.R;
import me.drakeet.support.toast.ToastCompat;
public class TorServiceUtils {
private final static String URI_ORBOT = "org.torproject.android";
private static final String URI_ORBOT = "org.torproject.android";
private static final Uri ORBOT_PLAYSTORE_URI = Uri.parse("market://details?id=" + URI_ORBOT);
private final static String ACTION_START_TOR = "org.torproject.android.START_TOR";
private static final String ACTION_START_TOR = "org.torproject.android.START_TOR";
public static final Intent INSTALL_INTENT = new Intent(Intent.ACTION_VIEW, ORBOT_PLAYSTORE_URI);
public static final Intent LAUNCH_INTENT = new Intent(ACTION_START_TOR);
public final static String ACTION_STATUS = "org.torproject.android.intent.action.STATUS";
public final static String EXTRA_STATUS = "org.torproject.android.intent.extra.STATUS";
public static final String ACTION_STATUS = "org.torproject.android.intent.action.STATUS";
public static final String EXTRA_STATUS = "org.torproject.android.intent.extra.STATUS";
public static boolean isOrbotInstalled(Context context) {
public static boolean isOrbotInstalled(final Context context) {
try {
context.getPackageManager().getPackageInfo(URI_ORBOT, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
} catch (final PackageManager.NameNotFoundException e) {
return false;
}
}
public static void downloadOrbot(Activity activity, int requestCode) {
try {
activity.startActivityForResult(INSTALL_INTENT, requestCode);
} catch (ActivityNotFoundException e) {
ToastCompat.makeText(activity, R.string.no_market_app_installed, ToastCompat.LENGTH_SHORT).show();
} catch (final ActivityNotFoundException e) {
ToastCompat.makeText(
activity, R.string.no_market_app_installed, ToastCompat.LENGTH_SHORT)
.show();
}
}
public static void startOrbot(Activity activity, int requestCode) {
public static void startOrbot(final Activity activity, final int requestCode) {
try {
activity.startActivityForResult(LAUNCH_INTENT, requestCode);
} catch (final ActivityNotFoundException e) {
Toast.makeText(activity, R.string.install_orbot, Toast.LENGTH_LONG).show();
}
}
}