Add location sharing toggle user restriction.
And add support for respecting it.
Change-Id: Ia5cf9134c5f5741c3f55afadbe54f862da7bfe5b
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index e4a5e7f..51e3e7c 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -15,15 +15,15 @@
*/
package android.os;
-import com.android.internal.R;
-
import android.app.ActivityManagerNative;
import android.content.Context;
import android.content.pm.UserInfo;
-import android.graphics.Bitmap;
import android.content.res.Resources;
+import android.graphics.Bitmap;
import android.util.Log;
+import com.android.internal.R;
+
import java.util.List;
/**
@@ -71,6 +71,14 @@
*/
public static final String ALLOW_UNINSTALL_APPS = "uninstall_apps";
+ /** @hide *
+ * Key for user restrictions. Specifies if a user is allowed to toggle location sharing.
+ * Type: Boolean
+ * @see #setUserRestrictions(Bundle)
+ * @see #getUserRestrictions()
+ */
+ public static final String ALLOW_CONFIG_LOCATION_ACCESS = "config_location_access";
+
/** @hide */
public UserManager(Context context, IUserManager service) {
mService = service;
@@ -86,11 +94,11 @@
return getMaxSupportedUsers() > 1;
}
- /**
+ /**
* Returns the user handle for the user that this application is running for.
* @return the user handle of the user making this call.
* @hide
- * */
+ */
public int getUserHandle() {
return UserHandle.myUserId();
}
@@ -197,6 +205,13 @@
}
}
+ /** @hide */
+ public void setUserRestriction(String key, boolean value, UserHandle userHandle) {
+ Bundle bundle = getUserRestrictions(userHandle);
+ bundle.putBoolean(key, value);
+ setUserRestrictions(bundle, userHandle);
+ }
+
/**
* Return the serial number for a user. This is a device-unique
* number assigned to that user; if the user is deleted and then a new
@@ -433,4 +448,12 @@
}
return -1;
}
+
+ /**
+ * Returns whether the current user is allow to toggle location sharing settings.
+ * @hide
+ */
+ public boolean isLocationSharingToggleAllowed() {
+ return getUserRestrictions().getBoolean(ALLOW_CONFIG_LOCATION_ACCESS);
+ }
}
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
index 621e662..4a67997 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
@@ -16,8 +16,6 @@
package com.android.providers.settings;
-import java.util.Locale;
-
import android.app.ActivityManagerNative;
import android.app.IActivityManager;
import android.app.backup.IBackupManager;
@@ -28,9 +26,12 @@
import android.os.IPowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
+import android.os.UserManager;
import android.provider.Settings;
import android.text.TextUtils;
+import java.util.Locale;
+
public class SettingsHelper {
private Context mContext;
private AudioManager mAudioManager;
@@ -96,6 +97,10 @@
}
private void setGpsLocation(String value) {
+ UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
+ if (! um.isLocationSharingToggleAllowed()) {
+ return;
+ }
final String GPS = LocationManager.GPS_PROVIDER;
boolean enabled =
GPS.equals(value) ||
diff --git a/services/java/com/android/server/pm/UserManagerService.java b/services/java/com/android/server/pm/UserManagerService.java
index 18ccf75..c3f4256 100644
--- a/services/java/com/android/server/pm/UserManagerService.java
+++ b/services/java/com/android/server/pm/UserManagerService.java
@@ -603,6 +603,7 @@
writeBoolean(serializer, restrictions, UserManager.ALLOW_MODIFY_ACCOUNTS);
writeBoolean(serializer, restrictions, UserManager.ALLOW_INSTALL_APPS);
writeBoolean(serializer, restrictions, UserManager.ALLOW_UNINSTALL_APPS);
+ writeBoolean(serializer, restrictions, UserManager.ALLOW_CONFIG_LOCATION_ACCESS);
serializer.endTag(null, TAG_RESTRICTIONS);
}
serializer.endTag(null, TAG_USER);
@@ -719,6 +720,7 @@
readBoolean(parser, restrictions, UserManager.ALLOW_MODIFY_ACCOUNTS);
readBoolean(parser, restrictions, UserManager.ALLOW_INSTALL_APPS);
readBoolean(parser, restrictions, UserManager.ALLOW_UNINSTALL_APPS);
+ readBoolean(parser, restrictions, UserManager.ALLOW_CONFIG_LOCATION_ACCESS);
}
}
}
@@ -763,6 +765,7 @@
restrictions.putBoolean(UserManager.ALLOW_MODIFY_ACCOUNTS, true);
restrictions.putBoolean(UserManager.ALLOW_INSTALL_APPS, true);
restrictions.putBoolean(UserManager.ALLOW_UNINSTALL_APPS, true);
+ restrictions.putBoolean(UserManager.ALLOW_CONFIG_LOCATION_ACCESS, true);
}
private int readIntAttribute(XmlPullParser parser, String attr, int defaultValue) {
diff --git a/services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java b/services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java
index c4911a0..7ef1485 100644
--- a/services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java
@@ -22,8 +22,6 @@
import android.content.IntentFilter;
import android.content.pm.UserInfo;
import android.os.Bundle;
-import android.os.Debug;
-import android.os.Environment;
import android.os.UserHandle;
import android.os.UserManager;
import android.test.AndroidTestCase;
@@ -67,6 +65,9 @@
&& !user.isAdmin()
&& !user.isPrimary()) {
found = true;
+ Bundle restrictions = mUserManager.getUserRestrictions(user.getUserHandle());
+ assertTrue("New user should have ALLOW_CONFIG_WIFI =true by default",
+ restrictions.getBoolean(UserManager.ALLOW_CONFIG_WIFI));
}
}
assertTrue(found);