Move Fingerprint settings to biometrics/fingerprint
Bug: 110589286 Test: make -j56 RunSettingsRoboTests Test: adb shell am start -a android.settings.FINGERPRINT_ENROLL still works Test: adb shell am start -a android.settings.FINGERPRINT_SETUP still works Change-Id: If33b557137cae7b57e4a0e906ee95032bc589436
This commit is contained in:
6
src/com/android/settings/biometrics/OWNERS
Normal file
6
src/com/android/settings/biometrics/OWNERS
Normal file
@@ -0,0 +1,6 @@
|
||||
# Default reviewers for this and subdirectories.
|
||||
jaggies@google.com
|
||||
kchyn@google.com
|
||||
yukl@google.com
|
||||
|
||||
# Emergency approvers in case the above are not available
|
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.hardware.fingerprint.FingerprintManager;
|
||||
import android.hardware.fingerprint.FingerprintManager.AuthenticationResult;
|
||||
import android.os.CancellationSignal;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.core.InstrumentedFragment;
|
||||
|
||||
/**
|
||||
* Sidecar fragment to handle the state around fingerprint authentication
|
||||
*/
|
||||
public class FingerprintAuthenticateSidecar extends InstrumentedFragment {
|
||||
|
||||
private static final String TAG = "FingerprintAuthenticateSidecar";
|
||||
|
||||
private FingerprintManager mFingerprintManager;
|
||||
private Listener mListener;
|
||||
private AuthenticationResult mAuthenticationResult;
|
||||
private CancellationSignal mCancellationSignal;
|
||||
private AuthenticationError mAuthenticationError;
|
||||
|
||||
public interface Listener {
|
||||
void onAuthenticationSucceeded(AuthenticationResult result);
|
||||
void onAuthenticationFailed();
|
||||
void onAuthenticationError(int errMsgId, CharSequence errString);
|
||||
void onAuthenticationHelp(int helpMsgId, CharSequence helpString);
|
||||
}
|
||||
|
||||
private class AuthenticationError {
|
||||
int error;
|
||||
CharSequence errorString;
|
||||
|
||||
public AuthenticationError(int errMsgId, CharSequence errString) {
|
||||
error = errMsgId;
|
||||
errorString = errString;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.FINGERPRINT_AUTHENTICATE_SIDECAR;
|
||||
}
|
||||
|
||||
private FingerprintManager.AuthenticationCallback mAuthenticationCallback =
|
||||
new FingerprintManager.AuthenticationCallback() {
|
||||
@Override
|
||||
public void onAuthenticationSucceeded(AuthenticationResult result) {
|
||||
mCancellationSignal = null;
|
||||
if (mListener != null) {
|
||||
mListener.onAuthenticationSucceeded(result);
|
||||
} else {
|
||||
mAuthenticationResult = result;
|
||||
mAuthenticationError = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationFailed() {
|
||||
if (mListener != null) {
|
||||
mListener.onAuthenticationFailed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationError(int errMsgId, CharSequence errString) {
|
||||
mCancellationSignal = null;
|
||||
if (mListener != null) {
|
||||
mListener.onAuthenticationError(errMsgId, errString);
|
||||
} else {
|
||||
mAuthenticationError = new AuthenticationError(errMsgId, errString);
|
||||
mAuthenticationResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
|
||||
if (mListener != null) {
|
||||
mListener.onAuthenticationHelp(helpMsgId, helpString);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public void setFingerprintManager(FingerprintManager fingerprintManager) {
|
||||
mFingerprintManager = fingerprintManager;
|
||||
}
|
||||
|
||||
public void startAuthentication(int userId) {
|
||||
mCancellationSignal = new CancellationSignal();
|
||||
mFingerprintManager.authenticate(null, mCancellationSignal, 0 /* flags */,
|
||||
mAuthenticationCallback, null, userId);
|
||||
}
|
||||
|
||||
public void stopAuthentication() {
|
||||
if (mCancellationSignal != null && !mCancellationSignal.isCanceled()) {
|
||||
mCancellationSignal.cancel();
|
||||
}
|
||||
mCancellationSignal = null;
|
||||
}
|
||||
|
||||
public void setListener(Listener listener) {
|
||||
if (mListener == null && listener != null) {
|
||||
if (mAuthenticationResult != null) {
|
||||
listener.onAuthenticationSucceeded(mAuthenticationResult);
|
||||
mAuthenticationResult = null;
|
||||
}
|
||||
if (mAuthenticationError != null &&
|
||||
mAuthenticationError.error != FingerprintManager.FINGERPRINT_ERROR_CANCELED) {
|
||||
listener.onAuthenticationError(mAuthenticationError.error,
|
||||
mAuthenticationError.errorString);
|
||||
mAuthenticationError = null;
|
||||
}
|
||||
}
|
||||
mListener = listener;
|
||||
}
|
||||
}
|
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.annotation.Nullable;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SetupWizardUtils;
|
||||
import com.android.settings.core.InstrumentedActivity;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
import com.android.setupwizardlib.GlifLayout;
|
||||
|
||||
/**
|
||||
* Base activity for all fingerprint enrollment steps.
|
||||
*/
|
||||
public abstract class FingerprintEnrollBase extends InstrumentedActivity
|
||||
implements View.OnClickListener {
|
||||
public static final int RESULT_FINISHED = FingerprintSettings.RESULT_FINISHED;
|
||||
static final int RESULT_SKIP = FingerprintSettings.RESULT_SKIP;
|
||||
static final int RESULT_TIMEOUT = FingerprintSettings.RESULT_TIMEOUT;
|
||||
|
||||
protected byte[] mToken;
|
||||
protected int mUserId;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mToken = getIntent().getByteArrayExtra(
|
||||
ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
|
||||
if (savedInstanceState != null && mToken == null) {
|
||||
mToken = savedInstanceState.getByteArray(
|
||||
ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
|
||||
}
|
||||
mUserId = getIntent().getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
|
||||
resid = SetupWizardUtils.getTheme(getIntent());
|
||||
super.onApplyThemeResource(theme, resid, first);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putByteArray(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
initViews();
|
||||
}
|
||||
|
||||
protected void initViews() {
|
||||
getWindow().setStatusBarColor(Color.TRANSPARENT);
|
||||
Button nextButton = getNextButton();
|
||||
if (nextButton != null) {
|
||||
nextButton.setOnClickListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
protected GlifLayout getLayout() {
|
||||
return (GlifLayout) findViewById(R.id.setup_wizard_layout);
|
||||
}
|
||||
|
||||
protected void setHeaderText(int resId, boolean force) {
|
||||
TextView layoutTitle = getLayout().getHeaderTextView();
|
||||
CharSequence previousTitle = layoutTitle.getText();
|
||||
CharSequence title = getText(resId);
|
||||
if (previousTitle != title || force) {
|
||||
if (!TextUtils.isEmpty(previousTitle)) {
|
||||
layoutTitle.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE);
|
||||
}
|
||||
getLayout().setHeaderText(title);
|
||||
setTitle(title);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setHeaderText(int resId) {
|
||||
setHeaderText(resId, false /* force */);
|
||||
}
|
||||
|
||||
protected Button getNextButton() {
|
||||
return (Button) findViewById(R.id.next_button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == getNextButton()) {
|
||||
onNextButtonClick();
|
||||
}
|
||||
}
|
||||
|
||||
protected void onNextButtonClick() {
|
||||
}
|
||||
|
||||
protected Intent getEnrollingIntent() {
|
||||
Intent intent = new Intent();
|
||||
intent.setClassName("com.android.settings", FingerprintEnrollEnrolling.class.getName());
|
||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
|
||||
if (mUserId != UserHandle.USER_NULL) {
|
||||
intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
|
||||
}
|
||||
return intent;
|
||||
}
|
||||
}
|
@@ -0,0 +1,507 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.animation.Animator;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Animatable2;
|
||||
import android.graphics.drawable.AnimatedVectorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.media.AudioAttributes;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.VibrationEffect;
|
||||
import android.os.Vibrator;
|
||||
import android.text.TextUtils;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
|
||||
/**
|
||||
* Activity which handles the actual enrolling for fingerprint.
|
||||
*/
|
||||
public class FingerprintEnrollEnrolling extends FingerprintEnrollBase
|
||||
implements FingerprintEnrollSidecar.Listener {
|
||||
|
||||
static final String TAG_SIDECAR = "sidecar";
|
||||
|
||||
private static final int PROGRESS_BAR_MAX = 10000;
|
||||
private static final int FINISH_DELAY = 250;
|
||||
|
||||
/**
|
||||
* If we don't see progress during this time, we show an error message to remind the user that
|
||||
* he needs to lift the finger and touch again.
|
||||
*/
|
||||
private static final int HINT_TIMEOUT_DURATION = 2500;
|
||||
|
||||
/**
|
||||
* How long the user needs to touch the icon until we show the dialog.
|
||||
*/
|
||||
private static final long ICON_TOUCH_DURATION_UNTIL_DIALOG_SHOWN = 500;
|
||||
|
||||
/**
|
||||
* How many times the user needs to touch the icon until we show the dialog that this is not the
|
||||
* fingerprint sensor.
|
||||
*/
|
||||
private static final int ICON_TOUCH_COUNT_SHOW_UNTIL_DIALOG_SHOWN = 3;
|
||||
|
||||
private static final VibrationEffect VIBRATE_EFFECT_ERROR =
|
||||
VibrationEffect.createWaveform(new long[] {0, 5, 55, 60}, -1);
|
||||
private static final AudioAttributes FINGERPRINT_ENROLLING_SONFICATION_ATTRIBUTES =
|
||||
new AudioAttributes.Builder()
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
||||
.setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
|
||||
.build();
|
||||
|
||||
private ProgressBar mProgressBar;
|
||||
private ObjectAnimator mProgressAnim;
|
||||
private TextView mStartMessage;
|
||||
private TextView mRepeatMessage;
|
||||
private TextView mErrorText;
|
||||
private Interpolator mFastOutSlowInInterpolator;
|
||||
private Interpolator mLinearOutSlowInInterpolator;
|
||||
private Interpolator mFastOutLinearInInterpolator;
|
||||
private int mIconTouchCount;
|
||||
private FingerprintEnrollSidecar mSidecar;
|
||||
private boolean mAnimationCancelled;
|
||||
private AnimatedVectorDrawable mIconAnimationDrawable;
|
||||
private AnimatedVectorDrawable mIconBackgroundBlinksDrawable;
|
||||
private boolean mRestoring;
|
||||
private Vibrator mVibrator;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.fingerprint_enroll_enrolling);
|
||||
setHeaderText(R.string.security_settings_fingerprint_enroll_repeat_title);
|
||||
mStartMessage = (TextView) findViewById(R.id.start_message);
|
||||
mRepeatMessage = (TextView) findViewById(R.id.repeat_message);
|
||||
mErrorText = (TextView) findViewById(R.id.error_text);
|
||||
mProgressBar = (ProgressBar) findViewById(R.id.fingerprint_progress_bar);
|
||||
mVibrator = getSystemService(Vibrator.class);
|
||||
|
||||
Button skipButton = findViewById(R.id.skip_button);
|
||||
skipButton.setOnClickListener(this);
|
||||
|
||||
final LayerDrawable fingerprintDrawable = (LayerDrawable) mProgressBar.getBackground();
|
||||
mIconAnimationDrawable = (AnimatedVectorDrawable)
|
||||
fingerprintDrawable.findDrawableByLayerId(R.id.fingerprint_animation);
|
||||
mIconBackgroundBlinksDrawable = (AnimatedVectorDrawable)
|
||||
fingerprintDrawable.findDrawableByLayerId(R.id.fingerprint_background);
|
||||
mIconAnimationDrawable.registerAnimationCallback(mIconAnimationCallback);
|
||||
mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(
|
||||
this, android.R.interpolator.fast_out_slow_in);
|
||||
mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(
|
||||
this, android.R.interpolator.linear_out_slow_in);
|
||||
mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(
|
||||
this, android.R.interpolator.fast_out_linear_in);
|
||||
mProgressBar.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
||||
mIconTouchCount++;
|
||||
if (mIconTouchCount == ICON_TOUCH_COUNT_SHOW_UNTIL_DIALOG_SHOWN) {
|
||||
showIconTouchDialog();
|
||||
} else {
|
||||
mProgressBar.postDelayed(mShowDialogRunnable,
|
||||
ICON_TOUCH_DURATION_UNTIL_DIALOG_SHOWN);
|
||||
}
|
||||
} else if (event.getActionMasked() == MotionEvent.ACTION_CANCEL
|
||||
|| event.getActionMasked() == MotionEvent.ACTION_UP) {
|
||||
mProgressBar.removeCallbacks(mShowDialogRunnable);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
mRestoring = savedInstanceState != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mSidecar = (FingerprintEnrollSidecar) getFragmentManager().findFragmentByTag(TAG_SIDECAR);
|
||||
if (mSidecar == null) {
|
||||
mSidecar = new FingerprintEnrollSidecar();
|
||||
getFragmentManager().beginTransaction().add(mSidecar, TAG_SIDECAR).commit();
|
||||
}
|
||||
mSidecar.setListener(this);
|
||||
updateProgress(false /* animate */);
|
||||
updateDescription();
|
||||
if (mRestoring) {
|
||||
startIconAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnterAnimationComplete() {
|
||||
super.onEnterAnimationComplete();
|
||||
mAnimationCancelled = false;
|
||||
startIconAnimation();
|
||||
}
|
||||
|
||||
private void startIconAnimation() {
|
||||
mIconAnimationDrawable.start();
|
||||
}
|
||||
|
||||
private void stopIconAnimation() {
|
||||
mAnimationCancelled = true;
|
||||
mIconAnimationDrawable.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
if (mSidecar != null) {
|
||||
mSidecar.setListener(null);
|
||||
}
|
||||
stopIconAnimation();
|
||||
if (!isChangingConfigurations()) {
|
||||
if (mSidecar != null) {
|
||||
mSidecar.cancelEnrollment();
|
||||
getFragmentManager().beginTransaction().remove(mSidecar).commitAllowingStateLoss();
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (mSidecar != null) {
|
||||
mSidecar.setListener(null);
|
||||
mSidecar.cancelEnrollment();
|
||||
getFragmentManager().beginTransaction().remove(mSidecar).commitAllowingStateLoss();
|
||||
mSidecar = null;
|
||||
}
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.skip_button:
|
||||
setResult(RESULT_SKIP);
|
||||
finish();
|
||||
break;
|
||||
default:
|
||||
super.onClick(v);
|
||||
}
|
||||
}
|
||||
|
||||
private void animateProgress(int progress) {
|
||||
if (mProgressAnim != null) {
|
||||
mProgressAnim.cancel();
|
||||
}
|
||||
ObjectAnimator anim = ObjectAnimator.ofInt(mProgressBar, "progress",
|
||||
mProgressBar.getProgress(), progress);
|
||||
anim.addListener(mProgressAnimationListener);
|
||||
anim.setInterpolator(mFastOutSlowInInterpolator);
|
||||
anim.setDuration(250);
|
||||
anim.start();
|
||||
mProgressAnim = anim;
|
||||
}
|
||||
|
||||
private void animateFlash() {
|
||||
mIconBackgroundBlinksDrawable.start();
|
||||
}
|
||||
|
||||
private void launchFinish(byte[] token) {
|
||||
Intent intent = getFinishIntent();
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token);
|
||||
if (mUserId != UserHandle.USER_NULL) {
|
||||
intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
|
||||
}
|
||||
startActivity(intent);
|
||||
overridePendingTransition(R.anim.suw_slide_next_in, R.anim.suw_slide_next_out);
|
||||
finish();
|
||||
}
|
||||
|
||||
protected Intent getFinishIntent() {
|
||||
return new Intent(this, FingerprintEnrollFinish.class);
|
||||
}
|
||||
|
||||
private void updateDescription() {
|
||||
if (mSidecar.getEnrollmentSteps() == -1) {
|
||||
mStartMessage.setVisibility(View.VISIBLE);
|
||||
mRepeatMessage.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
mStartMessage.setVisibility(View.INVISIBLE);
|
||||
mRepeatMessage.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnrollmentHelp(CharSequence helpString) {
|
||||
if (!TextUtils.isEmpty(helpString)) {
|
||||
mErrorText.removeCallbacks(mTouchAgainRunnable);
|
||||
showError(helpString);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnrollmentError(int errMsgId, CharSequence errString) {
|
||||
int msgId;
|
||||
switch (errMsgId) {
|
||||
case FingerprintManager.FINGERPRINT_ERROR_TIMEOUT:
|
||||
// This message happens when the underlying crypto layer decides to revoke the
|
||||
// enrollment auth token.
|
||||
msgId = R.string.security_settings_fingerprint_enroll_error_timeout_dialog_message;
|
||||
break;
|
||||
default:
|
||||
// There's nothing specific to tell the user about. Ask them to try again.
|
||||
msgId = R.string.security_settings_fingerprint_enroll_error_generic_dialog_message;
|
||||
break;
|
||||
}
|
||||
showErrorDialog(getText(msgId), errMsgId);
|
||||
stopIconAnimation();
|
||||
mErrorText.removeCallbacks(mTouchAgainRunnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnrollmentProgressChange(int steps, int remaining) {
|
||||
updateProgress(true /* animate */);
|
||||
updateDescription();
|
||||
clearError();
|
||||
animateFlash();
|
||||
mErrorText.removeCallbacks(mTouchAgainRunnable);
|
||||
mErrorText.postDelayed(mTouchAgainRunnable, HINT_TIMEOUT_DURATION);
|
||||
}
|
||||
|
||||
private void updateProgress(boolean animate) {
|
||||
int progress = getProgress(
|
||||
mSidecar.getEnrollmentSteps(), mSidecar.getEnrollmentRemaining());
|
||||
if (animate) {
|
||||
animateProgress(progress);
|
||||
} else {
|
||||
mProgressBar.setProgress(progress);
|
||||
if (progress >= PROGRESS_BAR_MAX) {
|
||||
mDelayedFinishRunnable.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getProgress(int steps, int remaining) {
|
||||
if (steps == -1) {
|
||||
return 0;
|
||||
}
|
||||
int progress = Math.max(0, steps + 1 - remaining);
|
||||
return PROGRESS_BAR_MAX * progress / (steps + 1);
|
||||
}
|
||||
|
||||
private void showErrorDialog(CharSequence msg, int msgId) {
|
||||
ErrorDialog dlg = ErrorDialog.newInstance(msg, msgId);
|
||||
dlg.show(getFragmentManager(), ErrorDialog.class.getName());
|
||||
}
|
||||
|
||||
private void showIconTouchDialog() {
|
||||
mIconTouchCount = 0;
|
||||
new IconTouchDialog().show(getFragmentManager(), null /* tag */);
|
||||
}
|
||||
|
||||
private void showError(CharSequence error) {
|
||||
mErrorText.setText(error);
|
||||
if (mErrorText.getVisibility() == View.INVISIBLE) {
|
||||
mErrorText.setVisibility(View.VISIBLE);
|
||||
mErrorText.setTranslationY(getResources().getDimensionPixelSize(
|
||||
R.dimen.fingerprint_error_text_appear_distance));
|
||||
mErrorText.setAlpha(0f);
|
||||
mErrorText.animate()
|
||||
.alpha(1f)
|
||||
.translationY(0f)
|
||||
.setDuration(200)
|
||||
.setInterpolator(mLinearOutSlowInInterpolator)
|
||||
.start();
|
||||
} else {
|
||||
mErrorText.animate().cancel();
|
||||
mErrorText.setAlpha(1f);
|
||||
mErrorText.setTranslationY(0f);
|
||||
}
|
||||
if (isResumed()) {
|
||||
mVibrator.vibrate(VIBRATE_EFFECT_ERROR, FINGERPRINT_ENROLLING_SONFICATION_ATTRIBUTES);
|
||||
}
|
||||
}
|
||||
|
||||
private void clearError() {
|
||||
if (mErrorText.getVisibility() == View.VISIBLE) {
|
||||
mErrorText.animate()
|
||||
.alpha(0f)
|
||||
.translationY(getResources().getDimensionPixelSize(
|
||||
R.dimen.fingerprint_error_text_disappear_distance))
|
||||
.setDuration(100)
|
||||
.setInterpolator(mFastOutLinearInInterpolator)
|
||||
.withEndAction(() -> mErrorText.setVisibility(View.INVISIBLE))
|
||||
.start();
|
||||
}
|
||||
}
|
||||
|
||||
private final Animator.AnimatorListener mProgressAnimationListener
|
||||
= new Animator.AnimatorListener() {
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) { }
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) { }
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
if (mProgressBar.getProgress() >= PROGRESS_BAR_MAX) {
|
||||
mProgressBar.postDelayed(mDelayedFinishRunnable, FINISH_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) { }
|
||||
};
|
||||
|
||||
// Give the user a chance to see progress completed before jumping to the next stage.
|
||||
private final Runnable mDelayedFinishRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
launchFinish(mToken);
|
||||
}
|
||||
};
|
||||
|
||||
private final Animatable2.AnimationCallback mIconAnimationCallback =
|
||||
new Animatable2.AnimationCallback() {
|
||||
@Override
|
||||
public void onAnimationEnd(Drawable d) {
|
||||
if (mAnimationCancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Start animation after it has ended.
|
||||
mProgressBar.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startIconAnimation();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
private final Runnable mShowDialogRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showIconTouchDialog();
|
||||
}
|
||||
};
|
||||
|
||||
private final Runnable mTouchAgainRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showError(getString(R.string.security_settings_fingerprint_enroll_lift_touch_again));
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.FINGERPRINT_ENROLLING;
|
||||
}
|
||||
|
||||
public static class IconTouchDialog extends InstrumentedDialogFragment {
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setTitle(R.string.security_settings_fingerprint_enroll_touch_dialog_title)
|
||||
.setMessage(R.string.security_settings_fingerprint_enroll_touch_dialog_message)
|
||||
.setPositiveButton(R.string.security_settings_fingerprint_enroll_dialog_ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.DIALOG_FINGERPRINT_ICON_TOUCH;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ErrorDialog extends InstrumentedDialogFragment {
|
||||
|
||||
/**
|
||||
* Create a new instance of ErrorDialog.
|
||||
*
|
||||
* @param msg the string to show for message text
|
||||
* @param msgId the FingerprintManager error id so we know the cause
|
||||
* @return a new ErrorDialog
|
||||
*/
|
||||
static ErrorDialog newInstance(CharSequence msg, int msgId) {
|
||||
ErrorDialog dlg = new ErrorDialog();
|
||||
Bundle args = new Bundle();
|
||||
args.putCharSequence("error_msg", msg);
|
||||
args.putInt("error_id", msgId);
|
||||
dlg.setArguments(args);
|
||||
return dlg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
CharSequence errorString = getArguments().getCharSequence("error_msg");
|
||||
final int errMsgId = getArguments().getInt("error_id");
|
||||
builder.setTitle(R.string.security_settings_fingerprint_enroll_error_dialog_title)
|
||||
.setMessage(errorString)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.security_settings_fingerprint_enroll_dialog_ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
boolean wasTimeout =
|
||||
errMsgId == FingerprintManager.FINGERPRINT_ERROR_TIMEOUT;
|
||||
Activity activity = getActivity();
|
||||
activity.setResult(wasTimeout ?
|
||||
RESULT_TIMEOUT : RESULT_FINISHED);
|
||||
activity.finish();
|
||||
}
|
||||
});
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.DIALOG_FINGERPINT_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.Intent;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.biometrics.fingerprint.FingerprintEnrollSidecar.Listener;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Activity explaining the fingerprint sensor location for fingerprint enrollment.
|
||||
*/
|
||||
public class FingerprintEnrollFindSensor extends FingerprintEnrollBase {
|
||||
|
||||
@VisibleForTesting
|
||||
static final int CONFIRM_REQUEST = 1;
|
||||
private static final int ENROLLING = 2;
|
||||
public static final String EXTRA_KEY_LAUNCHED_CONFIRM = "launched_confirm_lock";
|
||||
|
||||
@Nullable
|
||||
private FingerprintFindSensorAnimation mAnimation;
|
||||
private boolean mLaunchedConfirmLock;
|
||||
private FingerprintEnrollSidecar mSidecar;
|
||||
private boolean mNextClicked;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(getContentView());
|
||||
Button skipButton = findViewById(R.id.skip_button);
|
||||
skipButton.setOnClickListener(this);
|
||||
|
||||
setHeaderText(R.string.security_settings_fingerprint_enroll_find_sensor_title);
|
||||
if (savedInstanceState != null) {
|
||||
mLaunchedConfirmLock = savedInstanceState.getBoolean(EXTRA_KEY_LAUNCHED_CONFIRM);
|
||||
mToken = savedInstanceState.getByteArray(
|
||||
ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
|
||||
}
|
||||
if (mToken == null && !mLaunchedConfirmLock) {
|
||||
launchConfirmLock();
|
||||
} else if (mToken != null) {
|
||||
startLookingForFingerprint(); // already confirmed, so start looking for fingerprint
|
||||
}
|
||||
View animationView = findViewById(R.id.fingerprint_sensor_location_animation);
|
||||
if (animationView instanceof FingerprintFindSensorAnimation) {
|
||||
mAnimation = (FingerprintFindSensorAnimation) animationView;
|
||||
} else {
|
||||
mAnimation = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected int getContentView() {
|
||||
return R.layout.fingerprint_enroll_find_sensor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
if (mAnimation != null) {
|
||||
mAnimation.startAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
private void startLookingForFingerprint() {
|
||||
mSidecar = (FingerprintEnrollSidecar) getFragmentManager().findFragmentByTag(
|
||||
FingerprintEnrollEnrolling.TAG_SIDECAR);
|
||||
if (mSidecar == null) {
|
||||
mSidecar = new FingerprintEnrollSidecar();
|
||||
getFragmentManager().beginTransaction()
|
||||
.add(mSidecar, FingerprintEnrollEnrolling.TAG_SIDECAR).commit();
|
||||
}
|
||||
mSidecar.setListener(new Listener() {
|
||||
@Override
|
||||
public void onEnrollmentProgressChange(int steps, int remaining) {
|
||||
mNextClicked = true;
|
||||
proceedToEnrolling(true /* cancelEnrollment */);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnrollmentHelp(CharSequence helpString) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnrollmentError(int errMsgId, CharSequence errString) {
|
||||
if (mNextClicked && errMsgId == FingerprintManager.FINGERPRINT_ERROR_CANCELED) {
|
||||
mNextClicked = false;
|
||||
proceedToEnrolling(false /* cancelEnrollment */);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
if (mAnimation != null) {
|
||||
mAnimation.pauseAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mAnimation != null) {
|
||||
mAnimation.stopAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBoolean(EXTRA_KEY_LAUNCHED_CONFIRM, mLaunchedConfirmLock);
|
||||
outState.putByteArray(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.skip_button:
|
||||
onSkipButtonClick();
|
||||
break;
|
||||
default:
|
||||
super.onClick(v);
|
||||
}
|
||||
}
|
||||
|
||||
protected void onSkipButtonClick() {
|
||||
setResult(RESULT_SKIP);
|
||||
finish();
|
||||
}
|
||||
|
||||
private void proceedToEnrolling(boolean cancelEnrollment) {
|
||||
if (mSidecar != null) {
|
||||
if (cancelEnrollment) {
|
||||
if (mSidecar.cancelEnrollment()) {
|
||||
// Enrollment cancel requested. When the cancellation is successful,
|
||||
// onEnrollmentError will be called with FINGERPRINT_ERROR_CANCELED, calling
|
||||
// this again.
|
||||
return;
|
||||
}
|
||||
}
|
||||
getFragmentManager().beginTransaction().remove(mSidecar).commitAllowingStateLoss();
|
||||
mSidecar = null;
|
||||
startActivityForResult(getEnrollingIntent(), ENROLLING);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == CONFIRM_REQUEST) {
|
||||
if (resultCode == RESULT_OK && data != null) {
|
||||
mToken = data.getByteArrayExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
|
||||
overridePendingTransition(R.anim.suw_slide_next_in, R.anim.suw_slide_next_out);
|
||||
getIntent().putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
|
||||
startLookingForFingerprint();
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
} else if (requestCode == ENROLLING) {
|
||||
if (resultCode == RESULT_FINISHED) {
|
||||
setResult(RESULT_FINISHED);
|
||||
finish();
|
||||
} else if (resultCode == RESULT_SKIP) {
|
||||
setResult(RESULT_SKIP);
|
||||
finish();
|
||||
} else if (resultCode == RESULT_TIMEOUT) {
|
||||
setResult(RESULT_TIMEOUT);
|
||||
finish();
|
||||
} else {
|
||||
FingerprintManager fpm = Utils.getFingerprintManagerOrNull(this);
|
||||
int enrolled = fpm.getEnrolledFingerprints().size();
|
||||
int max = getResources().getInteger(
|
||||
com.android.internal.R.integer.config_fingerprintMaxTemplatesPerUser);
|
||||
if (enrolled >= max) {
|
||||
finish();
|
||||
} else {
|
||||
// We came back from enrolling but it wasn't completed, start again.
|
||||
startLookingForFingerprint();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
private void launchConfirmLock() {
|
||||
long challenge = Utils.getFingerprintManagerOrNull(this).preEnroll();
|
||||
ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(this);
|
||||
boolean launchedConfirmationActivity = false;
|
||||
if (mUserId == UserHandle.USER_NULL) {
|
||||
launchedConfirmationActivity = helper.launchConfirmationActivity(CONFIRM_REQUEST,
|
||||
getString(R.string.security_settings_fingerprint_preference_title),
|
||||
null, null, challenge);
|
||||
} else {
|
||||
launchedConfirmationActivity = helper.launchConfirmationActivity(CONFIRM_REQUEST,
|
||||
getString(R.string.security_settings_fingerprint_preference_title),
|
||||
null, null, challenge, mUserId);
|
||||
}
|
||||
if (!launchedConfirmationActivity) {
|
||||
// This shouldn't happen, as we should only end up at this step if a lock thingy is
|
||||
// already set.
|
||||
finish();
|
||||
} else {
|
||||
mLaunchedConfirmLock = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.FINGERPRINT_FIND_SENSOR;
|
||||
}
|
||||
}
|
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.Intent;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
/**
|
||||
* Activity which concludes fingerprint enrollment.
|
||||
*/
|
||||
public class FingerprintEnrollFinish extends FingerprintEnrollBase {
|
||||
|
||||
private static final int REQUEST_ADD_ANOTHER = 1;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.fingerprint_enroll_finish);
|
||||
setHeaderText(R.string.security_settings_fingerprint_enroll_finish_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
Button addButton = (Button) findViewById(R.id.add_another_button);
|
||||
|
||||
final FingerprintManager fpm = Utils.getFingerprintManagerOrNull(this);
|
||||
boolean hideAddAnother = false;
|
||||
if (fpm != null) {
|
||||
int enrolled = fpm.getEnrolledFingerprints(mUserId).size();
|
||||
int max = getResources().getInteger(
|
||||
com.android.internal.R.integer.config_fingerprintMaxTemplatesPerUser);
|
||||
hideAddAnother = enrolled >= max;
|
||||
}
|
||||
if (hideAddAnother) {
|
||||
// Don't show "Add" button if too many fingerprints already added
|
||||
addButton.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
addButton.setOnClickListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNextButtonClick() {
|
||||
setResult(RESULT_FINISHED);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.getId() == R.id.add_another_button) {
|
||||
startActivityForResult(getEnrollingIntent(), REQUEST_ADD_ANOTHER);
|
||||
}
|
||||
super.onClick(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == REQUEST_ADD_ANOTHER && resultCode != RESULT_CANCELED) {
|
||||
setResult(resultCode, data);
|
||||
finish();
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.FINGERPRINT_ENROLL_FINISH;
|
||||
}
|
||||
}
|
@@ -0,0 +1,233 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.app.admin.DevicePolicyManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.password.ChooseLockGeneric;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
import com.android.settingslib.HelpUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.setupwizardlib.span.LinkSpan;
|
||||
|
||||
/**
|
||||
* Onboarding activity for fingerprint enrollment.
|
||||
*/
|
||||
public class FingerprintEnrollIntroduction extends FingerprintEnrollBase
|
||||
implements View.OnClickListener, LinkSpan.OnClickListener {
|
||||
|
||||
private static final String TAG = "FingerprintIntro";
|
||||
|
||||
protected static final int CHOOSE_LOCK_GENERIC_REQUEST = 1;
|
||||
protected static final int FINGERPRINT_FIND_SENSOR_REQUEST = 2;
|
||||
protected static final int LEARN_MORE_REQUEST = 3;
|
||||
|
||||
private UserManager mUserManager;
|
||||
private boolean mHasPassword;
|
||||
private boolean mFingerprintUnlockDisabledByAdmin;
|
||||
private TextView mErrorText;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mFingerprintUnlockDisabledByAdmin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
|
||||
this, DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT, mUserId) != null;
|
||||
|
||||
setContentView(R.layout.fingerprint_enroll_introduction);
|
||||
if (mFingerprintUnlockDisabledByAdmin) {
|
||||
setHeaderText(R.string
|
||||
.security_settings_fingerprint_enroll_introduction_title_unlock_disabled);
|
||||
} else {
|
||||
setHeaderText(R.string.security_settings_fingerprint_enroll_introduction_title);
|
||||
}
|
||||
|
||||
Button cancelButton = (Button) findViewById(R.id.fingerprint_cancel_button);
|
||||
cancelButton.setOnClickListener(this);
|
||||
|
||||
mErrorText = (TextView) findViewById(R.id.error_text);
|
||||
|
||||
mUserManager = UserManager.get(this);
|
||||
updatePasswordQuality();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
final FingerprintManager fingerprintManager = Utils.getFingerprintManagerOrNull(this);
|
||||
int errorMsg = 0;
|
||||
if (fingerprintManager != null) {
|
||||
final int max = getResources().getInteger(
|
||||
com.android.internal.R.integer.config_fingerprintMaxTemplatesPerUser);
|
||||
final int numEnrolledFingerprints =
|
||||
fingerprintManager.getEnrolledFingerprints(mUserId).size();
|
||||
if (numEnrolledFingerprints >= max) {
|
||||
errorMsg = R.string.fingerprint_intro_error_max;
|
||||
}
|
||||
} else {
|
||||
errorMsg = R.string.fingerprint_intro_error_unknown;
|
||||
}
|
||||
if (errorMsg == 0) {
|
||||
mErrorText.setText(null);
|
||||
getNextButton().setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mErrorText.setText(errorMsg);
|
||||
getNextButton().setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePasswordQuality() {
|
||||
final int passwordQuality = new ChooseLockSettingsHelper(this).utils()
|
||||
.getActivePasswordQuality(mUserManager.getCredentialOwnerProfile(mUserId));
|
||||
mHasPassword = passwordQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Button getNextButton() {
|
||||
return (Button) findViewById(R.id.fingerprint_next_button);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNextButtonClick() {
|
||||
if (!mHasPassword) {
|
||||
// No fingerprints registered, launch into enrollment wizard.
|
||||
launchChooseLock();
|
||||
} else {
|
||||
// Lock thingy is already set up, launch directly into find sensor step from wizard.
|
||||
launchFindSensor(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void launchChooseLock() {
|
||||
Intent intent = getChooseLockIntent();
|
||||
long challenge = Utils.getFingerprintManagerOrNull(this).preEnroll();
|
||||
intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.MINIMUM_QUALITY_KEY,
|
||||
DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
|
||||
intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.HIDE_DISABLED_PREFS, true);
|
||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, true);
|
||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge);
|
||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, true);
|
||||
if (mUserId != UserHandle.USER_NULL) {
|
||||
intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
|
||||
}
|
||||
startActivityForResult(intent, CHOOSE_LOCK_GENERIC_REQUEST);
|
||||
}
|
||||
|
||||
private void launchFindSensor(byte[] token) {
|
||||
Intent intent = getFindSensorIntent();
|
||||
if (token != null) {
|
||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token);
|
||||
}
|
||||
if (mUserId != UserHandle.USER_NULL) {
|
||||
intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
|
||||
}
|
||||
startActivityForResult(intent, FINGERPRINT_FIND_SENSOR_REQUEST);
|
||||
}
|
||||
|
||||
protected Intent getChooseLockIntent() {
|
||||
return new Intent(this, ChooseLockGeneric.class);
|
||||
}
|
||||
|
||||
protected Intent getFindSensorIntent() {
|
||||
return new Intent(this, FingerprintEnrollFindSensor.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
final boolean isResultFinished = resultCode == RESULT_FINISHED;
|
||||
if (requestCode == FINGERPRINT_FIND_SENSOR_REQUEST) {
|
||||
if (isResultFinished || resultCode == RESULT_SKIP) {
|
||||
final int result = isResultFinished ? RESULT_OK : RESULT_SKIP;
|
||||
setResult(result, data);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
} else if (requestCode == CHOOSE_LOCK_GENERIC_REQUEST) {
|
||||
if (isResultFinished) {
|
||||
updatePasswordQuality();
|
||||
byte[] token = data.getByteArrayExtra(
|
||||
ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
|
||||
launchFindSensor(token);
|
||||
return;
|
||||
}
|
||||
} else if (requestCode == LEARN_MORE_REQUEST) {
|
||||
overridePendingTransition(R.anim.suw_slide_back_in, R.anim.suw_slide_back_out);
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.getId() == R.id.fingerprint_cancel_button) {
|
||||
onCancelButtonClick();
|
||||
} else {
|
||||
super.onClick(v);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.FINGERPRINT_ENROLL_INTRO;
|
||||
}
|
||||
|
||||
protected void onCancelButtonClick() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
super.initViews();
|
||||
|
||||
TextView description = (TextView) findViewById(R.id.description_text);
|
||||
if (mFingerprintUnlockDisabledByAdmin) {
|
||||
description.setText(R.string
|
||||
.security_settings_fingerprint_enroll_introduction_message_unlock_disabled);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(LinkSpan span) {
|
||||
if ("url".equals(span.getId())) {
|
||||
String url = getString(R.string.help_url_fingerprint);
|
||||
Intent intent = HelpUtils.getHelpIntent(this, url, getClass().getName());
|
||||
if (intent == null) {
|
||||
Log.w(TAG, "Null help intent.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// This needs to be startActivityForResult even though we do not care about the
|
||||
// actual result because the help app needs to know about who invoked it.
|
||||
startActivityForResult(intent, LEARN_MORE_REQUEST);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Log.w(TAG, "Activity was not found for intent, " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.annotation.Nullable;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.CancellationSignal;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.InstrumentedFragment;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Sidecar fragment to handle the state around fingerprint enrollment.
|
||||
*/
|
||||
public class FingerprintEnrollSidecar extends InstrumentedFragment {
|
||||
|
||||
private int mEnrollmentSteps = -1;
|
||||
private int mEnrollmentRemaining = 0;
|
||||
private Listener mListener;
|
||||
private boolean mEnrolling;
|
||||
private CancellationSignal mEnrollmentCancel;
|
||||
private Handler mHandler = new Handler();
|
||||
private byte[] mToken;
|
||||
private boolean mDone;
|
||||
private int mUserId;
|
||||
private FingerprintManager mFingerprintManager;
|
||||
private ArrayList<QueuedEvent> mQueuedEvents;
|
||||
|
||||
private abstract class QueuedEvent {
|
||||
public abstract void send(Listener listener);
|
||||
}
|
||||
|
||||
private class QueuedEnrollmentProgress extends QueuedEvent {
|
||||
int enrollmentSteps;
|
||||
int remaining;
|
||||
public QueuedEnrollmentProgress(int enrollmentSteps, int remaining) {
|
||||
this.enrollmentSteps = enrollmentSteps;
|
||||
this.remaining = remaining;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Listener listener) {
|
||||
listener.onEnrollmentProgressChange(enrollmentSteps, remaining);
|
||||
}
|
||||
}
|
||||
|
||||
private class QueuedEnrollmentHelp extends QueuedEvent {
|
||||
int helpMsgId;
|
||||
CharSequence helpString;
|
||||
public QueuedEnrollmentHelp(int helpMsgId, CharSequence helpString) {
|
||||
this.helpMsgId = helpMsgId;
|
||||
this.helpString = helpString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Listener listener) {
|
||||
listener.onEnrollmentHelp(helpString);
|
||||
}
|
||||
}
|
||||
|
||||
private class QueuedEnrollmentError extends QueuedEvent {
|
||||
int errMsgId;
|
||||
CharSequence errString;
|
||||
public QueuedEnrollmentError(int errMsgId, CharSequence errString) {
|
||||
this.errMsgId = errMsgId;
|
||||
this.errString = errString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Listener listener) {
|
||||
listener.onEnrollmentError(errMsgId, errString);
|
||||
}
|
||||
}
|
||||
|
||||
public FingerprintEnrollSidecar() {
|
||||
mQueuedEvents = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setRetainInstance(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
mFingerprintManager = Utils.getFingerprintManagerOrNull(activity);
|
||||
mToken = activity.getIntent().getByteArrayExtra(
|
||||
ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
|
||||
mUserId = activity.getIntent().getIntExtra(Intent.EXTRA_USER_ID, UserHandle.USER_NULL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (!mEnrolling) {
|
||||
startEnrollment();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
if (!getActivity().isChangingConfigurations()) {
|
||||
cancelEnrollment();
|
||||
}
|
||||
}
|
||||
|
||||
private void startEnrollment() {
|
||||
mHandler.removeCallbacks(mTimeoutRunnable);
|
||||
mEnrollmentSteps = -1;
|
||||
mEnrollmentCancel = new CancellationSignal();
|
||||
if (mUserId != UserHandle.USER_NULL) {
|
||||
mFingerprintManager.setActiveUser(mUserId);
|
||||
}
|
||||
mFingerprintManager.enroll(mToken, mEnrollmentCancel,
|
||||
0 /* flags */, mUserId, mEnrollmentCallback);
|
||||
mEnrolling = true;
|
||||
}
|
||||
|
||||
boolean cancelEnrollment() {
|
||||
mHandler.removeCallbacks(mTimeoutRunnable);
|
||||
if (mEnrolling) {
|
||||
mEnrollmentCancel.cancel();
|
||||
mEnrolling = false;
|
||||
mEnrollmentSteps = -1;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setListener(Listener listener) {
|
||||
mListener = listener;
|
||||
if (mListener != null) {
|
||||
for (int i=0; i<mQueuedEvents.size(); i++) {
|
||||
QueuedEvent event = mQueuedEvents.get(i);
|
||||
event.send(mListener);
|
||||
}
|
||||
mQueuedEvents.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public int getEnrollmentSteps() {
|
||||
return mEnrollmentSteps;
|
||||
}
|
||||
|
||||
public int getEnrollmentRemaining() {
|
||||
return mEnrollmentRemaining;
|
||||
}
|
||||
|
||||
public boolean isDone() {
|
||||
return mDone;
|
||||
}
|
||||
|
||||
private FingerprintManager.EnrollmentCallback mEnrollmentCallback
|
||||
= new FingerprintManager.EnrollmentCallback() {
|
||||
|
||||
@Override
|
||||
public void onEnrollmentProgress(int remaining) {
|
||||
if (mEnrollmentSteps == -1) {
|
||||
mEnrollmentSteps = remaining;
|
||||
}
|
||||
mEnrollmentRemaining = remaining;
|
||||
mDone = remaining == 0;
|
||||
if (mListener != null) {
|
||||
mListener.onEnrollmentProgressChange(mEnrollmentSteps, remaining);
|
||||
} else {
|
||||
mQueuedEvents.add(new QueuedEnrollmentProgress(mEnrollmentSteps, remaining));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnrollmentHelp(int helpMsgId, CharSequence helpString) {
|
||||
if (mListener != null) {
|
||||
mListener.onEnrollmentHelp(helpString);
|
||||
} else {
|
||||
mQueuedEvents.add(new QueuedEnrollmentHelp(helpMsgId, helpString));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnrollmentError(int errMsgId, CharSequence errString) {
|
||||
if (mListener != null) {
|
||||
mListener.onEnrollmentError(errMsgId, errString);
|
||||
} else {
|
||||
mQueuedEvents.add(new QueuedEnrollmentError(errMsgId, errString));
|
||||
}
|
||||
mEnrolling = false;
|
||||
}
|
||||
};
|
||||
|
||||
private final Runnable mTimeoutRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cancelEnrollment();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.FINGERPRINT_ENROLL_SIDECAR;
|
||||
}
|
||||
|
||||
public interface Listener {
|
||||
void onEnrollmentHelp(CharSequence helpString);
|
||||
void onEnrollmentError(int errMsgId, CharSequence errString);
|
||||
void onEnrollmentProgressChange(int steps, int remaining);
|
||||
}
|
||||
|
||||
public boolean isEnrolling() {
|
||||
return mEnrolling;
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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 com.android.settings.Utils;
|
||||
|
||||
public class FingerprintEnrollSuggestionActivity extends FingerprintEnrollIntroduction {
|
||||
|
||||
public static boolean isSuggestionComplete(Context context) {
|
||||
if (!Utils.hasFingerprintHardware(context)
|
||||
|| !FingerprintSuggestionActivity.isFingerprintEnabled(context)
|
||||
|| !Utils.hasFingerprintHardware(context)) {
|
||||
return true;
|
||||
}
|
||||
return Utils.getFingerprintManagerOrNull(context).hasEnrolledFingerprints();
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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;
|
||||
|
||||
/**
|
||||
* An abstraction for a view that contains an animation that shows the user
|
||||
* where the fingerprint sensor is on the device.
|
||||
*/
|
||||
public interface FingerprintFindSensorAnimation {
|
||||
|
||||
/**
|
||||
* Start the animation
|
||||
*/
|
||||
void startAnimation();
|
||||
|
||||
/**
|
||||
* Stop the animation
|
||||
*/
|
||||
void stopAnimation();
|
||||
|
||||
/**
|
||||
* Pause the animation
|
||||
*/
|
||||
void pauseAnimation();
|
||||
|
||||
}
|
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.SurfaceTexture;
|
||||
import android.media.MediaPlayer;
|
||||
import android.media.MediaPlayer.OnInfoListener;
|
||||
import android.media.MediaPlayer.OnPreparedListener;
|
||||
import android.net.Uri;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Surface;
|
||||
import android.view.TextureView;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
/**
|
||||
* A view containing a VideoView for showing the user how to enroll a fingerprint
|
||||
*/
|
||||
public class FingerprintLocationAnimationVideoView extends TextureView
|
||||
implements FingerprintFindSensorAnimation {
|
||||
protected float mAspect = 1.0f; // initial guess until we know
|
||||
protected MediaPlayer mMediaPlayer;
|
||||
|
||||
public FingerprintLocationAnimationVideoView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
// Width is driven by measurespec, height is derrived from aspect ratio
|
||||
int originalWidth = MeasureSpec.getSize(widthMeasureSpec);
|
||||
int height = Math.round(mAspect * originalWidth);
|
||||
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
|
||||
}
|
||||
|
||||
protected Uri getFingerprintLocationAnimation() {
|
||||
return resourceEntryToUri(getContext(), R.raw.fingerprint_location_animation);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
setSurfaceTextureListener(new SurfaceTextureListener() {
|
||||
private SurfaceTexture mTextureToDestroy = null;
|
||||
|
||||
@Override
|
||||
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width,
|
||||
int height) {
|
||||
setVisibility(View.INVISIBLE);
|
||||
Uri videoUri = getFingerprintLocationAnimation();
|
||||
if (mMediaPlayer != null) {
|
||||
mMediaPlayer.release();
|
||||
}
|
||||
if (mTextureToDestroy != null) {
|
||||
mTextureToDestroy.release();
|
||||
mTextureToDestroy = null;
|
||||
}
|
||||
mMediaPlayer = createMediaPlayer(mContext, videoUri);
|
||||
if (mMediaPlayer == null) {
|
||||
// MediaPlayer.create() method can return null
|
||||
return;
|
||||
}
|
||||
mMediaPlayer.setSurface(new Surface(surfaceTexture));
|
||||
mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
|
||||
@Override
|
||||
public void onPrepared(MediaPlayer mediaPlayer) {
|
||||
mediaPlayer.setLooping(true);
|
||||
}
|
||||
});
|
||||
mMediaPlayer.setOnInfoListener(new OnInfoListener() {
|
||||
@Override
|
||||
public boolean onInfo(MediaPlayer mediaPlayer, int what, int extra) {
|
||||
if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
|
||||
// Keep the view hidden until video starts
|
||||
setVisibility(View.VISIBLE);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
mAspect = (float) mMediaPlayer.getVideoHeight() / mMediaPlayer.getVideoWidth();
|
||||
requestLayout();
|
||||
startAnimation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture,
|
||||
int width, int height) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
|
||||
mTextureToDestroy = surfaceTexture;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
MediaPlayer createMediaPlayer(Context context, Uri videoUri) {
|
||||
return MediaPlayer.create(mContext, videoUri);
|
||||
}
|
||||
|
||||
protected static Uri resourceEntryToUri (Context context, int id) {
|
||||
Resources res = context.getResources();
|
||||
return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
|
||||
res.getResourcePackageName(id) + '/' +
|
||||
res.getResourceTypeName(id) + '/' +
|
||||
res.getResourceEntryName(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startAnimation() {
|
||||
if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
|
||||
mMediaPlayer.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopAnimation() {
|
||||
if (mMediaPlayer != null) {
|
||||
mMediaPlayer.stop();
|
||||
mMediaPlayer.release();
|
||||
mMediaPlayer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pauseAnimation() {
|
||||
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
|
||||
mMediaPlayer.pause();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.ColorInt;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
/**
|
||||
* View which plays an animation to indicate where the sensor is on the device.
|
||||
*/
|
||||
public class FingerprintLocationAnimationView extends View implements
|
||||
FingerprintFindSensorAnimation {
|
||||
|
||||
private static final float MAX_PULSE_ALPHA = 0.15f;
|
||||
private static final long DELAY_BETWEEN_PHASE = 1000;
|
||||
|
||||
private final Interpolator mLinearOutSlowInInterpolator;
|
||||
private final Interpolator mFastOutSlowInInterpolator;
|
||||
|
||||
private final int mDotRadius;
|
||||
private final int mMaxPulseRadius;
|
||||
private final float mFractionCenterX;
|
||||
private final float mFractionCenterY;
|
||||
private final Paint mDotPaint = new Paint();
|
||||
private final Paint mPulsePaint = new Paint();
|
||||
private float mPulseRadius;
|
||||
private ValueAnimator mRadiusAnimator;
|
||||
private ValueAnimator mAlphaAnimator;
|
||||
|
||||
public FingerprintLocationAnimationView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mDotRadius = getResources().getDimensionPixelSize(R.dimen.fingerprint_dot_radius);
|
||||
mMaxPulseRadius = getResources().getDimensionPixelSize(R.dimen.fingerprint_pulse_radius);
|
||||
mFractionCenterX = getResources().getFraction(
|
||||
R.fraction.fingerprint_sensor_location_fraction_x, 1, 1);
|
||||
mFractionCenterY = getResources().getFraction(
|
||||
R.fraction.fingerprint_sensor_location_fraction_y, 1, 1);
|
||||
@ColorInt int colorAccent = Utils.getColorAccentDefaultColor(context);
|
||||
mDotPaint.setAntiAlias(true);
|
||||
mPulsePaint.setAntiAlias(true);
|
||||
mDotPaint.setColor(colorAccent);
|
||||
mPulsePaint.setColor(colorAccent);
|
||||
mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
|
||||
android.R.interpolator.linear_out_slow_in);
|
||||
mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
|
||||
android.R.interpolator.linear_out_slow_in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
drawPulse(canvas);
|
||||
drawDot(canvas);
|
||||
}
|
||||
|
||||
private void drawDot(Canvas canvas) {
|
||||
canvas.drawCircle(getCenterX(), getCenterY(), mDotRadius, mDotPaint);
|
||||
}
|
||||
|
||||
private void drawPulse(Canvas canvas) {
|
||||
canvas.drawCircle(getCenterX(), getCenterY(), mPulseRadius, mPulsePaint);
|
||||
}
|
||||
|
||||
private float getCenterX() {
|
||||
return getWidth() * mFractionCenterX;
|
||||
}
|
||||
|
||||
private float getCenterY() {
|
||||
return getHeight() * mFractionCenterY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startAnimation() {
|
||||
startPhase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopAnimation() {
|
||||
removeCallbacks(mStartPhaseRunnable);
|
||||
if (mRadiusAnimator != null) {
|
||||
mRadiusAnimator.cancel();
|
||||
}
|
||||
if (mAlphaAnimator != null) {
|
||||
mAlphaAnimator.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pauseAnimation() {
|
||||
stopAnimation();
|
||||
}
|
||||
|
||||
private void startPhase() {
|
||||
startRadiusAnimation();
|
||||
startAlphaAnimation();
|
||||
}
|
||||
|
||||
private void startRadiusAnimation() {
|
||||
ValueAnimator animator = ValueAnimator.ofFloat(0, mMaxPulseRadius);
|
||||
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animation) {
|
||||
mPulseRadius = (float) animation.getAnimatedValue();
|
||||
invalidate();
|
||||
}
|
||||
});
|
||||
animator.addListener(new AnimatorListenerAdapter() {
|
||||
|
||||
boolean mCancelled;
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
mCancelled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mRadiusAnimator = null;
|
||||
if (!mCancelled) {
|
||||
postDelayed(mStartPhaseRunnable, DELAY_BETWEEN_PHASE);
|
||||
}
|
||||
}
|
||||
});
|
||||
animator.setDuration(1000);
|
||||
animator.setInterpolator(mLinearOutSlowInInterpolator);
|
||||
animator.start();
|
||||
mRadiusAnimator = animator;
|
||||
}
|
||||
|
||||
private void startAlphaAnimation() {
|
||||
mPulsePaint.setAlpha((int) (255f * MAX_PULSE_ALPHA));
|
||||
ValueAnimator animator = ValueAnimator.ofFloat(MAX_PULSE_ALPHA, 0f);
|
||||
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animation) {
|
||||
mPulsePaint.setAlpha((int) (255f * (float) animation.getAnimatedValue()));
|
||||
invalidate();
|
||||
}
|
||||
});
|
||||
animator.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mAlphaAnimator = null;
|
||||
}
|
||||
});
|
||||
animator.setDuration(750);
|
||||
animator.setInterpolator(mFastOutSlowInInterpolator);
|
||||
animator.setStartDelay(250);
|
||||
animator.start();
|
||||
mAlphaAnimator = animator;
|
||||
}
|
||||
|
||||
private final Runnable mStartPhaseRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startPhase();
|
||||
}
|
||||
};
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.os.UserHandle;
|
||||
|
||||
public class FingerprintProfileStatusPreferenceController
|
||||
extends FingerprintStatusPreferenceController {
|
||||
|
||||
public static final String KEY_FINGERPRINT_SETTINGS = "fingerprint_settings_profile";
|
||||
|
||||
public FingerprintProfileStatusPreferenceController(Context context) {
|
||||
super(context, KEY_FINGERPRINT_SETTINGS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isUserSupported() {
|
||||
return mProfileChallengeUserId != UserHandle.USER_NULL
|
||||
&& mLockPatternUtils.isSeparateProfileChallengeAllowed(mProfileChallengeUserId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getUserId() {
|
||||
return mProfileChallengeUserId;
|
||||
}
|
||||
}
|
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.annotation.Nullable;
|
||||
import android.hardware.fingerprint.Fingerprint;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.core.InstrumentedFragment;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
/**
|
||||
* Sidecar fragment to handle the state around fingerprint removal.
|
||||
*/
|
||||
public class FingerprintRemoveSidecar extends InstrumentedFragment {
|
||||
|
||||
private static final String TAG = "FingerprintRemoveSidecar";
|
||||
private Listener mListener;
|
||||
private Fingerprint mFingerprintRemoving;
|
||||
private Queue<Object> mFingerprintsRemoved;
|
||||
FingerprintManager mFingerprintManager;
|
||||
|
||||
private class RemovalError {
|
||||
Fingerprint fingerprint;
|
||||
int errMsgId;
|
||||
CharSequence errString;
|
||||
public RemovalError(Fingerprint fingerprint, int errMsgId, CharSequence errString) {
|
||||
this.fingerprint = fingerprint;
|
||||
this.errMsgId = errMsgId;
|
||||
this.errString = errString;
|
||||
}
|
||||
}
|
||||
|
||||
private FingerprintManager.RemovalCallback
|
||||
mRemoveCallback = new FingerprintManager.RemovalCallback() {
|
||||
@Override
|
||||
public void onRemovalSucceeded(Fingerprint fingerprint, int remaining) {
|
||||
if (mListener != null) {
|
||||
mListener.onRemovalSucceeded(fingerprint);
|
||||
} else {
|
||||
mFingerprintsRemoved.add(fingerprint);
|
||||
};
|
||||
mFingerprintRemoving = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemovalError(Fingerprint fp, int errMsgId, CharSequence errString) {
|
||||
if (mListener != null) {
|
||||
mListener.onRemovalError(fp, errMsgId, errString);
|
||||
} else {
|
||||
mFingerprintsRemoved.add(new RemovalError(fp, errMsgId, errString));
|
||||
}
|
||||
mFingerprintRemoving = null;
|
||||
}
|
||||
};
|
||||
|
||||
public void startRemove(Fingerprint fingerprint, int userId) {
|
||||
if (mFingerprintRemoving != null) {
|
||||
Log.e(TAG, "Remove already in progress");
|
||||
return;
|
||||
}
|
||||
if (userId != UserHandle.USER_NULL) {
|
||||
mFingerprintManager.setActiveUser(userId);
|
||||
}
|
||||
mFingerprintRemoving = fingerprint;
|
||||
mFingerprintManager.remove(fingerprint, userId, mRemoveCallback);;
|
||||
}
|
||||
|
||||
public FingerprintRemoveSidecar() {
|
||||
mFingerprintsRemoved = new LinkedList<>();
|
||||
}
|
||||
|
||||
public void setFingerprintManager(FingerprintManager fingerprintManager) {
|
||||
mFingerprintManager = fingerprintManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setRetainInstance(true);
|
||||
}
|
||||
|
||||
public void setListener(Listener listener) {
|
||||
if (mListener == null && listener != null) {
|
||||
while (!mFingerprintsRemoved.isEmpty()) {
|
||||
Object o = mFingerprintsRemoved.poll();
|
||||
if (o instanceof Fingerprint) {
|
||||
listener.onRemovalSucceeded((Fingerprint)o);
|
||||
} else if (o instanceof RemovalError) {
|
||||
RemovalError e = (RemovalError) o;
|
||||
listener.onRemovalError(e.fingerprint, e.errMsgId, e.errString);
|
||||
}
|
||||
}
|
||||
}
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
public interface Listener {
|
||||
void onRemovalSucceeded(Fingerprint fingerprint);
|
||||
void onRemovalError(Fingerprint fp, int errMsgId, CharSequence errString);
|
||||
}
|
||||
|
||||
final boolean isRemovingFingerprint(int fid) {
|
||||
return inProgress() && mFingerprintRemoving.getBiometricId() == fid;
|
||||
}
|
||||
|
||||
final boolean inProgress() {
|
||||
return mFingerprintRemoving != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.FINGERPRINT_REMOVE_SIDECAR;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,916 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.hardware.fingerprint.Fingerprint;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.SubSettings;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.password.ChooseLockGeneric;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
import com.android.settings.utils.AnnotationSpan;
|
||||
import com.android.settingslib.HelpUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.TwoTargetPreference;
|
||||
import com.android.settingslib.widget.FooterPreference;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
import androidx.preference.PreferenceGroup;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
/**
|
||||
* Settings screen for fingerprints
|
||||
*/
|
||||
public class FingerprintSettings extends SubSettings {
|
||||
|
||||
private static final String TAG = "FingerprintSettings";
|
||||
|
||||
/**
|
||||
* Used by the choose fingerprint wizard to indicate the wizard is
|
||||
* finished, and each activity in the wizard should finish.
|
||||
* <p>
|
||||
* Previously, each activity in the wizard would finish itself after
|
||||
* starting the next activity. However, this leads to broken 'Back'
|
||||
* behavior. So, now an activity does not finish itself until it gets this
|
||||
* result.
|
||||
*/
|
||||
protected static final int RESULT_FINISHED = RESULT_FIRST_USER;
|
||||
|
||||
/**
|
||||
* Used by the enrolling screen during setup wizard to skip over setting up fingerprint, which
|
||||
* will be useful if the user accidentally entered this flow.
|
||||
*/
|
||||
protected static final int RESULT_SKIP = RESULT_FIRST_USER + 1;
|
||||
|
||||
/**
|
||||
* Like {@link #RESULT_FINISHED} except this one indicates enrollment failed because the
|
||||
* device was left idle. This is used to clear the credential token to require the user to
|
||||
* re-enter their pin/pattern/password before continuing.
|
||||
*/
|
||||
protected static final int RESULT_TIMEOUT = RESULT_FIRST_USER + 2;
|
||||
|
||||
private static final long LOCKOUT_DURATION = 30000; // time we have to wait for fp to reset, ms
|
||||
|
||||
public static final String ANNOTATION_URL = "url";
|
||||
public static final String ANNOTATION_ADMIN_DETAILS = "admin_details";
|
||||
|
||||
@Override
|
||||
public Intent getIntent() {
|
||||
Intent modIntent = new Intent(super.getIntent());
|
||||
modIntent.putExtra(EXTRA_SHOW_FRAGMENT, FingerprintSettingsFragment.class.getName());
|
||||
return modIntent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isValidFragment(String fragmentName) {
|
||||
if (FingerprintSettingsFragment.class.getName().equals(fragmentName)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
CharSequence msg = getText(R.string.security_settings_fingerprint_preference_title);
|
||||
setTitle(msg);
|
||||
}
|
||||
|
||||
public static class FingerprintSettingsFragment extends SettingsPreferenceFragment
|
||||
implements OnPreferenceChangeListener, FingerprintPreference.OnDeleteClickListener {
|
||||
private static final int RESET_HIGHLIGHT_DELAY_MS = 500;
|
||||
|
||||
private static final String TAG = "FingerprintSettings";
|
||||
private static final String KEY_FINGERPRINT_ITEM_PREFIX = "key_fingerprint_item";
|
||||
private static final String KEY_FINGERPRINT_ADD = "key_fingerprint_add";
|
||||
private static final String KEY_FINGERPRINT_ENABLE_KEYGUARD_TOGGLE =
|
||||
"fingerprint_enable_keyguard_toggle";
|
||||
private static final String KEY_LAUNCHED_CONFIRM = "launched_confirm";
|
||||
|
||||
private static final int MSG_REFRESH_FINGERPRINT_TEMPLATES = 1000;
|
||||
private static final int MSG_FINGER_AUTH_SUCCESS = 1001;
|
||||
private static final int MSG_FINGER_AUTH_FAIL = 1002;
|
||||
private static final int MSG_FINGER_AUTH_ERROR = 1003;
|
||||
private static final int MSG_FINGER_AUTH_HELP = 1004;
|
||||
|
||||
private static final int CONFIRM_REQUEST = 101;
|
||||
private static final int CHOOSE_LOCK_GENERIC_REQUEST = 102;
|
||||
|
||||
private static final int ADD_FINGERPRINT_REQUEST = 10;
|
||||
|
||||
protected static final boolean DEBUG = true;
|
||||
|
||||
private FingerprintManager mFingerprintManager;
|
||||
private boolean mInFingerprintLockout;
|
||||
private byte[] mToken;
|
||||
private boolean mLaunchedConfirm;
|
||||
private Drawable mHighlightDrawable;
|
||||
private int mUserId;
|
||||
|
||||
private static final String TAG_AUTHENTICATE_SIDECAR = "authenticate_sidecar";
|
||||
private static final String TAG_REMOVAL_SIDECAR = "removal_sidecar";
|
||||
private FingerprintAuthenticateSidecar mAuthenticateSidecar;
|
||||
private FingerprintRemoveSidecar mRemovalSidecar;
|
||||
private HashMap<Integer, String> mFingerprintsRenaming;
|
||||
|
||||
FingerprintAuthenticateSidecar.Listener mAuthenticateListener =
|
||||
new FingerprintAuthenticateSidecar.Listener() {
|
||||
@Override
|
||||
public void onAuthenticationSucceeded(
|
||||
FingerprintManager.AuthenticationResult result) {
|
||||
int fingerId = result.getFingerprint().getBiometricId();
|
||||
mHandler.obtainMessage(MSG_FINGER_AUTH_SUCCESS, fingerId, 0).sendToTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationFailed() {
|
||||
mHandler.obtainMessage(MSG_FINGER_AUTH_FAIL).sendToTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationError(int errMsgId, CharSequence errString) {
|
||||
mHandler.obtainMessage(MSG_FINGER_AUTH_ERROR, errMsgId, 0, errString)
|
||||
.sendToTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
|
||||
mHandler.obtainMessage(MSG_FINGER_AUTH_HELP, helpMsgId, 0, helpString)
|
||||
.sendToTarget();
|
||||
}
|
||||
};
|
||||
|
||||
FingerprintRemoveSidecar.Listener mRemovalListener =
|
||||
new FingerprintRemoveSidecar.Listener() {
|
||||
public void onRemovalSucceeded(Fingerprint fingerprint) {
|
||||
mHandler.obtainMessage(MSG_REFRESH_FINGERPRINT_TEMPLATES,
|
||||
fingerprint.getBiometricId(), 0).sendToTarget();
|
||||
updateDialog();
|
||||
}
|
||||
|
||||
public void onRemovalError(Fingerprint fp, int errMsgId, CharSequence errString) {
|
||||
final Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
Toast.makeText(activity, errString, Toast.LENGTH_SHORT);
|
||||
}
|
||||
updateDialog();
|
||||
}
|
||||
|
||||
private void updateDialog() {
|
||||
RenameDialog renameDialog = (RenameDialog) getFragmentManager().
|
||||
findFragmentByTag(RenameDialog.class.getName());
|
||||
if (renameDialog != null) {
|
||||
renameDialog.enableDelete();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final Handler mHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(android.os.Message msg) {
|
||||
switch (msg.what) {
|
||||
case MSG_REFRESH_FINGERPRINT_TEMPLATES:
|
||||
removeFingerprintPreference(msg.arg1);
|
||||
updateAddPreference();
|
||||
retryFingerprint();
|
||||
break;
|
||||
case MSG_FINGER_AUTH_SUCCESS:
|
||||
highlightFingerprintItem(msg.arg1);
|
||||
retryFingerprint();
|
||||
break;
|
||||
case MSG_FINGER_AUTH_FAIL:
|
||||
// No action required... fingerprint will allow up to 5 of these
|
||||
break;
|
||||
case MSG_FINGER_AUTH_ERROR:
|
||||
handleError(msg.arg1 /* errMsgId */, (CharSequence) msg.obj /* errStr */ );
|
||||
break;
|
||||
case MSG_FINGER_AUTH_HELP: {
|
||||
// Not used
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param errMsgId
|
||||
*/
|
||||
protected void handleError(int errMsgId, CharSequence msg) {
|
||||
switch (errMsgId) {
|
||||
case FingerprintManager.FINGERPRINT_ERROR_CANCELED:
|
||||
return; // Only happens if we get preempted by another activity. Ignored.
|
||||
case FingerprintManager.FINGERPRINT_ERROR_LOCKOUT:
|
||||
mInFingerprintLockout = true;
|
||||
// We've been locked out. Reset after 30s.
|
||||
if (!mHandler.hasCallbacks(mFingerprintLockoutReset)) {
|
||||
mHandler.postDelayed(mFingerprintLockoutReset,
|
||||
LOCKOUT_DURATION);
|
||||
}
|
||||
break;
|
||||
case FingerprintManager.FINGERPRINT_ERROR_LOCKOUT_PERMANENT:
|
||||
mInFingerprintLockout = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (mInFingerprintLockout) {
|
||||
// Activity can be null on a screen rotation.
|
||||
final Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
Toast.makeText(activity, msg , Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
retryFingerprint(); // start again
|
||||
}
|
||||
|
||||
private void retryFingerprint() {
|
||||
if (mRemovalSidecar.inProgress()
|
||||
|| 0 == mFingerprintManager.getEnrolledFingerprints(mUserId).size()) {
|
||||
return;
|
||||
}
|
||||
// Don't start authentication if ChooseLockGeneric is showing, otherwise if the user
|
||||
// is in FP lockout, a toast will show on top
|
||||
if (mLaunchedConfirm) {
|
||||
return;
|
||||
}
|
||||
if (!mInFingerprintLockout) {
|
||||
mAuthenticateSidecar.startAuthentication(mUserId);
|
||||
mAuthenticateSidecar.setListener(mAuthenticateListener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.FINGERPRINT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Activity activity = getActivity();
|
||||
mFingerprintManager = Utils.getFingerprintManagerOrNull(activity);
|
||||
|
||||
mAuthenticateSidecar = (FingerprintAuthenticateSidecar)
|
||||
getFragmentManager().findFragmentByTag(TAG_AUTHENTICATE_SIDECAR);
|
||||
if (mAuthenticateSidecar == null) {
|
||||
mAuthenticateSidecar = new FingerprintAuthenticateSidecar();
|
||||
getFragmentManager().beginTransaction()
|
||||
.add(mAuthenticateSidecar, TAG_AUTHENTICATE_SIDECAR).commit();
|
||||
}
|
||||
mAuthenticateSidecar.setFingerprintManager(mFingerprintManager);
|
||||
|
||||
mRemovalSidecar = (FingerprintRemoveSidecar)
|
||||
getFragmentManager().findFragmentByTag(TAG_REMOVAL_SIDECAR);
|
||||
if (mRemovalSidecar == null) {
|
||||
mRemovalSidecar = new FingerprintRemoveSidecar();
|
||||
getFragmentManager().beginTransaction()
|
||||
.add(mRemovalSidecar, TAG_REMOVAL_SIDECAR).commit();
|
||||
}
|
||||
mRemovalSidecar.setFingerprintManager(mFingerprintManager);
|
||||
mRemovalSidecar.setListener(mRemovalListener);
|
||||
|
||||
RenameDialog renameDialog = (RenameDialog) getFragmentManager().
|
||||
findFragmentByTag(RenameDialog.class.getName());
|
||||
if (renameDialog != null) {
|
||||
renameDialog.setDeleteInProgress(mRemovalSidecar.inProgress());
|
||||
}
|
||||
|
||||
mFingerprintsRenaming = new HashMap<Integer, String>();
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mFingerprintsRenaming = (HashMap<Integer, String>)
|
||||
savedInstanceState.getSerializable("mFingerprintsRenaming");
|
||||
mToken = savedInstanceState.getByteArray(
|
||||
ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
|
||||
mLaunchedConfirm = savedInstanceState.getBoolean(
|
||||
KEY_LAUNCHED_CONFIRM, false);
|
||||
}
|
||||
mUserId = getActivity().getIntent().getIntExtra(
|
||||
Intent.EXTRA_USER_ID, UserHandle.myUserId());
|
||||
|
||||
// Need to authenticate a session token if none
|
||||
if (mToken == null && mLaunchedConfirm == false) {
|
||||
mLaunchedConfirm = true;
|
||||
launchChooseOrConfirmLock();
|
||||
}
|
||||
|
||||
final FooterPreference pref = mFooterPreferenceMixin.createFooterPreference();
|
||||
final EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
|
||||
activity, DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT, mUserId);
|
||||
final AnnotationSpan.LinkInfo adminLinkInfo = new AnnotationSpan.LinkInfo(
|
||||
ANNOTATION_ADMIN_DETAILS, (view) -> {
|
||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(activity, admin);
|
||||
});
|
||||
final Intent helpIntent = HelpUtils.getHelpIntent(
|
||||
activity, getString(getHelpResource()), activity.getClass().getName());
|
||||
final AnnotationSpan.LinkInfo linkInfo = new AnnotationSpan.LinkInfo(
|
||||
activity, ANNOTATION_URL, helpIntent);
|
||||
pref.setTitle(AnnotationSpan.linkify(getText(admin != null
|
||||
? R.string
|
||||
.security_settings_fingerprint_enroll_disclaimer_lockscreen_disabled
|
||||
: R.string.security_settings_fingerprint_enroll_disclaimer),
|
||||
linkInfo, adminLinkInfo));
|
||||
}
|
||||
|
||||
protected void removeFingerprintPreference(int fingerprintId) {
|
||||
String name = genKey(fingerprintId);
|
||||
Preference prefToRemove = findPreference(name);
|
||||
if (prefToRemove != null) {
|
||||
if (!getPreferenceScreen().removePreference(prefToRemove)) {
|
||||
Log.w(TAG, "Failed to remove preference with key " + name);
|
||||
}
|
||||
} else {
|
||||
Log.w(TAG, "Can't find preference to remove: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Important!
|
||||
*
|
||||
* Don't forget to update the SecuritySearchIndexProvider if you are doing any change in the
|
||||
* logic or adding/removing preferences here.
|
||||
*/
|
||||
private PreferenceScreen createPreferenceHierarchy() {
|
||||
PreferenceScreen root = getPreferenceScreen();
|
||||
if (root != null) {
|
||||
root.removeAll();
|
||||
}
|
||||
addPreferencesFromResource(R.xml.security_settings_fingerprint);
|
||||
root = getPreferenceScreen();
|
||||
addFingerprintItemPreferences(root);
|
||||
setPreferenceScreen(root);
|
||||
return root;
|
||||
}
|
||||
|
||||
private void addFingerprintItemPreferences(PreferenceGroup root) {
|
||||
root.removeAll();
|
||||
final List<Fingerprint> items = mFingerprintManager.getEnrolledFingerprints(mUserId);
|
||||
final int fingerprintCount = items.size();
|
||||
for (int i = 0; i < fingerprintCount; i++) {
|
||||
final Fingerprint item = items.get(i);
|
||||
FingerprintPreference pref = new FingerprintPreference(root.getContext(),
|
||||
this /* onDeleteClickListener */);
|
||||
pref.setKey(genKey(item.getBiometricId()));
|
||||
pref.setTitle(item.getName());
|
||||
pref.setFingerprint(item);
|
||||
pref.setPersistent(false);
|
||||
pref.setIcon(R.drawable.ic_fingerprint_24dp);
|
||||
if (mRemovalSidecar.isRemovingFingerprint(item.getBiometricId())) {
|
||||
pref.setEnabled(false);
|
||||
}
|
||||
if (mFingerprintsRenaming.containsKey(item.getBiometricId())) {
|
||||
pref.setTitle(mFingerprintsRenaming.get(item.getBiometricId()));
|
||||
}
|
||||
root.addPreference(pref);
|
||||
pref.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
Preference addPreference = new Preference(root.getContext());
|
||||
addPreference.setKey(KEY_FINGERPRINT_ADD);
|
||||
addPreference.setTitle(R.string.fingerprint_add_title);
|
||||
addPreference.setIcon(R.drawable.ic_menu_add);
|
||||
root.addPreference(addPreference);
|
||||
addPreference.setOnPreferenceChangeListener(this);
|
||||
updateAddPreference();
|
||||
}
|
||||
|
||||
private void updateAddPreference() {
|
||||
if (getActivity() == null) return; // Activity went away
|
||||
|
||||
/* Disable preference if too many fingerprints added */
|
||||
final int max = getContext().getResources().getInteger(
|
||||
com.android.internal.R.integer.config_fingerprintMaxTemplatesPerUser);
|
||||
boolean tooMany = mFingerprintManager.getEnrolledFingerprints(mUserId).size() >= max;
|
||||
// retryFingerprint() will be called when remove finishes
|
||||
// need to disable enroll or have a way to determine if enroll is in progress
|
||||
final boolean removalInProgress = mRemovalSidecar.inProgress();
|
||||
CharSequence maxSummary = tooMany ?
|
||||
getContext().getString(R.string.fingerprint_add_max, max) : "";
|
||||
Preference addPreference = findPreference(KEY_FINGERPRINT_ADD);
|
||||
addPreference.setSummary(maxSummary);
|
||||
addPreference.setEnabled(!tooMany && !removalInProgress);
|
||||
}
|
||||
|
||||
private static String genKey(int id) {
|
||||
return KEY_FINGERPRINT_ITEM_PREFIX + "_" + id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mInFingerprintLockout = false;
|
||||
// Make sure we reload the preference hierarchy since fingerprints may be added,
|
||||
// deleted or renamed.
|
||||
updatePreferences();
|
||||
if (mRemovalSidecar != null) {
|
||||
mRemovalSidecar.setListener(mRemovalListener);
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePreferences() {
|
||||
createPreferenceHierarchy();
|
||||
retryFingerprint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
if (mRemovalSidecar != null) {
|
||||
mRemovalSidecar.setListener(null);
|
||||
}
|
||||
if (mAuthenticateSidecar != null) {
|
||||
mAuthenticateSidecar.setListener(null);
|
||||
mAuthenticateSidecar.stopAuthentication();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(final Bundle outState) {
|
||||
outState.putByteArray(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN,
|
||||
mToken);
|
||||
outState.putBoolean(KEY_LAUNCHED_CONFIRM, mLaunchedConfirm);
|
||||
outState.putSerializable("mFingerprintsRenaming", mFingerprintsRenaming);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(Preference pref) {
|
||||
final String key = pref.getKey();
|
||||
if (KEY_FINGERPRINT_ADD.equals(key)) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClassName("com.android.settings",
|
||||
FingerprintEnrollEnrolling.class.getName());
|
||||
intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
|
||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
|
||||
startActivityForResult(intent, ADD_FINGERPRINT_REQUEST);
|
||||
} else if (pref instanceof FingerprintPreference) {
|
||||
FingerprintPreference fpref = (FingerprintPreference) pref;
|
||||
final Fingerprint fp = fpref.getFingerprint();
|
||||
showRenameDialog(fp);
|
||||
}
|
||||
return super.onPreferenceTreeClick(pref);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleteClick(FingerprintPreference p) {
|
||||
final boolean hasMultipleFingerprint =
|
||||
mFingerprintManager.getEnrolledFingerprints(mUserId).size() > 1;
|
||||
final Fingerprint fp = p.getFingerprint();
|
||||
|
||||
if (hasMultipleFingerprint) {
|
||||
if (mRemovalSidecar.inProgress()) {
|
||||
Log.d(TAG, "Fingerprint delete in progress, skipping");
|
||||
return;
|
||||
}
|
||||
DeleteFingerprintDialog.newInstance(fp, this /* target */)
|
||||
.show(getFragmentManager(), DeleteFingerprintDialog.class.getName());
|
||||
} else {
|
||||
ConfirmLastDeleteDialog lastDeleteDialog = new ConfirmLastDeleteDialog();
|
||||
final boolean isProfileChallengeUser =
|
||||
UserManager.get(getContext()).isManagedProfile(mUserId);
|
||||
final Bundle args = new Bundle();
|
||||
args.putParcelable("fingerprint", fp);
|
||||
args.putBoolean("isProfileChallengeUser", isProfileChallengeUser);
|
||||
lastDeleteDialog.setArguments(args);
|
||||
lastDeleteDialog.setTargetFragment(this, 0);
|
||||
lastDeleteDialog.show(getFragmentManager(),
|
||||
ConfirmLastDeleteDialog.class.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private void showRenameDialog(final Fingerprint fp) {
|
||||
RenameDialog renameDialog = new RenameDialog();
|
||||
Bundle args = new Bundle();
|
||||
if (mFingerprintsRenaming.containsKey(fp.getBiometricId())) {
|
||||
final Fingerprint f = new Fingerprint(mFingerprintsRenaming.get(fp.getBiometricId()),
|
||||
fp.getGroupId(), fp.getBiometricId(), fp.getDeviceId());
|
||||
args.putParcelable("fingerprint", f);
|
||||
} else {
|
||||
args.putParcelable("fingerprint", fp);
|
||||
}
|
||||
renameDialog.setDeleteInProgress(mRemovalSidecar.inProgress());
|
||||
renameDialog.setArguments(args);
|
||||
renameDialog.setTargetFragment(this, 0);
|
||||
renameDialog.show(getFragmentManager(), RenameDialog.class.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object value) {
|
||||
boolean result = true;
|
||||
final String key = preference.getKey();
|
||||
if (KEY_FINGERPRINT_ENABLE_KEYGUARD_TOGGLE.equals(key)) {
|
||||
// TODO
|
||||
} else {
|
||||
Log.v(TAG, "Unknown key:" + key);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHelpResource() {
|
||||
return R.string.help_url_fingerprint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == CHOOSE_LOCK_GENERIC_REQUEST
|
||||
|| requestCode == CONFIRM_REQUEST) {
|
||||
mLaunchedConfirm = false;
|
||||
if (resultCode == RESULT_FINISHED || resultCode == RESULT_OK) {
|
||||
// The lock pin/pattern/password was set. Start enrolling!
|
||||
if (data != null) {
|
||||
mToken = data.getByteArrayExtra(
|
||||
ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
|
||||
}
|
||||
}
|
||||
} else if (requestCode == ADD_FINGERPRINT_REQUEST) {
|
||||
if (resultCode == RESULT_TIMEOUT) {
|
||||
Activity activity = getActivity();
|
||||
activity.setResult(RESULT_TIMEOUT);
|
||||
activity.finish();
|
||||
}
|
||||
}
|
||||
|
||||
if (mToken == null) {
|
||||
// Didn't get an authentication, finishing
|
||||
getActivity().finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (getActivity().isFinishing()) {
|
||||
int result = mFingerprintManager.postEnroll();
|
||||
if (result < 0) {
|
||||
Log.w(TAG, "postEnroll failed: result = " + result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Drawable getHighlightDrawable() {
|
||||
if (mHighlightDrawable == null) {
|
||||
final Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
mHighlightDrawable = activity.getDrawable(R.drawable.preference_highlight);
|
||||
}
|
||||
}
|
||||
return mHighlightDrawable;
|
||||
}
|
||||
|
||||
private void highlightFingerprintItem(int fpId) {
|
||||
String prefName = genKey(fpId);
|
||||
FingerprintPreference fpref = (FingerprintPreference) findPreference(prefName);
|
||||
final Drawable highlight = getHighlightDrawable();
|
||||
if (highlight != null && fpref != null) {
|
||||
final View view = fpref.getView();
|
||||
if (view == null) {
|
||||
// FingerprintPreference is not bound to UI yet, so view is null.
|
||||
return;
|
||||
}
|
||||
final int centerX = view.getWidth() / 2;
|
||||
final int centerY = view.getHeight() / 2;
|
||||
highlight.setHotspot(centerX, centerY);
|
||||
view.setBackground(highlight);
|
||||
view.setPressed(true);
|
||||
view.setPressed(false);
|
||||
mHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
view.setBackground(null);
|
||||
}
|
||||
}, RESET_HIGHLIGHT_DELAY_MS);
|
||||
}
|
||||
}
|
||||
|
||||
private void launchChooseOrConfirmLock() {
|
||||
Intent intent = new Intent();
|
||||
long challenge = mFingerprintManager.preEnroll();
|
||||
ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(getActivity(), this);
|
||||
if (!helper.launchConfirmationActivity(CONFIRM_REQUEST,
|
||||
getString(R.string.security_settings_fingerprint_preference_title),
|
||||
null, null, challenge, mUserId)) {
|
||||
intent.setClassName("com.android.settings", ChooseLockGeneric.class.getName());
|
||||
intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.MINIMUM_QUALITY_KEY,
|
||||
DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
|
||||
intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.HIDE_DISABLED_PREFS,
|
||||
true);
|
||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, true);
|
||||
intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
|
||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge);
|
||||
intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
|
||||
startActivityForResult(intent, CHOOSE_LOCK_GENERIC_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void deleteFingerPrint(Fingerprint fingerPrint) {
|
||||
mRemovalSidecar.startRemove(fingerPrint, mUserId);
|
||||
String name = genKey(fingerPrint.getBiometricId());
|
||||
Preference prefToRemove = findPreference(name);
|
||||
prefToRemove.setEnabled(false);
|
||||
updateAddPreference();
|
||||
}
|
||||
|
||||
private void renameFingerPrint(int fingerId, String newName) {
|
||||
mFingerprintManager.rename(fingerId, mUserId, newName);
|
||||
if (!TextUtils.isEmpty(newName)) {
|
||||
mFingerprintsRenaming.put(fingerId, newName);
|
||||
}
|
||||
updatePreferences();
|
||||
}
|
||||
|
||||
private final Runnable mFingerprintLockoutReset = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mInFingerprintLockout = false;
|
||||
retryFingerprint();
|
||||
}
|
||||
};
|
||||
|
||||
public static class DeleteFingerprintDialog extends InstrumentedDialogFragment
|
||||
implements DialogInterface.OnClickListener {
|
||||
|
||||
private static final String KEY_FINGERPRINT = "fingerprint";
|
||||
private Fingerprint mFp;
|
||||
private AlertDialog mAlertDialog;
|
||||
|
||||
public static DeleteFingerprintDialog newInstance(Fingerprint fp,
|
||||
FingerprintSettingsFragment target) {
|
||||
final DeleteFingerprintDialog dialog = new DeleteFingerprintDialog();
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelable(KEY_FINGERPRINT, fp);
|
||||
dialog.setArguments(bundle);
|
||||
dialog.setTargetFragment(target, 0 /* requestCode */);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.DIALOG_FINGERPINT_EDIT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
mFp = getArguments().getParcelable(KEY_FINGERPRINT);
|
||||
final String title = getString(R.string.fingerprint_delete_title, mFp.getName());
|
||||
|
||||
mAlertDialog = new AlertDialog.Builder(getActivity())
|
||||
.setTitle(title)
|
||||
.setMessage(R.string.fingerprint_delete_message)
|
||||
.setPositiveButton(
|
||||
R.string.security_settings_fingerprint_enroll_dialog_delete,
|
||||
this /* onClickListener */)
|
||||
.setNegativeButton(R.string.cancel, null /* onClickListener */)
|
||||
.create();
|
||||
return mAlertDialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
final int fingerprintId = mFp.getBiometricId();
|
||||
Log.v(TAG, "Removing fpId=" + fingerprintId);
|
||||
mMetricsFeatureProvider.action(getContext(),
|
||||
MetricsEvent.ACTION_FINGERPRINT_DELETE,
|
||||
fingerprintId);
|
||||
FingerprintSettingsFragment parent
|
||||
= (FingerprintSettingsFragment) getTargetFragment();
|
||||
parent.deleteFingerPrint(mFp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class RenameDialog extends InstrumentedDialogFragment {
|
||||
|
||||
private Fingerprint mFp;
|
||||
private EditText mDialogTextField;
|
||||
private String mFingerName;
|
||||
private Boolean mTextHadFocus;
|
||||
private int mTextSelectionStart;
|
||||
private int mTextSelectionEnd;
|
||||
private AlertDialog mAlertDialog;
|
||||
private boolean mDeleteInProgress;
|
||||
|
||||
public void setDeleteInProgress(boolean deleteInProgress) {
|
||||
mDeleteInProgress = deleteInProgress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
mFp = getArguments().getParcelable("fingerprint");
|
||||
if (savedInstanceState != null) {
|
||||
mFingerName = savedInstanceState.getString("fingerName");
|
||||
mTextHadFocus = savedInstanceState.getBoolean("textHadFocus");
|
||||
mTextSelectionStart = savedInstanceState.getInt("startSelection");
|
||||
mTextSelectionEnd = savedInstanceState.getInt("endSelection");
|
||||
}
|
||||
mAlertDialog = new AlertDialog.Builder(getActivity())
|
||||
.setView(R.layout.fingerprint_rename_dialog)
|
||||
.setPositiveButton(R.string.security_settings_fingerprint_enroll_dialog_ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
final String newName =
|
||||
mDialogTextField.getText().toString();
|
||||
final CharSequence name = mFp.getName();
|
||||
if (!TextUtils.equals(newName, name)) {
|
||||
Log.d(TAG, "rename " + name + " to " + newName);
|
||||
mMetricsFeatureProvider.action(getContext(),
|
||||
MetricsEvent.ACTION_FINGERPRINT_RENAME,
|
||||
mFp.getBiometricId());
|
||||
FingerprintSettingsFragment parent
|
||||
= (FingerprintSettingsFragment)
|
||||
getTargetFragment();
|
||||
parent.renameFingerPrint(mFp.getBiometricId(),
|
||||
newName);
|
||||
}
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
mAlertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
||||
@Override
|
||||
public void onShow(DialogInterface dialog) {
|
||||
mDialogTextField = (EditText) mAlertDialog.findViewById(
|
||||
R.id.fingerprint_rename_field);
|
||||
CharSequence name = mFingerName == null ? mFp.getName() : mFingerName;
|
||||
mDialogTextField.setText(name);
|
||||
if (mTextHadFocus == null) {
|
||||
mDialogTextField.selectAll();
|
||||
} else {
|
||||
mDialogTextField.setSelection(mTextSelectionStart, mTextSelectionEnd);
|
||||
}
|
||||
if (mDeleteInProgress) {
|
||||
mAlertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setEnabled(false);
|
||||
}
|
||||
mDialogTextField.requestFocus();
|
||||
}
|
||||
});
|
||||
if (mTextHadFocus == null || mTextHadFocus) {
|
||||
// Request the IME
|
||||
mAlertDialog.getWindow().setSoftInputMode(
|
||||
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||
}
|
||||
return mAlertDialog;
|
||||
}
|
||||
|
||||
public void enableDelete() {
|
||||
mDeleteInProgress = false;
|
||||
if (mAlertDialog != null) {
|
||||
mAlertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
if (mDialogTextField != null) {
|
||||
outState.putString("fingerName", mDialogTextField.getText().toString());
|
||||
outState.putBoolean("textHadFocus", mDialogTextField.hasFocus());
|
||||
outState.putInt("startSelection", mDialogTextField.getSelectionStart());
|
||||
outState.putInt("endSelection", mDialogTextField.getSelectionEnd());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.DIALOG_FINGERPINT_EDIT;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConfirmLastDeleteDialog extends InstrumentedDialogFragment {
|
||||
|
||||
private Fingerprint mFp;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.DIALOG_FINGERPINT_DELETE_LAST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
mFp = getArguments().getParcelable("fingerprint");
|
||||
final boolean isProfileChallengeUser =
|
||||
getArguments().getBoolean("isProfileChallengeUser");
|
||||
final AlertDialog alertDialog = new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.fingerprint_last_delete_title)
|
||||
.setMessage((isProfileChallengeUser)
|
||||
? R.string.fingerprint_last_delete_message_profile_challenge
|
||||
: R.string.fingerprint_last_delete_message)
|
||||
.setPositiveButton(R.string.fingerprint_last_delete_confirm,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FingerprintSettingsFragment parent
|
||||
= (FingerprintSettingsFragment) getTargetFragment();
|
||||
parent.deleteFingerPrint(mFp);
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(
|
||||
R.string.cancel,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
return alertDialog;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class FingerprintPreference extends TwoTargetPreference {
|
||||
|
||||
private final OnDeleteClickListener mOnDeleteClickListener;
|
||||
|
||||
private Fingerprint mFingerprint;
|
||||
private View mView;
|
||||
private View mDeleteView;
|
||||
|
||||
public interface OnDeleteClickListener {
|
||||
void onDeleteClick(FingerprintPreference p);
|
||||
}
|
||||
|
||||
public FingerprintPreference(Context context, OnDeleteClickListener onDeleteClickListener) {
|
||||
super(context);
|
||||
mOnDeleteClickListener = onDeleteClickListener;
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
return mView;
|
||||
}
|
||||
|
||||
public void setFingerprint(Fingerprint item) {
|
||||
mFingerprint = item;
|
||||
}
|
||||
|
||||
public Fingerprint getFingerprint() {
|
||||
return mFingerprint;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSecondTargetResId() {
|
||||
return R.layout.preference_widget_delete;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||
super.onBindViewHolder(view);
|
||||
mView = view.itemView;
|
||||
mDeleteView = view.itemView.findViewById(R.id.delete_button);
|
||||
mDeleteView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mOnDeleteClickListener != null) {
|
||||
mOnDeleteClickListener.onDeleteClick(FingerprintPreference.this);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.content.Intent;
|
||||
import android.hardware.fingerprint.Fingerprint;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
public class FingerprintStatusPreferenceController extends BasePreferenceController {
|
||||
|
||||
private static final String KEY_FINGERPRINT_SETTINGS = "fingerprint_settings";
|
||||
|
||||
protected final FingerprintManager mFingerprintManager;
|
||||
protected final UserManager mUm;
|
||||
protected final LockPatternUtils mLockPatternUtils;
|
||||
|
||||
protected final int mUserId = UserHandle.myUserId();
|
||||
protected final int mProfileChallengeUserId;
|
||||
|
||||
public FingerprintStatusPreferenceController(Context context) {
|
||||
this(context, KEY_FINGERPRINT_SETTINGS);
|
||||
}
|
||||
|
||||
public FingerprintStatusPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mFingerprintManager = Utils.getFingerprintManagerOrNull(context);
|
||||
mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
mLockPatternUtils = FeatureFactory.getFactory(context)
|
||||
.getSecurityFeatureProvider()
|
||||
.getLockPatternUtils(context);
|
||||
mProfileChallengeUserId = Utils.getManagedProfileId(mUm, mUserId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (mFingerprintManager == null || !mFingerprintManager.isHardwareDetected()) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
if (isUserSupported()) {
|
||||
return AVAILABLE;
|
||||
} else {
|
||||
return DISABLED_FOR_USER;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
if (!isAvailable()) {
|
||||
if (preference != null) {
|
||||
preference.setVisible(false);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
preference.setVisible(true);
|
||||
}
|
||||
final int userId = getUserId();
|
||||
final List<Fingerprint> items = mFingerprintManager.getEnrolledFingerprints(userId);
|
||||
final int fingerprintCount = items != null ? items.size() : 0;
|
||||
final String clazz;
|
||||
if (fingerprintCount > 0) {
|
||||
preference.setSummary(mContext.getResources().getQuantityString(
|
||||
R.plurals.security_settings_fingerprint_preference_summary,
|
||||
fingerprintCount, fingerprintCount));
|
||||
clazz = FingerprintSettings.class.getName();
|
||||
} else {
|
||||
preference.setSummary(
|
||||
R.string.security_settings_fingerprint_preference_summary_none);
|
||||
clazz = FingerprintEnrollIntroduction.class.getName();
|
||||
}
|
||||
preference.setOnPreferenceClickListener(target -> {
|
||||
final Context context = target.getContext();
|
||||
final UserManager userManager = UserManager.get(context);
|
||||
if (Utils.startQuietModeDialogIfNecessary(context, userManager,
|
||||
userId)) {
|
||||
return false;
|
||||
}
|
||||
Intent intent = new Intent();
|
||||
intent.setClassName("com.android.settings", clazz);
|
||||
intent.putExtra(Intent.EXTRA_USER_ID, userId);
|
||||
context.startActivity(intent);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
protected int getUserId() {
|
||||
return mUserId;
|
||||
}
|
||||
|
||||
protected boolean isUserSupported() {
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
public class FingerprintSuggestionActivity extends SetupFingerprintEnrollIntroduction {
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
super.initViews();
|
||||
|
||||
final Button cancelButton = findViewById(R.id.fingerprint_cancel_button);
|
||||
cancelButton.setText(R.string.security_settings_fingerprint_enroll_introduction_cancel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
// Always use RESULT_CANCELED because this action can be done multiple times
|
||||
setResult(RESULT_CANCELED);
|
||||
super.finish();
|
||||
}
|
||||
|
||||
public static boolean isSuggestionComplete(Context context) {
|
||||
return !Utils.hasFingerprintHardware(context)
|
||||
|| !isFingerprintEnabled(context)
|
||||
|| isNotSingleFingerprintEnrolled(context);
|
||||
}
|
||||
|
||||
private static boolean isNotSingleFingerprintEnrolled(Context context) {
|
||||
final FingerprintManager manager = Utils.getFingerprintManagerOrNull(context);
|
||||
return manager == null || manager.getEnrolledFingerprints().size() != 1;
|
||||
}
|
||||
|
||||
static boolean isFingerprintEnabled(Context context) {
|
||||
final DevicePolicyManager dpManager =
|
||||
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
final int dpmFlags = dpManager.getKeyguardDisabledFeatures(null, /* admin */
|
||||
context.getUserId());
|
||||
return (dpmFlags & DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT) == 0;
|
||||
}
|
||||
}
|
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.CancellationSignal;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
/**
|
||||
* Small helper class to manage text/icon around fingerprint authentication UI.
|
||||
*/
|
||||
public class FingerprintUiHelper extends FingerprintManager.AuthenticationCallback {
|
||||
|
||||
private static final long ERROR_TIMEOUT = 1300;
|
||||
|
||||
private ImageView mIcon;
|
||||
private TextView mErrorTextView;
|
||||
private CancellationSignal mCancellationSignal;
|
||||
private int mUserId;
|
||||
|
||||
private Callback mCallback;
|
||||
private FingerprintManager mFingerprintManager;
|
||||
|
||||
public FingerprintUiHelper(ImageView icon, TextView errorTextView, Callback callback,
|
||||
int userId) {
|
||||
mFingerprintManager = Utils.getFingerprintManagerOrNull(icon.getContext());
|
||||
mIcon = icon;
|
||||
mErrorTextView = errorTextView;
|
||||
mCallback = callback;
|
||||
mUserId = userId;
|
||||
}
|
||||
|
||||
public void startListening() {
|
||||
if (mFingerprintManager != null && mFingerprintManager.isHardwareDetected()
|
||||
&& mFingerprintManager.getEnrolledFingerprints(mUserId).size() > 0) {
|
||||
mCancellationSignal = new CancellationSignal();
|
||||
mFingerprintManager.setActiveUser(mUserId);
|
||||
mFingerprintManager.authenticate(
|
||||
null, mCancellationSignal, 0 /* flags */, this, null, mUserId);
|
||||
setFingerprintIconVisibility(true);
|
||||
mIcon.setImageResource(R.drawable.ic_fingerprint);
|
||||
}
|
||||
}
|
||||
|
||||
public void stopListening() {
|
||||
if (mCancellationSignal != null) {
|
||||
mCancellationSignal.cancel();
|
||||
mCancellationSignal = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isListening() {
|
||||
return mCancellationSignal != null && !mCancellationSignal.isCanceled();
|
||||
}
|
||||
|
||||
private void setFingerprintIconVisibility(boolean visible) {
|
||||
mIcon.setVisibility(visible ? View.VISIBLE : View.GONE);
|
||||
mCallback.onFingerprintIconVisibilityChanged(visible);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationError(int errMsgId, CharSequence errString) {
|
||||
if (errMsgId == FingerprintManager.FINGERPRINT_ERROR_CANCELED) {
|
||||
// Only happens if we get preempted by another activity. Ignored.
|
||||
return;
|
||||
}
|
||||
showError(errString);
|
||||
setFingerprintIconVisibility(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
|
||||
showError(helpString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationFailed() {
|
||||
showError(mIcon.getResources().getString(
|
||||
R.string.fingerprint_not_recognized));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
|
||||
mIcon.setImageResource(R.drawable.ic_fingerprint_success);
|
||||
mCallback.onAuthenticated();
|
||||
}
|
||||
|
||||
private void showError(CharSequence error) {
|
||||
if (!isListening()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mIcon.setImageResource(R.drawable.ic_fingerprint_error);
|
||||
mErrorTextView.setText(error);
|
||||
mErrorTextView.removeCallbacks(mResetErrorTextRunnable);
|
||||
mErrorTextView.postDelayed(mResetErrorTextRunnable, ERROR_TIMEOUT);
|
||||
}
|
||||
|
||||
private Runnable mResetErrorTextRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mErrorTextView.setText("");
|
||||
mIcon.setImageResource(R.drawable.ic_fingerprint);
|
||||
}
|
||||
};
|
||||
|
||||
public interface Callback {
|
||||
void onAuthenticated();
|
||||
void onFingerprintIconVisibilityChanged(boolean visible);
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.Intent;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.SetupWizardUtils;
|
||||
|
||||
public class SetupFingerprintEnrollEnrolling extends FingerprintEnrollEnrolling {
|
||||
|
||||
@Override
|
||||
protected Intent getFinishIntent() {
|
||||
final Intent intent = new Intent(this, SetupFingerprintEnrollFinish.class);
|
||||
SetupWizardUtils.copySetupExtras(getIntent(), intent);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.FINGERPRINT_ENROLLING_SETUP;
|
||||
}
|
||||
}
|
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SetupWizardUtils;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class SetupFingerprintEnrollFindSensor extends FingerprintEnrollFindSensor {
|
||||
|
||||
@Override
|
||||
protected int getContentView() {
|
||||
return R.layout.fingerprint_enroll_find_sensor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Intent getEnrollingIntent() {
|
||||
Intent intent = new Intent(this, SetupFingerprintEnrollEnrolling.class);
|
||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
|
||||
if (mUserId != UserHandle.USER_NULL) {
|
||||
intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
|
||||
}
|
||||
SetupWizardUtils.copySetupExtras(getIntent(), intent);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSkipButtonClick() {
|
||||
new SkipFingerprintDialog().show(getFragmentManager());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.FINGERPRINT_FIND_SENSOR_SETUP;
|
||||
}
|
||||
|
||||
public static class SkipFingerprintDialog extends InstrumentedDialogFragment
|
||||
implements DialogInterface.OnClickListener {
|
||||
private static final String TAG_SKIP_DIALOG = "skip_dialog";
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.DIALOG_FINGERPRINT_SKIP_SETUP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
return onCreateDialogBuilder().create();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public AlertDialog.Builder onCreateDialogBuilder() {
|
||||
return new AlertDialog.Builder(getContext())
|
||||
.setTitle(R.string.setup_fingerprint_enroll_skip_title)
|
||||
.setPositiveButton(R.string.skip_anyway_button_label, this)
|
||||
.setNegativeButton(R.string.go_back_button_label, this)
|
||||
.setMessage(R.string.setup_fingerprint_enroll_skip_after_adding_lock_text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int button) {
|
||||
switch (button) {
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
activity.setResult(RESULT_SKIP);
|
||||
activity.finish();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void show(FragmentManager manager) {
|
||||
show(manager, TAG_SKIP_DIALOG);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.Intent;
|
||||
import android.os.UserHandle;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SetupWizardUtils;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
|
||||
public class SetupFingerprintEnrollFinish extends FingerprintEnrollFinish {
|
||||
|
||||
@Override
|
||||
protected Intent getEnrollingIntent() {
|
||||
Intent intent = new Intent(this, SetupFingerprintEnrollEnrolling.class);
|
||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
|
||||
if (mUserId != UserHandle.USER_NULL) {
|
||||
intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
|
||||
}
|
||||
SetupWizardUtils.copySetupExtras(getIntent(), intent);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
super.initViews();
|
||||
Button nextButton = findViewById(R.id.next_button);
|
||||
nextButton.setText(R.string.next_label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.FINGERPRINT_ENROLL_FINISH_SETUP;
|
||||
}
|
||||
}
|
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.app.Activity;
|
||||
import android.app.KeyguardManager;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SetupWizardUtils;
|
||||
import com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment;
|
||||
import com.android.settings.password.SetupChooseLockGeneric;
|
||||
import com.android.settings.password.SetupSkipDialog;
|
||||
import com.android.settings.password.StorageManagerWrapper;
|
||||
|
||||
public class SetupFingerprintEnrollIntroduction extends FingerprintEnrollIntroduction {
|
||||
private static final String KEY_LOCK_SCREEN_PRESENT = "wasLockScreenPresent";
|
||||
private boolean mAlreadyHadLockScreenSetup = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (savedInstanceState == null) {
|
||||
mAlreadyHadLockScreenSetup = isKeyguardSecure();
|
||||
} else {
|
||||
mAlreadyHadLockScreenSetup = savedInstanceState.getBoolean(
|
||||
KEY_LOCK_SCREEN_PRESENT, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBoolean(KEY_LOCK_SCREEN_PRESENT, mAlreadyHadLockScreenSetup);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Intent getChooseLockIntent() {
|
||||
Intent intent = new Intent(this, SetupChooseLockGeneric.class);
|
||||
|
||||
if (StorageManagerWrapper.isFileEncryptedNativeOrEmulated()) {
|
||||
intent.putExtra(
|
||||
LockPatternUtils.PASSWORD_TYPE_KEY,
|
||||
DevicePolicyManager.PASSWORD_QUALITY_NUMERIC);
|
||||
intent.putExtra(ChooseLockGenericFragment.EXTRA_SHOW_OPTIONS_BUTTON, true);
|
||||
}
|
||||
SetupWizardUtils.copySetupExtras(getIntent(), intent);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Intent getFindSensorIntent() {
|
||||
final Intent intent = new Intent(this, SetupFingerprintEnrollFindSensor.class);
|
||||
SetupWizardUtils.copySetupExtras(getIntent(), intent);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
super.initViews();
|
||||
|
||||
TextView description = (TextView) findViewById(R.id.description_text);
|
||||
description.setText(
|
||||
R.string.security_settings_fingerprint_enroll_introduction_message_setup);
|
||||
|
||||
Button nextButton = getNextButton();
|
||||
nextButton.setText(
|
||||
R.string.security_settings_fingerprint_enroll_introduction_continue_setup);
|
||||
|
||||
final Button cancelButton = (Button) findViewById(R.id.fingerprint_cancel_button);
|
||||
cancelButton.setText(
|
||||
R.string.security_settings_fingerprint_enroll_introduction_cancel_setup);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// if lock was already present, do not return intent data since it must have been
|
||||
// reported in previous attempts
|
||||
if (requestCode == FINGERPRINT_FIND_SENSOR_REQUEST && isKeyguardSecure()
|
||||
&& !mAlreadyHadLockScreenSetup) {
|
||||
data = getMetricIntent(data);
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
private Intent getMetricIntent(Intent data) {
|
||||
if (data == null) {
|
||||
data = new Intent();
|
||||
}
|
||||
LockPatternUtils lockPatternUtils = new LockPatternUtils(this);
|
||||
data.putExtra(SetupChooseLockGeneric.
|
||||
SetupChooseLockGenericFragment.EXTRA_PASSWORD_QUALITY,
|
||||
lockPatternUtils.getKeyguardStoredPasswordQuality(UserHandle.myUserId()));
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelButtonClick() {
|
||||
if (isKeyguardSecure()) {
|
||||
// If the keyguard is already set up securely (maybe the user added a backup screen
|
||||
// lock and skipped fingerprint), return RESULT_SKIP directly.
|
||||
setResult(RESULT_SKIP, mAlreadyHadLockScreenSetup ? null : getMetricIntent(null));
|
||||
finish();
|
||||
} else {
|
||||
setResult(SetupSkipDialog.RESULT_SKIP);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Propagate lock screen metrics if the user goes back from the fingerprint setup screen
|
||||
* after having added lock screen to his device.
|
||||
*/
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (!mAlreadyHadLockScreenSetup && isKeyguardSecure()) {
|
||||
setResult(Activity.RESULT_CANCELED, getMetricIntent(null));
|
||||
}
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
private boolean isKeyguardSecure() {
|
||||
return getSystemService(KeyguardManager.class).isKeyguardSecure();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.FINGERPRINT_ENROLL_INTRO_SETUP;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user