Merge "FingerprintSensorProperties refactor - domain layer" into udc-dev
This commit is contained in:
@@ -29,6 +29,8 @@ import com.android.systemui.biometrics.domain.interactor.DisplayStateInteractor
|
||||
import com.android.systemui.biometrics.domain.interactor.DisplayStateInteractorImpl
|
||||
import com.android.systemui.biometrics.domain.interactor.LogContextInteractor
|
||||
import com.android.systemui.biometrics.domain.interactor.LogContextInteractorImpl
|
||||
import com.android.systemui.biometrics.domain.interactor.SideFpsOverlayInteractor
|
||||
import com.android.systemui.biometrics.domain.interactor.SideFpsOverlayInteractorImpl
|
||||
import com.android.systemui.dagger.SysUISingleton
|
||||
import com.android.systemui.util.concurrency.ThreadFactory
|
||||
import dagger.Binds
|
||||
@@ -65,6 +67,11 @@ interface BiometricsModule {
|
||||
@SysUISingleton
|
||||
fun bindsLogContextInteractor(impl: LogContextInteractorImpl): LogContextInteractor
|
||||
|
||||
@Binds
|
||||
@SysUISingleton
|
||||
fun providesSideFpsOverlayInteractor(impl: SideFpsOverlayInteractorImpl):
|
||||
SideFpsOverlayInteractor
|
||||
|
||||
companion object {
|
||||
/** Background [Executor] for HAL related operations. */
|
||||
@Provides
|
||||
|
||||
@@ -57,13 +57,8 @@ interface FingerprintPropertyRepository {
|
||||
/** The types of fingerprint sensor (rear, ultrasonic, optical, etc.). */
|
||||
val sensorType: StateFlow<FingerprintSensorType>
|
||||
|
||||
/** The primary sensor location relative to the default display. */
|
||||
val sensorLocation: StateFlow<SensorLocationInternal>
|
||||
|
||||
// TODO(b/251476085): don't implement until we need it, but expose alternative locations as
|
||||
// a map of display id -> location or similar.
|
||||
/** The sensor location relative to each physical display. */
|
||||
// val sensorLocations<Map<String, SensorLocationInternal>>
|
||||
val sensorLocations: StateFlow<Map<String, SensorLocationInternal>>
|
||||
}
|
||||
|
||||
@SysUISingleton
|
||||
@@ -104,15 +99,19 @@ constructor(
|
||||
MutableStateFlow(FingerprintSensorType.UNKNOWN)
|
||||
override val sensorType = _sensorType.asStateFlow()
|
||||
|
||||
private val _sensorLocation: MutableStateFlow<SensorLocationInternal> =
|
||||
MutableStateFlow(SensorLocationInternal.DEFAULT)
|
||||
override val sensorLocation = _sensorLocation.asStateFlow()
|
||||
private val _sensorLocations: MutableStateFlow<Map<String, SensorLocationInternal>> =
|
||||
MutableStateFlow(mapOf("" to SensorLocationInternal.DEFAULT))
|
||||
override val sensorLocations: StateFlow<Map<String, SensorLocationInternal>> =
|
||||
_sensorLocations.asStateFlow()
|
||||
|
||||
private fun setProperties(prop: FingerprintSensorPropertiesInternal) {
|
||||
_sensorId.value = prop.sensorId
|
||||
_strength.value = sensorStrengthIntToObject(prop.sensorStrength)
|
||||
_sensorType.value = sensorTypeIntToObject(prop.sensorType)
|
||||
_sensorLocation.value = prop.location
|
||||
_sensorLocations.value =
|
||||
prop.allLocations.associateBy { sensorLocationInternal ->
|
||||
sensorLocationInternal.displayId
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.biometrics.domain.interactor
|
||||
|
||||
import android.hardware.biometrics.SensorLocationInternal
|
||||
import android.util.Log
|
||||
import com.android.systemui.biometrics.data.repository.FingerprintPropertyRepository
|
||||
import com.android.systemui.dagger.SysUISingleton
|
||||
import javax.inject.Inject
|
||||
|
||||
/** Business logic for SideFps overlay offsets. */
|
||||
interface SideFpsOverlayInteractor {
|
||||
|
||||
/** Get the corresponding offsets based on different displayId. */
|
||||
fun getOverlayOffsets(displayId: String): SensorLocationInternal
|
||||
}
|
||||
|
||||
@SysUISingleton
|
||||
class SideFpsOverlayInteractorImpl
|
||||
@Inject
|
||||
constructor(private val fingerprintPropertyRepository: FingerprintPropertyRepository) :
|
||||
SideFpsOverlayInteractor {
|
||||
|
||||
override fun getOverlayOffsets(displayId: String): SensorLocationInternal {
|
||||
val offsets = fingerprintPropertyRepository.sensorLocations.value
|
||||
return if (offsets.containsKey(displayId)) {
|
||||
offsets[displayId]!!
|
||||
} else {
|
||||
Log.w(TAG, "No location specified for display: $displayId")
|
||||
offsets[""]!!
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "SideFpsOverlayInteractorImpl"
|
||||
}
|
||||
}
|
||||
@@ -102,6 +102,12 @@ class FingerprintRepositoryImplTest : SysuiTestCase() {
|
||||
540 /* sensorLocationX */,
|
||||
1636 /* sensorLocationY */,
|
||||
130 /* sensorRadius */
|
||||
),
|
||||
SensorLocationInternal(
|
||||
"display_id_1" /* displayId */,
|
||||
100 /* sensorLocationX */,
|
||||
300 /* sensorLocationY */,
|
||||
20 /* sensorRadius */
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -112,7 +118,17 @@ class FingerprintRepositoryImplTest : SysuiTestCase() {
|
||||
assertThat(repository.sensorId.value).isEqualTo(1)
|
||||
assertThat(repository.strength.value).isEqualTo(SensorStrength.STRONG)
|
||||
assertThat(repository.sensorType.value).isEqualTo(FingerprintSensorType.REAR)
|
||||
with(repository.sensorLocation.value) {
|
||||
|
||||
assertThat(repository.sensorLocations.value.size).isEqualTo(2)
|
||||
assertThat(repository.sensorLocations.value).containsKey("display_id_1")
|
||||
with(repository.sensorLocations.value["display_id_1"]!!) {
|
||||
assertThat(displayId).isEqualTo("display_id_1")
|
||||
assertThat(sensorLocationX).isEqualTo(100)
|
||||
assertThat(sensorLocationY).isEqualTo(300)
|
||||
assertThat(sensorRadius).isEqualTo(20)
|
||||
}
|
||||
assertThat(repository.sensorLocations.value).containsKey("")
|
||||
with(repository.sensorLocations.value[""]!!) {
|
||||
assertThat(displayId).isEqualTo("")
|
||||
assertThat(sensorLocationX).isEqualTo(540)
|
||||
assertThat(sensorLocationY).isEqualTo(1636)
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.biometrics.domain.interactor
|
||||
|
||||
import android.hardware.biometrics.SensorLocationInternal
|
||||
import androidx.test.filters.SmallTest
|
||||
import com.android.systemui.SysuiTestCase
|
||||
import com.android.systemui.biometrics.data.repository.FakeFingerprintPropertyRepository
|
||||
import com.android.systemui.biometrics.shared.model.FingerprintSensorType
|
||||
import com.android.systemui.biometrics.shared.model.SensorStrength
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import kotlinx.coroutines.test.StandardTestDispatcher
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.JUnit4
|
||||
import org.mockito.junit.MockitoJUnit
|
||||
|
||||
@SmallTest
|
||||
@RunWith(JUnit4::class)
|
||||
class SideFpsOverlayInteractorTest : SysuiTestCase() {
|
||||
|
||||
@JvmField @Rule var mockitoRule = MockitoJUnit.rule()
|
||||
private lateinit var testScope: TestScope
|
||||
|
||||
private val fingerprintRepository = FakeFingerprintPropertyRepository()
|
||||
|
||||
private lateinit var interactor: SideFpsOverlayInteractor
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
testScope = TestScope(StandardTestDispatcher())
|
||||
interactor = SideFpsOverlayInteractorImpl(fingerprintRepository)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetOverlayOffsets() =
|
||||
testScope.runTest {
|
||||
fingerprintRepository.setProperties(
|
||||
sensorId = 1,
|
||||
strength = SensorStrength.STRONG,
|
||||
sensorType = FingerprintSensorType.REAR,
|
||||
sensorLocations =
|
||||
mapOf(
|
||||
"" to
|
||||
SensorLocationInternal(
|
||||
"" /* displayId */,
|
||||
540 /* sensorLocationX */,
|
||||
1636 /* sensorLocationY */,
|
||||
130 /* sensorRadius */
|
||||
),
|
||||
"display_id_1" to
|
||||
SensorLocationInternal(
|
||||
"display_id_1" /* displayId */,
|
||||
100 /* sensorLocationX */,
|
||||
300 /* sensorLocationY */,
|
||||
20 /* sensorRadius */
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
var offsets = interactor.getOverlayOffsets("display_id_1")
|
||||
assertThat(offsets.displayId).isEqualTo("display_id_1")
|
||||
assertThat(offsets.sensorLocationX).isEqualTo(100)
|
||||
assertThat(offsets.sensorLocationY).isEqualTo(300)
|
||||
assertThat(offsets.sensorRadius).isEqualTo(20)
|
||||
|
||||
offsets = interactor.getOverlayOffsets("invalid_display_id")
|
||||
assertThat(offsets.displayId).isEqualTo("")
|
||||
assertThat(offsets.sensorLocationX).isEqualTo(540)
|
||||
assertThat(offsets.sensorLocationY).isEqualTo(1636)
|
||||
assertThat(offsets.sensorRadius).isEqualTo(130)
|
||||
}
|
||||
}
|
||||
@@ -39,20 +39,21 @@ class FakeFingerprintPropertyRepository : FingerprintPropertyRepository {
|
||||
MutableStateFlow(FingerprintSensorType.UNKNOWN)
|
||||
override val sensorType: StateFlow<FingerprintSensorType> = _sensorType.asStateFlow()
|
||||
|
||||
private val _sensorLocation: MutableStateFlow<SensorLocationInternal> =
|
||||
MutableStateFlow(SensorLocationInternal.DEFAULT)
|
||||
override val sensorLocation = _sensorLocation.asStateFlow()
|
||||
private val _sensorLocations: MutableStateFlow<Map<String, SensorLocationInternal>> =
|
||||
MutableStateFlow(mapOf("" to SensorLocationInternal.DEFAULT))
|
||||
override val sensorLocations: StateFlow<Map<String, SensorLocationInternal>> =
|
||||
_sensorLocations.asStateFlow()
|
||||
|
||||
fun setProperties(
|
||||
sensorId: Int,
|
||||
strength: SensorStrength,
|
||||
sensorType: FingerprintSensorType,
|
||||
sensorLocation: SensorLocationInternal
|
||||
sensorLocations: Map<String, SensorLocationInternal>
|
||||
) {
|
||||
_sensorId.value = sensorId
|
||||
_strength.value = strength
|
||||
_sensorType.value = sensorType
|
||||
_sensorLocation.value = sensorLocation
|
||||
_sensorLocations.value = sensorLocations
|
||||
_isInitialized.value = true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user