Commit 2de25637 authored by Alex Catarineu's avatar Alex Catarineu Committed by clairehurst
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 f5e6afdb
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ class AppLinksFeature(
        isAuthenticationFlow: Boolean,
        fragmentManager: FragmentManager?,
    ): Boolean {
        val shouldShowPrompt = isPrivate || shouldPrompt()
        val shouldShowPrompt = true
        return fragmentManager == null || !shouldShowPrompt || isAuthenticationFlow
    }

+2 −1
Original line number 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.resolveActivityCompat
import java.net.URISyntaxException
import mozilla.components.support.utils.TorUtils

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

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

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

            return try {
                applicationContext.startActivity(newIntent)
                TorUtils.startActivityPrompt(applicationContext, newIntent)
                true
            } catch (error: ActivityNotFoundException) {
                false
+9 −9
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ 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.ext.getPackageInfoCompat
import mozilla.components.support.utils.TorUtils
import java.io.File

/**
@@ -115,12 +116,11 @@ fun Context.share(text: String, subject: String = getString(R.string.mozac_suppo
            flags = FLAG_ACTIVITY_NEW_TASK
        }

        startActivity(
            intent.createChooserExcludingCurrentApp(
                this,
                getString(R.string.mozac_support_ktx_menu_share_with),
            ),
        )
        val shareIntent = intent.createChooserExcludingCurrentApp(this, getString(R.string.mozac_support_ktx_menu_share_with)).apply {
            flags = FLAG_ACTIVITY_NEW_TASK
        }

        TorUtils.startActivityPrompt(this, shareIntent)
        true
    } catch (e: ActivityNotFoundException) {
        Log.log(Log.Priority.WARN, message = "No activity to share to found", throwable = e, tag = "share")
@@ -260,7 +260,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)
@@ -291,7 +291,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)
@@ -319,7 +319,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)
Loading