blob: e6c6f9f3ac002e8fe3470f91ce05736c34b80704 [file] [log] [blame]
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001/*
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
-b master501eec92009-07-06 13:53:11 -070019import java.io.FileNotFoundException;
Doug Zongker4f8ff392010-02-03 10:36:40 -080020import java.security.SecureRandom;
Julia Reynolds5e458dd2014-07-07 16:07:01 -040021import java.util.HashMap;
Christopher Tate06efb532012-08-24 15:29:27 -070022import java.util.HashSet;
Julia Reynolds5e458dd2014-07-07 16:07:01 -040023import java.util.Map;
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -070024import java.util.concurrent.atomic.AtomicBoolean;
25import java.util.concurrent.atomic.AtomicInteger;
-b master501eec92009-07-06 13:53:11 -070026
Christopher Tated5fe1472012-09-10 15:48:38 -070027import android.app.ActivityManager;
Dianne Hackborn961321f2013-02-05 17:22:41 -080028import android.app.AppOpsManager;
Christopher Tate45281862010-03-05 15:46:30 -080029import android.app.backup.BackupManager;
Christopher Tate06efb532012-08-24 15:29:27 -070030import android.content.BroadcastReceiver;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070031import android.content.ContentProvider;
32import android.content.ContentUris;
33import android.content.ContentValues;
34import android.content.Context;
Christopher Tate06efb532012-08-24 15:29:27 -070035import android.content.Intent;
36import android.content.IntentFilter;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070037import android.content.pm.PackageManager;
Christopher Tate38e7a602013-09-03 16:57:34 -070038import android.content.pm.UserInfo;
Marco Nelissen69f593c2009-07-28 09:55:04 -070039import android.content.res.AssetFileDescriptor;
Christopher Tateafccaa82012-10-03 17:41:51 -070040import android.database.AbstractCursor;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070041import android.database.Cursor;
42import android.database.sqlite.SQLiteDatabase;
Brad Fitzpatrick1877d012010-03-04 17:48:13 -080043import android.database.sqlite.SQLiteException;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070044import android.database.sqlite.SQLiteQueryBuilder;
45import android.media.RingtoneManager;
46import android.net.Uri;
Christopher Tate06efb532012-08-24 15:29:27 -070047import android.os.Binder;
Brad Fitzpatrick1877d012010-03-04 17:48:13 -080048import android.os.Bundle;
Amith Yamasani5cdf7f52013-06-27 15:12:01 -070049import android.os.DropBoxManager;
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -070050import android.os.FileObserver;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070051import android.os.ParcelFileDescriptor;
Christopher Tate0da13572013-10-13 17:34:49 -070052import android.os.Process;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070053import android.os.SystemProperties;
Christopher Tate06efb532012-08-24 15:29:27 -070054import android.os.UserHandle;
55import android.os.UserManager;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070056import android.provider.MediaStore;
57import android.provider.Settings;
58import android.text.TextUtils;
59import android.util.Log;
Jesse Wilson0c7faee2011-02-10 11:33:19 -080060import android.util.LruCache;
Christopher Tate06efb532012-08-24 15:29:27 -070061import android.util.Slog;
62import android.util.SparseArray;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070063
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070064public class SettingsProvider extends ContentProvider {
65 private static final String TAG = "SettingsProvider";
Christopher Tate4dc7a682012-09-11 12:15:49 -070066 private static final boolean LOCAL_LOGV = false;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070067
Christopher Tate0da13572013-10-13 17:34:49 -070068 private static final boolean USER_CHECK_THROWS = true;
69
Christopher Tate06efb532012-08-24 15:29:27 -070070 private static final String TABLE_SYSTEM = "system";
71 private static final String TABLE_SECURE = "secure";
72 private static final String TABLE_GLOBAL = "global";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 private static final String TABLE_FAVORITES = "favorites";
74 private static final String TABLE_OLD_FAVORITES = "old_favorites";
75
Brad Fitzpatrick1877d012010-03-04 17:48:13 -080076 private static final String[] COLUMN_VALUE = new String[] { "value" };
77
Christopher Tate06efb532012-08-24 15:29:27 -070078 // Caches for each user's settings, access-ordered for acting as LRU.
Brad Fitzpatrick1bd62bd2010-03-08 18:30:52 -080079 // Guarded by themselves.
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -070080 private static final int MAX_CACHE_ENTRIES = 200;
Christopher Tate06efb532012-08-24 15:29:27 -070081 private static final SparseArray<SettingsCache> sSystemCaches
82 = new SparseArray<SettingsCache>();
83 private static final SparseArray<SettingsCache> sSecureCaches
84 = new SparseArray<SettingsCache>();
85 private static final SettingsCache sGlobalCache = new SettingsCache(TABLE_GLOBAL);
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -070086
87 // The count of how many known (handled by SettingsProvider)
Christopher Tate06efb532012-08-24 15:29:27 -070088 // database mutations are currently being handled for this user.
89 // Used by file observers to not reload the database when it's ourselves
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -070090 // modifying it.
Christopher Tate06efb532012-08-24 15:29:27 -070091 private static final SparseArray<AtomicInteger> sKnownMutationsInFlight
92 = new SparseArray<AtomicInteger>();
Brad Fitzpatrick1bd62bd2010-03-08 18:30:52 -080093
Christopher Tate78d2a662012-09-13 16:19:44 -070094 // Each defined user has their own settings
95 protected final SparseArray<DatabaseHelper> mOpenHelpers = new SparseArray<DatabaseHelper>();
96
Brad Fitzpatrick342984a2010-03-09 16:59:30 -080097 // Over this size we don't reject loading or saving settings but
98 // we do consider them broken/malicious and don't keep them in
99 // memory at least:
100 private static final int MAX_CACHE_ENTRY_SIZE = 500;
101
Brad Fitzpatrick1bd62bd2010-03-08 18:30:52 -0800102 private static final Bundle NULL_SETTING = Bundle.forPair("value", null);
103
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -0700104 // Used as a sentinel value in an instance equality test when we
105 // want to cache the existence of a key, but not store its value.
106 private static final Bundle TOO_LARGE_TO_CACHE_MARKER = Bundle.forPair("_dummy", null);
107
Christopher Tate06efb532012-08-24 15:29:27 -0700108 private UserManager mUserManager;
Amith Yamasani8823c0a82009-07-07 14:30:17 -0700109 private BackupManager mBackupManager;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700110
111 /**
Christopher Tate06efb532012-08-24 15:29:27 -0700112 * Settings which need to be treated as global/shared in multi-user environments.
113 */
114 static final HashSet<String> sSecureGlobalKeys;
115 static final HashSet<String> sSystemGlobalKeys;
Amith Yamasani5cdf7f52013-06-27 15:12:01 -0700116
Julia Reynolds5e458dd2014-07-07 16:07:01 -0400117 // Settings that cannot be modified if associated user restrictions are enabled.
118 static final Map<String, String> sRestrictedKeys;
119
Amith Yamasani5cdf7f52013-06-27 15:12:01 -0700120 private static final String DROPBOX_TAG_USERLOG = "restricted_profile_ssaid";
121
Christopher Tate06efb532012-08-24 15:29:27 -0700122 static {
123 // Keys (name column) from the 'secure' table that are now in the owner user's 'global'
124 // table, shared across all users
125 // These must match Settings.Secure.MOVED_TO_GLOBAL
126 sSecureGlobalKeys = new HashSet<String>();
Christopher Tate66488d62012-10-02 11:58:01 -0700127 Settings.Secure.getMovedKeys(sSecureGlobalKeys);
Christopher Tate06efb532012-08-24 15:29:27 -0700128
129 // Keys from the 'system' table now moved to 'global'
130 // These must match Settings.System.MOVED_TO_GLOBAL
131 sSystemGlobalKeys = new HashSet<String>();
Christopher Tate66488d62012-10-02 11:58:01 -0700132 Settings.System.getNonLegacyMovedKeys(sSystemGlobalKeys);
Julia Reynolds5e458dd2014-07-07 16:07:01 -0400133
134 sRestrictedKeys = new HashMap<String, String>();
135 sRestrictedKeys.put(Settings.Secure.LOCATION_MODE, UserManager.DISALLOW_SHARE_LOCATION);
136 sRestrictedKeys.put(Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
137 UserManager.DISALLOW_SHARE_LOCATION);
138 sRestrictedKeys.put(Settings.Global.INSTALL_NON_MARKET_APPS,
139 UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES);
140 sRestrictedKeys.put(Settings.Global.ADB_ENABLED, UserManager.DISALLOW_DEBUGGING_FEATURES);
141 sRestrictedKeys.put(Settings.Global.PACKAGE_VERIFIER_ENABLE,
142 UserManager.ENSURE_VERIFY_APPS);
143 sRestrictedKeys.put(Settings.Global.PREFERRED_NETWORK_MODE,
144 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS);
Christopher Tate06efb532012-08-24 15:29:27 -0700145 }
146
147 private boolean settingMovedToGlobal(final String name) {
148 return sSecureGlobalKeys.contains(name) || sSystemGlobalKeys.contains(name);
149 }
150
151 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700152 * Decode a content URL into the table, projection, and arguments
153 * used to access the corresponding database rows.
154 */
155 private static class SqlArguments {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 public String table;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700157 public final String where;
158 public final String[] args;
159
160 /** Operate on existing rows. */
161 SqlArguments(Uri url, String where, String[] args) {
162 if (url.getPathSegments().size() == 1) {
Christopher Tatec221d2b2012-10-03 18:33:52 -0700163 // of the form content://settings/secure, arbitrary where clause
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700164 this.table = url.getPathSegments().get(0);
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700165 if (!DatabaseHelper.isValidTable(this.table)) {
166 throw new IllegalArgumentException("Bad root path: " + this.table);
167 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700168 this.where = where;
169 this.args = args;
170 } else if (url.getPathSegments().size() != 2) {
171 throw new IllegalArgumentException("Invalid URI: " + url);
172 } else if (!TextUtils.isEmpty(where)) {
173 throw new UnsupportedOperationException("WHERE clause not supported: " + url);
174 } else {
Christopher Tatec221d2b2012-10-03 18:33:52 -0700175 // of the form content://settings/secure/element_name, no where clause
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700176 this.table = url.getPathSegments().get(0);
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700177 if (!DatabaseHelper.isValidTable(this.table)) {
178 throw new IllegalArgumentException("Bad root path: " + this.table);
179 }
Doug Zongker5bcb5512012-09-24 12:24:54 -0700180 if (TABLE_SYSTEM.equals(this.table) || TABLE_SECURE.equals(this.table) ||
181 TABLE_GLOBAL.equals(this.table)) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700182 this.where = Settings.NameValueTable.NAME + "=?";
Christopher Tatec221d2b2012-10-03 18:33:52 -0700183 final String name = url.getPathSegments().get(1);
184 this.args = new String[] { name };
185 // Rewrite the table for known-migrated names
186 if (TABLE_SYSTEM.equals(this.table) || TABLE_SECURE.equals(this.table)) {
187 if (sSecureGlobalKeys.contains(name) || sSystemGlobalKeys.contains(name)) {
188 this.table = TABLE_GLOBAL;
189 }
190 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700191 } else {
Christopher Tatec221d2b2012-10-03 18:33:52 -0700192 // of the form content://bookmarks/19
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700193 this.where = "_id=" + ContentUris.parseId(url);
194 this.args = null;
195 }
196 }
197 }
198
199 /** Insert new rows (no where clause allowed). */
200 SqlArguments(Uri url) {
201 if (url.getPathSegments().size() == 1) {
202 this.table = url.getPathSegments().get(0);
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700203 if (!DatabaseHelper.isValidTable(this.table)) {
204 throw new IllegalArgumentException("Bad root path: " + this.table);
205 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700206 this.where = null;
207 this.args = null;
208 } else {
209 throw new IllegalArgumentException("Invalid URI: " + url);
210 }
211 }
212 }
213
214 /**
215 * Get the content URI of a row added to a table.
216 * @param tableUri of the entire table
217 * @param values found in the row
218 * @param rowId of the row
219 * @return the content URI for this particular row
220 */
221 private Uri getUriFor(Uri tableUri, ContentValues values, long rowId) {
222 if (tableUri.getPathSegments().size() != 1) {
223 throw new IllegalArgumentException("Invalid URI: " + tableUri);
224 }
225 String table = tableUri.getPathSegments().get(0);
Christopher Tate06efb532012-08-24 15:29:27 -0700226 if (TABLE_SYSTEM.equals(table) ||
227 TABLE_SECURE.equals(table) ||
228 TABLE_GLOBAL.equals(table)) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700229 String name = values.getAsString(Settings.NameValueTable.NAME);
230 return Uri.withAppendedPath(tableUri, name);
231 } else {
232 return ContentUris.withAppendedId(tableUri, rowId);
233 }
234 }
235
236 /**
237 * Send a notification when a particular content URI changes.
238 * Modify the system property used to communicate the version of
239 * this table, for tables which have such a property. (The Settings
240 * contract class uses these to provide client-side caches.)
241 * @param uri to send notifications for
242 */
Christopher Tate06efb532012-08-24 15:29:27 -0700243 private void sendNotify(Uri uri, int userHandle) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700244 // Update the system property *first*, so if someone is listening for
245 // a notification and then using the contract class to get their data,
246 // the system property will be updated and they'll get the new data.
247
Amith Yamasanid1582142009-07-08 20:04:55 -0700248 boolean backedUpDataChanged = false;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700249 String property = null, table = uri.getPathSegments().get(0);
Christopher Tate16aa9732012-09-17 16:23:44 -0700250 final boolean isGlobal = table.equals(TABLE_GLOBAL);
Christopher Tate06efb532012-08-24 15:29:27 -0700251 if (table.equals(TABLE_SYSTEM)) {
Dianne Hackborn139748f2012-09-24 11:36:57 -0700252 property = Settings.System.SYS_PROP_SETTING_VERSION;
Amith Yamasanid1582142009-07-08 20:04:55 -0700253 backedUpDataChanged = true;
Christopher Tate06efb532012-08-24 15:29:27 -0700254 } else if (table.equals(TABLE_SECURE)) {
Dianne Hackborn139748f2012-09-24 11:36:57 -0700255 property = Settings.Secure.SYS_PROP_SETTING_VERSION;
Christopher Tate06efb532012-08-24 15:29:27 -0700256 backedUpDataChanged = true;
Christopher Tate16aa9732012-09-17 16:23:44 -0700257 } else if (isGlobal) {
Christopher Tate06efb532012-08-24 15:29:27 -0700258 property = Settings.Global.SYS_PROP_SETTING_VERSION; // this one is global
Amith Yamasanid1582142009-07-08 20:04:55 -0700259 backedUpDataChanged = true;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700260 }
261
262 if (property != null) {
263 long version = SystemProperties.getLong(property, 0) + 1;
264 if (LOCAL_LOGV) Log.v(TAG, "property: " + property + "=" + version);
265 SystemProperties.set(property, Long.toString(version));
266 }
267
-b master501eec92009-07-06 13:53:11 -0700268 // Inform the backup manager about a data change
Amith Yamasanid1582142009-07-08 20:04:55 -0700269 if (backedUpDataChanged) {
270 mBackupManager.dataChanged();
271 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700272 // Now send the notification through the content framework.
273
274 String notify = uri.getQueryParameter("notify");
275 if (notify == null || "true".equals(notify)) {
Christopher Tate16aa9732012-09-17 16:23:44 -0700276 final int notifyTarget = isGlobal ? UserHandle.USER_ALL : userHandle;
Christopher Tatec8459dc82012-09-18 13:27:36 -0700277 final long oldId = Binder.clearCallingIdentity();
278 try {
279 getContext().getContentResolver().notifyChange(uri, null, true, notifyTarget);
280 } finally {
281 Binder.restoreCallingIdentity(oldId);
282 }
Christopher Tate16aa9732012-09-17 16:23:44 -0700283 if (LOCAL_LOGV) Log.v(TAG, "notifying for " + notifyTarget + ": " + uri);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700284 } else {
285 if (LOCAL_LOGV) Log.v(TAG, "notification suppressed: " + uri);
286 }
287 }
288
289 /**
290 * Make sure the caller has permission to write this data.
291 * @param args supplied by the caller
292 * @throws SecurityException if the caller is forbidden to write.
293 */
294 private void checkWritePermissions(SqlArguments args) {
Christopher Tate06efb532012-08-24 15:29:27 -0700295 if ((TABLE_SECURE.equals(args.table) || TABLE_GLOBAL.equals(args.table)) &&
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800296 getContext().checkCallingOrSelfPermission(
Doug Zongkeraed8f8e2010-01-07 18:07:50 -0800297 android.Manifest.permission.WRITE_SECURE_SETTINGS) !=
298 PackageManager.PERMISSION_GRANTED) {
Brett Chabot16dd82c2009-06-18 17:00:48 -0700299 throw new SecurityException(
Doug Zongkeraed8f8e2010-01-07 18:07:50 -0800300 String.format("Permission denial: writing to secure settings requires %1$s",
301 android.Manifest.permission.WRITE_SECURE_SETTINGS));
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700302 }
303 }
304
Julia Reynolds5e458dd2014-07-07 16:07:01 -0400305 private void checkUserRestrictions(String setting) {
306 String userRestriction = sRestrictedKeys.get(setting);
307 if (!TextUtils.isEmpty(userRestriction)
308 && mUserManager.hasUserRestriction(userRestriction)) {
309 throw new SecurityException(
310 "Permission denial: user is restricted from changing this setting.");
311 }
312 }
313
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -0700314 // FileObserver for external modifications to the database file.
315 // Note that this is for platform developers only with
316 // userdebug/eng builds who should be able to tinker with the
317 // sqlite database out from under the SettingsProvider, which is
318 // normally the exclusive owner of the database. But we keep this
319 // enabled all the time to minimize development-vs-user
320 // differences in testing.
Christopher Tate06efb532012-08-24 15:29:27 -0700321 private static SparseArray<SettingsFileObserver> sObserverInstances
322 = new SparseArray<SettingsFileObserver>();
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -0700323 private class SettingsFileObserver extends FileObserver {
324 private final AtomicBoolean mIsDirty = new AtomicBoolean(false);
Christopher Tate06efb532012-08-24 15:29:27 -0700325 private final int mUserHandle;
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -0700326 private final String mPath;
327
Christopher Tate06efb532012-08-24 15:29:27 -0700328 public SettingsFileObserver(int userHandle, String path) {
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -0700329 super(path, FileObserver.CLOSE_WRITE |
330 FileObserver.CREATE | FileObserver.DELETE |
331 FileObserver.MOVED_TO | FileObserver.MODIFY);
Christopher Tate06efb532012-08-24 15:29:27 -0700332 mUserHandle = userHandle;
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -0700333 mPath = path;
334 }
335
336 public void onEvent(int event, String path) {
Christopher Tate06efb532012-08-24 15:29:27 -0700337 int modsInFlight = sKnownMutationsInFlight.get(mUserHandle).get();
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -0700338 if (modsInFlight > 0) {
339 // our own modification.
340 return;
341 }
Christopher Tate06efb532012-08-24 15:29:27 -0700342 Log.d(TAG, "User " + mUserHandle + " external modification to " + mPath
343 + "; event=" + event);
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -0700344 if (!mIsDirty.compareAndSet(false, true)) {
345 // already handled. (we get a few update events
346 // during an sqlite write)
347 return;
348 }
Christopher Tate06efb532012-08-24 15:29:27 -0700349 Log.d(TAG, "User " + mUserHandle + " updating our caches for " + mPath);
350 fullyPopulateCaches(mUserHandle);
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -0700351 mIsDirty.set(false);
352 }
353 }
354
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700355 @Override
356 public boolean onCreate() {
Amith Yamasani8823c0a82009-07-07 14:30:17 -0700357 mBackupManager = new BackupManager(getContext());
Amith Yamasani27db4682013-03-30 17:07:47 -0700358 mUserManager = UserManager.get(getContext());
Fred Quintanac70239e2009-12-17 10:28:33 -0800359
Dianne Hackborn961321f2013-02-05 17:22:41 -0800360 setAppOps(AppOpsManager.OP_NONE, AppOpsManager.OP_WRITE_SETTINGS);
Christopher Tate78d2a662012-09-13 16:19:44 -0700361 establishDbTracking(UserHandle.USER_OWNER);
Christopher Tate06efb532012-08-24 15:29:27 -0700362
Christopher Tate78d2a662012-09-13 16:19:44 -0700363 IntentFilter userFilter = new IntentFilter();
364 userFilter.addAction(Intent.ACTION_USER_REMOVED);
365 getContext().registerReceiver(new BroadcastReceiver() {
366 @Override
367 public void onReceive(Context context, Intent intent) {
368 if (intent.getAction().equals(Intent.ACTION_USER_REMOVED)) {
369 final int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
370 UserHandle.USER_OWNER);
371 if (userHandle != UserHandle.USER_OWNER) {
372 onUserRemoved(userHandle);
Christopher Tate06efb532012-08-24 15:29:27 -0700373 }
374 }
Christopher Tate78d2a662012-09-13 16:19:44 -0700375 }
376 }, userFilter);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700377 return true;
378 }
379
Christopher Tate06efb532012-08-24 15:29:27 -0700380 void onUserRemoved(int userHandle) {
Christopher Tate06efb532012-08-24 15:29:27 -0700381 synchronized (this) {
Christopher Tate78d2a662012-09-13 16:19:44 -0700382 // the db file itself will be deleted automatically, but we need to tear down
383 // our caches and other internal bookkeeping.
Christopher Tate06efb532012-08-24 15:29:27 -0700384 FileObserver observer = sObserverInstances.get(userHandle);
385 if (observer != null) {
386 observer.stopWatching();
387 sObserverInstances.delete(userHandle);
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -0700388 }
Christopher Tate06efb532012-08-24 15:29:27 -0700389
390 mOpenHelpers.delete(userHandle);
391 sSystemCaches.delete(userHandle);
392 sSecureCaches.delete(userHandle);
393 sKnownMutationsInFlight.delete(userHandle);
Christopher Tate06efb532012-08-24 15:29:27 -0700394 }
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -0700395 }
396
Christopher Tate78d2a662012-09-13 16:19:44 -0700397 private void establishDbTracking(int userHandle) {
Christopher Tate06efb532012-08-24 15:29:27 -0700398 if (LOCAL_LOGV) {
399 Slog.i(TAG, "Installing settings db helper and caches for user " + userHandle);
400 }
401
Christopher Tate78d2a662012-09-13 16:19:44 -0700402 DatabaseHelper dbhelper;
Christopher Tate06efb532012-08-24 15:29:27 -0700403
Christopher Tate78d2a662012-09-13 16:19:44 -0700404 synchronized (this) {
405 dbhelper = mOpenHelpers.get(userHandle);
406 if (dbhelper == null) {
407 dbhelper = new DatabaseHelper(getContext(), userHandle);
408 mOpenHelpers.append(userHandle, dbhelper);
409
410 sSystemCaches.append(userHandle, new SettingsCache(TABLE_SYSTEM));
411 sSecureCaches.append(userHandle, new SettingsCache(TABLE_SECURE));
412 sKnownMutationsInFlight.append(userHandle, new AtomicInteger(0));
413 }
414 }
415
416 // Initialization of the db *outside* the locks. It's possible that racing
417 // threads might wind up here, the second having read the cache entries
418 // written by the first, but that's benign: the SQLite helper implementation
419 // manages concurrency itself, and it's important that we not run the db
420 // initialization with any of our own locks held, so we're fine.
Christopher Tate06efb532012-08-24 15:29:27 -0700421 SQLiteDatabase db = dbhelper.getWritableDatabase();
422
Christopher Tate78d2a662012-09-13 16:19:44 -0700423 // Watch for external modifications to the database files,
424 // keeping our caches in sync. We synchronize the observer set
425 // separately, and of course it has to run after the db file
426 // itself was set up by the DatabaseHelper.
427 synchronized (sObserverInstances) {
428 if (sObserverInstances.get(userHandle) == null) {
429 SettingsFileObserver observer = new SettingsFileObserver(userHandle, db.getPath());
430 sObserverInstances.append(userHandle, observer);
431 observer.startWatching();
432 }
433 }
Christopher Tate06efb532012-08-24 15:29:27 -0700434
Christopher Tate4dc7a682012-09-11 12:15:49 -0700435 ensureAndroidIdIsSet(userHandle);
436
Christopher Tate06efb532012-08-24 15:29:27 -0700437 startAsyncCachePopulation(userHandle);
438 }
439
440 class CachePrefetchThread extends Thread {
441 private int mUserHandle;
442
443 CachePrefetchThread(int userHandle) {
444 super("populate-settings-caches");
445 mUserHandle = userHandle;
446 }
447
448 @Override
449 public void run() {
450 fullyPopulateCaches(mUserHandle);
451 }
452 }
453
454 private void startAsyncCachePopulation(int userHandle) {
455 new CachePrefetchThread(userHandle).start();
456 }
457
458 private void fullyPopulateCaches(final int userHandle) {
459 DatabaseHelper dbHelper = mOpenHelpers.get(userHandle);
460 // Only populate the globals cache once, for the owning user
461 if (userHandle == UserHandle.USER_OWNER) {
462 fullyPopulateCache(dbHelper, TABLE_GLOBAL, sGlobalCache);
463 }
464 fullyPopulateCache(dbHelper, TABLE_SECURE, sSecureCaches.get(userHandle));
465 fullyPopulateCache(dbHelper, TABLE_SYSTEM, sSystemCaches.get(userHandle));
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -0700466 }
467
468 // Slurp all values (if sane in number & size) into cache.
Christopher Tate06efb532012-08-24 15:29:27 -0700469 private void fullyPopulateCache(DatabaseHelper dbHelper, String table, SettingsCache cache) {
470 SQLiteDatabase db = dbHelper.getReadableDatabase();
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -0700471 Cursor c = db.query(
472 table,
473 new String[] { Settings.NameValueTable.NAME, Settings.NameValueTable.VALUE },
474 null, null, null, null, null,
475 "" + (MAX_CACHE_ENTRIES + 1) /* limit */);
476 try {
477 synchronized (cache) {
Jesse Wilson0c7faee2011-02-10 11:33:19 -0800478 cache.evictAll();
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -0700479 cache.setFullyMatchesDisk(true); // optimistic
480 int rows = 0;
481 while (c.moveToNext()) {
482 rows++;
483 String name = c.getString(0);
484 String value = c.getString(1);
485 cache.populate(name, value);
486 }
487 if (rows > MAX_CACHE_ENTRIES) {
488 // Somewhat redundant, as removeEldestEntry() will
489 // have already done this, but to be explicit:
490 cache.setFullyMatchesDisk(false);
491 Log.d(TAG, "row count exceeds max cache entries for table " + table);
492 }
Dianne Hackborn40e9f292012-11-27 19:12:23 -0800493 if (LOCAL_LOGV) Log.d(TAG, "cache for settings table '" + table
494 + "' rows=" + rows + "; fullycached=" + cache.fullyMatchesDisk());
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -0700495 }
496 } finally {
497 c.close();
498 }
499 }
500
Christopher Tate4dc7a682012-09-11 12:15:49 -0700501 private boolean ensureAndroidIdIsSet(int userHandle) {
502 final Cursor c = queryForUser(Settings.Secure.CONTENT_URI,
Fred Quintanac70239e2009-12-17 10:28:33 -0800503 new String[] { Settings.NameValueTable.VALUE },
504 Settings.NameValueTable.NAME + "=?",
Christopher Tate4dc7a682012-09-11 12:15:49 -0700505 new String[] { Settings.Secure.ANDROID_ID }, null,
506 userHandle);
Fred Quintanac70239e2009-12-17 10:28:33 -0800507 try {
508 final String value = c.moveToNext() ? c.getString(0) : null;
509 if (value == null) {
Christopher Tate38e7a602013-09-03 16:57:34 -0700510 // sanity-check the user before touching the db
511 final UserInfo user = mUserManager.getUserInfo(userHandle);
512 if (user == null) {
513 // can happen due to races when deleting users; treat as benign
514 return false;
515 }
516
Nick Kralevich9bb4ec42010-09-24 11:48:37 -0700517 final SecureRandom random = new SecureRandom();
Fred Quintanac70239e2009-12-17 10:28:33 -0800518 final String newAndroidIdValue = Long.toHexString(random.nextLong());
Fred Quintanac70239e2009-12-17 10:28:33 -0800519 final ContentValues values = new ContentValues();
520 values.put(Settings.NameValueTable.NAME, Settings.Secure.ANDROID_ID);
521 values.put(Settings.NameValueTable.VALUE, newAndroidIdValue);
Christopher Tate4dc7a682012-09-11 12:15:49 -0700522 final Uri uri = insertForUser(Settings.Secure.CONTENT_URI, values, userHandle);
Fred Quintanac70239e2009-12-17 10:28:33 -0800523 if (uri == null) {
Christopher Tate4dc7a682012-09-11 12:15:49 -0700524 Slog.e(TAG, "Unable to generate new ANDROID_ID for user " + userHandle);
Fred Quintanac70239e2009-12-17 10:28:33 -0800525 return false;
526 }
Christopher Tate4dc7a682012-09-11 12:15:49 -0700527 Slog.d(TAG, "Generated and saved new ANDROID_ID [" + newAndroidIdValue
528 + "] for user " + userHandle);
Amith Yamasani5cdf7f52013-06-27 15:12:01 -0700529 // Write a dropbox entry if it's a restricted profile
Christopher Tate38e7a602013-09-03 16:57:34 -0700530 if (user.isRestricted()) {
Amith Yamasani5cdf7f52013-06-27 15:12:01 -0700531 DropBoxManager dbm = (DropBoxManager)
532 getContext().getSystemService(Context.DROPBOX_SERVICE);
533 if (dbm != null && dbm.isTagEnabled(DROPBOX_TAG_USERLOG)) {
534 dbm.addText(DROPBOX_TAG_USERLOG, System.currentTimeMillis()
535 + ",restricted_profile_ssaid,"
536 + newAndroidIdValue + "\n");
537 }
538 }
Fred Quintanac70239e2009-12-17 10:28:33 -0800539 }
540 return true;
Fred Quintanac70239e2009-12-17 10:28:33 -0800541 } finally {
542 c.close();
543 }
544 }
545
Christopher Tate06efb532012-08-24 15:29:27 -0700546 // Lazy-initialize the settings caches for non-primary users
547 private SettingsCache getOrConstructCache(int callingUser, SparseArray<SettingsCache> which) {
Christopher Tate78d2a662012-09-13 16:19:44 -0700548 getOrEstablishDatabase(callingUser); // ignore return value; we don't need it
549 return which.get(callingUser);
Christopher Tate06efb532012-08-24 15:29:27 -0700550 }
551
552 // Lazy initialize the database helper and caches for this user, if necessary
Christopher Tate78d2a662012-09-13 16:19:44 -0700553 private DatabaseHelper getOrEstablishDatabase(int callingUser) {
Christopher Tate0da13572013-10-13 17:34:49 -0700554 if (callingUser >= Process.SYSTEM_UID) {
555 if (USER_CHECK_THROWS) {
556 throw new IllegalArgumentException("Uid rather than user handle: " + callingUser);
557 } else {
558 Slog.wtf(TAG, "establish db for uid rather than user: " + callingUser);
559 }
560 }
561
Christopher Tate06efb532012-08-24 15:29:27 -0700562 long oldId = Binder.clearCallingIdentity();
563 try {
564 DatabaseHelper dbHelper = mOpenHelpers.get(callingUser);
565 if (null == dbHelper) {
Christopher Tate78d2a662012-09-13 16:19:44 -0700566 establishDbTracking(callingUser);
Christopher Tate06efb532012-08-24 15:29:27 -0700567 dbHelper = mOpenHelpers.get(callingUser);
568 }
569 return dbHelper;
570 } finally {
571 Binder.restoreCallingIdentity(oldId);
572 }
573 }
574
575 public SettingsCache cacheForTable(final int callingUser, String tableName) {
576 if (TABLE_SYSTEM.equals(tableName)) {
577 return getOrConstructCache(callingUser, sSystemCaches);
578 }
579 if (TABLE_SECURE.equals(tableName)) {
580 return getOrConstructCache(callingUser, sSecureCaches);
581 }
582 if (TABLE_GLOBAL.equals(tableName)) {
583 return sGlobalCache;
584 }
585 return null;
586 }
587
588 /**
589 * Used for wiping a whole cache on deletes when we're not
590 * sure what exactly was deleted or changed.
591 */
592 public void invalidateCache(final int callingUser, String tableName) {
593 SettingsCache cache = cacheForTable(callingUser, tableName);
594 if (cache == null) {
595 return;
596 }
597 synchronized (cache) {
598 cache.evictAll();
599 cache.mCacheFullyMatchesDisk = false;
600 }
601 }
602
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800603 /**
604 * Fast path that avoids the use of chatty remoted Cursors.
605 */
606 @Override
Jeff Sharkey911d7f42013-09-05 18:11:45 -0700607 public Bundle call(String method, String request, Bundle args) {
Christopher Tate06efb532012-08-24 15:29:27 -0700608 int callingUser = UserHandle.getCallingUserId();
609 if (args != null) {
610 int reqUser = args.getInt(Settings.CALL_METHOD_USER_KEY, callingUser);
611 if (reqUser != callingUser) {
Christopher Tated5fe1472012-09-10 15:48:38 -0700612 callingUser = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
613 Binder.getCallingUid(), reqUser, false, true,
614 "get/set setting for user", null);
615 if (LOCAL_LOGV) Slog.v(TAG, " access setting for user " + callingUser);
Christopher Tate06efb532012-08-24 15:29:27 -0700616 }
617 }
618
Christopher Tate61695ff2012-10-05 12:05:13 -0700619 // Note: we assume that get/put operations for moved-to-global names have already
620 // been directed to the new location on the caller side (otherwise we'd fix them
621 // up here).
622 DatabaseHelper dbHelper;
623 SettingsCache cache;
Christopher Tate06efb532012-08-24 15:29:27 -0700624
Christopher Tate61695ff2012-10-05 12:05:13 -0700625 // Get methods
626 if (Settings.CALL_METHOD_GET_SYSTEM.equals(method)) {
627 if (LOCAL_LOGV) Slog.v(TAG, "call(system:" + request + ") for " + callingUser);
628 dbHelper = getOrEstablishDatabase(callingUser);
629 cache = sSystemCaches.get(callingUser);
630 return lookupValue(dbHelper, TABLE_SYSTEM, cache, request);
631 }
632 if (Settings.CALL_METHOD_GET_SECURE.equals(method)) {
633 if (LOCAL_LOGV) Slog.v(TAG, "call(secure:" + request + ") for " + callingUser);
634 dbHelper = getOrEstablishDatabase(callingUser);
635 cache = sSecureCaches.get(callingUser);
636 return lookupValue(dbHelper, TABLE_SECURE, cache, request);
637 }
638 if (Settings.CALL_METHOD_GET_GLOBAL.equals(method)) {
639 if (LOCAL_LOGV) Slog.v(TAG, "call(global:" + request + ") for " + callingUser);
640 // fast path: owner db & cache are immutable after onCreate() so we need not
641 // guard on the attempt to look them up
642 return lookupValue(getOrEstablishDatabase(UserHandle.USER_OWNER), TABLE_GLOBAL,
643 sGlobalCache, request);
644 }
Christopher Tate06efb532012-08-24 15:29:27 -0700645
Christopher Tate61695ff2012-10-05 12:05:13 -0700646 // Put methods - new value is in the args bundle under the key named by
647 // the Settings.NameValueTable.VALUE static.
648 final String newValue = (args == null)
Dianne Hackborn961321f2013-02-05 17:22:41 -0800649 ? null : args.getString(Settings.NameValueTable.VALUE);
650
651 // Framework can't do automatic permission checking for calls, so we need
652 // to do it here.
653 if (getContext().checkCallingOrSelfPermission(android.Manifest.permission.WRITE_SETTINGS)
654 != PackageManager.PERMISSION_GRANTED) {
655 throw new SecurityException(
656 String.format("Permission denial: writing to settings requires %1$s",
657 android.Manifest.permission.WRITE_SETTINGS));
658 }
659
660 // Also need to take care of app op.
661 if (getAppOpsManager().noteOp(AppOpsManager.OP_WRITE_SETTINGS, Binder.getCallingUid(),
Jeff Sharkey911d7f42013-09-05 18:11:45 -0700662 getCallingPackage()) != AppOpsManager.MODE_ALLOWED) {
Dianne Hackborn961321f2013-02-05 17:22:41 -0800663 return null;
664 }
Christopher Tate06efb532012-08-24 15:29:27 -0700665
Christopher Tate61695ff2012-10-05 12:05:13 -0700666 final ContentValues values = new ContentValues();
667 values.put(Settings.NameValueTable.NAME, request);
668 values.put(Settings.NameValueTable.VALUE, newValue);
669 if (Settings.CALL_METHOD_PUT_SYSTEM.equals(method)) {
670 if (LOCAL_LOGV) Slog.v(TAG, "call_put(system:" + request + "=" + newValue + ") for " + callingUser);
671 insertForUser(Settings.System.CONTENT_URI, values, callingUser);
672 } else if (Settings.CALL_METHOD_PUT_SECURE.equals(method)) {
673 if (LOCAL_LOGV) Slog.v(TAG, "call_put(secure:" + request + "=" + newValue + ") for " + callingUser);
674 insertForUser(Settings.Secure.CONTENT_URI, values, callingUser);
675 } else if (Settings.CALL_METHOD_PUT_GLOBAL.equals(method)) {
676 if (LOCAL_LOGV) Slog.v(TAG, "call_put(global:" + request + "=" + newValue + ") for " + callingUser);
677 insertForUser(Settings.Global.CONTENT_URI, values, callingUser);
678 } else {
679 Slog.w(TAG, "call() with invalid method: " + method);
Christopher Tate06efb532012-08-24 15:29:27 -0700680 }
681
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800682 return null;
683 }
684
685 // Looks up value 'key' in 'table' and returns either a single-pair Bundle,
686 // possibly with a null value, or null on failure.
Christopher Tate06efb532012-08-24 15:29:27 -0700687 private Bundle lookupValue(DatabaseHelper dbHelper, String table,
688 final SettingsCache cache, String key) {
689 if (cache == null) {
690 Slog.e(TAG, "cache is null for user " + UserHandle.getCallingUserId() + " : key=" + key);
691 return null;
692 }
Brad Fitzpatrick1bd62bd2010-03-08 18:30:52 -0800693 synchronized (cache) {
Jesse Wilson0c7faee2011-02-10 11:33:19 -0800694 Bundle value = cache.get(key);
695 if (value != null) {
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -0700696 if (value != TOO_LARGE_TO_CACHE_MARKER) {
697 return value;
698 }
699 // else we fall through and read the value from disk
700 } else if (cache.fullyMatchesDisk()) {
701 // Fast path (very common). Don't even try touch disk
702 // if we know we've slurped it all in. Trying to
703 // touch the disk would mean waiting for yaffs2 to
704 // give us access, which could takes hundreds of
705 // milliseconds. And we're very likely being called
706 // from somebody's UI thread...
707 return NULL_SETTING;
Brad Fitzpatrick1bd62bd2010-03-08 18:30:52 -0800708 }
709 }
710
Christopher Tate06efb532012-08-24 15:29:27 -0700711 SQLiteDatabase db = dbHelper.getReadableDatabase();
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800712 Cursor cursor = null;
713 try {
714 cursor = db.query(table, COLUMN_VALUE, "name=?", new String[]{key},
715 null, null, null, null);
716 if (cursor != null && cursor.getCount() == 1) {
717 cursor.moveToFirst();
Brad Fitzpatrick342984a2010-03-09 16:59:30 -0800718 return cache.putIfAbsent(key, cursor.getString(0));
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800719 }
720 } catch (SQLiteException e) {
721 Log.w(TAG, "settings lookup error", e);
722 return null;
723 } finally {
724 if (cursor != null) cursor.close();
725 }
Brad Fitzpatrick342984a2010-03-09 16:59:30 -0800726 cache.putIfAbsent(key, null);
Brad Fitzpatrick1bd62bd2010-03-08 18:30:52 -0800727 return NULL_SETTING;
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800728 }
729
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700730 @Override
731 public Cursor query(Uri url, String[] select, String where, String[] whereArgs, String sort) {
Christopher Tate4dc7a682012-09-11 12:15:49 -0700732 return queryForUser(url, select, where, whereArgs, sort, UserHandle.getCallingUserId());
733 }
734
Christopher Tateb7564452012-09-19 16:21:18 -0700735 private Cursor queryForUser(Uri url, String[] select, String where, String[] whereArgs,
Christopher Tate4dc7a682012-09-11 12:15:49 -0700736 String sort, int forUser) {
737 if (LOCAL_LOGV) Slog.v(TAG, "query(" + url + ") for user " + forUser);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700738 SqlArguments args = new SqlArguments(url, where, whereArgs);
Christopher Tate06efb532012-08-24 15:29:27 -0700739 DatabaseHelper dbH;
Christopher Tate78d2a662012-09-13 16:19:44 -0700740 dbH = getOrEstablishDatabase(
741 TABLE_GLOBAL.equals(args.table) ? UserHandle.USER_OWNER : forUser);
Christopher Tate06efb532012-08-24 15:29:27 -0700742 SQLiteDatabase db = dbH.getReadableDatabase();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800744 // The favorites table was moved from this provider to a provider inside Home
745 // Home still need to query this table to upgrade from pre-cupcake builds
746 // However, a cupcake+ build with no data does not contain this table which will
747 // cause an exception in the SQL stack. The following line is a special case to
748 // let the caller of the query have a chance to recover and avoid the exception
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800749 if (TABLE_FAVORITES.equals(args.table)) {
750 return null;
751 } else if (TABLE_OLD_FAVORITES.equals(args.table)) {
752 args.table = TABLE_FAVORITES;
753 Cursor cursor = db.rawQuery("PRAGMA table_info(favorites);", null);
754 if (cursor != null) {
755 boolean exists = cursor.getCount() > 0;
756 cursor.close();
757 if (!exists) return null;
758 } else {
759 return null;
760 }
761 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800762
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700763 SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
764 qb.setTables(args.table);
765
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700766 Cursor ret = qb.query(db, select, args.where, args.args, null, null, sort);
Christopher Tateafccaa82012-10-03 17:41:51 -0700767 // the default Cursor interface does not support per-user observation
768 try {
769 AbstractCursor c = (AbstractCursor) ret;
770 c.setNotificationUri(getContext().getContentResolver(), url, forUser);
771 } catch (ClassCastException e) {
772 // details of the concrete Cursor implementation have changed and this code has
773 // not been updated to match -- complain and fail hard.
774 Log.wtf(TAG, "Incompatible cursor derivation!");
775 throw e;
776 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700777 return ret;
778 }
779
780 @Override
781 public String getType(Uri url) {
782 // If SqlArguments supplies a where clause, then it must be an item
783 // (because we aren't supplying our own where clause).
784 SqlArguments args = new SqlArguments(url, null, null);
785 if (TextUtils.isEmpty(args.where)) {
786 return "vnd.android.cursor.dir/" + args.table;
787 } else {
788 return "vnd.android.cursor.item/" + args.table;
789 }
790 }
791
792 @Override
793 public int bulkInsert(Uri uri, ContentValues[] values) {
Christopher Tate06efb532012-08-24 15:29:27 -0700794 final int callingUser = UserHandle.getCallingUserId();
795 if (LOCAL_LOGV) Slog.v(TAG, "bulkInsert() for user " + callingUser);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700796 SqlArguments args = new SqlArguments(uri);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797 if (TABLE_FAVORITES.equals(args.table)) {
798 return 0;
799 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700800 checkWritePermissions(args);
Christopher Tate06efb532012-08-24 15:29:27 -0700801 SettingsCache cache = cacheForTable(callingUser, args.table);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700802
Christopher Tate06efb532012-08-24 15:29:27 -0700803 final AtomicInteger mutationCount = sKnownMutationsInFlight.get(callingUser);
804 mutationCount.incrementAndGet();
Christopher Tate78d2a662012-09-13 16:19:44 -0700805 DatabaseHelper dbH = getOrEstablishDatabase(
806 TABLE_GLOBAL.equals(args.table) ? UserHandle.USER_OWNER : callingUser);
Christopher Tate06efb532012-08-24 15:29:27 -0700807 SQLiteDatabase db = dbH.getWritableDatabase();
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700808 db.beginTransaction();
809 try {
810 int numValues = values.length;
811 for (int i = 0; i < numValues; i++) {
Julia Reynolds5e458dd2014-07-07 16:07:01 -0400812 checkUserRestrictions(values[i].getAsString(Settings.Secure.NAME));
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700813 if (db.insert(args.table, null, values[i]) < 0) return 0;
Brad Fitzpatrick1bd62bd2010-03-08 18:30:52 -0800814 SettingsCache.populate(cache, values[i]);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700815 if (LOCAL_LOGV) Log.v(TAG, args.table + " <- " + values[i]);
816 }
817 db.setTransactionSuccessful();
818 } finally {
819 db.endTransaction();
Christopher Tate06efb532012-08-24 15:29:27 -0700820 mutationCount.decrementAndGet();
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700821 }
822
Christopher Tate06efb532012-08-24 15:29:27 -0700823 sendNotify(uri, callingUser);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700824 return values.length;
825 }
826
Mike Lockwoodbd2a7122009-04-02 23:41:33 -0700827 /*
828 * Used to parse changes to the value of Settings.Secure.LOCATION_PROVIDERS_ALLOWED.
829 * This setting contains a list of the currently enabled location providers.
830 * But helper functions in android.providers.Settings can enable or disable
831 * a single provider by using a "+" or "-" prefix before the provider name.
Brad Fitzpatrick1bd62bd2010-03-08 18:30:52 -0800832 *
833 * @returns whether the database needs to be updated or not, also modifying
834 * 'initialValues' if needed.
Mike Lockwoodbd2a7122009-04-02 23:41:33 -0700835 */
Maggie Benthalld2726582013-02-04 13:28:19 -0500836 private boolean parseProviderList(Uri url, ContentValues initialValues, int desiredUser) {
Mike Lockwoodbd2a7122009-04-02 23:41:33 -0700837 String value = initialValues.getAsString(Settings.Secure.VALUE);
838 String newProviders = null;
839 if (value != null && value.length() > 1) {
840 char prefix = value.charAt(0);
841 if (prefix == '+' || prefix == '-') {
842 // skip prefix
843 value = value.substring(1);
844
845 // read list of enabled providers into "providers"
846 String providers = "";
847 String[] columns = {Settings.Secure.VALUE};
848 String where = Settings.Secure.NAME + "=\'" + Settings.Secure.LOCATION_PROVIDERS_ALLOWED + "\'";
Maggie Benthalld2726582013-02-04 13:28:19 -0500849 Cursor cursor = queryForUser(url, columns, where, null, null, desiredUser);
Mike Lockwoodbd2a7122009-04-02 23:41:33 -0700850 if (cursor != null && cursor.getCount() == 1) {
851 try {
852 cursor.moveToFirst();
853 providers = cursor.getString(0);
854 } finally {
855 cursor.close();
856 }
857 }
858
859 int index = providers.indexOf(value);
860 int end = index + value.length();
861 // check for commas to avoid matching on partial string
862 if (index > 0 && providers.charAt(index - 1) != ',') index = -1;
863 if (end < providers.length() && providers.charAt(end) != ',') index = -1;
864
865 if (prefix == '+' && index < 0) {
866 // append the provider to the list if not present
867 if (providers.length() == 0) {
868 newProviders = value;
869 } else {
870 newProviders = providers + ',' + value;
871 }
872 } else if (prefix == '-' && index >= 0) {
873 // remove the provider from the list if present
Mike Lockwoodbdc7f892010-04-21 18:24:57 -0400874 // remove leading or trailing comma
875 if (index > 0) {
876 index--;
877 } else if (end < providers.length()) {
878 end++;
879 }
Mike Lockwoodbd2a7122009-04-02 23:41:33 -0700880
881 newProviders = providers.substring(0, index);
882 if (end < providers.length()) {
883 newProviders += providers.substring(end);
884 }
885 } else {
886 // nothing changed, so no need to update the database
887 return false;
888 }
889
890 if (newProviders != null) {
891 initialValues.put(Settings.Secure.VALUE, newProviders);
892 }
893 }
894 }
Brad Fitzpatrick1bd62bd2010-03-08 18:30:52 -0800895
Mike Lockwoodbd2a7122009-04-02 23:41:33 -0700896 return true;
897 }
898
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700899 @Override
900 public Uri insert(Uri url, ContentValues initialValues) {
Christopher Tate06efb532012-08-24 15:29:27 -0700901 return insertForUser(url, initialValues, UserHandle.getCallingUserId());
902 }
903
904 // Settings.put*ForUser() always winds up here, so this is where we apply
905 // policy around permission to write settings for other users.
906 private Uri insertForUser(Uri url, ContentValues initialValues, int desiredUserHandle) {
907 final int callingUser = UserHandle.getCallingUserId();
908 if (callingUser != desiredUserHandle) {
Christopher Tate4dc7a682012-09-11 12:15:49 -0700909 getContext().enforceCallingOrSelfPermission(
Christopher Tate06efb532012-08-24 15:29:27 -0700910 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
911 "Not permitted to access settings for other users");
912 }
913
914 if (LOCAL_LOGV) Slog.v(TAG, "insert(" + url + ") for user " + desiredUserHandle
915 + " by " + callingUser);
916
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700917 SqlArguments args = new SqlArguments(url);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800918 if (TABLE_FAVORITES.equals(args.table)) {
919 return null;
920 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700921
Mike Lockwoodbd2a7122009-04-02 23:41:33 -0700922 // Special case LOCATION_PROVIDERS_ALLOWED.
923 // Support enabling/disabling a single provider (using "+" or "-" prefix)
924 String name = initialValues.getAsString(Settings.Secure.NAME);
925 if (Settings.Secure.LOCATION_PROVIDERS_ALLOWED.equals(name)) {
Maggie Benthalld2726582013-02-04 13:28:19 -0500926 if (!parseProviderList(url, initialValues, desiredUserHandle)) return null;
Mike Lockwoodbd2a7122009-04-02 23:41:33 -0700927 }
928
Christopher Tatec221d2b2012-10-03 18:33:52 -0700929 // If this is an insert() of a key that has been migrated to the global store,
930 // redirect the operation to that store
931 if (name != null) {
932 if (sSecureGlobalKeys.contains(name) || sSystemGlobalKeys.contains(name)) {
933 if (!TABLE_GLOBAL.equals(args.table)) {
934 if (LOCAL_LOGV) Slog.i(TAG, "Rewrite of insert() of now-global key " + name);
935 }
936 args.table = TABLE_GLOBAL; // next condition will rewrite the user handle
937 }
938 }
939
Christopher Tate34637e52012-10-04 15:00:00 -0700940 // Check write permissions only after determining which table the insert will touch
941 checkWritePermissions(args);
942
Julia Reynolds5e458dd2014-07-07 16:07:01 -0400943 checkUserRestrictions(name);
944
Christopher Tate06efb532012-08-24 15:29:27 -0700945 // The global table is stored under the owner, always
946 if (TABLE_GLOBAL.equals(args.table)) {
947 desiredUserHandle = UserHandle.USER_OWNER;
948 }
949
950 SettingsCache cache = cacheForTable(desiredUserHandle, args.table);
Brad Fitzpatrick547a96b2010-03-09 17:58:53 -0800951 String value = initialValues.getAsString(Settings.NameValueTable.VALUE);
952 if (SettingsCache.isRedundantSetValue(cache, name, value)) {
953 return Uri.withAppendedPath(url, name);
954 }
955
Christopher Tate06efb532012-08-24 15:29:27 -0700956 final AtomicInteger mutationCount = sKnownMutationsInFlight.get(desiredUserHandle);
957 mutationCount.incrementAndGet();
Christopher Tate78d2a662012-09-13 16:19:44 -0700958 DatabaseHelper dbH = getOrEstablishDatabase(desiredUserHandle);
Christopher Tate06efb532012-08-24 15:29:27 -0700959 SQLiteDatabase db = dbH.getWritableDatabase();
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700960 final long rowId = db.insert(args.table, null, initialValues);
Christopher Tate06efb532012-08-24 15:29:27 -0700961 mutationCount.decrementAndGet();
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700962 if (rowId <= 0) return null;
963
Brad Fitzpatrick1bd62bd2010-03-08 18:30:52 -0800964 SettingsCache.populate(cache, initialValues); // before we notify
965
Christopher Tate78d2a662012-09-13 16:19:44 -0700966 if (LOCAL_LOGV) Log.v(TAG, args.table + " <- " + initialValues
967 + " for user " + desiredUserHandle);
Christopher Tate06efb532012-08-24 15:29:27 -0700968 // Note that we use the original url here, not the potentially-rewritten table name
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700969 url = getUriFor(url, initialValues, rowId);
Christopher Tate06efb532012-08-24 15:29:27 -0700970 sendNotify(url, desiredUserHandle);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700971 return url;
972 }
973
974 @Override
975 public int delete(Uri url, String where, String[] whereArgs) {
Christopher Tate4dc7a682012-09-11 12:15:49 -0700976 int callingUser = UserHandle.getCallingUserId();
Christopher Tate06efb532012-08-24 15:29:27 -0700977 if (LOCAL_LOGV) Slog.v(TAG, "delete() for user " + callingUser);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700978 SqlArguments args = new SqlArguments(url, where, whereArgs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 if (TABLE_FAVORITES.equals(args.table)) {
980 return 0;
981 } else if (TABLE_OLD_FAVORITES.equals(args.table)) {
982 args.table = TABLE_FAVORITES;
Christopher Tate4dc7a682012-09-11 12:15:49 -0700983 } else if (TABLE_GLOBAL.equals(args.table)) {
984 callingUser = UserHandle.USER_OWNER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800985 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700986 checkWritePermissions(args);
987
Christopher Tate06efb532012-08-24 15:29:27 -0700988 final AtomicInteger mutationCount = sKnownMutationsInFlight.get(callingUser);
989 mutationCount.incrementAndGet();
Christopher Tate78d2a662012-09-13 16:19:44 -0700990 DatabaseHelper dbH = getOrEstablishDatabase(callingUser);
Christopher Tate06efb532012-08-24 15:29:27 -0700991 SQLiteDatabase db = dbH.getWritableDatabase();
992 int count = db.delete(args.table, args.where, args.args);
993 mutationCount.decrementAndGet();
994 if (count > 0) {
995 invalidateCache(callingUser, args.table); // before we notify
996 sendNotify(url, callingUser);
997 }
998 startAsyncCachePopulation(callingUser);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700999 if (LOCAL_LOGV) Log.v(TAG, args.table + ": " + count + " row(s) deleted");
1000 return count;
1001 }
1002
1003 @Override
1004 public int update(Uri url, ContentValues initialValues, String where, String[] whereArgs) {
Christopher Tate06efb532012-08-24 15:29:27 -07001005 // NOTE: update() is never called by the front-end Settings API, and updates that
1006 // wind up affecting rows in Secure that are globally shared will not have the
1007 // intended effect (the update will be invisible to the rest of the system).
1008 // This should have no practical effect, since writes to the Secure db can only
1009 // be done by system code, and that code should be using the correct API up front.
Christopher Tate4dc7a682012-09-11 12:15:49 -07001010 int callingUser = UserHandle.getCallingUserId();
Christopher Tate06efb532012-08-24 15:29:27 -07001011 if (LOCAL_LOGV) Slog.v(TAG, "update() for user " + callingUser);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001012 SqlArguments args = new SqlArguments(url, where, whereArgs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001013 if (TABLE_FAVORITES.equals(args.table)) {
1014 return 0;
Christopher Tate4dc7a682012-09-11 12:15:49 -07001015 } else if (TABLE_GLOBAL.equals(args.table)) {
1016 callingUser = UserHandle.USER_OWNER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001018 checkWritePermissions(args);
Julia Reynolds5e458dd2014-07-07 16:07:01 -04001019 checkUserRestrictions(initialValues.getAsString(Settings.Secure.NAME));
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001020
Christopher Tate06efb532012-08-24 15:29:27 -07001021 final AtomicInteger mutationCount = sKnownMutationsInFlight.get(callingUser);
1022 mutationCount.incrementAndGet();
Christopher Tate78d2a662012-09-13 16:19:44 -07001023 DatabaseHelper dbH = getOrEstablishDatabase(callingUser);
Christopher Tate06efb532012-08-24 15:29:27 -07001024 SQLiteDatabase db = dbH.getWritableDatabase();
1025 int count = db.update(args.table, initialValues, args.where, args.args);
1026 mutationCount.decrementAndGet();
1027 if (count > 0) {
1028 invalidateCache(callingUser, args.table); // before we notify
1029 sendNotify(url, callingUser);
1030 }
1031 startAsyncCachePopulation(callingUser);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001032 if (LOCAL_LOGV) Log.v(TAG, args.table + ": " + count + " row(s) <- " + initialValues);
1033 return count;
1034 }
1035
1036 @Override
1037 public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
1038
1039 /*
1040 * When a client attempts to openFile the default ringtone or
1041 * notification setting Uri, we will proxy the call to the current
Mike Lockwood853ad6f2013-04-29 16:12:23 -07001042 * default ringtone's Uri (if it is in the media provider).
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -07001043 */
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001044 int ringtoneType = RingtoneManager.getDefaultType(uri);
1045 // Above call returns -1 if the Uri doesn't match a default type
1046 if (ringtoneType != -1) {
1047 Context context = getContext();
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -07001048
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001049 // Get the current value for the default sound
1050 Uri soundUri = RingtoneManager.getActualDefaultRingtoneUri(context, ringtoneType);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001051
Marco Nelissen69f593c2009-07-28 09:55:04 -07001052 if (soundUri != null) {
Mike Lockwood853ad6f2013-04-29 16:12:23 -07001053 // Proxy the openFile call to media provider
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001054 String authority = soundUri.getAuthority();
Mike Lockwood853ad6f2013-04-29 16:12:23 -07001055 if (authority.equals(MediaStore.AUTHORITY)) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001056 return context.getContentResolver().openFileDescriptor(soundUri, mode);
1057 }
1058 }
1059 }
1060
1061 return super.openFile(uri, mode);
1062 }
Marco Nelissen69f593c2009-07-28 09:55:04 -07001063
1064 @Override
1065 public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException {
1066
1067 /*
1068 * When a client attempts to openFile the default ringtone or
1069 * notification setting Uri, we will proxy the call to the current
Mike Lockwood853ad6f2013-04-29 16:12:23 -07001070 * default ringtone's Uri (if it is in the media provider).
Marco Nelissen69f593c2009-07-28 09:55:04 -07001071 */
1072 int ringtoneType = RingtoneManager.getDefaultType(uri);
1073 // Above call returns -1 if the Uri doesn't match a default type
1074 if (ringtoneType != -1) {
1075 Context context = getContext();
1076
1077 // Get the current value for the default sound
1078 Uri soundUri = RingtoneManager.getActualDefaultRingtoneUri(context, ringtoneType);
1079
1080 if (soundUri != null) {
Mike Lockwood853ad6f2013-04-29 16:12:23 -07001081 // Proxy the openFile call to media provider
Marco Nelissen69f593c2009-07-28 09:55:04 -07001082 String authority = soundUri.getAuthority();
Mike Lockwood853ad6f2013-04-29 16:12:23 -07001083 if (authority.equals(MediaStore.AUTHORITY)) {
Marco Nelissen69f593c2009-07-28 09:55:04 -07001084 ParcelFileDescriptor pfd = null;
1085 try {
1086 pfd = context.getContentResolver().openFileDescriptor(soundUri, mode);
1087 return new AssetFileDescriptor(pfd, 0, -1);
1088 } catch (FileNotFoundException ex) {
1089 // fall through and open the fallback ringtone below
1090 }
1091 }
1092
1093 try {
1094 return super.openAssetFile(soundUri, mode);
1095 } catch (FileNotFoundException ex) {
1096 // Since a non-null Uri was specified, but couldn't be opened,
1097 // fall back to the built-in ringtone.
1098 return context.getResources().openRawResourceFd(
1099 com.android.internal.R.raw.fallbackring);
1100 }
1101 }
1102 // no need to fall through and have openFile() try again, since we
1103 // already know that will fail.
1104 throw new FileNotFoundException(); // or return null ?
1105 }
1106
1107 // Note that this will end up calling openFile() above.
1108 return super.openAssetFile(uri, mode);
1109 }
Brad Fitzpatrick1bd62bd2010-03-08 18:30:52 -08001110
1111 /**
1112 * In-memory LRU Cache of system and secure settings, along with
1113 * associated helper functions to keep cache coherent with the
1114 * database.
1115 */
Jesse Wilson0c7faee2011-02-10 11:33:19 -08001116 private static final class SettingsCache extends LruCache<String, Bundle> {
Brad Fitzpatrick342984a2010-03-09 16:59:30 -08001117
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -07001118 private final String mCacheName;
1119 private boolean mCacheFullyMatchesDisk = false; // has the whole database slurped.
1120
1121 public SettingsCache(String name) {
Jesse Wilson0c7faee2011-02-10 11:33:19 -08001122 super(MAX_CACHE_ENTRIES);
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -07001123 mCacheName = name;
1124 }
1125
1126 /**
1127 * Is the whole database table slurped into this cache?
1128 */
1129 public boolean fullyMatchesDisk() {
1130 synchronized (this) {
1131 return mCacheFullyMatchesDisk;
1132 }
1133 }
1134
1135 public void setFullyMatchesDisk(boolean value) {
1136 synchronized (this) {
1137 mCacheFullyMatchesDisk = value;
1138 }
Brad Fitzpatrick1bd62bd2010-03-08 18:30:52 -08001139 }
1140
1141 @Override
Jesse Wilson32c80a22011-02-25 17:28:41 -08001142 protected void entryRemoved(boolean evicted, String key, Bundle oldValue, Bundle newValue) {
1143 if (evicted) {
1144 mCacheFullyMatchesDisk = false;
1145 }
Brad Fitzpatrick1bd62bd2010-03-08 18:30:52 -08001146 }
1147
Brad Fitzpatrick342984a2010-03-09 16:59:30 -08001148 /**
1149 * Atomic cache population, conditional on size of value and if
1150 * we lost a race.
1151 *
1152 * @returns a Bundle to send back to the client from call(), even
1153 * if we lost the race.
1154 */
1155 public Bundle putIfAbsent(String key, String value) {
1156 Bundle bundle = (value == null) ? NULL_SETTING : Bundle.forPair("value", value);
1157 if (value == null || value.length() <= MAX_CACHE_ENTRY_SIZE) {
1158 synchronized (this) {
Jesse Wilson0c7faee2011-02-10 11:33:19 -08001159 if (get(key) == null) {
Brad Fitzpatrick342984a2010-03-09 16:59:30 -08001160 put(key, bundle);
1161 }
Brad Fitzpatrick1bd62bd2010-03-08 18:30:52 -08001162 }
Brad Fitzpatrick1bd62bd2010-03-08 18:30:52 -08001163 }
Brad Fitzpatrick342984a2010-03-09 16:59:30 -08001164 return bundle;
Brad Fitzpatrick1bd62bd2010-03-08 18:30:52 -08001165 }
1166
Brad Fitzpatrick1bd62bd2010-03-08 18:30:52 -08001167 /**
1168 * Populates a key in a given (possibly-null) cache.
1169 */
1170 public static void populate(SettingsCache cache, ContentValues contentValues) {
1171 if (cache == null) {
1172 return;
1173 }
1174 String name = contentValues.getAsString(Settings.NameValueTable.NAME);
1175 if (name == null) {
1176 Log.w(TAG, "null name populating settings cache.");
1177 return;
1178 }
1179 String value = contentValues.getAsString(Settings.NameValueTable.VALUE);
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -07001180 cache.populate(name, value);
1181 }
1182
1183 public void populate(String name, String value) {
1184 synchronized (this) {
Brad Fitzpatrick342984a2010-03-09 16:59:30 -08001185 if (value == null || value.length() <= MAX_CACHE_ENTRY_SIZE) {
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -07001186 put(name, Bundle.forPair(Settings.NameValueTable.VALUE, value));
Brad Fitzpatrick342984a2010-03-09 16:59:30 -08001187 } else {
Brad Fitzpatrickf366a9b2010-08-24 16:14:07 -07001188 put(name, TOO_LARGE_TO_CACHE_MARKER);
Brad Fitzpatrick342984a2010-03-09 16:59:30 -08001189 }
Brad Fitzpatrick1bd62bd2010-03-08 18:30:52 -08001190 }
1191 }
1192
1193 /**
Brad Fitzpatrick547a96b2010-03-09 17:58:53 -08001194 * For suppressing duplicate/redundant settings inserts early,
1195 * checking our cache first (but without faulting it in),
1196 * before going to sqlite with the mutation.
1197 */
1198 public static boolean isRedundantSetValue(SettingsCache cache, String name, String value) {
1199 if (cache == null) return false;
1200 synchronized (cache) {
1201 Bundle bundle = cache.get(name);
1202 if (bundle == null) return false;
1203 String oldValue = bundle.getPairValue();
1204 if (oldValue == null && value == null) return true;
1205 if ((oldValue == null) != (value == null)) return false;
1206 return oldValue.equals(value);
1207 }
1208 }
Brad Fitzpatrick1bd62bd2010-03-08 18:30:52 -08001209 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001210}