SecuritySettings.java revision feff65213231ba6a0f6185f98e660042b5b14595
1/* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.settings; 18 19 20import java.util.Observable; 21import java.util.Observer; 22 23import android.app.Activity; 24import android.app.AlertDialog; 25import android.app.Dialog; 26import android.content.ContentQueryMap; 27import android.content.ContentResolver; 28import android.content.DialogInterface; 29import android.content.Intent; 30import android.database.Cursor; 31import android.location.LocationManager; 32import android.os.Bundle; 33import android.os.ICheckinService; 34import android.os.ServiceManager; 35import android.os.SystemProperties; 36import android.preference.CheckBoxPreference; 37import android.preference.ListPreference; 38import android.preference.Preference; 39import android.preference.PreferenceActivity; 40import android.preference.PreferenceCategory; 41import android.preference.PreferenceManager; 42import android.preference.PreferenceScreen; 43import android.preference.Preference.OnPreferenceChangeListener; 44import android.provider.Settings; 45import android.security.Credentials; 46import android.security.KeyStore; 47import android.telephony.TelephonyManager; 48import android.util.Log; 49import android.view.View; 50import android.widget.TextView; 51import android.widget.Toast; 52 53import com.android.internal.widget.LockPatternUtils; 54 55/** 56 * Gesture lock pattern settings. 57 */ 58public class SecuritySettings extends PreferenceActivity { 59 60 // Lock Settings 61 private static final String PACKAGE = "com.android.settings"; 62 private static final String LOCK_PATTERN_TUTORIAL = PACKAGE + ".ChooseLockPatternTutorial"; 63 private static final String ICC_LOCK_SETTINGS = PACKAGE + ".IccLockSettings"; 64 private static final String CHOOSE_LOCK_PATTERN = PACKAGE + ".ChooseLockPattern"; 65 private static final String CHOOSE_LOCK_PIN = PACKAGE + ".ChooseLockPassword"; 66 67 private static final String KEY_LOCK_ENABLED = "lockenabled"; 68 private static final String KEY_VISIBLE_PATTERN = "visiblepattern"; 69 private static final String KEY_TACTILE_FEEDBACK_ENABLED = "tactilefeedback"; 70 private static final String KEY_UNLOCK_METHOD = "unlock_method"; 71 private static final int UPDATE_PASSWORD_REQUEST = 56; 72 private static final int CONFIRM_EXISTING_REQUEST = 57; 73 74 // Encrypted File Systems constants 75 private static final String PROPERTY_EFS_ENABLED = "persist.security.efs.enabled"; 76 private static final String PROPERTY_EFS_TRANSITION = "persist.security.efs.trans"; 77 78 private static final String PREFS_NAME = "location_prefs"; 79 private static final String PREFS_USE_LOCATION = "use_location"; 80 81 private CheckBoxPreference mVisiblePattern; 82 private CheckBoxPreference mTactileFeedback; 83 84 private CheckBoxPreference mShowPassword; 85 86 // Location Settings 87 private static final String LOCATION_CATEGORY = "location_category"; 88 private static final String LOCATION_NETWORK = "location_network"; 89 private static final String LOCATION_GPS = "location_gps"; 90 private static final String ASSISTED_GPS = "assisted_gps"; 91 92 // Credential storage 93 private CredentialStorage mCredentialStorage = new CredentialStorage(); 94 95 // Encrypted file system 96 private CheckBoxPreference mEncryptedFSEnabled; 97 98 private CheckBoxPreference mNetwork; 99 private CheckBoxPreference mGps; 100 private CheckBoxPreference mAssistedGps; 101 102 // These provide support for receiving notification when Location Manager settings change. 103 // This is necessary because the Network Location Provider can change settings 104 // if the user does not confirm enabling the provider. 105 private ContentQueryMap mContentQueryMap; 106 private ListPreference mUnlockMethod; 107 private ChooseLockSettingsHelper mChooseLockSettingsHelper; 108 private final class SettingsObserver implements Observer { 109 public void update(Observable o, Object arg) { 110 updateToggles(); 111 } 112 } 113 114 @Override 115 protected void onCreate(Bundle savedInstanceState) { 116 super.onCreate(savedInstanceState); 117 addPreferencesFromResource(R.xml.security_settings); 118 119 mChooseLockSettingsHelper = new ChooseLockSettingsHelper(this); 120 121 createPreferenceHierarchy(); 122 123 mNetwork = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_NETWORK); 124 mGps = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_GPS); 125 mAssistedGps = (CheckBoxPreference) getPreferenceScreen().findPreference(ASSISTED_GPS); 126 127 updateToggles(); 128 129 // listen for Location Manager settings changes 130 Cursor settingsCursor = getContentResolver().query(Settings.Secure.CONTENT_URI, null, 131 "(" + Settings.System.NAME + "=?)", 132 new String[]{Settings.Secure.LOCATION_PROVIDERS_ALLOWED}, 133 null); 134 mContentQueryMap = new ContentQueryMap(settingsCursor, Settings.System.NAME, true, null); 135 mContentQueryMap.addObserver(new SettingsObserver()); 136 } 137 138 private PreferenceScreen createPreferenceHierarchy() { 139 // Root 140 PreferenceScreen root = this.getPreferenceScreen(); 141 142 PreferenceManager pm = getPreferenceManager(); 143 144 mUnlockMethod = (ListPreference) pm.findPreference(KEY_UNLOCK_METHOD); 145 mUnlockMethod.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { 146 public boolean onPreferenceChange(Preference preference, Object newValue) { 147 String value = (String) newValue; 148 handleUpdateUnlockMethod(value); 149 return false; 150 } 151 }); 152 153 // visible pattern 154 mVisiblePattern = (CheckBoxPreference) pm.findPreference(KEY_VISIBLE_PATTERN); 155 156 // tactile feedback 157 mTactileFeedback = (CheckBoxPreference) pm.findPreference(KEY_TACTILE_FEEDBACK_ENABLED); 158 159 int activePhoneType = TelephonyManager.getDefault().getPhoneType(); 160 161 // do not display SIM lock for CDMA phone 162 if (TelephonyManager.PHONE_TYPE_CDMA != activePhoneType) 163 { 164 PreferenceScreen simLockPreferences = getPreferenceManager() 165 .createPreferenceScreen(this); 166 simLockPreferences.setTitle(R.string.sim_lock_settings_category); 167 // Intent to launch SIM lock settings 168 simLockPreferences.setIntent(new Intent().setClassName(PACKAGE, ICC_LOCK_SETTINGS)); 169 PreferenceCategory simLockCat = new PreferenceCategory(this); 170 simLockCat.setTitle(R.string.sim_lock_settings_title); 171 root.addPreference(simLockCat); 172 simLockCat.addPreference(simLockPreferences); 173 } 174 175 // Passwords 176 PreferenceCategory passwordsCat = new PreferenceCategory(this); 177 passwordsCat.setTitle(R.string.security_passwords_title); 178 root.addPreference(passwordsCat); 179 180 CheckBoxPreference showPassword = mShowPassword = new CheckBoxPreference(this); 181 showPassword.setKey("show_password"); 182 showPassword.setTitle(R.string.show_password); 183 showPassword.setSummary(R.string.show_password_summary); 184 showPassword.setPersistent(false); 185 passwordsCat.addPreference(showPassword); 186 187 // Device policies 188 PreferenceCategory devicePoliciesCat = new PreferenceCategory(this); 189 devicePoliciesCat.setTitle(R.string.device_admin_title); 190 root.addPreference(devicePoliciesCat); 191 192 Preference deviceAdminButton = new Preference(this); 193 deviceAdminButton.setTitle(R.string.manage_device_admin); 194 deviceAdminButton.setSummary(R.string.manage_device_admin_summary); 195 Intent deviceAdminIntent = new Intent(); 196 deviceAdminIntent.setClass(this, DeviceAdminSettings.class); 197 deviceAdminButton.setIntent(deviceAdminIntent); 198 devicePoliciesCat.addPreference(deviceAdminButton); 199 200 // Credential storage 201 PreferenceCategory credentialsCat = new PreferenceCategory(this); 202 credentialsCat.setTitle(R.string.credentials_category); 203 root.addPreference(credentialsCat); 204 mCredentialStorage.createPreferences(credentialsCat, CredentialStorage.TYPE_KEYSTORE); 205 206 // File System Encryption 207 PreferenceCategory encryptedfsCat = new PreferenceCategory(this); 208 encryptedfsCat.setTitle(R.string.encrypted_fs_category); 209 root.addPreference(encryptedfsCat); 210 mCredentialStorage.createPreferences(encryptedfsCat, CredentialStorage.TYPE_ENCRYPTEDFS); 211 212 return root; 213 } 214 215 protected void handleUpdateUnlockMethod(final String value) { 216 final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils(); 217 if ("none".equals(value)) { 218 mChooseLockSettingsHelper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST); 219 } else if ("password".equals(value) || "pin".equals(value)) { 220 final int minLength = 4; // TODO: get from policy store. 221 final int maxLength = 16; 222 final int mode = "password".equals(value) 223 ? LockPatternUtils.MODE_PASSWORD : LockPatternUtils.MODE_PIN; 224 Intent intent = new Intent().setClassName(PACKAGE, CHOOSE_LOCK_PIN); 225 intent.putExtra(LockPatternUtils.PASSWORD_TYPE_KEY, mode); 226 intent.putExtra(ChooseLockPassword.PASSWORD_MIN_KEY, minLength); 227 intent.putExtra(ChooseLockPassword.PASSWORD_MAX_KEY, maxLength); 228 startActivityForResult(intent, UPDATE_PASSWORD_REQUEST); 229 } else if ("pattern".equals(value)) { 230 boolean showTutorial = !lockPatternUtils.isPatternEverChosen(); 231 Intent intent = new Intent(); 232 intent.setClassName(PACKAGE, showTutorial ? 233 LOCK_PATTERN_TUTORIAL : CHOOSE_LOCK_PATTERN); 234 intent.putExtra("key_lock_method", value); 235 startActivityForResult(intent, UPDATE_PASSWORD_REQUEST); 236 } 237 } 238 239 @Override 240 protected void onResume() { 241 super.onResume(); 242 243 final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils(); 244 boolean patternExists = lockPatternUtils.savedPatternExists(); 245 mVisiblePattern.setEnabled(patternExists); 246 mTactileFeedback.setEnabled(patternExists); 247 248 mVisiblePattern.setChecked(lockPatternUtils.isVisiblePatternEnabled()); 249 mTactileFeedback.setChecked(lockPatternUtils.isTactileFeedbackEnabled()); 250 251 mShowPassword.setChecked(Settings.System.getInt(getContentResolver(), 252 Settings.System.TEXT_SHOW_PASSWORD, 1) != 0); 253 254 mCredentialStorage.resume(); 255 } 256 257 @Override 258 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, 259 Preference preference) { 260 final String key = preference.getKey(); 261 262 final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils(); 263 if (KEY_LOCK_ENABLED.equals(key)) { 264 lockPatternUtils.setLockPatternEnabled(isToggled(preference)); 265 } else if (KEY_VISIBLE_PATTERN.equals(key)) { 266 lockPatternUtils.setVisiblePatternEnabled(isToggled(preference)); 267 } else if (KEY_TACTILE_FEEDBACK_ENABLED.equals(key)) { 268 lockPatternUtils.setTactileFeedbackEnabled(isToggled(preference)); 269 } else if (preference == mShowPassword) { 270 Settings.System.putInt(getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD, 271 mShowPassword.isChecked() ? 1 : 0); 272 } else if (preference == mNetwork) { 273 Settings.Secure.setLocationProviderEnabled(getContentResolver(), 274 LocationManager.NETWORK_PROVIDER, mNetwork.isChecked()); 275 } else if (preference == mGps) { 276 boolean enabled = mGps.isChecked(); 277 Settings.Secure.setLocationProviderEnabled(getContentResolver(), 278 LocationManager.GPS_PROVIDER, enabled); 279 if (mAssistedGps != null) { 280 mAssistedGps.setEnabled(enabled); 281 } 282 } else if (preference == mAssistedGps) { 283 Settings.Secure.putInt(getContentResolver(), Settings.Secure.ASSISTED_GPS_ENABLED, 284 mAssistedGps.isChecked() ? 1 : 0); 285 } 286 287 return false; 288 } 289 290 /* 291 * Creates toggles for each available location provider 292 */ 293 private void updateToggles() { 294 ContentResolver res = getContentResolver(); 295 boolean gpsEnabled = Settings.Secure.isLocationProviderEnabled( 296 res, LocationManager.GPS_PROVIDER); 297 mNetwork.setChecked(Settings.Secure.isLocationProviderEnabled( 298 res, LocationManager.NETWORK_PROVIDER)); 299 mGps.setChecked(gpsEnabled); 300 if (mAssistedGps != null) { 301 mAssistedGps.setChecked(Settings.Secure.getInt(res, 302 Settings.Secure.ASSISTED_GPS_ENABLED, 2) == 1); 303 mAssistedGps.setEnabled(gpsEnabled); 304 } 305 } 306 307 private boolean isToggled(Preference pref) { 308 return ((CheckBoxPreference) pref).isChecked(); 309 } 310 311 /** 312 * @see #confirmPatternThenDisableAndClear 313 */ 314 @Override 315 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 316 super.onActivityResult(requestCode, resultCode, data); 317 318 final boolean resultOk = resultCode == Activity.RESULT_OK; 319 320 LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils(); 321 if ((requestCode == CONFIRM_EXISTING_REQUEST) && resultOk) { 322 lockPatternUtils.saveLockPassword(null); 323 lockPatternUtils.setLockPatternEnabled(false); 324 lockPatternUtils.saveLockPattern(null); 325 } 326 } 327 328 private class CredentialStorage implements DialogInterface.OnClickListener, 329 DialogInterface.OnDismissListener, Preference.OnPreferenceChangeListener, 330 Preference.OnPreferenceClickListener { 331 private static final int MINIMUM_PASSWORD_LENGTH = 8; 332 333 private static final int TYPE_KEYSTORE = 0; 334 private static final int TYPE_ENCRYPTEDFS = 1; 335 336 // Dialog identifiers 337 private static final int DLG_BASE = 0; 338 private static final int DLG_UNLOCK = DLG_BASE + 1; 339 private static final int DLG_PASSWORD = DLG_UNLOCK + 1; 340 private static final int DLG_RESET = DLG_PASSWORD + 1; 341 private static final int DLG_ENABLE_EFS = DLG_RESET + 1; 342 343 private KeyStore mKeyStore = KeyStore.getInstance(); 344 private int mState; 345 private boolean mSubmit = false; 346 private boolean mExternal = false; 347 348 private boolean mWillEnableEncryptedFS; 349 private int mShowingDialog = 0; 350 351 // Key Store controls 352 private CheckBoxPreference mAccessCheckBox; 353 private Preference mInstallButton; 354 private Preference mPasswordButton; 355 private Preference mResetButton; 356 357 358 // Encrypted file system controls 359 private CheckBoxPreference mEncryptedFSEnabled; 360 361 void resume() { 362 mState = mKeyStore.test(); 363 updatePreferences(mState); 364 365 Intent intent = getIntent(); 366 if (!mExternal && intent != null && 367 Credentials.UNLOCK_ACTION.equals(intent.getAction())) { 368 mExternal = true; 369 if (mState == KeyStore.UNINITIALIZED) { 370 showPasswordDialog(); 371 } else if (mState == KeyStore.LOCKED) { 372 showUnlockDialog(); 373 } else { 374 finish(); 375 } 376 } 377 } 378 379 private void initialize(String password) { 380 mKeyStore.password(password); 381 updatePreferences(KeyStore.NO_ERROR); 382 } 383 384 private void reset() { 385 mKeyStore.reset(); 386 updatePreferences(KeyStore.UNINITIALIZED); 387 } 388 389 private void lock() { 390 mKeyStore.lock(); 391 updatePreferences(KeyStore.LOCKED); 392 } 393 394 private int unlock(String password) { 395 mKeyStore.unlock(password); 396 return mKeyStore.getLastError(); 397 } 398 399 private int changePassword(String oldPassword, String newPassword) { 400 mKeyStore.password(oldPassword, newPassword); 401 return mKeyStore.getLastError(); 402 } 403 404 public boolean onPreferenceChange(Preference preference, Object value) { 405 if (preference == mAccessCheckBox) { 406 if ((Boolean) value) { 407 showUnlockDialog(); 408 } else { 409 lock(); 410 } 411 return true; 412 } else if (preference == mEncryptedFSEnabled) { 413 Boolean bval = (Boolean)value; 414 mWillEnableEncryptedFS = bval.booleanValue(); 415 showSwitchEncryptedFSDialog(); 416 } 417 return true; 418 } 419 420 public boolean onPreferenceClick(Preference preference) { 421 if (preference == mInstallButton) { 422 Credentials.getInstance().installFromSdCard(SecuritySettings.this); 423 } else if (preference == mPasswordButton) { 424 showPasswordDialog(); 425 } else if (preference == mResetButton) { 426 showResetDialog(); 427 } else { 428 return false; 429 } 430 return true; 431 } 432 433 public void onClick(DialogInterface dialog, int button) { 434 if (mShowingDialog != DLG_ENABLE_EFS) { 435 mSubmit = (button == DialogInterface.BUTTON_POSITIVE); 436 if (button == DialogInterface.BUTTON_NEUTRAL) { 437 reset(); 438 } 439 } else { 440 if (button == DialogInterface.BUTTON_POSITIVE) { 441 // Perform action 442 // Reboot and toggle Encrypted File Systems 443 ICheckinService service = 444 ICheckinService.Stub.asInterface(ServiceManager.getService("checkin")); 445 if (service != null) { 446 try { 447 // This RPC should never return 448 if (mWillEnableEncryptedFS) { 449 service.masterClearAndToggleEFS(true); 450 } else { 451 service.masterClearAndToggleEFS(false); 452 } 453 } catch (android.os.RemoteException e) { 454 // Intentionally blank - there's nothing we can do here 455 Log.w("SecuritySettings", 456 "Unable to invoke ICheckinService.masterClearAndToggleEFS()"); 457 } 458 } else { 459 Log.w("SecuritySettings", "Unable to locate ICheckinService"); 460 } 461 updatePreferences(mState); 462 } else if (button == DialogInterface.BUTTON_NEGATIVE) { 463 // Cancel action 464 Toast.makeText(SecuritySettings.this, R.string.encrypted_fs_cancel_confirm, 465 Toast.LENGTH_SHORT).show(); 466 updatePreferences(mState); 467 } else { 468 // Unknown - should not happen 469 return; 470 } 471 } 472 } 473 474 public void onDismiss(DialogInterface dialog) { 475 if (mSubmit && !isFinishing()) { 476 mSubmit = false; 477 if (!checkPassword((Dialog) dialog)) { 478 ((Dialog) dialog).show(); 479 return; 480 } 481 } 482 updatePreferences(mState); 483 if (mExternal) { 484 finish(); 485 } 486 } 487 488 // Return true if there is no error. 489 private boolean checkPassword(Dialog dialog) { 490 String oldPassword = getText(dialog, R.id.old_password); 491 String newPassword = getText(dialog, R.id.new_password); 492 String confirmPassword = getText(dialog, R.id.confirm_password); 493 494 if (oldPassword != null && oldPassword.length() == 0) { 495 showError(dialog, R.string.credentials_password_empty); 496 return false; 497 } else if (newPassword == null) { 498 return !checkError(dialog, unlock(oldPassword)); 499 } else if (newPassword.length() == 0 || confirmPassword.length() == 0) { 500 showError(dialog, R.string.credentials_passwords_empty); 501 } else if (newPassword.length() < MINIMUM_PASSWORD_LENGTH) { 502 showError(dialog, R.string.credentials_password_too_short); 503 } else if (!newPassword.equals(confirmPassword)) { 504 showError(dialog, R.string.credentials_passwords_mismatch); 505 } else if (oldPassword == null) { 506 initialize(newPassword); 507 return true; 508 } else { 509 return !checkError(dialog, changePassword(oldPassword, newPassword)); 510 } 511 return false; 512 } 513 514 // Return false if there is no error. 515 private boolean checkError(Dialog dialog, int error) { 516 if (error == KeyStore.NO_ERROR) { 517 updatePreferences(KeyStore.NO_ERROR); 518 return false; 519 } 520 if (error == KeyStore.UNINITIALIZED) { 521 updatePreferences(KeyStore.UNINITIALIZED); 522 return false; 523 } 524 if (error < KeyStore.WRONG_PASSWORD) { 525 return false; 526 } 527 int count = error - KeyStore.WRONG_PASSWORD + 1; 528 if (count > 3) { 529 showError(dialog, R.string.credentials_wrong_password); 530 } else if (count == 1) { 531 showError(dialog, R.string.credentials_reset_warning); 532 } else { 533 showError(dialog, R.string.credentials_reset_warning_plural, count); 534 } 535 return true; 536 } 537 538 private String getText(Dialog dialog, int viewId) { 539 TextView view = (TextView) dialog.findViewById(viewId); 540 return (view == null || view.getVisibility() == View.GONE) ? null : 541 view.getText().toString(); 542 } 543 544 private void showError(Dialog dialog, int stringId, Object... formatArgs) { 545 TextView view = (TextView) dialog.findViewById(R.id.error); 546 if (view != null) { 547 if (formatArgs == null || formatArgs.length == 0) { 548 view.setText(stringId); 549 } else { 550 view.setText(dialog.getContext().getString(stringId, formatArgs)); 551 } 552 view.setVisibility(View.VISIBLE); 553 } 554 } 555 556 private void createPreferences(PreferenceCategory category, int type) { 557 switch(type) { 558 case TYPE_KEYSTORE: 559 mAccessCheckBox = new CheckBoxPreference(SecuritySettings.this); 560 mAccessCheckBox.setTitle(R.string.credentials_access); 561 mAccessCheckBox.setSummary(R.string.credentials_access_summary); 562 mAccessCheckBox.setOnPreferenceChangeListener(this); 563 category.addPreference(mAccessCheckBox); 564 565 mInstallButton = new Preference(SecuritySettings.this); 566 mInstallButton.setTitle(R.string.credentials_install_certificates); 567 mInstallButton.setSummary(R.string.credentials_install_certificates_summary); 568 mInstallButton.setOnPreferenceClickListener(this); 569 category.addPreference(mInstallButton); 570 571 mPasswordButton = new Preference(SecuritySettings.this); 572 mPasswordButton.setTitle(R.string.credentials_set_password); 573 mPasswordButton.setSummary(R.string.credentials_set_password_summary); 574 mPasswordButton.setOnPreferenceClickListener(this); 575 category.addPreference(mPasswordButton); 576 577 mResetButton = new Preference(SecuritySettings.this); 578 mResetButton.setTitle(R.string.credentials_reset); 579 mResetButton.setSummary(R.string.credentials_reset_summary); 580 mResetButton.setOnPreferenceClickListener(this); 581 category.addPreference(mResetButton); 582 break; 583 584 case TYPE_ENCRYPTEDFS: 585 mEncryptedFSEnabled = new CheckBoxPreference(SecuritySettings.this); 586 mEncryptedFSEnabled.setTitle(R.string.encrypted_fs_enable); 587 mEncryptedFSEnabled.setSummary(R.string.encrypted_fs_enable_summary); 588 mEncryptedFSEnabled.setOnPreferenceChangeListener(this); 589 category.addPreference(mEncryptedFSEnabled); 590 break; 591 } 592 } 593 594 private void updatePreferences(int state) { 595 mAccessCheckBox.setChecked(state == KeyStore.NO_ERROR); 596 boolean encFSEnabled = SystemProperties.getBoolean(PROPERTY_EFS_ENABLED, 597 false); 598 mResetButton.setEnabled((!encFSEnabled) && (state != KeyStore.UNINITIALIZED)); 599 mAccessCheckBox.setEnabled((state != KeyStore.UNINITIALIZED) && (!encFSEnabled)); 600 601 // Encrypted File system preferences 602 mEncryptedFSEnabled.setChecked(encFSEnabled); 603 604 // Show a toast message if the state is changed. 605 if (mState == state) { 606 return; 607 } else if (state == KeyStore.NO_ERROR) { 608 Toast.makeText(SecuritySettings.this, R.string.credentials_enabled, 609 Toast.LENGTH_SHORT).show(); 610 } else if (state == KeyStore.UNINITIALIZED) { 611 Toast.makeText(SecuritySettings.this, R.string.credentials_erased, 612 Toast.LENGTH_SHORT).show(); 613 } else if (state == KeyStore.LOCKED) { 614 Toast.makeText(SecuritySettings.this, R.string.credentials_disabled, 615 Toast.LENGTH_SHORT).show(); 616 } 617 mState = state; 618 } 619 620 private void showUnlockDialog() { 621 View view = View.inflate(SecuritySettings.this, 622 R.layout.credentials_unlock_dialog, null); 623 624 // Show extra hint only when the action comes from outside. 625 if (mExternal) { 626 view.findViewById(R.id.hint).setVisibility(View.VISIBLE); 627 } 628 629 Dialog dialog = new AlertDialog.Builder(SecuritySettings.this) 630 .setView(view) 631 .setTitle(R.string.credentials_unlock) 632 .setPositiveButton(android.R.string.ok, this) 633 .setNegativeButton(android.R.string.cancel, this) 634 .create(); 635 dialog.setOnDismissListener(this); 636 mShowingDialog = DLG_UNLOCK; 637 dialog.show(); 638 } 639 640 private void showPasswordDialog() { 641 View view = View.inflate(SecuritySettings.this, 642 R.layout.credentials_password_dialog, null); 643 644 if (mState == KeyStore.UNINITIALIZED) { 645 view.findViewById(R.id.hint).setVisibility(View.VISIBLE); 646 } else { 647 view.findViewById(R.id.old_password_prompt).setVisibility(View.VISIBLE); 648 view.findViewById(R.id.old_password).setVisibility(View.VISIBLE); 649 } 650 651 Dialog dialog = new AlertDialog.Builder(SecuritySettings.this) 652 .setView(view) 653 .setTitle(R.string.credentials_set_password) 654 .setPositiveButton(android.R.string.ok, this) 655 .setNegativeButton(android.R.string.cancel, this) 656 .create(); 657 dialog.setOnDismissListener(this); 658 mShowingDialog = DLG_PASSWORD; 659 dialog.show(); 660 } 661 662 private void showResetDialog() { 663 mShowingDialog = DLG_RESET; 664 new AlertDialog.Builder(SecuritySettings.this) 665 .setTitle(android.R.string.dialog_alert_title) 666 .setIcon(android.R.drawable.ic_dialog_alert) 667 .setMessage(R.string.credentials_reset_hint) 668 .setNeutralButton(getString(android.R.string.ok), this) 669 .setNegativeButton(getString(android.R.string.cancel), this) 670 .create().show(); 671 } 672 673 private void showSwitchEncryptedFSDialog() { 674 AlertDialog.Builder builder = new AlertDialog.Builder(SecuritySettings.this) 675 .setCancelable(false) 676 .setTitle(R.string.encrypted_fs_alert_dialog_title); 677 678 mShowingDialog = DLG_ENABLE_EFS; 679 if (mWillEnableEncryptedFS) { 680 builder.setMessage(R.string.encrypted_fs_enable_dialog) 681 .setPositiveButton(R.string.encrypted_fs_enable_button, this) 682 .setNegativeButton(R.string.encrypted_fs_cancel_button, this) 683 .create().show(); 684 } else { 685 builder.setMessage(R.string.encrypted_fs_disable_dialog) 686 .setPositiveButton(R.string.encrypted_fs_disable_button, this) 687 .setNegativeButton(R.string.encrypted_fs_cancel_button, this) 688 .create().show(); 689 } 690 } 691 } 692} 693