private Preference mRemoveButton;
private Preference mEnrollButton;
+ private boolean mConfirmingPassword;
+
private final FaceSettingsRemoveButtonPreferenceController.Listener mRemovalListener = () -> {
// Disable the toggles until the user re-enrolls
if (savedInstanceState != null) {
mToken = savedInstanceState.getByteArray(KEY_TOKEN);
}
+ }
- if (mToken == null) {
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ if (mToken == null && !mConfirmingPassword) {
+ // Generate challenge in onResume instead of onCreate, since FaceSettings can be
+ // created while Keyguard is showing, in which case the resetLockout revokeChallenge
+ // will invalidate the too-early created challenge here.
final long challenge = mFaceManager.generateChallenge();
ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(getActivity(), this);
+
+ mConfirmingPassword = true;
if (!helper.launchConfirmationActivity(CONFIRM_REQUEST,
getString(R.string.security_settings_face_preference_title),
null, null, challenge, mUserId)) {
Log.e(TAG, "Password not set");
finish();
}
- }
- }
-
- @Override
- public void onResume() {
- super.onResume();
- if (mToken != null) {
+ } else {
mAttentionController.setToken(mToken);
mEnrollController.setToken(mToken);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CONFIRM_REQUEST) {
+ mConfirmingPassword = false;
if (resultCode == RESULT_FINISHED || resultCode == RESULT_OK) {
mFaceManager.setActiveUser(mUserId);
// The pin/pattern/password was set.
}
@Override
- public void onDestroy() {
- super.onDestroy();
- if (getActivity().isFinishing()) {
- final int result = mFaceManager.revokeChallenge();
- if (result < 0) {
- Log.w(TAG, "revokeChallenge failed, result: " + result);
+ public void onStop() {
+ super.onStop();
+
+ if (!mEnrollController.isClicked() && !getActivity().isChangingConfigurations()
+ && !mConfirmingPassword) {
+ // Revoke challenge and finish
+ if (mToken != null) {
+ final int result = mFaceManager.revokeChallenge();
+ if (result < 0) {
+ Log.w(TAG, "revokeChallenge failed, result: " + result);
+ }
+ mToken = null;
}
+ getActivity().finish();
}
}
private byte[] mToken;
private SettingsActivity mActivity;
private Button mButton;
+ private boolean mIsClicked;
public FaceSettingsEnrollButtonPreferenceController(Context context) {
this(context, KEY);
@Override
public void onClick(View v) {
+ mIsClicked = true;
final Intent intent = new Intent();
intent.setClassName("com.android.settings", FaceEnrollIntroduction.class.getName());
intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
mToken = token;
}
+ // Return the click state, then clear its state.
+ public boolean isClicked() {
+ final boolean wasClicked = mIsClicked;
+ mIsClicked = false;
+ return wasClicked;
+ }
+
public void setActivity(SettingsActivity activity) {
mActivity = activity;
}