From dedf213028ac5cbb63513d4ce3c2d2b756896e05 Mon Sep 17 00:00:00 2001 From: Nathan Freitas Date: Sun, 6 Nov 2016 23:57:37 -0500 Subject: [PATCH] make sure browser intent exists before you open it for some reason, we see a lot of random crashes here do people really run devices without browsers on them? --- .../torproject/android/OrbotMainActivity.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java index a67b2b90..c43928e5 100644 --- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java +++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java @@ -665,7 +665,6 @@ public class OrbotMainActivity extends AppCompatActivity } }; - String requestMsg = getString(R.string.hidden_service_request, hiddenServicePortRequest); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(requestMsg).setPositiveButton("Allow", dialogClickListener) @@ -750,15 +749,11 @@ public class OrbotMainActivity extends AppCompatActivity else if (mBtnVPN.isChecked()||forceExternal) { //use the system browser since VPN is on - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl)); - intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(intent); + startIntent(null,Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl)); } else if (Prefs.useTransparentProxying()) { - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl)); - intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(intent); + startIntent(null,Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl)); } else { @@ -793,9 +788,7 @@ public class OrbotMainActivity extends AppCompatActivity @Override public void onClick(DialogInterface dialog, int which) { - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl)); - intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(intent); + startIntent(null,Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl)); } @@ -813,14 +806,25 @@ public class OrbotMainActivity extends AppCompatActivity private void startIntent (String pkg, String action, Uri data) { Intent i; - PackageManager manager = getPackageManager(); + PackageManager pm = getPackageManager(); + try { - i = manager.getLaunchIntentForPackage(pkg); - if (i == null) - throw new PackageManager.NameNotFoundException(); + if (pkg != null) { + i = pm.getLaunchIntentForPackage(pkg); + if (i == null) + throw new PackageManager.NameNotFoundException(); + } + else + { + i = new Intent(); + } + i.setAction(action); i.setData(data); - startActivity(i); + + if (i.resolveActivity(pm)!=null) + startActivity(i); + } catch (PackageManager.NameNotFoundException e) { }