Skip to content

Commit d0f1993

Browse files
Christopher TateAndroid (Google) Code Review
authored andcommitted
Merge "Make sure settings writes are permission checked correctly" into jb-mr1-dev
2 parents 7ef38ea + 61695ff commit d0f1993

File tree

1 file changed

+45
-52
lines changed

1 file changed

+45
-52
lines changed

packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -556,59 +556,52 @@ public Bundle call(String method, String request, Bundle args) {
556556
}
557557
}
558558

559-
// Okay, permission checks have cleared. Reset to our own identity so we can
560-
// manipulate all users' data with impunity.
561-
long oldId = Binder.clearCallingIdentity();
562-
try {
563-
// Note: we assume that get/put operations for moved-to-global names have already
564-
// been directed to the new location on the caller side (otherwise we'd fix them
565-
// up here).
566-
DatabaseHelper dbHelper;
567-
SettingsCache cache;
568-
569-
// Get methods
570-
if (Settings.CALL_METHOD_GET_SYSTEM.equals(method)) {
571-
if (LOCAL_LOGV) Slog.v(TAG, "call(system:" + request + ") for " + callingUser);
572-
dbHelper = getOrEstablishDatabase(callingUser);
573-
cache = sSystemCaches.get(callingUser);
574-
return lookupValue(dbHelper, TABLE_SYSTEM, cache, request);
575-
}
576-
if (Settings.CALL_METHOD_GET_SECURE.equals(method)) {
577-
if (LOCAL_LOGV) Slog.v(TAG, "call(secure:" + request + ") for " + callingUser);
578-
dbHelper = getOrEstablishDatabase(callingUser);
579-
cache = sSecureCaches.get(callingUser);
580-
return lookupValue(dbHelper, TABLE_SECURE, cache, request);
581-
}
582-
if (Settings.CALL_METHOD_GET_GLOBAL.equals(method)) {
583-
if (LOCAL_LOGV) Slog.v(TAG, "call(global:" + request + ") for " + callingUser);
584-
// fast path: owner db & cache are immutable after onCreate() so we need not
585-
// guard on the attempt to look them up
586-
return lookupValue(getOrEstablishDatabase(UserHandle.USER_OWNER), TABLE_GLOBAL,
587-
sGlobalCache, request);
588-
}
559+
// Note: we assume that get/put operations for moved-to-global names have already
560+
// been directed to the new location on the caller side (otherwise we'd fix them
561+
// up here).
562+
DatabaseHelper dbHelper;
563+
SettingsCache cache;
564+
565+
// Get methods
566+
if (Settings.CALL_METHOD_GET_SYSTEM.equals(method)) {
567+
if (LOCAL_LOGV) Slog.v(TAG, "call(system:" + request + ") for " + callingUser);
568+
dbHelper = getOrEstablishDatabase(callingUser);
569+
cache = sSystemCaches.get(callingUser);
570+
return lookupValue(dbHelper, TABLE_SYSTEM, cache, request);
571+
}
572+
if (Settings.CALL_METHOD_GET_SECURE.equals(method)) {
573+
if (LOCAL_LOGV) Slog.v(TAG, "call(secure:" + request + ") for " + callingUser);
574+
dbHelper = getOrEstablishDatabase(callingUser);
575+
cache = sSecureCaches.get(callingUser);
576+
return lookupValue(dbHelper, TABLE_SECURE, cache, request);
577+
}
578+
if (Settings.CALL_METHOD_GET_GLOBAL.equals(method)) {
579+
if (LOCAL_LOGV) Slog.v(TAG, "call(global:" + request + ") for " + callingUser);
580+
// fast path: owner db & cache are immutable after onCreate() so we need not
581+
// guard on the attempt to look them up
582+
return lookupValue(getOrEstablishDatabase(UserHandle.USER_OWNER), TABLE_GLOBAL,
583+
sGlobalCache, request);
584+
}
589585

590-
// Put methods - new value is in the args bundle under the key named by
591-
// the Settings.NameValueTable.VALUE static.
592-
final String newValue = (args == null)
593-
? null : args.getString(Settings.NameValueTable.VALUE);
594-
595-
final ContentValues values = new ContentValues();
596-
values.put(Settings.NameValueTable.NAME, request);
597-
values.put(Settings.NameValueTable.VALUE, newValue);
598-
if (Settings.CALL_METHOD_PUT_SYSTEM.equals(method)) {
599-
if (LOCAL_LOGV) Slog.v(TAG, "call_put(system:" + request + "=" + newValue + ") for " + callingUser);
600-
insertForUser(Settings.System.CONTENT_URI, values, callingUser);
601-
} else if (Settings.CALL_METHOD_PUT_SECURE.equals(method)) {
602-
if (LOCAL_LOGV) Slog.v(TAG, "call_put(secure:" + request + "=" + newValue + ") for " + callingUser);
603-
insertForUser(Settings.Secure.CONTENT_URI, values, callingUser);
604-
} else if (Settings.CALL_METHOD_PUT_GLOBAL.equals(method)) {
605-
if (LOCAL_LOGV) Slog.v(TAG, "call_put(global:" + request + "=" + newValue + ") for " + callingUser);
606-
insertForUser(Settings.Global.CONTENT_URI, values, callingUser);
607-
} else {
608-
Slog.w(TAG, "call() with invalid method: " + method);
609-
}
610-
} finally {
611-
Binder.restoreCallingIdentity(oldId);
586+
// Put methods - new value is in the args bundle under the key named by
587+
// the Settings.NameValueTable.VALUE static.
588+
final String newValue = (args == null)
589+
? null : args.getString(Settings.NameValueTable.VALUE);
590+
591+
final ContentValues values = new ContentValues();
592+
values.put(Settings.NameValueTable.NAME, request);
593+
values.put(Settings.NameValueTable.VALUE, newValue);
594+
if (Settings.CALL_METHOD_PUT_SYSTEM.equals(method)) {
595+
if (LOCAL_LOGV) Slog.v(TAG, "call_put(system:" + request + "=" + newValue + ") for " + callingUser);
596+
insertForUser(Settings.System.CONTENT_URI, values, callingUser);
597+
} else if (Settings.CALL_METHOD_PUT_SECURE.equals(method)) {
598+
if (LOCAL_LOGV) Slog.v(TAG, "call_put(secure:" + request + "=" + newValue + ") for " + callingUser);
599+
insertForUser(Settings.Secure.CONTENT_URI, values, callingUser);
600+
} else if (Settings.CALL_METHOD_PUT_GLOBAL.equals(method)) {
601+
if (LOCAL_LOGV) Slog.v(TAG, "call_put(global:" + request + "=" + newValue + ") for " + callingUser);
602+
insertForUser(Settings.Global.CONTENT_URI, values, callingUser);
603+
} else {
604+
Slog.w(TAG, "call() with invalid method: " + method);
612605
}
613606

614607
return null;

0 commit comments

Comments
 (0)