[tbb-commits] [Git][tpo/applications/android-components][android-components-57.0.6-10.0-1] 2 commits: Bug 40007: Port external helper app prompting

Matthew Finkel gitlab at torproject.org
Fri Sep 25 19:03:37 UTC 2020



Matthew Finkel pushed to branch android-components-57.0.6-10.0-1 at The Tor Project / Applications / android-components


Commits:
282eda4d by Alex Catarineu at 2020-09-24T14:55:29+02:00
Bug 40007: Port external helper app prompting

Together with the corresponding fenix patch, this allows all `startActivity`
that may open external apps to be replaced by `TorUtils.startActivityPrompt`.

- - - - -
288e6a1e by Matthew Finkel at 2020-09-25T19:01:43+00:00
Merge remote-tracking branch 'acatgl/40007+1' into android-components-57.0.6-10.0-1

- - - - -


7 changed files:

- components/feature/app-links/build.gradle
- components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksFeature.kt
- components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksUseCases.kt
- components/feature/contextmenu/src/main/java/mozilla/components/feature/contextmenu/ContextMenuCandidate.kt
- components/feature/downloads/src/main/java/mozilla/components/feature/downloads/AbstractFetchDownloadService.kt
- components/support/ktx/src/main/java/mozilla/components/support/ktx/android/content/Context.kt
- + components/support/utils/src/main/java/mozilla/components/support/utils/TorUtils.kt


Changes:

=====================================
components/feature/app-links/build.gradle
=====================================
@@ -36,6 +36,7 @@ dependencies {
 
     implementation Dependencies.kotlin_stdlib
     implementation Dependencies.kotlin_coroutines
+    implementation project(path: ':support-utils')
 
     testImplementation project(':support-test')
 


=====================================
components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksFeature.kt
=====================================
@@ -67,7 +67,8 @@ class AppLinksFeature(
                 loadUrlUseCase?.invoke(url, session, EngineSession.LoadUrlFlags.none())
             }
 
-            if (!session.private || fragmentManager == null) {
+            // useCases.openAppLink will now prompt: calling it directly to avoid prompting twice
+            if (true || !session.private || fragmentManager == null) {
                 doOpenApp()
                 return
             }


=====================================
components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksUseCases.kt
=====================================
@@ -19,6 +19,7 @@ import mozilla.components.support.base.log.logger.Logger
 import mozilla.components.support.ktx.android.content.pm.isPackageInstalled
 import mozilla.components.support.ktx.android.net.isHttpOrHttps
 import java.net.URISyntaxException
+import mozilla.components.support.utils.TorUtils
 
 private const val EXTRA_BROWSER_FALLBACK_URL = "browser_fallback_url"
 private const val MARKET_INTENT_URI_PACKAGE_PREFIX = "market://details?id="
@@ -200,7 +201,7 @@ class AppLinksUseCases(
                     if (launchInNewTask) {
                         it.flags = it.flags or Intent.FLAG_ACTIVITY_NEW_TASK
                     }
-                    context.startActivity(it)
+                    TorUtils.startActivityPrompt(context, it)
                 } catch (e: ActivityNotFoundException) {
                     failedToLaunchAction()
                     Logger.error("failed to start third party app activity", e)


=====================================
components/feature/contextmenu/src/main/java/mozilla/components/feature/contextmenu/ContextMenuCandidate.kt
=====================================
@@ -18,6 +18,7 @@ import mozilla.components.feature.app.links.AppLinksUseCases
 import mozilla.components.support.ktx.android.content.addContact
 import mozilla.components.support.ktx.android.content.share
 import mozilla.components.support.ktx.kotlin.stripMailToProtocol
+import mozilla.components.support.utils.TorUtils
 
 /**
  * A candidate for an item to be displayed in the context menu.
@@ -320,7 +321,7 @@ data class ContextMenuCandidate(
                     context.getString(R.string.mozac_feature_contextmenu_share_link)
                 ).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
 
-                context.startActivity(shareIntent)
+                TorUtils.startActivityPrompt(context, shareIntent)
             }
         )
 


=====================================
components/feature/downloads/src/main/java/mozilla/components/feature/downloads/AbstractFetchDownloadService.kt
=====================================
@@ -70,6 +70,7 @@ import mozilla.components.support.base.log.logger.Logger
 import mozilla.components.support.ktx.kotlin.sanitizeURL
 import mozilla.components.support.ktx.kotlinx.coroutines.throttleLatest
 import mozilla.components.support.utils.DownloadUtils
+import mozilla.components.support.utils.TorUtils
 import java.io.File
 import java.io.FileOutputStream
 import java.io.IOException
@@ -812,7 +813,7 @@ abstract class AbstractFetchDownloadService : Service() {
             }
 
             return try {
-                context.startActivity(newIntent)
+                TorUtils.startActivityPrompt(context, newIntent)
                 true
             } catch (error: ActivityNotFoundException) {
                 false


=====================================
components/support/ktx/src/main/java/mozilla/components/support/ktx/android/content/Context.kt
=====================================
@@ -35,6 +35,7 @@ import mozilla.components.support.base.log.Log
 import mozilla.components.support.base.log.logger.Logger
 import mozilla.components.support.ktx.R
 import mozilla.components.support.ktx.android.content.res.resolveAttribute
+import mozilla.components.support.utils.TorUtils
 
 /**
  * The (visible) version name of the application, as specified by the <manifest> tag's versionName
@@ -105,7 +106,7 @@ fun Context.share(text: String, subject: String = getString(R.string.mozac_suppo
             flags = FLAG_ACTIVITY_NEW_TASK
         }
 
-        startActivity(shareIntent)
+        TorUtils.startActivityPrompt(this, shareIntent)
         true
     } catch (e: ActivityNotFoundException) {
         Log.log(Log.Priority.WARN, message = "No activity to share to found", throwable = e, tag = "Reference-Browser")
@@ -136,7 +137,7 @@ fun Context.email(
             flags = FLAG_ACTIVITY_NEW_TASK
         }
 
-        startActivity(emailIntent)
+        TorUtils.startActivityPrompt(this, emailIntent)
         true
     } catch (e: ActivityNotFoundException) {
         Logger.warn("No activity found to handle email intent", throwable = e)
@@ -167,7 +168,7 @@ fun Context.call(
             flags = FLAG_ACTIVITY_NEW_TASK
         }
 
-        startActivity(callIntent)
+        TorUtils.startActivityPrompt(this, callIntent)
         true
     } catch (e: ActivityNotFoundException) {
         Logger.warn("No activity found to handle dial intent", throwable = e)
@@ -195,7 +196,7 @@ fun Context.addContact(
             addFlags(FLAG_ACTIVITY_NEW_TASK)
         }
 
-        startActivity(intent)
+        TorUtils.startActivityPrompt(this, intent)
         true
     } catch (e: ActivityNotFoundException) {
         Logger.warn("No activity found to handle dial intent", throwable = e)


=====================================
components/support/utils/src/main/java/mozilla/components/support/utils/TorUtils.kt
=====================================
@@ -0,0 +1,26 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package mozilla.components.support.utils
+
+import android.app.PendingIntent
+import android.content.Context
+import android.content.Intent
+
+object TorUtils {
+    const val TORBROWSER_START_ACTIVITY_PROMPT = "torbrowser_start_activity_prompt"
+
+    // Delegates showing prompt and possibly starting the activity to the main app activity.
+    // Highly dependant on Fenix/Tor Browser for Android.
+    // One downside of this implementation is that it does not throw exceptions like the
+    // direct context.startActivity, so the UI will behave as if the startActivity call was
+    // done successfully, which may not always be the case.
+    fun startActivityPrompt(context: Context, intent: Intent) {
+        val intentContainer = Intent()
+        intentContainer.setPackage(context.applicationContext.packageName)
+        intentContainer.putExtra(TORBROWSER_START_ACTIVITY_PROMPT, PendingIntent.getActivity(context, 0, intent, 0))
+        intentContainer.flags = Intent.FLAG_ACTIVITY_NEW_TASK
+        context.startActivity(intentContainer)
+    }
+}



View it on GitLab: https://gitlab.torproject.org/tpo/applications/android-components/-/compare/6af46bae4f0476ee3eb430a7ab9e6e6746be0265...288e6a1e81890ba3e2def9bb4863782bc8bba953

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/android-components/-/compare/6af46bae4f0476ee3eb430a7ab9e6e6746be0265...288e6a1e81890ba3e2def9bb4863782bc8bba953
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/tbb-commits/attachments/20200925/27ac2a59/attachment-0001.htm>


More information about the tbb-commits mailing list