Richard Pospesel pushed to branch tor-browser-102.2.1-12.0-2 at The Tor Project / Applications / fenix
Commits:
-
25e5afc9
by Tommy Webb at 2023-02-02T23:24:52+00:00
2 changed files:
- app/src/main/java/org/mozilla/fenix/HomeActivity.kt
- app/src/main/java/org/mozilla/fenix/IntentReceiverActivity.kt
Changes:
... | ... | @@ -129,6 +129,7 @@ import org.mozilla.fenix.tabstray.TabsTrayFragment |
129 | 129 | import org.mozilla.fenix.tabstray.TabsTrayFragmentDirections
|
130 | 130 | import org.mozilla.fenix.theme.DefaultThemeManager
|
131 | 131 | import org.mozilla.fenix.theme.ThemeManager
|
132 | +import org.mozilla.fenix.tor.TorEvents
|
|
132 | 133 | import org.mozilla.fenix.trackingprotection.TrackingProtectionPanelDialogFragmentDirections
|
133 | 134 | import org.mozilla.fenix.utils.BrowsersCache
|
134 | 135 | import org.mozilla.fenix.utils.Settings
|
... | ... | @@ -533,6 +534,24 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { |
533 | 534 | * Handles intents received when the activity is open.
|
534 | 535 | */
|
535 | 536 | final override fun onNewIntent(intent: Intent?) {
|
537 | + if (intent?.action == ACTION_MAIN || components.torController.isConnected) {
|
|
538 | + onNewIntentInternal(intent)
|
|
539 | + } else {
|
|
540 | + // Wait until Tor is connected to handle intents from external apps for links, search, etc.
|
|
541 | + components.torController.registerTorListener(object : TorEvents {
|
|
542 | + override fun onTorConnected() {
|
|
543 | + components.torController.unregisterTorListener(this)
|
|
544 | + onNewIntentInternal(intent)
|
|
545 | + }
|
|
546 | + override fun onTorConnecting() { /* no-op */ }
|
|
547 | + override fun onTorStopped() { /* no-op */ }
|
|
548 | + override fun onTorStatusUpdate(entry: String?, status: String?) { /* no-op */ }
|
|
549 | + })
|
|
550 | + return
|
|
551 | + }
|
|
552 | + }
|
|
553 | + |
|
554 | + private fun onNewIntentInternal(intent: Intent?) {
|
|
536 | 555 | super.onNewIntent(intent)
|
537 | 556 | intent?.let {
|
538 | 557 | handleNewIntent(it)
|
... | ... | @@ -1092,13 +1111,16 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { |
1092 | 1111 | |
1093 | 1112 | /**
|
1094 | 1113 | * Indicates if the user should be redirected to the [BrowserFragment] or to the [HomeFragment],
|
1095 | - * links from an external apps should always opened in the [BrowserFragment].
|
|
1114 | + * links from an external apps should always opened in the [BrowserFragment],
|
|
1115 | + * unless Tor is not yet connected.
|
|
1096 | 1116 | */
|
1097 | 1117 | fun shouldStartOnHome(intent: Intent? = this.intent): Boolean {
|
1098 | 1118 | return components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
|
1099 | 1119 | // We only want to open on home when users tap the app,
|
1100 | - // we want to ignore other cases when the app gets open by users clicking on links.
|
|
1101 | - getSettings().shouldStartOnHome() && intent?.action == ACTION_MAIN
|
|
1120 | + // we want to ignore other cases when the app gets open by users clicking on links,
|
|
1121 | + // unless Tor is not yet connected.
|
|
1122 | + getSettings().shouldStartOnHome() && (intent?.action == ACTION_MAIN ||
|
|
1123 | + !components.torController.isConnected)
|
|
1102 | 1124 | }
|
1103 | 1125 | }
|
1104 | 1126 |
... | ... | @@ -6,6 +6,7 @@ package org.mozilla.fenix |
6 | 6 | |
7 | 7 | import android.app.Activity
|
8 | 8 | import android.content.Intent
|
9 | +import android.content.Intent.ACTION_MAIN
|
|
9 | 10 | import android.content.pm.PackageManager
|
10 | 11 | import android.os.Build
|
11 | 12 | import android.os.Bundle
|
... | ... | @@ -24,6 +25,7 @@ import org.mozilla.fenix.ext.settings |
24 | 25 | import org.mozilla.fenix.perf.MarkersActivityLifecycleCallbacks
|
25 | 26 | import org.mozilla.fenix.perf.StartupTimeline
|
26 | 27 | import org.mozilla.fenix.shortcut.NewTabShortcutIntentProcessor
|
28 | +import org.mozilla.fenix.tor.TorEvents
|
|
27 | 29 | |
28 | 30 | /**
|
29 | 31 | * Processes incoming intents and sends them to the corresponding activity.
|
... | ... | @@ -45,7 +47,23 @@ class IntentReceiverActivity : Activity() { |
45 | 47 | // the HomeActivity.
|
46 | 48 | val intent = intent?.let { Intent(it) } ?: Intent()
|
47 | 49 | intent.sanitize().stripUnwantedFlags()
|
48 | - processIntent(intent)
|
|
50 | + if (intent.action == ACTION_MAIN || components.torController.isConnected) {
|
|
51 | + processIntent(intent)
|
|
52 | + } else {
|
|
53 | + // Wait until Tor is connected to handle intents from external apps for links, search, etc.
|
|
54 | + components.torController.registerTorListener(object : TorEvents {
|
|
55 | + override fun onTorConnected() {
|
|
56 | + components.torController.unregisterTorListener(this)
|
|
57 | + processIntent(intent)
|
|
58 | + }
|
|
59 | + override fun onTorConnecting() { /* no-op */ }
|
|
60 | + override fun onTorStopped() { /* no-op */ }
|
|
61 | + override fun onTorStatusUpdate(entry: String?, status: String?) { /* no-op */ }
|
|
62 | + })
|
|
63 | + |
|
64 | + // In the meantime, open the HomeActivity so the user can get connected.
|
|
65 | + processIntent(Intent())
|
|
66 | + }
|
|
49 | 67 | |
50 | 68 | components.core.engine.profiler?.addMarker(
|
51 | 69 | MarkersActivityLifecycleCallbacks.MARKER_NAME, startTimeProfiler, "IntentReceiverActivity.onCreate"
|