Merge "Update orientation on rotation changes" into sc-dev
This commit is contained in:
@@ -37,6 +37,7 @@ import android.hardware.biometrics.BiometricManager.BiometricMultiSensorMode;
|
||||
import android.hardware.biometrics.BiometricPrompt;
|
||||
import android.hardware.biometrics.IBiometricSysuiReceiver;
|
||||
import android.hardware.biometrics.PromptInfo;
|
||||
import android.hardware.display.DisplayManager;
|
||||
import android.hardware.face.FaceManager;
|
||||
import android.hardware.face.FaceSensorPropertiesInternal;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
@@ -57,6 +58,7 @@ import com.android.internal.os.SomeArgs;
|
||||
import com.android.systemui.SystemUI;
|
||||
import com.android.systemui.assist.ui.DisplayUtils;
|
||||
import com.android.systemui.dagger.SysUISingleton;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.doze.DozeReceiver;
|
||||
import com.android.systemui.statusbar.CommandQueue;
|
||||
|
||||
@@ -423,7 +425,9 @@ public class AuthController extends SystemUI implements CommandQueue.Callbacks,
|
||||
@Nullable FingerprintManager fingerprintManager,
|
||||
@Nullable FaceManager faceManager,
|
||||
Provider<UdfpsController> udfpsControllerFactory,
|
||||
Provider<SidefpsController> sidefpsControllerFactory) {
|
||||
Provider<SidefpsController> sidefpsControllerFactory,
|
||||
@NonNull DisplayManager displayManager,
|
||||
@Main Handler handler) {
|
||||
super(context);
|
||||
mCommandQueue = commandQueue;
|
||||
mActivityTaskManager = activityTaskManager;
|
||||
@@ -432,10 +436,13 @@ public class AuthController extends SystemUI implements CommandQueue.Callbacks,
|
||||
mUdfpsControllerFactory = udfpsControllerFactory;
|
||||
mSidefpsControllerFactory = sidefpsControllerFactory;
|
||||
mWindowManager = windowManager;
|
||||
mOrientationListener = new BiometricOrientationEventListener(context, () -> {
|
||||
onOrientationChanged();
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
mOrientationListener = new BiometricOrientationEventListener(context,
|
||||
() -> {
|
||||
onOrientationChanged();
|
||||
return Unit.INSTANCE;
|
||||
},
|
||||
displayManager,
|
||||
handler);
|
||||
|
||||
mFaceProps = mFaceManager != null ? mFaceManager.getSensorPropertiesInternal() : null;
|
||||
|
||||
|
||||
@@ -17,7 +17,10 @@
|
||||
package com.android.systemui.biometrics
|
||||
|
||||
import android.content.Context
|
||||
import android.hardware.display.DisplayManager
|
||||
import android.os.Handler
|
||||
import android.view.OrientationEventListener
|
||||
import android.view.Surface
|
||||
|
||||
/**
|
||||
* An [OrientationEventListener] that invokes the [onOrientationChanged] callback whenever
|
||||
@@ -26,20 +29,16 @@ import android.view.OrientationEventListener
|
||||
*/
|
||||
class BiometricOrientationEventListener(
|
||||
private val context: Context,
|
||||
private val onOrientationChanged: () -> Unit
|
||||
) : OrientationEventListener(context) {
|
||||
private val onOrientationChanged: () -> Unit,
|
||||
private val displayManager: DisplayManager,
|
||||
private val handler: Handler
|
||||
) : DisplayManager.DisplayListener {
|
||||
|
||||
/** If actively listening (not available in base class). */
|
||||
var enabled: Boolean = false
|
||||
private set
|
||||
|
||||
private var lastRotation = context.display?.rotation ?: ORIENTATION_UNKNOWN
|
||||
|
||||
override fun onOrientationChanged(orientation: Int) {
|
||||
if (orientation == ORIENTATION_UNKNOWN) {
|
||||
return
|
||||
}
|
||||
private var lastRotation = context.display?.rotation ?: Surface.ROTATION_0
|
||||
|
||||
override fun onDisplayAdded(displayId: Int) {}
|
||||
override fun onDisplayRemoved(displayId: Int) {}
|
||||
override fun onDisplayChanged(displayId: Int) {
|
||||
val rotation = context.display?.rotation ?: return
|
||||
if (lastRotation != rotation) {
|
||||
lastRotation = rotation
|
||||
@@ -48,13 +47,11 @@ class BiometricOrientationEventListener(
|
||||
}
|
||||
}
|
||||
|
||||
override fun enable() {
|
||||
enabled = true
|
||||
super.enable()
|
||||
fun enable() {
|
||||
displayManager.registerDisplayListener(this, handler)
|
||||
}
|
||||
|
||||
override fun disable() {
|
||||
enabled = false
|
||||
super.disable()
|
||||
fun disable() {
|
||||
displayManager.unregisterDisplayListener(this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,11 @@ import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.hardware.display.DisplayManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
|
||||
import android.hardware.fingerprint.ISidefpsController;
|
||||
import android.os.Handler;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
@@ -93,16 +95,22 @@ public class SidefpsController {
|
||||
@NonNull LayoutInflater inflater,
|
||||
@Nullable FingerprintManager fingerprintManager,
|
||||
@NonNull WindowManager windowManager,
|
||||
@Main DelayableExecutor fgExecutor) {
|
||||
@Main DelayableExecutor fgExecutor,
|
||||
@NonNull DisplayManager displayManager,
|
||||
@Main Handler handler) {
|
||||
mContext = context;
|
||||
mInflater = inflater;
|
||||
mFingerprintManager = checkNotNull(fingerprintManager);
|
||||
mWindowManager = windowManager;
|
||||
mFgExecutor = fgExecutor;
|
||||
mOrientationListener = new BiometricOrientationEventListener(context, () -> {
|
||||
onOrientationChanged();
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
mOrientationListener = new BiometricOrientationEventListener(
|
||||
context,
|
||||
() -> {
|
||||
onOrientationChanged();
|
||||
return Unit.INSTANCE;
|
||||
},
|
||||
displayManager,
|
||||
handler);
|
||||
|
||||
mSensorProps = findFirstSidefps();
|
||||
checkArgument(mSensorProps != null);
|
||||
|
||||
@@ -32,6 +32,7 @@ import android.content.IntentFilter;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.RectF;
|
||||
import android.hardware.display.DisplayManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
|
||||
import android.hardware.fingerprint.IUdfpsOverlayController;
|
||||
@@ -519,7 +520,9 @@ public class UdfpsController implements DozeReceiver {
|
||||
@NonNull UdfpsHapticsSimulator udfpsHapticsSimulator,
|
||||
@NonNull Optional<UdfpsHbmProvider> hbmProvider,
|
||||
@NonNull KeyguardStateController keyguardStateController,
|
||||
@NonNull KeyguardBypassController keyguardBypassController) {
|
||||
@NonNull KeyguardBypassController keyguardBypassController,
|
||||
@NonNull DisplayManager displayManager,
|
||||
@Main Handler mainHandler) {
|
||||
mContext = context;
|
||||
mExecution = execution;
|
||||
// TODO (b/185124905): inject main handler and vibrator once done prototyping
|
||||
@@ -545,10 +548,14 @@ public class UdfpsController implements DozeReceiver {
|
||||
mHbmProvider = hbmProvider.orElse(null);
|
||||
screenLifecycle.addObserver(mScreenObserver);
|
||||
mScreenOn = screenLifecycle.getScreenState() == ScreenLifecycle.SCREEN_ON;
|
||||
mOrientationListener = new BiometricOrientationEventListener(context, () -> {
|
||||
onOrientationChanged();
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
mOrientationListener = new BiometricOrientationEventListener(
|
||||
context,
|
||||
() -> {
|
||||
onOrientationChanged();
|
||||
return Unit.INSTANCE;
|
||||
},
|
||||
displayManager,
|
||||
mainHandler);
|
||||
mKeyguardBypassController = keyguardBypassController;
|
||||
|
||||
mSensorProps = findFirstUdfps();
|
||||
@@ -662,7 +669,8 @@ public class UdfpsController implements DozeReceiver {
|
||||
// Transform dimensions if the device is in landscape mode
|
||||
switch (mContext.getDisplay().getRotation()) {
|
||||
case Surface.ROTATION_90:
|
||||
if (animation instanceof UdfpsKeyguardViewController) {
|
||||
if (animation instanceof UdfpsKeyguardViewController
|
||||
&& mKeyguardUpdateMonitor.isGoingToSleep()) {
|
||||
break;
|
||||
}
|
||||
mCoreLayoutParams.x = mSensorProps.sensorLocationY - mSensorProps.sensorRadius
|
||||
@@ -672,7 +680,8 @@ public class UdfpsController implements DozeReceiver {
|
||||
break;
|
||||
|
||||
case Surface.ROTATION_270:
|
||||
if (animation instanceof UdfpsKeyguardViewController) {
|
||||
if (animation instanceof UdfpsKeyguardViewController
|
||||
&& mKeyguardUpdateMonitor.isGoingToSleep()) {
|
||||
break;
|
||||
}
|
||||
mCoreLayoutParams.x = p.x - mSensorProps.sensorLocationY - mSensorProps.sensorRadius
|
||||
|
||||
@@ -20,9 +20,7 @@ import static android.hardware.biometrics.BiometricManager.Authenticators;
|
||||
import static android.hardware.biometrics.BiometricManager.BIOMETRIC_MULTI_SENSOR_FACE_THEN_FINGERPRINT;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
@@ -50,12 +48,14 @@ import android.hardware.biometrics.ComponentInfoInternal;
|
||||
import android.hardware.biometrics.IBiometricSysuiReceiver;
|
||||
import android.hardware.biometrics.PromptInfo;
|
||||
import android.hardware.biometrics.SensorProperties;
|
||||
import android.hardware.display.DisplayManager;
|
||||
import android.hardware.face.FaceManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.hardware.fingerprint.FingerprintSensorProperties;
|
||||
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
|
||||
import android.hardware.fingerprint.IFingerprintAuthenticatorsRegisteredCallback;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.RemoteException;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableContext;
|
||||
@@ -110,6 +110,10 @@ public class AuthControllerTest extends SysuiTestCase {
|
||||
private UdfpsController mUdfpsController;
|
||||
@Mock
|
||||
private SidefpsController mSidefpsController;
|
||||
@Mock
|
||||
private DisplayManager mDisplayManager;
|
||||
@Mock
|
||||
private Handler mHandler;
|
||||
@Captor
|
||||
ArgumentCaptor<IFingerprintAuthenticatorsRegisteredCallback> mAuthenticatorsRegisteredCaptor;
|
||||
|
||||
@@ -544,13 +548,12 @@ public class AuthControllerTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void testSubscribesToOrientationChangesWhenShowingDialog() {
|
||||
assertFalse(mAuthController.mOrientationListener.getEnabled());
|
||||
|
||||
showDialog(new int[]{1} /* sensorIds */, false /* credentialAllowed */);
|
||||
assertTrue(mAuthController.mOrientationListener.getEnabled());
|
||||
|
||||
verify(mDisplayManager).registerDisplayListener(any(), eq(mHandler));
|
||||
|
||||
mAuthController.hideAuthenticationDialog();
|
||||
assertFalse(mAuthController.mOrientationListener.getEnabled());
|
||||
verify(mDisplayManager).unregisterDisplayListener(any());
|
||||
}
|
||||
|
||||
// Helpers
|
||||
@@ -603,7 +606,7 @@ public class AuthControllerTest extends SysuiTestCase {
|
||||
Provider<SidefpsController> sidefpsControllerFactory) {
|
||||
super(context, commandQueue, activityTaskManager, windowManager,
|
||||
fingerprintManager, faceManager, udfpsControllerFactory,
|
||||
sidefpsControllerFactory);
|
||||
sidefpsControllerFactory, mDisplayManager, mHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,11 +17,13 @@
|
||||
package com.android.systemui.biometrics
|
||||
|
||||
import android.hardware.biometrics.SensorProperties
|
||||
import android.hardware.display.DisplayManager
|
||||
import android.hardware.display.DisplayManagerGlobal
|
||||
import android.hardware.fingerprint.FingerprintManager
|
||||
import android.hardware.fingerprint.FingerprintSensorProperties
|
||||
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal
|
||||
import android.hardware.fingerprint.ISidefpsController
|
||||
import android.os.Handler
|
||||
import android.testing.AndroidTestingRunner
|
||||
import android.testing.TestableLooper
|
||||
import android.view.Display
|
||||
@@ -34,14 +36,15 @@ import com.android.systemui.R
|
||||
import com.android.systemui.SysuiTestCase
|
||||
import com.android.systemui.util.concurrency.FakeExecutor
|
||||
import com.android.systemui.util.time.FakeSystemClock
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentCaptor
|
||||
import org.mockito.ArgumentMatchers.eq
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.Mockito.any
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.junit.MockitoJUnit
|
||||
|
||||
@@ -64,6 +67,10 @@ class SidefpsControllerTest : SysuiTestCase() {
|
||||
lateinit var windowManager: WindowManager
|
||||
@Mock
|
||||
lateinit var sidefpsView: SidefpsView
|
||||
@Mock
|
||||
lateinit var displayManager: DisplayManager
|
||||
@Mock
|
||||
lateinit var handler: Handler
|
||||
|
||||
private val executor = FakeExecutor(FakeSystemClock())
|
||||
private lateinit var overlayController: ISidefpsController
|
||||
@@ -94,7 +101,8 @@ class SidefpsControllerTest : SysuiTestCase() {
|
||||
)
|
||||
|
||||
sideFpsController = SidefpsController(
|
||||
mContext, layoutInflater, fingerprintManager, windowManager, executor
|
||||
mContext, layoutInflater, fingerprintManager, windowManager, executor,
|
||||
displayManager, handler
|
||||
)
|
||||
|
||||
overlayController = ArgumentCaptor.forClass(ISidefpsController::class.java).apply {
|
||||
@@ -104,14 +112,13 @@ class SidefpsControllerTest : SysuiTestCase() {
|
||||
|
||||
@Test
|
||||
fun testSubscribesToOrientationChangesWhenShowingOverlay() {
|
||||
assertThat(sideFpsController.mOrientationListener.enabled).isFalse()
|
||||
|
||||
overlayController.show()
|
||||
executor.runAllReady()
|
||||
assertThat(sideFpsController.mOrientationListener.enabled).isTrue()
|
||||
|
||||
verify(displayManager).registerDisplayListener(any(), eq(handler))
|
||||
|
||||
overlayController.hide()
|
||||
executor.runAllReady()
|
||||
assertThat(sideFpsController.mOrientationListener.enabled).isFalse()
|
||||
verify(displayManager).unregisterDisplayListener(any())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
package com.android.systemui.biometrics;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
@@ -33,11 +31,13 @@ import static org.mockito.Mockito.when;
|
||||
import android.content.res.TypedArray;
|
||||
import android.hardware.biometrics.ComponentInfoInternal;
|
||||
import android.hardware.biometrics.SensorProperties;
|
||||
import android.hardware.display.DisplayManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.hardware.fingerprint.FingerprintSensorProperties;
|
||||
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
|
||||
import android.hardware.fingerprint.IUdfpsOverlayController;
|
||||
import android.hardware.fingerprint.IUdfpsOverlayControllerCallback;
|
||||
import android.os.Handler;
|
||||
import android.os.PowerManager;
|
||||
import android.os.RemoteException;
|
||||
import android.os.Vibrator;
|
||||
@@ -139,6 +139,10 @@ public class UdfpsControllerTest extends SysuiTestCase {
|
||||
private KeyguardStateController mKeyguardStateController;
|
||||
@Mock
|
||||
private KeyguardBypassController mKeyguardBypassController;
|
||||
@Mock
|
||||
private DisplayManager mDisplayManager;
|
||||
@Mock
|
||||
private Handler mHandler;
|
||||
|
||||
private FakeExecutor mFgExecutor;
|
||||
|
||||
@@ -208,7 +212,9 @@ public class UdfpsControllerTest extends SysuiTestCase {
|
||||
mUdfpsHapticsSimulator,
|
||||
Optional.of(mHbmProvider),
|
||||
mKeyguardStateController,
|
||||
mKeyguardBypassController);
|
||||
mKeyguardBypassController,
|
||||
mDisplayManager,
|
||||
mHandler);
|
||||
verify(mFingerprintManager).setUdfpsOverlayController(mOverlayCaptor.capture());
|
||||
mOverlayController = mOverlayCaptor.getValue();
|
||||
verify(mScreenLifecycle).addObserver(mScreenObserverCaptor.capture());
|
||||
@@ -324,18 +330,16 @@ public class UdfpsControllerTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void testSubscribesToOrientationChangesWhenShowingOverlay() throws Exception {
|
||||
assertFalse(mUdfpsController.mOrientationListener.getEnabled());
|
||||
|
||||
mOverlayController.showUdfpsOverlay(TEST_UDFPS_SENSOR_ID,
|
||||
IUdfpsOverlayController.REASON_AUTH_FPM_KEYGUARD, mUdfpsOverlayControllerCallback);
|
||||
mFgExecutor.runAllReady();
|
||||
|
||||
assertTrue(mUdfpsController.mOrientationListener.getEnabled());
|
||||
verify(mDisplayManager).registerDisplayListener(any(), eq(mHandler));
|
||||
|
||||
mOverlayController.hideUdfpsOverlay(TEST_UDFPS_SENSOR_ID);
|
||||
mFgExecutor.runAllReady();
|
||||
|
||||
assertFalse(mUdfpsController.mOrientationListener.getEnabled());
|
||||
verify(mDisplayManager).unregisterDisplayListener(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user