Miscellaneous fixes for Settings
(1) It's okay to write literal null as a settings element value
(2) Properly convey the user handle in the put-for-user variant
Bug 7137201
Bug 7139826
Change-Id: I0ed77d65e8377f0e0580a2668f10b7167ad34928
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 841a076..1739205 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -739,6 +739,7 @@
try {
Bundle arg = new Bundle();
arg.putString(Settings.NameValueTable.VALUE, value);
+ arg.putInt(CALL_METHOD_USER_KEY, userHandle);
IContentProvider cp = lazyGetProvider(cr);
cp.call(mCallSetCommand, name, arg);
} catch (RemoteException e) {
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
index f859f41..6773482 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
@@ -22,6 +22,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
+import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.backup.BackupManager;
import android.content.BroadcastReceiver;
@@ -60,7 +61,7 @@
public class SettingsProvider extends ContentProvider {
private static final String TAG = "SettingsProvider";
- private static final boolean LOCAL_LOGV = false;
+ private static final boolean LOCAL_LOGV = true;
private static final String TABLE_SYSTEM = "system";
private static final String TABLE_SECURE = "secure";
@@ -621,24 +622,10 @@
if (args != null) {
int reqUser = args.getInt(Settings.CALL_METHOD_USER_KEY, callingUser);
if (reqUser != callingUser) {
- getContext().enforceCallingPermission(
- android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
- "Not permitted to access settings for other users");
- if (reqUser == UserHandle.USER_CURRENT) {
- try {
- reqUser = ActivityManagerNative.getDefault().getCurrentUser().id;
- } catch (RemoteException e) {
- // can't happen
- }
- if (LOCAL_LOGV) {
- Slog.v(TAG, " USER_CURRENT resolved to " + reqUser);
- }
- }
- if (reqUser < 0) {
- throw new IllegalArgumentException("Bad user handle " + reqUser);
- }
- callingUser = reqUser;
- if (LOCAL_LOGV) Slog.v(TAG, " fetching setting for user " + callingUser);
+ callingUser = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
+ Binder.getCallingUid(), reqUser, false, true,
+ "get/set setting for user", null);
+ if (LOCAL_LOGV) Slog.v(TAG, " access setting for user " + callingUser);
}
}
@@ -678,9 +665,6 @@
// the Settings.NameValueTable.VALUE static.
final String newValue = (args == null)
? null : args.getString(Settings.NameValueTable.VALUE);
- if (newValue == null) {
- throw new IllegalArgumentException("Bad value for " + method);
- }
final ContentValues values = new ContentValues();
values.put(Settings.NameValueTable.NAME, request);