summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Austin Delgado <austindelgado@google.com> 2023-10-30 18:30:08 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-10-30 18:30:08 +0000
commit3a1138a86ed1b4e3d383d0416bed8d7f39c0b7aa (patch)
tree628396b6d6fed10c84c6f36fd9117aae17e346d2
parentdbb916f1534c681341868713d16b98d82f940256 (diff)
parentbb632ecb3fefea4bd91069b0d6f888be9288acf7 (diff)
Merge "Move Face/FingerprintManager registration calls off main thread" into main
-rw-r--r--packages/SystemUI/src/com/android/systemui/biometrics/data/repository/FacePropertyRepository.kt10
-rw-r--r--packages/SystemUI/src/com/android/systemui/biometrics/data/repository/FingerprintPropertyRepository.kt8
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/biometrics/data/repository/FacePropertyRepositoryImplTest.kt8
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/biometrics/data/repository/FingerprintRepositoryImplTest.kt6
4 files changed, 26 insertions, 6 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/data/repository/FacePropertyRepository.kt b/packages/SystemUI/src/com/android/systemui/biometrics/data/repository/FacePropertyRepository.kt
index 5b0bd959d902..0ae2e1614fba 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/data/repository/FacePropertyRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/data/repository/FacePropertyRepository.kt
@@ -29,13 +29,16 @@ import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLoggin
import com.android.systemui.common.coroutine.ConflatedCallbackFlow
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
+import com.android.systemui.dagger.qualifiers.Background
import javax.inject.Inject
+import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
+import kotlinx.coroutines.withContext
/** A repository for the global state of Face sensor. */
interface FacePropertyRepository {
@@ -56,7 +59,8 @@ class FacePropertyRepositoryImpl
@Inject
constructor(
@Application private val applicationScope: CoroutineScope,
- private val faceManager: FaceManager?
+ @Background private val backgroundDispatcher: CoroutineDispatcher,
+ private val faceManager: FaceManager?,
) : FacePropertyRepository {
override val sensorInfo: StateFlow<FaceSensorInfo?> =
@@ -77,7 +81,9 @@ constructor(
)
}
}
- faceManager?.addAuthenticatorsRegisteredCallback(callback)
+ withContext(backgroundDispatcher) {
+ faceManager?.addAuthenticatorsRegisteredCallback(callback)
+ }
awaitClose {}
}
.onEach { Log.d(TAG, "sensorProps changed: $it") }
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/data/repository/FingerprintPropertyRepository.kt b/packages/SystemUI/src/com/android/systemui/biometrics/data/repository/FingerprintPropertyRepository.kt
index aa33100a3abe..0c0ed77a65f7 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/data/repository/FingerprintPropertyRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/data/repository/FingerprintPropertyRepository.kt
@@ -33,7 +33,9 @@ import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLoggin
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
+import com.android.systemui.dagger.qualifiers.Background
import javax.inject.Inject
+import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
@@ -41,6 +43,7 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
+import kotlinx.coroutines.withContext
/**
* A repository for the global state of FingerprintProperty.
@@ -67,6 +70,7 @@ class FingerprintPropertyRepositoryImpl
@Inject
constructor(
@Application private val applicationScope: CoroutineScope,
+ @Background private val backgroundDispatcher: CoroutineDispatcher,
private val fingerprintManager: FingerprintManager?,
) : FingerprintPropertyRepository {
@@ -93,7 +97,9 @@ constructor(
}
}
}
- fingerprintManager?.addAuthenticatorsRegisteredCallback(callback)
+ withContext(backgroundDispatcher) {
+ fingerprintManager?.addAuthenticatorsRegisteredCallback(callback)
+ }
awaitClose {}
}
.stateIn(
diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/data/repository/FacePropertyRepositoryImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/data/repository/FacePropertyRepositoryImplTest.kt
index 0da7b4ac88f8..c14ad6a46616 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/data/repository/FacePropertyRepositoryImplTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/data/repository/FacePropertyRepositoryImplTest.kt
@@ -32,6 +32,8 @@ import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.StandardTestDispatcher
+import kotlinx.coroutines.test.TestDispatcher
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
@@ -54,18 +56,20 @@ class FacePropertyRepositoryImplTest : SysuiTestCase() {
@JvmField @Rule val mockitoRule: MockitoRule = MockitoJUnit.rule()
private lateinit var underTest: FacePropertyRepository
+ private lateinit var dispatcher: TestDispatcher
private lateinit var testScope: TestScope
@Captor private lateinit var callback: ArgumentCaptor<IFaceAuthenticatorsRegisteredCallback>
@Mock private lateinit var faceManager: FaceManager
@Before
fun setup() {
- testScope = TestScope()
+ dispatcher = StandardTestDispatcher()
+ testScope = TestScope(dispatcher)
underTest = createRepository(faceManager)
}
private fun createRepository(manager: FaceManager? = faceManager) =
- FacePropertyRepositoryImpl(testScope.backgroundScope, manager)
+ FacePropertyRepositoryImpl(testScope.backgroundScope, dispatcher, manager)
@Test
fun whenFaceManagerIsNotPresentIsNull() =
diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/data/repository/FingerprintRepositoryImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/data/repository/FingerprintRepositoryImplTest.kt
index ed9ae5e3dc01..dc438d7d80f2 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/data/repository/FingerprintRepositoryImplTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/data/repository/FingerprintRepositoryImplTest.kt
@@ -65,7 +65,11 @@ class FingerprintRepositoryImplTest : SysuiTestCase() {
val dispatcher = StandardTestDispatcher()
testScope = TestScope(dispatcher)
repository =
- FingerprintPropertyRepositoryImpl(testScope.backgroundScope, fingerprintManager)
+ FingerprintPropertyRepositoryImpl(
+ testScope.backgroundScope,
+ dispatcher,
+ fingerprintManager
+ )
testScope.runCurrent()
verify(fingerprintManager)