Add sensorLocationX/Y and sensorRadius to SensorProps

Removes the above properties from the Udfps Styleable, but
ensures that the properties are passed in after inflation and
before attachment.

Bug: 171071087
Test: atest com.android.systemui.biometrics
Test: com.android.server.biometrics
Change-Id: I6ff932772c8e2be22210c16b58e603f8a363f247
This commit is contained in:
Kevin Chyn
2020-10-27 18:11:09 -07:00
parent cc07fa7dd6
commit cf22a0bcdc
6 changed files with 68 additions and 44 deletions

View File

@@ -28,11 +28,40 @@ import android.os.Parcel;
* @hide
*/
public class FingerprintSensorPropertiesInternal extends SensorPropertiesInternal {
/**
* See {@link FingerprintSensorProperties.SensorType}.
*/
public final @FingerprintSensorProperties.SensorType int sensorType;
// IBiometricsFingerprint@2.1 does not manage timeout below the HAL, so the Gatekeeper HAT
// cannot be checked
/**
* IBiometricsFingerprint@2.1 does not manage timeout below the HAL, so the Gatekeeper HAT
* cannot be checked
*/
public final boolean resetLockoutRequiresHardwareAuthToken;
/**
* The location of the center of the sensor if applicable. For example, sensors of type
* {@link FingerprintSensorProperties#TYPE_UDFPS_OPTICAL} would report this value as the
* distance in pixels, measured from the left edge of the screen.
* TODO: Value should be provided from the HAL
*/
public final int sensorLocationX = 540;
/**
* The location of the center of the sensor if applicable. For example, sensors of type
* {@link FingerprintSensorProperties#TYPE_UDFPS_OPTICAL} would report this value as the
* distance in pixels, measured from the top edge of the screen.
* TODO: Value should be provided from the HAL
*/
public final int sensorLocationY = 1636;
/**
* The radius of the sensor if applicable. For example, sensors of type
* {@link FingerprintSensorProperties#TYPE_UDFPS_OPTICAL} would report this value as the radius
* of the sensor, in pixels.
*/
public final int sensorRadius = 130;
/**
* Initializes SensorProperties with specified values
*/

View File

@@ -5,6 +5,4 @@
android:id="@+id/udfps_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
systemui:sensorRadius="130px"
systemui:sensorCenterY="1636px"
systemui:sensorTouchAreaCoefficient="0.5"/>

View File

@@ -158,8 +158,6 @@
</declare-styleable>
<declare-styleable name="UdfpsView">
<attr name="sensorRadius" format="dimension"/>
<attr name="sensorCenterY" format="dimension"/>
<attr name="sensorPressureCoefficient" format="float"/>
<attr name="sensorTouchAreaCoefficient" format="float"/>
</declare-styleable>

View File

@@ -78,7 +78,7 @@ class UdfpsController implements DozeReceiver {
// Currently the UdfpsController supports a single UDFPS sensor. If devices have multiple
// sensors, this, in addition to a lot of the code here, will be updated.
@VisibleForTesting
final int mUdfpsSensorId;
final FingerprintSensorPropertiesInternal mSensorProps;
private final WindowManager mWindowManager;
private final SystemSettings mSystemSettings;
private final DelayableExecutor mFgExecutor;
@@ -180,19 +180,12 @@ class UdfpsController implements DozeReceiver {
mFgExecutor = fgExecutor;
mLayoutParams = createLayoutParams(context);
int udfpsSensorId = -1;
for (FingerprintSensorPropertiesInternal props :
mFingerprintManager.getSensorPropertiesInternal()) {
if (props.isAnyUdfpsType()) {
udfpsSensorId = props.sensorId;
break;
}
}
mSensorProps = findFirstUdfps();
// At least one UDFPS sensor exists
checkArgument(udfpsSensorId != -1);
mUdfpsSensorId = udfpsSensorId;
checkArgument(mSensorProps != null);
mView = (UdfpsView) inflater.inflate(R.layout.udfps_view, null, false);
mView.setSensorProperties(mSensorProps);
mHbmPath = resources.getString(R.string.udfps_hbm_sysfs_path);
mHbmEnableCommand = resources.getString(R.string.udfps_hbm_enable_command);
@@ -235,6 +228,17 @@ class UdfpsController implements DozeReceiver {
mIsOverlayShowing = false;
}
@Nullable
private FingerprintSensorPropertiesInternal findFirstUdfps() {
for (FingerprintSensorPropertiesInternal props :
mFingerprintManager.getSensorPropertiesInternal()) {
if (props.isAnyUdfpsType()) {
return props;
}
}
return null;
}
@Override
public void dozeTimeTick() {
mView.dozeTimeTick();
@@ -374,7 +378,7 @@ class UdfpsController implements DozeReceiver {
fw.write(mHbmEnableCommand);
fw.close();
}
mFingerprintManager.onPointerDown(mUdfpsSensorId, x, y, minor, major);
mFingerprintManager.onPointerDown(mSensorProps.sensorId, x, y, minor, major);
} catch (IOException e) {
mView.hideScrimAndDot();
Log.e(TAG, "onFingerDown | failed to enable HBM: " + e.getMessage());
@@ -382,7 +386,7 @@ class UdfpsController implements DozeReceiver {
}
private void onFingerUp() {
mFingerprintManager.onPointerUp(mUdfpsSensorId);
mFingerprintManager.onPointerUp(mSensorProps.sensorId);
// Hiding the scrim before disabling HBM results in less noticeable flicker.
mView.hideScrimAndDot();
if (mHbmSupported) {

View File

@@ -18,6 +18,7 @@ package com.android.systemui.biometrics;
import static com.android.systemui.doze.util.BurnInHelperKt.getBurnInOffset;
import android.annotation.NonNull;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
@@ -25,6 +26,7 @@ import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
@@ -55,8 +57,6 @@ public class UdfpsView extends View implements DozeReceiver,
private final RectF mSensorRect;
private final Paint mSensorPaint;
private final float mSensorRadius;
private final float mSensorCenterY;
private final float mSensorTouchAreaCoefficient;
private final int mMaxBurnInOffsetX;
private final int mMaxBurnInOffsetY;
@@ -64,9 +64,7 @@ public class UdfpsView extends View implements DozeReceiver,
private final Rect mTouchableRegion;
private final ViewTreeObserver.OnComputeInternalInsetsListener mInsetsListener;
// This is calculated from the screen's dimensions at runtime, as opposed to mSensorCenterY,
// which is defined in layout.xml
private float mSensorCenterX;
@NonNull private FingerprintSensorPropertiesInternal mProps;
// AOD anti-burn-in offsets
private float mInterpolatedDarkAmount;
@@ -83,18 +81,10 @@ public class UdfpsView extends View implements DozeReceiver,
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.UdfpsView, 0,
0);
try {
if (!a.hasValue(R.styleable.UdfpsView_sensorRadius)) {
throw new IllegalArgumentException("UdfpsView must contain sensorRadius");
}
if (!a.hasValue(R.styleable.UdfpsView_sensorCenterY)) {
throw new IllegalArgumentException("UdfpsView must contain sensorMarginBottom");
}
if (!a.hasValue(R.styleable.UdfpsView_sensorTouchAreaCoefficient)) {
throw new IllegalArgumentException(
"UdfpsView must contain sensorTouchAreaCoefficient");
}
mSensorRadius = a.getDimension(R.styleable.UdfpsView_sensorRadius, 0f);
mSensorCenterY = a.getDimension(R.styleable.UdfpsView_sensorCenterY, 0f);
mSensorTouchAreaCoefficient = a.getFloat(
R.styleable.UdfpsView_sensorTouchAreaCoefficient, 0f);
} finally {
@@ -134,6 +124,10 @@ public class UdfpsView extends View implements DozeReceiver,
mIsScrimShowing = false;
}
void setSensorProperties(@NonNull FingerprintSensorPropertiesInternal properties) {
mProps = properties;
}
@Override
public void dozeTimeTick() {
updateAodPosition();
@@ -165,9 +159,10 @@ public class UdfpsView extends View implements DozeReceiver,
final int h = getLayoutParams().height;
final int w = getLayoutParams().width;
mScrimRect.set(0 /* left */, 0 /* top */, w, h);
mSensorCenterX = w / 2f;
mSensorRect.set(mSensorCenterX - mSensorRadius, mSensorCenterY - mSensorRadius,
mSensorCenterX + mSensorRadius, mSensorCenterY + mSensorRadius);
mSensorRect.set(mProps.sensorLocationX - mProps.sensorRadius,
mProps.sensorLocationY - mProps.sensorRadius,
mProps.sensorLocationX + mProps.sensorRadius,
mProps.sensorLocationY + mProps.sensorRadius);
// Sets mTouchableRegion with rounded up values from mSensorRect.
mSensorRect.roundOut(mTouchableRegion);
@@ -211,10 +206,10 @@ public class UdfpsView extends View implements DozeReceiver,
}
boolean isValidTouch(float x, float y, float pressure) {
return x > (mSensorCenterX - mSensorRadius * mSensorTouchAreaCoefficient)
&& x < (mSensorCenterX + mSensorRadius * mSensorTouchAreaCoefficient)
&& y > (mSensorCenterY - mSensorRadius * mSensorTouchAreaCoefficient)
&& y < (mSensorCenterY + mSensorRadius * mSensorTouchAreaCoefficient);
return x > (mProps.sensorLocationX - mProps.sensorRadius * mSensorTouchAreaCoefficient)
&& x < (mProps.sensorLocationX + mProps.sensorRadius * mSensorTouchAreaCoefficient)
&& y > (mProps.sensorLocationY - mProps.sensorRadius * mSensorTouchAreaCoefficient)
&& y < (mProps.sensorLocationY + mProps.sensorRadius * mSensorTouchAreaCoefficient);
}
void setScrimAlpha(int alpha) {

View File

@@ -132,7 +132,7 @@ public class UdfpsControllerTest extends SysuiTestCase {
verify(mFingerprintManager).setUdfpsOverlayController(mOverlayCaptor.capture());
mOverlayController = mOverlayCaptor.getValue();
assertEquals(TEST_UDFPS_SENSOR_ID, mUdfpsController.mUdfpsSensorId);
assertEquals(TEST_UDFPS_SENSOR_ID, mUdfpsController.mSensorProps.sensorId);
}
private void setUpResources() {
@@ -222,8 +222,8 @@ public class UdfpsControllerTest extends SysuiTestCase {
mTouchListenerCaptor.getValue().onTouch(mUdfpsView, event);
event.recycle();
// THEN the event is passed to the FingerprintManager
verify(mFingerprintManager).onPointerDown(eq(mUdfpsController.mUdfpsSensorId), eq(0), eq(0),
eq(0f), eq(0f));
verify(mFingerprintManager).onPointerDown(eq(mUdfpsController.mSensorProps.sensorId), eq(0),
eq(0), eq(0f), eq(0f));
// AND the scrim and dot is shown
verify(mUdfpsView).showScrimAndDot();
}
@@ -236,8 +236,8 @@ public class UdfpsControllerTest extends SysuiTestCase {
// WHEN fingerprint is requested because of AOD interrupt
mUdfpsController.onAodInterrupt(0, 0);
// THEN the event is passed to the FingerprintManager
verify(mFingerprintManager).onPointerDown(eq(mUdfpsController.mUdfpsSensorId), eq(0), eq(0),
anyFloat(), anyFloat());
verify(mFingerprintManager).onPointerDown(eq(mUdfpsController.mSensorProps.sensorId), eq(0),
eq(0), anyFloat(), anyFloat());
// AND the scrim and dot is shown
verify(mUdfpsView).showScrimAndDot();
}