Commit 550cec65 authored by Alex Catarineu's avatar Alex Catarineu Committed by Pier Angelo Vendrame
Browse files

TB 34378: [android] 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`.

Originally, android-components#40007 and fenix#34378.
parent 16b0c9ac
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -46,6 +46,7 @@ dependencies {
    implementation project(':ui-widgets')
    implementation project(':ui-widgets')


    implementation ComponentsDependencies.kotlin_coroutines
    implementation ComponentsDependencies.kotlin_coroutines
    implementation project(path: ':support-utils')


    testImplementation project(':support-test')
    testImplementation project(':support-test')
    testImplementation project(':support-test-libstate')
    testImplementation project(':support-test-libstate')
+1 −1
Original line number Original line Diff line number Diff line
@@ -108,7 +108,7 @@ class AppLinksFeature(
        }
        }


        @Suppress("ComplexCondition")
        @Suppress("ComplexCondition")
        if (isAuthentication(tab, appIntent) || (!tab.content.private && !shouldPrompt()) ||
        if (isAuthentication(tab, appIntent) || (true || !tab.content.private && !shouldPrompt()) ||
            fragmentManager == null
            fragmentManager == null
        ) {
        ) {
            doOpenApp()
            doOpenApp()
+2 −1
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import mozilla.components.support.utils.BrowsersCache
import mozilla.components.support.utils.ext.queryIntentActivitiesCompat
import mozilla.components.support.utils.ext.queryIntentActivitiesCompat
import mozilla.components.support.utils.ext.resolveActivityCompat
import mozilla.components.support.utils.ext.resolveActivityCompat
import java.net.URISyntaxException
import java.net.URISyntaxException
import mozilla.components.support.utils.TorUtils


@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal const val EXTRA_BROWSER_FALLBACK_URL = "browser_fallback_url"
internal const val EXTRA_BROWSER_FALLBACK_URL = "browser_fallback_url"
@@ -244,7 +245,7 @@ class AppLinksUseCases(
                    if (launchInNewTask) {
                    if (launchInNewTask) {
                        it.flags = it.flags or Intent.FLAG_ACTIVITY_NEW_TASK
                        it.flags = it.flags or Intent.FLAG_ACTIVITY_NEW_TASK
                    }
                    }
                    context.startActivity(it)
                    TorUtils.startActivityPrompt(context, it)
                } catch (e: Exception) {
                } catch (e: Exception) {
                    when (e) {
                    when (e) {
                        is ActivityNotFoundException, is SecurityException, is NullPointerException -> {
                        is ActivityNotFoundException, is SecurityException, is NullPointerException -> {
+3 −1
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@ import mozilla.components.support.ktx.kotlin.stripMailToProtocol
import mozilla.components.support.ktx.kotlin.takeOrReplace
import mozilla.components.support.ktx.kotlin.takeOrReplace
import mozilla.components.ui.widgets.DefaultSnackbarDelegate
import mozilla.components.ui.widgets.DefaultSnackbarDelegate
import mozilla.components.ui.widgets.SnackbarDelegate
import mozilla.components.ui.widgets.SnackbarDelegate
import mozilla.components.support.utils.TorUtils


/**
/**
 * A candidate for an item to be displayed in the context menu.
 * A candidate for an item to be displayed in the context menu.
@@ -495,7 +496,8 @@ data class ContextMenuCandidate(
                }
                }


                try {
                try {
                    context.startActivity(
                    TorUtils.startActivityPrompt(
                        context,
                        intent.createChooserExcludingCurrentApp(
                        intent.createChooserExcludingCurrentApp(
                            context,
                            context,
                            context.getString(R.string.mozac_feature_contextmenu_share_link),
                            context.getString(R.string.mozac_feature_contextmenu_share_link),
+2 −1
Original line number Original line Diff line number Diff line
@@ -78,6 +78,7 @@ import mozilla.components.support.ktx.kotlinx.coroutines.throttleLatest
import mozilla.components.support.utils.DownloadUtils
import mozilla.components.support.utils.DownloadUtils
import mozilla.components.support.utils.ext.registerReceiverCompat
import mozilla.components.support.utils.ext.registerReceiverCompat
import mozilla.components.support.utils.ext.stopForegroundCompat
import mozilla.components.support.utils.ext.stopForegroundCompat
import mozilla.components.support.utils.TorUtils
import java.io.File
import java.io.File
import java.io.FileOutputStream
import java.io.FileOutputStream
import java.io.IOException
import java.io.IOException
@@ -1021,7 +1022,7 @@ abstract class AbstractFetchDownloadService : Service() {
            val newIntent = createOpenFileIntent(applicationContext, download)
            val newIntent = createOpenFileIntent(applicationContext, download)


            return try {
            return try {
                applicationContext.startActivity(newIntent)
                TorUtils.startActivityPrompt(applicationContext, newIntent)
                true
                true
            } catch (error: ActivityNotFoundException) {
            } catch (error: ActivityNotFoundException) {
                false
                false
Loading