Commit a03f6853 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 35877569
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -178,7 +178,7 @@ class AppLinksFeature(
        isPrivate: Boolean,
        isWallet: Boolean,
    ): Boolean {
        val shouldShowPrompt = isPrivate || isWallet || shouldPrompt()
        val shouldShowPrompt = true
        return !shouldShowPrompt
    }

+2 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import mozilla.components.support.utils.Browsers
import mozilla.components.support.utils.BrowsersCache
import mozilla.components.support.utils.ext.packageManagerCompatHelper
import java.net.URISyntaxException
import mozilla.components.support.utils.TorUtils

@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal const val EXTRA_BROWSER_FALLBACK_URL = "browser_fallback_url"
@@ -260,7 +261,7 @@ class AppLinksUseCases(
                    if (clearTop) {
                        it.flags = it.flags or Intent.FLAG_ACTIVITY_CLEAR_TOP
                    }
                    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
@@ -29,6 +29,7 @@ import mozilla.components.support.ktx.kotlin.takeOrReplace
import mozilla.components.ui.widgets.DefaultSnackbarDelegate
import mozilla.components.ui.widgets.SnackbarDelegate
import kotlin.String
import mozilla.components.support.utils.TorUtils

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

                try {
                    context.startActivity(
                    TorUtils.startActivityPrompt(
                        context,
                        intent.createChooserExcludingCurrentApp(
                            context,
                            context.getString(R.string.mozac_feature_contextmenu_share_link),
+9 −9
Original line number Diff line number Diff line
@@ -52,6 +52,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.packageManagerCompatHelper
import mozilla.components.support.utils.TorUtils
import java.io.File

/**
@@ -120,12 +121,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")
@@ -314,7 +314,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)
@@ -345,7 +345,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)
@@ -373,7 +373,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)
+2 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import mozilla.components.support.utils.DownloadUtils.findFileInMediaStore
import mozilla.components.support.utils.DownloadUtils.isDefaultDownloadDirectory
import mozilla.components.support.utils.DownloadUtils.sanitizeMimeType
import mozilla.components.support.utils.DownloadUtils.truncateFileName
import mozilla.components.support.utils.TorUtils
import java.io.File
import java.io.FileNotFoundException

@@ -102,7 +103,7 @@ class DefaultDownloadFileUtils(
        )

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