Merge "Take home controls setting into account" into tm-qpr-dev

This commit is contained in:
Alejandro Nijamkin
2022-08-09 20:05:04 +00:00
committed by Android (Google) Code Review
3 changed files with 53 additions and 21 deletions

View File

@@ -36,6 +36,7 @@ import com.android.systemui.util.kotlin.getOrNull
import javax.inject.Inject import javax.inject.Inject
import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.flowOf
/** Home controls quick affordance data source. */ /** Home controls quick affordance data source. */
@@ -50,7 +51,13 @@ constructor(
private val appContext = context.applicationContext private val appContext = context.applicationContext
override val state: Flow<KeyguardQuickAffordanceConfig.State> = override val state: Flow<KeyguardQuickAffordanceConfig.State> =
stateInternal(component.getControlsListingController().getOrNull()) component.canShowWhileLockedSetting.flatMapLatest { canShowWhileLocked ->
if (canShowWhileLocked) {
stateInternal(component.getControlsListingController().getOrNull())
} else {
flowOf(KeyguardQuickAffordanceConfig.State.Hidden)
}
}
override fun onQuickAffordanceClicked( override fun onQuickAffordanceClicked(
animationController: ActivityLaunchAnimator.Controller?, animationController: ActivityLaunchAnimator.Controller?,

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.systemui.keyguard.data.repository package com.android.systemui.keyguard.data.quickaffordance
import androidx.test.filters.SmallTest import androidx.test.filters.SmallTest
import com.android.systemui.R import com.android.systemui.R
@@ -22,11 +22,10 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.controls.controller.ControlsController import com.android.systemui.controls.controller.ControlsController
import com.android.systemui.controls.dagger.ControlsComponent import com.android.systemui.controls.dagger.ControlsComponent
import com.android.systemui.controls.management.ControlsListingController import com.android.systemui.controls.management.ControlsListingController
import com.android.systemui.keyguard.data.quickaffordance.HomeControlsKeyguardQuickAffordanceConfig
import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceConfig
import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.mock
import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertThat
import java.util.Optional import java.util.Optional
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.test.runBlockingTest import kotlinx.coroutines.test.runBlockingTest
@@ -50,18 +49,19 @@ class HomeControlsKeyguardQuickAffordanceConfigParameterizedStateTest : SysuiTes
companion object { companion object {
@Parameters( @Parameters(
name = name =
"feature enabled = {0}, has favorites = {1}, has service infos = {2} - expected" + "feature enabled = {0}, has favorites = {1}, has service infos = {2}, can show" +
" visible = {3}" " while locked = {3} - expected visible = {4}"
) )
@JvmStatic @JvmStatic
fun data() = fun data() =
(0 until 8) (0 until 16)
.map { combination -> .map { combination ->
arrayOf( arrayOf(
/* isFeatureEnabled= */ combination and 0b100 != 0, /* isFeatureEnabled= */ combination and 0b1000 != 0,
/* hasFavorites= */ combination and 0b010 != 0, /* hasFavorites= */ combination and 0b0100 != 0,
/* hasServiceInfos= */ combination and 0b001 != 0, /* hasServiceInfos= */ combination and 0b0010 != 0,
/* isVisible= */ combination == 0b111, /* canShowWhileLocked= */ combination and 0b0001 != 0,
/* isVisible= */ combination == 0b1111,
) )
} }
.toList() .toList()
@@ -79,7 +79,8 @@ class HomeControlsKeyguardQuickAffordanceConfigParameterizedStateTest : SysuiTes
@JvmField @Parameter(0) var isFeatureEnabled: Boolean = false @JvmField @Parameter(0) var isFeatureEnabled: Boolean = false
@JvmField @Parameter(1) var hasFavorites: Boolean = false @JvmField @Parameter(1) var hasFavorites: Boolean = false
@JvmField @Parameter(2) var hasServiceInfos: Boolean = false @JvmField @Parameter(2) var hasServiceInfos: Boolean = false
@JvmField @Parameter(3) var isVisible: Boolean = false @JvmField @Parameter(3) var canShowWhileLocked: Boolean = false
@JvmField @Parameter(4) var isVisible: Boolean = false
@Before @Before
fun setUp() { fun setUp() {
@@ -89,6 +90,8 @@ class HomeControlsKeyguardQuickAffordanceConfigParameterizedStateTest : SysuiTes
whenever(component.getControlsController()).thenReturn(Optional.of(controlsController)) whenever(component.getControlsController()).thenReturn(Optional.of(controlsController))
whenever(component.getControlsListingController()) whenever(component.getControlsListingController())
.thenReturn(Optional.of(controlsListingController)) .thenReturn(Optional.of(controlsListingController))
whenever(component.canShowWhileLockedSetting)
.thenReturn(MutableStateFlow(canShowWhileLocked))
underTest = underTest =
HomeControlsKeyguardQuickAffordanceConfig( HomeControlsKeyguardQuickAffordanceConfig(
@@ -111,14 +114,16 @@ class HomeControlsKeyguardQuickAffordanceConfigParameterizedStateTest : SysuiTes
val values = mutableListOf<KeyguardQuickAffordanceConfig.State>() val values = mutableListOf<KeyguardQuickAffordanceConfig.State>()
val job = underTest.state.onEach(values::add).launchIn(this) val job = underTest.state.onEach(values::add).launchIn(this)
verify(controlsListingController).addCallback(callbackCaptor.capture()) if (canShowWhileLocked) {
callbackCaptor.value.onServicesUpdated( verify(controlsListingController).addCallback(callbackCaptor.capture())
if (hasServiceInfos) { callbackCaptor.value.onServicesUpdated(
listOf(mock()) if (hasServiceInfos) {
} else { listOf(mock())
emptyList() } else {
} emptyList()
) }
)
}
assertThat(values.last()) assertThat(values.last())
.isInstanceOf( .isInstanceOf(

View File

@@ -51,6 +51,7 @@ class HomeControlsKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
@Before @Before
fun setUp() { fun setUp() {
MockitoAnnotations.initMocks(this) MockitoAnnotations.initMocks(this)
whenever(component.canShowWhileLockedSetting).thenReturn(MutableStateFlow(true))
underTest = underTest =
HomeControlsKeyguardQuickAffordanceConfig( HomeControlsKeyguardQuickAffordanceConfig(
@@ -60,7 +61,26 @@ class HomeControlsKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
} }
@Test @Test
fun `state - when listing controller is missing - returns None`() = runBlockingTest { fun `state - when cannot show while locked - returns Hidden`() = runBlockingTest {
whenever(component.canShowWhileLockedSetting).thenReturn(MutableStateFlow(false))
whenever(component.isEnabled()).thenReturn(true)
whenever(component.getTileImageId()).thenReturn(R.drawable.controls_icon)
whenever(component.getTileTitleId()).thenReturn(R.string.quick_controls_title)
val controlsController = mock<ControlsController>()
whenever(component.getControlsController()).thenReturn(Optional.of(controlsController))
whenever(component.getControlsListingController()).thenReturn(Optional.empty())
whenever(controlsController.getFavorites()).thenReturn(listOf(mock()))
val values = mutableListOf<KeyguardQuickAffordanceConfig.State>()
val job = underTest.state.onEach(values::add).launchIn(this)
assertThat(values.last())
.isInstanceOf(KeyguardQuickAffordanceConfig.State.Hidden::class.java)
job.cancel()
}
@Test
fun `state - when listing controller is missing - returns Hidden`() = runBlockingTest {
whenever(component.isEnabled()).thenReturn(true) whenever(component.isEnabled()).thenReturn(true)
whenever(component.getTileImageId()).thenReturn(R.drawable.controls_icon) whenever(component.getTileImageId()).thenReturn(R.drawable.controls_icon)
whenever(component.getTileTitleId()).thenReturn(R.string.quick_controls_title) whenever(component.getTileTitleId()).thenReturn(R.string.quick_controls_title)