diff options
author | Daniel Micay <danielmicay@gmail.com> | 2015-06-27 12:39:17 -0400 |
---|---|---|
committer | Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de> | 2016-12-16 20:00:29 +0100 |
commit | 1c224e1186090db1a617eafe4c492992a869b427 (patch) | |
tree | b1e19b0719e185f298223aad0c6de1bd3a4d8174 /src | |
parent | da369854affb579124f6f258e1cb7068b3ee7892 (diff) | |
download | packages_apps_Settings-1c224e1186090db1a617eafe4c492992a869b427.zip packages_apps_Settings-1c224e1186090db1a617eafe4c492992a869b427.tar.gz packages_apps_Settings-1c224e1186090db1a617eafe4c492992a869b427.tar.bz2 |
support replacing a separate encryption password
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/settings/ReplaceEncryptionPassword.java | 99 | ||||
-rw-r--r-- | src/com/android/settings/SecuritySettings.java | 11 |
2 files changed, 110 insertions, 0 deletions
diff --git a/src/com/android/settings/ReplaceEncryptionPassword.java b/src/com/android/settings/ReplaceEncryptionPassword.java new file mode 100644 index 0000000..f3d0532 --- /dev/null +++ b/src/com/android/settings/ReplaceEncryptionPassword.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2015 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. + */ + +package com.android.settings; + +import com.android.internal.widget.LockPatternUtils; +import com.android.internal.widget.LockPatternUtils.RequestThrottledException; + +import android.app.Activity; +import android.app.Fragment; +import android.content.Intent; +import android.content.res.Resources; +import android.os.Bundle; +import android.os.storage.StorageManager; +import android.os.UserHandle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +public class ReplaceEncryptionPassword extends SettingsActivity { + @Override + public Intent getIntent() { + Intent modIntent = new Intent(super.getIntent()); + modIntent.putExtra(EXTRA_SHOW_FRAGMENT, getFragmentClass().getName()); + return modIntent; + } + + @Override + protected boolean isValidFragment(String fragmentName) { + if (ReplaceEncryptionPasswordFragment.class.getName().equals(fragmentName)) return true; + return false; + } + + /* package */ Class<? extends Fragment> getFragmentClass() { + return ReplaceEncryptionPasswordFragment.class; + } + + public static class ReplaceEncryptionPasswordFragment extends Fragment { + private static final int KEYGUARD_REQUEST = 55; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (!(getActivity() instanceof ReplaceEncryptionPassword)) { + throw new SecurityException("Fragment contained in wrong activity"); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { + Resources res = getActivity().getResources(); + ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(getActivity(), this); + + helper.launchConfirmationActivity(KEYGUARD_REQUEST, + res.getText(R.string.unlock_set_unlock_password_title), + true); + + return null; + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + if (requestCode != KEYGUARD_REQUEST) { + return; + } + + // 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) { + LockPatternUtils utils = new LockPatternUtils(getActivity()); + int type = data.getIntExtra(ChooseLockSettingsHelper.EXTRA_KEY_TYPE, -1); + String password = data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD); + if (type == StorageManager.CRYPT_TYPE_PATTERN) { + utils.replaceSeparateEncryptionPasswordWithPattern( + utils.stringToPattern(password)); + } else { + utils.replaceSeparateEncryptionPassword(password); + } + } + + getActivity().finish(); + } + } +} diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java index 7db4a4e..6977672 100644 --- a/src/com/android/settings/SecuritySettings.java +++ b/src/com/android/settings/SecuritySettings.java @@ -98,6 +98,7 @@ public class SecuritySettings extends SettingsPreferenceFragment private static final String KEY_VISIBLE_ERROR_PATTERN = "visible_error_pattern"; private static final String KEY_VISIBLE_DOTS = "visibledots"; private static final String KEY_SECURITY_CATEGORY = "security_category"; + private static final String KEY_ENCRYPTION_CATEGORY = "encryption_category"; private static final String KEY_DEVICE_ADMIN_CATEGORY = "device_admin_category"; private static final String KEY_LOCK_AFTER_TIMEOUT = "lock_after_timeout"; private static final String KEY_OWNER_INFO_SETTINGS = "owner_info_settings"; @@ -127,6 +128,7 @@ public class SecuritySettings extends SettingsPreferenceFragment private static final String KEY_GENERAL_CATEGORY = "general_category"; private static final String KEY_LIVE_LOCK_SCREEN = "live_lock_screen"; private static final String KEY_LOCK_SCREEN_BLUR = CMSettings.Secure.LOCK_SCREEN_BLUR_ENABLED; + private static final String KEY_REPLACE_ENCRYPTION_PASSWORD = "crypt_keeper_replace_password"; // These switch preferences need special handling since they're not all stored in Settings. private static final String SWITCH_PREFERENCE_KEYS[] = { KEY_LOCK_AFTER_TIMEOUT, @@ -300,6 +302,15 @@ public class SecuritySettings extends SettingsPreferenceFragment if (LockPatternUtils.isDeviceEncryptionEnabled()) { // The device is currently encrypted. addPreferencesFromResource(R.xml.security_settings_encrypted); + if (!mLockPatternUtils.isSeparateEncryptionPasswordEnabled()) { + PreferenceGroup encryptionCategory = + (PreferenceGroup) root.findPreference(KEY_ENCRYPTION_CATEGORY); + if (encryptionCategory != null) { + Preference replaceEncryptionPassword = + root.findPreference(KEY_REPLACE_ENCRYPTION_PASSWORD); + encryptionCategory.removePreference(replaceEncryptionPassword); + } + } } else { // This device supports encryption but isn't encrypted. addPreferencesFromResource(R.xml.security_settings_unencrypted); |