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
This commit is contained in:
Josh Tsuji
2023-02-09 17:15:06 -05:00
parent 44b660ae9d
commit 059066e3b8
2 changed files with 41 additions and 19 deletions

View File

@@ -134,7 +134,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;
@@ -595,11 +594,23 @@ 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) (xFpLocation * mScaleFactor),
(int) (mContext.getResources().getDimensionPixelSize(
com.android.systemui.R.dimen
.physical_fingerprint_sensor_center_screen_location_y)
* mScaleFactor)
);
}
return new Point(
(int) (mFingerprintSensorLocationDefault.x * mScaleFactor),
(int) (mFingerprintSensorLocationDefault.y * mScaleFactor)
);
}
/**
@@ -778,19 +789,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();
@@ -1265,7 +1263,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());

View File

@@ -24,6 +24,7 @@ import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotSame;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
@@ -33,6 +34,8 @@ 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;
import static org.mockito.Mockito.reset;
@@ -48,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;
@@ -177,6 +181,8 @@ public class AuthControllerTest extends SysuiTestCase {
private ArgumentCaptor<IFaceAuthenticatorsRegisteredCallback> mFaceAuthenticatorsRegisteredCaptor;
@Captor
private ArgumentCaptor<BiometricStateListener> mBiometricStateCaptor;
@Mock
private Resources mResources;
private TestableContext mContextSpy;
private Execution mExecution;
@@ -905,6 +911,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 */,