Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7acb8990 authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Move SettingObserver#setListening out of frequent path

FooterActionsController#setListening is called in the main thread
because it updates views. There was a register/unregister content
observer in that path that was causing jank.

As the setting doesn't change frequently, move the register/unregister
to match the view attached/detached.

Test: atest FooterActionsController
Test: manual
Fixes: 220874628
Change-Id: I9b5130eaee71ab8d5eb226a3078631ac7d153e23
parent 4d897c6a
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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()
+24 −3
Original line number Diff line number Diff line
@@ -100,8 +100,10 @@ class FooterActionsControllerTest : LeakCheckedTest() {

    @After
    fun tearDown() {
        if (view.isAttachedToWindow) {
            ViewUtils.detachView(view)
        }
    }

    @Test
    fun testLogPowerMenuClick() {
@@ -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)
    }
}
 No newline at end of file