diff --git a/res/layout-xlarge-land/crypt_keeper.xml b/res/layout-xlarge-land/crypt_keeper.xml
index 892cf529fc8..76d2278a604 100644
--- a/res/layout-xlarge-land/crypt_keeper.xml
+++ b/res/layout-xlarge-land/crypt_keeper.xml
@@ -20,8 +20,51 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout-xlarge/crypt_keeper.xml b/res/layout-xlarge/crypt_keeper.xml
index 7cd82c5cdd2..4dce67adf66 100644
--- a/res/layout-xlarge/crypt_keeper.xml
+++ b/res/layout-xlarge/crypt_keeper.xml
@@ -20,8 +20,49 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/crypt_keeper_content.xml b/res/layout/crypt_keeper.xml
similarity index 84%
rename from res/layout/crypt_keeper_content.xml
rename to res/layout/crypt_keeper.xml
index fa337e87414..4dce67adf66 100644
--- a/res/layout/crypt_keeper_content.xml
+++ b/res/layout/crypt_keeper.xml
@@ -17,11 +17,14 @@
*/
-->
-
-
+
@@ -30,10 +33,9 @@
@@ -62,4 +64,5 @@
/>
-
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 1a6dcd644c2..30f7b209a99 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -576,6 +576,10 @@
Passwords
+ Device encryption
+ Encrypt data on device
+ Requires you to set a device unlock pin or password
+
diff --git a/res/xml/security_settings_encryption.xml b/res/xml/security_settings_encryption.xml
new file mode 100644
index 00000000000..fa6d70e67ff
--- /dev/null
+++ b/res/xml/security_settings_encryption.xml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 704eacd146d..ea6232d5bba 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -32,8 +32,11 @@ import android.content.Intent;
import android.database.Cursor;
import android.location.LocationManager;
import android.os.Bundle;
+import android.os.IBinder;
+import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.Vibrator;
+import android.os.storage.IMountService;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
@@ -62,6 +65,8 @@ public class SecuritySettings extends SettingsPreferenceFragment
implements OnPreferenceChangeListener {
private static final String KEY_UNLOCK_SET_OR_CHANGE = "unlock_set_or_change";
+ private static final String KEY_ENCRYPTION = "encryption";
+
// Lock Settings
private static final String PACKAGE = "com.android.settings";
private static final String ICC_LOCK_SETTINGS = PACKAGE + ".IccLockSettings";
@@ -184,6 +189,12 @@ public class SecuritySettings extends SettingsPreferenceFragment
}
PreferenceManager pm = getPreferenceManager();
+
+ // Add options for device encryption
+ // TODO: It still needs to be determined how a device specifies that it supports
+ // encryption. That mechanism needs to be checked before adding the following code
+
+ addPreferencesFromResource(R.xml.security_settings_encryption);
// Add options for lock/unlock screen
int resid = 0;
@@ -407,6 +418,8 @@ public class SecuritySettings extends SettingsPreferenceFragment
} else if (preference == mAssistedGps) {
Settings.Secure.putInt(getContentResolver(), Settings.Secure.ASSISTED_GPS_ENABLED,
mAssistedGps.isChecked() ? 1 : 0);
+ } else if (KEY_ENCRYPTION.equals(key)) {
+ new Encryption().showPasswordDialog();
} else {
// If we didn't handle it, let preferences handle it.
return super.onPreferenceTreeClick(preferenceScreen, preference);
@@ -445,6 +458,89 @@ public class SecuritySettings extends SettingsPreferenceFragment
createPreferenceHierarchy();
}
+ private class Encryption implements DialogInterface.OnClickListener,
+ DialogInterface.OnDismissListener {
+
+ private boolean mSubmit;
+
+ public void showPasswordDialog() {
+ View view = View.inflate(SecuritySettings.this.getActivity(),
+ R.layout.credentials_password_dialog, null);
+
+ Dialog dialog = new AlertDialog.Builder(SecuritySettings.this.getActivity())
+ .setView(view).setTitle(R.string.credentials_set_password)
+ .setPositiveButton(android.R.string.ok, this)
+ .setNegativeButton(android.R.string.cancel, this).create();
+ dialog.setOnDismissListener(this);
+ dialog.show();
+ }
+
+ public void onClick(DialogInterface dialog, int button) {
+ if (button == DialogInterface.BUTTON_POSITIVE) {
+ mSubmit = true;
+ }
+ }
+
+ public void onDismiss(DialogInterface dialog) {
+ if (mSubmit) {
+ mSubmit = false;
+ if (!checkPassword((Dialog) dialog)) {
+ ((Dialog) dialog).show();
+ return;
+ }
+ }
+ }
+
+ // Return true if there is no error.
+ private boolean checkPassword(Dialog dialog) {
+ String newPassword = getText(dialog, R.id.new_password);
+ String confirmPassword = getText(dialog, R.id.confirm_password);
+
+ if (newPassword == null || confirmPassword == null || newPassword.length() == 0
+ || confirmPassword.length() == 0) {
+ showError(dialog, R.string.credentials_passwords_empty);
+ } else if (!newPassword.equals(confirmPassword)) {
+ showError(dialog, R.string.credentials_passwords_mismatch);
+ } else {
+
+ IBinder service = ServiceManager.getService("mount");
+ if (service == null) {
+ return false;
+ }
+
+ IMountService mountService = IMountService.Stub.asInterface(service);
+ try {
+ mountService.encryptStorage(newPassword);
+ } catch (Exception e) {
+ Log.e(TAG, "Error while encrypting...", e);
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ private String getText(Dialog dialog, int viewId) {
+ TextView view = (TextView) dialog.findViewById(viewId);
+ return (view == null || view.getVisibility() == View.GONE) ? null : view.getText()
+ .toString();
+ }
+
+ private void showError(Dialog dialog, int stringId, Object... formatArgs) {
+ TextView view = (TextView) dialog.findViewById(R.id.error);
+ if (view != null) {
+ if (formatArgs == null || formatArgs.length == 0) {
+ view.setText(stringId);
+ } else {
+ view.setText(dialog.getContext().getString(stringId, formatArgs));
+ }
+ view.setVisibility(View.VISIBLE);
+ }
+ }
+
+ }
+
private class CredentialStorage implements DialogInterface.OnClickListener,
DialogInterface.OnDismissListener, Preference.OnPreferenceChangeListener,
Preference.OnPreferenceClickListener {