Update portrait enrollment for UDFPS

Bug: 171353506

Test: No effect on existing devices

Change-Id: I701baf06bf3defde78af50eff5c0e01fafeb07cd
This commit is contained in:
Kevin Chyn
2020-11-30 17:16:00 -08:00
parent 61464f21a5
commit b07e2dbfd3
4 changed files with 223 additions and 5 deletions

View File

@@ -27,6 +27,7 @@ import android.graphics.drawable.AnimatedVectorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.hardware.fingerprint.FingerprintManager;
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
import android.media.AudioAttributes;
import android.os.Bundle;
import android.os.VibrationEffect;
@@ -51,6 +52,8 @@ import com.google.android.setupcompat.template.FooterBarMixin;
import com.google.android.setupcompat.template.FooterButton;
import com.google.android.setupdesign.util.DescriptionStyler;
import java.util.List;
/**
* Activity which handles the actual enrolling for fingerprint.
*/
@@ -130,12 +133,29 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fingerprint_enroll_enrolling);
final FingerprintManager fingerprintManager = getSystemService(FingerprintManager.class);
final List<FingerprintSensorPropertiesInternal> props =
fingerprintManager.getSensorPropertiesInternal();
final boolean canAssumeUdfps = props.size() == 1 && props.get(0).isAnyUdfpsType();
if (canAssumeUdfps) {
// Use a custom layout since animations, etc must be based off of the sensor's physical
// location.
setContentView(R.layout.udfps_enroll_enrolling);
final UdfpsEnrollLayout udfpsEnrollLayout = (UdfpsEnrollLayout) getLayoutInflater()
.inflate(R.layout.udfps_enroll_layout, null /* root */);
getLayout().addView(udfpsEnrollLayout);
} else {
setContentView(R.layout.fingerprint_enroll_enrolling);
}
setHeaderText(R.string.security_settings_fingerprint_enroll_repeat_title);
mStartMessage = (TextView) findViewById(R.id.sud_layout_description);
mRepeatMessage = (TextView) findViewById(R.id.repeat_message);
mErrorText = (TextView) findViewById(R.id.error_text);
mProgressBar = (ProgressBar) findViewById(R.id.fingerprint_progress_bar);
mStartMessage = findViewById(R.id.sud_layout_description);
mRepeatMessage = findViewById(R.id.repeat_message);
mErrorText = findViewById(R.id.error_text);
mProgressBar = findViewById(R.id.fingerprint_progress_bar);
mVibrator = getSystemService(Vibrator.class);
if (getLayout().shouldApplyPartnerHeavyThemeResource()) {

View File

@@ -0,0 +1,76 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.biometrics.fingerprint;
import android.content.Context;
import android.graphics.Rect;
import android.hardware.fingerprint.FingerprintManager;
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.widget.LinearLayout;
import com.android.settings.R;
public class UdfpsEnrollLayout extends LinearLayout {
private static final String TAG = "UdfpsEnrollLayout";
private final FingerprintSensorPropertiesInternal mSensorProps;
public UdfpsEnrollLayout(Context context, AttributeSet attrs) {
super(context, attrs);
mSensorProps = context.getSystemService(FingerprintManager.class)
.getSensorPropertiesInternal().get(0);
}
@Override
public void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
final View animation = findViewById(R.id.fingerprint_progress_bar);
final WindowManager wm = getContext().getSystemService(WindowManager.class);
final int statusbarHeight = Math.abs(wm.getCurrentWindowMetrics().getWindowInsets()
.getInsets(WindowInsets.Type.statusBars()).toRect().height());
// Calculate the amount of translation required. This is just re-arranged from
// animation.setY(mSensorProps.sensorLocationY-statusbarHeight-mSensorProps.sensorRadius)
// The translationY is the amount of extra height that should be added to the spacer
// above the animation
final int spaceHeight = mSensorProps.sensorLocationY - statusbarHeight
- mSensorProps.sensorRadius - animation.getTop();
animation.setTranslationY(spaceHeight);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
final View animation = findViewById(R.id.fingerprint_progress_bar);
final int sensorDiameter = mSensorProps.sensorRadius * 2;
// Multiply it slightly so that the progress bar is outside the UDFPS affordance, and that
// the animation is within the UDFPS affordance.
final int animationDiameter = (int) (sensorDiameter * 1);
animation.measure(MeasureSpec.makeMeasureSpec(animationDiameter, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(animationDiameter, MeasureSpec.EXACTLY));
}
}