blob: 6dd1175441565a4288b24d70da0d4e27e1be7586 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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.content.res.Resources;
26import android.database.Cursor;
27import android.database.sqlite.SQLiteDatabase;
28import android.database.sqlite.SQLiteOpenHelper;
29import android.database.sqlite.SQLiteStatement;
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;
Wink Saville767a6622009-04-02 01:37:02 -070041import com.android.internal.telephony.RILConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
43import com.android.internal.widget.LockPatternUtils;
44import com.android.internal.widget.LockPatternView;
45
46import org.xmlpull.v1.XmlPullParser;
47import org.xmlpull.v1.XmlPullParserException;
48
49import java.io.File;
50import java.io.FileNotFoundException;
51import java.io.FileReader;
52import java.io.IOException;
53import 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 */
59class DatabaseHelper extends SQLiteOpenHelper {
60 /**
61 * Path to file containing default bookmarks, relative to ANDROID_ROOT.
62 */
63 private static final String DEFAULT_BOOKMARKS_PATH = "etc/bookmarks.xml";
64
65 private static final String TAG = "SettingsProvider";
66 private static final String DATABASE_NAME = "settings.db";
Dianne Hackborncf098292009-07-01 19:55:20 -070067 private static final int DATABASE_VERSION = 35;
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -070068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 private Context mContext;
70
71 public DatabaseHelper(Context context) {
72 super(context, DATABASE_NAME, null, DATABASE_VERSION);
73 mContext = context;
74 }
75
76 private void createSecureTable(SQLiteDatabase db) {
77 db.execSQL("CREATE TABLE secure (" +
78 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
79 "name TEXT UNIQUE ON CONFLICT REPLACE," +
80 "value TEXT" +
81 ");");
82 db.execSQL("CREATE INDEX secureIndex1 ON secure (name);");
83 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -070084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 @Override
86 public void onCreate(SQLiteDatabase db) {
87 db.execSQL("CREATE TABLE system (" +
88 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
89 "name TEXT UNIQUE ON CONFLICT REPLACE," +
90 "value TEXT" +
91 ");");
92 db.execSQL("CREATE INDEX systemIndex1 ON system (name);");
93
94 createSecureTable(db);
95
96 db.execSQL("CREATE TABLE gservices (" +
97 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
98 "name TEXT UNIQUE ON CONFLICT REPLACE," +
99 "value TEXT" +
100 ");");
101 db.execSQL("CREATE INDEX gservicesIndex1 ON gservices (name);");
102
103 db.execSQL("CREATE TABLE bluetooth_devices (" +
104 "_id INTEGER PRIMARY KEY," +
105 "name TEXT," +
106 "addr TEXT," +
107 "channel INTEGER," +
108 "type INTEGER" +
109 ");");
110
111 db.execSQL("CREATE TABLE bookmarks (" +
112 "_id INTEGER PRIMARY KEY," +
113 "title TEXT," +
114 "folder TEXT," +
115 "intent TEXT," +
116 "shortcut INTEGER," +
117 "ordering INTEGER" +
118 ");");
119
120 db.execSQL("CREATE INDEX bookmarksIndex1 ON bookmarks (folder);");
121 db.execSQL("CREATE INDEX bookmarksIndex2 ON bookmarks (shortcut);");
122
123 // Populate bookmarks table with initial bookmarks
124 loadBookmarks(db);
125
126 // Load initial volume levels into DB
127 loadVolumeLevels(db);
128
129 // Load inital settings values
130 loadSettings(db);
131 }
132
133 @Override
134 public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
135 Log.w(TAG, "Upgrading settings database from version " + oldVersion + " to "
136 + currentVersion);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 int upgradeVersion = oldVersion;
139
140 // Pattern for upgrade blocks:
141 //
142 // if (upgradeVersion == [the DATABASE_VERSION you set] - 1) {
143 // .. your upgrade logic..
144 // upgradeVersion = [the DATABASE_VERSION you set]
145 // }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 if (upgradeVersion == 20) {
148 /*
149 * Version 21 is part of the volume control refresh. There is no
150 * longer a UI-visible for setting notification vibrate on/off (in
151 * our design), but the functionality still exists. Force the
152 * notification vibrate to on.
153 */
154 loadVibrateSetting(db, true);
155 if (Config.LOGD) Log.d(TAG, "Reset system vibrate setting");
156
157 upgradeVersion = 21;
158 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 if (upgradeVersion < 22) {
161 upgradeVersion = 22;
162 // Upgrade the lock gesture storage location and format
163 upgradeLockPatternLocation(db);
164 }
165
166 if (upgradeVersion < 23) {
167 db.execSQL("UPDATE favorites SET iconResource=0 WHERE iconType=0");
168 upgradeVersion = 23;
169 }
170
171 if (upgradeVersion == 23) {
172 db.beginTransaction();
173 try {
174 db.execSQL("ALTER TABLE favorites ADD spanX INTEGER");
175 db.execSQL("ALTER TABLE favorites ADD spanY INTEGER");
176 // Shortcuts, applications, folders
177 db.execSQL("UPDATE favorites SET spanX=1, spanY=1 WHERE itemType<=0");
178 // Photo frames, clocks
Wink Saville767a6622009-04-02 01:37:02 -0700179 db.execSQL(
180 "UPDATE favorites SET spanX=2, spanY=2 WHERE itemType=1000 or itemType=1002");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 // Search boxes
182 db.execSQL("UPDATE favorites SET spanX=4, spanY=1 WHERE itemType=1001");
183 db.setTransactionSuccessful();
184 } finally {
185 db.endTransaction();
186 }
187 upgradeVersion = 24;
188 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 if (upgradeVersion == 24) {
191 db.beginTransaction();
192 try {
193 // The value of the constants for preferring wifi or preferring mobile have been
194 // swapped, so reload the default.
195 db.execSQL("DELETE FROM system WHERE name='network_preference'");
196 db.execSQL("INSERT INTO system ('name', 'value') values ('network_preference', '" +
197 ConnectivityManager.DEFAULT_NETWORK_PREFERENCE + "')");
198 db.setTransactionSuccessful();
199 } finally {
200 db.endTransaction();
201 }
202 upgradeVersion = 25;
203 }
204
205 if (upgradeVersion == 25) {
206 db.beginTransaction();
207 try {
208 db.execSQL("ALTER TABLE favorites ADD uri TEXT");
209 db.execSQL("ALTER TABLE favorites ADD displayMode INTEGER");
210 db.setTransactionSuccessful();
211 } finally {
212 db.endTransaction();
213 }
214 upgradeVersion = 26;
215 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 if (upgradeVersion == 26) {
218 // This introduces the new secure settings table.
219 db.beginTransaction();
220 try {
221 createSecureTable(db);
222 db.setTransactionSuccessful();
223 } finally {
224 db.endTransaction();
225 }
226 upgradeVersion = 27;
227 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 if (upgradeVersion == 27) {
230 // Copy settings values from 'system' to 'secure' and delete them from 'system'
231 SQLiteStatement insertStmt = null;
232 SQLiteStatement deleteStmt = null;
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800234 db.beginTransaction();
235 try {
236 insertStmt =
237 db.compileStatement("INSERT INTO secure (name,value) SELECT name,value FROM "
238 + "system WHERE name=?");
239 deleteStmt = db.compileStatement("DELETE FROM system WHERE name=?");
240
241 String[] settingsToMove = {
242 Settings.Secure.ADB_ENABLED,
243 Settings.Secure.ANDROID_ID,
244 Settings.Secure.BLUETOOTH_ON,
245 Settings.Secure.DATA_ROAMING,
246 Settings.Secure.DEVICE_PROVISIONED,
247 Settings.Secure.HTTP_PROXY,
248 Settings.Secure.INSTALL_NON_MARKET_APPS,
249 Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
250 Settings.Secure.LOGGING_ID,
251 Settings.Secure.NETWORK_PREFERENCE,
252 Settings.Secure.PARENTAL_CONTROL_ENABLED,
253 Settings.Secure.PARENTAL_CONTROL_LAST_UPDATE,
254 Settings.Secure.PARENTAL_CONTROL_REDIRECT_URL,
255 Settings.Secure.SETTINGS_CLASSNAME,
256 Settings.Secure.USB_MASS_STORAGE_ENABLED,
257 Settings.Secure.USE_GOOGLE_MAIL,
258 Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
259 Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY,
260 Settings.Secure.WIFI_NUM_OPEN_NETWORKS_KEPT,
261 Settings.Secure.WIFI_ON,
262 Settings.Secure.WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE,
263 Settings.Secure.WIFI_WATCHDOG_AP_COUNT,
264 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS,
265 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED,
266 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS,
267 Settings.Secure.WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT,
268 Settings.Secure.WIFI_WATCHDOG_MAX_AP_CHECKS,
269 Settings.Secure.WIFI_WATCHDOG_ON,
270 Settings.Secure.WIFI_WATCHDOG_PING_COUNT,
271 Settings.Secure.WIFI_WATCHDOG_PING_DELAY_MS,
272 Settings.Secure.WIFI_WATCHDOG_PING_TIMEOUT_MS,
273 };
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 for (String setting : settingsToMove) {
276 insertStmt.bindString(1, setting);
277 insertStmt.execute();
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 deleteStmt.bindString(1, setting);
280 deleteStmt.execute();
281 }
282 db.setTransactionSuccessful();
283 } finally {
284 db.endTransaction();
285 if (insertStmt != null) {
286 insertStmt.close();
287 }
288 if (deleteStmt != null) {
289 deleteStmt.close();
290 }
291 }
292 upgradeVersion = 28;
293 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 if (upgradeVersion == 28 || upgradeVersion == 29) {
296 // Note: The upgrade to 28 was flawed since it didn't delete the old
297 // setting first before inserting. Combining 28 and 29 with the
298 // fixed version.
299
300 // This upgrade adds the STREAM_NOTIFICATION type to the list of
301 // types affected by ringer modes (silent, vibrate, etc.)
302 db.beginTransaction();
303 try {
304 db.execSQL("DELETE FROM system WHERE name='"
305 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
306 int newValue = (1 << AudioManager.STREAM_RING)
307 | (1 << AudioManager.STREAM_NOTIFICATION)
308 | (1 << AudioManager.STREAM_SYSTEM);
309 db.execSQL("INSERT INTO system ('name', 'value') values ('"
310 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
311 + String.valueOf(newValue) + "')");
312 db.setTransactionSuccessful();
313 } finally {
314 db.endTransaction();
315 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 upgradeVersion = 30;
318 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320 if (upgradeVersion == 30) {
321 /*
322 * Upgrade 31 clears the title for all quick launch shortcuts so the
323 * activities' titles will be resolved at display time. Also, the
324 * folder is changed to '@quicklaunch'.
325 */
326 db.beginTransaction();
327 try {
328 db.execSQL("UPDATE bookmarks SET folder = '@quicklaunch'");
329 db.execSQL("UPDATE bookmarks SET title = ''");
330 db.setTransactionSuccessful();
331 } finally {
332 db.endTransaction();
333 }
334 upgradeVersion = 31;
335 }
336
337 if (upgradeVersion == 31) {
338 /*
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700339 * Animations are now managed in preferences, and may be
340 * enabled or disabled based on product resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 */
342 db.beginTransaction();
343 try {
344 db.execSQL("DELETE FROM system WHERE name='"
345 + Settings.System.WINDOW_ANIMATION_SCALE + "'");
346 db.execSQL("DELETE FROM system WHERE name='"
347 + Settings.System.TRANSITION_ANIMATION_SCALE + "'");
348 SQLiteStatement stmt = db.compileStatement("INSERT INTO system(name,value)"
349 + " VALUES(?,?);");
350 loadDefaultAnimationSettings(stmt);
351 stmt.close();
352 db.setTransactionSuccessful();
353 } finally {
354 db.endTransaction();
355 }
356 upgradeVersion = 32;
357 }
358
359 if (upgradeVersion == 32) {
360 // The Wi-Fi watchdog SSID list is now seeded with the value of
361 // the property ro.com.android.wifi-watchlist
362 String wifiWatchList = SystemProperties.get("ro.com.android.wifi-watchlist");
363 if (!TextUtils.isEmpty(wifiWatchList)) {
364 db.beginTransaction();
365 try {
366 db.execSQL("INSERT OR IGNORE INTO secure(name,value) values('" +
367 Settings.Secure.WIFI_WATCHDOG_WATCH_LIST + "','" +
368 wifiWatchList + "');");
369 db.setTransactionSuccessful();
370 } finally {
371 db.endTransaction();
372 }
373 }
374 upgradeVersion = 33;
375 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700376
The Android Open Source Project4df24232009-03-05 14:34:35 -0800377 if (upgradeVersion == 33) {
378 // Set the default zoom controls to: tap-twice to bring up +/-
379 db.beginTransaction();
380 try {
381 db.execSQL("INSERT INTO system(name,value) values('zoom','2');");
382 db.setTransactionSuccessful();
383 } finally {
384 db.endTransaction();
385 }
386 upgradeVersion = 34;
387 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388
Dianne Hackborncf098292009-07-01 19:55:20 -0700389 if (upgradeVersion == 34) {
390 db.beginTransaction();
391 try {
392 SQLiteStatement stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
393 + " VALUES(?,?);");
394 loadSecure35Settings(stmt);
395 stmt.close();
396 db.setTransactionSuccessful();
397 } finally {
398 db.endTransaction();
399 }
400 upgradeVersion = 35;
401 }
402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 if (upgradeVersion != currentVersion) {
404 Log.w(TAG, "Got stuck trying to upgrade from version " + upgradeVersion
405 + ", must wipe the settings provider");
406 db.execSQL("DROP TABLE IF EXISTS system");
407 db.execSQL("DROP INDEX IF EXISTS systemIndex1");
408 db.execSQL("DROP TABLE IF EXISTS secure");
409 db.execSQL("DROP INDEX IF EXISTS secureIndex1");
410 db.execSQL("DROP TABLE IF EXISTS gservices");
411 db.execSQL("DROP INDEX IF EXISTS gservicesIndex1");
412 db.execSQL("DROP TABLE IF EXISTS bluetooth_devices");
413 db.execSQL("DROP TABLE IF EXISTS bookmarks");
414 db.execSQL("DROP INDEX IF EXISTS bookmarksIndex1");
415 db.execSQL("DROP INDEX IF EXISTS bookmarksIndex2");
416 db.execSQL("DROP TABLE IF EXISTS favorites");
417 onCreate(db);
418 }
419 }
420
421 private void upgradeLockPatternLocation(SQLiteDatabase db) {
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700422 Cursor c = db.query("system", new String[] {"_id", "value"}, "name='lock_pattern'",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 null, null, null, null);
424 if (c.getCount() > 0) {
425 c.moveToFirst();
426 String lockPattern = c.getString(1);
427 if (!TextUtils.isEmpty(lockPattern)) {
428 // Convert lock pattern
429 try {
430 LockPatternUtils lpu = new LockPatternUtils(mContext.getContentResolver());
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700431 List<LockPatternView.Cell> cellPattern =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 LockPatternUtils.stringToPattern(lockPattern);
433 lpu.saveLockPattern(cellPattern);
434 } catch (IllegalArgumentException e) {
435 // Don't want corrupted lock pattern to hang the reboot process
436 }
437 }
438 c.close();
439 db.delete("system", "name='lock_pattern'", null);
440 } else {
441 c.close();
442 }
443 }
444
445 /**
446 * Loads the default set of bookmarked shortcuts from an xml file.
447 *
448 * @param db The database to write the values into
449 * @param startingIndex The zero-based position at which bookmarks in this file should begin
450 * @param subPath The relative path from ANDROID_ROOT to the file to read
451 * @param quiet If true, do no complain if the file is missing
452 */
453 private int loadBookmarks(SQLiteDatabase db, int startingIndex, String subPath,
454 boolean quiet) {
455 FileReader bookmarksReader;
456
457 // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
458 final File favFile = new File(Environment.getRootDirectory(), subPath);
459 try {
460 bookmarksReader = new FileReader(favFile);
461 } catch (FileNotFoundException e) {
462 if (!quiet) {
463 Log.e(TAG, "Couldn't find or open bookmarks file " + favFile);
464 }
465 return 0;
466 }
467
468 Intent intent = new Intent(Intent.ACTION_MAIN, null);
469 intent.addCategory(Intent.CATEGORY_LAUNCHER);
470 ContentValues values = new ContentValues();
471
472 PackageManager packageManager = mContext.getPackageManager();
473 ActivityInfo info;
474 int i = startingIndex;
475 try {
476 XmlPullParser parser = Xml.newPullParser();
477 parser.setInput(bookmarksReader);
478
479 XmlUtils.beginDocument(parser, "bookmarks");
480
481 while (true) {
482 XmlUtils.nextElement(parser);
483
484 String name = parser.getName();
485 if (!"bookmark".equals(name)) {
486 break;
487 }
488
489 String pkg = parser.getAttributeValue(null, "package");
490 String cls = parser.getAttributeValue(null, "class");
491 String shortcutStr = parser.getAttributeValue(null, "shortcut");
492 int shortcutValue = (int) shortcutStr.charAt(0);
493 if (TextUtils.isEmpty(shortcutStr)) {
494 Log.w(TAG, "Unable to get shortcut for: " + pkg + "/" + cls);
495 }
496 try {
497 ComponentName cn = new ComponentName(pkg, cls);
498 info = packageManager.getActivityInfo(cn, 0);
499 intent.setComponent(cn);
500 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
501 values.put(Settings.Bookmarks.INTENT, intent.toURI());
502 values.put(Settings.Bookmarks.TITLE,
503 info.loadLabel(packageManager).toString());
504 values.put(Settings.Bookmarks.SHORTCUT, shortcutValue);
505 db.insert("bookmarks", null, values);
506 i++;
507 } catch (PackageManager.NameNotFoundException e) {
508 Log.w(TAG, "Unable to add bookmark: " + pkg + "/" + cls, e);
509 }
510 }
511 } catch (XmlPullParserException e) {
512 Log.w(TAG, "Got execption parsing bookmarks.", e);
513 } catch (IOException e) {
514 Log.w(TAG, "Got execption parsing bookmarks.", e);
515 }
516
517 return i;
518 }
519
520 /**
521 * Loads the default set of bookmark packages.
522 *
523 * @param db The database to write the values into
524 */
525 private void loadBookmarks(SQLiteDatabase db) {
526 loadBookmarks(db, 0, DEFAULT_BOOKMARKS_PATH, false);
527 }
528
529 /**
530 * Loads the default volume levels. It is actually inserting the index of
531 * the volume array for each of the volume controls.
532 *
533 * @param db the database to insert the volume levels into
534 */
535 private void loadVolumeLevels(SQLiteDatabase db) {
536 SQLiteStatement stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
537 + " VALUES(?,?);");
538
539 loadSetting(stmt, Settings.System.VOLUME_MUSIC,
540 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_MUSIC]);
541 loadSetting(stmt, Settings.System.VOLUME_RING,
542 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_RING]);
543 loadSetting(stmt, Settings.System.VOLUME_SYSTEM,
544 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_SYSTEM]);
545 loadSetting(
546 stmt,
547 Settings.System.VOLUME_VOICE,
548 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_VOICE_CALL]);
549 loadSetting(stmt, Settings.System.VOLUME_ALARM,
550 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_ALARM]);
551 loadSetting(
552 stmt,
553 Settings.System.VOLUME_NOTIFICATION,
554 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_NOTIFICATION]);
555 loadSetting(stmt, Settings.System.MODE_RINGER,
556 AudioManager.RINGER_MODE_NORMAL);
557
558 loadVibrateSetting(db, false);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 // By default, only the ring/notification and system streams are affected
561 loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED,
562 (1 << AudioManager.STREAM_RING) | (1 << AudioManager.STREAM_NOTIFICATION) |
563 (1 << AudioManager.STREAM_SYSTEM));
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED,
566 ((1 << AudioManager.STREAM_MUSIC) |
567 (1 << AudioManager.STREAM_RING) |
568 (1 << AudioManager.STREAM_NOTIFICATION) |
569 (1 << AudioManager.STREAM_SYSTEM)));
570
571 stmt.close();
572 }
573
574 private void loadVibrateSetting(SQLiteDatabase db, boolean deleteOld) {
575 if (deleteOld) {
576 db.execSQL("DELETE FROM system WHERE name='" + Settings.System.VIBRATE_ON + "'");
577 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 SQLiteStatement stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
580 + " VALUES(?,?);");
581
582 // Vibrate off by default for ringer, on for notification
583 int vibrate = 0;
584 vibrate = AudioService.getValueForVibrateSetting(vibrate,
585 AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON);
586 vibrate = AudioService.getValueForVibrateSetting(vibrate,
587 AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
588 loadSetting(stmt, Settings.System.VIBRATE_ON, vibrate);
589 }
590
591 private void loadSettings(SQLiteDatabase db) {
592 loadSystemSettings(db);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700593 loadSecureSettings(db);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 private void loadSystemSettings(SQLiteDatabase db) {
597 SQLiteStatement stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
598 + " VALUES(?,?);");
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600 Resources r = mContext.getResources();
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602 loadBooleanSetting(stmt, Settings.System.DIM_SCREEN,
603 R.bool.def_dim_screen);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700604 loadSetting(stmt, Settings.System.STAY_ON_WHILE_PLUGGED_IN,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 "1".equals(SystemProperties.get("ro.kernel.qemu")) ? 1 : 0);
606 loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
607 R.integer.def_screen_off_timeout);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700608
David Kraused0f67152009-06-13 18:01:13 -0500609 // Set default cdma emergency tone
610 loadSetting(stmt, Settings.System.EMERGENCY_TONE, 0);
611
612 // Set default cdma call auto retry
613 loadSetting(stmt, Settings.System.CALL_AUTO_RETRY, 0);
614
615 // Set default cdma DTMF type
616 loadSetting(stmt, Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, 0);
617
618 // Set default hearing aid
619 loadSetting(stmt, Settings.System.HEARING_AID, 0);
620
621 // Set default tty mode
622 loadSetting(stmt, Settings.System.TTY_MODE, 0);
623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624 loadBooleanSetting(stmt, Settings.System.AIRPLANE_MODE_ON,
625 R.bool.def_airplane_mode_on);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_RADIOS,
628 R.string.def_airplane_mode_radios);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630 loadBooleanSetting(stmt, Settings.System.AUTO_TIME,
631 R.bool.def_auto_time); // Sync time to NITZ
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS,
634 R.integer.def_screen_brightness);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 loadDefaultAnimationSettings(stmt);
637
638 loadBooleanSetting(stmt, Settings.System.ACCELEROMETER_ROTATION,
639 R.bool.def_accelerometer_rotation);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800641 stmt.close();
642 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 private void loadDefaultAnimationSettings(SQLiteStatement stmt) {
645 loadFractionSetting(stmt, Settings.System.WINDOW_ANIMATION_SCALE,
646 R.fraction.def_window_animation_scale, 1);
647 loadFractionSetting(stmt, Settings.System.TRANSITION_ANIMATION_SCALE,
648 R.fraction.def_window_transition_scale, 1);
649 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 private void loadSecureSettings(SQLiteDatabase db) {
652 SQLiteStatement stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
653 + " VALUES(?,?);");
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655 loadBooleanSetting(stmt, Settings.Secure.BLUETOOTH_ON,
656 R.bool.def_bluetooth_on);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658 // Data roaming default, based on build
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700659 loadSetting(stmt, Settings.Secure.DATA_ROAMING,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800660 "true".equalsIgnoreCase(
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700661 SystemProperties.get("ro.com.android.dataroaming",
662 "false")) ? 1 : 0);
663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800664 loadBooleanSetting(stmt, Settings.Secure.INSTALL_NON_MARKET_APPS,
665 R.bool.def_install_non_market_apps);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 loadStringSetting(stmt, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
668 R.string.def_location_providers_allowed);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 loadIntegerSetting(stmt, Settings.Secure.NETWORK_PREFERENCE,
671 R.integer.def_network_preference);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 loadBooleanSetting(stmt, Settings.Secure.USB_MASS_STORAGE_ENABLED,
674 R.bool.def_usb_mass_storage_enabled);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 loadBooleanSetting(stmt, Settings.Secure.WIFI_ON,
677 R.bool.def_wifi_on);
678 loadBooleanSetting(stmt, Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
679 R.bool.def_networks_available_notification_on);
680
681 String wifiWatchList = SystemProperties.get("ro.com.android.wifi-watchlist");
682 if (!TextUtils.isEmpty(wifiWatchList)) {
683 loadSetting(stmt, Settings.Secure.WIFI_WATCHDOG_WATCH_LIST, wifiWatchList);
684 }
685
Wink Saville767a6622009-04-02 01:37:02 -0700686 // Set the preferred network mode to 0 = Global, CDMA default
Jaikumar Ganeshee748d372009-05-14 22:26:35 -0700687 int type = SystemProperties.getInt("ro.telephony.default_network",
Wink Saville767a6622009-04-02 01:37:02 -0700688 RILConstants.PREFERRED_NETWORK_MODE);
Jaikumar Ganeshee748d372009-05-14 22:26:35 -0700689 loadSetting(stmt, Settings.Secure.PREFERRED_NETWORK_MODE, type);
Wink Saville767a6622009-04-02 01:37:02 -0700690
691 // Enable or disable Cell Broadcast SMS
692 loadSetting(stmt, Settings.Secure.CDMA_CELL_BROADCAST_SMS,
693 RILConstants.CDMA_CELL_BROADCAST_SMS_DISABLED);
694
695 // Set the preferred cdma subscription to 0 = Subscription from RUIM, when available
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700696 loadSetting(stmt, Settings.Secure.PREFERRED_CDMA_SUBSCRIPTION,
Wink Saville767a6622009-04-02 01:37:02 -0700697 RILConstants.PREFERRED_CDMA_SUBSCRIPTION);
698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800699 // Don't do this. The SystemServer will initialize ADB_ENABLED from a
700 // persistent system property instead.
701 //loadSetting(stmt, Settings.Secure.ADB_ENABLED, 0);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703 // Allow mock locations default, based on build
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700704 loadSetting(stmt, Settings.Secure.ALLOW_MOCK_LOCATION,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800705 "1".equals(SystemProperties.get("ro.allow.mock.location")) ? 1 : 0);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700706
Dianne Hackborncf098292009-07-01 19:55:20 -0700707 loadSecure35Settings(stmt);
708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800709 stmt.close();
710 }
711
Dianne Hackborncf098292009-07-01 19:55:20 -0700712 private void loadSecure35Settings(SQLiteStatement stmt) {
713 loadBooleanSetting(stmt, Settings.Secure.BACKUP_ENABLED,
714 R.bool.def_backup_enabled);
715
716 loadStringSetting(stmt, Settings.Secure.BACKUP_TRANSPORT,
717 R.string.def_backup_transport);
718 }
719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720 private void loadSetting(SQLiteStatement stmt, String key, Object value) {
721 stmt.bindString(1, key);
722 stmt.bindString(2, value.toString());
723 stmt.execute();
724 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800726 private void loadStringSetting(SQLiteStatement stmt, String key, int resid) {
727 loadSetting(stmt, key, mContext.getResources().getString(resid));
728 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 private void loadBooleanSetting(SQLiteStatement stmt, String key, int resid) {
731 loadSetting(stmt, key,
732 mContext.getResources().getBoolean(resid) ? "1" : "0");
733 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 private void loadIntegerSetting(SQLiteStatement stmt, String key, int resid) {
736 loadSetting(stmt, key,
737 Integer.toString(mContext.getResources().getInteger(resid)));
738 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800740 private void loadFractionSetting(SQLiteStatement stmt, String key, int resid, int base) {
741 loadSetting(stmt, key,
742 Float.toString(mContext.getResources().getFraction(resid, base, base)));
743 }
744}