Skip to content
Snippets Groups Projects
Unverified Commit 86ae994e authored by Alex Catarineu's avatar Alex Catarineu Committed by boklm
Browse files

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`.
parent a3e4f167
No related branches found
No related tags found
1 merge request!69Rebase android-components patches to v91.0.8
......@@ -42,6 +42,7 @@ dependencies {
implementation Dependencies.kotlin_stdlib
implementation Dependencies.kotlin_coroutines
implementation project(path: ':support-utils')
testImplementation project(':support-test')
testImplementation project(':support-test-libstate')
......
......@@ -100,7 +100,7 @@ class AppLinksFeature(
)
}
if (!tab.content.private || fragmentManager == null) {
if (true || !tab.content.private || fragmentManager == null) {
doOpenApp()
return
}
......
......@@ -21,6 +21,7 @@ import mozilla.components.support.ktx.android.net.isHttpOrHttps
import java.lang.Exception
import java.lang.NullPointerException
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="
......@@ -211,7 +212,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 -> {
......
......@@ -23,6 +23,7 @@ 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.ktx.kotlin.takeOrReplace
import mozilla.components.support.utils.TorUtils
/**
* A candidate for an item to be displayed in the context menu.
......@@ -358,7 +359,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)
}
)
......
......@@ -74,6 +74,7 @@ import mozilla.components.support.ktx.kotlin.ifNullOrEmpty
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
......@@ -947,7 +948,7 @@ abstract class AbstractFetchDownloadService : Service() {
}
return try {
applicationContext.startActivity(newIntent)
TorUtils.startActivityPrompt(applicationContext, newIntent)
true
} catch (error: ActivityNotFoundException) {
false
......
......@@ -39,6 +39,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
import java.io.File
/**
......@@ -110,7 +111,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")
......@@ -191,7 +192,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)
......@@ -222,7 +223,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)
......@@ -250,7 +251,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)
......
/* 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)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment