Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4b96dc3e authored by Irina Dumitrescu's avatar Irina Dumitrescu
Browse files

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

Test: atest RunSettingsRoboTests
Bug: 120039091
Change-Id: Ib0860ccbc1ba84a2ac8dafcf3cf33f6ddf160e4c
parent 4db6ebbf
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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>
+6 −8
Original line number Diff line number Diff line
@@ -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);
        }
    }
}
+6 −7
Original line number Diff line number Diff line
@@ -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
+17 −8
Original line number Diff line number Diff line
@@ -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);
    }
}