Introduce LockscreenCredential
Bug: 65239740 Test: make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.password Change-Id: Icb73d639291d6d2eda8015e18e93d0906f916bb2
This commit is contained in:
@@ -36,12 +36,14 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.internal.widget.LockPatternUtils.RequestThrottledException;
|
||||
import com.android.internal.widget.LockPatternView;
|
||||
import com.android.internal.widget.LockPatternView.Cell;
|
||||
import com.android.internal.widget.LockPatternView.DisplayMode;
|
||||
import com.android.internal.widget.LockscreenCredential;
|
||||
import com.android.settings.EncryptionInterstitial;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
@@ -116,7 +118,7 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
return this;
|
||||
}
|
||||
|
||||
public IntentBuilder setPattern(byte[] pattern) {
|
||||
public IntentBuilder setPattern(LockscreenCredential pattern) {
|
||||
mIntent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD, pattern);
|
||||
return this;
|
||||
}
|
||||
@@ -188,7 +190,7 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
|
||||
private static final String FRAGMENT_TAG_SAVE_AND_FINISH = "save_and_finish_worker";
|
||||
|
||||
private byte[] mCurrentPattern;
|
||||
private LockscreenCredential mCurrentCredential;
|
||||
private boolean mHasChallenge;
|
||||
private long mChallenge;
|
||||
protected TextView mTitleText;
|
||||
@@ -198,7 +200,7 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
protected TextView mFooterText;
|
||||
protected FooterButton mSkipOrClearButton;
|
||||
private FooterButton mNextButton;
|
||||
protected List<LockPatternView.Cell> mChosenPattern = null;
|
||||
@VisibleForTesting protected LockscreenCredential mChosenPattern;
|
||||
private ColorStateList mDefaultHeaderColorList;
|
||||
|
||||
// ScrollView that contains title and header, only exist in land mode
|
||||
@@ -225,7 +227,7 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
getActivity().setResult(RESULT_FINISHED);
|
||||
getActivity().finish();
|
||||
} else {
|
||||
mCurrentPattern = data.getByteArrayExtra(
|
||||
mCurrentCredential = data.getParcelableExtra(
|
||||
ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
|
||||
}
|
||||
|
||||
@@ -262,16 +264,19 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
if (mUiStage == Stage.NeedToConfirm || mUiStage == Stage.ConfirmWrong) {
|
||||
if (mChosenPattern == null) throw new IllegalStateException(
|
||||
"null chosen pattern in stage 'need to confirm");
|
||||
if (mChosenPattern.equals(pattern)) {
|
||||
updateStage(Stage.ChoiceConfirmed);
|
||||
} else {
|
||||
updateStage(Stage.ConfirmWrong);
|
||||
try (LockscreenCredential confirmPattern =
|
||||
LockscreenCredential.createPattern(pattern)) {
|
||||
if (mChosenPattern.equals(confirmPattern)) {
|
||||
updateStage(Stage.ChoiceConfirmed);
|
||||
} else {
|
||||
updateStage(Stage.ConfirmWrong);
|
||||
}
|
||||
}
|
||||
} else if (mUiStage == Stage.Introduction || mUiStage == Stage.ChoiceTooShort){
|
||||
if (pattern.size() < LockPatternUtils.MIN_LOCK_PATTERN_SIZE) {
|
||||
updateStage(Stage.ChoiceTooShort);
|
||||
} else {
|
||||
mChosenPattern = new ArrayList<LockPatternView.Cell>(pattern);
|
||||
mChosenPattern = LockscreenCredential.createPattern(pattern);
|
||||
updateStage(Stage.FirstChoiceValid);
|
||||
}
|
||||
} else {
|
||||
@@ -458,12 +463,12 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
SaveAndFinishWorker w = new SaveAndFinishWorker();
|
||||
final boolean required = getActivity().getIntent().getBooleanExtra(
|
||||
EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true);
|
||||
byte[] current = intent.getByteArrayExtra(
|
||||
LockscreenCredential current = intent.getParcelableExtra(
|
||||
ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
|
||||
w.setBlocking(true);
|
||||
w.setListener(this);
|
||||
w.start(mChooseLockSettingsHelper.utils(), required,
|
||||
false, 0, LockPatternUtils.byteArrayToPattern(current), current, mUserId);
|
||||
false, 0, current, current, mUserId);
|
||||
}
|
||||
mForFingerprint = intent.getBooleanExtra(
|
||||
ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, false);
|
||||
@@ -541,8 +546,8 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
final boolean confirmCredentials = getActivity().getIntent()
|
||||
.getBooleanExtra(ChooseLockGeneric.CONFIRM_CREDENTIALS, true);
|
||||
Intent intent = getActivity().getIntent();
|
||||
mCurrentPattern =
|
||||
intent.getByteArrayExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
|
||||
mCurrentCredential =
|
||||
intent.getParcelableExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
|
||||
mHasChallenge = intent.getBooleanExtra(
|
||||
ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, false);
|
||||
mChallenge = intent.getLongExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, 0);
|
||||
@@ -565,13 +570,10 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
}
|
||||
} else {
|
||||
// restore from previous state
|
||||
final byte[] pattern = savedInstanceState.getByteArray(KEY_PATTERN_CHOICE);
|
||||
if (pattern != null) {
|
||||
mChosenPattern = LockPatternUtils.byteArrayToPattern(pattern);
|
||||
}
|
||||
mChosenPattern = savedInstanceState.getParcelable(KEY_PATTERN_CHOICE);
|
||||
|
||||
if (mCurrentPattern == null) {
|
||||
mCurrentPattern = savedInstanceState.getByteArray(KEY_CURRENT_PATTERN);
|
||||
if (mCurrentCredential == null) {
|
||||
mCurrentCredential = savedInstanceState.getParcelable(KEY_CURRENT_PATTERN);
|
||||
}
|
||||
updateStage(Stage.values()[savedInstanceState.getInt(KEY_UI_STAGE)]);
|
||||
|
||||
@@ -606,6 +608,7 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
|
||||
public void handleLeftButton() {
|
||||
if (mUiStage.leftMode == LeftButtonMode.Retry) {
|
||||
mChosenPattern.zeroize();
|
||||
mChosenPattern = null;
|
||||
mLockPatternView.clearPattern();
|
||||
updateStage(Stage.Introduction);
|
||||
@@ -667,12 +670,11 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
|
||||
outState.putInt(KEY_UI_STAGE, mUiStage.ordinal());
|
||||
if (mChosenPattern != null) {
|
||||
outState.putByteArray(KEY_PATTERN_CHOICE,
|
||||
LockPatternUtils.patternToByteArray(mChosenPattern));
|
||||
outState.putParcelable(KEY_PATTERN_CHOICE, mChosenPattern);
|
||||
}
|
||||
|
||||
if (mCurrentPattern != null) {
|
||||
outState.putByteArray(KEY_CURRENT_PATTERN, mCurrentPattern);
|
||||
if (mCurrentCredential != null) {
|
||||
outState.putParcelable(KEY_CURRENT_PATTERN, mCurrentCredential);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -812,15 +814,18 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
final boolean required = getActivity().getIntent().getBooleanExtra(
|
||||
EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true);
|
||||
mSaveAndFinishWorker.start(mChooseLockSettingsHelper.utils(), required,
|
||||
mHasChallenge, mChallenge, mChosenPattern, mCurrentPattern, mUserId);
|
||||
mHasChallenge, mChallenge, mChosenPattern, mCurrentCredential, mUserId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChosenLockSaveFinished(boolean wasSecureBefore, Intent resultData) {
|
||||
getActivity().setResult(RESULT_FINISHED, resultData);
|
||||
|
||||
if (mCurrentPattern != null) {
|
||||
Arrays.fill(mCurrentPattern, (byte) 0);
|
||||
if (mChosenPattern != null) {
|
||||
mChosenPattern.zeroize();
|
||||
}
|
||||
if (mCurrentCredential != null) {
|
||||
mCurrentCredential.zeroize();
|
||||
}
|
||||
|
||||
if (!wasSecureBefore) {
|
||||
@@ -835,16 +840,17 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
|
||||
public static class SaveAndFinishWorker extends SaveChosenLockWorkerBase {
|
||||
|
||||
private List<LockPatternView.Cell> mChosenPattern;
|
||||
private byte[] mCurrentPattern;
|
||||
private LockscreenCredential mChosenPattern;
|
||||
private LockscreenCredential mCurrentCredential;
|
||||
private boolean mLockVirgin;
|
||||
|
||||
public void start(LockPatternUtils utils, boolean credentialRequired,
|
||||
boolean hasChallenge, long challenge,
|
||||
List<LockPatternView.Cell> chosenPattern, byte[] currentPattern, int userId) {
|
||||
public void start(LockPatternUtils utils, boolean credentialRequired, boolean hasChallenge,
|
||||
long challenge, LockscreenCredential chosenPattern,
|
||||
LockscreenCredential currentCredential, int userId) {
|
||||
prepare(utils, credentialRequired, hasChallenge, challenge, userId);
|
||||
|
||||
mCurrentPattern = currentPattern;
|
||||
mCurrentCredential = currentCredential != null ? currentCredential
|
||||
: LockscreenCredential.createNone();
|
||||
mChosenPattern = chosenPattern;
|
||||
mUserId = userId;
|
||||
|
||||
@@ -856,12 +862,13 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
@Override
|
||||
protected Pair<Boolean, Intent> saveAndVerifyInBackground() {
|
||||
final int userId = mUserId;
|
||||
final boolean success = mUtils.saveLockPattern(mChosenPattern, mCurrentPattern, userId);
|
||||
final boolean success = mUtils.setLockCredential(mChosenPattern, mCurrentCredential,
|
||||
userId);
|
||||
Intent result = null;
|
||||
if (success && mHasChallenge) {
|
||||
byte[] token;
|
||||
try {
|
||||
token = mUtils.verifyPattern(mChosenPattern, mChallenge, userId);
|
||||
token = mUtils.verifyCredential(mChosenPattern, mChallenge, userId);
|
||||
} catch (RequestThrottledException e) {
|
||||
token = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user