Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 06e6eeb0 authored by Beverly's avatar Beverly Committed by Beverly Tai
Browse files

Update orientation on rotation changes

The rotation can change without the phyiscal
orientation of the phone changing.

Test: manual, atest UdfpsControllerTest AuthControllerTest
SidefpsControllerTest
Fixes: 193975552

Change-Id: I621ea06984f17954e9be138e9e5669aeb3cfb3fe
parent 72922c8a
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -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, () -> {
        mOrientationListener = new BiometricOrientationEventListener(context,
                () -> {
                    onOrientationChanged();
                    return Unit.INSTANCE;
        });
                },
                displayManager,
                handler);

        mFaceProps = mFaceManager != null ? mFaceManager.getSensorPropertiesInternal() : null;

+15 −18
Original line number Diff line number Diff line
@@ -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)
    }
}
+13 −5
Original line number Diff line number Diff line
@@ -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, () -> {
        mOrientationListener = new BiometricOrientationEventListener(
                context,
                () -> {
                    onOrientationChanged();
                    return Unit.INSTANCE;
        });
                },
                displayManager,
                handler);

        mSensorProps = findFirstSidefps();
        checkArgument(mSensorProps != null);
+16 −7
Original line number Diff line number Diff line
@@ -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, () -> {
        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
+10 −7
Original line number Diff line number Diff line
@@ -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
Loading