commit 8113e126c343292bc2fbfc612aab22f08d8c2648 Author: n8fr8 nathan@freitas.net Date: Fri Jan 5 13:42:46 2018 -0500
re-enable Orfox install code --- .../org/torproject/android/OrbotMainActivity.java | 5 ++- .../android/ui/onboarding/OnboardingActivity.java | 50 ++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java index c9882b76..cbc7349e 100644 --- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java +++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java @@ -12,6 +12,7 @@ import java.net.URLDecoder; import java.net.URLEncoder; import java.text.NumberFormat; import java.util.ArrayList; +import java.util.List; import java.util.Locale; import java.util.StringTokenizer;
@@ -50,6 +51,7 @@ import android.content.SharedPreferences.Editor; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; +import android.content.pm.ResolveInfo; import android.database.Cursor; import android.net.Uri; import android.os.Build; @@ -830,7 +832,7 @@ public class OrbotMainActivity extends AppCompatActivity @Override public void onClick(DialogInterface dialog, int which) {
- // startActivity(PromoAppsActivity.getInstallIntent(TorServiceConstants.BROWSER_APP_USERNAME,OrbotMainActivity.this)); + startActivity(OnboardingActivity.getInstallIntent(TorServiceConstants.BROWSER_APP_USERNAME,OrbotMainActivity.this));
} @@ -848,6 +850,7 @@ public class OrbotMainActivity extends AppCompatActivity .show(); }
+ private void startIntent (String pkg, String action, Uri data) { Intent i; diff --git a/app/src/main/java/org/torproject/android/ui/onboarding/OnboardingActivity.java b/app/src/main/java/org/torproject/android/ui/onboarding/OnboardingActivity.java index ca1cc494..dbe329a4 100644 --- a/app/src/main/java/org/torproject/android/ui/onboarding/OnboardingActivity.java +++ b/app/src/main/java/org/torproject/android/ui/onboarding/OnboardingActivity.java @@ -2,9 +2,14 @@ package org.torproject.android.ui.onboarding;
import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.net.Uri; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; +import android.text.TextUtils; +import android.util.Log; import android.view.View;
import com.github.paolorotolo.appintro.AppIntro; @@ -14,6 +19,8 @@ import org.torproject.android.settings.LocaleHelper; import org.torproject.android.ui.AppManagerActivity; import org.torproject.android.vpn.VPNEnableActivity;
+import java.util.List; + public class OnboardingActivity extends AppIntro {
@Override @@ -92,4 +99,47 @@ public class OnboardingActivity extends AppIntro { protected void attachBaseContext(Context base) { super.attachBaseContext(LocaleHelper.onAttach(base)); } + + public static boolean isAppInstalled(PackageManager pm, String packageName) { + try { + pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); + return true; + } catch (PackageManager.NameNotFoundException e) { + return false; + } + } + + public static Intent getInstallIntent(String packageName, Context context) { + final Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse(MARKET_URI + packageName)); + + PackageManager pm = context.getPackageManager(); + List<ResolveInfo> resInfos = pm.queryIntentActivities(intent, 0); + + String foundPackageName = null; + for (ResolveInfo r : resInfos) { + Log.i("Install", "market: " + r.activityInfo.packageName); + if (TextUtils.equals(r.activityInfo.packageName, FDROID_PACKAGE_NAME) + || TextUtils.equals(r.activityInfo.packageName, PLAY_PACKAGE_NAME)) { + foundPackageName = r.activityInfo.packageName; + break; + } + } + + if (foundPackageName == null) { + intent.setData(Uri.parse(FDROID_APP_URI + packageName)); + } else { + intent.setPackage(foundPackageName); + } + return intent; + } + + final static String MARKET_URI = "market://details?id="; + final static String FDROID_APP_URI = "https://f-droid.org/repository/browse/?fdid="; + final static String PLAY_APP_URI = "https://play.google.com/store/apps/details?id="; + final static String FDROID_URI = "https://f-droid.org/repository/browse/?fdfilter=info.guardianproject"; + final static String PLAY_URI = "https://play.google.com/store/apps/developer?id=The+Guardian+Project"; + + private final static String FDROID_PACKAGE_NAME = "org.fdroid.fdroid"; + private final static String PLAY_PACKAGE_NAME = "com.android.vending"; } \ No newline at end of file
tor-commits@lists.torproject.org