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

Commit a0e1236f authored by Andres Morales's avatar Andres Morales
Browse files

[LockSettings] pipe old password through when setting new one

Change-Id: Ia98b93d1cdb8c2d0bff42de7ecb59f5b80fb780e
parent f24037da
Loading
Loading
Loading
Loading
+22 −3
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ public class ChooseLockGeneric extends SettingsActivity {
        private int mEncryptionRequestQuality;
        private boolean mEncryptionRequestDisabled;
        private boolean mRequirePassword;
        private String mUserPassword;
        private LockPatternUtils mLockPatternUtils;
        private FingerprintManager mFingerprintManager;
        private RemovalCallback mRemovalCallback = new RemovalCallback() {
@@ -146,7 +147,7 @@ public class ChooseLockGeneric extends SettingsActivity {
                ChooseLockSettingsHelper helper =
                        new ChooseLockSettingsHelper(this.getActivity(), this);
                if (!helper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST,
                        getString(R.string.unlock_set_unlock_launch_picker_title))) {
                        getString(R.string.unlock_set_unlock_launch_picker_title), true)) {
                    mPasswordConfirmed = true; // no password set, so no need to confirm
                    updatePreferencesOrFinish();
                } else {
@@ -177,6 +178,8 @@ public class ChooseLockGeneric extends SettingsActivity {
         * @param quality
         * @param disabled
         */
        // TODO: why does this take disabled, its always called with a quality higher than
        // what makes sense with disabled == true
        private void maybeEnableEncryption(int quality, boolean disabled) {
            if (Process.myUserHandle().isOwner() && LockPatternUtils.isDeviceEncryptionEnabled()) {
                mEncryptionRequestQuality = quality;
@@ -201,6 +204,7 @@ public class ChooseLockGeneric extends SettingsActivity {
            mWaitingForConfirmation = false;
            if (requestCode == CONFIRM_EXISTING_REQUEST && resultCode == Activity.RESULT_OK) {
                mPasswordConfirmed = true;
                mUserPassword = data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
                updatePreferencesOrFinish();
            } else if (requestCode == ENABLE_ENCRYPTION_REQUEST
                    && resultCode == Activity.RESULT_OK) {
@@ -385,12 +389,27 @@ public class ChooseLockGeneric extends SettingsActivity {
                    maxLength, requirePasswordToDecrypt, confirmCredentials);
        }

        // SetupWizard version will not need this as they will never be changing a password
        // TODO: confirm
        private Intent getLockPasswordIntent(Context context, int quality, int minLength,
                final int maxLength, boolean requirePasswordToDecrypt, String password) {
            return ChooseLockPassword.createIntent(context, quality, minLength, maxLength,
                    requirePasswordToDecrypt, password);
        }

        protected Intent getLockPatternIntent(Context context, final boolean requirePassword,
                final boolean confirmCredentials) {
            return ChooseLockPattern.createIntent(context, requirePassword,
                    confirmCredentials);
        }

        // SetupWizard version will not need this as they will never be changing a password
        // TODO: confirm
        private Intent getLockPatternIntent(Context context, final boolean requirePassword,
                final String pattern) {
            return ChooseLockPattern.createIntent(context, requirePassword, pattern);
        }

        protected Intent getEncryptionInterstitialIntent(Context context, int quality,
                boolean required) {
            return EncryptionInterstitial.createStartIntent(context, quality, required);
@@ -421,11 +440,11 @@ public class ChooseLockGeneric extends SettingsActivity {
                }
                final int maxLength = mDPM.getPasswordMaximumLength(quality);
                Intent intent = getLockPasswordIntent(context, quality, minLength,
                        maxLength, mRequirePassword,  /* confirm credentials */false);
                        maxLength, mRequirePassword, mUserPassword);
                startActivityForResult(intent, CHOOSE_LOCK_REQUEST);
            } else if (quality == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) {
                Intent intent = getLockPatternIntent(context, mRequirePassword,
                        /* confirm credentials */false);
                        mUserPassword);
                startActivityForResult(intent, CHOOSE_LOCK_REQUEST);
            } else if (quality == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
                mChooseLockSettingsHelper.utils().clearLock();
+23 −2
Original line number Diff line number Diff line
@@ -76,6 +76,14 @@ public class ChooseLockPassword extends SettingsActivity {
        return intent;
    }

    public static Intent createIntent(Context context, int quality,
            int minLength, final int maxLength, boolean requirePasswordToDecrypt, String password) {
        Intent intent = createIntent(context, quality, minLength, maxLength, requirePasswordToDecrypt,
                false);
        intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD, password);
        return intent;
    }

    @Override
    protected boolean isValidFragment(String fragmentName) {
        if (ChooseLockPasswordFragment.class.getName().equals(fragmentName)) return true;
@@ -101,6 +109,9 @@ public class ChooseLockPassword extends SettingsActivity {
            implements OnClickListener, OnEditorActionListener,  TextWatcher {
        private static final String KEY_FIRST_PIN = "first_pin";
        private static final String KEY_UI_STAGE = "ui_stage";
        private static final String KEY_CURRENT_PASSWORD = "current_password";

        private String mCurrentPassword;
        private TextView mPasswordEntry;
        private int mPasswordMinLength = LockPatternUtils.MIN_LOCK_PASSWORD_SIZE;
        private int mPasswordMaxLength = 16;
@@ -239,19 +250,25 @@ public class ChooseLockPassword extends SettingsActivity {

            Intent intent = getActivity().getIntent();
            final boolean confirmCredentials = intent.getBooleanExtra("confirm_credentials", true);
            mCurrentPassword = intent.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
            if (savedInstanceState == null) {
                updateStage(Stage.Introduction);
                if (confirmCredentials) {
                    mChooseLockSettingsHelper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST,
                            getString(R.string.unlock_set_unlock_launch_picker_title));
                            getString(R.string.unlock_set_unlock_launch_picker_title), true);
                }
            } else {
                // restore from previous state
                mFirstPin = savedInstanceState.getString(KEY_FIRST_PIN);
                final String state = savedInstanceState.getString(KEY_UI_STAGE);
                if (state != null) {
                    mUiStage = Stage.valueOf(state);
                    updateStage(mUiStage);
                }

                if (mCurrentPassword == null) {
                    mCurrentPassword = savedInstanceState.getString(KEY_CURRENT_PASSWORD);
                }
            }
            mDone = false;
            if (activity instanceof SettingsActivity) {
@@ -287,6 +304,7 @@ public class ChooseLockPassword extends SettingsActivity {
            super.onSaveInstanceState(outState);
            outState.putString(KEY_UI_STAGE, mUiStage.name());
            outState.putString(KEY_FIRST_PIN, mFirstPin);
            outState.putString(KEY_CURRENT_PASSWORD, mCurrentPassword);
        }

        @Override
@@ -298,6 +316,9 @@ public class ChooseLockPassword extends SettingsActivity {
                    if (resultCode != Activity.RESULT_OK) {
                        getActivity().setResult(RESULT_FINISHED);
                        getActivity().finish();
                    } else {
                        mCurrentPassword = data.getStringExtra(
                                ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
                    }
                    break;
            }
@@ -441,7 +462,7 @@ public class ChooseLockPassword extends SettingsActivity {
                    final boolean required = getActivity().getIntent().getBooleanExtra(
                            EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true);
                    mLockPatternUtils.setCredentialRequiredToDecrypt(required);
                    mLockPatternUtils.saveLockPassword(pin, mRequestedQuality);
                    mLockPatternUtils.saveLockPassword(pin, mCurrentPassword, mRequestedQuality);
                    getActivity().setResult(RESULT_FINISHED);
                    getActivity().finish();
                    mDone = true;
+27 −2
Original line number Diff line number Diff line
@@ -77,6 +77,13 @@ public class ChooseLockPattern extends SettingsActivity {
        return intent;
    }

    public static Intent createIntent(Context context,
            boolean requirePassword, String pattern) {
        Intent intent = createIntent(context, requirePassword, false);
        intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD, pattern);
        return intent;
    }

    @Override
    protected boolean isValidFragment(String fragmentName) {
        if (ChooseLockPatternFragment.class.getName().equals(fragmentName)) return true;
@@ -115,6 +122,7 @@ public class ChooseLockPattern extends SettingsActivity {

        private static final int ID_EMPTY_MESSAGE = -1;

        private String mCurrentPattern;
        protected TextView mHeaderText;
        protected LockPatternView mLockPatternView;
        protected TextView mFooterText;
@@ -142,7 +150,11 @@ public class ChooseLockPattern extends SettingsActivity {
                    if (resultCode != Activity.RESULT_OK) {
                        getActivity().setResult(RESULT_FINISHED);
                        getActivity().finish();
                    } else {
                        mCurrentPattern = data.getStringExtra(
                                ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
                    }

                    updateStage(Stage.Introduction);
                    break;
            }
@@ -329,6 +341,7 @@ public class ChooseLockPattern extends SettingsActivity {

        private static final String KEY_UI_STAGE = "uiStage";
        private static final String KEY_PATTERN_CHOICE = "chosenPattern";
        private static final String KEY_CURRENT_PATTERN = "currentPattern";

        @Override
        public void onCreate(Bundle savedInstanceState) {
@@ -371,6 +384,8 @@ public class ChooseLockPattern extends SettingsActivity {

            final boolean confirmCredentials = getActivity().getIntent()
                    .getBooleanExtra("confirm_credentials", true);
            mCurrentPattern = getActivity().getIntent()
                    .getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);

            if (savedInstanceState == null) {
                if (confirmCredentials) {
@@ -380,7 +395,7 @@ public class ChooseLockPattern extends SettingsActivity {
                    boolean launchedConfirmationActivity =
                        mChooseLockSettingsHelper.launchConfirmationActivity(
                                CONFIRM_EXISTING_REQUEST,
                                getString(R.string.unlock_set_unlock_launch_picker_title));
                                getString(R.string.unlock_set_unlock_launch_picker_title), true);
                    if (!launchedConfirmationActivity) {
                        updateStage(Stage.Introduction);
                    }
@@ -393,6 +408,10 @@ public class ChooseLockPattern extends SettingsActivity {
                if (patternString != null) {
                    mChosenPattern = LockPatternUtils.stringToPattern(patternString);
                }

                if (mCurrentPattern == null) {
                    mCurrentPattern = savedInstanceState.getString(KEY_CURRENT_PATTERN);
                }
                updateStage(Stage.values()[savedInstanceState.getInt(KEY_UI_STAGE)]);
            }
            mDone = false;
@@ -472,6 +491,11 @@ public class ChooseLockPattern extends SettingsActivity {
                outState.putString(KEY_PATTERN_CHOICE,
                        LockPatternUtils.patternToString(mChosenPattern));
            }

            if (mCurrentPattern != null) {
                outState.putString(KEY_CURRENT_PATTERN,
                        mCurrentPattern);
            }
        }

        /**
@@ -571,8 +595,9 @@ public class ChooseLockPattern extends SettingsActivity {

            final boolean required = getActivity().getIntent().getBooleanExtra(
                    EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true);

            utils.setCredentialRequiredToDecrypt(required);
            utils.saveLockPattern(mChosenPattern);
            utils.saveLockPattern(mChosenPattern, mCurrentPattern);

            if (lockVirgin) {
                utils.setVisiblePatternEnabled(true);