Loading core/java/android/os/UserManager.java +28 −5 Original line number Original line Diff line number Diff line Loading @@ -15,15 +15,15 @@ */ */ package android.os; package android.os; import com.android.internal.R; import android.app.ActivityManagerNative; import android.app.ActivityManagerNative; import android.content.Context; import android.content.Context; import android.content.pm.UserInfo; import android.content.pm.UserInfo; import android.graphics.Bitmap; import android.content.res.Resources; import android.content.res.Resources; import android.graphics.Bitmap; import android.util.Log; import android.util.Log; import com.android.internal.R; import java.util.List; import java.util.List; /** /** Loading Loading @@ -71,6 +71,14 @@ public class UserManager { */ */ public static final String ALLOW_UNINSTALL_APPS = "uninstall_apps"; 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 */ /** @hide */ public UserManager(Context context, IUserManager service) { public UserManager(Context context, IUserManager service) { mService = service; mService = service; Loading @@ -90,7 +98,7 @@ public class UserManager { * Returns the user handle for the user that this application is running for. * Returns the user handle for the user that this application is running for. * @return the user handle of the user making this call. * @return the user handle of the user making this call. * @hide * @hide * */ */ public int getUserHandle() { public int getUserHandle() { return UserHandle.myUserId(); return UserHandle.myUserId(); } } Loading Loading @@ -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 * 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 * number assigned to that user; if the user is deleted and then a new Loading Loading @@ -433,4 +448,12 @@ public class UserManager { } } return -1; 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); } } } packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java +7 −2 Original line number Original line Diff line number Diff line Loading @@ -16,8 +16,6 @@ package com.android.providers.settings; package com.android.providers.settings; import java.util.Locale; import android.app.ActivityManagerNative; import android.app.ActivityManagerNative; import android.app.IActivityManager; import android.app.IActivityManager; import android.app.backup.IBackupManager; import android.app.backup.IBackupManager; Loading @@ -28,9 +26,12 @@ import android.media.AudioManager; import android.os.IPowerManager; import android.os.IPowerManager; import android.os.RemoteException; import android.os.RemoteException; import android.os.ServiceManager; import android.os.ServiceManager; import android.os.UserManager; import android.provider.Settings; import android.provider.Settings; import android.text.TextUtils; import android.text.TextUtils; import java.util.Locale; public class SettingsHelper { public class SettingsHelper { private Context mContext; private Context mContext; private AudioManager mAudioManager; private AudioManager mAudioManager; Loading Loading @@ -96,6 +97,10 @@ public class SettingsHelper { } } private void setGpsLocation(String value) { private void setGpsLocation(String value) { UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE); if (! um.isLocationSharingToggleAllowed()) { return; } final String GPS = LocationManager.GPS_PROVIDER; final String GPS = LocationManager.GPS_PROVIDER; boolean enabled = boolean enabled = GPS.equals(value) || GPS.equals(value) || Loading services/java/com/android/server/pm/UserManagerService.java +3 −0 Original line number Original line Diff line number Diff line Loading @@ -603,6 +603,7 @@ public class UserManagerService extends IUserManager.Stub { writeBoolean(serializer, restrictions, UserManager.ALLOW_MODIFY_ACCOUNTS); writeBoolean(serializer, restrictions, UserManager.ALLOW_MODIFY_ACCOUNTS); writeBoolean(serializer, restrictions, UserManager.ALLOW_INSTALL_APPS); writeBoolean(serializer, restrictions, UserManager.ALLOW_INSTALL_APPS); writeBoolean(serializer, restrictions, UserManager.ALLOW_UNINSTALL_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_RESTRICTIONS); } } serializer.endTag(null, TAG_USER); serializer.endTag(null, TAG_USER); Loading Loading @@ -719,6 +720,7 @@ public class UserManagerService extends IUserManager.Stub { readBoolean(parser, restrictions, UserManager.ALLOW_MODIFY_ACCOUNTS); readBoolean(parser, restrictions, UserManager.ALLOW_MODIFY_ACCOUNTS); readBoolean(parser, restrictions, UserManager.ALLOW_INSTALL_APPS); readBoolean(parser, restrictions, UserManager.ALLOW_INSTALL_APPS); readBoolean(parser, restrictions, UserManager.ALLOW_UNINSTALL_APPS); readBoolean(parser, restrictions, UserManager.ALLOW_UNINSTALL_APPS); readBoolean(parser, restrictions, UserManager.ALLOW_CONFIG_LOCATION_ACCESS); } } } } } } Loading Loading @@ -763,6 +765,7 @@ public class UserManagerService extends IUserManager.Stub { restrictions.putBoolean(UserManager.ALLOW_MODIFY_ACCOUNTS, true); restrictions.putBoolean(UserManager.ALLOW_MODIFY_ACCOUNTS, true); restrictions.putBoolean(UserManager.ALLOW_INSTALL_APPS, true); restrictions.putBoolean(UserManager.ALLOW_INSTALL_APPS, true); restrictions.putBoolean(UserManager.ALLOW_UNINSTALL_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) { private int readIntAttribute(XmlPullParser parser, String attr, int defaultValue) { Loading services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java +3 −2 Original line number Original line Diff line number Diff line Loading @@ -22,8 +22,6 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.IntentFilter; import android.content.pm.UserInfo; import android.content.pm.UserInfo; import android.os.Bundle; import android.os.Bundle; import android.os.Debug; import android.os.Environment; import android.os.UserHandle; import android.os.UserHandle; import android.os.UserManager; import android.os.UserManager; import android.test.AndroidTestCase; import android.test.AndroidTestCase; Loading Loading @@ -67,6 +65,9 @@ public class UserManagerTest extends AndroidTestCase { && !user.isAdmin() && !user.isAdmin() && !user.isPrimary()) { && !user.isPrimary()) { found = true; 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); assertTrue(found); Loading Loading
core/java/android/os/UserManager.java +28 −5 Original line number Original line Diff line number Diff line Loading @@ -15,15 +15,15 @@ */ */ package android.os; package android.os; import com.android.internal.R; import android.app.ActivityManagerNative; import android.app.ActivityManagerNative; import android.content.Context; import android.content.Context; import android.content.pm.UserInfo; import android.content.pm.UserInfo; import android.graphics.Bitmap; import android.content.res.Resources; import android.content.res.Resources; import android.graphics.Bitmap; import android.util.Log; import android.util.Log; import com.android.internal.R; import java.util.List; import java.util.List; /** /** Loading Loading @@ -71,6 +71,14 @@ public class UserManager { */ */ public static final String ALLOW_UNINSTALL_APPS = "uninstall_apps"; 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 */ /** @hide */ public UserManager(Context context, IUserManager service) { public UserManager(Context context, IUserManager service) { mService = service; mService = service; Loading @@ -90,7 +98,7 @@ public class UserManager { * Returns the user handle for the user that this application is running for. * Returns the user handle for the user that this application is running for. * @return the user handle of the user making this call. * @return the user handle of the user making this call. * @hide * @hide * */ */ public int getUserHandle() { public int getUserHandle() { return UserHandle.myUserId(); return UserHandle.myUserId(); } } Loading Loading @@ -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 * 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 * number assigned to that user; if the user is deleted and then a new Loading Loading @@ -433,4 +448,12 @@ public class UserManager { } } return -1; 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); } } }
packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java +7 −2 Original line number Original line Diff line number Diff line Loading @@ -16,8 +16,6 @@ package com.android.providers.settings; package com.android.providers.settings; import java.util.Locale; import android.app.ActivityManagerNative; import android.app.ActivityManagerNative; import android.app.IActivityManager; import android.app.IActivityManager; import android.app.backup.IBackupManager; import android.app.backup.IBackupManager; Loading @@ -28,9 +26,12 @@ import android.media.AudioManager; import android.os.IPowerManager; import android.os.IPowerManager; import android.os.RemoteException; import android.os.RemoteException; import android.os.ServiceManager; import android.os.ServiceManager; import android.os.UserManager; import android.provider.Settings; import android.provider.Settings; import android.text.TextUtils; import android.text.TextUtils; import java.util.Locale; public class SettingsHelper { public class SettingsHelper { private Context mContext; private Context mContext; private AudioManager mAudioManager; private AudioManager mAudioManager; Loading Loading @@ -96,6 +97,10 @@ public class SettingsHelper { } } private void setGpsLocation(String value) { private void setGpsLocation(String value) { UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE); if (! um.isLocationSharingToggleAllowed()) { return; } final String GPS = LocationManager.GPS_PROVIDER; final String GPS = LocationManager.GPS_PROVIDER; boolean enabled = boolean enabled = GPS.equals(value) || GPS.equals(value) || Loading
services/java/com/android/server/pm/UserManagerService.java +3 −0 Original line number Original line Diff line number Diff line Loading @@ -603,6 +603,7 @@ public class UserManagerService extends IUserManager.Stub { writeBoolean(serializer, restrictions, UserManager.ALLOW_MODIFY_ACCOUNTS); writeBoolean(serializer, restrictions, UserManager.ALLOW_MODIFY_ACCOUNTS); writeBoolean(serializer, restrictions, UserManager.ALLOW_INSTALL_APPS); writeBoolean(serializer, restrictions, UserManager.ALLOW_INSTALL_APPS); writeBoolean(serializer, restrictions, UserManager.ALLOW_UNINSTALL_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_RESTRICTIONS); } } serializer.endTag(null, TAG_USER); serializer.endTag(null, TAG_USER); Loading Loading @@ -719,6 +720,7 @@ public class UserManagerService extends IUserManager.Stub { readBoolean(parser, restrictions, UserManager.ALLOW_MODIFY_ACCOUNTS); readBoolean(parser, restrictions, UserManager.ALLOW_MODIFY_ACCOUNTS); readBoolean(parser, restrictions, UserManager.ALLOW_INSTALL_APPS); readBoolean(parser, restrictions, UserManager.ALLOW_INSTALL_APPS); readBoolean(parser, restrictions, UserManager.ALLOW_UNINSTALL_APPS); readBoolean(parser, restrictions, UserManager.ALLOW_UNINSTALL_APPS); readBoolean(parser, restrictions, UserManager.ALLOW_CONFIG_LOCATION_ACCESS); } } } } } } Loading Loading @@ -763,6 +765,7 @@ public class UserManagerService extends IUserManager.Stub { restrictions.putBoolean(UserManager.ALLOW_MODIFY_ACCOUNTS, true); restrictions.putBoolean(UserManager.ALLOW_MODIFY_ACCOUNTS, true); restrictions.putBoolean(UserManager.ALLOW_INSTALL_APPS, true); restrictions.putBoolean(UserManager.ALLOW_INSTALL_APPS, true); restrictions.putBoolean(UserManager.ALLOW_UNINSTALL_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) { private int readIntAttribute(XmlPullParser parser, String attr, int defaultValue) { Loading
services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java +3 −2 Original line number Original line Diff line number Diff line Loading @@ -22,8 +22,6 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.IntentFilter; import android.content.pm.UserInfo; import android.content.pm.UserInfo; import android.os.Bundle; import android.os.Bundle; import android.os.Debug; import android.os.Environment; import android.os.UserHandle; import android.os.UserHandle; import android.os.UserManager; import android.os.UserManager; import android.test.AndroidTestCase; import android.test.AndroidTestCase; Loading Loading @@ -67,6 +65,9 @@ public class UserManagerTest extends AndroidTestCase { && !user.isAdmin() && !user.isAdmin() && !user.isPrimary()) { && !user.isPrimary()) { found = true; 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); assertTrue(found); Loading