From aa66b3e66e3576ffba17950d4a5d158727a8252a Mon Sep 17 00:00:00 2001 From: Mihai Branescu Date: Sat, 26 Oct 2019 07:41:31 +0300 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/5733 - Private mode notification - wrong home screen (https://github.com/mozilla-mobile/fenix/pull/6188) - added PRIVATE MODE intent extra to the notification action (could use also the OPEN_FROM_NOTIFICATION, but I considered this one to be more explicit. Kept the old one in case other checks will be done filtering for it) - added intent? param to the getPrivateModeFromIntent method, because onNewIntent() method does not set the activities intent, and it was needed to be used both in onCreate() and onNewIntent() --- app/src/main/java/org/mozilla/fenix/HomeActivity.kt | 5 +++-- .../org/mozilla/fenix/session/SessionNotificationService.kt | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index 77a49c782b..f0853a2279 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -86,7 +86,7 @@ open class HomeActivity : AppCompatActivity() { final override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val mode = getPrivateModeFromIntent() + val mode = getPrivateModeFromIntent(intent) components.publicSuffixList.prefetch() setupThemeAndBrowsingMode(mode) @@ -150,6 +150,7 @@ open class HomeActivity : AppCompatActivity() { val intentProcessors = listOf(CrashReporterIntentProcessor()) + externalSourceIntentProcessors intentProcessors.any { it.process(intent, navHost.navController, this.intent) } + browsingModeManager.mode = getPrivateModeFromIntent(intent) } /** @@ -192,7 +193,7 @@ open class HomeActivity : AppCompatActivity() { * External sources such as 3rd party links and shortcuts use this function to enter * private mode directly before the content view is created. */ - private fun getPrivateModeFromIntent(): BrowsingMode { + private fun getPrivateModeFromIntent(intent: Intent?): BrowsingMode { intent?.toSafeIntent()?.let { if (it.hasExtra(PRIVATE_BROWSING_MODE)) { val startPrivateMode = it.getBooleanExtra(PRIVATE_BROWSING_MODE, false) diff --git a/app/src/main/java/org/mozilla/fenix/session/SessionNotificationService.kt b/app/src/main/java/org/mozilla/fenix/session/SessionNotificationService.kt index a3e9f048fb..4743d456a2 100644 --- a/app/src/main/java/org/mozilla/fenix/session/SessionNotificationService.kt +++ b/app/src/main/java/org/mozilla/fenix/session/SessionNotificationService.kt @@ -18,9 +18,8 @@ import androidx.core.content.ContextCompat import androidx.core.content.getSystemService import mozilla.components.browser.session.SessionManager import mozilla.components.support.utils.ThreadUtils - -import org.mozilla.fenix.R import org.mozilla.fenix.HomeActivity +import org.mozilla.fenix.R import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.metrics @@ -104,6 +103,7 @@ class SessionNotificationService : Service() { private fun createOpenActionIntent(): PendingIntent { val intent = Intent(this, HomeActivity::class.java) intent.putExtra(HomeActivity.EXTRA_OPENED_FROM_NOTIFICATION, true) + intent.putExtra(HomeActivity.PRIVATE_BROWSING_MODE, true) return PendingIntent.getActivity(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT) }