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

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

View file

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