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 17 package com.android.providers.settings; 18 19 import android.content.Context; 20 import android.content.res.Resources; 21 import android.database.Cursor; 22 import android.database.sqlite.SQLiteDatabase; 23 import android.database.sqlite.SQLiteOpenHelper; 24 import android.database.sqlite.SQLiteStatement; 25 import android.media.AudioManager; 26 import android.media.AudioSystem; 27 import android.net.ConnectivityManager; 28 import android.os.Build; 29 import android.os.Environment; 30 import android.os.SystemProperties; 31 import android.os.UserHandle; 32 import android.provider.Settings; 33 import android.provider.Settings.Global; 34 import android.provider.Settings.Secure; 35 import android.sysprop.TelephonyProperties; 36 import android.telephony.TelephonyManager; 37 import android.text.TextUtils; 38 import android.util.Log; 39 40 import com.android.internal.content.InstallLocationUtils; 41 import com.android.internal.telephony.Phone; 42 import com.android.internal.telephony.RILConstants; 43 import com.android.internal.widget.LockPatternUtils; 44 import com.android.internal.widget.LockPatternView; 45 import com.android.internal.widget.LockscreenCredential; 46 47 import java.io.File; 48 import java.util.HashSet; 49 import java.util.List; 50 import java.util.Set; 51 52 /** 53 * Legacy settings database helper class for {@link SettingsProvider}. 54 * 55 * IMPORTANT: Do not add any more upgrade steps here as the global, 56 * secure, and system settings are no longer stored in a database 57 * but are kept in memory and persisted to XML. 58 * 59 * See: SettingsProvider.UpgradeController#onUpgradeLocked 60 * 61 * @deprecated The implementation is frozen. Do not add any new code to this class! 62 */ 63 @Deprecated 64 class DatabaseHelper extends SQLiteOpenHelper { 65 private static final String TAG = "SettingsProvider"; 66 private static final String DATABASE_NAME = "settings.db"; 67 68 // Please, please please. If you update the database version, check to make sure the 69 // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion' 70 // is properly propagated through your change. Not doing so will result in a loss of user 71 // settings. 72 private static final int DATABASE_VERSION = 118; 73 74 private Context mContext; 75 private int mUserHandle; 76 77 private static final HashSet<String> mValidTables = new HashSet<>(); 78 79 private static final String DATABASE_BACKUP_SUFFIX = "-backup"; 80 81 private static final String TABLE_SYSTEM = "system"; 82 private static final String TABLE_SECURE = "secure"; 83 private static final String TABLE_GLOBAL = "global"; 84 85 static { 86 mValidTables.add(TABLE_SYSTEM); 87 mValidTables.add(TABLE_SECURE); 88 mValidTables.add(TABLE_GLOBAL); 89 90 // These are old. 91 mValidTables.add("bluetooth_devices"); 92 mValidTables.add("favorites"); 93 mValidTables.add("old_favorites"); 94 mValidTables.add("android_metadata"); 95 } 96 dbNameForUser(final int userHandle)97 static String dbNameForUser(final int userHandle) { 98 // The owner gets the unadorned db name; 99 if (userHandle == UserHandle.USER_SYSTEM) { 100 return DATABASE_NAME; 101 } else { 102 // Place the database in the user-specific data tree so that it's 103 // cleaned up automatically when the user is deleted. 104 File databaseFile = new File( 105 Environment.getUserSystemDirectory(userHandle), DATABASE_NAME); 106 // If databaseFile doesn't exist, database can be kept in memory. It's safe because the 107 // database will be migrated and disposed of immediately after onCreate finishes 108 if (!databaseFile.exists()) { 109 Log.i(TAG, "No previous database file exists - running in in-memory mode"); 110 return null; 111 } 112 return databaseFile.getPath(); 113 } 114 } 115 DatabaseHelper(Context context, int userHandle)116 public DatabaseHelper(Context context, int userHandle) { 117 super(context, dbNameForUser(userHandle), null, DATABASE_VERSION); 118 mContext = context; 119 mUserHandle = userHandle; 120 } 121 isValidTable(String name)122 public static boolean isValidTable(String name) { 123 return mValidTables.contains(name); 124 } 125 isInMemory()126 private boolean isInMemory() { 127 return getDatabaseName() == null; 128 } 129 dropDatabase()130 public void dropDatabase() { 131 close(); 132 // No need to remove files if db is in memory 133 if (isInMemory()) { 134 return; 135 } 136 File databaseFile = mContext.getDatabasePath(getDatabaseName()); 137 if (databaseFile.exists()) { 138 SQLiteDatabase.deleteDatabase(databaseFile); 139 } 140 } 141 backupDatabase()142 public void backupDatabase() { 143 close(); 144 // No need to backup files if db is in memory 145 if (isInMemory()) { 146 return; 147 } 148 File databaseFile = mContext.getDatabasePath(getDatabaseName()); 149 if (!databaseFile.exists()) { 150 return; 151 } 152 File backupFile = mContext.getDatabasePath(getDatabaseName() 153 + DATABASE_BACKUP_SUFFIX); 154 if (backupFile.exists()) { 155 return; 156 } 157 databaseFile.renameTo(backupFile); 158 } 159 createSecureTable(SQLiteDatabase db)160 private void createSecureTable(SQLiteDatabase db) { 161 db.execSQL("CREATE TABLE secure (" + 162 "_id INTEGER PRIMARY KEY AUTOINCREMENT," + 163 "name TEXT UNIQUE ON CONFLICT REPLACE," + 164 "value TEXT" + 165 ");"); 166 db.execSQL("CREATE INDEX secureIndex1 ON secure (name);"); 167 } 168 createGlobalTable(SQLiteDatabase db)169 private void createGlobalTable(SQLiteDatabase db) { 170 db.execSQL("CREATE TABLE global (" + 171 "_id INTEGER PRIMARY KEY AUTOINCREMENT," + 172 "name TEXT UNIQUE ON CONFLICT REPLACE," + 173 "value TEXT" + 174 ");"); 175 db.execSQL("CREATE INDEX globalIndex1 ON global (name);"); 176 } 177 178 @Override onCreate(SQLiteDatabase db)179 public void onCreate(SQLiteDatabase db) { 180 db.execSQL("CREATE TABLE system (" + 181 "_id INTEGER PRIMARY KEY AUTOINCREMENT," + 182 "name TEXT UNIQUE ON CONFLICT REPLACE," + 183 "value TEXT" + 184 ");"); 185 db.execSQL("CREATE INDEX systemIndex1 ON system (name);"); 186 187 createSecureTable(db); 188 189 // Only create the global table for the singleton 'owner/system' user 190 if (mUserHandle == UserHandle.USER_SYSTEM) { 191 createGlobalTable(db); 192 } 193 194 db.execSQL("CREATE TABLE bluetooth_devices (" + 195 "_id INTEGER PRIMARY KEY," + 196 "name TEXT," + 197 "addr TEXT," + 198 "channel INTEGER," + 199 "type INTEGER" + 200 ");"); 201 202 // Load initial volume levels into DB 203 loadVolumeLevels(db); 204 205 // Load inital settings values 206 loadSettings(db); 207 } 208 209 @Override onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion)210 public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) { 211 Log.w(TAG, "Upgrading settings database from version " + oldVersion + " to " 212 + currentVersion); 213 214 int upgradeVersion = oldVersion; 215 216 // Pattern for upgrade blocks: 217 // 218 // if (upgradeVersion == [the DATABASE_VERSION you set] - 1) { 219 // .. your upgrade logic.. 220 // upgradeVersion = [the DATABASE_VERSION you set] 221 // } 222 223 if (upgradeVersion == 20) { 224 /* 225 * Version 21 is part of the volume control refresh. There is no 226 * longer a UI-visible for setting notification vibrate on/off (in 227 * our design), but the functionality still exists. Force the 228 * notification vibrate to on. 229 */ 230 loadVibrateSetting(db, true); 231 232 upgradeVersion = 21; 233 } 234 235 if (upgradeVersion < 22) { 236 upgradeVersion = 22; 237 // Upgrade the lock gesture storage location and format 238 upgradeLockPatternLocation(db); 239 } 240 241 if (upgradeVersion < 23) { 242 db.execSQL("UPDATE favorites SET iconResource=0 WHERE iconType=0"); 243 upgradeVersion = 23; 244 } 245 246 if (upgradeVersion == 23) { 247 db.beginTransaction(); 248 try { 249 db.execSQL("ALTER TABLE favorites ADD spanX INTEGER"); 250 db.execSQL("ALTER TABLE favorites ADD spanY INTEGER"); 251 // Shortcuts, applications, folders 252 db.execSQL("UPDATE favorites SET spanX=1, spanY=1 WHERE itemType<=0"); 253 // Photo frames, clocks 254 db.execSQL( 255 "UPDATE favorites SET spanX=2, spanY=2 WHERE itemType=1000 or itemType=1002"); 256 // Search boxes 257 db.execSQL("UPDATE favorites SET spanX=4, spanY=1 WHERE itemType=1001"); 258 db.setTransactionSuccessful(); 259 } finally { 260 db.endTransaction(); 261 } 262 upgradeVersion = 24; 263 } 264 265 if (upgradeVersion == 24) { 266 db.beginTransaction(); 267 try { 268 // The value of the constants for preferring wifi or preferring mobile have been 269 // swapped, so reload the default. 270 db.execSQL("DELETE FROM system WHERE name='network_preference'"); 271 db.execSQL("INSERT INTO system ('name', 'value') values ('network_preference', '" + 272 ConnectivityManager.DEFAULT_NETWORK_PREFERENCE + "')"); 273 db.setTransactionSuccessful(); 274 } finally { 275 db.endTransaction(); 276 } 277 upgradeVersion = 25; 278 } 279 280 if (upgradeVersion == 25) { 281 db.beginTransaction(); 282 try { 283 db.execSQL("ALTER TABLE favorites ADD uri TEXT"); 284 db.execSQL("ALTER TABLE favorites ADD displayMode INTEGER"); 285 db.setTransactionSuccessful(); 286 } finally { 287 db.endTransaction(); 288 } 289 upgradeVersion = 26; 290 } 291 292 if (upgradeVersion == 26) { 293 // This introduces the new secure settings table. 294 db.beginTransaction(); 295 try { 296 createSecureTable(db); 297 db.setTransactionSuccessful(); 298 } finally { 299 db.endTransaction(); 300 } 301 upgradeVersion = 27; 302 } 303 304 if (upgradeVersion == 27) { 305 String[] settingsToMove = { 306 Settings.Secure.ADB_ENABLED, 307 Settings.Secure.ANDROID_ID, 308 Settings.Secure.BLUETOOTH_ON, 309 Settings.Secure.DATA_ROAMING, 310 Settings.Secure.DEVICE_PROVISIONED, 311 Settings.Secure.HTTP_PROXY, 312 Settings.Secure.INSTALL_NON_MARKET_APPS, 313 Settings.Secure.LOCATION_PROVIDERS_ALLOWED, 314 Settings.Secure.LOGGING_ID, 315 Settings.Secure.NETWORK_PREFERENCE, 316 Settings.Secure.PARENTAL_CONTROL_ENABLED, 317 Settings.Secure.PARENTAL_CONTROL_LAST_UPDATE, 318 Settings.Secure.PARENTAL_CONTROL_REDIRECT_URL, 319 Settings.Secure.SETTINGS_CLASSNAME, 320 Settings.Secure.USB_MASS_STORAGE_ENABLED, 321 Settings.Secure.USE_GOOGLE_MAIL, 322 Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 323 Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY, 324 Settings.Secure.WIFI_NUM_OPEN_NETWORKS_KEPT, 325 Settings.Secure.WIFI_ON, 326 Settings.Secure.WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE, 327 Settings.Secure.WIFI_WATCHDOG_AP_COUNT, 328 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS, 329 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED, 330 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS, 331 Settings.Secure.WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT, 332 Settings.Secure.WIFI_WATCHDOG_MAX_AP_CHECKS, 333 Settings.Secure.WIFI_WATCHDOG_ON, 334 Settings.Secure.WIFI_WATCHDOG_PING_COUNT, 335 Settings.Secure.WIFI_WATCHDOG_PING_DELAY_MS, 336 Settings.Secure.WIFI_WATCHDOG_PING_TIMEOUT_MS, 337 }; 338 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false); 339 upgradeVersion = 28; 340 } 341 342 if (upgradeVersion == 28 || upgradeVersion == 29) { 343 // Note: The upgrade to 28 was flawed since it didn't delete the old 344 // setting first before inserting. Combining 28 and 29 with the 345 // fixed version. 346 347 // This upgrade adds the STREAM_NOTIFICATION type to the list of 348 // types affected by ringer modes (silent, vibrate, etc.) 349 db.beginTransaction(); 350 try { 351 db.execSQL("DELETE FROM system WHERE name='" 352 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'"); 353 int newValue = (1 << AudioManager.STREAM_RING) 354 | (1 << AudioManager.STREAM_NOTIFICATION) 355 | (1 << AudioManager.STREAM_SYSTEM); 356 db.execSQL("INSERT INTO system ('name', 'value') values ('" 357 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '" 358 + String.valueOf(newValue) + "')"); 359 db.setTransactionSuccessful(); 360 } finally { 361 db.endTransaction(); 362 } 363 364 upgradeVersion = 30; 365 } 366 367 if (upgradeVersion == 30) { 368 upgradeVersion = 31; 369 } 370 371 if (upgradeVersion == 31) { 372 /* 373 * Animations are now managed in preferences, and may be 374 * enabled or disabled based on product resources. 375 */ 376 db.beginTransaction(); 377 SQLiteStatement stmt = null; 378 try { 379 db.execSQL("DELETE FROM system WHERE name='" 380 + Settings.System.WINDOW_ANIMATION_SCALE + "'"); 381 db.execSQL("DELETE FROM system WHERE name='" 382 + Settings.System.TRANSITION_ANIMATION_SCALE + "'"); 383 stmt = db.compileStatement("INSERT INTO system(name,value)" 384 + " VALUES(?,?);"); 385 loadDefaultAnimationSettings(stmt); 386 db.setTransactionSuccessful(); 387 } finally { 388 db.endTransaction(); 389 if (stmt != null) stmt.close(); 390 } 391 upgradeVersion = 32; 392 } 393 394 if (upgradeVersion == 32) { 395 upgradeVersion = 33; 396 } 397 398 if (upgradeVersion == 33) { 399 // Set the default zoom controls to: tap-twice to bring up +/- 400 db.beginTransaction(); 401 try { 402 db.execSQL("INSERT INTO system(name,value) values('zoom','2');"); 403 db.setTransactionSuccessful(); 404 } finally { 405 db.endTransaction(); 406 } 407 upgradeVersion = 34; 408 } 409 410 if (upgradeVersion == 34) { 411 db.beginTransaction(); 412 SQLiteStatement stmt = null; 413 try { 414 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)" 415 + " VALUES(?,?);"); 416 loadSecure35Settings(stmt); 417 db.setTransactionSuccessful(); 418 } finally { 419 db.endTransaction(); 420 if (stmt != null) stmt.close(); 421 } 422 upgradeVersion = 35; 423 } 424 // due to a botched merge from donut to eclair, the initialization of ASSISTED_GPS_ENABLED 425 // was accidentally done out of order here. 426 // to fix this, ASSISTED_GPS_ENABLED is now initialized while upgrading from 38 to 39, 427 // and we intentionally do nothing from 35 to 36 now. 428 if (upgradeVersion == 35) { 429 upgradeVersion = 36; 430 } 431 432 if (upgradeVersion == 36) { 433 // This upgrade adds the STREAM_SYSTEM_ENFORCED type to the list of 434 // types affected by ringer modes (silent, vibrate, etc.) 435 db.beginTransaction(); 436 try { 437 db.execSQL("DELETE FROM system WHERE name='" 438 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'"); 439 int newValue = (1 << AudioManager.STREAM_RING) 440 | (1 << AudioManager.STREAM_NOTIFICATION) 441 | (1 << AudioManager.STREAM_SYSTEM) 442 | (1 << AudioManager.STREAM_SYSTEM_ENFORCED); 443 db.execSQL("INSERT INTO system ('name', 'value') values ('" 444 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '" 445 + String.valueOf(newValue) + "')"); 446 db.setTransactionSuccessful(); 447 } finally { 448 db.endTransaction(); 449 } 450 upgradeVersion = 37; 451 } 452 453 if (upgradeVersion == 37) { 454 db.beginTransaction(); 455 SQLiteStatement stmt = null; 456 try { 457 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)" 458 + " VALUES(?,?);"); 459 loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS, 460 R.string.airplane_mode_toggleable_radios); 461 db.setTransactionSuccessful(); 462 } finally { 463 db.endTransaction(); 464 if (stmt != null) stmt.close(); 465 } 466 upgradeVersion = 38; 467 } 468 469 if (upgradeVersion == 38) { 470 db.beginTransaction(); 471 try { 472 String value = 473 mContext.getResources().getBoolean(R.bool.assisted_gps_enabled) ? "1" : "0"; 474 db.execSQL("INSERT OR IGNORE INTO secure(name,value) values('" + 475 Settings.Global.ASSISTED_GPS_ENABLED + "','" + value + "');"); 476 db.setTransactionSuccessful(); 477 } finally { 478 db.endTransaction(); 479 } 480 481 upgradeVersion = 39; 482 } 483 484 if (upgradeVersion == 39) { 485 upgradeAutoBrightness(db); 486 upgradeVersion = 40; 487 } 488 489 if (upgradeVersion == 40) { 490 /* 491 * All animations are now turned on by default! 492 */ 493 db.beginTransaction(); 494 SQLiteStatement stmt = null; 495 try { 496 db.execSQL("DELETE FROM system WHERE name='" 497 + Settings.System.WINDOW_ANIMATION_SCALE + "'"); 498 db.execSQL("DELETE FROM system WHERE name='" 499 + Settings.System.TRANSITION_ANIMATION_SCALE + "'"); 500 stmt = db.compileStatement("INSERT INTO system(name,value)" 501 + " VALUES(?,?);"); 502 loadDefaultAnimationSettings(stmt); 503 db.setTransactionSuccessful(); 504 } finally { 505 db.endTransaction(); 506 if (stmt != null) stmt.close(); 507 } 508 upgradeVersion = 41; 509 } 510 511 if (upgradeVersion == 41) { 512 /* 513 * Initialize newly public haptic feedback setting 514 */ 515 db.beginTransaction(); 516 SQLiteStatement stmt = null; 517 try { 518 db.execSQL("DELETE FROM system WHERE name='" 519 + Settings.System.HAPTIC_FEEDBACK_ENABLED + "'"); 520 stmt = db.compileStatement("INSERT INTO system(name,value)" 521 + " VALUES(?,?);"); 522 loadDefaultHapticSettings(stmt); 523 db.setTransactionSuccessful(); 524 } finally { 525 db.endTransaction(); 526 if (stmt != null) stmt.close(); 527 } 528 upgradeVersion = 42; 529 } 530 531 if (upgradeVersion == 42) { 532 /* 533 * Initialize new notification pulse setting 534 */ 535 db.beginTransaction(); 536 SQLiteStatement stmt = null; 537 try { 538 stmt = db.compileStatement("INSERT INTO system(name,value)" 539 + " VALUES(?,?);"); 540 loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE, 541 R.bool.def_notification_pulse); 542 db.setTransactionSuccessful(); 543 } finally { 544 db.endTransaction(); 545 if (stmt != null) stmt.close(); 546 } 547 upgradeVersion = 43; 548 } 549 550 if (upgradeVersion == 43) { 551 /* 552 * This upgrade stores bluetooth volume separately from voice volume 553 */ 554 db.beginTransaction(); 555 SQLiteStatement stmt = null; 556 try { 557 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)" 558 + " VALUES(?,?);"); 559 loadSetting(stmt, Settings.System.VOLUME_BLUETOOTH_SCO, 560 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO)); 561 db.setTransactionSuccessful(); 562 } finally { 563 db.endTransaction(); 564 if (stmt != null) stmt.close(); 565 } 566 upgradeVersion = 44; 567 } 568 569 if (upgradeVersion == 44) { 570 /* 571 * Gservices was moved into vendor/google. 572 */ 573 db.execSQL("DROP TABLE IF EXISTS gservices"); 574 db.execSQL("DROP INDEX IF EXISTS gservicesIndex1"); 575 upgradeVersion = 45; 576 } 577 578 if (upgradeVersion == 45) { 579 /* 580 * New settings for StorageManagerService 581 */ 582 db.beginTransaction(); 583 try { 584 db.execSQL("INSERT INTO secure(name,value) values('" + 585 Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND + "','1');"); 586 db.execSQL("INSERT INTO secure(name,value) values('" + 587 Settings.Secure.MOUNT_UMS_AUTOSTART + "','0');"); 588 db.execSQL("INSERT INTO secure(name,value) values('" + 589 Settings.Secure.MOUNT_UMS_PROMPT + "','1');"); 590 db.execSQL("INSERT INTO secure(name,value) values('" + 591 Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED + "','1');"); 592 db.setTransactionSuccessful(); 593 } finally { 594 db.endTransaction(); 595 } 596 upgradeVersion = 46; 597 } 598 599 if (upgradeVersion == 46) { 600 /* 601 * The password mode constants have changed; reset back to no 602 * password. 603 */ 604 db.beginTransaction(); 605 try { 606 db.execSQL("DELETE FROM system WHERE name='lockscreen.password_type';"); 607 db.setTransactionSuccessful(); 608 } finally { 609 db.endTransaction(); 610 } 611 upgradeVersion = 47; 612 } 613 614 615 if (upgradeVersion == 47) { 616 /* 617 * The password mode constants have changed again; reset back to no 618 * password. 619 */ 620 db.beginTransaction(); 621 try { 622 db.execSQL("DELETE FROM system WHERE name='lockscreen.password_type';"); 623 db.setTransactionSuccessful(); 624 } finally { 625 db.endTransaction(); 626 } 627 upgradeVersion = 48; 628 } 629 630 if (upgradeVersion == 48) { 631 /* 632 * Default recognition service no longer initialized here, 633 * moved to RecognitionManagerService. 634 */ 635 upgradeVersion = 49; 636 } 637 638 if (upgradeVersion == 49) { 639 /* 640 * New settings for new user interface noises. 641 */ 642 db.beginTransaction(); 643 SQLiteStatement stmt = null; 644 try { 645 stmt = db.compileStatement("INSERT INTO system(name,value)" 646 + " VALUES(?,?);"); 647 loadUISoundEffectsSettings(stmt); 648 db.setTransactionSuccessful(); 649 } finally { 650 db.endTransaction(); 651 if (stmt != null) stmt.close(); 652 } 653 654 upgradeVersion = 50; 655 } 656 657 if (upgradeVersion == 50) { 658 /* 659 * Install location no longer initiated here. 660 */ 661 upgradeVersion = 51; 662 } 663 664 if (upgradeVersion == 51) { 665 /* Move the lockscreen related settings to Secure, including some private ones. */ 666 String[] settingsToMove = { 667 Secure.LOCK_PATTERN_ENABLED, 668 Secure.LOCK_PATTERN_VISIBLE, 669 Secure.LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED, 670 "lockscreen.password_type", 671 "lockscreen.lockoutattemptdeadline", 672 "lockscreen.patterneverchosen", 673 "lock_pattern_autolock", 674 "lockscreen.lockedoutpermanently", 675 "lockscreen.password_salt" 676 }; 677 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false); 678 upgradeVersion = 52; 679 } 680 681 if (upgradeVersion == 52) { 682 // new vibration/silent mode settings 683 db.beginTransaction(); 684 SQLiteStatement stmt = null; 685 try { 686 stmt = db.compileStatement("INSERT INTO system(name,value)" 687 + " VALUES(?,?);"); 688 loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT, 689 R.bool.def_vibrate_in_silent); 690 db.setTransactionSuccessful(); 691 } finally { 692 db.endTransaction(); 693 if (stmt != null) stmt.close(); 694 } 695 696 upgradeVersion = 53; 697 } 698 699 if (upgradeVersion == 53) { 700 /* 701 * New settings for set install location UI no longer initiated here. 702 */ 703 upgradeVersion = 54; 704 } 705 706 if (upgradeVersion == 54) { 707 /* 708 * Update the screen timeout value if set to never 709 */ 710 db.beginTransaction(); 711 try { 712 upgradeScreenTimeoutFromNever(db); 713 db.setTransactionSuccessful(); 714 } finally { 715 db.endTransaction(); 716 } 717 718 upgradeVersion = 55; 719 } 720 721 if (upgradeVersion == 55) { 722 /* Move the install location settings. */ 723 String[] settingsToMove = { 724 Global.SET_INSTALL_LOCATION, 725 Global.DEFAULT_INSTALL_LOCATION 726 }; 727 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false); 728 db.beginTransaction(); 729 SQLiteStatement stmt = null; 730 try { 731 stmt = db.compileStatement("INSERT INTO system(name,value)" 732 + " VALUES(?,?);"); 733 loadSetting(stmt, Global.SET_INSTALL_LOCATION, 0); 734 loadSetting(stmt, Global.DEFAULT_INSTALL_LOCATION, 735 InstallLocationUtils.APP_INSTALL_AUTO); 736 db.setTransactionSuccessful(); 737 } finally { 738 db.endTransaction(); 739 if (stmt != null) stmt.close(); 740 } 741 upgradeVersion = 56; 742 } 743 744 if (upgradeVersion == 56) { 745 /* 746 * Add Bluetooth to list of toggleable radios in airplane mode 747 */ 748 db.beginTransaction(); 749 SQLiteStatement stmt = null; 750 try { 751 db.execSQL("DELETE FROM system WHERE name='" 752 + Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS + "'"); 753 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)" 754 + " VALUES(?,?);"); 755 loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS, 756 R.string.airplane_mode_toggleable_radios); 757 db.setTransactionSuccessful(); 758 } finally { 759 db.endTransaction(); 760 if (stmt != null) stmt.close(); 761 } 762 upgradeVersion = 57; 763 } 764 765 /************* The following are Honeycomb changes ************/ 766 767 if (upgradeVersion == 57) { 768 /* 769 * No longer initializing deleted setting ACCESSIBILITY_SCRIPT_INJECTION. 770 */ 771 upgradeVersion = 58; 772 } 773 774 if (upgradeVersion == 58) { 775 /* Add default for new Auto Time Zone */ 776 int autoTimeValue = getIntValueFromSystem(db, Settings.System.AUTO_TIME, 0); 777 db.beginTransaction(); 778 SQLiteStatement stmt = null; 779 try { 780 stmt = db.compileStatement("INSERT INTO system(name,value)" + " VALUES(?,?);"); 781 loadSetting(stmt, Settings.System.AUTO_TIME_ZONE, 782 autoTimeValue); // Sync timezone to NITZ if auto_time was enabled 783 db.setTransactionSuccessful(); 784 } finally { 785 db.endTransaction(); 786 if (stmt != null) stmt.close(); 787 } 788 upgradeVersion = 59; 789 } 790 791 if (upgradeVersion == 59) { 792 // Persistence for the rotation lock feature. 793 db.beginTransaction(); 794 SQLiteStatement stmt = null; 795 try { 796 stmt = db.compileStatement("INSERT INTO system(name,value)" 797 + " VALUES(?,?);"); 798 loadIntegerSetting(stmt, Settings.System.USER_ROTATION, 799 R.integer.def_user_rotation); 800 db.setTransactionSuccessful(); 801 } finally { 802 db.endTransaction(); 803 if (stmt != null) stmt.close(); 804 } 805 upgradeVersion = 60; 806 } 807 808 if (upgradeVersion == 60) { 809 // Don't do this for upgrades from Gingerbread 810 // Were only required for intra-Honeycomb upgrades for testing 811 // upgradeScreenTimeout(db); 812 upgradeVersion = 61; 813 } 814 815 if (upgradeVersion == 61) { 816 // Don't do this for upgrades from Gingerbread 817 // Were only required for intra-Honeycomb upgrades for testing 818 // upgradeScreenTimeout(db); 819 upgradeVersion = 62; 820 } 821 822 // Change the default for screen auto-brightness mode 823 if (upgradeVersion == 62) { 824 // Don't do this for upgrades from Gingerbread 825 // Were only required for intra-Honeycomb upgrades for testing 826 // upgradeAutoBrightness(db); 827 upgradeVersion = 63; 828 } 829 830 if (upgradeVersion == 63) { 831 // This upgrade adds the STREAM_MUSIC type to the list of 832 // types affected by ringer modes (silent, vibrate, etc.) 833 db.beginTransaction(); 834 try { 835 db.execSQL("DELETE FROM system WHERE name='" 836 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'"); 837 int newValue = (1 << AudioManager.STREAM_RING) 838 | (1 << AudioManager.STREAM_NOTIFICATION) 839 | (1 << AudioManager.STREAM_SYSTEM) 840 | (1 << AudioManager.STREAM_SYSTEM_ENFORCED) 841 | (1 << AudioManager.STREAM_MUSIC); 842 db.execSQL("INSERT INTO system ('name', 'value') values ('" 843 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '" 844 + String.valueOf(newValue) + "')"); 845 db.setTransactionSuccessful(); 846 } finally { 847 db.endTransaction(); 848 } 849 upgradeVersion = 64; 850 } 851 852 if (upgradeVersion == 64) { 853 // New setting to configure the long press timeout. 854 db.beginTransaction(); 855 SQLiteStatement stmt = null; 856 try { 857 stmt = db.compileStatement("INSERT INTO secure(name,value)" 858 + " VALUES(?,?);"); 859 loadIntegerSetting(stmt, Settings.Secure.LONG_PRESS_TIMEOUT, 860 R.integer.def_long_press_timeout_millis); 861 stmt.close(); 862 db.setTransactionSuccessful(); 863 } finally { 864 db.endTransaction(); 865 if (stmt != null) stmt.close(); 866 } 867 upgradeVersion = 65; 868 } 869 870 /************* The following are Ice Cream Sandwich changes ************/ 871 872 if (upgradeVersion == 65) { 873 /* 874 * Animations are removed from Settings. Turned on by default 875 */ 876 db.beginTransaction(); 877 SQLiteStatement stmt = null; 878 try { 879 db.execSQL("DELETE FROM system WHERE name='" 880 + Settings.System.WINDOW_ANIMATION_SCALE + "'"); 881 db.execSQL("DELETE FROM system WHERE name='" 882 + Settings.System.TRANSITION_ANIMATION_SCALE + "'"); 883 stmt = db.compileStatement("INSERT INTO system(name,value)" 884 + " VALUES(?,?);"); 885 loadDefaultAnimationSettings(stmt); 886 db.setTransactionSuccessful(); 887 } finally { 888 db.endTransaction(); 889 if (stmt != null) stmt.close(); 890 } 891 upgradeVersion = 66; 892 } 893 894 if (upgradeVersion == 66) { 895 // This upgrade makes sure that MODE_RINGER_STREAMS_AFFECTED is set 896 // according to device voice capability 897 db.beginTransaction(); 898 try { 899 int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) | 900 (1 << AudioManager.STREAM_NOTIFICATION) | 901 (1 << AudioManager.STREAM_SYSTEM) | 902 (1 << AudioManager.STREAM_SYSTEM_ENFORCED); 903 if (!getTelephonyManager().isVoiceCapable()) { 904 ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC); 905 } 906 db.execSQL("DELETE FROM system WHERE name='" 907 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'"); 908 db.execSQL("INSERT INTO system ('name', 'value') values ('" 909 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '" 910 + String.valueOf(ringerModeAffectedStreams) + "')"); 911 db.setTransactionSuccessful(); 912 } finally { 913 db.endTransaction(); 914 } 915 upgradeVersion = 67; 916 } 917 918 if (upgradeVersion == 67) { 919 // New setting to enable touch exploration. 920 db.beginTransaction(); 921 SQLiteStatement stmt = null; 922 try { 923 stmt = db.compileStatement("INSERT INTO secure(name,value)" 924 + " VALUES(?,?);"); 925 loadBooleanSetting(stmt, Settings.Secure.TOUCH_EXPLORATION_ENABLED, 926 R.bool.def_touch_exploration_enabled); 927 stmt.close(); 928 db.setTransactionSuccessful(); 929 } finally { 930 db.endTransaction(); 931 if (stmt != null) stmt.close(); 932 } 933 upgradeVersion = 68; 934 } 935 936 if (upgradeVersion == 68) { 937 // Enable all system sounds by default 938 db.beginTransaction(); 939 try { 940 db.execSQL("DELETE FROM system WHERE name='" 941 + Settings.System.NOTIFICATIONS_USE_RING_VOLUME + "'"); 942 db.setTransactionSuccessful(); 943 } finally { 944 db.endTransaction(); 945 } 946 upgradeVersion = 69; 947 } 948 949 if (upgradeVersion == 69) { 950 // Add RADIO_NFC to AIRPLANE_MODE_RADIO and AIRPLANE_MODE_TOGGLEABLE_RADIOS 951 String airplaneRadios = mContext.getResources().getString( 952 R.string.def_airplane_mode_radios); 953 String toggleableRadios = mContext.getResources().getString( 954 R.string.airplane_mode_toggleable_radios); 955 db.beginTransaction(); 956 try { 957 db.execSQL("UPDATE system SET value='" + airplaneRadios + "' " + 958 "WHERE name='" + Settings.System.AIRPLANE_MODE_RADIOS + "'"); 959 db.execSQL("UPDATE system SET value='" + toggleableRadios + "' " + 960 "WHERE name='" + Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS + "'"); 961 db.setTransactionSuccessful(); 962 } finally { 963 db.endTransaction(); 964 } 965 upgradeVersion = 70; 966 } 967 968 if (upgradeVersion == 70) { 969 upgradeVersion = 71; 970 } 971 972 if (upgradeVersion == 71) { 973 // New setting to specify whether to speak passwords in accessibility mode. 974 db.beginTransaction(); 975 SQLiteStatement stmt = null; 976 try { 977 stmt = db.compileStatement("INSERT INTO secure(name,value)" 978 + " VALUES(?,?);"); 979 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD, 980 R.bool.def_accessibility_speak_password); 981 db.setTransactionSuccessful(); 982 } finally { 983 db.endTransaction(); 984 if (stmt != null) stmt.close(); 985 } 986 upgradeVersion = 72; 987 } 988 989 if (upgradeVersion == 72) { 990 // update vibration settings 991 db.beginTransaction(); 992 SQLiteStatement stmt = null; 993 try { 994 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)" 995 + " VALUES(?,?);"); 996 loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT, 997 R.bool.def_vibrate_in_silent); 998 db.setTransactionSuccessful(); 999 } finally { 1000 db.endTransaction(); 1001 if (stmt != null) stmt.close(); 1002 } 1003 upgradeVersion = 73; 1004 } 1005 1006 if (upgradeVersion == 73) { 1007 upgradeVibrateSettingFromNone(db); 1008 upgradeVersion = 74; 1009 } 1010 1011 if (upgradeVersion == 74) { 1012 // No longer using URL from which WebView loads a JavaScript based screen-reader. 1013 upgradeVersion = 75; 1014 } 1015 if (upgradeVersion == 75) { 1016 db.beginTransaction(); 1017 SQLiteStatement stmt = null; 1018 Cursor c = null; 1019 try { 1020 c = db.query(TABLE_SECURE, new String[] {"_id", "value"}, 1021 "name='lockscreen.disabled'", 1022 null, null, null, null); 1023 // only set default if it has not yet been set 1024 if (c == null || c.getCount() == 0) { 1025 stmt = db.compileStatement("INSERT INTO system(name,value)" 1026 + " VALUES(?,?);"); 1027 loadBooleanSetting(stmt, Settings.System.LOCKSCREEN_DISABLED, 1028 R.bool.def_lockscreen_disabled); 1029 } 1030 db.setTransactionSuccessful(); 1031 } finally { 1032 db.endTransaction(); 1033 if (c != null) c.close(); 1034 if (stmt != null) stmt.close(); 1035 } 1036 upgradeVersion = 76; 1037 } 1038 1039 /************* The following are Jelly Bean changes ************/ 1040 1041 if (upgradeVersion == 76) { 1042 // Removed VIBRATE_IN_SILENT setting 1043 db.beginTransaction(); 1044 try { 1045 db.execSQL("DELETE FROM system WHERE name='" 1046 + Settings.System.VIBRATE_IN_SILENT + "'"); 1047 db.setTransactionSuccessful(); 1048 } finally { 1049 db.endTransaction(); 1050 } 1051 1052 upgradeVersion = 77; 1053 } 1054 1055 if (upgradeVersion == 77) { 1056 // "vibrate when ringing" setting moved to SettingsProvider version 168 1057 upgradeVersion = 78; 1058 } 1059 1060 if (upgradeVersion == 78) { 1061 // ACCESSIBILITY_SCREEN_READER_URL has been removed 1062 upgradeVersion = 79; 1063 } 1064 1065 if (upgradeVersion == 79) { 1066 // Before touch exploration was a global setting controlled by the user 1067 // via the UI. However, if the enabled accessibility services do not 1068 // handle touch exploration mode, enabling it makes no sense. Therefore, 1069 // now the services request touch exploration mode and the user is 1070 // presented with a dialog to allow that and if she does we store that 1071 // in the database. As a result of this change a user that has enabled 1072 // accessibility, touch exploration, and some accessibility services 1073 // may lose touch exploration state, thus rendering the device useless 1074 // unless sighted help is provided, since the enabled service(s) are 1075 // not in the list of services to which the user granted a permission 1076 // to put the device in touch explore mode. Here we are allowing all 1077 // enabled accessibility services to toggle touch exploration provided 1078 // accessibility and touch exploration are enabled and no services can 1079 // toggle touch exploration. Note that the user has already manually 1080 // enabled the services and touch exploration which means the she has 1081 // given consent to have these services work in touch exploration mode. 1082 final boolean accessibilityEnabled = getIntValueFromTable(db, TABLE_SECURE, 1083 Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1; 1084 final boolean touchExplorationEnabled = getIntValueFromTable(db, TABLE_SECURE, 1085 Settings.Secure.TOUCH_EXPLORATION_ENABLED, 0) == 1; 1086 if (accessibilityEnabled && touchExplorationEnabled) { 1087 String enabledServices = getStringValueFromTable(db, TABLE_SECURE, 1088 Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, ""); 1089 String touchExplorationGrantedServices = getStringValueFromTable(db, TABLE_SECURE, 1090 Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES, ""); 1091 if (TextUtils.isEmpty(touchExplorationGrantedServices) 1092 && !TextUtils.isEmpty(enabledServices)) { 1093 SQLiteStatement stmt = null; 1094 try { 1095 db.beginTransaction(); 1096 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)" 1097 + " VALUES(?,?);"); 1098 loadSetting(stmt, 1099 Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES, 1100 enabledServices); 1101 db.setTransactionSuccessful(); 1102 } finally { 1103 db.endTransaction(); 1104 if (stmt != null) stmt.close(); 1105 } 1106 } 1107 } 1108 upgradeVersion = 80; 1109 } 1110 1111 // vvv Jelly Bean MR1 changes begin here vvv 1112 1113 if (upgradeVersion == 80) { 1114 // update screensaver settings 1115 db.beginTransaction(); 1116 SQLiteStatement stmt = null; 1117 try { 1118 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)" 1119 + " VALUES(?,?);"); 1120 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ENABLED, 1121 com.android.internal.R.bool.config_dreamsEnabledByDefault); 1122 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK, 1123 com.android.internal.R.bool.config_dreamsActivatedOnDockByDefault); 1124 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP, 1125 com.android.internal.R.bool.config_dreamsActivatedOnSleepByDefault); 1126 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT, 1127 com.android.internal.R.string.config_dreamsDefaultComponent); 1128 1129 db.setTransactionSuccessful(); 1130 } finally { 1131 db.endTransaction(); 1132 if (stmt != null) stmt.close(); 1133 } 1134 upgradeVersion = 81; 1135 } 1136 1137 if (upgradeVersion == 81) { 1138 // package_verifier_enable has been removed 1139 upgradeVersion = 82; 1140 } 1141 1142 if (upgradeVersion == 82) { 1143 // Move to per-user settings dbs 1144 if (mUserHandle == UserHandle.USER_SYSTEM) { 1145 1146 db.beginTransaction(); 1147 SQLiteStatement stmt = null; 1148 try { 1149 // Migrate now-global settings. Note that this happens before 1150 // new users can be created. 1151 createGlobalTable(db); 1152 String[] settingsToMove = setToStringArray( 1153 SettingsProvider.sSystemMovedToGlobalSettings); 1154 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, false); 1155 settingsToMove = setToStringArray( 1156 SettingsProvider.sSecureMovedToGlobalSettings); 1157 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, false); 1158 1159 db.setTransactionSuccessful(); 1160 } finally { 1161 db.endTransaction(); 1162 if (stmt != null) stmt.close(); 1163 } 1164 } 1165 upgradeVersion = 83; 1166 } 1167 1168 if (upgradeVersion == 83) { 1169 // 1. Setting whether screen magnification is enabled. 1170 // 2. Setting for screen magnification scale. 1171 // 3. Setting for screen magnification auto update. 1172 db.beginTransaction(); 1173 SQLiteStatement stmt = null; 1174 try { 1175 stmt = db.compileStatement("INSERT INTO secure(name,value) VALUES(?,?);"); 1176 loadBooleanSetting(stmt, 1177 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 1178 R.bool.def_accessibility_display_magnification_enabled); 1179 stmt.close(); 1180 stmt = db.compileStatement("INSERT INTO secure(name,value) VALUES(?,?);"); 1181 loadFractionSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE, 1182 R.fraction.def_accessibility_display_magnification_scale, 1); 1183 stmt.close(); 1184 1185 db.setTransactionSuccessful(); 1186 } finally { 1187 db.endTransaction(); 1188 if (stmt != null) stmt.close(); 1189 } 1190 upgradeVersion = 84; 1191 } 1192 1193 if (upgradeVersion == 84) { 1194 if (mUserHandle == UserHandle.USER_SYSTEM) { 1195 db.beginTransaction(); 1196 SQLiteStatement stmt = null; 1197 try { 1198 // Patch up the slightly-wrong key migration from 82 -> 83 for those 1199 // devices that missed it, ignoring if the move is redundant 1200 String[] settingsToMove = { 1201 Settings.Secure.ADB_ENABLED, 1202 Settings.Secure.BLUETOOTH_ON, 1203 Settings.Secure.DATA_ROAMING, 1204 Settings.Secure.DEVICE_PROVISIONED, 1205 Settings.Secure.INSTALL_NON_MARKET_APPS, 1206 Settings.Secure.USB_MASS_STORAGE_ENABLED 1207 }; 1208 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true); 1209 db.setTransactionSuccessful(); 1210 } finally { 1211 db.endTransaction(); 1212 if (stmt != null) stmt.close(); 1213 } 1214 } 1215 upgradeVersion = 85; 1216 } 1217 1218 if (upgradeVersion == 85) { 1219 if (mUserHandle == UserHandle.USER_SYSTEM) { 1220 db.beginTransaction(); 1221 try { 1222 // Fix up the migration, ignoring already-migrated elements, to snap up to 1223 // date with new changes to the set of global versus system/secure settings 1224 String[] settingsToMove = { Settings.System.STAY_ON_WHILE_PLUGGED_IN }; 1225 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, true); 1226 1227 db.setTransactionSuccessful(); 1228 } finally { 1229 db.endTransaction(); 1230 } 1231 } 1232 upgradeVersion = 86; 1233 } 1234 1235 if (upgradeVersion == 86) { 1236 if (mUserHandle == UserHandle.USER_SYSTEM) { 1237 db.beginTransaction(); 1238 try { 1239 String[] settingsToMove = { 1240 Settings.Global.PACKAGE_VERIFIER_TIMEOUT, 1241 Settings.Global.PACKAGE_VERIFIER_DEFAULT_RESPONSE 1242 }; 1243 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true); 1244 1245 db.setTransactionSuccessful(); 1246 } finally { 1247 db.endTransaction(); 1248 } 1249 } 1250 upgradeVersion = 87; 1251 } 1252 1253 if (upgradeVersion == 87) { 1254 if (mUserHandle == UserHandle.USER_SYSTEM) { 1255 db.beginTransaction(); 1256 try { 1257 String[] settingsToMove = { 1258 Settings.Global.DATA_STALL_ALARM_NON_AGGRESSIVE_DELAY_IN_MS, 1259 Settings.Global.DATA_STALL_ALARM_AGGRESSIVE_DELAY_IN_MS, 1260 Settings.Global.GPRS_REGISTER_CHECK_PERIOD_MS 1261 }; 1262 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true); 1263 1264 db.setTransactionSuccessful(); 1265 } finally { 1266 db.endTransaction(); 1267 } 1268 } 1269 upgradeVersion = 88; 1270 } 1271 1272 if (upgradeVersion == 88) { 1273 if (mUserHandle == UserHandle.USER_SYSTEM) { 1274 db.beginTransaction(); 1275 try { 1276 String[] settingsToMove = { 1277 Settings.Global.BATTERY_DISCHARGE_DURATION_THRESHOLD, 1278 Settings.Global.BATTERY_DISCHARGE_THRESHOLD, 1279 Settings.Global.SEND_ACTION_APP_ERROR, 1280 Settings.Global.DROPBOX_AGE_SECONDS, 1281 Settings.Global.DROPBOX_MAX_FILES, 1282 Settings.Global.DROPBOX_QUOTA_KB, 1283 Settings.Global.DROPBOX_QUOTA_PERCENT, 1284 Settings.Global.DROPBOX_RESERVE_PERCENT, 1285 Settings.Global.DROPBOX_TAG_PREFIX, 1286 Settings.Global.ERROR_LOGCAT_PREFIX, 1287 Settings.Global.SYS_FREE_STORAGE_LOG_INTERVAL, 1288 Settings.Global.DISK_FREE_CHANGE_REPORTING_THRESHOLD, 1289 Settings.Global.SYS_STORAGE_THRESHOLD_PERCENTAGE, 1290 Settings.Global.SYS_STORAGE_THRESHOLD_MAX_BYTES, 1291 Settings.Global.SYS_STORAGE_FULL_THRESHOLD_BYTES, 1292 Settings.Global.SYNC_MAX_RETRY_DELAY_IN_SECONDS, 1293 Settings.Global.CONNECTIVITY_CHANGE_DELAY, 1294 Settings.Global.CAPTIVE_PORTAL_DETECTION_ENABLED, 1295 Settings.Global.CAPTIVE_PORTAL_SERVER, 1296 Settings.Global.SET_INSTALL_LOCATION, 1297 Settings.Global.DEFAULT_INSTALL_LOCATION, 1298 Settings.Global.INET_CONDITION_DEBOUNCE_UP_DELAY, 1299 Settings.Global.INET_CONDITION_DEBOUNCE_DOWN_DELAY, 1300 Settings.Global.READ_EXTERNAL_STORAGE_ENFORCED_DEFAULT, 1301 Settings.Global.HTTP_PROXY, 1302 Settings.Global.GLOBAL_HTTP_PROXY_HOST, 1303 Settings.Global.GLOBAL_HTTP_PROXY_PORT, 1304 Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST, 1305 Settings.Global.SET_GLOBAL_HTTP_PROXY, 1306 Settings.Global.DEFAULT_DNS_SERVER, 1307 }; 1308 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true); 1309 db.setTransactionSuccessful(); 1310 } finally { 1311 db.endTransaction(); 1312 } 1313 } 1314 upgradeVersion = 89; 1315 } 1316 1317 if (upgradeVersion == 89) { 1318 if (mUserHandle == UserHandle.USER_SYSTEM) { 1319 db.beginTransaction(); 1320 try { 1321 String[] prefixesToMove = { 1322 Settings.Global.BLUETOOTH_HEADSET_PRIORITY_PREFIX, 1323 Settings.Global.BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX, 1324 Settings.Global.BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX, 1325 }; 1326 1327 movePrefixedSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, prefixesToMove); 1328 1329 db.setTransactionSuccessful(); 1330 } finally { 1331 db.endTransaction(); 1332 } 1333 } 1334 upgradeVersion = 90; 1335 } 1336 1337 if (upgradeVersion == 90) { 1338 if (mUserHandle == UserHandle.USER_SYSTEM) { 1339 db.beginTransaction(); 1340 try { 1341 String[] systemToGlobal = { 1342 Settings.Global.WINDOW_ANIMATION_SCALE, 1343 Settings.Global.TRANSITION_ANIMATION_SCALE, 1344 Settings.Global.ANIMATOR_DURATION_SCALE, 1345 Settings.Global.FANCY_IME_ANIMATIONS, 1346 Settings.Global.COMPATIBILITY_MODE, 1347 Settings.Global.EMERGENCY_TONE, 1348 Settings.Global.CALL_AUTO_RETRY, 1349 Settings.Global.DEBUG_APP, 1350 Settings.Global.WAIT_FOR_DEBUGGER, 1351 Settings.Global.ALWAYS_FINISH_ACTIVITIES, 1352 }; 1353 String[] secureToGlobal = { 1354 Settings.Global.PREFERRED_NETWORK_MODE, 1355 Settings.Global.CDMA_SUBSCRIPTION_MODE, 1356 }; 1357 1358 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, systemToGlobal, true); 1359 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, secureToGlobal, true); 1360 1361 db.setTransactionSuccessful(); 1362 } finally { 1363 db.endTransaction(); 1364 } 1365 } 1366 upgradeVersion = 91; 1367 } 1368 1369 if (upgradeVersion == 91) { 1370 if (mUserHandle == UserHandle.USER_SYSTEM) { 1371 db.beginTransaction(); 1372 try { 1373 // Move ringer mode from system to global settings 1374 String[] settingsToMove = { Settings.Global.MODE_RINGER }; 1375 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, true); 1376 1377 db.setTransactionSuccessful(); 1378 } finally { 1379 db.endTransaction(); 1380 } 1381 } 1382 upgradeVersion = 92; 1383 } 1384 1385 if (upgradeVersion == 92) { 1386 SQLiteStatement stmt = null; 1387 try { 1388 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)" 1389 + " VALUES(?,?);"); 1390 if (mUserHandle == UserHandle.USER_SYSTEM) { 1391 // consider existing primary users to have made it through user setup 1392 // if the globally-scoped device-provisioned bit is set 1393 // (indicating they already made it through setup as primary) 1394 int deviceProvisioned = getIntValueFromTable(db, TABLE_GLOBAL, 1395 Settings.Global.DEVICE_PROVISIONED, 0); 1396 loadSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE, 1397 deviceProvisioned); 1398 } else { 1399 // otherwise use the default 1400 loadBooleanSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE, 1401 R.bool.def_user_setup_complete); 1402 } 1403 } finally { 1404 if (stmt != null) stmt.close(); 1405 } 1406 upgradeVersion = 93; 1407 } 1408 1409 if (upgradeVersion == 93) { 1410 // Redo this step, since somehow it didn't work the first time for some users 1411 if (mUserHandle == UserHandle.USER_SYSTEM) { 1412 db.beginTransaction(); 1413 try { 1414 // Migrate now-global settings 1415 String[] settingsToMove = setToStringArray( 1416 SettingsProvider.sSystemMovedToGlobalSettings); 1417 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, true); 1418 settingsToMove = setToStringArray( 1419 SettingsProvider.sSecureMovedToGlobalSettings); 1420 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true); 1421 1422 db.setTransactionSuccessful(); 1423 } finally { 1424 db.endTransaction(); 1425 } 1426 } 1427 upgradeVersion = 94; 1428 } 1429 1430 if (upgradeVersion == 94) { 1431 // charging sound moved to SettingsProvider version 184 1432 upgradeVersion = 95; 1433 } 1434 1435 if (upgradeVersion == 95) { 1436 if (mUserHandle == UserHandle.USER_SYSTEM) { 1437 db.beginTransaction(); 1438 try { 1439 String[] settingsToMove = { Settings.Global.BUGREPORT_IN_POWER_MENU }; 1440 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true); 1441 db.setTransactionSuccessful(); 1442 } finally { 1443 db.endTransaction(); 1444 } 1445 } 1446 upgradeVersion = 96; 1447 } 1448 1449 if (upgradeVersion == 96) { 1450 // NOP bump due to a reverted change that some people got on upgrade. 1451 upgradeVersion = 97; 1452 } 1453 1454 if (upgradeVersion == 97) { 1455 if (mUserHandle == UserHandle.USER_SYSTEM) { 1456 db.beginTransaction(); 1457 SQLiteStatement stmt = null; 1458 try { 1459 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)" 1460 + " VALUES(?,?);"); 1461 loadIntegerSetting(stmt, Settings.Global.LOW_BATTERY_SOUND_TIMEOUT, 1462 R.integer.def_low_battery_sound_timeout); 1463 db.setTransactionSuccessful(); 1464 } finally { 1465 db.endTransaction(); 1466 if (stmt != null) stmt.close(); 1467 } 1468 } 1469 upgradeVersion = 98; 1470 } 1471 1472 if (upgradeVersion == 98) { 1473 // no-op; LOCK_SCREEN_SHOW_NOTIFICATIONS now handled in version 106 1474 upgradeVersion = 99; 1475 } 1476 1477 if (upgradeVersion == 99) { 1478 // no-op; HEADS_UP_NOTIFICATIONS_ENABLED now handled in version 100 1479 upgradeVersion = 100; 1480 } 1481 1482 if (upgradeVersion == 100) { 1483 // note: LOCK_SCREEN_SHOW_NOTIFICATIONS now handled in version 106 1484 if (mUserHandle == UserHandle.USER_SYSTEM) { 1485 db.beginTransaction(); 1486 SQLiteStatement stmt = null; 1487 try { 1488 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)" 1489 + " VALUES(?,?);"); 1490 loadIntegerSetting(stmt, Global.HEADS_UP_NOTIFICATIONS_ENABLED, 1491 R.integer.def_heads_up_enabled); 1492 db.setTransactionSuccessful(); 1493 } finally { 1494 db.endTransaction(); 1495 if (stmt != null) stmt.close(); 1496 } 1497 } 1498 upgradeVersion = 101; 1499 } 1500 1501 if (upgradeVersion == 101) { 1502 if (mUserHandle == UserHandle.USER_SYSTEM) { 1503 db.beginTransaction(); 1504 SQLiteStatement stmt = null; 1505 try { 1506 stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)" 1507 + " VALUES(?,?);"); 1508 loadSetting(stmt, Settings.Global.DEVICE_NAME, getDefaultDeviceName()); 1509 db.setTransactionSuccessful(); 1510 } finally { 1511 db.endTransaction(); 1512 if (stmt != null) stmt.close(); 1513 } 1514 } 1515 upgradeVersion = 102; 1516 } 1517 1518 if (upgradeVersion == 102) { 1519 db.beginTransaction(); 1520 SQLiteStatement stmt = null; 1521 try { 1522 // The INSTALL_NON_MARKET_APPS setting is becoming per-user rather 1523 // than device-global. 1524 if (mUserHandle == UserHandle.USER_SYSTEM) { 1525 // In the owner user, the global table exists so we can migrate the 1526 // entry from there to the secure table, preserving its value. 1527 String[] globalToSecure = { 1528 Settings.Secure.INSTALL_NON_MARKET_APPS 1529 }; 1530 moveSettingsToNewTable(db, TABLE_GLOBAL, TABLE_SECURE, globalToSecure, true); 1531 } else { 1532 // Secondary users' dbs don't have the global table, so institute the 1533 // default. 1534 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)" 1535 + " VALUES(?,?);"); 1536 loadBooleanSetting(stmt, Settings.Secure.INSTALL_NON_MARKET_APPS, 1537 R.bool.def_install_non_market_apps); 1538 } 1539 db.setTransactionSuccessful(); 1540 } finally { 1541 db.endTransaction(); 1542 if (stmt != null) stmt.close(); 1543 } 1544 upgradeVersion = 103; 1545 } 1546 1547 if (upgradeVersion == 103) { 1548 db.beginTransaction(); 1549 SQLiteStatement stmt = null; 1550 try { 1551 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)" 1552 + " VALUES(?,?);"); 1553 loadBooleanSetting(stmt, Settings.Secure.WAKE_GESTURE_ENABLED, 1554 R.bool.def_wake_gesture_enabled); 1555 db.setTransactionSuccessful(); 1556 } finally { 1557 db.endTransaction(); 1558 if (stmt != null) stmt.close(); 1559 } 1560 upgradeVersion = 104; 1561 } 1562 1563 if (upgradeVersion < 105) { 1564 // No-op: GUEST_USER_ENABLED setting was removed 1565 upgradeVersion = 105; 1566 } 1567 1568 if (upgradeVersion < 106) { 1569 // LOCK_SCREEN_SHOW_NOTIFICATIONS is now per-user. 1570 db.beginTransaction(); 1571 SQLiteStatement stmt = null; 1572 try { 1573 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)" 1574 + " VALUES(?,?);"); 1575 loadIntegerSetting(stmt, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1576 R.integer.def_lock_screen_show_notifications); 1577 if (mUserHandle == UserHandle.USER_SYSTEM) { 1578 final int oldShow = getIntValueFromTable(db, 1579 TABLE_GLOBAL, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, -1); 1580 if (oldShow >= 0) { 1581 // overwrite the default with whatever you had 1582 loadSetting(stmt, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, oldShow); 1583 final SQLiteStatement deleteStmt 1584 = db.compileStatement("DELETE FROM global WHERE name=?"); 1585 deleteStmt.bindString(1, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS); 1586 deleteStmt.execute(); 1587 } 1588 } 1589 db.setTransactionSuccessful(); 1590 } finally { 1591 db.endTransaction(); 1592 if (stmt != null) stmt.close(); 1593 } 1594 upgradeVersion = 106; 1595 } 1596 1597 if (upgradeVersion < 107) { 1598 // Add trusted sound setting 1599 if (mUserHandle == UserHandle.USER_SYSTEM) { 1600 db.beginTransaction(); 1601 SQLiteStatement stmt = null; 1602 try { 1603 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)" 1604 + " VALUES(?,?);"); 1605 loadStringSetting(stmt, Settings.Global.TRUSTED_SOUND, 1606 R.string.def_trusted_sound); 1607 db.setTransactionSuccessful(); 1608 } finally { 1609 db.endTransaction(); 1610 if (stmt != null) stmt.close(); 1611 } 1612 } 1613 upgradeVersion = 107; 1614 } 1615 1616 if (upgradeVersion < 108) { 1617 // Reset the auto-brightness setting to default since the behavior 1618 // of the feature is now quite different and is being presented to 1619 // the user in a new way as "adaptive brightness". 1620 db.beginTransaction(); 1621 SQLiteStatement stmt = null; 1622 try { 1623 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)" 1624 + " VALUES(?,?);"); 1625 loadBooleanSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_MODE, 1626 R.bool.def_screen_brightness_automatic_mode); 1627 db.setTransactionSuccessful(); 1628 } finally { 1629 db.endTransaction(); 1630 if (stmt != null) stmt.close(); 1631 } 1632 upgradeVersion = 108; 1633 } 1634 1635 if (upgradeVersion < 109) { 1636 db.beginTransaction(); 1637 SQLiteStatement stmt = null; 1638 try { 1639 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)" 1640 + " VALUES(?,?);"); 1641 loadBooleanSetting(stmt, Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1642 R.bool.def_lock_screen_allow_private_notifications); 1643 db.setTransactionSuccessful(); 1644 } finally { 1645 db.endTransaction(); 1646 if (stmt != null) stmt.close(); 1647 } 1648 upgradeVersion = 109; 1649 } 1650 1651 if (upgradeVersion < 110) { 1652 // The SIP_CALL_OPTIONS value SIP_ASK_EACH_TIME is being deprecated. 1653 // If the SIP_CALL_OPTIONS setting is set to SIP_ASK_EACH_TIME, default to 1654 // SIP_ADDRESS_ONLY. 1655 db.beginTransaction(); 1656 SQLiteStatement stmt = null; 1657 try { 1658 stmt = db.compileStatement("UPDATE system SET value = ? " + 1659 "WHERE name = ? AND value = ?;"); 1660 stmt.bindString(1, Settings.System.SIP_ADDRESS_ONLY); 1661 stmt.bindString(2, Settings.System.SIP_CALL_OPTIONS); 1662 stmt.bindString(3, Settings.System.SIP_ASK_ME_EACH_TIME); 1663 stmt.execute(); 1664 db.setTransactionSuccessful(); 1665 } finally { 1666 db.endTransaction(); 1667 if (stmt != null) stmt.close(); 1668 } 1669 upgradeVersion = 110; 1670 } 1671 1672 if (upgradeVersion < 111) { 1673 // reset ringer mode, so it doesn't force zen mode to follow 1674 if (mUserHandle == UserHandle.USER_SYSTEM) { 1675 db.beginTransaction(); 1676 SQLiteStatement stmt = null; 1677 try { 1678 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)" 1679 + " VALUES(?,?);"); 1680 loadSetting(stmt, Settings.Global.MODE_RINGER, AudioManager.RINGER_MODE_NORMAL); 1681 db.setTransactionSuccessful(); 1682 } finally { 1683 db.endTransaction(); 1684 if (stmt != null) stmt.close(); 1685 } 1686 } 1687 upgradeVersion = 111; 1688 } 1689 1690 if (upgradeVersion < 112) { 1691 if (mUserHandle == UserHandle.USER_SYSTEM) { 1692 // When device name was added, we went with Manufacturer + Model, device name should 1693 // actually be Model only. 1694 // Update device name to Model if it wasn't modified by user. 1695 db.beginTransaction(); 1696 SQLiteStatement stmt = null; 1697 try { 1698 stmt = db.compileStatement("UPDATE global SET value = ? " 1699 + " WHERE name = ? AND value = ?"); 1700 stmt.bindString(1, getDefaultDeviceName()); // new default device name 1701 stmt.bindString(2, Settings.Global.DEVICE_NAME); 1702 stmt.bindString(3, getOldDefaultDeviceName()); // old default device name 1703 stmt.execute(); 1704 db.setTransactionSuccessful(); 1705 } finally { 1706 db.endTransaction(); 1707 if (stmt != null) stmt.close(); 1708 } 1709 } 1710 upgradeVersion = 112; 1711 } 1712 1713 if (upgradeVersion < 113) { 1714 db.beginTransaction(); 1715 SQLiteStatement stmt = null; 1716 try { 1717 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)" 1718 + " VALUES(?,?);"); 1719 loadIntegerSetting(stmt, Settings.Secure.SLEEP_TIMEOUT, 1720 R.integer.def_sleep_timeout); 1721 db.setTransactionSuccessful(); 1722 } finally { 1723 db.endTransaction(); 1724 if (stmt != null) stmt.close(); 1725 } 1726 upgradeVersion = 113; 1727 } 1728 1729 // We skipped 114 to handle a merge conflict with the introduction of theater mode. 1730 1731 if (upgradeVersion < 115) { 1732 if (mUserHandle == UserHandle.USER_SYSTEM) { 1733 db.beginTransaction(); 1734 SQLiteStatement stmt = null; 1735 try { 1736 stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)" 1737 + " VALUES(?,?);"); 1738 loadBooleanSetting(stmt, Global.THEATER_MODE_ON, 1739 R.bool.def_theater_mode_on); 1740 db.setTransactionSuccessful(); 1741 } finally { 1742 db.endTransaction(); 1743 if (stmt != null) stmt.close(); 1744 } 1745 } 1746 upgradeVersion = 115; 1747 } 1748 1749 if (upgradeVersion < 116) { 1750 /* 1751 * To control the default value by carrier config manager, initializing 1752 * ENHANCED_4G_MODE_ENABLED has been removed. 1753 */ 1754 upgradeVersion = 116; 1755 } 1756 1757 if (upgradeVersion < 117) { 1758 db.beginTransaction(); 1759 try { 1760 String[] systemToSecure = { 1761 Settings.Secure.LOCK_TO_APP_EXIT_LOCKED 1762 }; 1763 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, systemToSecure, true); 1764 db.setTransactionSuccessful(); 1765 } finally { 1766 db.endTransaction(); 1767 } 1768 upgradeVersion = 117; 1769 } 1770 1771 if (upgradeVersion < 118) { 1772 // Reset rotation-lock-for-accessibility on upgrade, since it now hides the display 1773 // setting. 1774 db.beginTransaction(); 1775 SQLiteStatement stmt = null; 1776 try { 1777 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)" 1778 + " VALUES(?,?);"); 1779 loadSetting(stmt, Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0); 1780 db.setTransactionSuccessful(); 1781 } finally { 1782 db.endTransaction(); 1783 if (stmt != null) stmt.close(); 1784 } 1785 upgradeVersion = 118; 1786 } 1787 1788 /* 1789 * IMPORTANT: Do not add any more upgrade steps here as the global, 1790 * secure, and system settings are no longer stored in a database 1791 * but are kept in memory and persisted to XML. 1792 * 1793 * See: SettingsProvider.UpgradeController#onUpgradeLocked 1794 */ 1795 1796 if (upgradeVersion != currentVersion) { 1797 recreateDatabase(db, oldVersion, upgradeVersion, currentVersion); 1798 } 1799 } 1800 recreateDatabase(SQLiteDatabase db, int oldVersion, int upgradeVersion, int currentVersion)1801 public void recreateDatabase(SQLiteDatabase db, int oldVersion, 1802 int upgradeVersion, int currentVersion) { 1803 db.execSQL("DROP TABLE IF EXISTS global"); 1804 db.execSQL("DROP TABLE IF EXISTS globalIndex1"); 1805 db.execSQL("DROP TABLE IF EXISTS system"); 1806 db.execSQL("DROP INDEX IF EXISTS systemIndex1"); 1807 db.execSQL("DROP TABLE IF EXISTS secure"); 1808 db.execSQL("DROP INDEX IF EXISTS secureIndex1"); 1809 db.execSQL("DROP TABLE IF EXISTS gservices"); 1810 db.execSQL("DROP INDEX IF EXISTS gservicesIndex1"); 1811 db.execSQL("DROP TABLE IF EXISTS bluetooth_devices"); 1812 db.execSQL("DROP TABLE IF EXISTS bookmarks"); 1813 db.execSQL("DROP INDEX IF EXISTS bookmarksIndex1"); 1814 db.execSQL("DROP INDEX IF EXISTS bookmarksIndex2"); 1815 db.execSQL("DROP TABLE IF EXISTS favorites"); 1816 1817 onCreate(db); 1818 1819 // Added for diagnosing settings.db wipes after the fact 1820 String wipeReason = oldVersion + "/" + upgradeVersion + "/" + currentVersion; 1821 db.execSQL("INSERT INTO secure(name,value) values('" + 1822 "wiped_db_reason" + "','" + wipeReason + "');"); 1823 } 1824 setToStringArray(Set<String> set)1825 private String[] setToStringArray(Set<String> set) { 1826 String[] array = new String[set.size()]; 1827 return set.toArray(array); 1828 } 1829 moveSettingsToNewTable(SQLiteDatabase db, String sourceTable, String destTable, String[] settingsToMove, boolean doIgnore)1830 private void moveSettingsToNewTable(SQLiteDatabase db, 1831 String sourceTable, String destTable, 1832 String[] settingsToMove, boolean doIgnore) { 1833 // Copy settings values from the source table to the dest, and remove from the source 1834 SQLiteStatement insertStmt = null; 1835 SQLiteStatement deleteStmt = null; 1836 1837 db.beginTransaction(); 1838 try { 1839 insertStmt = db.compileStatement("INSERT " 1840 + (doIgnore ? " OR IGNORE " : "") 1841 + " INTO " + destTable + " (name,value) SELECT name,value FROM " 1842 + sourceTable + " WHERE name=?"); 1843 deleteStmt = db.compileStatement("DELETE FROM " + sourceTable + " WHERE name=?"); 1844 1845 for (String setting : settingsToMove) { 1846 insertStmt.bindString(1, setting); 1847 insertStmt.execute(); 1848 1849 deleteStmt.bindString(1, setting); 1850 deleteStmt.execute(); 1851 } 1852 db.setTransactionSuccessful(); 1853 } finally { 1854 db.endTransaction(); 1855 if (insertStmt != null) { 1856 insertStmt.close(); 1857 } 1858 if (deleteStmt != null) { 1859 deleteStmt.close(); 1860 } 1861 } 1862 } 1863 1864 /** 1865 * Move any settings with the given prefixes from the source table to the 1866 * destination table. 1867 */ movePrefixedSettingsToNewTable( SQLiteDatabase db, String sourceTable, String destTable, String[] prefixesToMove)1868 private void movePrefixedSettingsToNewTable( 1869 SQLiteDatabase db, String sourceTable, String destTable, String[] prefixesToMove) { 1870 SQLiteStatement insertStmt = null; 1871 SQLiteStatement deleteStmt = null; 1872 1873 db.beginTransaction(); 1874 try { 1875 insertStmt = db.compileStatement("INSERT INTO " + destTable 1876 + " (name,value) SELECT name,value FROM " + sourceTable 1877 + " WHERE substr(name,0,?)=?"); 1878 deleteStmt = db.compileStatement( 1879 "DELETE FROM " + sourceTable + " WHERE substr(name,0,?)=?"); 1880 1881 for (String prefix : prefixesToMove) { 1882 insertStmt.bindLong(1, prefix.length() + 1); 1883 insertStmt.bindString(2, prefix); 1884 insertStmt.execute(); 1885 1886 deleteStmt.bindLong(1, prefix.length() + 1); 1887 deleteStmt.bindString(2, prefix); 1888 deleteStmt.execute(); 1889 } 1890 db.setTransactionSuccessful(); 1891 } finally { 1892 db.endTransaction(); 1893 if (insertStmt != null) { 1894 insertStmt.close(); 1895 } 1896 if (deleteStmt != null) { 1897 deleteStmt.close(); 1898 } 1899 } 1900 } 1901 upgradeLockPatternLocation(SQLiteDatabase db)1902 private void upgradeLockPatternLocation(SQLiteDatabase db) { 1903 Cursor c = db.query(TABLE_SYSTEM, new String[] {"_id", "value"}, "name='lock_pattern'", 1904 null, null, null, null); 1905 if (c.getCount() > 0) { 1906 c.moveToFirst(); 1907 String lockPattern = c.getString(1); 1908 if (!TextUtils.isEmpty(lockPattern)) { 1909 // Convert lock pattern 1910 try { 1911 LockPatternUtils lpu = new LockPatternUtils(mContext); 1912 List<LockPatternView.Cell> cellPattern = 1913 LockPatternUtils.byteArrayToPattern(lockPattern.getBytes()); 1914 lpu.setLockCredential( 1915 LockscreenCredential.createPattern(cellPattern), 1916 LockscreenCredential.createNone(), 1917 UserHandle.USER_SYSTEM); 1918 } catch (IllegalArgumentException e) { 1919 // Don't want corrupted lock pattern to hang the reboot process 1920 } 1921 } 1922 c.close(); 1923 db.delete(TABLE_SYSTEM, "name='lock_pattern'", null); 1924 } else { 1925 c.close(); 1926 } 1927 } 1928 upgradeScreenTimeoutFromNever(SQLiteDatabase db)1929 private void upgradeScreenTimeoutFromNever(SQLiteDatabase db) { 1930 // See if the timeout is -1 (for "Never"). 1931 Cursor c = db.query(TABLE_SYSTEM, new String[] { "_id", "value" }, "name=? AND value=?", 1932 new String[] { Settings.System.SCREEN_OFF_TIMEOUT, "-1" }, 1933 null, null, null); 1934 1935 SQLiteStatement stmt = null; 1936 if (c.getCount() > 0) { 1937 c.close(); 1938 try { 1939 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)" 1940 + " VALUES(?,?);"); 1941 1942 // Set the timeout to 30 minutes in milliseconds 1943 loadSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT, 1944 Integer.toString(30 * 60 * 1000)); 1945 } finally { 1946 if (stmt != null) stmt.close(); 1947 } 1948 } else { 1949 c.close(); 1950 } 1951 } 1952 upgradeVibrateSettingFromNone(SQLiteDatabase db)1953 private void upgradeVibrateSettingFromNone(SQLiteDatabase db) { 1954 int vibrateSetting = getIntValueFromSystem(db, Settings.System.VIBRATE_ON, 0); 1955 // If the ringer vibrate value is invalid, set it to the default 1956 if ((vibrateSetting & 3) == AudioManager.VIBRATE_SETTING_OFF) { 1957 vibrateSetting = AudioSystem.getValueForVibrateSetting(0, 1958 AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT); 1959 } 1960 // Apply the same setting to the notification vibrate value 1961 vibrateSetting = AudioSystem.getValueForVibrateSetting(vibrateSetting, 1962 AudioManager.VIBRATE_TYPE_NOTIFICATION, vibrateSetting); 1963 1964 SQLiteStatement stmt = null; 1965 try { 1966 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)" 1967 + " VALUES(?,?);"); 1968 loadSetting(stmt, Settings.System.VIBRATE_ON, vibrateSetting); 1969 } finally { 1970 if (stmt != null) 1971 stmt.close(); 1972 } 1973 } 1974 upgradeScreenTimeout(SQLiteDatabase db)1975 private void upgradeScreenTimeout(SQLiteDatabase db) { 1976 // Change screen timeout to current default 1977 db.beginTransaction(); 1978 SQLiteStatement stmt = null; 1979 try { 1980 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)" 1981 + " VALUES(?,?);"); 1982 loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT, 1983 R.integer.def_screen_off_timeout); 1984 db.setTransactionSuccessful(); 1985 } finally { 1986 db.endTransaction(); 1987 if (stmt != null) 1988 stmt.close(); 1989 } 1990 } 1991 upgradeAutoBrightness(SQLiteDatabase db)1992 private void upgradeAutoBrightness(SQLiteDatabase db) { 1993 db.beginTransaction(); 1994 try { 1995 String value = 1996 mContext.getResources().getBoolean( 1997 R.bool.def_screen_brightness_automatic_mode) ? "1" : "0"; 1998 db.execSQL("INSERT OR REPLACE INTO system(name,value) values('" + 1999 Settings.System.SCREEN_BRIGHTNESS_MODE + "','" + value + "');"); 2000 db.setTransactionSuccessful(); 2001 } finally { 2002 db.endTransaction(); 2003 } 2004 } 2005 2006 /** 2007 * Loads the default volume levels. It is actually inserting the index of 2008 * the volume array for each of the volume controls. 2009 * 2010 * @param db the database to insert the volume levels into 2011 */ loadVolumeLevels(SQLiteDatabase db)2012 private void loadVolumeLevels(SQLiteDatabase db) { 2013 SQLiteStatement stmt = null; 2014 try { 2015 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)" 2016 + " VALUES(?,?);"); 2017 2018 loadSetting(stmt, Settings.System.VOLUME_MUSIC, 2019 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_MUSIC)); 2020 loadSetting(stmt, Settings.System.VOLUME_RING, 2021 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_RING)); 2022 loadSetting(stmt, Settings.System.VOLUME_SYSTEM, 2023 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_SYSTEM)); 2024 loadSetting( 2025 stmt, 2026 Settings.System.VOLUME_VOICE, 2027 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_VOICE_CALL)); 2028 loadSetting(stmt, Settings.System.VOLUME_ALARM, 2029 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_ALARM)); 2030 loadSetting( 2031 stmt, 2032 Settings.System.VOLUME_NOTIFICATION, 2033 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_NOTIFICATION)); 2034 loadSetting( 2035 stmt, 2036 Settings.System.VOLUME_BLUETOOTH_SCO, 2037 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO)); 2038 2039 // By default: 2040 // - ringtones, notification, system and music streams are affected by ringer mode 2041 // on non voice capable devices (tablets) 2042 // - ringtones, notification and system streams are affected by ringer mode 2043 // on voice capable devices (phones) 2044 int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) | 2045 (1 << AudioManager.STREAM_NOTIFICATION) | 2046 (1 << AudioManager.STREAM_SYSTEM) | 2047 (1 << AudioManager.STREAM_SYSTEM_ENFORCED); 2048 if (!getTelephonyManager().isVoiceCapable()) { 2049 ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC); 2050 } 2051 loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED, 2052 ringerModeAffectedStreams); 2053 2054 loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED, 2055 AudioSystem.DEFAULT_MUTE_STREAMS_AFFECTED); 2056 } finally { 2057 if (stmt != null) stmt.close(); 2058 } 2059 } 2060 loadVibrateSetting(SQLiteDatabase db, boolean deleteOld)2061 private void loadVibrateSetting(SQLiteDatabase db, boolean deleteOld) { 2062 if (deleteOld) { 2063 db.execSQL("DELETE FROM system WHERE name='" + Settings.System.VIBRATE_ON + "'"); 2064 } 2065 2066 SQLiteStatement stmt = null; 2067 try { 2068 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)" 2069 + " VALUES(?,?);"); 2070 2071 // Vibrate on by default for ringer, on for notification 2072 int vibrate = 0; 2073 vibrate = AudioSystem.getValueForVibrateSetting(vibrate, 2074 AudioManager.VIBRATE_TYPE_NOTIFICATION, 2075 AudioManager.VIBRATE_SETTING_ONLY_SILENT); 2076 vibrate |= AudioSystem.getValueForVibrateSetting(vibrate, 2077 AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT); 2078 loadSetting(stmt, Settings.System.VIBRATE_ON, vibrate); 2079 } finally { 2080 if (stmt != null) stmt.close(); 2081 } 2082 } 2083 loadSettings(SQLiteDatabase db)2084 private void loadSettings(SQLiteDatabase db) { 2085 loadSystemSettings(db); 2086 loadSecureSettings(db); 2087 // The global table only exists for the 'owner/system' user 2088 if (mUserHandle == UserHandle.USER_SYSTEM) { 2089 loadGlobalSettings(db); 2090 } 2091 } 2092 loadSystemSettings(SQLiteDatabase db)2093 private void loadSystemSettings(SQLiteDatabase db) { 2094 SQLiteStatement stmt = null; 2095 try { 2096 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)" 2097 + " VALUES(?,?);"); 2098 2099 loadBooleanSetting(stmt, Settings.System.DIM_SCREEN, 2100 R.bool.def_dim_screen); 2101 loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT, 2102 R.integer.def_screen_off_timeout); 2103 2104 // Set default cdma DTMF type 2105 loadSetting(stmt, Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, 0); 2106 2107 // Set default hearing aid 2108 loadSetting(stmt, Settings.System.HEARING_AID, 0); 2109 2110 // Set default tty mode 2111 loadSetting(stmt, Settings.System.TTY_MODE, 0); 2112 2113 loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS, 2114 R.integer.def_screen_brightness); 2115 2116 loadBooleanSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_MODE, 2117 R.bool.def_screen_brightness_automatic_mode); 2118 2119 loadBooleanSetting(stmt, Settings.System.ACCELEROMETER_ROTATION, 2120 R.bool.def_accelerometer_rotation); 2121 2122 loadIntegerSetting(stmt, Settings.System.USER_ROTATION, R.integer.def_user_rotation); 2123 2124 loadDefaultHapticSettings(stmt); 2125 2126 loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE, 2127 R.bool.def_notification_pulse); 2128 2129 loadUISoundEffectsSettings(stmt); 2130 2131 loadIntegerSetting(stmt, Settings.System.POINTER_SPEED, 2132 R.integer.def_pointer_speed); 2133 2134 /* 2135 * IMPORTANT: Do not add any more upgrade steps here as the global, 2136 * secure, and system settings are no longer stored in a database 2137 * but are kept in memory and persisted to XML. 2138 * 2139 * See: SettingsProvider.UpgradeController#onUpgradeLocked 2140 */ 2141 } finally { 2142 if (stmt != null) stmt.close(); 2143 } 2144 } 2145 loadUISoundEffectsSettings(SQLiteStatement stmt)2146 private void loadUISoundEffectsSettings(SQLiteStatement stmt) { 2147 loadBooleanSetting(stmt, Settings.System.DTMF_TONE_WHEN_DIALING, 2148 R.bool.def_dtmf_tones_enabled); 2149 loadBooleanSetting(stmt, Settings.System.SOUND_EFFECTS_ENABLED, 2150 R.bool.def_sound_effects_enabled); 2151 loadBooleanSetting(stmt, Settings.System.HAPTIC_FEEDBACK_ENABLED, 2152 R.bool.def_haptic_feedback); 2153 2154 loadIntegerSetting(stmt, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 2155 R.integer.def_lockscreen_sounds_enabled); 2156 } 2157 loadDefaultAnimationSettings(SQLiteStatement stmt)2158 private void loadDefaultAnimationSettings(SQLiteStatement stmt) { 2159 loadFractionSetting(stmt, Settings.System.WINDOW_ANIMATION_SCALE, 2160 R.fraction.def_window_animation_scale, 1); 2161 loadFractionSetting(stmt, Settings.System.TRANSITION_ANIMATION_SCALE, 2162 R.fraction.def_window_transition_scale, 1); 2163 } 2164 loadDefaultHapticSettings(SQLiteStatement stmt)2165 private void loadDefaultHapticSettings(SQLiteStatement stmt) { 2166 loadBooleanSetting(stmt, Settings.System.HAPTIC_FEEDBACK_ENABLED, 2167 R.bool.def_haptic_feedback); 2168 } 2169 loadSecureSettings(SQLiteDatabase db)2170 private void loadSecureSettings(SQLiteDatabase db) { 2171 SQLiteStatement stmt = null; 2172 try { 2173 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)" 2174 + " VALUES(?,?);"); 2175 2176 // Don't do this. The SystemServer will initialize ADB_ENABLED from a 2177 // persistent system property instead. 2178 //loadSetting(stmt, Settings.Secure.ADB_ENABLED, 0); 2179 2180 // Allow mock locations default, based on build 2181 loadSetting(stmt, Settings.Secure.ALLOW_MOCK_LOCATION, 2182 "1".equals(SystemProperties.get("ro.allow.mock.location")) ? 1 : 0); 2183 2184 loadSecure35Settings(stmt); 2185 2186 loadBooleanSetting(stmt, Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND, 2187 R.bool.def_mount_play_notification_snd); 2188 2189 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_AUTOSTART, 2190 R.bool.def_mount_ums_autostart); 2191 2192 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_PROMPT, 2193 R.bool.def_mount_ums_prompt); 2194 2195 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED, 2196 R.bool.def_mount_ums_notify_enabled); 2197 2198 loadIntegerSetting(stmt, Settings.Secure.LONG_PRESS_TIMEOUT, 2199 R.integer.def_long_press_timeout_millis); 2200 2201 loadBooleanSetting(stmt, Settings.Secure.TOUCH_EXPLORATION_ENABLED, 2202 R.bool.def_touch_exploration_enabled); 2203 2204 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD, 2205 R.bool.def_accessibility_speak_password); 2206 2207 if (SystemProperties.getBoolean("ro.lockscreen.disable.default", false) == true) { 2208 loadSetting(stmt, Settings.System.LOCKSCREEN_DISABLED, "1"); 2209 } else { 2210 loadBooleanSetting(stmt, Settings.System.LOCKSCREEN_DISABLED, 2211 R.bool.def_lockscreen_disabled); 2212 } 2213 2214 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ENABLED, 2215 com.android.internal.R.bool.config_dreamsEnabledByDefault); 2216 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK, 2217 com.android.internal.R.bool.config_dreamsActivatedOnDockByDefault); 2218 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP, 2219 com.android.internal.R.bool.config_dreamsActivatedOnSleepByDefault); 2220 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT, 2221 com.android.internal.R.string.config_dreamsDefaultComponent); 2222 2223 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 2224 R.bool.def_accessibility_display_magnification_enabled); 2225 2226 loadFractionSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE, 2227 R.fraction.def_accessibility_display_magnification_scale, 1); 2228 2229 loadBooleanSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE, 2230 R.bool.def_user_setup_complete); 2231 2232 loadStringSetting(stmt, Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS, 2233 R.string.def_immersive_mode_confirmations); 2234 2235 loadBooleanSetting(stmt, Settings.Secure.INSTALL_NON_MARKET_APPS, 2236 R.bool.def_install_non_market_apps); 2237 2238 loadBooleanSetting(stmt, Settings.Secure.WAKE_GESTURE_ENABLED, 2239 R.bool.def_wake_gesture_enabled); 2240 2241 loadIntegerSetting(stmt, Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 2242 R.integer.def_lock_screen_show_notifications); 2243 2244 loadBooleanSetting(stmt, Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 2245 R.bool.def_lock_screen_allow_private_notifications); 2246 2247 loadIntegerSetting(stmt, Settings.Secure.SLEEP_TIMEOUT, 2248 R.integer.def_sleep_timeout); 2249 2250 /* 2251 * IMPORTANT: Do not add any more upgrade steps here as the global, 2252 * secure, and system settings are no longer stored in a database 2253 * but are kept in memory and persisted to XML. 2254 * 2255 * See: SettingsProvider.UpgradeController#onUpgradeLocked 2256 */ 2257 } finally { 2258 if (stmt != null) stmt.close(); 2259 } 2260 } 2261 loadSecure35Settings(SQLiteStatement stmt)2262 private void loadSecure35Settings(SQLiteStatement stmt) { 2263 loadBooleanSetting(stmt, Settings.Secure.BACKUP_ENABLED, 2264 R.bool.def_backup_enabled); 2265 2266 loadStringSetting(stmt, Settings.Secure.BACKUP_TRANSPORT, 2267 R.string.def_backup_transport); 2268 } 2269 loadGlobalSettings(SQLiteDatabase db)2270 private void loadGlobalSettings(SQLiteDatabase db) { 2271 SQLiteStatement stmt = null; 2272 final Resources res = mContext.getResources(); 2273 try { 2274 stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)" 2275 + " VALUES(?,?);"); 2276 2277 // --- Previously in 'system' 2278 loadBooleanSetting(stmt, Settings.Global.AIRPLANE_MODE_ON, 2279 R.bool.def_airplane_mode_on); 2280 2281 loadBooleanSetting(stmt, Settings.Global.THEATER_MODE_ON, 2282 R.bool.def_theater_mode_on); 2283 2284 loadStringSetting(stmt, Settings.Global.AIRPLANE_MODE_RADIOS, 2285 R.string.def_airplane_mode_radios); 2286 2287 loadStringSetting(stmt, Global.SATELLITE_MODE_RADIOS, 2288 R.string.def_satellite_mode_radios); 2289 2290 loadIntegerSetting(stmt, Global.SATELLITE_MODE_ENABLED, 2291 R.integer.def_satellite_mode_enabled); 2292 2293 loadStringSetting(stmt, Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS, 2294 R.string.airplane_mode_toggleable_radios); 2295 2296 loadBooleanSetting(stmt, Settings.Global.ASSISTED_GPS_ENABLED, 2297 R.bool.assisted_gps_enabled); 2298 2299 loadBooleanSetting(stmt, Settings.Global.AUTO_TIME, 2300 R.bool.def_auto_time); // Sync time to NITZ 2301 2302 loadBooleanSetting(stmt, Settings.Global.AUTO_TIME_ZONE, 2303 R.bool.def_auto_time_zone); // Sync timezone to NITZ 2304 2305 loadSetting(stmt, Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 2306 res.getBoolean(R.bool.def_stay_on_while_plugged_in) ? 1 : 0); 2307 2308 loadIntegerSetting(stmt, Settings.Global.WIFI_SLEEP_POLICY, 2309 R.integer.def_wifi_sleep_policy); 2310 2311 loadSetting(stmt, Settings.Global.MODE_RINGER, 2312 AudioManager.RINGER_MODE_NORMAL); 2313 2314 loadDefaultAnimationSettings(stmt); 2315 2316 // --- Previously in 'secure' 2317 loadBooleanSetting(stmt, Settings.Global.WIFI_ON, 2318 R.bool.def_wifi_on); 2319 2320 loadBooleanSetting(stmt, Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 2321 R.bool.def_networks_available_notification_on); 2322 2323 loadBooleanSetting(stmt, Settings.Global.BLUETOOTH_ON, 2324 R.bool.def_bluetooth_on); 2325 2326 loadIntegerSetting(stmt, Settings.Global.CELL_ON, 2327 R.integer.def_cell_on); 2328 2329 // Enable or disable Cell Broadcast SMS 2330 loadSetting(stmt, Settings.Global.CDMA_CELL_BROADCAST_SMS, 2331 RILConstants.CDMA_CELL_BROADCAST_SMS_DISABLED); 2332 2333 // Data roaming default, based on build 2334 loadSetting(stmt, Settings.Global.DATA_ROAMING, 2335 TelephonyProperties.data_roaming().orElse(false) ? 1 : 0); 2336 2337 loadBooleanSetting(stmt, Settings.Global.DEVICE_PROVISIONED, 2338 R.bool.def_device_provisioned); 2339 2340 final int maxBytes = res.getInteger( 2341 R.integer.def_download_manager_max_bytes_over_mobile); 2342 if (maxBytes > 0) { 2343 loadSetting(stmt, Settings.Global.DOWNLOAD_MAX_BYTES_OVER_MOBILE, 2344 Integer.toString(maxBytes)); 2345 } 2346 2347 final int recommendedMaxBytes = res.getInteger( 2348 R.integer.def_download_manager_recommended_max_bytes_over_mobile); 2349 if (recommendedMaxBytes > 0) { 2350 loadSetting(stmt, Settings.Global.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE, 2351 Integer.toString(recommendedMaxBytes)); 2352 } 2353 2354 // Mobile Data default, based on build 2355 loadSetting(stmt, Settings.Global.MOBILE_DATA, 2356 TelephonyProperties.mobile_data().orElse(true) ? 1 : 0); 2357 2358 loadBooleanSetting(stmt, Settings.Global.NETSTATS_ENABLED, 2359 R.bool.def_netstats_enabled); 2360 2361 loadBooleanSetting(stmt, Settings.Global.USB_MASS_STORAGE_ENABLED, 2362 R.bool.def_usb_mass_storage_enabled); 2363 2364 loadIntegerSetting(stmt, Settings.Global.WIFI_MAX_DHCP_RETRY_COUNT, 2365 R.integer.def_max_dhcp_retries); 2366 2367 loadBooleanSetting(stmt, Settings.Global.WIFI_DISPLAY_ON, 2368 R.bool.def_wifi_display_on); 2369 2370 loadStringSetting(stmt, Settings.Global.LOCK_SOUND, 2371 R.string.def_lock_sound); 2372 loadStringSetting(stmt, Settings.Global.UNLOCK_SOUND, 2373 R.string.def_unlock_sound); 2374 loadStringSetting(stmt, Settings.Global.TRUSTED_SOUND, 2375 R.string.def_trusted_sound); 2376 loadIntegerSetting(stmt, Settings.Global.POWER_SOUNDS_ENABLED, 2377 R.integer.def_power_sounds_enabled); 2378 loadStringSetting(stmt, Settings.Global.LOW_BATTERY_SOUND, 2379 R.string.def_low_battery_sound); 2380 loadIntegerSetting(stmt, Settings.Global.DOCK_SOUNDS_ENABLED, 2381 R.integer.def_dock_sounds_enabled); 2382 loadIntegerSetting(stmt, Settings.Global.DOCK_SOUNDS_ENABLED_WHEN_ACCESSIBILITY, 2383 R.integer.def_dock_sounds_enabled_when_accessibility); 2384 loadStringSetting(stmt, Settings.Global.DESK_DOCK_SOUND, 2385 R.string.def_desk_dock_sound); 2386 loadStringSetting(stmt, Settings.Global.DESK_UNDOCK_SOUND, 2387 R.string.def_desk_undock_sound); 2388 loadStringSetting(stmt, Settings.Global.CAR_DOCK_SOUND, 2389 R.string.def_car_dock_sound); 2390 loadStringSetting(stmt, Settings.Global.CAR_UNDOCK_SOUND, 2391 R.string.def_car_undock_sound); 2392 2393 loadIntegerSetting(stmt, Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, 2394 R.integer.def_dock_audio_media_enabled); 2395 2396 loadSetting(stmt, Settings.Global.SET_INSTALL_LOCATION, 0); 2397 loadSetting(stmt, Settings.Global.DEFAULT_INSTALL_LOCATION, 2398 InstallLocationUtils.APP_INSTALL_AUTO); 2399 2400 // Set default cdma emergency tone 2401 loadSetting(stmt, Settings.Global.EMERGENCY_TONE, 0); 2402 2403 // Set default cdma call auto retry 2404 loadSetting(stmt, Settings.Global.CALL_AUTO_RETRY, 0); 2405 2406 // Set the preferred network mode to target desired value or Default 2407 // value defined in system property 2408 StringBuilder val = new StringBuilder(); 2409 List<Integer> defaultNetworks = TelephonyProperties.default_network(); 2410 int phoneCount = 1; 2411 TelephonyManager telephonyManager = getTelephonyManager(); 2412 if (telephonyManager != null) { 2413 phoneCount = telephonyManager.getSupportedModemCount(); 2414 } 2415 for (int phoneId = 0; phoneId < phoneCount; phoneId++) { 2416 int mode = defaultNetworks.size() <= phoneId 2417 || defaultNetworks.get(phoneId) == null 2418 ? TelephonyManager.DEFAULT_PREFERRED_NETWORK_MODE : defaultNetworks.get(phoneId); 2419 if (phoneId > 0) val.append(','); 2420 val.append(mode); 2421 } 2422 loadSetting(stmt, Settings.Global.PREFERRED_NETWORK_MODE, val.toString()); 2423 2424 // Set the preferred cdma subscription source to target desired value or default 2425 // value defined in Phone 2426 int type = SystemProperties.getInt("ro.telephony.default_cdma_sub", 2427 Phone.PREFERRED_CDMA_SUBSCRIPTION); 2428 loadSetting(stmt, Settings.Global.CDMA_SUBSCRIPTION_MODE, type); 2429 2430 loadIntegerSetting(stmt, Settings.Global.LOW_BATTERY_SOUND_TIMEOUT, 2431 R.integer.def_low_battery_sound_timeout); 2432 2433 loadIntegerSetting(stmt, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 2434 R.integer.def_wifi_scan_always_available); 2435 2436 loadIntegerSetting(stmt, Global.HEADS_UP_NOTIFICATIONS_ENABLED, 2437 R.integer.def_heads_up_enabled); 2438 2439 loadSetting(stmt, Settings.Global.DEVICE_NAME, getDefaultDeviceName()); 2440 2441 // Set default lid/cover behaviour according to legacy device config 2442 final int defaultLidBehavior; 2443 if (res.getBoolean(com.android.internal.R.bool.config_lidControlsSleep)) { 2444 // WindowManagerFuncs.LID_BEHAVIOR_SLEEP 2445 defaultLidBehavior = 1; 2446 } else if (res.getBoolean(com.android.internal.R.bool.config_lidControlsScreenLock)) { 2447 // WindowManagerFuncs.LID_BEHAVIOR_LOCK 2448 defaultLidBehavior = 2; 2449 } else { 2450 // WindowManagerFuncs.LID_BEHAVIOR_NONE 2451 defaultLidBehavior = 0; 2452 } 2453 loadSetting(stmt, Settings.Global.LID_BEHAVIOR, defaultLidBehavior); 2454 2455 /* 2456 * IMPORTANT: Do not add any more upgrade steps here as the global, 2457 * secure, and system settings are no longer stored in a database 2458 * but are kept in memory and persisted to XML. 2459 * 2460 * See: SettingsProvider.UpgradeController#onUpgradeLocked 2461 */ 2462 } finally { 2463 if (stmt != null) stmt.close(); 2464 } 2465 } 2466 loadSetting(SQLiteStatement stmt, String key, Object value)2467 private void loadSetting(SQLiteStatement stmt, String key, Object value) { 2468 stmt.bindString(1, key); 2469 stmt.bindString(2, value.toString()); 2470 stmt.execute(); 2471 } 2472 loadStringSetting(SQLiteStatement stmt, String key, int resid)2473 private void loadStringSetting(SQLiteStatement stmt, String key, int resid) { 2474 loadSetting(stmt, key, mContext.getResources().getString(resid)); 2475 } 2476 loadBooleanSetting(SQLiteStatement stmt, String key, int resid)2477 private void loadBooleanSetting(SQLiteStatement stmt, String key, int resid) { 2478 loadSetting(stmt, key, 2479 mContext.getResources().getBoolean(resid) ? "1" : "0"); 2480 } 2481 loadIntegerSetting(SQLiteStatement stmt, String key, int resid)2482 private void loadIntegerSetting(SQLiteStatement stmt, String key, int resid) { 2483 loadSetting(stmt, key, 2484 Integer.toString(mContext.getResources().getInteger(resid))); 2485 } 2486 loadFractionSetting(SQLiteStatement stmt, String key, int resid, int base)2487 private void loadFractionSetting(SQLiteStatement stmt, String key, int resid, int base) { 2488 loadSetting(stmt, key, 2489 Float.toString(mContext.getResources().getFraction(resid, base, base))); 2490 } 2491 getIntValueFromSystem(SQLiteDatabase db, String name, int defaultValue)2492 private int getIntValueFromSystem(SQLiteDatabase db, String name, int defaultValue) { 2493 return getIntValueFromTable(db, TABLE_SYSTEM, name, defaultValue); 2494 } 2495 getIntValueFromTable(SQLiteDatabase db, String table, String name, int defaultValue)2496 private int getIntValueFromTable(SQLiteDatabase db, String table, String name, 2497 int defaultValue) { 2498 String value = getStringValueFromTable(db, table, name, null); 2499 return (value != null) ? Integer.parseInt(value) : defaultValue; 2500 } 2501 getStringValueFromTable(SQLiteDatabase db, String table, String name, String defaultValue)2502 private String getStringValueFromTable(SQLiteDatabase db, String table, String name, 2503 String defaultValue) { 2504 Cursor c = null; 2505 try { 2506 c = db.query(table, new String[] { Settings.System.VALUE }, "name='" + name + "'", 2507 null, null, null, null); 2508 if (c != null && c.moveToFirst()) { 2509 String val = c.getString(0); 2510 return val == null ? defaultValue : val; 2511 } 2512 } finally { 2513 if (c != null) c.close(); 2514 } 2515 return defaultValue; 2516 } 2517 getOldDefaultDeviceName()2518 private String getOldDefaultDeviceName() { 2519 return mContext.getResources().getString(R.string.def_device_name, 2520 Build.MANUFACTURER, Build.MODEL); 2521 } 2522 getDefaultDeviceName()2523 private String getDefaultDeviceName() { 2524 return mContext.getResources().getString(R.string.def_device_name_simple, Build.MODEL); 2525 } 2526 getTelephonyManager()2527 private TelephonyManager getTelephonyManager() { 2528 return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); 2529 } 2530 } 2531