1package eu.siacs.conversations.utils;
2
3import android.app.Activity;
4import android.content.ActivityNotFoundException;
5import android.content.Context;
6import android.content.Intent;
7import android.content.pm.PackageManager;
8import android.net.Uri;
9
10import eu.siacs.conversations.R;
11import me.drakeet.support.toast.ToastCompat;
12
13public class TorServiceUtils {
14
15 private final static String URI_ORBOT = "org.torproject.android";
16 private static final Uri ORBOT_PLAYSTORE_URI = Uri.parse("market://details?id=" + URI_ORBOT);
17 private final static String ACTION_START_TOR = "org.torproject.android.START_TOR";
18
19 public final static String ACTION_STATUS = "org.torproject.android.intent.action.STATUS";
20 public final static String EXTRA_STATUS = "org.torproject.android.intent.extra.STATUS";
21
22 public static boolean isOrbotInstalled(Context context) {
23 try {
24 context.getPackageManager().getPackageInfo(URI_ORBOT, PackageManager.GET_ACTIVITIES);
25 return true;
26 } catch (PackageManager.NameNotFoundException e) {
27 return false;
28 }
29 }
30
31
32 public static void downloadOrbot(Activity activity, int requestCode) {
33 final Intent intent = new Intent(Intent.ACTION_VIEW, ORBOT_PLAYSTORE_URI);
34 try {
35 activity.startActivityForResult(intent, requestCode);
36 } catch (ActivityNotFoundException e) {
37 ToastCompat.makeText(activity, R.string.no_market_app_installed, ToastCompat.LENGTH_SHORT).show();
38 }
39 }
40
41 public static void startOrbot(Activity activity, int requestCode) {
42 final Intent launchIntent = new Intent(URI_ORBOT);
43 launchIntent.setAction(ACTION_START_TOR);
44 activity.startActivityForResult(launchIntent, requestCode);
45 }
46}