Commit 468a1891 authored by android-build-team Robot's avatar android-build-team Robot

Snap for 5422807 from 5d9189fa to pi-qpr3-b-release

Change-Id: Iffef7cc1a559bae689f7d1a6e91cfcd7d835dc3b
parents 56cbe0bb 5d9189fa
......@@ -38,6 +38,7 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.core.InstrumentedFragment;
import java.util.Arrays;
import java.util.Locale;
public class CryptKeeperConfirm extends InstrumentedFragment {
......@@ -87,7 +88,12 @@ public class CryptKeeperConfirm extends InstrumentedFragment {
IStorageManager storageManager = IStorageManager.Stub.asInterface(service);
try {
Bundle args = getIntent().getExtras();
storageManager.encryptStorage(args.getInt("type", -1), args.getString("password"));
// TODO(b/120484642): Update vold to accept a password as a byte array
byte[] passwordBytes = args.getByteArray("password");
String password = passwordBytes != null ? new String(passwordBytes) : null;
Arrays.fill(passwordBytes, (byte) 0);
storageManager.encryptStorage(args.getInt("type", -1),
password);
} catch (Exception e) {
Log.e("CryptKeeper", "Error while encrypting...", e);
}
......
......@@ -63,6 +63,7 @@ import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedPreference;
import java.util.Arrays;
import java.util.List;
public class ChooseLockGeneric extends SettingsActivity {
......@@ -144,7 +145,7 @@ public class ChooseLockGeneric extends SettingsActivity {
private int mEncryptionRequestQuality;
private boolean mEncryptionRequestDisabled;
private boolean mForChangeCredRequiredForBoot = false;
private String mUserPassword;
private byte[] mUserPassword;
private LockPatternUtils mLockPatternUtils;
private FingerprintManager mFingerprintManager;
private int mUserId;
......@@ -184,7 +185,7 @@ public class ChooseLockGeneric extends SettingsActivity {
.getBooleanExtra(CONFIRM_CREDENTIALS, true);
if (getActivity() instanceof ChooseLockGeneric.InternalActivity) {
mPasswordConfirmed = !confirmCredentials;
mUserPassword = getActivity().getIntent().getStringExtra(
mUserPassword = getActivity().getIntent().getByteArrayExtra(
ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
}
mHideDrawer = getActivity().getIntent().getBooleanExtra(EXTRA_HIDE_DRAWER, false);
......@@ -206,7 +207,7 @@ public class ChooseLockGeneric extends SettingsActivity {
mEncryptionRequestDisabled = savedInstanceState.getBoolean(
ENCRYPT_REQUESTED_DISABLED);
if (mUserPassword == null) {
mUserPassword = savedInstanceState.getString(
mUserPassword = savedInstanceState.getByteArray(
ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
}
}
......@@ -351,10 +352,12 @@ 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);
mUserPassword = data != null
? data.getByteArrayExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD)
: null;
updatePreferencesOrFinish(false /* isRecreatingActivity */);
if (mForChangeCredRequiredForBoot) {
if (!TextUtils.isEmpty(mUserPassword)) {
if (!(mUserPassword == null || mUserPassword.length == 0)) {
maybeEnableEncryption(
mLockPatternUtils.getKeyguardStoredPasswordQuality(mUserId), false);
} else {
......@@ -414,7 +417,7 @@ public class ChooseLockGeneric extends SettingsActivity {
outState.putInt(ENCRYPT_REQUESTED_QUALITY, mEncryptionRequestQuality);
outState.putBoolean(ENCRYPT_REQUESTED_DISABLED, mEncryptionRequestDisabled);
if (mUserPassword != null) {
outState.putString(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD, mUserPassword);
outState.putByteArray(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD, mUserPassword);
}
}
......@@ -590,7 +593,7 @@ public class ChooseLockGeneric extends SettingsActivity {
setPreferenceSummary(ScreenLockType.MANAGED, R.string.secure_lock_encryption_warning);
}
protected Intent getLockManagedPasswordIntent(String password) {
protected Intent getLockManagedPasswordIntent(byte[] password) {
return mManagedPasswordProvider.createIntent(false, password);
}
......
......@@ -70,6 +70,7 @@ import com.android.settings.widget.ImeAwareEditText;
import com.android.setupwizardlib.GlifLayout;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ChooseLockPassword extends SettingsActivity {
......@@ -130,7 +131,7 @@ public class ChooseLockPassword extends SettingsActivity {
return this;
}
public IntentBuilder setPassword(String password) {
public IntentBuilder setPassword(byte[] password) {
mIntent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD, password);
return this;
}
......@@ -176,8 +177,8 @@ public class ChooseLockPassword extends SettingsActivity {
private static final String KEY_CURRENT_PASSWORD = "current_password";
private static final String FRAGMENT_TAG_SAVE_AND_FINISH = "save_and_finish_worker";
private String mCurrentPassword;
private String mChosenPassword;
private byte[] mCurrentPassword;
private byte[] mChosenPassword;
private boolean mHasChallenge;
private long mChallenge;
private ImeAwareEditText mPasswordEntry;
......@@ -208,7 +209,7 @@ public class ChooseLockPassword extends SettingsActivity {
private GlifLayout mLayout;
protected boolean mForFingerprint;
private String mFirstPin;
private byte[] mFirstPin;
private RecyclerView mPasswordRestrictionView;
protected boolean mIsAlphaMode;
protected Button mSkipButton;
......@@ -228,7 +229,7 @@ public class ChooseLockPassword extends SettingsActivity {
private static final int MIN_NUMBER_IN_PASSWORD = 4;
private static final int MIN_NON_LETTER_IN_PASSWORD = 5;
// Error code returned from {@link #validatePassword(String)}.
// Error code returned from {@link #validatePassword(byte[])}.
static final int NO_ERROR = 0;
static final int CONTAIN_INVALID_CHARACTERS = 1 << 0;
static final int TOO_SHORT = 1 << 1;
......@@ -350,12 +351,13 @@ public class ChooseLockPassword extends SettingsActivity {
SaveAndFinishWorker w = new SaveAndFinishWorker();
final boolean required = getActivity().getIntent().getBooleanExtra(
EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true);
String current = intent.getStringExtra(
byte[] currentBytes = intent.getByteArrayExtra(
ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
w.setBlocking(true);
w.setListener(this);
w.start(mChooseLockSettingsHelper.utils(), required,
false, 0, current, current, mRequestedQuality, mUserId);
w.start(mChooseLockSettingsHelper.utils(), required, false, 0,
currentBytes, currentBytes, mRequestedQuality, mUserId);
}
mTextChangedHandler = new TextChangedHandler();
}
......@@ -416,7 +418,8 @@ public class ChooseLockPassword extends SettingsActivity {
Intent intent = getActivity().getIntent();
final boolean confirmCredentials = intent.getBooleanExtra(
ChooseLockGeneric.CONFIRM_CREDENTIALS, true);
mCurrentPassword = intent.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
mCurrentPassword = intent.getByteArrayExtra(
ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
mHasChallenge = intent.getBooleanExtra(
ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, false);
mChallenge = intent.getLongExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, 0);
......@@ -428,8 +431,9 @@ public class ChooseLockPassword extends SettingsActivity {
mUserId);
}
} else {
// restore from previous state
mFirstPin = savedInstanceState.getString(KEY_FIRST_PIN);
mFirstPin = savedInstanceState.getByteArray(KEY_FIRST_PIN);
final String state = savedInstanceState.getString(KEY_UI_STAGE);
if (state != null) {
mUiStage = Stage.valueOf(state);
......@@ -437,7 +441,7 @@ public class ChooseLockPassword extends SettingsActivity {
}
if (mCurrentPassword == null) {
mCurrentPassword = savedInstanceState.getString(KEY_CURRENT_PASSWORD);
mCurrentPassword = savedInstanceState.getByteArray(KEY_CURRENT_PASSWORD);
}
// Re-attach to the exiting worker if there is one.
......@@ -536,8 +540,8 @@ public class ChooseLockPassword extends SettingsActivity {
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(KEY_UI_STAGE, mUiStage.name());
outState.putString(KEY_FIRST_PIN, mFirstPin);
outState.putString(KEY_CURRENT_PASSWORD, mCurrentPassword);
outState.putByteArray(KEY_FIRST_PIN, mFirstPin);
outState.putByteArray(KEY_CURRENT_PASSWORD, mCurrentPassword);
}
@Override
......@@ -550,7 +554,7 @@ public class ChooseLockPassword extends SettingsActivity {
getActivity().setResult(RESULT_FINISHED);
getActivity().finish();
} else {
mCurrentPassword = data.getStringExtra(
mCurrentPassword = data.getByteArrayExtra(
ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
}
break;
......@@ -641,22 +645,22 @@ public class ChooseLockPassword extends SettingsActivity {
* @param password the raw password the user typed in
* @return the validation result.
*/
private int validatePassword(String password) {
int validatePassword(byte[] password) {
int errorCode = NO_ERROR;
final PasswordMetrics metrics = PasswordMetrics.computeForPassword(password);
if (password.length() < mPasswordMinLength) {
if (password == null || password.length < mPasswordMinLength) {
if (mPasswordMinLength > mPasswordMinLengthToFulfillAllPolicies) {
errorCode |= TOO_SHORT;
}
} else if (password.length() > mPasswordMaxLength) {
} else if (password.length > mPasswordMaxLength) {
errorCode |= TOO_LONG;
} else {
// The length requirements are fulfilled.
final int dpmQuality = mLockPatternUtils.getRequestedPasswordQuality(mUserId);
if (dpmQuality == PASSWORD_QUALITY_NUMERIC_COMPLEX &&
metrics.numeric == password.length()) {
metrics.numeric == password.length) {
// Check for repeated characters or sequences (e.g. '1234', '0000', '2468')
// if DevicePolicyManager requires a complex numeric password. There can be
// two cases in the UI: 1. User chooses to enroll a PIN, 2. User chooses to
......@@ -675,8 +679,8 @@ public class ChooseLockPassword extends SettingsActivity {
}
// Allow non-control Latin-1 characters only.
for (int i = 0; i < password.length(); i++) {
char c = password.charAt(i);
for (int i = 0; i < password.length; i++) {
char c = (char) password[i];
if (c < 32 || c > 127) {
errorCode |= CONTAIN_INVALID_CHARACTERS;
break;
......@@ -746,8 +750,9 @@ public class ChooseLockPassword extends SettingsActivity {
public void handleNext() {
if (mSaveAndFinishWorker != null) return;
mChosenPassword = mPasswordEntry.getText().toString();
if (TextUtils.isEmpty(mChosenPassword)) {
// TODO(b/120484642): This is a point of entry for passwords from the UI
mChosenPassword = LockPatternUtils.charSequenceToByteArray(mPasswordEntry.getText());
if (mChosenPassword == null || mChosenPassword.length == 0) {
return;
}
if (mUiStage == Stage.Introduction) {
......@@ -755,9 +760,11 @@ public class ChooseLockPassword extends SettingsActivity {
mFirstPin = mChosenPassword;
mPasswordEntry.setText("");
updateStage(Stage.NeedToConfirm);
} else {
Arrays.fill(mChosenPassword, (byte) 0);
}
} else if (mUiStage == Stage.NeedToConfirm) {
if (mFirstPin.equals(mChosenPassword)) {
if (Arrays.equals(mFirstPin, mChosenPassword)) {
startSaveAndFinish();
} else {
CharSequence tmp = mPasswordEntry.getText();
......@@ -765,6 +772,7 @@ public class ChooseLockPassword extends SettingsActivity {
Selection.setSelection((Spannable) tmp, 0, tmp.length());
}
updateStage(Stage.ConfirmWrong);
Arrays.fill(mChosenPassword, (byte) 0);
}
}
}
......@@ -875,8 +883,8 @@ public class ChooseLockPassword extends SettingsActivity {
*/
protected void updateUi() {
final boolean canInput = mSaveAndFinishWorker == null;
String password = mPasswordEntry.getText().toString();
final int length = password.length();
byte[] password = LockPatternUtils.charSequenceToByteArray(mPasswordEntry.getText());
final int length = password.length;
if (mUiStage == Stage.Introduction) {
mPasswordRestrictionView.setVisibility(View.VISIBLE);
final int errorCode = validatePassword(password);
......@@ -904,6 +912,7 @@ public class ChooseLockPassword extends SettingsActivity {
setNextText(mUiStage.buttonText);
mPasswordEntryInputDisabler.setInputEnabled(canInput);
Arrays.fill(password, (byte) 0);
}
private int toVisibility(boolean visibleOrGone) {
......@@ -962,6 +971,18 @@ public class ChooseLockPassword extends SettingsActivity {
public void onChosenLockSaveFinished(boolean wasSecureBefore, Intent resultData) {
getActivity().setResult(RESULT_FINISHED, resultData);
if (mChosenPassword != null) {
Arrays.fill(mChosenPassword, (byte) 0);
}
if (mCurrentPassword != null) {
Arrays.fill(mCurrentPassword, (byte) 0);
}
if (mFirstPin != null) {
Arrays.fill(mFirstPin, (byte) 0);
}
mPasswordEntry.setText("");
if (!wasSecureBefore) {
Intent intent = getRedactionInterstitialIntent(getActivity());
if (intent != null) {
......@@ -999,13 +1020,13 @@ public class ChooseLockPassword extends SettingsActivity {
public static class SaveAndFinishWorker extends SaveChosenLockWorkerBase {
private String mChosenPassword;
private String mCurrentPassword;
private byte[] mChosenPassword;
private byte[] mCurrentPassword;
private int mRequestedQuality;
public void start(LockPatternUtils utils, boolean required,
boolean hasChallenge, long challenge,
String chosenPassword, String currentPassword, int requestedQuality, int userId) {
byte[] chosenPassword, byte[] currentPassword, int requestedQuality, int userId) {
prepare(utils, required, hasChallenge, challenge, userId);
mChosenPassword = chosenPassword;
......
......@@ -52,6 +52,7 @@ import com.android.setupwizardlib.GlifLayout;
import com.google.android.collect.Lists;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
......@@ -111,7 +112,7 @@ public class ChooseLockPattern extends SettingsActivity {
return this;
}
public IntentBuilder setPattern(String pattern) {
public IntentBuilder setPattern(byte[] pattern) {
mIntent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD, pattern);
return this;
}
......@@ -170,7 +171,7 @@ public class ChooseLockPattern extends SettingsActivity {
private static final String FRAGMENT_TAG_SAVE_AND_FINISH = "save_and_finish_worker";
private String mCurrentPattern;
private byte[] mCurrentPattern;
private boolean mHasChallenge;
private long mChallenge;
protected TextView mTitleText;
......@@ -208,7 +209,7 @@ public class ChooseLockPattern extends SettingsActivity {
getActivity().setResult(RESULT_FINISHED);
getActivity().finish();
} else {
mCurrentPattern = data.getStringExtra(
mCurrentPattern = data.getByteArrayExtra(
ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
}
......@@ -441,12 +442,12 @@ public class ChooseLockPattern extends SettingsActivity {
SaveAndFinishWorker w = new SaveAndFinishWorker();
final boolean required = getActivity().getIntent().getBooleanExtra(
EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true);
String current = intent.getStringExtra(
byte[] current = intent.getByteArrayExtra(
ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
w.setBlocking(true);
w.setListener(this);
w.start(mChooseLockSettingsHelper.utils(), required,
false, 0, LockPatternUtils.stringToPattern(current), current, mUserId);
false, 0, LockPatternUtils.byteArrayToPattern(current), current, mUserId);
}
mHideDrawer = getActivity().getIntent().getBooleanExtra(EXTRA_HIDE_DRAWER, false);
mForFingerprint = intent.getBooleanExtra(
......@@ -507,7 +508,8 @@ public class ChooseLockPattern extends SettingsActivity {
final boolean confirmCredentials = getActivity().getIntent()
.getBooleanExtra(ChooseLockGeneric.CONFIRM_CREDENTIALS, true);
Intent intent = getActivity().getIntent();
mCurrentPattern = intent.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
mCurrentPattern =
intent.getByteArrayExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
mHasChallenge = intent.getBooleanExtra(
ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, false);
mChallenge = intent.getLongExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, 0);
......@@ -530,13 +532,13 @@ public class ChooseLockPattern extends SettingsActivity {
}
} else {
// restore from previous state
final String patternString = savedInstanceState.getString(KEY_PATTERN_CHOICE);
if (patternString != null) {
mChosenPattern = LockPatternUtils.stringToPattern(patternString);
final byte[] pattern = savedInstanceState.getByteArray(KEY_PATTERN_CHOICE);
if (pattern != null) {
mChosenPattern = LockPatternUtils.byteArrayToPattern(pattern);
}
if (mCurrentPattern == null) {
mCurrentPattern = savedInstanceState.getString(KEY_CURRENT_PATTERN);
mCurrentPattern = savedInstanceState.getByteArray(KEY_CURRENT_PATTERN);
}
updateStage(Stage.values()[savedInstanceState.getInt(KEY_UI_STAGE)]);
......@@ -632,13 +634,12 @@ public class ChooseLockPattern extends SettingsActivity {
outState.putInt(KEY_UI_STAGE, mUiStage.ordinal());
if (mChosenPattern != null) {
outState.putString(KEY_PATTERN_CHOICE,
LockPatternUtils.patternToString(mChosenPattern));
outState.putByteArray(KEY_PATTERN_CHOICE,
LockPatternUtils.patternToByteArray(mChosenPattern));
}
if (mCurrentPattern != null) {
outState.putString(KEY_CURRENT_PATTERN,
mCurrentPattern);
outState.putByteArray(KEY_CURRENT_PATTERN, mCurrentPattern);
}
}
......@@ -784,6 +785,10 @@ public class ChooseLockPattern extends SettingsActivity {
public void onChosenLockSaveFinished(boolean wasSecureBefore, Intent resultData) {
getActivity().setResult(RESULT_FINISHED, resultData);
if (mCurrentPattern != null) {
Arrays.fill(mCurrentPattern, (byte) 0);
}
if (!wasSecureBefore) {
Intent intent = getRedactionInterstitialIntent(getActivity());
if (intent != null) {
......@@ -798,12 +803,12 @@ public class ChooseLockPattern extends SettingsActivity {
public static class SaveAndFinishWorker extends SaveChosenLockWorkerBase {
private List<LockPatternView.Cell> mChosenPattern;
private String mCurrentPattern;
private byte[] mCurrentPattern;
private boolean mLockVirgin;
public void start(LockPatternUtils utils, boolean credentialRequired,
boolean hasChallenge, long challenge,
List<LockPatternView.Cell> chosenPattern, String currentPattern, int userId) {
List<LockPatternView.Cell> chosenPattern, byte[] currentPattern, int userId) {
prepare(utils, credentialRequired, hasChallenge, challenge, userId);
mCurrentPattern = currentPattern;
......
......@@ -332,8 +332,9 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
return;
}
final String pin = mPasswordEntry.getText().toString();
if (TextUtils.isEmpty(pin)) {
// TODO(b/120484642): This is a point of entry for passwords from the UI
final byte[] pin = LockPatternUtils.charSequenceToByteArray(mPasswordEntry.getText());
if (pin == null || pin.length == 0) {
return;
}
......@@ -359,7 +360,7 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
return getActivity() instanceof ConfirmLockPassword.InternalActivity;
}
private void startVerifyPassword(final String pin, final Intent intent) {
private void startVerifyPassword(final byte[] pin, final Intent intent) {
long challenge = getActivity().getIntent().getLongExtra(
ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, 0);
final int localEffectiveUserId = mEffectiveUserId;
......@@ -390,7 +391,7 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
onVerifyCallback);
}
private void startCheckPassword(final String pin, final Intent intent) {
private void startCheckPassword(final byte[] pin, final Intent intent) {
final int localEffectiveUserId = mEffectiveUserId;
mPendingLockCheck = LockPatternChecker.checkPassword(
mLockPatternUtils,
......
......@@ -462,7 +462,7 @@ public class ConfirmLockPattern extends ConfirmDeviceCredentialBaseActivity {
mLockPatternUtils, pattern, challenge, localUserId,
onVerifyCallback)
: LockPatternChecker.verifyTiedProfileChallenge(
mLockPatternUtils, LockPatternUtils.patternToString(pattern),
mLockPatternUtils, LockPatternUtils.patternToByteArray(pattern),
true, challenge, localUserId, onVerifyCallback);
}
......@@ -487,7 +487,7 @@ public class ConfirmLockPattern extends ConfirmDeviceCredentialBaseActivity {
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_TYPE,
StorageManager.CRYPT_TYPE_PATTERN);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD,
LockPatternUtils.patternToString(pattern));
LockPatternUtils.patternToByteArray(pattern));
}
mCredentialCheckResultTracker.setResult(matched, intent, timeoutMs,
localEffectiveUserId);
......
......@@ -61,7 +61,7 @@ public class ManagedLockPasswordProvider {
* @param password Current lock password.
* @return Intent that should update lock password to a managed password.
*/
Intent createIntent(boolean requirePasswordToDecrypt, String password) {
Intent createIntent(boolean requirePasswordToDecrypt, byte[] password) {
return null;
}
}
......@@ -172,7 +172,7 @@ public class CryptKeeperSettings extends InstrumentedPreferenceFragment {
if (helper.utils().getKeyguardStoredPasswordQuality(UserHandle.myUserId())
== DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
showFinalConfirmation(StorageManager.CRYPT_TYPE_DEFAULT, "");
showFinalConfirmation(StorageManager.CRYPT_TYPE_DEFAULT, "".getBytes());
return true;
}
......@@ -192,14 +192,14 @@ public class CryptKeeperSettings extends InstrumentedPreferenceFragment {
// confirmation prompt; otherwise, go back to the initial state.
if (resultCode == Activity.RESULT_OK && data != null) {
int type = data.getIntExtra(ChooseLockSettingsHelper.EXTRA_KEY_TYPE, -1);
String password = data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
if (!TextUtils.isEmpty(password)) {
byte[] password = data.getByteArrayExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
if (!(password == null || password.length == 0)) {
showFinalConfirmation(type, password);
}
}
}
private void showFinalConfirmation(int type, String password) {
private void showFinalConfirmation(int type, byte[] password) {
Preference preference = new Preference(getPreferenceManager().getContext());
preference.setFragment(CryptKeeperConfirm.class.getName());
preference.setTitle(R.string.crypt_keeper_confirm_title);
......@@ -207,16 +207,16 @@ public class CryptKeeperSettings extends InstrumentedPreferenceFragment {
((SettingsActivity) getActivity()).onPreferenceStartFragment(null, preference);
}
private void addEncryptionInfoToPreference(Preference preference, int type, String password) {
private void addEncryptionInfoToPreference(Preference preference, int type, byte[] password) {
Activity activity = getActivity();
DevicePolicyManager dpm = (DevicePolicyManager)
activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
if (dpm.getDoNotAskCredentialsOnBoot()) {
preference.getExtras().putInt(TYPE, StorageManager.CRYPT_TYPE_DEFAULT);
preference.getExtras().putString(PASSWORD, "");
preference.getExtras().putByteArray(PASSWORD, "".getBytes());
} else {
preference.getExtras().putInt(TYPE, type);
preference.getExtras().putString(PASSWORD, password);
preference.getExtras().putByteArray(PASSWORD, password);
}
}
}
......@@ -56,9 +56,8 @@ public class LockUnificationPreferenceController extends AbstractPreferenceContr
private RestrictedSwitchPreference mUnifyProfile;
private String mCurrentDevicePassword;
private String mCurrentProfilePassword;
private byte[] mCurrentDevicePassword;
private byte[] mCurrentProfilePassword;
@Override
public void displayPreference(PreferenceScreen screen) {
......@@ -139,13 +138,13 @@ public class LockUnificationPreferenceController extends AbstractPreferenceContr
} else if (requestCode == UNIFY_LOCK_CONFIRM_DEVICE_REQUEST
&& resultCode == Activity.RESULT_OK) {
mCurrentDevicePassword =
data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
data.getByteArrayExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
launchConfirmProfileLockForUnification();
return true;
} else if (requestCode == UNIFY_LOCK_CONFIRM_PROFILE_REQUEST
&& resultCode == Activity.RESULT_OK) {
mCurrentProfilePassword =
data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
data.getByteArrayExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
unifyLocks();
return true;
}
......@@ -192,7 +191,7 @@ public class LockUnificationPreferenceController extends AbstractPreferenceContr
mLockPatternUtils.getKeyguardStoredPasswordQuality(mProfileChallengeUserId);
if (profileQuality == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) {
mLockPatternUtils.saveLockPattern(
LockPatternUtils.stringToPattern(mCurrentProfilePassword),
LockPatternUtils.byteArrayToPattern(mCurrentProfilePassword),
mCurrentDevicePassword, MY_USER_ID);
} else {
mLockPatternUtils.saveLockPassword(
......
......@@ -65,7 +65,7 @@ public class ChooseLockPasswordTest {
@Test
public void intentBuilder_setPassword_shouldAddExtras() {
Intent intent = new IntentBuilder(application)
.setPassword("password")
.setPassword("password".getBytes())
.setPasswordQuality(DevicePolicyManager.PASSWORD_QUALITY_NUMERIC)
.setPasswordLengthRange(123, 456)