Merge "Update views in (Q)QS footer when shade opens" into sc-v2-dev am: 5170817dea am: 7aa0266efb

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16132670

Change-Id: I03e0a7461c8b806a87fbce1cec883007d41ab63b
This commit is contained in:
Fabian Kozynski
2021-11-01 15:09:54 +00:00
committed by Automerger Merge Worker
3 changed files with 41 additions and 19 deletions

View File

@@ -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)
@@ -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() {
@@ -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) {

View File

@@ -107,7 +107,6 @@ class FooterActionsView(context: Context?, attrs: AttributeSet?) : LinearLayout(
}
fun disable(
buttonsVisible: Boolean,
state2: Int,
isTunerEnabled: Boolean,
multiUserEnabled: Boolean
@@ -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
}
@@ -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) {

View File

@@ -1,7 +1,9 @@
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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)
}
}