Merge "Fix 180 rotations during enrollment" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
1fb6cab2cf
@@ -20,7 +20,7 @@ import android.content.Context
|
|||||||
import android.hardware.display.DisplayManager
|
import android.hardware.display.DisplayManager
|
||||||
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal
|
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.view.Surface
|
import android.view.DisplayInfo
|
||||||
import com.android.systemui.biometrics.BiometricDisplayListener.SensorType.Generic
|
import com.android.systemui.biometrics.BiometricDisplayListener.SensorType.Generic
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,7 +37,7 @@ class BiometricDisplayListener(
|
|||||||
private val onChanged: () -> Unit
|
private val onChanged: () -> Unit
|
||||||
) : DisplayManager.DisplayListener {
|
) : DisplayManager.DisplayListener {
|
||||||
|
|
||||||
private var lastRotation = Surface.ROTATION_0
|
private var cachedDisplayInfo = DisplayInfo()
|
||||||
|
|
||||||
override fun onDisplayAdded(displayId: Int) {}
|
override fun onDisplayAdded(displayId: Int) {}
|
||||||
override fun onDisplayRemoved(displayId: Int) {}
|
override fun onDisplayRemoved(displayId: Int) {}
|
||||||
@@ -55,15 +55,14 @@ class BiometricDisplayListener(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun didRotationChange(): Boolean {
|
private fun didRotationChange(): Boolean {
|
||||||
val rotation = context.display?.rotation ?: return false
|
val last = cachedDisplayInfo.rotation
|
||||||
val last = lastRotation
|
context.display?.getDisplayInfo(cachedDisplayInfo)
|
||||||
lastRotation = rotation
|
return last != cachedDisplayInfo.rotation
|
||||||
return last != rotation
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Listen for changes. */
|
/** Listen for changes. */
|
||||||
fun enable() {
|
fun enable() {
|
||||||
lastRotation = context.display?.rotation ?: Surface.ROTATION_0
|
context.display?.getDisplayInfo(cachedDisplayInfo)
|
||||||
displayManager.registerDisplayListener(
|
displayManager.registerDisplayListener(
|
||||||
this,
|
this,
|
||||||
handler,
|
handler,
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ import static com.android.systemui.biometrics.BiometricDisplayListener.SensorTyp
|
|||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.ArgumentMatchers.same;
|
import static org.mockito.ArgumentMatchers.same;
|
||||||
import static org.mockito.Mockito.never;
|
|
||||||
import static org.mockito.Mockito.reset;
|
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@@ -36,7 +34,6 @@ import android.testing.TestableLooper;
|
|||||||
import android.testing.TestableLooper.RunWithLooper;
|
import android.testing.TestableLooper.RunWithLooper;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import android.view.Surface.Rotation;
|
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
@@ -106,76 +103,6 @@ public class BiometricDisplayListenerTest extends SysuiTestCase {
|
|||||||
verify(mDisplayManager).unregisterDisplayListener(any());
|
verify(mDisplayManager).unregisterDisplayListener(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void detectsRotationChanges_forUdfps_relativeToRotationWhenEnabled() {
|
|
||||||
// Create a listener when the rotation is portrait.
|
|
||||||
when(mDisplay.getRotation()).thenReturn(Surface.ROTATION_0);
|
|
||||||
BiometricDisplayListener listener = new BiometricDisplayListener(
|
|
||||||
mContextSpy, mDisplayManager, mHandler, mUdfpsType, mOnChangedCallback);
|
|
||||||
|
|
||||||
// Rotate the device to landscape and then enable the listener.
|
|
||||||
when(mDisplay.getRotation()).thenReturn(Surface.ROTATION_90);
|
|
||||||
listener.enable();
|
|
||||||
verify(mDisplayManager).registerDisplayListener(mDisplayListenerCaptor.capture(),
|
|
||||||
same(mHandler), eq(DisplayManager.EVENT_FLAG_DISPLAY_CHANGED));
|
|
||||||
|
|
||||||
// Rotate the device back to portrait and ensure the rotation is detected.
|
|
||||||
when(mDisplay.getRotation()).thenReturn(Surface.ROTATION_0);
|
|
||||||
mDisplayListenerCaptor.getValue().onDisplayChanged(999);
|
|
||||||
verify(mOnChangedCallback).invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void callsOnChanged_forUdfps_onlyWhenRotationChanges() {
|
|
||||||
final @Rotation int[] rotations =
|
|
||||||
new int[]{
|
|
||||||
Surface.ROTATION_0,
|
|
||||||
Surface.ROTATION_90,
|
|
||||||
Surface.ROTATION_180,
|
|
||||||
Surface.ROTATION_270
|
|
||||||
};
|
|
||||||
|
|
||||||
for (@Rotation int rot1 : rotations) {
|
|
||||||
for (@Rotation int rot2 : rotations) {
|
|
||||||
// Make the third rotation the same as the first one to simplify this test.
|
|
||||||
@Rotation int rot3 = rot1;
|
|
||||||
|
|
||||||
// Clean up prior interactions.
|
|
||||||
reset(mDisplayManager);
|
|
||||||
reset(mDisplay);
|
|
||||||
reset(mOnChangedCallback);
|
|
||||||
|
|
||||||
// Set up the mock for 3 invocations.
|
|
||||||
when(mDisplay.getRotation()).thenReturn(rot1, rot2, rot3);
|
|
||||||
|
|
||||||
BiometricDisplayListener listener = new BiometricDisplayListener(
|
|
||||||
mContextSpy, mDisplayManager, mHandler, mUdfpsType, mOnChangedCallback);
|
|
||||||
listener.enable();
|
|
||||||
|
|
||||||
// The listener should record the current rotation and register a display listener.
|
|
||||||
verify(mDisplay).getRotation();
|
|
||||||
verify(mDisplayManager).registerDisplayListener(mDisplayListenerCaptor.capture(),
|
|
||||||
same(mHandler), eq(DisplayManager.EVENT_FLAG_DISPLAY_CHANGED));
|
|
||||||
|
|
||||||
// Test the first rotation since the listener was enabled.
|
|
||||||
mDisplayListenerCaptor.getValue().onDisplayChanged(123);
|
|
||||||
if (rot2 != rot1) {
|
|
||||||
verify(mOnChangedCallback).invoke();
|
|
||||||
} else {
|
|
||||||
verify(mOnChangedCallback, never()).invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test continued rotations.
|
|
||||||
mDisplayListenerCaptor.getValue().onDisplayChanged(123);
|
|
||||||
if (rot3 != rot2) {
|
|
||||||
verify(mOnChangedCallback, times(2)).invoke();
|
|
||||||
} else {
|
|
||||||
verify(mOnChangedCallback, never()).invoke();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void callsOnChanged_forSideFingerprint_whenAnythingDisplayChanges() {
|
public void callsOnChanged_forSideFingerprint_whenAnythingDisplayChanges() {
|
||||||
// Any rotation will do for this test, we just need to return something.
|
// Any rotation will do for this test, we just need to return something.
|
||||||
|
|||||||
Reference in New Issue
Block a user