Merge "Move SettingObserver#setListening out of frequent path" into tm-dev

This commit is contained in:
TreeHugger Robot
2022-02-23 13:22:47 +00:00
committed by Android (Google) Code Review
2 changed files with 26 additions and 4 deletions

View File

@@ -165,6 +165,7 @@ internal class FooterActionsController @Inject constructor(
powerMenuLite.visibility = View.GONE
}
settingsButton.setOnClickListener(onClickListener)
multiUserSetting.isListening = true
if (featureFlags.isEnabled(Flags.NEW_FOOTER)) {
val securityFooter = securityFooterController.view as DualHeightHorizontalLinearLayout
securityFootersContainer?.addView(securityFooter)
@@ -215,6 +216,7 @@ internal class FooterActionsController @Inject constructor(
override fun onViewDetached() {
setListening(false)
multiUserSetting.isListening = false
}
fun setListening(listening: Boolean) {
@@ -222,7 +224,6 @@ internal class FooterActionsController @Inject constructor(
return
}
this.listening = listening
multiUserSetting.isListening = listening
if (this.listening) {
userInfoController.addCallback(onUserInfoChangedListener)
updateView()

View File

@@ -100,7 +100,9 @@ class FooterActionsControllerTest : LeakCheckedTest() {
@After
fun tearDown() {
ViewUtils.detachView(view)
if (view.isAttachedToWindow) {
ViewUtils.detachView(view)
}
}
@Test
@@ -139,8 +141,7 @@ class FooterActionsControllerTest : LeakCheckedTest() {
@Test
fun testMultiUserSwitchUpdatedWhenSettingChanged() {
// When expanded, listening is true
controller.setListening(true)
// Always listening to setting while View is attached
testableLooper.processAllMessages()
val multiUserSwitch = view.requireViewById<View>(R.id.multi_user_switch)
@@ -156,4 +157,24 @@ class FooterActionsControllerTest : LeakCheckedTest() {
assertThat(multiUserSwitch.visibility).isEqualTo(View.VISIBLE)
}
@Test
fun testMultiUserSettingNotListenedAfterDetach() {
testableLooper.processAllMessages()
val multiUserSwitch = view.requireViewById<View>(R.id.multi_user_switch)
assertThat(multiUserSwitch.visibility).isNotEqualTo(View.VISIBLE)
ViewUtils.detachView(view)
// The setting is only used as an indicator for whether the view should refresh. The actual
// value of the setting is ignored; isMultiUserEnabled is the source of truth
whenever(multiUserSwitchController.isMultiUserEnabled).thenReturn(true)
// Changing the value of USER_SWITCHER_ENABLED should cause the view to update
fakeSettings.putIntForUser(Settings.Global.USER_SWITCHER_ENABLED, 1, userTracker.userId)
testableLooper.processAllMessages()
assertThat(multiUserSwitch.visibility).isNotEqualTo(View.VISIBLE)
}
}