Loading packages/SystemUI/src/com/android/systemui/qs/FooterActionsController.kt +3 −10 Original line number Diff line number Diff line Loading @@ -72,12 +72,6 @@ class FooterActionsController @Inject constructor( private var listening: Boolean = false var expanded = false set(value) { if (field != value) { field = value updateView() } } private val settingsButton: SettingsButton = view.findViewById(R.id.settings_button) private val settingsButtonContainer: View? = view.findViewById(R.id.settings_button_container) Loading Loading @@ -176,8 +170,7 @@ class FooterActionsController @Inject constructor( } private fun updateView() { mView.updateEverything(buttonsVisible(), isTunerEnabled(), multiUserSwitchController.isMultiUserEnabled) mView.updateEverything(isTunerEnabled(), multiUserSwitchController.isMultiUserEnabled) } override fun onViewDetached() { Loading @@ -191,14 +184,14 @@ class FooterActionsController @Inject constructor( this.listening = listening if (this.listening) { userInfoController.addCallback(onUserInfoChangedListener) updateView() } else { userInfoController.removeCallback(onUserInfoChangedListener) } } fun disable(state2: Int) { mView.disable(buttonsVisible(), state2, isTunerEnabled(), multiUserSwitchController.isMultiUserEnabled) mView.disable(state2, isTunerEnabled(), multiUserSwitchController.isMultiUserEnabled) } fun setExpansion(headerExpansionFraction: Float) { Loading packages/SystemUI/src/com/android/systemui/qs/FooterActionsView.kt +4 −7 Original line number Diff line number Diff line Loading @@ -107,7 +107,6 @@ class FooterActionsView(context: Context?, attrs: AttributeSet?) : LinearLayout( } fun disable( buttonsVisible: Boolean, state2: Int, isTunerEnabled: Boolean, multiUserEnabled: Boolean Loading @@ -115,16 +114,15 @@ class FooterActionsView(context: Context?, attrs: AttributeSet?) : LinearLayout( val disabled = state2 and StatusBarManager.DISABLE2_QUICK_SETTINGS != 0 if (disabled == qsDisabled) return qsDisabled = disabled updateEverything(buttonsVisible, isTunerEnabled, multiUserEnabled) updateEverything(isTunerEnabled, multiUserEnabled) } fun updateEverything( buttonsVisible: Boolean, isTunerEnabled: Boolean, multiUserEnabled: Boolean ) { post { updateVisibilities(buttonsVisible, isTunerEnabled, multiUserEnabled) updateVisibilities(isTunerEnabled, multiUserEnabled) updateClickabilities() isClickable = false } Loading @@ -137,15 +135,14 @@ class FooterActionsView(context: Context?, attrs: AttributeSet?) : LinearLayout( } private fun updateVisibilities( buttonsVisible: Boolean, isTunerEnabled: Boolean, multiUserEnabled: Boolean ) { settingsContainer.visibility = if (qsDisabled) GONE else VISIBLE 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) settingsButton.visibility = if (isDemo || !buttonsVisible) INVISIBLE else VISIBLE settingsButton.visibility = if (isDemo) INVISIBLE else VISIBLE } fun onUserInfoChanged(picture: Drawable?, isGuestUser: Boolean) { Loading packages/SystemUI/tests/src/com/android/systemui/qs/FooterActionsControllerTest.kt +34 −2 Original line number Diff line number Diff line package com.android.systemui.qs import com.android.systemui.R import android.os.UserManager import android.testing.AndroidTestingRunner import android.testing.TestableLooper import android.testing.ViewUtils import android.view.LayoutInflater import android.view.View import androidx.test.filters.SmallTest Loading @@ -9,6 +11,7 @@ import com.android.internal.logging.MetricsLogger import com.android.internal.logging.UiEventLogger import com.android.internal.logging.testing.FakeMetricsLogger import com.android.systemui.Dependency import com.android.systemui.R import com.android.systemui.classifier.FalsingManagerFake import com.android.systemui.globalactions.GlobalActionsDialogLite import com.android.systemui.plugins.ActivityStarter Loading @@ -19,8 +22,11 @@ import com.android.systemui.statusbar.policy.UserInfoController import com.android.systemui.tuner.TunerService import com.android.systemui.utils.leaks.FakeTunerService 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.Test import org.junit.runner.RunWith import org.mockito.ArgumentMatchers.any import org.mockito.ArgumentMatchers.anyBoolean import org.mockito.Mock Loading @@ -30,6 +36,8 @@ import org.mockito.MockitoAnnotations import org.mockito.Mockito.`when` as whenever @SmallTest @TestableLooper.RunWithLooper @RunWith(AndroidTestingRunner::class) class FooterActionsControllerTest : LeakCheckedTest() { @Mock private lateinit var userManager: UserManager Loading @@ -53,10 +61,12 @@ class FooterActionsControllerTest : LeakCheckedTest() { private val metricsLogger: MetricsLogger = FakeMetricsLogger() private lateinit var view: FooterActionsView private val falsingManager: FalsingManagerFake = FalsingManagerFake() private lateinit var testableLooper: TestableLooper @Before fun setUp() { MockitoAnnotations.initMocks(this) testableLooper = TestableLooper.get(this) injectLeakCheckedDependencies(*LeakCheckedTest.ALL_SUPPORTED_CLASSES) val fakeTunerService = Dependency.get(TunerService::class.java) as FakeTunerService Loading @@ -69,7 +79,14 @@ class FooterActionsControllerTest : LeakCheckedTest() { globalActionsDialog, uiEventLogger, showPMLiteButton = true, buttonsVisibleState = ExpansionState.EXPANDED) 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 Loading @@ -90,4 +107,19 @@ class FooterActionsControllerTest : LeakCheckedTest() { // Verify Settings wasn't launched. 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 Loading
packages/SystemUI/src/com/android/systemui/qs/FooterActionsController.kt +3 −10 Original line number Diff line number Diff line Loading @@ -72,12 +72,6 @@ class FooterActionsController @Inject constructor( private var listening: Boolean = false var expanded = false set(value) { if (field != value) { field = value updateView() } } private val settingsButton: SettingsButton = view.findViewById(R.id.settings_button) private val settingsButtonContainer: View? = view.findViewById(R.id.settings_button_container) Loading Loading @@ -176,8 +170,7 @@ class FooterActionsController @Inject constructor( } private fun updateView() { mView.updateEverything(buttonsVisible(), isTunerEnabled(), multiUserSwitchController.isMultiUserEnabled) mView.updateEverything(isTunerEnabled(), multiUserSwitchController.isMultiUserEnabled) } override fun onViewDetached() { Loading @@ -191,14 +184,14 @@ class FooterActionsController @Inject constructor( this.listening = listening if (this.listening) { userInfoController.addCallback(onUserInfoChangedListener) updateView() } else { userInfoController.removeCallback(onUserInfoChangedListener) } } fun disable(state2: Int) { mView.disable(buttonsVisible(), state2, isTunerEnabled(), multiUserSwitchController.isMultiUserEnabled) mView.disable(state2, isTunerEnabled(), multiUserSwitchController.isMultiUserEnabled) } fun setExpansion(headerExpansionFraction: Float) { Loading
packages/SystemUI/src/com/android/systemui/qs/FooterActionsView.kt +4 −7 Original line number Diff line number Diff line Loading @@ -107,7 +107,6 @@ class FooterActionsView(context: Context?, attrs: AttributeSet?) : LinearLayout( } fun disable( buttonsVisible: Boolean, state2: Int, isTunerEnabled: Boolean, multiUserEnabled: Boolean Loading @@ -115,16 +114,15 @@ class FooterActionsView(context: Context?, attrs: AttributeSet?) : LinearLayout( val disabled = state2 and StatusBarManager.DISABLE2_QUICK_SETTINGS != 0 if (disabled == qsDisabled) return qsDisabled = disabled updateEverything(buttonsVisible, isTunerEnabled, multiUserEnabled) updateEverything(isTunerEnabled, multiUserEnabled) } fun updateEverything( buttonsVisible: Boolean, isTunerEnabled: Boolean, multiUserEnabled: Boolean ) { post { updateVisibilities(buttonsVisible, isTunerEnabled, multiUserEnabled) updateVisibilities(isTunerEnabled, multiUserEnabled) updateClickabilities() isClickable = false } Loading @@ -137,15 +135,14 @@ class FooterActionsView(context: Context?, attrs: AttributeSet?) : LinearLayout( } private fun updateVisibilities( buttonsVisible: Boolean, isTunerEnabled: Boolean, multiUserEnabled: Boolean ) { settingsContainer.visibility = if (qsDisabled) GONE else VISIBLE 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) settingsButton.visibility = if (isDemo || !buttonsVisible) INVISIBLE else VISIBLE settingsButton.visibility = if (isDemo) INVISIBLE else VISIBLE } fun onUserInfoChanged(picture: Drawable?, isGuestUser: Boolean) { Loading
packages/SystemUI/tests/src/com/android/systemui/qs/FooterActionsControllerTest.kt +34 −2 Original line number Diff line number Diff line package com.android.systemui.qs import com.android.systemui.R import android.os.UserManager import android.testing.AndroidTestingRunner import android.testing.TestableLooper import android.testing.ViewUtils import android.view.LayoutInflater import android.view.View import androidx.test.filters.SmallTest Loading @@ -9,6 +11,7 @@ import com.android.internal.logging.MetricsLogger import com.android.internal.logging.UiEventLogger import com.android.internal.logging.testing.FakeMetricsLogger import com.android.systemui.Dependency import com.android.systemui.R import com.android.systemui.classifier.FalsingManagerFake import com.android.systemui.globalactions.GlobalActionsDialogLite import com.android.systemui.plugins.ActivityStarter Loading @@ -19,8 +22,11 @@ import com.android.systemui.statusbar.policy.UserInfoController import com.android.systemui.tuner.TunerService import com.android.systemui.utils.leaks.FakeTunerService 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.Test import org.junit.runner.RunWith import org.mockito.ArgumentMatchers.any import org.mockito.ArgumentMatchers.anyBoolean import org.mockito.Mock Loading @@ -30,6 +36,8 @@ import org.mockito.MockitoAnnotations import org.mockito.Mockito.`when` as whenever @SmallTest @TestableLooper.RunWithLooper @RunWith(AndroidTestingRunner::class) class FooterActionsControllerTest : LeakCheckedTest() { @Mock private lateinit var userManager: UserManager Loading @@ -53,10 +61,12 @@ class FooterActionsControllerTest : LeakCheckedTest() { private val metricsLogger: MetricsLogger = FakeMetricsLogger() private lateinit var view: FooterActionsView private val falsingManager: FalsingManagerFake = FalsingManagerFake() private lateinit var testableLooper: TestableLooper @Before fun setUp() { MockitoAnnotations.initMocks(this) testableLooper = TestableLooper.get(this) injectLeakCheckedDependencies(*LeakCheckedTest.ALL_SUPPORTED_CLASSES) val fakeTunerService = Dependency.get(TunerService::class.java) as FakeTunerService Loading @@ -69,7 +79,14 @@ class FooterActionsControllerTest : LeakCheckedTest() { globalActionsDialog, uiEventLogger, showPMLiteButton = true, buttonsVisibleState = ExpansionState.EXPANDED) 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 Loading @@ -90,4 +107,19 @@ class FooterActionsControllerTest : LeakCheckedTest() { // Verify Settings wasn't launched. 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