Merge "Add onUdfpsLocationChanged callback" into tm-dev

This commit is contained in:
Beverly Tai
2022-05-07 01:27:38 +00:00
committed by Android (Google) Code Review
5 changed files with 39 additions and 38 deletions

View File

@@ -55,7 +55,7 @@ public class LockIconView extends FrameLayout implements Dumpable {
@NonNull private final RectF mSensorRect; @NonNull private final RectF mSensorRect;
@NonNull private PointF mLockIconCenter = new PointF(0f, 0f); @NonNull private PointF mLockIconCenter = new PointF(0f, 0f);
private int mRadius; private float mRadius;
private int mLockIconPadding; private int mLockIconPadding;
private ImageView mLockIcon; private ImageView mLockIcon;
@@ -126,7 +126,7 @@ public class LockIconView extends FrameLayout implements Dumpable {
* Set the location of the lock icon. * Set the location of the lock icon.
*/ */
@VisibleForTesting @VisibleForTesting
public void setCenterLocation(@NonNull PointF center, int radius, int drawablePadding) { public void setCenterLocation(@NonNull PointF center, float radius, int drawablePadding) {
mLockIconCenter = center; mLockIconCenter = center;
mRadius = radius; mRadius = radius;
mLockIconPadding = drawablePadding; mLockIconPadding = drawablePadding;

View File

@@ -188,6 +188,7 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
protected void onViewAttached() { protected void onViewAttached() {
updateIsUdfpsEnrolled(); updateIsUdfpsEnrolled();
updateConfiguration(); updateConfiguration();
updateLockIconLocation();
updateKeyguardShowing(); updateKeyguardShowing();
mUserUnlockedWithBiometric = false; mUserUnlockedWithBiometric = false;
@@ -340,20 +341,17 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
mHeightPixels = bounds.bottom; mHeightPixels = bounds.bottom;
mBottomPaddingPx = getResources().getDimensionPixelSize(R.dimen.lock_icon_margin_bottom); mBottomPaddingPx = getResources().getDimensionPixelSize(R.dimen.lock_icon_margin_bottom);
final int defaultPaddingPx =
getResources().getDimensionPixelSize(R.dimen.lock_icon_padding);
mScaledPaddingPx = (int) (defaultPaddingPx * mAuthController.getScaleFactor());
mUnlockedLabel = mView.getContext().getResources().getString( mUnlockedLabel = mView.getContext().getResources().getString(
R.string.accessibility_unlock_button); R.string.accessibility_unlock_button);
mLockedLabel = mView.getContext() mLockedLabel = mView.getContext()
.getResources().getString(R.string.accessibility_lock_icon); .getResources().getString(R.string.accessibility_lock_icon);
updateLockIconLocation();
} }
private void updateLockIconLocation() { private void updateLockIconLocation() {
if (mUdfpsSupported) { if (mUdfpsSupported) {
final int defaultPaddingPx =
getResources().getDimensionPixelSize(R.dimen.lock_icon_padding);
mScaledPaddingPx = (int) (defaultPaddingPx * mAuthController.getScaleFactor());
mView.setCenterLocation(mAuthController.getUdfpsLocation(), mView.setCenterLocation(mAuthController.getUdfpsLocation(),
mAuthController.getUdfpsRadius(), mScaledPaddingPx); mAuthController.getUdfpsRadius(), mScaledPaddingPx);
} else { } else {
@@ -362,8 +360,6 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
mHeightPixels - mBottomPaddingPx - sLockIconRadiusPx), mHeightPixels - mBottomPaddingPx - sLockIconRadiusPx),
sLockIconRadiusPx, mScaledPaddingPx); sLockIconRadiusPx, mScaledPaddingPx);
} }
mView.getHitRect(mSensorTouchLocation);
} }
@Override @Override
@@ -386,6 +382,7 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
pw.println(" mCanDismissLockScreen: " + mCanDismissLockScreen); pw.println(" mCanDismissLockScreen: " + mCanDismissLockScreen);
pw.println(" mStatusBarState: " + StatusBarState.toString(mStatusBarState)); pw.println(" mStatusBarState: " + StatusBarState.toString(mStatusBarState));
pw.println(" mInterpolatedDarkAmount: " + mInterpolatedDarkAmount); pw.println(" mInterpolatedDarkAmount: " + mInterpolatedDarkAmount);
pw.println(" mSensorTouchLocation: " + mSensorTouchLocation);
if (mView != null) { if (mView != null) {
mView.dump(pw, args); mView.dump(pw, args);
@@ -672,6 +669,7 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
} }
private boolean inLockIconArea(MotionEvent event) { private boolean inLockIconArea(MotionEvent event) {
mView.getHitRect(mSensorTouchLocation);
return mSensorTouchLocation.contains((int) event.getX(), (int) event.getY()) return mSensorTouchLocation.contains((int) event.getX(), (int) event.getY())
&& mView.getVisibility() == View.VISIBLE; && mView.getVisibility() == View.VISIBLE;
} }
@@ -692,6 +690,7 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
mExecutor.execute(() -> { mExecutor.execute(() -> {
updateIsUdfpsEnrolled(); updateIsUdfpsEnrolled();
updateConfiguration(); updateConfiguration();
updateLockIconLocation();
}); });
} }
@@ -705,6 +704,11 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
public void onEnrollmentsChanged() { public void onEnrollmentsChanged() {
updateUdfpsConfig(); updateUdfpsConfig();
} }
@Override
public void onUdfpsLocationChanged() {
updateLockIconLocation();
}
}; };
private final View.OnClickListener mA11yClickListener = v -> onLongPress(); private final View.OnClickListener mA11yClickListener = v -> onLongPress();

View File

@@ -79,6 +79,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
@@ -446,11 +447,11 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
/** /**
* @return the radius of UDFPS on the screen in pixels * @return the radius of UDFPS on the screen in pixels
*/ */
public int getUdfpsRadius() { public float getUdfpsRadius() {
if (mUdfpsController == null || mUdfpsBounds == null) { if (mUdfpsController == null || mUdfpsBounds == null) {
return -1; return -1;
} }
return mUdfpsBounds.height() / 2; return mUdfpsBounds.height() / 2f;
} }
/** /**
@@ -634,11 +635,17 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
displayInfo.getNaturalHeight()); displayInfo.getNaturalHeight());
final FingerprintSensorPropertiesInternal udfpsProp = mUdfpsProps.get(0); final FingerprintSensorPropertiesInternal udfpsProp = mUdfpsProps.get(0);
final Rect previousUdfpsBounds = mUdfpsBounds;
mUdfpsBounds = udfpsProp.getLocation().getRect(); mUdfpsBounds = udfpsProp.getLocation().getRect();
mUdfpsBounds.scale(scaleFactor); mUdfpsBounds.scale(scaleFactor);
mUdfpsController.updateOverlayParams(udfpsProp.sensorId, mUdfpsController.updateOverlayParams(udfpsProp.sensorId,
new UdfpsOverlayParams(mUdfpsBounds, displayInfo.getNaturalWidth(), new UdfpsOverlayParams(mUdfpsBounds, displayInfo.getNaturalWidth(),
displayInfo.getNaturalHeight(), scaleFactor, displayInfo.rotation)); displayInfo.getNaturalHeight(), scaleFactor, displayInfo.rotation));
if (!Objects.equals(previousUdfpsBounds, mUdfpsBounds)) {
for (Callback cb : mCallbacks) {
cb.onUdfpsLocationChanged();
}
}
} }
} }
@@ -1054,5 +1061,10 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
* Called when the biometric prompt is no longer showing. * Called when the biometric prompt is no longer showing.
*/ */
default void onBiometricPromptDismissed() {} default void onBiometricPromptDismissed() {}
/**
* The location in pixels can change due to resolution changes.
*/
default void onUdfpsLocationChanged() {}
} }
} }

View File

@@ -335,15 +335,17 @@ class AuthRippleController @Inject constructor(
updateSensorLocation() updateSensorLocation()
} }
override fun onEnrollmentsChanged() { override fun onUdfpsLocationChanged() {
updateUdfpsDependentParams()
updateSensorLocation()
} }
} }
private fun updateUdfpsDependentParams() { private fun updateUdfpsDependentParams() {
authController.udfpsProps?.let { authController.udfpsProps?.let {
if (it.size > 0) { if (it.size > 0) {
udfpsRadius = it[0].location.sensorRadius.toFloat()
udfpsController = udfpsControllerProvider.get() udfpsController = udfpsControllerProvider.get()
udfpsRadius = authController.udfpsRadius
if (mView.isAttachedToWindow) { if (mView.isAttachedToWindow) {
udfpsController?.addCallback(udfpsControllerCallback) udfpsController?.addCallback(udfpsControllerCallback)

View File

@@ -34,8 +34,6 @@ import android.graphics.PointF;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.AnimatedStateListDrawable; import android.graphics.drawable.AnimatedStateListDrawable;
import android.hardware.biometrics.BiometricSourceType; import android.hardware.biometrics.BiometricSourceType;
import android.hardware.biometrics.SensorLocationInternal;
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
import android.testing.AndroidTestingRunner; import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper; import android.testing.TestableLooper;
import android.util.Pair; import android.util.Pair;
@@ -77,9 +75,6 @@ import org.mockito.MockitoAnnotations;
import org.mockito.MockitoSession; import org.mockito.MockitoSession;
import org.mockito.quality.Strictness; import org.mockito.quality.Strictness;
import java.util.ArrayList;
import java.util.List;
@SmallTest @SmallTest
@RunWith(AndroidTestingRunner.class) @RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper @TestableLooper.RunWithLooper
@@ -182,7 +177,7 @@ public class LockIconViewControllerTest extends SysuiTestCase {
@Test @Test
public void testUpdateFingerprintLocationOnInit() { public void testUpdateFingerprintLocationOnInit() {
// GIVEN fp sensor location is available pre-attached // GIVEN fp sensor location is available pre-attached
Pair<Integer, PointF> udfps = setupUdfps(); // first = radius, second = udfps location Pair<Float, PointF> udfps = setupUdfps(); // first = radius, second = udfps location
// WHEN lock icon view controller is initialized and attached // WHEN lock icon view controller is initialized and attached
mLockIconViewController.init(); mLockIconViewController.init();
@@ -197,7 +192,7 @@ public class LockIconViewControllerTest extends SysuiTestCase {
@Test @Test
public void testUpdatePaddingBasedOnResolutionScale() { public void testUpdatePaddingBasedOnResolutionScale() {
// GIVEN fp sensor location is available pre-attached & scaled resolution factor is 5 // GIVEN fp sensor location is available pre-attached & scaled resolution factor is 5
Pair<Integer, PointF> udfps = setupUdfps(); // first = radius, second = udfps location Pair<Float, PointF> udfps = setupUdfps(); // first = radius, second = udfps location
when(mAuthController.getScaleFactor()).thenReturn(5f); when(mAuthController.getScaleFactor()).thenReturn(5f);
// WHEN lock icon view controller is initialized and attached // WHEN lock icon view controller is initialized and attached
@@ -215,20 +210,19 @@ public class LockIconViewControllerTest extends SysuiTestCase {
// GIVEN fp sensor location is not available pre-init // GIVEN fp sensor location is not available pre-init
when(mKeyguardUpdateMonitor.isUdfpsSupported()).thenReturn(false); when(mKeyguardUpdateMonitor.isUdfpsSupported()).thenReturn(false);
when(mAuthController.getFingerprintSensorLocation()).thenReturn(null); when(mAuthController.getFingerprintSensorLocation()).thenReturn(null);
when(mAuthController.getUdfpsProps()).thenReturn(null);
mLockIconViewController.init(); mLockIconViewController.init();
captureAttachListener(); captureAttachListener();
mAttachListener.onViewAttachedToWindow(mLockIconView); mAttachListener.onViewAttachedToWindow(mLockIconView);
// GIVEN fp sensor location is available post-atttached // GIVEN fp sensor location is available post-attached
captureAuthControllerCallback(); captureAuthControllerCallback();
Pair<Integer, PointF> udfps = setupUdfps(); Pair<Float, PointF> udfps = setupUdfps();
// WHEN all authenticators are registered // WHEN all authenticators are registered
mAuthControllerCallback.onAllAuthenticatorsRegistered(); mAuthControllerCallback.onAllAuthenticatorsRegistered();
mDelayableExecutor.runAllReady(); mDelayableExecutor.runAllReady();
// THEN lock icon view location is updated with the same coordinates as fpProps // THEN lock icon view location is updated with the same coordinates as auth controller vals
verify(mLockIconView).setCenterLocation(eq(udfps.second), eq(udfps.first), verify(mLockIconView).setCenterLocation(eq(udfps.second), eq(udfps.first),
eq(PADDING)); eq(PADDING));
} }
@@ -402,21 +396,10 @@ public class LockIconViewControllerTest extends SysuiTestCase {
verify(mLockIconView).setTranslationX(0); verify(mLockIconView).setTranslationX(0);
} }
private Pair<Integer, PointF> setupUdfps() { private Pair<Float, PointF> setupUdfps() {
when(mKeyguardUpdateMonitor.isUdfpsSupported()).thenReturn(true); when(mKeyguardUpdateMonitor.isUdfpsSupported()).thenReturn(true);
final PointF udfpsLocation = new PointF(50, 75); final PointF udfpsLocation = new PointF(50, 75);
final int radius = 33; final float radius = 33f;
final FingerprintSensorPropertiesInternal fpProps =
new FingerprintSensorPropertiesInternal(
/* sensorId */ 0,
/* strength */ 0,
/* max enrollments per user */ 5,
/* component info */ new ArrayList<>(),
/* sensorType */ 3,
/* halControlsIllumination */ true,
/* resetLockoutRequiresHwToken */ false,
List.of(new SensorLocationInternal("" /* displayId */,
(int) udfpsLocation.x, (int) udfpsLocation.y, radius)));
when(mAuthController.getUdfpsLocation()).thenReturn(udfpsLocation); when(mAuthController.getUdfpsLocation()).thenReturn(udfpsLocation);
when(mAuthController.getUdfpsRadius()).thenReturn(radius); when(mAuthController.getUdfpsRadius()).thenReturn(radius);