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
-
288e6a1e
by Matthew Finkel at 2020-09-25T19:01:43+00:00
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:
... | ... | @@ -36,6 +36,7 @@ dependencies { |
36 | 36 |
|
37 | 37 |
implementation Dependencies.kotlin_stdlib
|
38 | 38 |
implementation Dependencies.kotlin_coroutines
|
39 |
+ implementation project(path: ':support-utils')
|
|
39 | 40 |
|
40 | 41 |
testImplementation project(':support-test')
|
41 | 42 |
|
... | ... | @@ -67,7 +67,8 @@ class AppLinksFeature( |
67 | 67 |
loadUrlUseCase?.invoke(url, session, EngineSession.LoadUrlFlags.none())
|
68 | 68 |
}
|
69 | 69 |
|
70 |
- if (!session.private || fragmentManager == null) {
|
|
70 |
+ // useCases.openAppLink will now prompt: calling it directly to avoid prompting twice
|
|
71 |
+ if (true || !session.private || fragmentManager == null) {
|
|
71 | 72 |
doOpenApp()
|
72 | 73 |
return
|
73 | 74 |
}
|
... | ... | @@ -19,6 +19,7 @@ import mozilla.components.support.base.log.logger.Logger |
19 | 19 |
import mozilla.components.support.ktx.android.content.pm.isPackageInstalled
|
20 | 20 |
import mozilla.components.support.ktx.android.net.isHttpOrHttps
|
21 | 21 |
import java.net.URISyntaxException
|
22 |
+import mozilla.components.support.utils.TorUtils
|
|
22 | 23 |
|
23 | 24 |
private const val EXTRA_BROWSER_FALLBACK_URL = "browser_fallback_url"
|
24 | 25 |
private const val MARKET_INTENT_URI_PACKAGE_PREFIX = "market://details?id="
|
... | ... | @@ -200,7 +201,7 @@ class AppLinksUseCases( |
200 | 201 |
if (launchInNewTask) {
|
201 | 202 |
it.flags = it.flags or Intent.FLAG_ACTIVITY_NEW_TASK
|
202 | 203 |
}
|
203 |
- context.startActivity(it)
|
|
204 |
+ TorUtils.startActivityPrompt(context, it)
|
|
204 | 205 |
} catch (e: ActivityNotFoundException) {
|
205 | 206 |
failedToLaunchAction()
|
206 | 207 |
Logger.error("failed to start third party app activity", e)
|
... | ... | @@ -18,6 +18,7 @@ import mozilla.components.feature.app.links.AppLinksUseCases |
18 | 18 |
import mozilla.components.support.ktx.android.content.addContact
|
19 | 19 |
import mozilla.components.support.ktx.android.content.share
|
20 | 20 |
import mozilla.components.support.ktx.kotlin.stripMailToProtocol
|
21 |
+import mozilla.components.support.utils.TorUtils
|
|
21 | 22 |
|
22 | 23 |
/**
|
23 | 24 |
* A candidate for an item to be displayed in the context menu.
|
... | ... | @@ -320,7 +321,7 @@ data class ContextMenuCandidate( |
320 | 321 |
context.getString(R.string.mozac_feature_contextmenu_share_link)
|
321 | 322 |
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
322 | 323 |
|
323 |
- context.startActivity(shareIntent)
|
|
324 |
+ TorUtils.startActivityPrompt(context, shareIntent)
|
|
324 | 325 |
}
|
325 | 326 |
)
|
326 | 327 |
|
... | ... | @@ -70,6 +70,7 @@ import mozilla.components.support.base.log.logger.Logger |
70 | 70 |
import mozilla.components.support.ktx.kotlin.sanitizeURL
|
71 | 71 |
import mozilla.components.support.ktx.kotlinx.coroutines.throttleLatest
|
72 | 72 |
import mozilla.components.support.utils.DownloadUtils
|
73 |
+import mozilla.components.support.utils.TorUtils
|
|
73 | 74 |
import java.io.File
|
74 | 75 |
import java.io.FileOutputStream
|
75 | 76 |
import java.io.IOException
|
... | ... | @@ -812,7 +813,7 @@ abstract class AbstractFetchDownloadService : Service() { |
812 | 813 |
}
|
813 | 814 |
|
814 | 815 |
return try {
|
815 |
- context.startActivity(newIntent)
|
|
816 |
+ TorUtils.startActivityPrompt(context, newIntent)
|
|
816 | 817 |
true
|
817 | 818 |
} catch (error: ActivityNotFoundException) {
|
818 | 819 |
false
|
... | ... | @@ -35,6 +35,7 @@ import mozilla.components.support.base.log.Log |
35 | 35 |
import mozilla.components.support.base.log.logger.Logger
|
36 | 36 |
import mozilla.components.support.ktx.R
|
37 | 37 |
import mozilla.components.support.ktx.android.content.res.resolveAttribute
|
38 |
+import mozilla.components.support.utils.TorUtils
|
|
38 | 39 |
|
39 | 40 |
/**
|
40 | 41 |
* 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 |
105 | 106 |
flags = FLAG_ACTIVITY_NEW_TASK
|
106 | 107 |
}
|
107 | 108 |
|
108 |
- startActivity(shareIntent)
|
|
109 |
+ TorUtils.startActivityPrompt(this, shareIntent)
|
|
109 | 110 |
true
|
110 | 111 |
} catch (e: ActivityNotFoundException) {
|
111 | 112 |
Log.log(Log.Priority.WARN, message = "No activity to share to found", throwable = e, tag = "Reference-Browser")
|
... | ... | @@ -136,7 +137,7 @@ fun Context.email( |
136 | 137 |
flags = FLAG_ACTIVITY_NEW_TASK
|
137 | 138 |
}
|
138 | 139 |
|
139 |
- startActivity(emailIntent)
|
|
140 |
+ TorUtils.startActivityPrompt(this, emailIntent)
|
|
140 | 141 |
true
|
141 | 142 |
} catch (e: ActivityNotFoundException) {
|
142 | 143 |
Logger.warn("No activity found to handle email intent", throwable = e)
|
... | ... | @@ -167,7 +168,7 @@ fun Context.call( |
167 | 168 |
flags = FLAG_ACTIVITY_NEW_TASK
|
168 | 169 |
}
|
169 | 170 |
|
170 |
- startActivity(callIntent)
|
|
171 |
+ TorUtils.startActivityPrompt(this, callIntent)
|
|
171 | 172 |
true
|
172 | 173 |
} catch (e: ActivityNotFoundException) {
|
173 | 174 |
Logger.warn("No activity found to handle dial intent", throwable = e)
|
... | ... | @@ -195,7 +196,7 @@ fun Context.addContact( |
195 | 196 |
addFlags(FLAG_ACTIVITY_NEW_TASK)
|
196 | 197 |
}
|
197 | 198 |
|
198 |
- startActivity(intent)
|
|
199 |
+ TorUtils.startActivityPrompt(this, intent)
|
|
199 | 200 |
true
|
200 | 201 |
} catch (e: ActivityNotFoundException) {
|
201 | 202 |
Logger.warn("No activity found to handle dial intent", throwable = e)
|
1 |
+/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2 |
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3 |
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
4 |
+ |
|
5 |
+package mozilla.components.support.utils
|
|
6 |
+ |
|
7 |
+import android.app.PendingIntent
|
|
8 |
+import android.content.Context
|
|
9 |
+import android.content.Intent
|
|
10 |
+ |
|
11 |
+object TorUtils {
|
|
12 |
+ const val TORBROWSER_START_ACTIVITY_PROMPT = "torbrowser_start_activity_prompt"
|
|
13 |
+ |
|
14 |
+ // Delegates showing prompt and possibly starting the activity to the main app activity.
|
|
15 |
+ // Highly dependant on Fenix/Tor Browser for Android.
|
|
16 |
+ // One downside of this implementation is that it does not throw exceptions like the
|
|
17 |
+ // direct context.startActivity, so the UI will behave as if the startActivity call was
|
|
18 |
+ // done successfully, which may not always be the case.
|
|
19 |
+ fun startActivityPrompt(context: Context, intent: Intent) {
|
|
20 |
+ val intentContainer = Intent()
|
|
21 |
+ intentContainer.setPackage(context.applicationContext.packageName)
|
|
22 |
+ intentContainer.putExtra(TORBROWSER_START_ACTIVITY_PROMPT, PendingIntent.getActivity(context, 0, intent, 0))
|
|
23 |
+ intentContainer.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
|
24 |
+ context.startActivity(intentContainer)
|
|
25 |
+ }
|
|
26 |
+}
|