SecuritySettings.java revision b0883cb384fc7ad46e011a72355c9fda924e5b28
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 android.app.Activity; 21import android.app.AlertDialog; 22import android.app.Dialog; 23import android.content.ContentQueryMap; 24import android.content.ContentResolver; 25import android.content.Context; 26import android.content.DialogInterface; 27import android.content.Intent; 28import android.content.SharedPreferences; 29import android.content.pm.PackageManager.NameNotFoundException; 30import android.database.Cursor; 31import android.location.LocationManager; 32import android.os.Bundle; 33import android.preference.CheckBoxPreference; 34import android.preference.EditTextPreference; 35import android.preference.Preference; 36import android.preference.PreferenceActivity; 37import android.preference.PreferenceCategory; 38import android.preference.PreferenceGroup; 39import android.preference.PreferenceScreen; 40import android.provider.Settings; 41import android.security.Credentials; 42import android.security.KeyStore; 43import android.text.Html; 44import android.text.TextUtils; 45import android.text.method.LinkMovementMethod; 46import android.util.Log; 47import android.view.View; 48import android.widget.TextView; 49import android.widget.Toast; 50 51import com.android.internal.widget.LockPatternUtils; 52import android.telephony.TelephonyManager; 53 54import java.util.ArrayList; 55import java.util.List; 56import java.util.Observable; 57import java.util.Observer; 58 59/** 60 * Gesture lock pattern settings. 61 */ 62public class SecuritySettings extends PreferenceActivity { 63 64 // Lock Settings 65 66 private static final String KEY_LOCK_ENABLED = "lockenabled"; 67 private static final String KEY_VISIBLE_PATTERN = "visiblepattern"; 68 private static final String KEY_TACTILE_FEEDBACK_ENABLED = "tactilefeedback"; 69 private static final int CONFIRM_PATTERN_THEN_DISABLE_AND_CLEAR_REQUEST_CODE = 55; 70 71 private static final String PREFS_NAME = "location_prefs"; 72 private static final String PREFS_USE_LOCATION = "use_location"; 73 74 private LockPatternUtils mLockPatternUtils; 75 private CheckBoxPreference mLockEnabled; 76 private CheckBoxPreference mVisiblePattern; 77 private CheckBoxPreference mTactileFeedback; 78 private Preference mChoosePattern; 79 80 private CheckBoxPreference mShowPassword; 81 82 // Location Settings 83 private static final String LOCATION_CATEGORY = "location_category"; 84 private static final String LOCATION_NETWORK = "location_network"; 85 private static final String LOCATION_GPS = "location_gps"; 86 private static final String ASSISTED_GPS = "assisted_gps"; 87 88 // Credential storage 89 private static final int CSTOR_MIN_PASSWORD_LENGTH = 8; 90 91 private static final int CSTOR_INIT_DIALOG = 1; 92 private static final int CSTOR_CHANGE_PASSWORD_DIALOG = 2; 93 private static final int CSTOR_UNLOCK_DIALOG = 3; 94 private static final int CSTOR_RESET_DIALOG = 4; 95 96 private CstorHelper mCstorHelper = new CstorHelper(); 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 final class SettingsObserver implements Observer { 107 public void update(Observable o, Object arg) { 108 updateToggles(); 109 } 110 } 111 112 @Override 113 protected void onCreate(Bundle savedInstanceState) { 114 super.onCreate(savedInstanceState); 115 addPreferencesFromResource(R.xml.security_settings); 116 117 mLockPatternUtils = new LockPatternUtils(getContentResolver()); 118 119 createPreferenceHierarchy(); 120 121 mNetwork = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_NETWORK); 122 mGps = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_GPS); 123 mAssistedGps = (CheckBoxPreference) getPreferenceScreen().findPreference(ASSISTED_GPS); 124 125 updateToggles(); 126 127 // listen for Location Manager settings changes 128 Cursor settingsCursor = getContentResolver().query(Settings.Secure.CONTENT_URI, null, 129 "(" + Settings.System.NAME + "=?)", 130 new String[]{Settings.Secure.LOCATION_PROVIDERS_ALLOWED}, 131 null); 132 mContentQueryMap = new ContentQueryMap(settingsCursor, Settings.System.NAME, true, null); 133 mContentQueryMap.addObserver(new SettingsObserver()); 134 135 mCstorHelper.handleIntent(getIntent()); 136 } 137 138 private PreferenceScreen createPreferenceHierarchy() { 139 // Root 140 PreferenceScreen root = this.getPreferenceScreen(); 141 142 // Inline preferences 143 PreferenceCategory inlinePrefCat = new PreferenceCategory(this); 144 inlinePrefCat.setTitle(R.string.lock_settings_title); 145 root.addPreference(inlinePrefCat); 146 147 // change pattern lock 148 Intent intent = new Intent(); 149 intent.setClassName("com.android.settings", 150 "com.android.settings.ChooseLockPatternTutorial"); 151 mChoosePattern = getPreferenceManager().createPreferenceScreen(this); 152 mChoosePattern.setIntent(intent); 153 inlinePrefCat.addPreference(mChoosePattern); 154 155 // autolock toggle 156 mLockEnabled = new LockEnabledPref(this); 157 mLockEnabled.setTitle(R.string.lockpattern_settings_enable_title); 158 mLockEnabled.setSummary(R.string.lockpattern_settings_enable_summary); 159 mLockEnabled.setKey(KEY_LOCK_ENABLED); 160 inlinePrefCat.addPreference(mLockEnabled); 161 162 // visible pattern 163 mVisiblePattern = new CheckBoxPreference(this); 164 mVisiblePattern.setKey(KEY_VISIBLE_PATTERN); 165 mVisiblePattern.setTitle(R.string.lockpattern_settings_enable_visible_pattern_title); 166 inlinePrefCat.addPreference(mVisiblePattern); 167 168 // tactile feedback 169 mTactileFeedback = new CheckBoxPreference(this); 170 mTactileFeedback.setKey(KEY_TACTILE_FEEDBACK_ENABLED); 171 mTactileFeedback.setTitle(R.string.lockpattern_settings_enable_tactile_feedback_title); 172 inlinePrefCat.addPreference(mTactileFeedback); 173 174 int activePhoneType = TelephonyManager.getDefault().getPhoneType(); 175 176 // do not display SIM lock for CDMA phone 177 if (TelephonyManager.PHONE_TYPE_CDMA != activePhoneType) 178 { 179 PreferenceScreen simLockPreferences = getPreferenceManager() 180 .createPreferenceScreen(this); 181 simLockPreferences.setTitle(R.string.sim_lock_settings_category); 182 // Intent to launch SIM lock settings 183 intent = new Intent(); 184 intent.setClassName("com.android.settings", "com.android.settings.IccLockSettings"); 185 simLockPreferences.setIntent(intent); 186 187 PreferenceCategory simLockCat = new PreferenceCategory(this); 188 simLockCat.setTitle(R.string.sim_lock_settings_title); 189 root.addPreference(simLockCat); 190 simLockCat.addPreference(simLockPreferences); 191 } 192 193 // Passwords 194 PreferenceCategory passwordsCat = new PreferenceCategory(this); 195 passwordsCat.setTitle(R.string.security_passwords_title); 196 root.addPreference(passwordsCat); 197 198 CheckBoxPreference showPassword = mShowPassword = new CheckBoxPreference(this); 199 showPassword.setKey("show_password"); 200 showPassword.setTitle(R.string.show_password); 201 showPassword.setSummary(R.string.show_password_summary); 202 showPassword.setPersistent(false); 203 passwordsCat.addPreference(showPassword); 204 205 // Credential storage 206 PreferenceCategory credStoreCat = new PreferenceCategory(this); 207 credStoreCat.setTitle(R.string.cstor_settings_category); 208 root.addPreference(credStoreCat); 209 mCstorHelper.createPreferences(credStoreCat); 210 211 return root; 212 } 213 214 @Override 215 protected void onResume() { 216 super.onResume(); 217 218 boolean patternExists = mLockPatternUtils.savedPatternExists(); 219 mLockEnabled.setEnabled(patternExists); 220 mVisiblePattern.setEnabled(patternExists); 221 mTactileFeedback.setEnabled(patternExists); 222 223 mLockEnabled.setChecked(mLockPatternUtils.isLockPatternEnabled()); 224 mVisiblePattern.setChecked(mLockPatternUtils.isVisiblePatternEnabled()); 225 mTactileFeedback.setChecked(mLockPatternUtils.isTactileFeedbackEnabled()); 226 227 int chooseStringRes = mLockPatternUtils.savedPatternExists() ? 228 R.string.lockpattern_settings_change_lock_pattern : 229 R.string.lockpattern_settings_choose_lock_pattern; 230 mChoosePattern.setTitle(chooseStringRes); 231 232 mShowPassword.setChecked(Settings.System.getInt(getContentResolver(), 233 Settings.System.TEXT_SHOW_PASSWORD, 1) != 0); 234 235 mCstorHelper.resume(); 236 } 237 238 @Override 239 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, 240 Preference preference) { 241 final String key = preference.getKey(); 242 243 if (KEY_LOCK_ENABLED.equals(key)) { 244 mLockPatternUtils.setLockPatternEnabled(isToggled(preference)); 245 } else if (KEY_VISIBLE_PATTERN.equals(key)) { 246 mLockPatternUtils.setVisiblePatternEnabled(isToggled(preference)); 247 } else if (KEY_TACTILE_FEEDBACK_ENABLED.equals(key)) { 248 mLockPatternUtils.setTactileFeedbackEnabled(isToggled(preference)); 249 } else if (preference == mShowPassword) { 250 Settings.System.putInt(getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD, 251 mShowPassword.isChecked() ? 1 : 0); 252 } else if (preference == mNetwork) { 253 Settings.Secure.setLocationProviderEnabled(getContentResolver(), 254 LocationManager.NETWORK_PROVIDER, mNetwork.isChecked()); 255 } else if (preference == mGps) { 256 boolean enabled = mGps.isChecked(); 257 Settings.Secure.setLocationProviderEnabled(getContentResolver(), 258 LocationManager.GPS_PROVIDER, enabled); 259 if (mAssistedGps != null) { 260 mAssistedGps.setEnabled(enabled); 261 } 262 } else if (preference == mAssistedGps) { 263 Settings.Secure.putInt(getContentResolver(), Settings.Secure.ASSISTED_GPS_ENABLED, 264 mAssistedGps.isChecked() ? 1 : 0); 265 } 266 267 return false; 268 } 269 270 private void showPrivacyPolicy() { 271 Intent intent = new Intent("android.settings.TERMS"); 272 startActivity(intent); 273 } 274 275 /* 276 * Creates toggles for each available location provider 277 */ 278 private void updateToggles() { 279 ContentResolver res = getContentResolver(); 280 boolean gpsEnabled = Settings.Secure.isLocationProviderEnabled( 281 res, LocationManager.GPS_PROVIDER); 282 mNetwork.setChecked(Settings.Secure.isLocationProviderEnabled( 283 res, LocationManager.NETWORK_PROVIDER)); 284 mGps.setChecked(gpsEnabled); 285 if (mAssistedGps != null) { 286 mAssistedGps.setChecked(Settings.Secure.getInt(res, 287 Settings.Secure.ASSISTED_GPS_ENABLED, 2) == 1); 288 mAssistedGps.setEnabled(gpsEnabled); 289 } 290 } 291 292 private boolean isToggled(Preference pref) { 293 return ((CheckBoxPreference) pref).isChecked(); 294 } 295 296 /** 297 * For the user to disable keyguard, we first make them verify their 298 * existing pattern. 299 */ 300 private class LockEnabledPref extends CheckBoxPreference { 301 302 public LockEnabledPref(Context context) { 303 super(context); 304 } 305 306 @Override 307 protected void onClick() { 308 if (mLockPatternUtils.savedPatternExists() && isChecked()) { 309 confirmPatternThenDisableAndClear(); 310 } else { 311 super.onClick(); 312 } 313 } 314 } 315 316 /** 317 * Launch screen to confirm the existing lock pattern. 318 * @see #onActivityResult(int, int, android.content.Intent) 319 */ 320 private void confirmPatternThenDisableAndClear() { 321 final Intent intent = new Intent(); 322 intent.setClassName("com.android.settings", "com.android.settings.ConfirmLockPattern"); 323 startActivityForResult(intent, CONFIRM_PATTERN_THEN_DISABLE_AND_CLEAR_REQUEST_CODE); 324 } 325 326 /** 327 * @see #confirmPatternThenDisableAndClear 328 */ 329 @Override 330 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 331 super.onActivityResult(requestCode, resultCode, data); 332 333 final boolean resultOk = resultCode == Activity.RESULT_OK; 334 335 if ((requestCode == CONFIRM_PATTERN_THEN_DISABLE_AND_CLEAR_REQUEST_CODE) 336 && resultOk) { 337 mLockPatternUtils.setLockPatternEnabled(false); 338 mLockPatternUtils.saveLockPattern(null); 339 } 340 } 341 342 @Override 343 protected Dialog onCreateDialog(int id) { 344 switch (id) { 345 case CSTOR_INIT_DIALOG: 346 case CSTOR_CHANGE_PASSWORD_DIALOG: 347 return mCstorHelper.createSetPasswordDialog(id); 348 349 case CSTOR_UNLOCK_DIALOG: 350 return mCstorHelper.createUnlockDialog(); 351 352 case CSTOR_RESET_DIALOG: 353 return mCstorHelper.createResetDialog(); 354 355 default: 356 return null; 357 } 358 } 359 360 private class CstorHelper implements DialogInterface.OnClickListener, 361 DialogInterface.OnDismissListener { 362 private KeyStore mKeyStore = KeyStore.getInstance(); 363 private int mState; 364 365 private View mView; 366 private int mDialogId; 367 private boolean mRetry; 368 private CheckBoxPreference mAccessCheckBox; 369 private Preference mResetButton; 370 371 private Intent mExternalIntent; 372 373 CstorHelper() { 374 mState = mKeyStore.test(); 375 } 376 377 void handleIntent(Intent intent) { 378 if (intent == null) return; 379 String action = intent.getAction(); 380 381 if (Credentials.UNLOCK_ACTION.equals(action)) { 382 mExternalIntent = intent; 383 showCstorDialog(mState == KeyStore.UNINITIALIZED 384 ? CSTOR_INIT_DIALOG : CSTOR_UNLOCK_DIALOG); 385 } 386 } 387 388 void resume() { 389 if (mExternalIntent != null) return; 390 updatePreferences(mKeyStore.test()); 391 } 392 393 private void updatePreferences(int state) { 394 mAccessCheckBox.setEnabled(state != KeyStore.UNINITIALIZED); 395 mAccessCheckBox.setChecked(state == KeyStore.NO_ERROR); 396 mResetButton.setEnabled(state != KeyStore.UNINITIALIZED); 397 398 // Show a toast message if the state is changed. 399 if (mState == state) return; 400 if (state == KeyStore.NO_ERROR) { 401 Toast.makeText(SecuritySettings.this, R.string.cstor_is_enabled, 402 Toast.LENGTH_SHORT).show(); 403 } else if (state == KeyStore.UNINITIALIZED) { 404 Toast.makeText(SecuritySettings.this, R.string.cstor_is_reset, 405 Toast.LENGTH_LONG).show(); 406 } 407 // TODO: disabled? 408 mState = state; 409 } 410 411 private void lockCstor() { 412 mKeyStore.lock(); 413 updatePreferences(KeyStore.LOCKED); 414 } 415 416 private int unlockCstor(String passwd) { 417 mKeyStore.unlock(passwd); 418 return mKeyStore.getLastError(); 419 } 420 421 private int changeCstorPassword(String oldPasswd, String newPasswd) { 422 mKeyStore.password(oldPasswd, newPasswd); 423 return mKeyStore.getLastError(); 424 } 425 426 private void initCstor(String passwd) { 427 mKeyStore.password(passwd); 428 updatePreferences(KeyStore.NO_ERROR); 429 } 430 431 private void resetCstor() { 432 mKeyStore.reset(); 433 updatePreferences(KeyStore.UNINITIALIZED); 434 } 435 436 private void showCstorDialog(int dialogId) { 437 mDialogId = dialogId; 438 mRetry = false; 439 showDialog(dialogId); 440 } 441 442 public void onClick(DialogInterface dialog, int which) { 443 if (which == DialogInterface.BUTTON_NEGATIVE) return; 444 445 switch (mDialogId) { 446 case CSTOR_INIT_DIALOG: 447 case CSTOR_CHANGE_PASSWORD_DIALOG: 448 mRetry = !checkPasswords((Dialog) dialog); 449 break; 450 451 case CSTOR_UNLOCK_DIALOG: 452 mRetry = !checkPassword((Dialog) dialog); 453 break; 454 455 case CSTOR_RESET_DIALOG: 456 resetCstor(); 457 break; 458 } 459 } 460 461 public void onDismiss(DialogInterface dialog) { 462 if (mRetry) { 463 showCstorDialog(mDialogId); 464 } else { 465 removeDialog(mDialogId); 466 updatePreferences(mState); // may revert checkbox 467 468 if (mExternalIntent != null) { 469 finish(); 470 } 471 } 472 } 473 474 // returns false if there is no error. 475 private boolean checkError(int error) { 476 if (error == KeyStore.NO_ERROR) { 477 updatePreferences(KeyStore.NO_ERROR); 478 return false; 479 } 480 if (error == KeyStore.UNINITIALIZED) { 481 updatePreferences(KeyStore.UNINITIALIZED); 482 return false; 483 } 484 if (error < KeyStore.WRONG_PASSWORD) { 485 return false; 486 } 487 int count = error - KeyStore.WRONG_PASSWORD + 1; 488 if (count > 3) { 489 showError(R.string.cstor_password_error); 490 return true; 491 } 492 TextView v = showError(R.string.cstor_password_error_reset_warning); 493 if (count == 1) { 494 v.setText(R.string.cstor_password_error_reset_warning); 495 } else { 496 String format = getString( 497 R.string.cstor_password_error_reset_warning_plural); 498 v.setText(String.format(format, count)); 499 } 500 return true; 501 } 502 503 // returns true if the password is correct 504 private boolean checkPassword(Dialog d) { 505 hideError(); 506 507 String passwd = getText(R.id.cstor_password); 508 if (TextUtils.isEmpty(passwd)) { 509 showError(R.string.cstor_password_empty_error); 510 return false; 511 } 512 513 return !checkError(unlockCstor(passwd)); 514 } 515 516 // returns true if the passwords are correct 517 private boolean checkPasswords(Dialog d) { 518 hideError(); 519 520 String oldPasswd = getText(R.id.cstor_old_password); 521 String newPasswd = getText(R.id.cstor_new_password); 522 String confirmPasswd = getText(R.id.cstor_confirm_password); 523 524 if ((mDialogId == CSTOR_CHANGE_PASSWORD_DIALOG) 525 && TextUtils.isEmpty(oldPasswd)) { 526 showError(R.string.cstor_password_empty_error); 527 } else if (TextUtils.isEmpty(newPasswd) 528 || TextUtils.isEmpty(confirmPasswd)) { 529 showError(R.string.cstor_passwords_empty_error); 530 } else if (newPasswd.length() < CSTOR_MIN_PASSWORD_LENGTH) { 531 showError(R.string.cstor_password_verification_error); 532 } else if (!newPasswd.equals(confirmPasswd)) { 533 showError(R.string.cstor_passwords_error); 534 } else { 535 if (mDialogId == CSTOR_CHANGE_PASSWORD_DIALOG) { 536 return !checkError(changeCstorPassword(oldPasswd, newPasswd)); 537 } else { 538 initCstor(newPasswd); 539 return true; 540 } 541 } 542 return false; 543 } 544 545 private TextView showError(int messageId) { 546 TextView v = (TextView) mView.findViewById(R.id.cstor_error); 547 v.setText(messageId); 548 if (v != null) v.setVisibility(View.VISIBLE); 549 return v; 550 } 551 552 private void hideError() { 553 hide(R.id.cstor_error); 554 } 555 556 private void hide(int viewId) { 557 View v = mView.findViewById(viewId); 558 if (v != null) v.setVisibility(View.GONE); 559 } 560 561 private String getText(int viewId) { 562 return ((TextView) mView.findViewById(viewId)).getText().toString(); 563 } 564 565 private void createPreferences(PreferenceCategory category) { 566 mAccessCheckBox = new CheckBoxPreference(SecuritySettings.this); 567 mAccessCheckBox.setTitle(R.string.cstor_access_title); 568 mAccessCheckBox.setSummary(R.string.cstor_access_summary); 569 mAccessCheckBox.setOnPreferenceChangeListener( 570 new Preference.OnPreferenceChangeListener() { 571 public boolean onPreferenceChange( 572 Preference pref, Object value) { 573 if (((Boolean) value)) { 574 showCstorDialog(CSTOR_UNLOCK_DIALOG); 575 } else { 576 lockCstor(); 577 } 578 return true; 579 } 580 }); 581 category.addPreference(mAccessCheckBox); 582 583 Preference install = new Preference(SecuritySettings.this); 584 install.setTitle(R.string.cstor_cert_install_title); 585 install.setSummary(R.string.cstor_cert_install_summary); 586 install.setOnPreferenceClickListener( 587 new Preference.OnPreferenceClickListener() { 588 public boolean onPreferenceClick(Preference pref) { 589 Credentials.getInstance().installFromSdCard( 590 SecuritySettings.this); 591 return true; 592 } 593 }); 594 category.addPreference(install); 595 596 Preference password = new Preference(SecuritySettings.this); 597 password.setTitle(R.string.cstor_set_passwd_title); 598 password.setSummary(R.string.cstor_set_passwd_summary); 599 password.setOnPreferenceClickListener( 600 new Preference.OnPreferenceClickListener() { 601 public boolean onPreferenceClick(Preference pref) { 602 showCstorDialog(mState == KeyStore.UNINITIALIZED 603 ? CSTOR_INIT_DIALOG 604 : CSTOR_CHANGE_PASSWORD_DIALOG); 605 return true; 606 } 607 }); 608 category.addPreference(password); 609 610 mResetButton = new Preference(SecuritySettings.this); 611 mResetButton.setTitle(R.string.cstor_reset_title); 612 mResetButton.setSummary(R.string.cstor_reset_summary); 613 mResetButton.setOnPreferenceClickListener( 614 new Preference.OnPreferenceClickListener() { 615 public boolean onPreferenceClick(Preference pref) { 616 showCstorDialog(CSTOR_RESET_DIALOG); 617 return true; 618 } 619 }); 620 category.addPreference(mResetButton); 621 622 updatePreferences(mState); 623 } 624 625 private Dialog createUnlockDialog() { 626 mView = View.inflate(SecuritySettings.this, 627 R.layout.cstor_unlock_dialog_view, null); 628 hideError(); 629 630 // show extra hint only when the action comes from outside 631 if (mExternalIntent == null) { 632 hide(R.id.cstor_access_dialog_hint_from_action); 633 } 634 635 Dialog d = new AlertDialog.Builder(SecuritySettings.this) 636 .setView(mView) 637 .setTitle(R.string.cstor_access_dialog_title) 638 .setPositiveButton(android.R.string.ok, this) 639 .setNegativeButton(android.R.string.cancel, this) 640 .create(); 641 d.setOnDismissListener(this); 642 return d; 643 } 644 645 private Dialog createSetPasswordDialog(int id) { 646 mView = View.inflate(SecuritySettings.this, 647 R.layout.cstor_set_password_dialog_view, null); 648 hideError(); 649 650 switch (id) { 651 case CSTOR_INIT_DIALOG: 652 mView.findViewById(R.id.cstor_old_password_block) 653 .setVisibility(View.GONE); 654 break; 655 656 case CSTOR_CHANGE_PASSWORD_DIALOG: 657 mView.findViewById(R.id.cstor_first_time_hint) 658 .setVisibility(View.GONE); 659 break; 660 661 default: 662 throw new RuntimeException( 663 "Unknown dialog id: " + mDialogId); 664 } 665 666 Dialog d = new AlertDialog.Builder(SecuritySettings.this) 667 .setView(mView) 668 .setTitle(R.string.cstor_set_passwd_dialog_title) 669 .setPositiveButton(android.R.string.ok, this) 670 .setNegativeButton(android.R.string.cancel, this) 671 .create(); 672 d.setOnDismissListener(this); 673 return d; 674 } 675 676 private Dialog createResetDialog() { 677 return new AlertDialog.Builder(SecuritySettings.this) 678 .setTitle(android.R.string.dialog_alert_title) 679 .setIcon(android.R.drawable.ic_dialog_alert) 680 .setMessage(R.string.cstor_reset_hint) 681 .setPositiveButton(getString(android.R.string.ok), this) 682 .setNegativeButton(getString(android.R.string.cancel), this) 683 .create(); 684 } 685 } 686} 687