2018-12-03 12:15:06 +00:00
|
|
|
package eu.siacs.conversations.utils;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.ActivityNotFoundException;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.net.Uri;
|
2022-07-09 12:45:59 +00:00
|
|
|
import android.widget.Toast;
|
2018-12-03 12:15:06 +00:00
|
|
|
|
|
|
|
import eu.siacs.conversations.R;
|
|
|
|
import me.drakeet.support.toast.ToastCompat;
|
|
|
|
|
|
|
|
public class TorServiceUtils {
|
|
|
|
|
2022-07-09 12:45:59 +00:00
|
|
|
private static final String URI_ORBOT = "org.torproject.android";
|
2018-12-03 12:15:06 +00:00
|
|
|
private static final Uri ORBOT_PLAYSTORE_URI = Uri.parse("market://details?id=" + URI_ORBOT);
|
2022-07-09 12:45:59 +00:00
|
|
|
private static final String ACTION_START_TOR = "org.torproject.android.START_TOR";
|
2018-12-03 12:15:06 +00:00
|
|
|
|
2020-08-19 13:29:25 +00:00
|
|
|
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);
|
|
|
|
|
2022-07-09 12:45:59 +00:00
|
|
|
public static final String ACTION_STATUS = "org.torproject.android.intent.action.STATUS";
|
|
|
|
public static final String EXTRA_STATUS = "org.torproject.android.intent.extra.STATUS";
|
2020-08-19 11:57:33 +00:00
|
|
|
|
2022-07-09 12:45:59 +00:00
|
|
|
public static boolean isOrbotInstalled(final Context context) {
|
2018-12-03 12:15:06 +00:00
|
|
|
try {
|
|
|
|
context.getPackageManager().getPackageInfo(URI_ORBOT, PackageManager.GET_ACTIVITIES);
|
|
|
|
return true;
|
2022-07-09 12:45:59 +00:00
|
|
|
} catch (final PackageManager.NameNotFoundException e) {
|
2018-12-03 12:15:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void downloadOrbot(Activity activity, int requestCode) {
|
|
|
|
try {
|
2020-08-19 13:29:25 +00:00
|
|
|
activity.startActivityForResult(INSTALL_INTENT, requestCode);
|
2022-07-09 12:45:59 +00:00
|
|
|
} catch (final ActivityNotFoundException e) {
|
|
|
|
ToastCompat.makeText(
|
|
|
|
activity, R.string.no_market_app_installed, ToastCompat.LENGTH_SHORT)
|
|
|
|
.show();
|
2018-12-03 12:15:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-09 12:45:59 +00:00
|
|
|
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();
|
|
|
|
}
|
2018-12-03 12:15:06 +00:00
|
|
|
}
|
|
|
|
}
|