For #10494: Process HomeMenu builder changes on the main thread
Problem was that we were trying to process menu changes (in response to account manager events) on some background thread as that's what account manager emits them on, so some code internally in PopupWindow's dismiss handling (i think, didn't dig very deeply here) was silently giving up and we'd get into a bad state. The reason this seemingly only happened if you quickly opened a menu on startup is because account manager isn't initialized until sometime after the startup finished. So the trick was to open the menu (and register account manager state callbacks) before it got initialized, so that the callbacks are invoked. This should also reproduce in other, much more obscure ways, e.g. if you open the menu right before sync is scheduled to run in the background, change FxA password on another connected client, and then eventually receive a onAuthenticationProblem callback.master
parent
ebb562a789
commit
b26ac51e90
|
@ -8,6 +8,9 @@ import android.content.Context
|
||||||
import androidx.core.content.ContextCompat.getColor
|
import androidx.core.content.ContextCompat.getColor
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import mozilla.components.browser.menu.BrowserMenuBuilder
|
import mozilla.components.browser.menu.BrowserMenuBuilder
|
||||||
import mozilla.components.browser.menu.BrowserMenuHighlight
|
import mozilla.components.browser.menu.BrowserMenuHighlight
|
||||||
import mozilla.components.browser.menu.ext.getHighlight
|
import mozilla.components.browser.menu.ext.getHighlight
|
||||||
|
@ -174,21 +177,31 @@ class HomeMenu(
|
||||||
}
|
}
|
||||||
context.components.backgroundServices.accountManager.register(object : AccountObserver {
|
context.components.backgroundServices.accountManager.register(object : AccountObserver {
|
||||||
override fun onAuthenticationProblems() {
|
override fun onAuthenticationProblems() {
|
||||||
onMenuBuilderChanged(BrowserMenuBuilder(
|
lifecycleOwner.lifecycleScope.launch(Dispatchers.Main) {
|
||||||
listOf(reconnectToSyncItem) + coreMenuItems
|
onMenuBuilderChanged(BrowserMenuBuilder(
|
||||||
))
|
listOf(reconnectToSyncItem) + coreMenuItems
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAuthenticated(account: OAuthAccount, authType: AuthType) {
|
override fun onAuthenticated(account: OAuthAccount, authType: AuthType) {
|
||||||
onMenuBuilderChanged(BrowserMenuBuilder(
|
lifecycleOwner.lifecycleScope.launch(Dispatchers.Main) {
|
||||||
coreMenuItems
|
onMenuBuilderChanged(
|
||||||
))
|
BrowserMenuBuilder(
|
||||||
|
coreMenuItems
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLoggedOut() {
|
override fun onLoggedOut() {
|
||||||
onMenuBuilderChanged(BrowserMenuBuilder(
|
lifecycleOwner.lifecycleScope.launch(Dispatchers.Main) {
|
||||||
coreMenuItems
|
onMenuBuilderChanged(
|
||||||
))
|
BrowserMenuBuilder(
|
||||||
|
coreMenuItems
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, lifecycleOwner)
|
}, lifecycleOwner)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue