Do not show side fingerprint sensor overlay on keyguard.

Bug: 197265282
Test: atest SidefpsControllerTest
Test: manual (lock device and verify no overlay on keyguard)
Change-Id: I7ff487e3d15d68ea1b182c6c7e7fd255801e4dea
This commit is contained in:
Joe Bolinger
2021-09-15 12:17:17 -07:00
parent f2e41730bb
commit b13dc6a105
6 changed files with 41 additions and 17 deletions

View File

@@ -21,9 +21,9 @@ package android.hardware.fingerprint;
*/
oneway interface ISidefpsController {
// Shows the overlay.
void show();
// Shows the overlay for the given sensor with a reason from BiometricOverlayConstants.
void show(int sensorId, int reason);
// Hides the overlay.
void hide();
void hide(int sensorId);
}

View File

@@ -22,7 +22,7 @@ import android.hardware.fingerprint.IUdfpsOverlayControllerCallback;
* @hide
*/
oneway interface IUdfpsOverlayController {
// Shows the overlay.
// Shows the overlay for the given sensor with a reason from BiometricOverlayConstants.
void showUdfpsOverlay(int sensorId, int reason, IUdfpsOverlayControllerCallback callback);
// Hides the overlay.

View File

@@ -18,6 +18,8 @@ package com.android.systemui.biometrics
import android.content.Context
import android.graphics.PixelFormat
import android.graphics.Rect
import android.hardware.biometrics.BiometricOverlayConstants
import android.hardware.biometrics.BiometricOverlayConstants.REASON_AUTH_KEYGUARD
import android.hardware.display.DisplayManager
import android.hardware.fingerprint.FingerprintManager
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal
@@ -100,14 +102,20 @@ class SidefpsController @Inject constructor(
init {
fingerprintManager?.setSidefpsController(object : ISidefpsController.Stub() {
override fun show() = mainExecutor.execute {
override fun show(
sensorId: Int,
@BiometricOverlayConstants.ShowReason reason: Int
) = if (reason.isReasonToShow()) doShow() else hide(sensorId)
private fun doShow() = mainExecutor.execute {
if (overlayView == null) {
overlayView = createOverlayForDisplay()
} else {
Log.v(TAG, "overlay already shown")
}
}
override fun hide() = mainExecutor.execute { overlayView = null }
override fun hide(sensorId: Int) = mainExecutor.execute { overlayView = null }
})
}
@@ -165,6 +173,12 @@ class SidefpsController @Inject constructor(
}
}
@BiometricOverlayConstants.ShowReason
private fun Int.isReasonToShow(): Boolean = when (this) {
REASON_AUTH_KEYGUARD -> false
else -> true
}
@RawRes
private fun Display.asSideFpsAnimation(): Int = when (rotation) {
Surface.ROTATION_0 -> R.raw.sfps_pulse

View File

@@ -17,6 +17,8 @@
package com.android.systemui.biometrics
import android.graphics.Rect
import android.hardware.biometrics.BiometricOverlayConstants.REASON_AUTH_KEYGUARD
import android.hardware.biometrics.BiometricOverlayConstants.REASON_UNKNOWN
import android.hardware.biometrics.SensorProperties
import android.hardware.display.DisplayManager
import android.hardware.display.DisplayManagerGlobal
@@ -128,25 +130,25 @@ class SidefpsControllerTest : SysuiTestCase() {
@Test
fun testSubscribesToOrientationChangesWhenShowingOverlay() {
overlayController.show()
overlayController.show(SENSOR_ID, REASON_UNKNOWN)
executor.runAllReady()
verify(displayManager).registerDisplayListener(any(), eq(handler))
overlayController.hide()
overlayController.hide(SENSOR_ID)
executor.runAllReady()
verify(displayManager).unregisterDisplayListener(any())
}
@Test
fun testShowsAndHides() {
overlayController.show()
overlayController.show(SENSOR_ID, REASON_UNKNOWN)
executor.runAllReady()
verify(windowManager).addView(overlayCaptor.capture(), any())
reset(windowManager)
overlayController.hide()
overlayController.hide(SENSOR_ID)
executor.runAllReady()
verify(windowManager, never()).addView(any(), any())
@@ -156,7 +158,7 @@ class SidefpsControllerTest : SysuiTestCase() {
@Test
fun testShowsOnce() {
repeat(5) {
overlayController.show()
overlayController.show(SENSOR_ID, REASON_UNKNOWN)
executor.runAllReady()
}
@@ -166,15 +168,23 @@ class SidefpsControllerTest : SysuiTestCase() {
@Test
fun testHidesOnce() {
overlayController.show()
overlayController.show(SENSOR_ID, REASON_UNKNOWN)
executor.runAllReady()
repeat(5) {
overlayController.hide()
overlayController.hide(SENSOR_ID)
executor.runAllReady()
}
verify(windowManager).addView(any(), any())
verify(windowManager).removeView(any())
}
@Test
fun testIgnoredForKeyguard() {
overlayController.show(SENSOR_ID, REASON_AUTH_KEYGUARD)
executor.runAllReady()
verify(windowManager, never()).addView(any(), any())
}
}

View File

@@ -68,7 +68,7 @@ public final class SensorOverlays {
@NonNull AcquisitionClient<?> client) {
if (mSidefpsController.isPresent()) {
try {
mSidefpsController.get().show();
mSidefpsController.get().show(sensorId, reason);
} catch (RemoteException e) {
Slog.e(TAG, "Remote exception when showing the side-fps overlay", e);
}
@@ -99,7 +99,7 @@ public final class SensorOverlays {
public void hide(int sensorId) {
if (mSidefpsController.isPresent()) {
try {
mSidefpsController.get().hide();
mSidefpsController.get().hide(sensorId);
} catch (RemoteException e) {
Slog.e(TAG, "Remote exception when hiding the side-fps overlay", e);
}

View File

@@ -95,7 +95,7 @@ public class SensorOverlaysTest {
verify(mUdfpsOverlayController).showUdfpsOverlay(eq(SENSOR_ID), eq(reason), any());
}
if (sidefps != null) {
verify(mSidefpsController).show();
verify(mSidefpsController).show(eq(SENSOR_ID), eq(reason));
}
}
@@ -123,7 +123,7 @@ public class SensorOverlaysTest {
verify(mUdfpsOverlayController).hideUdfpsOverlay(eq(SENSOR_ID));
}
if (sidefps != null) {
verify(mSidefpsController).hide();
verify(mSidefpsController).hide(eq(SENSOR_ID));
}
}
}