DatabaseHelper.java revision ad450be78bb99a965b6aeb7cec04f865da59f052
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.providers.settings; 18 19import com.android.internal.content.PackageHelper; 20import com.android.internal.telephony.RILConstants; 21import com.android.internal.util.XmlUtils; 22import com.android.internal.widget.LockPatternUtils; 23import com.android.internal.widget.LockPatternView; 24 25import org.xmlpull.v1.XmlPullParser; 26import org.xmlpull.v1.XmlPullParserException; 27 28import android.content.ComponentName; 29import android.content.ContentValues; 30import android.content.Context; 31import android.content.Intent; 32import android.content.pm.ActivityInfo; 33import android.content.pm.PackageManager; 34import android.content.res.XmlResourceParser; 35import android.database.Cursor; 36import android.database.sqlite.SQLiteDatabase; 37import android.database.sqlite.SQLiteOpenHelper; 38import android.database.sqlite.SQLiteStatement; 39import android.media.AudioManager; 40import android.media.AudioService; 41import android.net.ConnectivityManager; 42import android.os.SystemProperties; 43import android.provider.Settings; 44import android.provider.Settings.Secure; 45import android.text.TextUtils; 46import android.util.Log; 47 48import java.io.IOException; 49import java.util.HashSet; 50import java.util.List; 51 52/** 53 * Database helper class for {@link SettingsProvider}. 54 * Mostly just has a bit {@link #onCreate} to initialize the database. 55 */ 56public class DatabaseHelper extends SQLiteOpenHelper { 57 private static final String TAG = "SettingsProvider"; 58 private static final String DATABASE_NAME = "settings.db"; 59 60 // Please, please please. If you update the database version, check to make sure the 61 // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion' 62 // is properly propagated through your change. Not doing so will result in a loss of user 63 // settings. 64 private static final int DATABASE_VERSION = 59; 65 66 private Context mContext; 67 68 private static final HashSet<String> mValidTables = new HashSet<String>(); 69 70 static { 71 mValidTables.add("system"); 72 mValidTables.add("secure"); 73 mValidTables.add("bluetooth_devices"); 74 mValidTables.add("bookmarks"); 75 76 // These are old. 77 mValidTables.add("favorites"); 78 mValidTables.add("gservices"); 79 mValidTables.add("old_favorites"); 80 } 81 82 public DatabaseHelper(Context context) { 83 super(context, DATABASE_NAME, null, DATABASE_VERSION); 84 mContext = context; 85 } 86 87 public static boolean isValidTable(String name) { 88 return mValidTables.contains(name); 89 } 90 91 private void createSecureTable(SQLiteDatabase db) { 92 db.execSQL("CREATE TABLE secure (" + 93 "_id INTEGER PRIMARY KEY AUTOINCREMENT," + 94 "name TEXT UNIQUE ON CONFLICT REPLACE," + 95 "value TEXT" + 96 ");"); 97 db.execSQL("CREATE INDEX secureIndex1 ON secure (name);"); 98 } 99 100 @Override 101 public void onCreate(SQLiteDatabase db) { 102 db.execSQL("CREATE TABLE system (" + 103 "_id INTEGER PRIMARY KEY AUTOINCREMENT," + 104 "name TEXT UNIQUE ON CONFLICT REPLACE," + 105 "value TEXT" + 106 ");"); 107 db.execSQL("CREATE INDEX systemIndex1 ON system (name);"); 108 109 createSecureTable(db); 110 111 db.execSQL("CREATE TABLE bluetooth_devices (" + 112 "_id INTEGER PRIMARY KEY," + 113 "name TEXT," + 114 "addr TEXT," + 115 "channel INTEGER," + 116 "type INTEGER" + 117 ");"); 118 119 db.execSQL("CREATE TABLE bookmarks (" + 120 "_id INTEGER PRIMARY KEY," + 121 "title TEXT," + 122 "folder TEXT," + 123 "intent TEXT," + 124 "shortcut INTEGER," + 125 "ordering INTEGER" + 126 ");"); 127 128 db.execSQL("CREATE INDEX bookmarksIndex1 ON bookmarks (folder);"); 129 db.execSQL("CREATE INDEX bookmarksIndex2 ON bookmarks (shortcut);"); 130 131 // Populate bookmarks table with initial bookmarks 132 loadBookmarks(db); 133 134 // Load initial volume levels into DB 135 loadVolumeLevels(db); 136 137 // Load inital settings values 138 loadSettings(db); 139 } 140 141 @Override 142 public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) { 143 Log.w(TAG, "Upgrading settings database from version " + oldVersion + " to " 144 + currentVersion); 145 146 int upgradeVersion = oldVersion; 147 148 // Pattern for upgrade blocks: 149 // 150 // if (upgradeVersion == [the DATABASE_VERSION you set] - 1) { 151 // .. your upgrade logic.. 152 // upgradeVersion = [the DATABASE_VERSION you set] 153 // } 154 155 if (upgradeVersion == 20) { 156 /* 157 * Version 21 is part of the volume control refresh. There is no 158 * longer a UI-visible for setting notification vibrate on/off (in 159 * our design), but the functionality still exists. Force the 160 * notification vibrate to on. 161 */ 162 loadVibrateSetting(db, true); 163 164 upgradeVersion = 21; 165 } 166 167 if (upgradeVersion < 22) { 168 upgradeVersion = 22; 169 // Upgrade the lock gesture storage location and format 170 upgradeLockPatternLocation(db); 171 } 172 173 if (upgradeVersion < 23) { 174 db.execSQL("UPDATE favorites SET iconResource=0 WHERE iconType=0"); 175 upgradeVersion = 23; 176 } 177 178 if (upgradeVersion == 23) { 179 db.beginTransaction(); 180 try { 181 db.execSQL("ALTER TABLE favorites ADD spanX INTEGER"); 182 db.execSQL("ALTER TABLE favorites ADD spanY INTEGER"); 183 // Shortcuts, applications, folders 184 db.execSQL("UPDATE favorites SET spanX=1, spanY=1 WHERE itemType<=0"); 185 // Photo frames, clocks 186 db.execSQL( 187 "UPDATE favorites SET spanX=2, spanY=2 WHERE itemType=1000 or itemType=1002"); 188 // Search boxes 189 db.execSQL("UPDATE favorites SET spanX=4, spanY=1 WHERE itemType=1001"); 190 db.setTransactionSuccessful(); 191 } finally { 192 db.endTransaction(); 193 } 194 upgradeVersion = 24; 195 } 196 197 if (upgradeVersion == 24) { 198 db.beginTransaction(); 199 try { 200 // The value of the constants for preferring wifi or preferring mobile have been 201 // swapped, so reload the default. 202 db.execSQL("DELETE FROM system WHERE name='network_preference'"); 203 db.execSQL("INSERT INTO system ('name', 'value') values ('network_preference', '" + 204 ConnectivityManager.DEFAULT_NETWORK_PREFERENCE + "')"); 205 db.setTransactionSuccessful(); 206 } finally { 207 db.endTransaction(); 208 } 209 upgradeVersion = 25; 210 } 211 212 if (upgradeVersion == 25) { 213 db.beginTransaction(); 214 try { 215 db.execSQL("ALTER TABLE favorites ADD uri TEXT"); 216 db.execSQL("ALTER TABLE favorites ADD displayMode INTEGER"); 217 db.setTransactionSuccessful(); 218 } finally { 219 db.endTransaction(); 220 } 221 upgradeVersion = 26; 222 } 223 224 if (upgradeVersion == 26) { 225 // This introduces the new secure settings table. 226 db.beginTransaction(); 227 try { 228 createSecureTable(db); 229 db.setTransactionSuccessful(); 230 } finally { 231 db.endTransaction(); 232 } 233 upgradeVersion = 27; 234 } 235 236 if (upgradeVersion == 27) { 237 String[] settingsToMove = { 238 Settings.Secure.ADB_ENABLED, 239 Settings.Secure.ANDROID_ID, 240 Settings.Secure.BLUETOOTH_ON, 241 Settings.Secure.DATA_ROAMING, 242 Settings.Secure.DEVICE_PROVISIONED, 243 Settings.Secure.HTTP_PROXY, 244 Settings.Secure.INSTALL_NON_MARKET_APPS, 245 Settings.Secure.LOCATION_PROVIDERS_ALLOWED, 246 Settings.Secure.LOGGING_ID, 247 Settings.Secure.NETWORK_PREFERENCE, 248 Settings.Secure.PARENTAL_CONTROL_ENABLED, 249 Settings.Secure.PARENTAL_CONTROL_LAST_UPDATE, 250 Settings.Secure.PARENTAL_CONTROL_REDIRECT_URL, 251 Settings.Secure.SETTINGS_CLASSNAME, 252 Settings.Secure.USB_MASS_STORAGE_ENABLED, 253 Settings.Secure.USE_GOOGLE_MAIL, 254 Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 255 Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY, 256 Settings.Secure.WIFI_NUM_OPEN_NETWORKS_KEPT, 257 Settings.Secure.WIFI_ON, 258 Settings.Secure.WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE, 259 Settings.Secure.WIFI_WATCHDOG_AP_COUNT, 260 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS, 261 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED, 262 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS, 263 Settings.Secure.WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT, 264 Settings.Secure.WIFI_WATCHDOG_MAX_AP_CHECKS, 265 Settings.Secure.WIFI_WATCHDOG_ON, 266 Settings.Secure.WIFI_WATCHDOG_PING_COUNT, 267 Settings.Secure.WIFI_WATCHDOG_PING_DELAY_MS, 268 Settings.Secure.WIFI_WATCHDOG_PING_TIMEOUT_MS, 269 }; 270 moveFromSystemToSecure(db, settingsToMove); 271 upgradeVersion = 28; 272 } 273 274 if (upgradeVersion == 28 || upgradeVersion == 29) { 275 // Note: The upgrade to 28 was flawed since it didn't delete the old 276 // setting first before inserting. Combining 28 and 29 with the 277 // fixed version. 278 279 // This upgrade adds the STREAM_NOTIFICATION type to the list of 280 // types affected by ringer modes (silent, vibrate, etc.) 281 db.beginTransaction(); 282 try { 283 db.execSQL("DELETE FROM system WHERE name='" 284 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'"); 285 int newValue = (1 << AudioManager.STREAM_RING) 286 | (1 << AudioManager.STREAM_NOTIFICATION) 287 | (1 << AudioManager.STREAM_SYSTEM); 288 db.execSQL("INSERT INTO system ('name', 'value') values ('" 289 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '" 290 + String.valueOf(newValue) + "')"); 291 db.setTransactionSuccessful(); 292 } finally { 293 db.endTransaction(); 294 } 295 296 upgradeVersion = 30; 297 } 298 299 if (upgradeVersion == 30) { 300 /* 301 * Upgrade 31 clears the title for all quick launch shortcuts so the 302 * activities' titles will be resolved at display time. Also, the 303 * folder is changed to '@quicklaunch'. 304 */ 305 db.beginTransaction(); 306 try { 307 db.execSQL("UPDATE bookmarks SET folder = '@quicklaunch'"); 308 db.execSQL("UPDATE bookmarks SET title = ''"); 309 db.setTransactionSuccessful(); 310 } finally { 311 db.endTransaction(); 312 } 313 upgradeVersion = 31; 314 } 315 316 if (upgradeVersion == 31) { 317 /* 318 * Animations are now managed in preferences, and may be 319 * enabled or disabled based on product resources. 320 */ 321 db.beginTransaction(); 322 SQLiteStatement stmt = null; 323 try { 324 db.execSQL("DELETE FROM system WHERE name='" 325 + Settings.System.WINDOW_ANIMATION_SCALE + "'"); 326 db.execSQL("DELETE FROM system WHERE name='" 327 + Settings.System.TRANSITION_ANIMATION_SCALE + "'"); 328 stmt = db.compileStatement("INSERT INTO system(name,value)" 329 + " VALUES(?,?);"); 330 loadDefaultAnimationSettings(stmt); 331 db.setTransactionSuccessful(); 332 } finally { 333 db.endTransaction(); 334 if (stmt != null) stmt.close(); 335 } 336 upgradeVersion = 32; 337 } 338 339 if (upgradeVersion == 32) { 340 // The Wi-Fi watchdog SSID list is now seeded with the value of 341 // the property ro.com.android.wifi-watchlist 342 String wifiWatchList = SystemProperties.get("ro.com.android.wifi-watchlist"); 343 if (!TextUtils.isEmpty(wifiWatchList)) { 344 db.beginTransaction(); 345 try { 346 db.execSQL("INSERT OR IGNORE INTO secure(name,value) values('" + 347 Settings.Secure.WIFI_WATCHDOG_WATCH_LIST + "','" + 348 wifiWatchList + "');"); 349 db.setTransactionSuccessful(); 350 } finally { 351 db.endTransaction(); 352 } 353 } 354 upgradeVersion = 33; 355 } 356 357 if (upgradeVersion == 33) { 358 // Set the default zoom controls to: tap-twice to bring up +/- 359 db.beginTransaction(); 360 try { 361 db.execSQL("INSERT INTO system(name,value) values('zoom','2');"); 362 db.setTransactionSuccessful(); 363 } finally { 364 db.endTransaction(); 365 } 366 upgradeVersion = 34; 367 } 368 369 if (upgradeVersion == 34) { 370 db.beginTransaction(); 371 SQLiteStatement stmt = null; 372 try { 373 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)" 374 + " VALUES(?,?);"); 375 loadSecure35Settings(stmt); 376 db.setTransactionSuccessful(); 377 } finally { 378 db.endTransaction(); 379 if (stmt != null) stmt.close(); 380 } 381 upgradeVersion = 35; 382 } 383 // due to a botched merge from donut to eclair, the initialization of ASSISTED_GPS_ENABLED 384 // was accidentally done out of order here. 385 // to fix this, ASSISTED_GPS_ENABLED is now initialized while upgrading from 38 to 39, 386 // and we intentionally do nothing from 35 to 36 now. 387 if (upgradeVersion == 35) { 388 upgradeVersion = 36; 389 } 390 391 if (upgradeVersion == 36) { 392 // This upgrade adds the STREAM_SYSTEM_ENFORCED type to the list of 393 // types affected by ringer modes (silent, vibrate, etc.) 394 db.beginTransaction(); 395 try { 396 db.execSQL("DELETE FROM system WHERE name='" 397 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'"); 398 int newValue = (1 << AudioManager.STREAM_RING) 399 | (1 << AudioManager.STREAM_NOTIFICATION) 400 | (1 << AudioManager.STREAM_SYSTEM) 401 | (1 << AudioManager.STREAM_SYSTEM_ENFORCED); 402 db.execSQL("INSERT INTO system ('name', 'value') values ('" 403 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '" 404 + String.valueOf(newValue) + "')"); 405 db.setTransactionSuccessful(); 406 } finally { 407 db.endTransaction(); 408 } 409 upgradeVersion = 37; 410 } 411 412 if (upgradeVersion == 37) { 413 db.beginTransaction(); 414 SQLiteStatement stmt = null; 415 try { 416 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)" 417 + " VALUES(?,?);"); 418 loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS, 419 R.string.airplane_mode_toggleable_radios); 420 db.setTransactionSuccessful(); 421 } finally { 422 db.endTransaction(); 423 if (stmt != null) stmt.close(); 424 } 425 upgradeVersion = 38; 426 } 427 428 if (upgradeVersion == 38) { 429 db.beginTransaction(); 430 try { 431 String value = 432 mContext.getResources().getBoolean(R.bool.assisted_gps_enabled) ? "1" : "0"; 433 db.execSQL("INSERT OR IGNORE INTO secure(name,value) values('" + 434 Settings.Secure.ASSISTED_GPS_ENABLED + "','" + value + "');"); 435 db.setTransactionSuccessful(); 436 } finally { 437 db.endTransaction(); 438 } 439 440 upgradeVersion = 39; 441 } 442 443 if (upgradeVersion == 39) { 444 db.beginTransaction(); 445 try { 446 String value = 447 mContext.getResources().getBoolean( 448 R.bool.def_screen_brightness_automatic_mode) ? "1" : "0"; 449 db.execSQL("INSERT OR IGNORE INTO system(name,value) values('" + 450 Settings.System.SCREEN_BRIGHTNESS_MODE + "','" + value + "');"); 451 db.setTransactionSuccessful(); 452 } finally { 453 db.endTransaction(); 454 } 455 456 upgradeVersion = 40; 457 } 458 459 if (upgradeVersion == 40) { 460 /* 461 * All animations are now turned on by default! 462 */ 463 db.beginTransaction(); 464 SQLiteStatement stmt = null; 465 try { 466 db.execSQL("DELETE FROM system WHERE name='" 467 + Settings.System.WINDOW_ANIMATION_SCALE + "'"); 468 db.execSQL("DELETE FROM system WHERE name='" 469 + Settings.System.TRANSITION_ANIMATION_SCALE + "'"); 470 stmt = db.compileStatement("INSERT INTO system(name,value)" 471 + " VALUES(?,?);"); 472 loadDefaultAnimationSettings(stmt); 473 db.setTransactionSuccessful(); 474 } finally { 475 db.endTransaction(); 476 if (stmt != null) stmt.close(); 477 } 478 upgradeVersion = 41; 479 } 480 481 if (upgradeVersion == 41) { 482 /* 483 * Initialize newly public haptic feedback setting 484 */ 485 db.beginTransaction(); 486 SQLiteStatement stmt = null; 487 try { 488 db.execSQL("DELETE FROM system WHERE name='" 489 + Settings.System.HAPTIC_FEEDBACK_ENABLED + "'"); 490 stmt = db.compileStatement("INSERT INTO system(name,value)" 491 + " VALUES(?,?);"); 492 loadDefaultHapticSettings(stmt); 493 db.setTransactionSuccessful(); 494 } finally { 495 db.endTransaction(); 496 if (stmt != null) stmt.close(); 497 } 498 upgradeVersion = 42; 499 } 500 501 if (upgradeVersion == 42) { 502 /* 503 * Initialize new notification pulse setting 504 */ 505 db.beginTransaction(); 506 SQLiteStatement stmt = null; 507 try { 508 stmt = db.compileStatement("INSERT INTO system(name,value)" 509 + " VALUES(?,?);"); 510 loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE, 511 R.bool.def_notification_pulse); 512 db.setTransactionSuccessful(); 513 } finally { 514 db.endTransaction(); 515 if (stmt != null) stmt.close(); 516 } 517 upgradeVersion = 43; 518 } 519 520 if (upgradeVersion == 43) { 521 /* 522 * This upgrade stores bluetooth volume separately from voice volume 523 */ 524 db.beginTransaction(); 525 SQLiteStatement stmt = null; 526 try { 527 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)" 528 + " VALUES(?,?);"); 529 loadSetting(stmt, Settings.System.VOLUME_BLUETOOTH_SCO, 530 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_BLUETOOTH_SCO]); 531 db.setTransactionSuccessful(); 532 } finally { 533 db.endTransaction(); 534 if (stmt != null) stmt.close(); 535 } 536 upgradeVersion = 44; 537 } 538 539 if (upgradeVersion == 44) { 540 /* 541 * Gservices was moved into vendor/google. 542 */ 543 db.execSQL("DROP TABLE IF EXISTS gservices"); 544 db.execSQL("DROP INDEX IF EXISTS gservicesIndex1"); 545 upgradeVersion = 45; 546 } 547 548 if (upgradeVersion == 45) { 549 /* 550 * New settings for MountService 551 */ 552 db.beginTransaction(); 553 try { 554 db.execSQL("INSERT INTO secure(name,value) values('" + 555 Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND + "','1');"); 556 db.execSQL("INSERT INTO secure(name,value) values('" + 557 Settings.Secure.MOUNT_UMS_AUTOSTART + "','0');"); 558 db.execSQL("INSERT INTO secure(name,value) values('" + 559 Settings.Secure.MOUNT_UMS_PROMPT + "','1');"); 560 db.execSQL("INSERT INTO secure(name,value) values('" + 561 Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED + "','1');"); 562 db.setTransactionSuccessful(); 563 } finally { 564 db.endTransaction(); 565 } 566 upgradeVersion = 46; 567 } 568 569 if (upgradeVersion == 46) { 570 /* 571 * The password mode constants have changed; reset back to no 572 * password. 573 */ 574 db.beginTransaction(); 575 try { 576 db.execSQL("DELETE FROM system WHERE name='lockscreen.password_type';"); 577 db.setTransactionSuccessful(); 578 } finally { 579 db.endTransaction(); 580 } 581 upgradeVersion = 47; 582 } 583 584 585 if (upgradeVersion == 47) { 586 /* 587 * The password mode constants have changed again; reset back to no 588 * password. 589 */ 590 db.beginTransaction(); 591 try { 592 db.execSQL("DELETE FROM system WHERE name='lockscreen.password_type';"); 593 db.setTransactionSuccessful(); 594 } finally { 595 db.endTransaction(); 596 } 597 upgradeVersion = 48; 598 } 599 600 if (upgradeVersion == 48) { 601 /* 602 * Default recognition service no longer initialized here, 603 * moved to RecognitionManagerService. 604 */ 605 upgradeVersion = 49; 606 } 607 608 if (upgradeVersion == 49) { 609 /* 610 * New settings for new user interface noises. 611 */ 612 db.beginTransaction(); 613 SQLiteStatement stmt = null; 614 try { 615 stmt = db.compileStatement("INSERT INTO system(name,value)" 616 + " VALUES(?,?);"); 617 loadUISoundEffectsSettings(stmt); 618 db.setTransactionSuccessful(); 619 } finally { 620 db.endTransaction(); 621 if (stmt != null) stmt.close(); 622 } 623 624 upgradeVersion = 50; 625 } 626 627 if (upgradeVersion == 50) { 628 /* 629 * Install location no longer initiated here. 630 */ 631 upgradeVersion = 51; 632 } 633 634 if (upgradeVersion == 51) { 635 /* Move the lockscreen related settings to Secure, including some private ones. */ 636 String[] settingsToMove = { 637 Secure.LOCK_PATTERN_ENABLED, 638 Secure.LOCK_PATTERN_VISIBLE, 639 Secure.LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED, 640 "lockscreen.password_type", 641 "lockscreen.lockoutattemptdeadline", 642 "lockscreen.patterneverchosen", 643 "lock_pattern_autolock", 644 "lockscreen.lockedoutpermanently", 645 "lockscreen.password_salt" 646 }; 647 moveFromSystemToSecure(db, settingsToMove); 648 upgradeVersion = 52; 649 } 650 651 if (upgradeVersion == 52) { 652 // new vibration/silent mode settings 653 db.beginTransaction(); 654 SQLiteStatement stmt = null; 655 try { 656 stmt = db.compileStatement("INSERT INTO system(name,value)" 657 + " VALUES(?,?);"); 658 loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT, 659 R.bool.def_vibrate_in_silent); 660 db.setTransactionSuccessful(); 661 } finally { 662 db.endTransaction(); 663 if (stmt != null) stmt.close(); 664 } 665 666 upgradeVersion = 53; 667 } 668 669 if (upgradeVersion == 53) { 670 /* 671 * New settings for set install location UI no longer initiated here. 672 */ 673 upgradeVersion = 54; 674 } 675 676 if (upgradeVersion == 54) { 677 /* 678 * Update the screen timeout value if set to never 679 */ 680 db.beginTransaction(); 681 try { 682 upgradeScreenTimeoutFromNever(db); 683 db.setTransactionSuccessful(); 684 } finally { 685 db.endTransaction(); 686 } 687 688 upgradeVersion = 55; 689 } 690 691 if (upgradeVersion == 55) { 692 /* Move the install location settings. */ 693 String[] settingsToMove = { 694 Secure.SET_INSTALL_LOCATION, 695 Secure.DEFAULT_INSTALL_LOCATION 696 }; 697 moveFromSystemToSecure(db, settingsToMove); 698 db.beginTransaction(); 699 SQLiteStatement stmt = null; 700 try { 701 stmt = db.compileStatement("INSERT INTO system(name,value)" 702 + " VALUES(?,?);"); 703 loadSetting(stmt, Secure.SET_INSTALL_LOCATION, 0); 704 loadSetting(stmt, Secure.DEFAULT_INSTALL_LOCATION, 705 PackageHelper.APP_INSTALL_AUTO); 706 db.setTransactionSuccessful(); 707 } finally { 708 db.endTransaction(); 709 if (stmt != null) stmt.close(); 710 } 711 upgradeVersion = 56; 712 } 713 714 if (upgradeVersion == 56) { 715 /* 716 * Add Bluetooth to list of toggleable radios in airplane mode 717 */ 718 db.beginTransaction(); 719 SQLiteStatement stmt = null; 720 try { 721 db.execSQL("DELETE FROM system WHERE name='" 722 + Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS + "'"); 723 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)" 724 + " VALUES(?,?);"); 725 loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS, 726 R.string.airplane_mode_toggleable_radios); 727 db.setTransactionSuccessful(); 728 } finally { 729 db.endTransaction(); 730 if (stmt != null) stmt.close(); 731 } 732 upgradeVersion = 57; 733 } 734 735 if (upgradeVersion == 57) { 736 /* 737 * New settings to: 738 * 1. Enable injection of accessibility scripts in WebViews. 739 * 2. Define the key bindings for traversing web content in WebViews. 740 */ 741 db.beginTransaction(); 742 SQLiteStatement stmt = null; 743 try { 744 stmt = db.compileStatement("INSERT INTO secure(name,value)" 745 + " VALUES(?,?);"); 746 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION, 747 R.bool.def_accessibility_script_injection); 748 stmt.close(); 749 stmt = db.compileStatement("INSERT INTO secure(name,value)" 750 + " VALUES(?,?);"); 751 loadStringSetting(stmt, Settings.Secure.ACCESSIBILITY_WEB_CONTENT_KEY_BINDINGS, 752 R.string.def_accessibility_web_content_key_bindings); 753 db.setTransactionSuccessful(); 754 } finally { 755 db.endTransaction(); 756 if (stmt != null) stmt.close(); 757 } 758 upgradeVersion = 58; 759 } 760 761 if (upgradeVersion == 58) { 762 /* Add default for new Auto Time Zone */ 763 db.beginTransaction(); 764 SQLiteStatement stmt = null; 765 try { 766 stmt = db.compileStatement("INSERT INTO secure(name,value)" 767 + " VALUES(?,?);"); 768 loadBooleanSetting(stmt, Settings.System.AUTO_TIME_ZONE, 769 R.bool.def_auto_time_zone); // Sync timezone to NITZ 770 db.setTransactionSuccessful(); 771 } finally { 772 db.endTransaction(); 773 if (stmt != null) stmt.close(); 774 } 775 upgradeVersion = 59; 776 } 777 778 // *** Remember to update DATABASE_VERSION above! 779 780 if (upgradeVersion != currentVersion) { 781 Log.w(TAG, "Got stuck trying to upgrade from version " + upgradeVersion 782 + ", must wipe the settings provider"); 783 db.execSQL("DROP TABLE IF EXISTS system"); 784 db.execSQL("DROP INDEX IF EXISTS systemIndex1"); 785 db.execSQL("DROP TABLE IF EXISTS secure"); 786 db.execSQL("DROP INDEX IF EXISTS secureIndex1"); 787 db.execSQL("DROP TABLE IF EXISTS gservices"); 788 db.execSQL("DROP INDEX IF EXISTS gservicesIndex1"); 789 db.execSQL("DROP TABLE IF EXISTS bluetooth_devices"); 790 db.execSQL("DROP TABLE IF EXISTS bookmarks"); 791 db.execSQL("DROP INDEX IF EXISTS bookmarksIndex1"); 792 db.execSQL("DROP INDEX IF EXISTS bookmarksIndex2"); 793 db.execSQL("DROP TABLE IF EXISTS favorites"); 794 onCreate(db); 795 796 // Added for diagnosing settings.db wipes after the fact 797 String wipeReason = oldVersion + "/" + upgradeVersion + "/" + currentVersion; 798 db.execSQL("INSERT INTO secure(name,value) values('" + 799 "wiped_db_reason" + "','" + wipeReason + "');"); 800 } 801 } 802 803 private void moveFromSystemToSecure(SQLiteDatabase db, String [] settingsToMove) { 804 // Copy settings values from 'system' to 'secure' and delete them from 'system' 805 SQLiteStatement insertStmt = null; 806 SQLiteStatement deleteStmt = null; 807 808 db.beginTransaction(); 809 try { 810 insertStmt = 811 db.compileStatement("INSERT INTO secure (name,value) SELECT name,value FROM " 812 + "system WHERE name=?"); 813 deleteStmt = db.compileStatement("DELETE FROM system WHERE name=?"); 814 815 816 for (String setting : settingsToMove) { 817 insertStmt.bindString(1, setting); 818 insertStmt.execute(); 819 820 deleteStmt.bindString(1, setting); 821 deleteStmt.execute(); 822 } 823 db.setTransactionSuccessful(); 824 } finally { 825 db.endTransaction(); 826 if (insertStmt != null) { 827 insertStmt.close(); 828 } 829 if (deleteStmt != null) { 830 deleteStmt.close(); 831 } 832 } 833 } 834 835 private void upgradeLockPatternLocation(SQLiteDatabase db) { 836 Cursor c = db.query("system", new String[] {"_id", "value"}, "name='lock_pattern'", 837 null, null, null, null); 838 if (c.getCount() > 0) { 839 c.moveToFirst(); 840 String lockPattern = c.getString(1); 841 if (!TextUtils.isEmpty(lockPattern)) { 842 // Convert lock pattern 843 try { 844 LockPatternUtils lpu = new LockPatternUtils(mContext); 845 List<LockPatternView.Cell> cellPattern = 846 LockPatternUtils.stringToPattern(lockPattern); 847 lpu.saveLockPattern(cellPattern); 848 } catch (IllegalArgumentException e) { 849 // Don't want corrupted lock pattern to hang the reboot process 850 } 851 } 852 c.close(); 853 db.delete("system", "name='lock_pattern'", null); 854 } else { 855 c.close(); 856 } 857 } 858 859 private void upgradeScreenTimeoutFromNever(SQLiteDatabase db) { 860 // See if the timeout is -1 (for "Never"). 861 Cursor c = db.query("system", new String[] { "_id", "value" }, "name=? AND value=?", 862 new String[] { Settings.System.SCREEN_OFF_TIMEOUT, "-1" }, 863 null, null, null); 864 865 SQLiteStatement stmt = null; 866 if (c.getCount() > 0) { 867 c.close(); 868 try { 869 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)" 870 + " VALUES(?,?);"); 871 872 // Set the timeout to 30 minutes in milliseconds 873 loadSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT, 874 Integer.toString(30 * 60 * 1000)); 875 } finally { 876 if (stmt != null) stmt.close(); 877 } 878 } else { 879 c.close(); 880 } 881 } 882 883 /** 884 * Loads the default set of bookmarked shortcuts from an xml file. 885 * 886 * @param db The database to write the values into 887 * @param startingIndex The zero-based position at which bookmarks in this file should begin 888 */ 889 private int loadBookmarks(SQLiteDatabase db, int startingIndex) { 890 Intent intent = new Intent(Intent.ACTION_MAIN, null); 891 intent.addCategory(Intent.CATEGORY_LAUNCHER); 892 ContentValues values = new ContentValues(); 893 894 PackageManager packageManager = mContext.getPackageManager(); 895 int i = startingIndex; 896 897 try { 898 XmlResourceParser parser = mContext.getResources().getXml(R.xml.bookmarks); 899 XmlUtils.beginDocument(parser, "bookmarks"); 900 901 final int depth = parser.getDepth(); 902 int type; 903 904 while (((type = parser.next()) != XmlPullParser.END_TAG || 905 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { 906 907 if (type != XmlPullParser.START_TAG) { 908 continue; 909 } 910 911 String name = parser.getName(); 912 if (!"bookmark".equals(name)) { 913 break; 914 } 915 916 String pkg = parser.getAttributeValue(null, "package"); 917 String cls = parser.getAttributeValue(null, "class"); 918 String shortcutStr = parser.getAttributeValue(null, "shortcut"); 919 920 int shortcutValue = shortcutStr.charAt(0); 921 if (TextUtils.isEmpty(shortcutStr)) { 922 Log.w(TAG, "Unable to get shortcut for: " + pkg + "/" + cls); 923 } 924 925 ActivityInfo info = null; 926 ComponentName cn = new ComponentName(pkg, cls); 927 try { 928 info = packageManager.getActivityInfo(cn, 0); 929 } catch (PackageManager.NameNotFoundException e) { 930 String[] packages = packageManager.canonicalToCurrentPackageNames( 931 new String[] { pkg }); 932 cn = new ComponentName(packages[0], cls); 933 try { 934 info = packageManager.getActivityInfo(cn, 0); 935 } catch (PackageManager.NameNotFoundException e1) { 936 Log.w(TAG, "Unable to add bookmark: " + pkg + "/" + cls, e); 937 } 938 } 939 940 if (info != null) { 941 intent.setComponent(cn); 942 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 943 values.put(Settings.Bookmarks.INTENT, intent.toUri(0)); 944 values.put(Settings.Bookmarks.TITLE, 945 info.loadLabel(packageManager).toString()); 946 values.put(Settings.Bookmarks.SHORTCUT, shortcutValue); 947 db.insert("bookmarks", null, values); 948 i++; 949 } 950 } 951 } catch (XmlPullParserException e) { 952 Log.w(TAG, "Got execption parsing bookmarks.", e); 953 } catch (IOException e) { 954 Log.w(TAG, "Got execption parsing bookmarks.", e); 955 } 956 957 return i; 958 } 959 960 /** 961 * Loads the default set of bookmark packages. 962 * 963 * @param db The database to write the values into 964 */ 965 private void loadBookmarks(SQLiteDatabase db) { 966 loadBookmarks(db, 0); 967 } 968 969 /** 970 * Loads the default volume levels. It is actually inserting the index of 971 * the volume array for each of the volume controls. 972 * 973 * @param db the database to insert the volume levels into 974 */ 975 private void loadVolumeLevels(SQLiteDatabase db) { 976 SQLiteStatement stmt = null; 977 try { 978 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)" 979 + " VALUES(?,?);"); 980 981 loadSetting(stmt, Settings.System.VOLUME_MUSIC, 982 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_MUSIC]); 983 loadSetting(stmt, Settings.System.VOLUME_RING, 984 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_RING]); 985 loadSetting(stmt, Settings.System.VOLUME_SYSTEM, 986 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_SYSTEM]); 987 loadSetting( 988 stmt, 989 Settings.System.VOLUME_VOICE, 990 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_VOICE_CALL]); 991 loadSetting(stmt, Settings.System.VOLUME_ALARM, 992 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_ALARM]); 993 loadSetting( 994 stmt, 995 Settings.System.VOLUME_NOTIFICATION, 996 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_NOTIFICATION]); 997 loadSetting( 998 stmt, 999 Settings.System.VOLUME_BLUETOOTH_SCO, 1000 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_BLUETOOTH_SCO]); 1001 1002 loadSetting(stmt, Settings.System.MODE_RINGER, 1003 AudioManager.RINGER_MODE_NORMAL); 1004 1005 loadVibrateSetting(db, false); 1006 1007 // By default, only the ring/notification and system streams are affected 1008 loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED, 1009 (1 << AudioManager.STREAM_RING) | (1 << AudioManager.STREAM_NOTIFICATION) | 1010 (1 << AudioManager.STREAM_SYSTEM) | (1 << AudioManager.STREAM_SYSTEM_ENFORCED)); 1011 1012 loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED, 1013 ((1 << AudioManager.STREAM_MUSIC) | 1014 (1 << AudioManager.STREAM_RING) | 1015 (1 << AudioManager.STREAM_NOTIFICATION) | 1016 (1 << AudioManager.STREAM_SYSTEM))); 1017 } finally { 1018 if (stmt != null) stmt.close(); 1019 } 1020 } 1021 1022 private void loadVibrateSetting(SQLiteDatabase db, boolean deleteOld) { 1023 if (deleteOld) { 1024 db.execSQL("DELETE FROM system WHERE name='" + Settings.System.VIBRATE_ON + "'"); 1025 } 1026 1027 SQLiteStatement stmt = null; 1028 try { 1029 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)" 1030 + " VALUES(?,?);"); 1031 1032 // Vibrate off by default for ringer, on for notification 1033 int vibrate = 0; 1034 vibrate = AudioService.getValueForVibrateSetting(vibrate, 1035 AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON); 1036 vibrate |= AudioService.getValueForVibrateSetting(vibrate, 1037 AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF); 1038 loadSetting(stmt, Settings.System.VIBRATE_ON, vibrate); 1039 } finally { 1040 if (stmt != null) stmt.close(); 1041 } 1042 } 1043 1044 private void loadSettings(SQLiteDatabase db) { 1045 loadSystemSettings(db); 1046 loadSecureSettings(db); 1047 } 1048 1049 private void loadSystemSettings(SQLiteDatabase db) { 1050 SQLiteStatement stmt = null; 1051 try { 1052 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)" 1053 + " VALUES(?,?);"); 1054 1055 loadBooleanSetting(stmt, Settings.System.DIM_SCREEN, 1056 R.bool.def_dim_screen); 1057 loadSetting(stmt, Settings.System.STAY_ON_WHILE_PLUGGED_IN, 1058 "1".equals(SystemProperties.get("ro.kernel.qemu")) ? 1 : 0); 1059 loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT, 1060 R.integer.def_screen_off_timeout); 1061 1062 // Set default cdma emergency tone 1063 loadSetting(stmt, Settings.System.EMERGENCY_TONE, 0); 1064 1065 // Set default cdma call auto retry 1066 loadSetting(stmt, Settings.System.CALL_AUTO_RETRY, 0); 1067 1068 // Set default cdma DTMF type 1069 loadSetting(stmt, Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, 0); 1070 1071 // Set default hearing aid 1072 loadSetting(stmt, Settings.System.HEARING_AID, 0); 1073 1074 // Set default tty mode 1075 loadSetting(stmt, Settings.System.TTY_MODE, 0); 1076 1077 loadBooleanSetting(stmt, Settings.System.AIRPLANE_MODE_ON, 1078 R.bool.def_airplane_mode_on); 1079 1080 loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_RADIOS, 1081 R.string.def_airplane_mode_radios); 1082 1083 loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS, 1084 R.string.airplane_mode_toggleable_radios); 1085 1086 loadBooleanSetting(stmt, Settings.System.AUTO_TIME, 1087 R.bool.def_auto_time); // Sync time to NITZ 1088 1089 loadBooleanSetting(stmt, Settings.System.AUTO_TIME_ZONE, 1090 R.bool.def_auto_time_zone); // Sync timezone to NITZ 1091 1092 loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS, 1093 R.integer.def_screen_brightness); 1094 1095 loadBooleanSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_MODE, 1096 R.bool.def_screen_brightness_automatic_mode); 1097 1098 loadDefaultAnimationSettings(stmt); 1099 1100 loadBooleanSetting(stmt, Settings.System.ACCELEROMETER_ROTATION, 1101 R.bool.def_accelerometer_rotation); 1102 1103 loadDefaultHapticSettings(stmt); 1104 1105 loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE, 1106 R.bool.def_notification_pulse); 1107 loadSetting(stmt, Settings.Secure.SET_INSTALL_LOCATION, 0); 1108 loadSetting(stmt, Settings.Secure.DEFAULT_INSTALL_LOCATION, 1109 PackageHelper.APP_INSTALL_AUTO); 1110 1111 loadUISoundEffectsSettings(stmt); 1112 1113 loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT, 1114 R.bool.def_vibrate_in_silent); 1115 1116 loadBooleanSetting(stmt, Settings.System.USE_PTP_INTERFACE, 1117 R.bool.def_use_ptp_interface); 1118 } finally { 1119 if (stmt != null) stmt.close(); 1120 } 1121 } 1122 1123 private void loadUISoundEffectsSettings(SQLiteStatement stmt) { 1124 loadIntegerSetting(stmt, Settings.System.POWER_SOUNDS_ENABLED, 1125 R.integer.def_power_sounds_enabled); 1126 loadStringSetting(stmt, Settings.System.LOW_BATTERY_SOUND, 1127 R.string.def_low_battery_sound); 1128 1129 loadIntegerSetting(stmt, Settings.System.DOCK_SOUNDS_ENABLED, 1130 R.integer.def_dock_sounds_enabled); 1131 loadStringSetting(stmt, Settings.System.DESK_DOCK_SOUND, 1132 R.string.def_desk_dock_sound); 1133 loadStringSetting(stmt, Settings.System.DESK_UNDOCK_SOUND, 1134 R.string.def_desk_undock_sound); 1135 loadStringSetting(stmt, Settings.System.CAR_DOCK_SOUND, 1136 R.string.def_car_dock_sound); 1137 loadStringSetting(stmt, Settings.System.CAR_UNDOCK_SOUND, 1138 R.string.def_car_undock_sound); 1139 1140 loadIntegerSetting(stmt, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1141 R.integer.def_lockscreen_sounds_enabled); 1142 loadStringSetting(stmt, Settings.System.LOCK_SOUND, 1143 R.string.def_lock_sound); 1144 loadStringSetting(stmt, Settings.System.UNLOCK_SOUND, 1145 R.string.def_unlock_sound); 1146 } 1147 1148 private void loadDefaultAnimationSettings(SQLiteStatement stmt) { 1149 loadFractionSetting(stmt, Settings.System.WINDOW_ANIMATION_SCALE, 1150 R.fraction.def_window_animation_scale, 1); 1151 loadFractionSetting(stmt, Settings.System.TRANSITION_ANIMATION_SCALE, 1152 R.fraction.def_window_transition_scale, 1); 1153 } 1154 1155 private void loadDefaultHapticSettings(SQLiteStatement stmt) { 1156 loadBooleanSetting(stmt, Settings.System.HAPTIC_FEEDBACK_ENABLED, 1157 R.bool.def_haptic_feedback); 1158 } 1159 1160 private void loadSecureSettings(SQLiteDatabase db) { 1161 SQLiteStatement stmt = null; 1162 try { 1163 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)" 1164 + " VALUES(?,?);"); 1165 1166 loadBooleanSetting(stmt, Settings.Secure.BLUETOOTH_ON, 1167 R.bool.def_bluetooth_on); 1168 1169 // Data roaming default, based on build 1170 loadSetting(stmt, Settings.Secure.DATA_ROAMING, 1171 "true".equalsIgnoreCase( 1172 SystemProperties.get("ro.com.android.dataroaming", 1173 "false")) ? 1 : 0); 1174 1175 loadBooleanSetting(stmt, Settings.Secure.INSTALL_NON_MARKET_APPS, 1176 R.bool.def_install_non_market_apps); 1177 1178 loadStringSetting(stmt, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, 1179 R.string.def_location_providers_allowed); 1180 1181 loadBooleanSetting(stmt, Settings.Secure.ASSISTED_GPS_ENABLED, 1182 R.bool.assisted_gps_enabled); 1183 1184 loadIntegerSetting(stmt, Settings.Secure.NETWORK_PREFERENCE, 1185 R.integer.def_network_preference); 1186 1187 loadBooleanSetting(stmt, Settings.Secure.USB_MASS_STORAGE_ENABLED, 1188 R.bool.def_usb_mass_storage_enabled); 1189 1190 loadBooleanSetting(stmt, Settings.Secure.WIFI_ON, 1191 R.bool.def_wifi_on); 1192 loadBooleanSetting(stmt, Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 1193 R.bool.def_networks_available_notification_on); 1194 1195 String wifiWatchList = SystemProperties.get("ro.com.android.wifi-watchlist"); 1196 if (!TextUtils.isEmpty(wifiWatchList)) { 1197 loadSetting(stmt, Settings.Secure.WIFI_WATCHDOG_WATCH_LIST, wifiWatchList); 1198 } 1199 1200 // Set the preferred network mode to 0 = Global, CDMA default 1201 int type = SystemProperties.getInt("ro.telephony.default_network", 1202 RILConstants.PREFERRED_NETWORK_MODE); 1203 loadSetting(stmt, Settings.Secure.PREFERRED_NETWORK_MODE, type); 1204 1205 // Enable or disable Cell Broadcast SMS 1206 loadSetting(stmt, Settings.Secure.CDMA_CELL_BROADCAST_SMS, 1207 RILConstants.CDMA_CELL_BROADCAST_SMS_DISABLED); 1208 1209 // Set the preferred cdma subscription to 0 = Subscription from RUIM, when available 1210 loadSetting(stmt, Settings.Secure.PREFERRED_CDMA_SUBSCRIPTION, 1211 RILConstants.PREFERRED_CDMA_SUBSCRIPTION); 1212 1213 // Don't do this. The SystemServer will initialize ADB_ENABLED from a 1214 // persistent system property instead. 1215 //loadSetting(stmt, Settings.Secure.ADB_ENABLED, 0); 1216 1217 // Allow mock locations default, based on build 1218 loadSetting(stmt, Settings.Secure.ALLOW_MOCK_LOCATION, 1219 "1".equals(SystemProperties.get("ro.allow.mock.location")) ? 1 : 0); 1220 1221 loadSecure35Settings(stmt); 1222 1223 loadBooleanSetting(stmt, Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND, 1224 R.bool.def_mount_play_notification_snd); 1225 1226 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_AUTOSTART, 1227 R.bool.def_mount_ums_autostart); 1228 1229 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_PROMPT, 1230 R.bool.def_mount_ums_prompt); 1231 1232 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED, 1233 R.bool.def_mount_ums_notify_enabled); 1234 1235 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION, 1236 R.bool.def_accessibility_script_injection); 1237 1238 loadStringSetting(stmt, Settings.Secure.ACCESSIBILITY_WEB_CONTENT_KEY_BINDINGS, 1239 R.string.def_accessibility_web_content_key_bindings); 1240 } finally { 1241 if (stmt != null) stmt.close(); 1242 } 1243 } 1244 1245 private void loadSecure35Settings(SQLiteStatement stmt) { 1246 loadBooleanSetting(stmt, Settings.Secure.BACKUP_ENABLED, 1247 R.bool.def_backup_enabled); 1248 1249 loadStringSetting(stmt, Settings.Secure.BACKUP_TRANSPORT, 1250 R.string.def_backup_transport); 1251 } 1252 1253 private void loadSetting(SQLiteStatement stmt, String key, Object value) { 1254 stmt.bindString(1, key); 1255 stmt.bindString(2, value.toString()); 1256 stmt.execute(); 1257 } 1258 1259 private void loadStringSetting(SQLiteStatement stmt, String key, int resid) { 1260 loadSetting(stmt, key, mContext.getResources().getString(resid)); 1261 } 1262 1263 private void loadBooleanSetting(SQLiteStatement stmt, String key, int resid) { 1264 loadSetting(stmt, key, 1265 mContext.getResources().getBoolean(resid) ? "1" : "0"); 1266 } 1267 1268 private void loadIntegerSetting(SQLiteStatement stmt, String key, int resid) { 1269 loadSetting(stmt, key, 1270 Integer.toString(mContext.getResources().getInteger(resid))); 1271 } 1272 1273 private void loadFractionSetting(SQLiteStatement stmt, String key, int resid, int base) { 1274 loadSetting(stmt, key, 1275 Float.toString(mContext.getResources().getFraction(resid, base, base))); 1276 } 1277} 1278