mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-09 19:10:42 +00:00
[fenix] Closes https://github.com/mozilla-mobile/fenix/issues/15882: check for account state abnormalities after account manager is ready
This commit is contained in:
parent
4d440e1570
commit
e136adf6c6
@ -89,17 +89,7 @@ class AccountAbnormalities(
|
||||
hadAccountPrior = prefPair.second
|
||||
}
|
||||
|
||||
/**
|
||||
* Once [accountManager] is initialized, queries it to detect abnormal account states.
|
||||
* Call this right after running [FxaAccountManager.initAsync].
|
||||
*
|
||||
* @param accountManager An instance of [FxaAccountManager].
|
||||
* @param initResult A deferred result of initializing [accountManager].
|
||||
* @return A [Unit] deferred, resolved once [initResult] is resolved and state is processed for abnormalities.
|
||||
*/
|
||||
fun accountManagerStarted(
|
||||
accountManager: FxaAccountManager
|
||||
) {
|
||||
override fun onReady(authenticatedAccount: OAuthAccount?) {
|
||||
check(!accountManagerConfigured) { "accountManagerStarted called twice" }
|
||||
accountManagerConfigured = true
|
||||
|
||||
@ -110,7 +100,7 @@ class AccountAbnormalities(
|
||||
// account. This works because our account state is persisted in the application's
|
||||
// directory, same as SharedPreferences. If user clears application data, both the
|
||||
// fxa state and our flag will be removed.
|
||||
val hasAccountNow = accountManager.authenticatedAccount() != null
|
||||
val hasAccountNow = authenticatedAccount != null
|
||||
if (hadAccountPrior && !hasAccountNow) {
|
||||
prefs.edit().putBoolean(KEY_HAS_ACCOUNT, false).apply()
|
||||
|
||||
|
@ -177,6 +177,8 @@ class BackgroundServices(
|
||||
// unexpected logouts.
|
||||
accountManager.register(accountAbnormalities)
|
||||
|
||||
accountManager.register(AccountManagerReadyObserver(accountManagerAvailableQueue))
|
||||
|
||||
// Enable push if it's configured.
|
||||
push.feature?.let { autoPushFeature ->
|
||||
FxaPushSupportFeature(context, accountManager, autoPushFeature, crashReporter)
|
||||
@ -190,10 +192,7 @@ class BackgroundServices(
|
||||
|
||||
MainScope().launch {
|
||||
accountManager.start()
|
||||
accountAbnormalities.accountManagerStarted(accountManager)
|
||||
}
|
||||
}.also {
|
||||
accountManagerAvailableQueue.ready()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -204,6 +203,14 @@ class BackgroundServices(
|
||||
}
|
||||
}
|
||||
|
||||
private class AccountManagerReadyObserver(
|
||||
private val accountManagerAvailableQueue: RunWhenReadyQueue
|
||||
) : AccountObserver {
|
||||
override fun onReady(authenticatedAccount: OAuthAccount?) {
|
||||
accountManagerAvailableQueue.ready()
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = PRIVATE)
|
||||
internal class TelemetryAccountObserver(
|
||||
private val settings: Settings,
|
||||
|
Loading…
Reference in New Issue
Block a user