From aa5069caca760dd2b44604c37071794c2196be16 Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Wed, 28 Aug 2019 20:03:04 +0200 Subject: [PATCH] Closes #4215: CustomTabActivity: Remove attached session if activity is finishing. (#4985) --- .../fenix/customtabs/CustomTabActivity.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabActivity.kt b/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabActivity.kt index 05ff3ea9a..efa48a53f 100644 --- a/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabActivity.kt @@ -6,12 +6,14 @@ package org.mozilla.fenix.customtabs import androidx.navigation.NavDestination import mozilla.components.browser.session.intent.getSessionId +import mozilla.components.browser.session.runWithSession import mozilla.components.support.utils.SafeIntent import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.NavGraphDirections import org.mozilla.fenix.browser.browsingmode.CustomTabBrowsingModeManager import org.mozilla.fenix.components.metrics.Event +import org.mozilla.fenix.ext.components import org.mozilla.fenix.theme.CustomTabThemeManager import java.security.InvalidParameterException @@ -40,4 +42,19 @@ open class CustomTabActivity : HomeActivity() { CustomTabBrowsingModeManager() final override fun createThemeManager() = CustomTabThemeManager() + + override fun onDestroy() { + super.onDestroy() + + if (isFinishing) { + // When this activity finishes, the process is staying around and the session still + // exists then remove it now to free all its resources. Once this activity is finished + // then there's no way to get back to it other than relaunching it. + val sessionId = getIntentSessionId(SafeIntent(intent)) + components.core.sessionManager.runWithSession(sessionId) { session -> + remove(session) + true + } + } + } }