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

@@ -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,24 +154,18 @@ 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,
res.getText(R.string.master_clear_gesture_prompt),
res.getText(R.string.master_clear_gesture_explanation));
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));
}
@Override
@@ -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);
}