[tor-commits] [Git][tpo/applications/fenix][tor-browser-81.1.1-10.0-1] 2 commits: Bug 34378: Port external helper app prompting

Matthew Finkel gitlab at torproject.org
Fri Sep 25 19:06:46 UTC 2020



Matthew Finkel pushed to branch tor-browser-81.1.1-10.0-1 at The Tor Project / Applications / fenix


Commits:
67e28112 by Alex Catarineu at 2020-09-22T17:43:24+02:00
Bug 34378: Port external helper app prompting

With the corresponding android-components patch, this allows all `startActivity`
that may open external apps to be replaced by `TorUtils.startActivityPrompt`.

- - - - -
8b0f722f by Matthew Finkel at 2020-09-25T19:06:31+00:00
Merge remote-tracking branch 'acatgl/34378' into tor-browser-81.1.1-10.0-1

- - - - -


2 changed files:

- app/src/main/java/org/mozilla/fenix/HomeActivity.kt
- app/src/main/java/org/mozilla/fenix/share/ShareController.kt


Changes:

=====================================
app/src/main/java/org/mozilla/fenix/HomeActivity.kt
=====================================
@@ -4,6 +4,7 @@
 
 package org.mozilla.fenix
 
+import android.app.PendingIntent
 import android.content.BroadcastReceiver
 import android.content.Context
 import android.content.Intent
@@ -45,6 +46,8 @@ import mozilla.components.browser.state.state.SessionState
 import mozilla.components.browser.state.state.WebExtensionState
 import mozilla.components.concept.engine.EngineSession
 import mozilla.components.concept.engine.EngineView
+import mozilla.components.feature.app.links.RedirectDialogFragment
+import mozilla.components.feature.app.links.SimpleRedirectDialogFragment
 import mozilla.components.feature.contextmenu.DefaultSelectionActionDelegate
 import mozilla.components.feature.privatemode.notification.PrivateNotificationFeature
 import mozilla.components.feature.search.BrowserStoreSearchAdapter
@@ -58,6 +61,7 @@ import mozilla.components.support.ktx.kotlin.isUrl
 import mozilla.components.support.ktx.kotlin.toNormalizedUrl
 import mozilla.components.support.locale.LocaleAwareAppCompatActivity
 import mozilla.components.support.utils.SafeIntent
+import mozilla.components.support.utils.TorUtils
 import mozilla.components.support.utils.toSafeIntent
 import mozilla.components.support.webextensions.WebExtensionPopupFeature
 import org.mozilla.fenix.GleanMetrics.Metrics
@@ -154,6 +158,8 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
 
     private lateinit var navigationToolbar: Toolbar
 
+    private var dialog: RedirectDialogFragment? = null
+
     final override fun onCreate(savedInstanceState: Bundle?) {
         // Give Orbot the base Context
         Prefs.setContext(applicationContext)
@@ -387,6 +393,26 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
         super.recreate()
     }
 
+    // Copied from mozac AppLinksFeature.kt
+    internal fun getOrCreateDialog(): RedirectDialogFragment {
+        val existingDialog = dialog
+        if (existingDialog != null) {
+            return existingDialog
+        }
+
+        SimpleRedirectDialogFragment.newInstance().also {
+            dialog = it
+            return it
+        }
+    }
+    private fun isAlreadyADialogCreated(): Boolean {
+        return findPreviousDialogFragment() != null
+    }
+
+    private fun findPreviousDialogFragment(): RedirectDialogFragment? {
+        return supportFragmentManager.findFragmentByTag(RedirectDialogFragment.FRAGMENT_TAG) as? RedirectDialogFragment
+    }
+
     /**
      * Handles intents received when the activity is open.
      */
@@ -394,6 +420,25 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
         super.onNewIntent(intent)
         intent ?: return
 
+        val startIntent = intent.getParcelableExtra<PendingIntent>(TorUtils.TORBROWSER_START_ACTIVITY_PROMPT)
+        if (startIntent != null) {
+            if (startIntent.creatorPackage == applicationContext.packageName) {
+                val dialog = getOrCreateDialog()
+                dialog.onConfirmRedirect = {
+                    try {
+                        startIntent.send()
+                    } catch (error: PendingIntent.CanceledException) {
+                    }
+                }
+                dialog.onCancelRedirect = {}
+
+                if (!isAlreadyADialogCreated()) {
+                    dialog.showNow(supportFragmentManager, RedirectDialogFragment.FRAGMENT_TAG)
+                }
+            }
+            return
+        }
+
         // Diagnostic breadcrumb for "Display already aquired" crash:
         // https://github.com/mozilla-mobile/android-components/issues/7960
         breadcrumb(


=====================================
app/src/main/java/org/mozilla/fenix/share/ShareController.kt
=====================================
@@ -25,6 +25,7 @@ import mozilla.components.concept.sync.TabData
 import mozilla.components.feature.accounts.push.SendTabUseCases
 import mozilla.components.feature.share.RecentAppsStorage
 import mozilla.components.support.ktx.kotlin.isExtensionUrl
+import mozilla.components.support.utils.TorUtils
 import org.mozilla.fenix.R
 import org.mozilla.fenix.components.FenixSnackbar
 import org.mozilla.fenix.components.metrics.Event
@@ -99,7 +100,7 @@ class DefaultShareController(
         }
 
         val result = try {
-            context.startActivity(intent)
+            TorUtils.startActivityPrompt(context, intent)
             ShareController.Result.SUCCESS
         } catch (e: SecurityException) {
             snackbar.setText(context.getString(R.string.share_error_snackbar))



View it on GitLab: https://gitlab.torproject.org/tpo/applications/fenix/-/compare/7b11da2715b70282eefe8a30ca7aea6a86e9186c...8b0f722ffcc6d22049fb12b0d545d7b6d2fbe69f

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/fenix/-/compare/7b11da2715b70282eefe8a30ca7aea6a86e9186c...8b0f722ffcc6d22049fb12b0d545d7b6d2fbe69f
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tor-commits/attachments/20200925/af9b620a/attachment-0001.htm>


More information about the tor-commits mailing list