From 146fc11958ae93d4c97ce83839188ece762f3275 Mon Sep 17 00:00:00 2001 From: Andrei Kapishnikov Date: Thu, 9 Apr 2015 11:08:16 -0400 Subject: [PATCH] Added support for DO_NOT_ASK_CREDENTIALS_ON_BOOT DPM flag When DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set in DevicePolicyManager, the Settings UI: 1) Should not encrypt the device with password when the user encrypts the device for the first time. The default encryption type should be used instead. 2) Should not give the choice to the user whether to encrypt the device with password/PIN or not but always encrypt the device without password. Related CL: https://googleplex-android-review.git.corp.google.com/#/c/665371/ Change-Id: Ic09f02c033a0b16b7ffc45bf6d675b62d1be4bd8 --- .../android/settings/ChooseLockGeneric.java | 4 +++- .../android/settings/CryptKeeperSettings.java | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/ChooseLockGeneric.java b/src/com/android/settings/ChooseLockGeneric.java index 4b2de72a939..7aa10534e85 100644 --- a/src/com/android/settings/ChooseLockGeneric.java +++ b/src/com/android/settings/ChooseLockGeneric.java @@ -189,7 +189,9 @@ public class ChooseLockGeneric extends SettingsActivity { // TODO: why does this take disabled, its always called with a quality higher than // what makes sense with disabled == true private void maybeEnableEncryption(int quality, boolean disabled) { - if (Process.myUserHandle().isOwner() && LockPatternUtils.isDeviceEncryptionEnabled()) { + DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE); + if (Process.myUserHandle().isOwner() && LockPatternUtils.isDeviceEncryptionEnabled() + && !dpm.getDoNotAskCredentialsOnBoot()) { mEncryptionRequestQuality = quality; mEncryptionRequestDisabled = disabled; final Context context = getActivity(); diff --git a/src/com/android/settings/CryptKeeperSettings.java b/src/com/android/settings/CryptKeeperSettings.java index c5a06eb6489..46d7dd18648 100644 --- a/src/com/android/settings/CryptKeeperSettings.java +++ b/src/com/android/settings/CryptKeeperSettings.java @@ -39,6 +39,8 @@ import com.android.internal.logging.MetricsLogger; public class CryptKeeperSettings extends InstrumentedFragment { private static final String TAG = "CryptKeeper"; + private static final String TYPE = "type"; + private static final String PASSWORD = "password"; private static final int KEYGUARD_REQUEST = 55; @@ -194,8 +196,20 @@ public class CryptKeeperSettings extends InstrumentedFragment { 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); + addEncryptionInfoToPreference(preference, type, password); ((SettingsActivity) getActivity()).onPreferenceStartFragment(null, preference); } + + private void addEncryptionInfoToPreference(Preference preference, int type, String 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, ""); + } else { + preference.getExtras().putInt(TYPE, type); + preference.getExtras().putString(PASSWORD, password); + } + } }