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 static boolean isOrbotInstalled(Context context) {
20 try {
21 context.getPackageManager().getPackageInfo(URI_ORBOT, PackageManager.GET_ACTIVITIES);
22 return true;
23 } catch (PackageManager.NameNotFoundException e) {
24 return false;
25 }
26 }
27
28
29 public static void downloadOrbot(Activity activity, int requestCode) {
30 final Intent intent = new Intent(Intent.ACTION_VIEW, ORBOT_PLAYSTORE_URI);
31 try {
32 activity.startActivityForResult(intent, requestCode);
33 } catch (ActivityNotFoundException e) {
34 ToastCompat.makeText(activity, R.string.no_market_app_installed, ToastCompat.LENGTH_SHORT).show();
35 }
36 }
37
38 public static void startOrbot(Activity activity, int requestCode) {
39 final Intent launchIntent = new Intent(URI_ORBOT);
40 launchIntent.setAction(ACTION_START_TOR);
41 activity.startActivityForResult(launchIntent, requestCode);
42 }
43}