]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Detect the Google Play flavor of I2P. https://redmine.stoutner.com/issues/895
authorSoren Stoutner <soren@stoutner.com>
Thu, 27 Oct 2022 18:16:38 +0000 (11:16 -0700)
committerSoren Stoutner <soren@stoutner.com>
Thu, 27 Oct 2022 18:16:38 +0000 (11:16 -0700)
app/src/main/AndroidManifest.xml
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java
app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt
app/src/main/res/values/strings.xml

index cc2645dd84fde815a6df5ec11100fc295428c20e..70b076d3d8ec35a8703d638fc9d50f0ca5b95c64 100644 (file)
@@ -36,7 +36,8 @@
     <!-- List the apps that Privacy Browser needs to query to see if they are installed. -->
     <queries>
         <!-- I2P. -->
     <!-- List the apps that Privacy Browser needs to query to see if they are installed. -->
     <queries>
         <!-- I2P. -->
-        <package android:name="net.i2p.android.router" />
+        <package android:name="net.i2p.android" />  <!-- Google Play flavor. -->
+        <package android:name="net.i2p.android.router" />  <!-- F-Droid flavor. -->
 
         <!-- Orbot. -->
         <package android:name="org.torproject.android" />
 
         <!-- Orbot. -->
         <package android:name="org.torproject.android" />
index a7cbffb53280f5ee365ef22be77fdd4b17e17cb5..08ab30c351efe3b04ae84c1d1ef1731097c57dda 100644 (file)
@@ -4335,27 +4335,31 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
                 } else {
                     appBarLayout.setBackgroundResource(R.color.dark_blue_30);
                 }
                 } else {
                     appBarLayout.setBackgroundResource(R.color.dark_blue_30);
                 }
+                // Get the package manager.
+                PackageManager packageManager = getPackageManager();
 
                 // Check to see if I2P is installed.
                 try {
 
                 // Check to see if I2P is installed.
                 try {
-                    // Get the package manager.
-                    PackageManager packageManager = getPackageManager();
-
-                    // Check to see if I2P is in the list.  This will throw an error and drop to the catch section if it isn't installed.
+                    // Check to see if the F-Droid flavor is installed.  This will throw an error and drop to the catch section if it isn't installed.
                     packageManager.getPackageInfo("net.i2p.android.router", 0);
                     packageManager.getPackageInfo("net.i2p.android.router", 0);
-                } catch (PackageManager.NameNotFoundException exception) {  // I2P is not installed.
-                    // Sow the I2P not installed dialog if it is not already displayed.
-                    if (getSupportFragmentManager().findFragmentByTag(getString(R.string.proxy_not_installed_dialog)) == null) {
-                        // Get a handle for the waiting for proxy alert dialog.
-                        DialogFragment i2pNotInstalledDialogFragment = ProxyNotInstalledDialog.displayDialog(proxyMode);
+                } catch (PackageManager.NameNotFoundException fdroidException) {  // The F-Droid flavor is not installed.
+                    try {
+                        // Check to see if the Google Play flavor is installed.  This will throw an error and drop to the catch section if it isn't installed.
+                        packageManager.getPackageInfo("net.i2p.android", 0);
+                    } catch (PackageManager.NameNotFoundException googlePlayException) {  // The Google Play flavor is not installed.
+                        // Sow the I2P not installed dialog if it is not already displayed.
+                        if (getSupportFragmentManager().findFragmentByTag(getString(R.string.proxy_not_installed_dialog)) == null) {
+                            // Get a handle for the waiting for proxy alert dialog.
+                            DialogFragment i2pNotInstalledDialogFragment = ProxyNotInstalledDialog.displayDialog(proxyMode);
 
 
-                        // Try to show the dialog.  Sometimes the window is not yet active if returning from Settings.
-                        try {
-                            // Display the I2P not installed alert dialog.
-                            i2pNotInstalledDialogFragment.show(getSupportFragmentManager(), getString(R.string.proxy_not_installed_dialog));
-                        } catch (Exception i2pNotInstalledException) {
-                            // Add the dialog to the pending dialog array list.  It will be displayed in `onStart()`.
-                            pendingDialogsArrayList.add(new PendingDialog(i2pNotInstalledDialogFragment, getString(R.string.proxy_not_installed_dialog)));
+                            // Try to show the dialog.  Sometimes the window is not yet active if returning from Settings.
+                            try {
+                                // Display the I2P not installed alert dialog.
+                                i2pNotInstalledDialogFragment.show(getSupportFragmentManager(), getString(R.string.proxy_not_installed_dialog));
+                            } catch (Exception i2pNotInstalledException) {
+                                // Add the dialog to the pending dialog array list.  It will be displayed in `onStart()`.
+                                pendingDialogsArrayList.add(new PendingDialog(i2pNotInstalledDialogFragment, getString(R.string.proxy_not_installed_dialog)));
+                            }
                         }
                     }
                 }
                         }
                     }
                 }
index 6d74af793ef4aa86bb51f5ab95d19231d3fac350..c4c522741f892e56f80ee0930bc4a7a8b9856d14 100644 (file)
@@ -330,12 +330,18 @@ class AboutVersionFragment : Fragment() {
 
         // Get the I2P version name if I2P is installed.
         val i2p: String = try {
 
         // Get the I2P version name if I2P is installed.
         val i2p: String = try {
-            // Store the version name.  The newer `getPackageInfo()` may be used once the minimum API >= 33.
+            // Check to see if the F-Droid flavor is installed.  The newer `getPackageInfo()` may be used once the minimum API >= 33.
             @Suppress("DEPRECATION")
             @Suppress("DEPRECATION")
-            requireContext().packageManager.getPackageInfo("net.i2p.android.router", 0).versionName
-        } catch (exception: PackageManager.NameNotFoundException) {  // I2P is not installed.
-            // Store an empty string.
-            ""
+            requireContext().packageManager.getPackageInfo("net.i2p.android.router", 0).versionName + " " + requireContext().getString(R.string.fdroid_flavor)
+        } catch (exception: PackageManager.NameNotFoundException) {  // The F-Droid flavor is not installed.
+            try {
+                // Check to see if the F-Droid flavor is installed.  The newer `getPackageInfo()` may be used once the minimum API >= 33.
+                @Suppress("DEPRECATION")
+                requireContext().packageManager.getPackageInfo("net.i2p.android", 0).versionName + " " + requireContext().getString(R.string.google_play_flavor)
+            } catch (exception: PackageManager.NameNotFoundException) {  // The Google Play flavor is not installed either.
+                // Store an empty string.
+                ""
+            }
         }
 
         // Get the OpenKeychain version name if it is installed.
         }
 
         // Get the OpenKeychain version name if it is installed.
index 6ff8f67567dbe9e1d5f1e012ba4ab611156f9328..9c9c0efe965c72c86199ae1cfa7985a3a78337e6 100644 (file)
             <string name="webview_version">WebView Version:</string>
             <string name="orbot">Orbot:</string>
             <string name="i2p">I2P:</string>
             <string name="webview_version">WebView Version:</string>
             <string name="orbot">Orbot:</string>
             <string name="i2p">I2P:</string>
+                <string name="fdroid_flavor">(F-Droid flavor)</string>
+                <string name="google_play_flavor">(Google Play flavor)</string>
             <string name="openkeychain">OpenKeychain:</string>
         <string name="memory_usage">Memory Usage</string>
             <string name="app_consumed_memory">App Consumed Memory:</string>
             <string name="openkeychain">OpenKeychain:</string>
         <string name="memory_usage">Memory Usage</string>
             <string name="app_consumed_memory">App Consumed Memory:</string>