Loading packages/SystemUI/src/com/android/systemui/biometrics/BiometricDisplayListener.kt +6 −7 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ import android.content.Context import android.hardware.display.DisplayManager import android.hardware.fingerprint.FingerprintSensorPropertiesInternal import android.os.Handler import android.view.Surface import android.view.DisplayInfo import com.android.systemui.biometrics.BiometricDisplayListener.SensorType.Generic /** Loading @@ -37,7 +37,7 @@ class BiometricDisplayListener( private val onChanged: () -> Unit ) : DisplayManager.DisplayListener { private var lastRotation = Surface.ROTATION_0 private var cachedDisplayInfo = DisplayInfo() override fun onDisplayAdded(displayId: Int) {} override fun onDisplayRemoved(displayId: Int) {} Loading @@ -55,15 +55,14 @@ class BiometricDisplayListener( } private fun didRotationChange(): Boolean { val rotation = context.display?.rotation ?: return false val last = lastRotation lastRotation = rotation return last != rotation val last = cachedDisplayInfo.rotation context.display?.getDisplayInfo(cachedDisplayInfo) return last != cachedDisplayInfo.rotation } /** Listen for changes. */ fun enable() { lastRotation = context.display?.rotation ?: Surface.ROTATION_0 context.display?.getDisplayInfo(cachedDisplayInfo) displayManager.registerDisplayListener( this, handler, Loading packages/SystemUI/tests/src/com/android/systemui/biometrics/BiometricDisplayListenerTest.java +0 −73 Original line number Diff line number Diff line Loading @@ -22,8 +22,6 @@ import static com.android.systemui.biometrics.BiometricDisplayListener.SensorTyp import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; 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.times; import static org.mockito.Mockito.verify; Loading @@ -36,7 +34,6 @@ import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import android.view.Display; import android.view.Surface; import android.view.Surface.Rotation; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; Loading Loading @@ -106,76 +103,6 @@ public class BiometricDisplayListenerTest extends SysuiTestCase { 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 public void callsOnChanged_forSideFingerprint_whenAnythingDisplayChanges() { // Any rotation will do for this test, we just need to return something. Loading Loading
packages/SystemUI/src/com/android/systemui/biometrics/BiometricDisplayListener.kt +6 −7 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ import android.content.Context import android.hardware.display.DisplayManager import android.hardware.fingerprint.FingerprintSensorPropertiesInternal import android.os.Handler import android.view.Surface import android.view.DisplayInfo import com.android.systemui.biometrics.BiometricDisplayListener.SensorType.Generic /** Loading @@ -37,7 +37,7 @@ class BiometricDisplayListener( private val onChanged: () -> Unit ) : DisplayManager.DisplayListener { private var lastRotation = Surface.ROTATION_0 private var cachedDisplayInfo = DisplayInfo() override fun onDisplayAdded(displayId: Int) {} override fun onDisplayRemoved(displayId: Int) {} Loading @@ -55,15 +55,14 @@ class BiometricDisplayListener( } private fun didRotationChange(): Boolean { val rotation = context.display?.rotation ?: return false val last = lastRotation lastRotation = rotation return last != rotation val last = cachedDisplayInfo.rotation context.display?.getDisplayInfo(cachedDisplayInfo) return last != cachedDisplayInfo.rotation } /** Listen for changes. */ fun enable() { lastRotation = context.display?.rotation ?: Surface.ROTATION_0 context.display?.getDisplayInfo(cachedDisplayInfo) displayManager.registerDisplayListener( this, handler, Loading
packages/SystemUI/tests/src/com/android/systemui/biometrics/BiometricDisplayListenerTest.java +0 −73 Original line number Diff line number Diff line Loading @@ -22,8 +22,6 @@ import static com.android.systemui.biometrics.BiometricDisplayListener.SensorTyp import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; 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.times; import static org.mockito.Mockito.verify; Loading @@ -36,7 +34,6 @@ import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import android.view.Display; import android.view.Surface; import android.view.Surface.Rotation; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; Loading Loading @@ -106,76 +103,6 @@ public class BiometricDisplayListenerTest extends SysuiTestCase { 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 public void callsOnChanged_forSideFingerprint_whenAnythingDisplayChanges() { // Any rotation will do for this test, we just need to return something. Loading