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:
Paul Lawrence
2014-04-03 09:18:45 -07:00
parent 5de92cca6f
commit d71c31ef94
5 changed files with 25 additions and 24 deletions

View File

@@ -25,6 +25,7 @@ import android.content.Intent;
public final class ChooseLockSettingsHelper { public final class ChooseLockSettingsHelper {
static final String EXTRA_KEY_TYPE = "type";
static final String EXTRA_KEY_PASSWORD = "password"; static final String EXTRA_KEY_PASSWORD = "password";
private LockPatternUtils mLockPatternUtils; private LockPatternUtils mLockPatternUtils;

View File

@@ -28,6 +28,7 @@ import android.os.Bundle;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.os.Handler; import android.os.Handler;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.storage.StorageManager;
import android.text.Editable; import android.text.Editable;
import android.text.InputType; import android.text.InputType;
import android.text.TextWatcher; import android.text.TextWatcher;
@@ -168,6 +169,9 @@ public class ConfirmLockPassword extends SettingsActivity {
if (mLockPatternUtils.checkPassword(pin)) { if (mLockPatternUtils.checkPassword(pin)) {
Intent intent = new Intent(); 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); intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD, pin);
getActivity().setResult(RESULT_OK, intent); getActivity().setResult(RESULT_OK, intent);

View File

@@ -27,6 +27,7 @@ import android.content.Intent;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.Bundle; import android.os.Bundle;
import android.os.storage.StorageManager;
import android.widget.TextView; import android.widget.TextView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@@ -266,6 +267,8 @@ public class ConfirmLockPattern extends SettingsActivity {
if (mLockPatternUtils.checkPattern(pattern)) { if (mLockPatternUtils.checkPattern(pattern)) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_TYPE,
StorageManager.CRYPT_TYPE_PATTERN);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD, intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD,
LockPatternUtils.patternToString(pattern)); LockPatternUtils.patternToString(pattern));

View File

@@ -72,7 +72,7 @@ public class CryptKeeperConfirm extends Fragment {
IMountService mountService = IMountService.Stub.asInterface(service); IMountService mountService = IMountService.Stub.asInterface(service);
try { try {
Bundle args = getIntent().getExtras(); Bundle args = getIntent().getExtras();
mountService.encryptStorage(args.getString("password")); mountService.encryptStorage(args.getInt("type", -1), args.getString("password"));
} catch (Exception e) { } catch (Exception e) {
Log.e("CryptKeeper", "Error while encrypting...", e); Log.e("CryptKeeper", "Error while encrypting...", e);
} }

View File

@@ -29,6 +29,7 @@ import android.content.IntentFilter;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.BatteryManager; import android.os.BatteryManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.storage.StorageManager;
import android.preference.Preference; import android.preference.Preference;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@@ -41,10 +42,6 @@ public class CryptKeeperSettings extends Fragment {
private static final int KEYGUARD_REQUEST = 55; 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 // Minimum battery charge level (in percent) to launch encryption. If the battery charge is
// lower than this, encryption should not be activated. // lower than this, encryption should not be activated.
private static final int MIN_BATTERY_LEVEL = 80; private static final int MIN_BATTERY_LEVEL = 80;
@@ -157,22 +154,16 @@ public class CryptKeeperSettings extends Fragment {
* @return true if confirmation launched * @return true if confirmation launched
*/ */
private boolean runKeyguardConfirmation(int request) { 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(); Resources res = getActivity().getResources();
return new ChooseLockSettingsHelper(getActivity(), this) ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(getActivity(), this);
.launchConfirmationActivity(request,
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_prompt),
res.getText(R.string.master_clear_gesture_explanation)); 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 // If the user entered a valid keyguard trace, present the final
// confirmation prompt; otherwise, go back to the initial state. // confirmation prompt; otherwise, go back to the initial state.
if (resultCode == Activity.RESULT_OK && data != null) { if (resultCode == Activity.RESULT_OK && data != null) {
int type = data.getIntExtra(ChooseLockSettingsHelper.EXTRA_KEY_TYPE, -1);
String password = data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD); String password = data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
if (!TextUtils.isEmpty(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 preference = new Preference(getActivity());
preference.setFragment(CryptKeeperConfirm.class.getName()); preference.setFragment(CryptKeeperConfirm.class.getName());
preference.setTitle(R.string.crypt_keeper_confirm_title); preference.setTitle(R.string.crypt_keeper_confirm_title);
preference.getExtras().putInt("type", type);
preference.getExtras().putString("password", password); preference.getExtras().putString("password", password);
((SettingsActivity) getActivity()).onPreferenceStartFragment(null, preference); ((SettingsActivity) getActivity()).onPreferenceStartFragment(null, preference);
} }