Fail the screen lock flow if the old password has already changed.

Test: atest RunSettingsRoboTests
Bug: 120039091
Change-Id: Ib0860ccbc1ba84a2ac8dafcf3cf33f6ddf160e4c
This commit is contained in:
Irina Dumitrescu
2019-02-28 15:35:36 +00:00
parent 4db6ebbf4d
commit 4b96dc3ec7
4 changed files with 32 additions and 23 deletions

View File

@@ -1584,6 +1584,9 @@
<!-- Label for ChoosePassword/PIN Clear button that clears all text entered by the user so far. -->
<string name="lockpassword_clear_label">Clear</string>
<!-- Toast for a failed password change attempt when the old credential has been changed. [CHAR LIMIT=120]-->
<string name="lockpassword_credential_changed">Screen lock was already changed. Try again with the new screen lock.</string>
<!-- Label for LockPatternTutorial Cancel button -->
<string name="lockpattern_tutorial_cancel_label">Cancel</string>

View File

@@ -45,10 +45,10 @@ import android.text.Spannable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.util.Pair;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.LinearLayout;
@@ -1100,12 +1100,11 @@ public class ChooseLockPassword extends SettingsActivity {
}
@Override
protected Intent saveAndVerifyInBackground() {
protected Pair<Boolean, Intent> saveAndVerifyInBackground() {
final boolean success = mUtils.saveLockPassword(
mChosenPassword, mCurrentPassword, mRequestedQuality, mUserId);
Intent result = null;
mUtils.saveLockPassword(mChosenPassword, mCurrentPassword, mRequestedQuality,
mUserId);
if (mHasChallenge) {
if (success && mHasChallenge) {
byte[] token;
try {
token = mUtils.verifyPassword(mChosenPassword, mChallenge, mUserId);
@@ -1120,8 +1119,7 @@ public class ChooseLockPassword extends SettingsActivity {
result = new Intent();
result.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token);
}
return result;
return Pair.create(success, result);
}
}
}

View File

@@ -24,6 +24,7 @@ import android.content.res.ColorStateList;
import android.content.res.Resources.Theme;
import android.os.Bundle;
import android.util.Log;
import android.util.Pair;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@@ -854,12 +855,11 @@ public class ChooseLockPattern extends SettingsActivity {
}
@Override
protected Intent saveAndVerifyInBackground() {
Intent result = null;
protected Pair<Boolean, Intent> saveAndVerifyInBackground() {
final int userId = mUserId;
mUtils.saveLockPattern(mChosenPattern, mCurrentPattern, userId);
if (mHasChallenge) {
final boolean success = mUtils.saveLockPattern(mChosenPattern, mCurrentPattern, userId);
Intent result = null;
if (success && mHasChallenge) {
byte[] token;
try {
token = mUtils.verifyPattern(mChosenPattern, mChallenge, userId);
@@ -874,8 +874,7 @@ public class ChooseLockPattern extends SettingsActivity {
result = new Intent();
result.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token);
}
return result;
return Pair.create(success, result);
}
@Override

View File

@@ -21,10 +21,13 @@ import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.UserManager;
import android.util.Pair;
import android.widget.Toast;
import androidx.fragment.app.Fragment;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
/**
* An invisible retained worker fragment to track the AsyncWork that saves (and optionally
@@ -84,7 +87,7 @@ abstract class SaveChosenLockWorkerBase extends Fragment {
protected void start() {
if (mBlocking) {
finish(saveAndVerifyInBackground());
finish(saveAndVerifyInBackground().second);
} else {
new Task().execute();
}
@@ -92,9 +95,10 @@ abstract class SaveChosenLockWorkerBase extends Fragment {
/**
* Executes the save and verify work in background.
* @return Intent with challenge token or null.
* @return pair where the first is a boolean confirming whether the change was successful or not
* and second is the Intent which has the challenge token or is null.
*/
protected abstract Intent saveAndVerifyInBackground();
protected abstract Pair<Boolean, Intent> saveAndVerifyInBackground();
protected void finish(Intent resultData) {
mFinished = true;
@@ -108,19 +112,24 @@ abstract class SaveChosenLockWorkerBase extends Fragment {
mBlocking = blocking;
}
private class Task extends AsyncTask<Void, Void, Intent> {
private class Task extends AsyncTask<Void, Void, Pair<Boolean, Intent>> {
@Override
protected Intent doInBackground(Void... params){
protected Pair<Boolean, Intent> doInBackground(Void... params){
return saveAndVerifyInBackground();
}
@Override
protected void onPostExecute(Intent resultData) {
finish(resultData);
protected void onPostExecute(Pair<Boolean, Intent> resultData) {
if (!resultData.first) {
Toast.makeText(getContext(), R.string.lockpassword_credential_changed,
Toast.LENGTH_LONG).show();
}
finish(resultData.second);
}
}
interface Listener {
public void onChosenLockSaveFinished(boolean wasSecureBefore, Intent resultData);
void onChosenLockSaveFinished(boolean wasSecureBefore, Intent resultData);
}
}