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

Commit 559244bd authored by Ilya Matyukhin's avatar Ilya Matyukhin Committed by Android (Google) Code Review
Browse files

Merge "Enable RRS (FHD<->QHD) support for UDFPS" into tm-dev

parents bd72a95c 84438ca2
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.hardware.biometrics;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.Rect;
import android.os.Parcel;
import android.os.Parcelable;

@@ -109,4 +110,12 @@ public class SensorLocationInternal implements Parcelable {
                + ", y: " + sensorLocationY
                + ", r: " + sensorRadius + "]";
    }

    /** Returns coordinates of a bounding box around the sensor. */
    public Rect getRect() {
        return new Rect(sensorLocationX - sensorRadius,
                sensorLocationY - sensorRadius,
                sensorLocationX + sensorRadius,
                sensorLocationY + sensorRadius);
    }
}
+25 −13
Original line number Diff line number Diff line
@@ -88,14 +88,14 @@ public class RotationUtils {
    }

    /**
     * Rotates bounds as if parentBounds and bounds are a group. The group is rotated by `delta`
     * 90-degree counter-clockwise increments. This assumes that parentBounds is at 0,0 and
     * remains at 0,0 after rotation. The bounds will be at the same physical position in
     * parentBounds.
     * Rotates inOutBounds together with the parent for a given rotation delta. This assumes that
     * the parent starts at 0,0 and remains at 0,0 after the rotation. The inOutBounds will remain
     * at the same physical position within the parent.
     *
     * Only 'inOutBounds' is mutated.
     */
    public static void rotateBounds(Rect inOutBounds, Rect parentBounds, @Rotation int rotation) {
    public static void rotateBounds(Rect inOutBounds, int parentWidth, int parentHeight,
            @Rotation int rotation) {
        final int origLeft = inOutBounds.left;
        final int origTop = inOutBounds.top;
        switch (rotation) {
@@ -103,24 +103,36 @@ public class RotationUtils {
                return;
            case ROTATION_90:
                inOutBounds.left = inOutBounds.top;
                inOutBounds.top = parentBounds.right - inOutBounds.right;
                inOutBounds.top = parentWidth - inOutBounds.right;
                inOutBounds.right = inOutBounds.bottom;
                inOutBounds.bottom = parentBounds.right - origLeft;
                inOutBounds.bottom = parentWidth - origLeft;
                return;
            case ROTATION_180:
                inOutBounds.left = parentBounds.right - inOutBounds.right;
                inOutBounds.right = parentBounds.right - origLeft;
                inOutBounds.top = parentBounds.bottom - inOutBounds.bottom;
                inOutBounds.bottom = parentBounds.bottom - origTop;
                inOutBounds.left = parentWidth - inOutBounds.right;
                inOutBounds.right = parentWidth - origLeft;
                inOutBounds.top = parentHeight - inOutBounds.bottom;
                inOutBounds.bottom = parentHeight - origTop;
                return;
            case ROTATION_270:
                inOutBounds.left = parentBounds.bottom - inOutBounds.bottom;
                inOutBounds.left = parentHeight - inOutBounds.bottom;
                inOutBounds.bottom = inOutBounds.right;
                inOutBounds.right = parentBounds.bottom - inOutBounds.top;
                inOutBounds.right = parentHeight - inOutBounds.top;
                inOutBounds.top = origLeft;
        }
    }

    /**
     * Rotates bounds as if parentBounds and bounds are a group. The group is rotated by `delta`
     * 90-degree counter-clockwise increments. This assumes that parentBounds is at 0,0 and
     * remains at 0,0 after rotation. The bounds will be at the same physical position in
     * parentBounds.
     *
     * Only 'inOutBounds' is mutated.
     */
    public static void rotateBounds(Rect inOutBounds, Rect parentBounds, @Rotation int rotation) {
        rotateBounds(inOutBounds, parentBounds.right, parentBounds.bottom, rotation);
    }

    /** @return the rotation needed to rotate from oldRotation to newRotation. */
    @Rotation
    public static int deltaRotation(@Rotation int oldRotation, @Rotation int newRotation) {
+57 −21
Original line number Diff line number Diff line
@@ -30,7 +30,9 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.hardware.SensorPrivacyManager;
import android.hardware.biometrics.BiometricAuthenticator.Modality;
import android.hardware.biometrics.BiometricConstants;
@@ -54,6 +56,7 @@ import android.os.RemoteException;
import android.os.UserManager;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.DisplayInfo;
import android.view.MotionEvent;
import android.view.WindowManager;

@@ -104,16 +107,16 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
    private final CommandQueue mCommandQueue;
    private final StatusBarStateController mStatusBarStateController;
    private final ActivityTaskManager mActivityTaskManager;
    @Nullable
    private final FingerprintManager mFingerprintManager;
    @Nullable
    private final FaceManager mFaceManager;
    @Nullable private final FingerprintManager mFingerprintManager;
    @Nullable private final FaceManager mFaceManager;
    private final Provider<UdfpsController> mUdfpsControllerFactory;
    private final Provider<SidefpsController> mSidefpsControllerFactory;
    @Nullable
    private final PointF mFaceAuthSensorLocation;
    @Nullable
    private PointF mFingerprintLocation;

    @NonNull private Point mStableDisplaySize = new Point();

    @Nullable private final PointF mFaceAuthSensorLocation;
    @Nullable private PointF mFingerprintLocation;
    @Nullable private Rect mUdfpsBounds;
    private final Set<Callback> mCallbacks = new HashSet<>();

    // TODO: These should just be saved from onSaveState
@@ -122,14 +125,13 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
    AuthDialog mCurrentDialog;

    @NonNull private final WindowManager mWindowManager;
    @NonNull private final DisplayManager mDisplayManager;
    @Nullable private UdfpsController mUdfpsController;
    @Nullable private IUdfpsHbmListener mUdfpsHbmListener;
    @Nullable private SidefpsController mSidefpsController;
    @Nullable private IBiometricContextListener mBiometricContextListener;
    @VisibleForTesting
    IBiometricSysuiReceiver mReceiver;
    @VisibleForTesting
    @NonNull final BiometricDisplayListener mOrientationListener;
    @VisibleForTesting IBiometricSysuiReceiver mReceiver;
    @VisibleForTesting @NonNull final BiometricDisplayListener mOrientationListener;
    @Nullable private final List<FaceSensorPropertiesInternal> mFaceProps;
    @Nullable private List<FingerprintSensorPropertiesInternal> mFpProps;
    @Nullable private List<FingerprintSensorPropertiesInternal> mUdfpsProps;
@@ -249,6 +251,7 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
        }
        mAllFingerprintAuthenticatorsRegistered = true;
        mFpProps = sensors;

        List<FingerprintSensorPropertiesInternal> udfpsProps = new ArrayList<>();
        List<FingerprintSensorPropertiesInternal> sidefpsProps = new ArrayList<>();
        for (FingerprintSensorPropertiesInternal props : mFpProps) {
@@ -259,12 +262,14 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
                sidefpsProps.add(props);
            }
        }

        mUdfpsProps = !udfpsProps.isEmpty() ? udfpsProps : null;
        if (mUdfpsProps != null) {
            mUdfpsController = mUdfpsControllerFactory.get();
            mUdfpsController.addCallback(new UdfpsController.Callback() {
                @Override
                public void onFingerUp() {}
                public void onFingerUp() {
                }

                @Override
                public void onFingerDown() {
@@ -273,15 +278,22 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
                    }
                }
            });
            mUdfpsController.setAuthControllerUpdateUdfpsLocation(this::updateUdfpsLocation);
            mUdfpsBounds = mUdfpsProps.get(0).getLocation().getRect();
            updateUdfpsLocation();
        }

        mSidefpsProps = !sidefpsProps.isEmpty() ? sidefpsProps : null;
        if (mSidefpsProps != null) {
            mSidefpsController = mSidefpsControllerFactory.get();
        }

        mFingerprintManager.registerBiometricStateListener(mBiometricStateListener);
        updateFingerprintLocation();

        for (Callback cb : mCallbacks) {
            cb.onAllAuthenticatorsRegistered();
        }
        mFingerprintManager.registerBiometricStateListener(mBiometricStateListener);
    }

    private void handleEnrollmentsChanged(int userId, int sensorId, boolean hasEnrollments) {
@@ -424,12 +436,11 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
    /**
     * @return where the UDFPS exists on the screen in pixels in portrait mode.
     */
    @Nullable public PointF getUdfpsSensorLocation() {
        if (mUdfpsController == null) {
    @Nullable public PointF getUdfpsLocation() {
        if (mUdfpsController == null || mUdfpsBounds == null) {
            return null;
        }
        return new PointF(mUdfpsController.getSensorLocation().centerX(),
                mUdfpsController.getSensorLocation().centerY());
        return new PointF(mUdfpsBounds.centerX(), mUdfpsBounds.centerY());
    }

    /**
@@ -437,8 +448,8 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
     * overridden value will use the default value even if they don't have a fingerprint sensor
     */
    @Nullable public PointF getFingerprintSensorLocation() {
        if (getUdfpsSensorLocation() != null) {
            return getUdfpsSensorLocation();
        if (getUdfpsLocation() != null) {
            return getUdfpsLocation();
        }
        return mFingerprintLocation;
    }
@@ -525,12 +536,13 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
        mFaceManager = faceManager;
        mUdfpsControllerFactory = udfpsControllerFactory;
        mSidefpsControllerFactory = sidefpsControllerFactory;
        mDisplayManager = displayManager;
        mWindowManager = windowManager;
        mUdfpsEnrolledForUser = new SparseBooleanArray();

        mOrientationListener = new BiometricDisplayListener(
                context,
                displayManager,
                mDisplayManager,
                mHandler,
                BiometricDisplayListener.SensorType.Generic.INSTANCE,
                () -> {
@@ -582,6 +594,27 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
                yLocation);
    }

    // TODO(b/229290039): UDFPS controller should manage its dimensions on its own. Remove this.
    // This is not combined with updateFingerprintLocation because this is invoked directly from
    // UdfpsController, only when it cares about a rotation change. The implications of calling
    // updateFingerprintLocation in such a case are unclear.
    private void updateUdfpsLocation() {
        if (mUdfpsController != null) {
            final DisplayInfo displayInfo = new DisplayInfo();
            mContext.getDisplay().getDisplayInfo(displayInfo);
            final float scaleFactor = android.util.DisplayUtils.getPhysicalPixelDisplaySizeRatio(
                    mStableDisplaySize.x, mStableDisplaySize.y, displayInfo.getNaturalWidth(),
                    displayInfo.getNaturalHeight());

            final FingerprintSensorPropertiesInternal udfpsProp = mUdfpsProps.get(0);
            mUdfpsBounds = udfpsProp.getLocation().getRect();
            mUdfpsBounds.scale(scaleFactor);
            mUdfpsController.updateOverlayParams(udfpsProp.sensorId,
                    new UdfpsOverlayParams(mUdfpsBounds, displayInfo.getNaturalWidth(),
                            displayInfo.getNaturalHeight(), scaleFactor, displayInfo.rotation));
        }
    }

    @SuppressWarnings("deprecation")
    @Override
    public void start() {
@@ -592,6 +625,7 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
                    mFingerprintAuthenticatorsRegisteredCallback);
        }

        mStableDisplaySize = mDisplayManager.getStableDisplaySize();
        mActivityTaskManager.registerTaskStackListener(mTaskStackListener);
    }

@@ -906,6 +940,7 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
    protected void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        updateFingerprintLocation();
        updateUdfpsLocation();

        // Save the state of the current dialog (buttons showing, etc)
        if (mCurrentDialog != null) {
@@ -935,6 +970,7 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba

    private void onOrientationChanged() {
        updateFingerprintLocation();
        updateUdfpsLocation();
        if (mCurrentDialog != null) {
            mCurrentDialog.onOrientationChanged();
        }
+6 −4
Original line number Diff line number Diff line
@@ -64,7 +64,11 @@ class BiometricDisplayListener(
    /** Listen for changes. */
    fun enable() {
        lastRotation = context.display?.rotation ?: Surface.ROTATION_0
        displayManager.registerDisplayListener(this, handler)
        displayManager.registerDisplayListener(
            this,
            handler,
            DisplayManager.EVENT_FLAG_DISPLAY_CHANGED
        )
    }

    /** Stop listening for changes. */
@@ -80,9 +84,7 @@ class BiometricDisplayListener(
     */
    sealed class SensorType {
        object Generic : SensorType()
        data class UnderDisplayFingerprint(
            val properties: FingerprintSensorPropertiesInternal
        ) : SensorType()
        object UnderDisplayFingerprint : SensorType()
        data class SideFingerprint(
            val properties: FingerprintSensorPropertiesInternal
        ) : SensorType()
+76 −93

File changed.

Preview size limit exceeded, changes collapsed.

Loading