tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 3faaa8ab7adf87c6e0276634786fab7757ff5739
parent f326950b5e24534838fc57687b4c6dd467657668
Author: Ben Dean-Kawamura <bdk@mozilla.com>
Date:   Fri,  3 Oct 2025 20:32:45 +0000

Bug 1851018 - Handle account state push msgs, r=jonalmeida,android-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D267043

Diffstat:
Mmobile/android/android-components/components/service/firefox-accounts/src/main/java/mozilla/components/service/fxa/manager/FxaAccountManager.kt | 33+++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+), 0 deletions(-)

diff --git a/mobile/android/android-components/components/service/firefox-accounts/src/main/java/mozilla/components/service/fxa/manager/FxaAccountManager.kt b/mobile/android/android-components/components/service/firefox-accounts/src/main/java/mozilla/components/service/fxa/manager/FxaAccountManager.kt @@ -8,6 +8,7 @@ import android.content.Context import androidx.annotation.GuardedBy import androidx.annotation.VisibleForTesting import androidx.lifecycle.LifecycleOwner +import androidx.lifecycle.ProcessLifecycleOwner import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.asCoroutineDispatcher @@ -20,6 +21,7 @@ import mozilla.appservices.fxaclient.FxaState import mozilla.appservices.syncmanager.DeviceSettings import mozilla.components.concept.base.crash.Breadcrumb import mozilla.components.concept.base.crash.CrashReporting +import mozilla.components.concept.sync.AccountEvent import mozilla.components.concept.sync.AccountEventsObserver import mozilla.components.concept.sync.AccountObserver import mozilla.components.concept.sync.AuthFlowError @@ -115,6 +117,7 @@ open class FxaAccountManager( private val accountOnDisk by lazy { getStorageWrapper().account() } private val account by lazy { accountOnDisk.account() } + private val accountStateEventsObserver = AccountStateEventsObserver(this::queueEvent) // Note on threading: we use a single-threaded executor, so there's no concurrent access possible. // However, that executor doesn't guarantee that it'll always use the same thread, and so vars @@ -149,6 +152,8 @@ open class FxaAccountManager( private var syncManager: SyncManager? = null init { + registerForAccountEvents(accountStateEventsObserver, ProcessLifecycleOwner.get(), false) + syncConfig?.let { // Initialize sync manager with the passed-in config. require(syncConfig.supportedEngines.isNotEmpty()) { @@ -427,6 +432,12 @@ open class FxaAccountManager( logger.debug("processQueue: finished") } + internal fun queueEvent(event: Event) { + CoroutineScope(coroutineContext).launch { + processQueue(event) + } + } + private fun calcFxaEvent(event: Event): FxaEvent? = when (event) { Event.Account.Start -> FxaEvent.Initialize( ASDeviceConfig( @@ -765,3 +776,25 @@ open class FxaAccountManager( } } } + +internal class AccountStateEventsObserver( + internal val queueEvent: (Event) -> Unit, +) : AccountEventsObserver { + private val logger = Logger("FxA AccountStateEventsObserver") + + override fun onEvents(events: List<AccountEvent>) { + for (event in events) { + when (event) { + AccountEvent.AccountAuthStateChanged -> { + logger.info("Saw AccountAuthStateChanged") + queueEvent(Event.Account.AuthenticationError("AccountAuthStateChanged event")) + } + AccountEvent.AccountDestroyed -> { + logger.info("Saw AccountDestroyed") + queueEvent(Event.Account.Logout) + } + else -> Unit + } + } + } +}