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

Commit f9e4d806 authored by Josh Tsuji's avatar Josh Tsuji
Browse files

Re-calculate non-UDFPS fingerprint location onConfigChanged.

The location relative to the screen may change due
to orientation or folded status changes.

Bug: 268204504
Test: unlock on foldable/tablet
Change-Id: I4de30d67d878f24ca240daa711521562f427ff7d
Merged-In: I4de30d67d878f24ca240daa711521562f427ff7d
parent f612fe0d
Loading
Loading
Loading
Loading
+16 −19
Original line number Diff line number Diff line
@@ -129,7 +129,6 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
    private float mScaleFactor = 1f;
    // sensor locations without any resolution scaling nor rotation adjustments:
    @Nullable private final Point mFaceSensorLocationDefault;
    @Nullable private final Point mFingerprintSensorLocationDefault;
    // cached sensor locations:
    @Nullable private Point mFaceSensorLocation;
    @Nullable private Point mFingerprintSensorLocation;
@@ -586,12 +585,24 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
    @Nullable private Point getFingerprintSensorLocationInNaturalOrientation() {
        if (getUdfpsLocation() != null) {
            return getUdfpsLocation();
        } else {
            int xFpLocation = mCachedDisplayInfo.getNaturalWidth() / 2;
            try {
                xFpLocation = mContext.getResources().getDimensionPixelSize(
                        com.android.systemui.R.dimen
                                .physical_fingerprint_sensor_center_screen_location_x);
            } catch (Resources.NotFoundException e) {
            }

            return new Point(
                (int) (mFingerprintSensorLocationDefault.x * mScaleFactor),
                (int) (mFingerprintSensorLocationDefault.y * mScaleFactor)
                    (int) (xFpLocation * mScaleFactor),
                    (int) (mContext.getResources().getDimensionPixelSize(
                            com.android.systemui.R.dimen
                                    .physical_fingerprint_sensor_center_screen_location_y)
                            * mScaleFactor)
            );
        }
    }

    /**
     * @return where the fingerprint sensor exists in pixels exists the current device orientation.
@@ -774,19 +785,6 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
        }

        mDisplay = mContext.getDisplay();
        mDisplay.getDisplayInfo(mCachedDisplayInfo);
        int xFpLocation = mCachedDisplayInfo.getNaturalWidth() / 2;
        try {
            xFpLocation = mContext.getResources().getDimensionPixelSize(
                    com.android.systemui.R.dimen
                            .physical_fingerprint_sensor_center_screen_location_x);
        } catch (Resources.NotFoundException e) {
        }
        mFingerprintSensorLocationDefault = new Point(
                xFpLocation,
                mContext.getResources().getDimensionPixelSize(com.android.systemui.R.dimen
                        .physical_fingerprint_sensor_center_screen_location_y)
        );
        updateSensorLocations();

        IntentFilter filter = new IntentFilter();
@@ -1246,7 +1244,6 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
        pw.println("  mScaleFactor=" + mScaleFactor);
        pw.println("  faceAuthSensorLocationDefault=" + mFaceSensorLocationDefault);
        pw.println("  faceAuthSensorLocation=" + getFaceSensorLocation());
        pw.println("  fingerprintSensorLocationDefault=" + mFingerprintSensorLocationDefault);
        pw.println("  fingerprintSensorLocationInNaturalOrientation="
                + getFingerprintSensorLocationInNaturalOrientation());
        pw.println("  fingerprintSensorLocation=" + getFingerprintSensorLocation());
+24 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_AWA
import static com.google.common.truth.Truth.assertThat;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotSame;
import static junit.framework.Assert.assertNull;

import static org.mockito.ArgumentMatchers.any;
@@ -33,6 +34,7 @@ import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -49,6 +51,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Point;
import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.biometrics.BiometricConstants;
@@ -166,6 +169,8 @@ public class AuthControllerTest extends SysuiTestCase {
    private ArgumentCaptor<StatusBarStateController.StateListener> mStatusBarStateListenerCaptor;
    @Captor
    private ArgumentCaptor<WakefulnessLifecycle.Observer> mWakefullnessObserverCaptor;
    @Mock
    private Resources mResources;

    private TestableContext mContextSpy;
    private Execution mExecution;
@@ -879,6 +884,25 @@ public class AuthControllerTest extends SysuiTestCase {
        );
    }

    @Test
    public void testUpdateFingerprintLocation_defaultPointChanges_whenConfigChanges() {
        when(mContextSpy.getResources()).thenReturn(mResources);

        doReturn(500).when(mResources)
                .getDimensionPixelSize(eq(com.android.systemui.R.dimen
                        .physical_fingerprint_sensor_center_screen_location_y));
        mAuthController.onConfigurationChanged(null /* newConfig */);

        final Point firstFpLocation = mAuthController.getFingerprintSensorLocation();

        doReturn(1000).when(mResources)
                .getDimensionPixelSize(eq(com.android.systemui.R.dimen
                        .physical_fingerprint_sensor_center_screen_location_y));
        mAuthController.onConfigurationChanged(null /* newConfig */);

        assertNotSame(firstFpLocation, mAuthController.getFingerprintSensorLocation());
    }

    private void showDialog(int[] sensorIds, boolean credentialAllowed) {
        mAuthController.showAuthenticationDialog(createTestPromptInfo(),
                mReceiver /* receiver */,