diff options
| author | 2020-10-29 00:11:59 +0000 | |
|---|---|---|
| committer | 2020-10-29 00:11:59 +0000 | |
| commit | 6a7992b9dd2a0cf18c885ec6b683428b98c54ff7 (patch) | |
| tree | 1daad36734937de2359be56601fd3d2f9992566c | |
| parent | 286c33a5c55e352d1ca337e2a7d988b65b26286c (diff) | |
| parent | cf22a0bcdc5b8d553df21504d54c69a74e935be0 (diff) | |
Merge "Add sensorLocationX/Y and sensorRadius to SensorProps"
6 files changed, 68 insertions, 44 deletions
| diff --git a/core/java/android/hardware/fingerprint/FingerprintSensorPropertiesInternal.java b/core/java/android/hardware/fingerprint/FingerprintSensorPropertiesInternal.java index 1f896cdf4298..9a9e47868b85 100644 --- a/core/java/android/hardware/fingerprint/FingerprintSensorPropertiesInternal.java +++ b/core/java/android/hardware/fingerprint/FingerprintSensorPropertiesInternal.java @@ -28,12 +28,41 @@ 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       */      public FingerprintSensorPropertiesInternal(int sensorId, diff --git a/packages/SystemUI/res/layout/udfps_view.xml b/packages/SystemUI/res/layout/udfps_view.xml index 31a33fbfc308..ccd235d54c0b 100644 --- a/packages/SystemUI/res/layout/udfps_view.xml +++ b/packages/SystemUI/res/layout/udfps_view.xml @@ -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"/> diff --git a/packages/SystemUI/res/values/attrs.xml b/packages/SystemUI/res/values/attrs.xml index a62502965dd2..78d92c4b47e2 100644 --- a/packages/SystemUI/res/values/attrs.xml +++ b/packages/SystemUI/res/values/attrs.xml @@ -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> diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java index e3b00495f3dc..3c2e00869ab8 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java @@ -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) { diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.java index d7e91384f049..0ed3bda40c4b 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.java @@ -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) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerTest.java index e24f4ca3581d..a95396cccd66 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerTest.java @@ -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();      } |