Merge "Add location sharing toggle user restriction." into jb-mr2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
40bbc3bb99
@ -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;
|
||||
@ -90,7 +98,7 @@ public class UserManager {
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
@ -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) ||
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user