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

Commit 65f6f2c1 authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Update views in (Q)QS footer when shade opens

The signal indicating that the shade is opening is `setListening(true)`,
so tie the checks for the views to that signal.

Also, remove the conditional state based on where the footer is.
Individual actions don't change visibility depending on QQS vs QS.

Test: manual
Test: atest com.android.systemui.qs
Fixes: 204165361
Change-Id: I86bf6818739f7f8c2890e9450e64dd9aefb691b5
parent 104ef43d
Loading
Loading
Loading
Loading
+3 −10
Original line number Original line Diff line number Diff line
@@ -72,12 +72,6 @@ class FooterActionsController @Inject constructor(
    private var listening: Boolean = false
    private var listening: Boolean = false


    var expanded = false
    var expanded = false
        set(value) {
            if (field != value) {
                field = value
                updateView()
            }
        }


    private val settingsButton: SettingsButton = view.findViewById(R.id.settings_button)
    private val settingsButton: SettingsButton = view.findViewById(R.id.settings_button)
    private val settingsButtonContainer: View? = view.findViewById(R.id.settings_button_container)
    private val settingsButtonContainer: View? = view.findViewById(R.id.settings_button_container)
@@ -176,8 +170,7 @@ class FooterActionsController @Inject constructor(
    }
    }


    private fun updateView() {
    private fun updateView() {
        mView.updateEverything(buttonsVisible(), isTunerEnabled(),
        mView.updateEverything(isTunerEnabled(), multiUserSwitchController.isMultiUserEnabled)
                multiUserSwitchController.isMultiUserEnabled)
    }
    }


    override fun onViewDetached() {
    override fun onViewDetached() {
@@ -191,14 +184,14 @@ class FooterActionsController @Inject constructor(
        this.listening = listening
        this.listening = listening
        if (this.listening) {
        if (this.listening) {
            userInfoController.addCallback(onUserInfoChangedListener)
            userInfoController.addCallback(onUserInfoChangedListener)
            updateView()
        } else {
        } else {
            userInfoController.removeCallback(onUserInfoChangedListener)
            userInfoController.removeCallback(onUserInfoChangedListener)
        }
        }
    }
    }


    fun disable(state2: Int) {
    fun disable(state2: Int) {
        mView.disable(buttonsVisible(), state2, isTunerEnabled(),
        mView.disable(state2, isTunerEnabled(), multiUserSwitchController.isMultiUserEnabled)
                multiUserSwitchController.isMultiUserEnabled)
    }
    }


    fun setExpansion(headerExpansionFraction: Float) {
    fun setExpansion(headerExpansionFraction: Float) {
+4 −7
Original line number Original line Diff line number Diff line
@@ -107,7 +107,6 @@ class FooterActionsView(context: Context?, attrs: AttributeSet?) : LinearLayout(
    }
    }


    fun disable(
    fun disable(
        buttonsVisible: Boolean,
        state2: Int,
        state2: Int,
        isTunerEnabled: Boolean,
        isTunerEnabled: Boolean,
        multiUserEnabled: Boolean
        multiUserEnabled: Boolean
@@ -115,16 +114,15 @@ class FooterActionsView(context: Context?, attrs: AttributeSet?) : LinearLayout(
        val disabled = state2 and StatusBarManager.DISABLE2_QUICK_SETTINGS != 0
        val disabled = state2 and StatusBarManager.DISABLE2_QUICK_SETTINGS != 0
        if (disabled == qsDisabled) return
        if (disabled == qsDisabled) return
        qsDisabled = disabled
        qsDisabled = disabled
        updateEverything(buttonsVisible, isTunerEnabled, multiUserEnabled)
        updateEverything(isTunerEnabled, multiUserEnabled)
    }
    }


    fun updateEverything(
    fun updateEverything(
        buttonsVisible: Boolean,
        isTunerEnabled: Boolean,
        isTunerEnabled: Boolean,
        multiUserEnabled: Boolean
        multiUserEnabled: Boolean
    ) {
    ) {
        post {
        post {
            updateVisibilities(buttonsVisible, isTunerEnabled, multiUserEnabled)
            updateVisibilities(isTunerEnabled, multiUserEnabled)
            updateClickabilities()
            updateClickabilities()
            isClickable = false
            isClickable = false
        }
        }
@@ -137,15 +135,14 @@ class FooterActionsView(context: Context?, attrs: AttributeSet?) : LinearLayout(
    }
    }


    private fun updateVisibilities(
    private fun updateVisibilities(
        buttonsVisible: Boolean,
        isTunerEnabled: Boolean,
        isTunerEnabled: Boolean,
        multiUserEnabled: Boolean
        multiUserEnabled: Boolean
    ) {
    ) {
        settingsContainer.visibility = if (qsDisabled) GONE else VISIBLE
        settingsContainer.visibility = if (qsDisabled) GONE else VISIBLE
        tunerIcon.visibility = if (isTunerEnabled) VISIBLE else INVISIBLE
        tunerIcon.visibility = if (isTunerEnabled) VISIBLE else INVISIBLE
        multiUserSwitch.visibility = if (buttonsVisible && multiUserEnabled) VISIBLE else GONE
        multiUserSwitch.visibility = if (multiUserEnabled) VISIBLE else GONE
        val isDemo = UserManager.isDeviceInDemoMode(context)
        val isDemo = UserManager.isDeviceInDemoMode(context)
        settingsButton.visibility = if (isDemo || !buttonsVisible) INVISIBLE else VISIBLE
        settingsButton.visibility = if (isDemo) INVISIBLE else VISIBLE
    }
    }


    fun onUserInfoChanged(picture: Drawable?, isGuestUser: Boolean) {
    fun onUserInfoChanged(picture: Drawable?, isGuestUser: Boolean) {
+34 −2
Original line number Original line Diff line number Diff line
package com.android.systemui.qs
package com.android.systemui.qs


import com.android.systemui.R
import android.os.UserManager
import android.os.UserManager
import android.testing.AndroidTestingRunner
import android.testing.TestableLooper
import android.testing.ViewUtils
import android.view.LayoutInflater
import android.view.LayoutInflater
import android.view.View
import android.view.View
import androidx.test.filters.SmallTest
import androidx.test.filters.SmallTest
@@ -9,6 +11,7 @@ import com.android.internal.logging.MetricsLogger
import com.android.internal.logging.UiEventLogger
import com.android.internal.logging.UiEventLogger
import com.android.internal.logging.testing.FakeMetricsLogger
import com.android.internal.logging.testing.FakeMetricsLogger
import com.android.systemui.Dependency
import com.android.systemui.Dependency
import com.android.systemui.R
import com.android.systemui.classifier.FalsingManagerFake
import com.android.systemui.classifier.FalsingManagerFake
import com.android.systemui.globalactions.GlobalActionsDialogLite
import com.android.systemui.globalactions.GlobalActionsDialogLite
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.plugins.ActivityStarter
@@ -19,8 +22,11 @@ import com.android.systemui.statusbar.policy.UserInfoController
import com.android.systemui.tuner.TunerService
import com.android.systemui.tuner.TunerService
import com.android.systemui.utils.leaks.FakeTunerService
import com.android.systemui.utils.leaks.FakeTunerService
import com.android.systemui.utils.leaks.LeakCheckedTest
import com.android.systemui.utils.leaks.LeakCheckedTest
import com.google.common.truth.Truth.assertThat
import org.junit.After
import org.junit.Before
import org.junit.Before
import org.junit.Test
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.any
import org.mockito.ArgumentMatchers.any
import org.mockito.ArgumentMatchers.anyBoolean
import org.mockito.ArgumentMatchers.anyBoolean
import org.mockito.Mock
import org.mockito.Mock
@@ -30,6 +36,8 @@ import org.mockito.MockitoAnnotations
import org.mockito.Mockito.`when` as whenever
import org.mockito.Mockito.`when` as whenever


@SmallTest
@SmallTest
@TestableLooper.RunWithLooper
@RunWith(AndroidTestingRunner::class)
class FooterActionsControllerTest : LeakCheckedTest() {
class FooterActionsControllerTest : LeakCheckedTest() {
    @Mock
    @Mock
    private lateinit var userManager: UserManager
    private lateinit var userManager: UserManager
@@ -53,10 +61,12 @@ class FooterActionsControllerTest : LeakCheckedTest() {
    private val metricsLogger: MetricsLogger = FakeMetricsLogger()
    private val metricsLogger: MetricsLogger = FakeMetricsLogger()
    private lateinit var view: FooterActionsView
    private lateinit var view: FooterActionsView
    private val falsingManager: FalsingManagerFake = FalsingManagerFake()
    private val falsingManager: FalsingManagerFake = FalsingManagerFake()
    private lateinit var testableLooper: TestableLooper


    @Before
    @Before
    fun setUp() {
    fun setUp() {
        MockitoAnnotations.initMocks(this)
        MockitoAnnotations.initMocks(this)
        testableLooper = TestableLooper.get(this)
        injectLeakCheckedDependencies(*LeakCheckedTest.ALL_SUPPORTED_CLASSES)
        injectLeakCheckedDependencies(*LeakCheckedTest.ALL_SUPPORTED_CLASSES)
        val fakeTunerService = Dependency.get(TunerService::class.java) as FakeTunerService
        val fakeTunerService = Dependency.get(TunerService::class.java) as FakeTunerService


@@ -69,7 +79,14 @@ class FooterActionsControllerTest : LeakCheckedTest() {
                globalActionsDialog, uiEventLogger, showPMLiteButton = true,
                globalActionsDialog, uiEventLogger, showPMLiteButton = true,
                buttonsVisibleState = ExpansionState.EXPANDED)
                buttonsVisibleState = ExpansionState.EXPANDED)
        controller.init()
        controller.init()
        controller.onViewAttached()
        ViewUtils.attachView(view)
        // View looper is the testable looper associated with the test
        testableLooper.processAllMessages()
    }

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


    @Test
    @Test
@@ -90,4 +107,19 @@ class FooterActionsControllerTest : LeakCheckedTest() {
        // Verify Settings wasn't launched.
        // Verify Settings wasn't launched.
        verify<ActivityStarter>(activityStarter, Mockito.never()).startActivity(any(), anyBoolean())
        verify<ActivityStarter>(activityStarter, Mockito.never()).startActivity(any(), anyBoolean())
    }
    }

    @Test
    fun testMultiUserSwitchUpdatedWhenExpansionStarts() {
        // When expansion starts, listening is set to true
        val multiUserSwitch = view.requireViewById<View>(R.id.multi_user_switch)

        assertThat(multiUserSwitch.visibility).isNotEqualTo(View.VISIBLE)

        whenever(multiUserSwitchController.isMultiUserEnabled).thenReturn(true)

        controller.setListening(true)
        testableLooper.processAllMessages()

        assertThat(multiUserSwitch.visibility).isEqualTo(View.VISIBLE)
    }
}
}
 No newline at end of file