Allow encryption when keyguard is set to pattern or no protection
Don't block based on keyguard type, and pass type to encryption function. Circular dependency on https://googleplex-android-review.git.corp.google.com/#/c/444200/ Bug: 13749169 Change-Id: Ica95713adca9552ae56341ff33badd1d4b748af8
This commit is contained in:
@@ -25,6 +25,7 @@ import android.content.Intent;
|
||||
|
||||
public final class ChooseLockSettingsHelper {
|
||||
|
||||
static final String EXTRA_KEY_TYPE = "type";
|
||||
static final String EXTRA_KEY_PASSWORD = "password";
|
||||
|
||||
private LockPatternUtils mLockPatternUtils;
|
||||
|
@@ -28,6 +28,7 @@ import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.os.Handler;
|
||||
import android.os.SystemClock;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.text.Editable;
|
||||
import android.text.InputType;
|
||||
import android.text.TextWatcher;
|
||||
@@ -168,6 +169,9 @@ public class ConfirmLockPassword extends SettingsActivity {
|
||||
if (mLockPatternUtils.checkPassword(pin)) {
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_TYPE,
|
||||
mIsAlpha ? StorageManager.CRYPT_TYPE_PASSWORD
|
||||
: StorageManager.CRYPT_TYPE_PIN);
|
||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD, pin);
|
||||
|
||||
getActivity().setResult(RESULT_OK, intent);
|
||||
|
@@ -27,6 +27,7 @@ import android.content.Intent;
|
||||
import android.os.CountDownTimer;
|
||||
import android.os.SystemClock;
|
||||
import android.os.Bundle;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.widget.TextView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -266,6 +267,8 @@ public class ConfirmLockPattern extends SettingsActivity {
|
||||
if (mLockPatternUtils.checkPattern(pattern)) {
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_TYPE,
|
||||
StorageManager.CRYPT_TYPE_PATTERN);
|
||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD,
|
||||
LockPatternUtils.patternToString(pattern));
|
||||
|
||||
|
@@ -72,7 +72,7 @@ public class CryptKeeperConfirm extends Fragment {
|
||||
IMountService mountService = IMountService.Stub.asInterface(service);
|
||||
try {
|
||||
Bundle args = getIntent().getExtras();
|
||||
mountService.encryptStorage(args.getString("password"));
|
||||
mountService.encryptStorage(args.getInt("type", -1), args.getString("password"));
|
||||
} catch (Exception e) {
|
||||
Log.e("CryptKeeper", "Error while encrypting...", e);
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@ import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.preference.Preference;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -41,10 +42,6 @@ public class CryptKeeperSettings extends Fragment {
|
||||
|
||||
private static final int KEYGUARD_REQUEST = 55;
|
||||
|
||||
// This is the minimum acceptable password quality. If the current password quality is
|
||||
// lower than this, encryption should not be activated.
|
||||
static final int MIN_PASSWORD_QUALITY = DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
|
||||
|
||||
// Minimum battery charge level (in percent) to launch encryption. If the battery charge is
|
||||
// lower than this, encryption should not be activated.
|
||||
private static final int MIN_BATTERY_LEVEL = 80;
|
||||
@@ -157,22 +154,16 @@ public class CryptKeeperSettings extends Fragment {
|
||||
* @return true if confirmation launched
|
||||
*/
|
||||
private boolean runKeyguardConfirmation(int request) {
|
||||
// 1. Confirm that we have a sufficient PIN/Password to continue
|
||||
LockPatternUtils lockPatternUtils = new LockPatternUtils(getActivity());
|
||||
int quality = lockPatternUtils.getActivePasswordQuality();
|
||||
if (quality == DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK
|
||||
&& lockPatternUtils.isLockPasswordEnabled()) {
|
||||
// Use the alternate as the quality. We expect this to be
|
||||
// PASSWORD_QUALITY_SOMETHING(pattern) or PASSWORD_QUALITY_NUMERIC(PIN).
|
||||
quality = lockPatternUtils.getKeyguardStoredPasswordQuality();
|
||||
}
|
||||
if (quality < MIN_PASSWORD_QUALITY) {
|
||||
return false;
|
||||
}
|
||||
// 2. Ask the user to confirm the current PIN/Password
|
||||
Resources res = getActivity().getResources();
|
||||
return new ChooseLockSettingsHelper(getActivity(), this)
|
||||
.launchConfirmationActivity(request,
|
||||
ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(getActivity(), this);
|
||||
|
||||
if (helper.utils().getKeyguardStoredPasswordQuality()
|
||||
== DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
|
||||
showFinalConfirmation(StorageManager.CRYPT_TYPE_DEFAULT, "");
|
||||
return true;
|
||||
}
|
||||
|
||||
return helper.launchConfirmationActivity(request,
|
||||
res.getText(R.string.master_clear_gesture_prompt),
|
||||
res.getText(R.string.master_clear_gesture_explanation));
|
||||
}
|
||||
@@ -188,17 +179,19 @@ public class CryptKeeperSettings extends Fragment {
|
||||
// If the user entered a valid keyguard trace, present the final
|
||||
// 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)) {
|
||||
showFinalConfirmation(password);
|
||||
showFinalConfirmation(type, password);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showFinalConfirmation(String password) {
|
||||
private void showFinalConfirmation(int type, String password) {
|
||||
Preference preference = new Preference(getActivity());
|
||||
preference.setFragment(CryptKeeperConfirm.class.getName());
|
||||
preference.setTitle(R.string.crypt_keeper_confirm_title);
|
||||
preference.getExtras().putInt("type", type);
|
||||
preference.getExtras().putString("password", password);
|
||||
((SettingsActivity) getActivity()).onPreferenceStartFragment(null, preference);
|
||||
}
|
||||
|
Reference in New Issue
Block a user