Merge "[Bouncer] Revert from shared flow..." into tm-qpr-dev
This commit is contained in:
@@ -23,10 +23,7 @@ import com.android.systemui.keyguard.shared.model.BouncerShowMessageModel
|
|||||||
import com.android.systemui.keyguard.shared.model.KeyguardBouncerModel
|
import com.android.systemui.keyguard.shared.model.KeyguardBouncerModel
|
||||||
import com.android.systemui.statusbar.phone.KeyguardBouncer
|
import com.android.systemui.statusbar.phone.KeyguardBouncer
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.channels.BufferOverflow
|
|
||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asSharedFlow
|
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
|
||||||
/** Encapsulates app state for the lock screen primary and alternate bouncer. */
|
/** Encapsulates app state for the lock screen primary and alternate bouncer. */
|
||||||
@@ -71,12 +68,8 @@ constructor(
|
|||||||
private val _keyguardAuthenticated = MutableStateFlow<Boolean?>(null)
|
private val _keyguardAuthenticated = MutableStateFlow<Boolean?>(null)
|
||||||
/** Determines if user is already unlocked */
|
/** Determines if user is already unlocked */
|
||||||
val keyguardAuthenticated = _keyguardAuthenticated.asStateFlow()
|
val keyguardAuthenticated = _keyguardAuthenticated.asStateFlow()
|
||||||
private val _showMessage =
|
private val _showMessage = MutableStateFlow<BouncerShowMessageModel?>(null)
|
||||||
MutableSharedFlow<BouncerShowMessageModel?>(
|
val showMessage = _showMessage.asStateFlow()
|
||||||
replay = 1,
|
|
||||||
onBufferOverflow = BufferOverflow.DROP_OLDEST
|
|
||||||
)
|
|
||||||
val showMessage = _showMessage.asSharedFlow()
|
|
||||||
private val _resourceUpdateRequests = MutableStateFlow(false)
|
private val _resourceUpdateRequests = MutableStateFlow(false)
|
||||||
val resourceUpdateRequests = _resourceUpdateRequests.asStateFlow()
|
val resourceUpdateRequests = _resourceUpdateRequests.asStateFlow()
|
||||||
val bouncerPromptReason: Int
|
val bouncerPromptReason: Int
|
||||||
@@ -125,7 +118,7 @@ constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun setShowMessage(bouncerShowMessageModel: BouncerShowMessageModel?) {
|
fun setShowMessage(bouncerShowMessageModel: BouncerShowMessageModel?) {
|
||||||
_showMessage.tryEmit(bouncerShowMessageModel)
|
_showMessage.value = bouncerShowMessageModel
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setKeyguardAuthenticated(keyguardAuthenticated: Boolean?) {
|
fun setKeyguardAuthenticated(keyguardAuthenticated: Boolean?) {
|
||||||
|
|||||||
@@ -271,6 +271,11 @@ constructor(
|
|||||||
repository.setKeyguardAuthenticated(null)
|
repository.setKeyguardAuthenticated(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Notifies that the message was shown. */
|
||||||
|
fun onMessageShown() {
|
||||||
|
repository.setShowMessage(null)
|
||||||
|
}
|
||||||
|
|
||||||
/** Notify that view visibility has changed. */
|
/** Notify that view visibility has changed. */
|
||||||
fun notifyBouncerVisibilityHasChanged(visibility: Int) {
|
fun notifyBouncerVisibilityHasChanged(visibility: Int) {
|
||||||
primaryBouncerCallbackInteractor.dispatchVisibilityChanged(visibility)
|
primaryBouncerCallbackInteractor.dispatchVisibilityChanged(visibility)
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import com.android.systemui.lifecycle.repeatWhenAttached
|
|||||||
import com.android.systemui.plugins.ActivityStarter
|
import com.android.systemui.plugins.ActivityStarter
|
||||||
import com.android.systemui.statusbar.phone.KeyguardBouncer.EXPANSION_VISIBLE
|
import com.android.systemui.statusbar.phone.KeyguardBouncer.EXPANSION_VISIBLE
|
||||||
import kotlinx.coroutines.awaitCancellation
|
import kotlinx.coroutines.awaitCancellation
|
||||||
import kotlinx.coroutines.flow.collect
|
|
||||||
import kotlinx.coroutines.flow.filter
|
import kotlinx.coroutines.flow.filter
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@@ -182,6 +181,7 @@ object KeyguardBouncerViewBinder {
|
|||||||
launch {
|
launch {
|
||||||
viewModel.bouncerShowMessage.collect {
|
viewModel.bouncerShowMessage.collect {
|
||||||
hostViewController.showMessage(it.message, it.colorStateList)
|
hostViewController.showMessage(it.message, it.colorStateList)
|
||||||
|
viewModel.onMessageShown()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,6 +86,11 @@ constructor(
|
|||||||
interactor.notifyKeyguardAuthenticatedHandled()
|
interactor.notifyKeyguardAuthenticatedHandled()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Notifies that the message was shown. */
|
||||||
|
fun onMessageShown() {
|
||||||
|
interactor.onMessageShown()
|
||||||
|
}
|
||||||
|
|
||||||
/** Observe whether back button is enabled. */
|
/** Observe whether back button is enabled. */
|
||||||
fun observeOnIsBackButtonEnabled(systemUiVisibility: () -> Int): Flow<Int> {
|
fun observeOnIsBackButtonEnabled(systemUiVisibility: () -> Int): Flow<Int> {
|
||||||
return interactor.isBackButtonEnabled.map { enabled ->
|
return interactor.isBackButtonEnabled.map { enabled ->
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import org.junit.Before
|
|||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mockito.Answers
|
import org.mockito.Answers
|
||||||
|
import org.mockito.ArgumentCaptor
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.Mockito.mock
|
import org.mockito.Mockito.mock
|
||||||
import org.mockito.Mockito.never
|
import org.mockito.Mockito.never
|
||||||
@@ -170,8 +171,10 @@ class PrimaryBouncerInteractorTest : SysuiTestCase() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testShowMessage() {
|
fun testShowMessage() {
|
||||||
|
val argCaptor = ArgumentCaptor.forClass(BouncerShowMessageModel::class.java)
|
||||||
mPrimaryBouncerInteractor.showMessage("abc", null)
|
mPrimaryBouncerInteractor.showMessage("abc", null)
|
||||||
verify(repository).setShowMessage(BouncerShowMessageModel("abc", null))
|
verify(repository).setShowMessage(argCaptor.capture())
|
||||||
|
assertThat(argCaptor.value.message).isEqualTo("abc")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -194,6 +197,12 @@ class PrimaryBouncerInteractorTest : SysuiTestCase() {
|
|||||||
verify(repository).setKeyguardAuthenticated(true)
|
verify(repository).setKeyguardAuthenticated(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testNotifyShowedMessage() {
|
||||||
|
mPrimaryBouncerInteractor.onMessageShown()
|
||||||
|
verify(repository).setShowMessage(null)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testOnScreenTurnedOff() {
|
fun testOnScreenTurnedOff() {
|
||||||
mPrimaryBouncerInteractor.onScreenTurnedOff()
|
mPrimaryBouncerInteractor.onScreenTurnedOff()
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.systemui.keyguard.ui.viewmodel
|
||||||
|
|
||||||
|
import androidx.test.filters.SmallTest
|
||||||
|
import com.android.systemui.SysuiTestCase
|
||||||
|
import com.android.systemui.keyguard.data.BouncerView
|
||||||
|
import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerInteractor
|
||||||
|
import com.android.systemui.keyguard.shared.model.BouncerShowMessageModel
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.launchIn
|
||||||
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.junit.runners.JUnit4
|
||||||
|
import org.mockito.Mock
|
||||||
|
import org.mockito.Mockito
|
||||||
|
import org.mockito.MockitoAnnotations
|
||||||
|
|
||||||
|
@SmallTest
|
||||||
|
@RunWith(JUnit4::class)
|
||||||
|
class KeyguardBouncerViewModelTest : SysuiTestCase() {
|
||||||
|
lateinit var underTest: KeyguardBouncerViewModel
|
||||||
|
@Mock lateinit var bouncerView: BouncerView
|
||||||
|
@Mock lateinit var bouncerInteractor: PrimaryBouncerInteractor
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
MockitoAnnotations.initMocks(this)
|
||||||
|
underTest = KeyguardBouncerViewModel(bouncerView, bouncerInteractor)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun setMessage() =
|
||||||
|
runBlocking(Dispatchers.Main.immediate) {
|
||||||
|
val flow = MutableStateFlow<BouncerShowMessageModel?>(null)
|
||||||
|
var message: BouncerShowMessageModel? = null
|
||||||
|
Mockito.`when`(bouncerInteractor.showMessage)
|
||||||
|
.thenReturn(flow as Flow<BouncerShowMessageModel>)
|
||||||
|
// Reinitialize the view model.
|
||||||
|
underTest = KeyguardBouncerViewModel(bouncerView, bouncerInteractor)
|
||||||
|
|
||||||
|
flow.value = BouncerShowMessageModel(message = "abc", colorStateList = null)
|
||||||
|
|
||||||
|
val job = underTest.bouncerShowMessage.onEach { message = it }.launchIn(this)
|
||||||
|
assertThat(message?.message).isEqualTo("abc")
|
||||||
|
job.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user