DatabaseHelper.java revision 074da8f9aa424b25d84f4e4eb762ca534ea96716
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 android.content.ComponentName;
20import android.content.ContentValues;
21import android.content.Context;
22import android.content.Intent;
23import android.content.pm.ActivityInfo;
24import android.content.pm.PackageManager;
25import android.database.Cursor;
26import android.database.sqlite.SQLiteDatabase;
27import android.database.sqlite.SQLiteOpenHelper;
28import android.database.sqlite.SQLiteStatement;
29import android.location.LocationManager;
30import android.media.AudioManager;
31import android.media.AudioService;
32import android.net.ConnectivityManager;
33import android.os.Environment;
34import android.os.SystemProperties;
35import android.provider.Settings;
36import android.text.TextUtils;
37import android.util.Config;
38import android.util.Log;
39import android.util.Xml;
40import com.android.internal.util.XmlUtils;
41
42import com.android.internal.widget.LockPatternUtils;
43import com.android.internal.widget.LockPatternView;
44
45import org.xmlpull.v1.XmlPullParser;
46import org.xmlpull.v1.XmlPullParserException;
47
48import java.io.File;
49import java.io.FileNotFoundException;
50import java.io.FileReader;
51import java.io.IOException;
52import java.util.List;
53
54/**
55 * Database helper class for {@link SettingsProvider}.
56 * Mostly just has a bit {@link #onCreate} to initialize the database.
57 */
58public class DatabaseHelper extends SQLiteOpenHelper {
59    /**
60     * Path to file containing default bookmarks, relative to ANDROID_ROOT.
61     */
62    private static final String DEFAULT_BOOKMARKS_PATH = "etc/bookmarks.xml";
63
64    private static final String TAG = "SettingsProvider";
65    private static final String DATABASE_NAME = "settings.db";
66    private static final int DATABASE_VERSION = 31;
67
68    private Context mContext;
69
70    public DatabaseHelper(Context context) {
71        super(context, DATABASE_NAME, null, DATABASE_VERSION);
72        mContext = context;
73    }
74
75    private void createSecureTable(SQLiteDatabase db) {
76        db.execSQL("CREATE TABLE secure (" +
77                "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
78                "name TEXT UNIQUE ON CONFLICT REPLACE," +
79                "value TEXT" +
80                ");");
81        db.execSQL("CREATE INDEX secureIndex1 ON secure (name);");
82    }
83
84    @Override
85    public void onCreate(SQLiteDatabase db) {
86        db.execSQL("CREATE TABLE system (" +
87                    "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
88                    "name TEXT UNIQUE ON CONFLICT REPLACE," +
89                    "value TEXT" +
90                    ");");
91        db.execSQL("CREATE INDEX systemIndex1 ON system (name);");
92
93        createSecureTable(db);
94
95        db.execSQL("CREATE TABLE gservices (" +
96                   "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
97                   "name TEXT UNIQUE ON CONFLICT REPLACE," +
98                   "value TEXT" +
99                   ");");
100        db.execSQL("CREATE INDEX gservicesIndex1 ON gservices (name);");
101
102        db.execSQL("CREATE TABLE bluetooth_devices (" +
103                    "_id INTEGER PRIMARY KEY," +
104                    "name TEXT," +
105                    "addr TEXT," +
106                    "channel INTEGER," +
107                    "type INTEGER" +
108                    ");");
109
110        db.execSQL("CREATE TABLE bookmarks (" +
111                    "_id INTEGER PRIMARY KEY," +
112                    "title TEXT," +
113                    "folder TEXT," +
114                    "intent TEXT," +
115                    "shortcut INTEGER," +
116                    "ordering INTEGER" +
117                    ");");
118
119        db.execSQL("CREATE INDEX bookmarksIndex1 ON bookmarks (folder);");
120        db.execSQL("CREATE INDEX bookmarksIndex2 ON bookmarks (shortcut);");
121
122        // Populate bookmarks table with initial bookmarks
123        loadBookmarks(db);
124
125        // Load initial volume levels into DB
126        loadVolumeLevels(db);
127
128        // Load inital settings values
129        loadSettings(db);
130    }
131
132    @Override
133    public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
134        Log.w(TAG, "Upgrading settings database from version " + oldVersion + " to "
135                + currentVersion);
136
137        int upgradeVersion = oldVersion;
138
139        // Pattern for upgrade blocks:
140        //
141        //    if (upgradeVersion == [the DATABASE_VERSION you set] - 1) {
142        //        .. your upgrade logic..
143        //        upgradeVersion = [the DATABASE_VERSION you set]
144        //    }
145
146        if (upgradeVersion == 20) {
147            /*
148             * Version 21 is part of the volume control refresh. There is no
149             * longer a UI-visible for setting notification vibrate on/off (in
150             * our design), but the functionality still exists. Force the
151             * notification vibrate to on.
152             */
153            loadVibrateSetting(db, true);
154            if (Config.LOGD) Log.d(TAG, "Reset system vibrate setting");
155
156            upgradeVersion = 21;
157        }
158
159        if (upgradeVersion < 22) {
160            upgradeVersion = 22;
161            // Upgrade the lock gesture storage location and format
162            upgradeLockPatternLocation(db);
163        }
164
165        if (upgradeVersion < 23) {
166            db.execSQL("UPDATE favorites SET iconResource=0 WHERE iconType=0");
167            upgradeVersion = 23;
168        }
169
170        if (upgradeVersion == 23) {
171            db.beginTransaction();
172            try {
173                db.execSQL("ALTER TABLE favorites ADD spanX INTEGER");
174                db.execSQL("ALTER TABLE favorites ADD spanY INTEGER");
175                // Shortcuts, applications, folders
176                db.execSQL("UPDATE favorites SET spanX=1, spanY=1 WHERE itemType<=0");
177                // Photo frames, clocks
178                db.execSQL("UPDATE favorites SET spanX=2, spanY=2 WHERE itemType=1000 or itemType=1002");
179                // Search boxes
180                db.execSQL("UPDATE favorites SET spanX=4, spanY=1 WHERE itemType=1001");
181                db.setTransactionSuccessful();
182            } finally {
183                db.endTransaction();
184            }
185            upgradeVersion = 24;
186        }
187
188        if (upgradeVersion == 24) {
189            db.beginTransaction();
190            try {
191                // The value of the constants for preferring wifi or preferring mobile have been
192                // swapped, so reload the default.
193                db.execSQL("DELETE FROM system WHERE name='network_preference'");
194                db.execSQL("INSERT INTO system ('name', 'value') values ('network_preference', '" +
195                        ConnectivityManager.DEFAULT_NETWORK_PREFERENCE + "')");
196                db.setTransactionSuccessful();
197            } finally {
198                db.endTransaction();
199            }
200            upgradeVersion = 25;
201        }
202
203        if (upgradeVersion == 25) {
204            db.beginTransaction();
205            try {
206                db.execSQL("ALTER TABLE favorites ADD uri TEXT");
207                db.execSQL("ALTER TABLE favorites ADD displayMode INTEGER");
208                db.setTransactionSuccessful();
209            } finally {
210                db.endTransaction();
211            }
212            upgradeVersion = 26;
213        }
214
215        if (upgradeVersion == 26) {
216            // This introduces the new secure settings table.
217            db.beginTransaction();
218            try {
219                createSecureTable(db);
220                db.setTransactionSuccessful();
221            } finally {
222                db.endTransaction();
223            }
224            upgradeVersion = 27;
225        }
226
227        if (upgradeVersion == 27) {
228            // Copy settings values from 'system' to 'secure' and delete them from 'system'
229            SQLiteStatement insertStmt = null;
230            SQLiteStatement deleteStmt = null;
231
232            db.beginTransaction();
233            try {
234                insertStmt =
235                    db.compileStatement("INSERT INTO secure (name,value) SELECT name,value FROM "
236                        + "system WHERE name=?");
237                deleteStmt = db.compileStatement("DELETE FROM system WHERE name=?");
238
239                String[] settingsToMove = {
240                    Settings.Secure.ADB_ENABLED,
241                    Settings.Secure.ANDROID_ID,
242                    Settings.Secure.BLUETOOTH_ON,
243                    Settings.Secure.DATA_ROAMING,
244                    Settings.Secure.DEVICE_PROVISIONED,
245                    Settings.Secure.HTTP_PROXY,
246                    Settings.Secure.INSTALL_NON_MARKET_APPS,
247                    Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
248                    Settings.Secure.LOGGING_ID,
249                    Settings.Secure.NETWORK_PREFERENCE,
250                    Settings.Secure.PARENTAL_CONTROL_ENABLED,
251                    Settings.Secure.PARENTAL_CONTROL_LAST_UPDATE,
252                    Settings.Secure.PARENTAL_CONTROL_REDIRECT_URL,
253                    Settings.Secure.SETTINGS_CLASSNAME,
254                    Settings.Secure.USB_MASS_STORAGE_ENABLED,
255                    Settings.Secure.USE_GOOGLE_MAIL,
256                    Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
257                    Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY,
258                    Settings.Secure.WIFI_NUM_OPEN_NETWORKS_KEPT,
259                    Settings.Secure.WIFI_ON,
260                    Settings.Secure.WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE,
261                    Settings.Secure.WIFI_WATCHDOG_AP_COUNT,
262                    Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS,
263                    Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED,
264                    Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS,
265                    Settings.Secure.WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT,
266                    Settings.Secure.WIFI_WATCHDOG_MAX_AP_CHECKS,
267                    Settings.Secure.WIFI_WATCHDOG_ON,
268                    Settings.Secure.WIFI_WATCHDOG_PING_COUNT,
269                    Settings.Secure.WIFI_WATCHDOG_PING_DELAY_MS,
270                    Settings.Secure.WIFI_WATCHDOG_PING_TIMEOUT_MS,
271                };
272
273                for (String setting : settingsToMove) {
274                    insertStmt.bindString(1, setting);
275                    insertStmt.execute();
276
277                    deleteStmt.bindString(1, setting);
278                    deleteStmt.execute();
279                }
280                db.setTransactionSuccessful();
281            } finally {
282                db.endTransaction();
283                if (insertStmt != null) {
284                    insertStmt.close();
285                }
286                if (deleteStmt != null) {
287                    deleteStmt.close();
288                }
289            }
290            upgradeVersion = 28;
291        }
292
293        if (upgradeVersion == 28 || upgradeVersion == 29) {
294            // Note: The upgrade to 28 was flawed since it didn't delete the old
295            // setting first before inserting. Combining 28 and 29 with the
296            // fixed version.
297
298            // This upgrade adds the STREAM_NOTIFICATION type to the list of
299            // types affected by ringer modes (silent, vibrate, etc.)
300            db.beginTransaction();
301            try {
302                db.execSQL("DELETE FROM system WHERE name='"
303                        + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
304                int newValue = (1 << AudioManager.STREAM_RING)
305                        | (1 << AudioManager.STREAM_NOTIFICATION)
306                        | (1 << AudioManager.STREAM_SYSTEM);
307                db.execSQL("INSERT INTO system ('name', 'value') values ('"
308                        + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
309                        + String.valueOf(newValue) + "')");
310                db.setTransactionSuccessful();
311            } finally {
312                db.endTransaction();
313            }
314
315            upgradeVersion = 30;
316        }
317
318        if (upgradeVersion == 30) {
319            /*
320             * Upgrade 31 clears the title for all quick launch shortcuts so the
321             * activities' titles will be resolved at display time. Also, the
322             * folder is changed to '@quicklaunch'.
323             */
324            db.beginTransaction();
325            try {
326                db.execSQL("UPDATE bookmarks SET folder = '@quicklaunch'");
327                db.execSQL("UPDATE bookmarks SET title = ''");
328                db.setTransactionSuccessful();
329            } finally {
330                db.endTransaction();
331            }
332            upgradeVersion = 31;
333        }
334
335        if (upgradeVersion != currentVersion) {
336            Log.w(TAG, "Got stuck trying to upgrade from version " + upgradeVersion
337                    + ", must wipe the settings provider");
338            db.execSQL("DROP TABLE IF EXISTS system");
339            db.execSQL("DROP INDEX IF EXISTS systemIndex1");
340            db.execSQL("DROP TABLE IF EXISTS secure");
341            db.execSQL("DROP INDEX IF EXISTS secureIndex1");
342            db.execSQL("DROP TABLE IF EXISTS gservices");
343            db.execSQL("DROP INDEX IF EXISTS gservicesIndex1");
344            db.execSQL("DROP TABLE IF EXISTS bluetooth_devices");
345            db.execSQL("DROP TABLE IF EXISTS bookmarks");
346            db.execSQL("DROP INDEX IF EXISTS bookmarksIndex1");
347            db.execSQL("DROP INDEX IF EXISTS bookmarksIndex2");
348            db.execSQL("DROP TABLE IF EXISTS favorites");
349            onCreate(db);
350        }
351    }
352
353    private void upgradeLockPatternLocation(SQLiteDatabase db) {
354        Cursor c = db.query("system", new String[] {"_id", "value"}, "name='lock_pattern'",
355                null, null, null, null);
356        if (c.getCount() > 0) {
357            c.moveToFirst();
358            String lockPattern = c.getString(1);
359            if (!TextUtils.isEmpty(lockPattern)) {
360                // Convert lock pattern
361                try {
362                    LockPatternUtils lpu = new LockPatternUtils(mContext.getContentResolver());
363                    List<LockPatternView.Cell> cellPattern =
364                            LockPatternUtils.stringToPattern(lockPattern);
365                    lpu.saveLockPattern(cellPattern);
366                } catch (IllegalArgumentException e) {
367                    // Don't want corrupted lock pattern to hang the reboot process
368                }
369            }
370            c.close();
371            db.delete("system", "name='lock_pattern'", null);
372        } else {
373            c.close();
374        }
375    }
376
377    /**
378     * Loads the default set of bookmarked shortcuts from an xml file.
379     *
380     * @param db The database to write the values into
381     * @param startingIndex The zero-based position at which bookmarks in this file should begin
382     * @param subPath The relative path from ANDROID_ROOT to the file to read
383     * @param quiet If true, do no complain if the file is missing
384     */
385    private int loadBookmarks(SQLiteDatabase db, int startingIndex, String subPath,
386            boolean quiet) {
387        FileReader bookmarksReader;
388
389        // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
390        final File favFile = new File(Environment.getRootDirectory(), subPath);
391        try {
392            bookmarksReader = new FileReader(favFile);
393        } catch (FileNotFoundException e) {
394            if (!quiet) {
395                Log.e(TAG, "Couldn't find or open bookmarks file " + favFile);
396            }
397            return 0;
398        }
399
400        Intent intent = new Intent(Intent.ACTION_MAIN, null);
401        intent.addCategory(Intent.CATEGORY_LAUNCHER);
402        ContentValues values = new ContentValues();
403
404        PackageManager packageManager = mContext.getPackageManager();
405        ActivityInfo info;
406        int i = startingIndex;
407        try {
408            XmlPullParser parser = Xml.newPullParser();
409            parser.setInput(bookmarksReader);
410
411            XmlUtils.beginDocument(parser, "bookmarks");
412
413            while (true) {
414                XmlUtils.nextElement(parser);
415
416                String name = parser.getName();
417                if (!"bookmark".equals(name)) {
418                    break;
419                }
420
421                String pkg = parser.getAttributeValue(null, "package");
422                String cls = parser.getAttributeValue(null, "class");
423                String shortcutStr = parser.getAttributeValue(null, "shortcut");
424                int shortcutValue = (int) shortcutStr.charAt(0);
425                if (TextUtils.isEmpty(shortcutStr)) {
426                    Log.w(TAG, "Unable to get shortcut for: " + pkg + "/" + cls);
427                }
428                try {
429                    ComponentName cn = new ComponentName(pkg, cls);
430                    info = packageManager.getActivityInfo(cn, 0);
431                    intent.setComponent(cn);
432                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
433                    values.put(Settings.Bookmarks.INTENT, intent.toURI());
434                    values.put(Settings.Bookmarks.TITLE,
435                            info.loadLabel(packageManager).toString());
436                    values.put(Settings.Bookmarks.SHORTCUT, shortcutValue);
437                    db.insert("bookmarks", null, values);
438                    i++;
439                } catch (PackageManager.NameNotFoundException e) {
440                    Log.w(TAG, "Unable to add bookmark: " + pkg + "/" + cls, e);
441                }
442            }
443        } catch (XmlPullParserException e) {
444            Log.w(TAG, "Got execption parsing bookmarks.", e);
445        } catch (IOException e) {
446            Log.w(TAG, "Got execption parsing bookmarks.", e);
447        }
448
449        return i;
450    }
451
452    /**
453     * Loads the default set of bookmark packages.
454     *
455     * @param db The database to write the values into
456     */
457    private void loadBookmarks(SQLiteDatabase db) {
458        loadBookmarks(db, 0, DEFAULT_BOOKMARKS_PATH, false);
459    }
460
461    /**
462     * Loads the default volume levels. It is actually inserting the index of
463     * the volume array for each of the volume controls.
464     *
465     * @param db the database to insert the volume levels into
466     */
467    private void loadVolumeLevels(SQLiteDatabase db) {
468        SQLiteStatement stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
469                + " VALUES(?,?);");
470
471        loadSetting(stmt, Settings.System.VOLUME_MUSIC,
472                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_MUSIC]);
473        loadSetting(stmt, Settings.System.VOLUME_RING,
474                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_RING]);
475        loadSetting(stmt, Settings.System.VOLUME_SYSTEM,
476                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_SYSTEM]);
477        loadSetting(
478                stmt,
479                Settings.System.VOLUME_VOICE,
480                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_VOICE_CALL]);
481        loadSetting(stmt, Settings.System.VOLUME_ALARM,
482                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_ALARM]);
483        loadSetting(
484                stmt,
485                Settings.System.VOLUME_NOTIFICATION,
486                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_NOTIFICATION]);
487        loadSetting(stmt, Settings.System.MODE_RINGER,
488                AudioManager.RINGER_MODE_NORMAL);
489
490        loadVibrateSetting(db, false);
491
492        // By default, only the ring/notification and system streams are affected
493        loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED,
494                (1 << AudioManager.STREAM_RING) | (1 << AudioManager.STREAM_NOTIFICATION) |
495                (1 << AudioManager.STREAM_SYSTEM));
496
497        loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED,
498                ((1 << AudioManager.STREAM_MUSIC) |
499                 (1 << AudioManager.STREAM_RING) |
500                 (1 << AudioManager.STREAM_NOTIFICATION) |
501                 (1 << AudioManager.STREAM_SYSTEM)));
502
503        stmt.close();
504    }
505
506    private void loadVibrateSetting(SQLiteDatabase db, boolean deleteOld) {
507        if (deleteOld) {
508            db.execSQL("DELETE FROM system WHERE name='" + Settings.System.VIBRATE_ON + "'");
509        }
510
511        SQLiteStatement stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
512                + " VALUES(?,?);");
513
514        // Vibrate off by default for ringer, on for notification
515        int vibrate = 0;
516        vibrate = AudioService.getValueForVibrateSetting(vibrate,
517                AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON);
518        vibrate = AudioService.getValueForVibrateSetting(vibrate,
519                AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
520        loadSetting(stmt, Settings.System.VIBRATE_ON, vibrate);
521    }
522
523    private void loadSettings(SQLiteDatabase db) {
524        loadSystemSettings(db);
525        loadSecureSettings(db);
526    }
527
528    private void loadSystemSettings(SQLiteDatabase db) {
529        SQLiteStatement stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
530                + " VALUES(?,?);");
531
532        loadSetting(stmt, Settings.System.DIM_SCREEN, 1);
533        loadSetting(stmt, Settings.System.STAY_ON_WHILE_PLUGGED_IN,
534                "1".equals(SystemProperties.get("ro.kernel.qemu")) ? 1 : 0);
535        loadSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT, 60000);
536        // Allow airplane mode to turn off cell radio
537        loadSetting(stmt, Settings.System.AIRPLANE_MODE_RADIOS,
538                Settings.System.RADIO_CELL + ","
539                + Settings.System.RADIO_BLUETOOTH + "," + Settings.System.RADIO_WIFI);
540
541        loadSetting(stmt, Settings.System.AIRPLANE_MODE_ON, 0);
542
543        loadSetting(stmt, Settings.System.AUTO_TIME, 1); // Sync time to NITZ
544
545        // Set default brightness to 40%
546        loadSetting(stmt, Settings.System.SCREEN_BRIGHTNESS,
547                (int) (android.os.Power.BRIGHTNESS_ON * 0.4f));
548
549        // Enable normal window animations (menus, toasts); disable
550        // activity transition animations.
551        loadSetting(stmt, Settings.System.WINDOW_ANIMATION_SCALE, "1");
552        loadSetting(stmt, Settings.System.TRANSITION_ANIMATION_SCALE, "1");
553
554        // Default date format based on build
555        loadSetting(stmt, Settings.System.DATE_FORMAT,
556                SystemProperties.get("ro.com.android.dateformat",
557                        "MM-dd-yyyy"));
558        stmt.close();
559    }
560
561    private void loadSecureSettings(SQLiteDatabase db) {
562        SQLiteStatement stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
563                + " VALUES(?,?);");
564
565        // Bluetooth off
566        loadSetting(stmt, Settings.Secure.BLUETOOTH_ON, 0);
567
568        // Data roaming default, based on build
569        loadSetting(stmt, Settings.Secure.DATA_ROAMING,
570                "true".equalsIgnoreCase(
571                        SystemProperties.get("ro.com.android.dataroaming",
572                                "false")) ? 1 : 0);
573
574        // Don't allow non-market apps to be installed
575        loadSetting(stmt, Settings.Secure.INSTALL_NON_MARKET_APPS, 0);
576
577        // Set the default location providers to network based (cell-id)
578        loadSetting(stmt, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
579                LocationManager.NETWORK_PROVIDER);
580
581        loadSetting(stmt, Settings.Secure.NETWORK_PREFERENCE,
582            ConnectivityManager.DEFAULT_NETWORK_PREFERENCE);
583
584        // USB mass storage on by default
585        loadSetting(stmt, Settings.Secure.USB_MASS_STORAGE_ENABLED, 1);
586
587        // WIFI on, notify about available networks
588        loadSetting(stmt, Settings.Secure.WIFI_ON, 0);
589        loadSetting(stmt, Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 1);
590
591        // Don't do this.  The SystemServer will initialize ADB_ENABLED from a
592        // persistent system property instead.
593        //loadSetting(stmt, Settings.Secure.ADB_ENABLED, 0);
594
595        stmt.close();
596    }
597
598    private void loadSetting(SQLiteStatement stmt, String key, Object value) {
599        stmt.bindString(1, key);
600        stmt.bindString(2, value.toString());
601        stmt.execute();
602    }
603}
604