Merge "Take home controls setting into account" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
bca7840e34
@@ -36,6 +36,7 @@ import com.android.systemui.util.kotlin.getOrNull
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
|
||||
/** Home controls quick affordance data source. */
|
||||
@@ -50,7 +51,13 @@ constructor(
|
||||
private val appContext = context.applicationContext
|
||||
|
||||
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(
|
||||
animationController: ActivityLaunchAnimator.Controller?,
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.keyguard.data.repository
|
||||
package com.android.systemui.keyguard.data.quickaffordance
|
||||
|
||||
import androidx.test.filters.SmallTest
|
||||
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.dagger.ControlsComponent
|
||||
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.google.common.truth.Truth.assertThat
|
||||
import java.util.Optional
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.test.runBlockingTest
|
||||
@@ -50,18 +49,19 @@ class HomeControlsKeyguardQuickAffordanceConfigParameterizedStateTest : SysuiTes
|
||||
companion object {
|
||||
@Parameters(
|
||||
name =
|
||||
"feature enabled = {0}, has favorites = {1}, has service infos = {2} - expected" +
|
||||
" visible = {3}"
|
||||
"feature enabled = {0}, has favorites = {1}, has service infos = {2}, can show" +
|
||||
" while locked = {3} - expected visible = {4}"
|
||||
)
|
||||
@JvmStatic
|
||||
fun data() =
|
||||
(0 until 8)
|
||||
(0 until 16)
|
||||
.map { combination ->
|
||||
arrayOf(
|
||||
/* isFeatureEnabled= */ combination and 0b100 != 0,
|
||||
/* hasFavorites= */ combination and 0b010 != 0,
|
||||
/* hasServiceInfos= */ combination and 0b001 != 0,
|
||||
/* isVisible= */ combination == 0b111,
|
||||
/* isFeatureEnabled= */ combination and 0b1000 != 0,
|
||||
/* hasFavorites= */ combination and 0b0100 != 0,
|
||||
/* hasServiceInfos= */ combination and 0b0010 != 0,
|
||||
/* canShowWhileLocked= */ combination and 0b0001 != 0,
|
||||
/* isVisible= */ combination == 0b1111,
|
||||
)
|
||||
}
|
||||
.toList()
|
||||
@@ -79,7 +79,8 @@ class HomeControlsKeyguardQuickAffordanceConfigParameterizedStateTest : SysuiTes
|
||||
@JvmField @Parameter(0) var isFeatureEnabled: Boolean = false
|
||||
@JvmField @Parameter(1) var hasFavorites: 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
|
||||
fun setUp() {
|
||||
@@ -89,6 +90,8 @@ class HomeControlsKeyguardQuickAffordanceConfigParameterizedStateTest : SysuiTes
|
||||
whenever(component.getControlsController()).thenReturn(Optional.of(controlsController))
|
||||
whenever(component.getControlsListingController())
|
||||
.thenReturn(Optional.of(controlsListingController))
|
||||
whenever(component.canShowWhileLockedSetting)
|
||||
.thenReturn(MutableStateFlow(canShowWhileLocked))
|
||||
|
||||
underTest =
|
||||
HomeControlsKeyguardQuickAffordanceConfig(
|
||||
@@ -111,14 +114,16 @@ class HomeControlsKeyguardQuickAffordanceConfigParameterizedStateTest : SysuiTes
|
||||
val values = mutableListOf<KeyguardQuickAffordanceConfig.State>()
|
||||
val job = underTest.state.onEach(values::add).launchIn(this)
|
||||
|
||||
verify(controlsListingController).addCallback(callbackCaptor.capture())
|
||||
callbackCaptor.value.onServicesUpdated(
|
||||
if (hasServiceInfos) {
|
||||
listOf(mock())
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
)
|
||||
if (canShowWhileLocked) {
|
||||
verify(controlsListingController).addCallback(callbackCaptor.capture())
|
||||
callbackCaptor.value.onServicesUpdated(
|
||||
if (hasServiceInfos) {
|
||||
listOf(mock())
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
assertThat(values.last())
|
||||
.isInstanceOf(
|
||||
@@ -51,6 +51,7 @@ class HomeControlsKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
whenever(component.canShowWhileLockedSetting).thenReturn(MutableStateFlow(true))
|
||||
|
||||
underTest =
|
||||
HomeControlsKeyguardQuickAffordanceConfig(
|
||||
@@ -60,7 +61,26 @@ class HomeControlsKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
|
||||
}
|
||||
|
||||
@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.getTileImageId()).thenReturn(R.drawable.controls_icon)
|
||||
whenever(component.getTileTitleId()).thenReturn(R.string.quick_controls_title)
|
||||
|
||||
Reference in New Issue
Block a user