diff options
author | Jason parks <jparks@google.com> | 2011-01-07 09:02:14 -0600 |
---|---|---|
committer | Jason parks <jparks@google.com> | 2011-01-07 13:43:01 -0600 |
commit | 1533eb826b4af5db8853c7e3be7bfd6bdfd6fbde (patch) | |
tree | d411cafd682183b6a2acbdaa3c0e02564baea139 | |
parent | 586fa0264cacb216f04f003770562c77fb7dd646 (diff) | |
download | packages_apps_Settings-1533eb826b4af5db8853c7e3be7bfd6bdfd6fbde.tar.gz packages_apps_Settings-1533eb826b4af5db8853c7e3be7bfd6bdfd6fbde.tar.bz2 packages_apps_Settings-1533eb826b4af5db8853c7e3be7bfd6bdfd6fbde.zip |
Add a setting to enable encryption.
This isn't final and it will wipe your device.
Change-Id: I3449f04514a430f11f353543fdb78e17df16fba3
-rw-r--r-- | res/values/strings.xml | 4 | ||||
-rw-r--r-- | res/xml/security_settings_encryption.xml | 31 | ||||
-rw-r--r-- | src/com/android/settings/SecuritySettings.java | 96 |
3 files changed, 131 insertions, 0 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index 408ff2e24..3ae446171 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -576,6 +576,10 @@ <!-- In the security screen, the header title for settings related to Passwords--> <string name="security_passwords_title">Passwords</string> + <string name="encryption_settings_title">Device encryption</string> + <string name="encrypt_title">Encrypt data on device</string> + <string name="encrypt_summary">Requires you to set a device unlock pin or password</string> + <!-- Unlock Picker Settings --><skip /> <!-- Security Picker --><skip /> diff --git a/res/xml/security_settings_encryption.xml b/res/xml/security_settings_encryption.xml new file mode 100644 index 000000000..fa6d70e67 --- /dev/null +++ b/res/xml/security_settings_encryption.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2010 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> + + <PreferenceCategory + android:key="security_category" + android:title="@string/encryption_settings_title"> + + <PreferenceScreen + android:key="encryption" + android:title="@string/encrypt_title" + android:summary="@string/encrypt_summary" + android:persistent="false"/> + + </PreferenceCategory> + +</PreferenceScreen> diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java index eea98b4ce..45e884d11 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; @@ -385,6 +396,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); @@ -423,6 +436,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 { |