~singpolyma/cheogram-android

e455ed4f1ae10ebb82d88d98102c7a6673c43a6f — Daniel Gultsch 2 years ago 2364d7c
fix orbot detection
M src/main/AndroidManifest.xml => src/main/AndroidManifest.xml +7 -5
@@ 50,27 50,29 @@
        android:required="false" />

    <queries>
        <package android:name="org.sufficientlysecure.keychain"/>
        <package android:name="org.sufficientlysecure.keychain" />
        <package android:name="org.torproject.android" />

        <intent>
            <action android:name="eu.siacs.conversations.location.request"/>
            <action android:name="eu.siacs.conversations.location.request" />
        </intent>
        <intent>
            <action android:name="eu.siacs.conversations.location.show"/>
            <action android:name="eu.siacs.conversations.location.show" />
        </intent>
    </queries>


    <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">

M src/main/java/eu/siacs/conversations/utils/TorServiceUtils.java => src/main/java/eu/siacs/conversations/utils/TorServiceUtils.java +17 -11
@@ 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) {
        activity.startActivityForResult(LAUNCH_INTENT, 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();
        }
    }
}