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