diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java index e4a5e7f5d0840..51e3e7c937333 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 class UserManager { */ 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 @@ public class UserManager { 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 @@ public class UserManager { } } + /** @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 @@ public class UserManager { } 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 621e662f8c193..4a6799722fbd2 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.media.AudioManager; 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 @@ public class SettingsHelper { } 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 18ccf750cd7a5..c3f4256099b3c 100644 --- a/services/java/com/android/server/pm/UserManagerService.java +++ b/services/java/com/android/server/pm/UserManagerService.java @@ -603,6 +603,7 @@ public class UserManagerService extends IUserManager.Stub { 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 @@ public class UserManagerService extends IUserManager.Stub { 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 @@ public class UserManagerService extends IUserManager.Stub { 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 c4911a0004aa1..7ef148587b56b 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.Intent; 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 @@ public class UserManagerTest extends AndroidTestCase { && !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);