Merge "Do not use UM.setUserRestrictions() in Settings"

This commit is contained in:
Makoto Onuki
2015-10-26 21:37:08 +00:00
committed by Android (Google) Code Review
2 changed files with 13 additions and 8 deletions

View File

@@ -78,16 +78,17 @@ public class RestrictionUtils {
public static void setRestrictions(Context context, ArrayList<RestrictionEntry> entries,
UserHandle user) {
UserManager um = UserManager.get(context);
Bundle userRestrictions = um.getUserRestrictions(user);
for (RestrictionEntry entry : entries) {
userRestrictions.putBoolean(entry.getKey(), !entry.getSelectedState());
um.setUserRestriction(entry.getKey(), !entry.getSelectedState());
// TODO This will no longer be needed once b/23902097 is fixed. um.setUserRestriction
// should do it.
if (entry.getKey().equals(UserManager.DISALLOW_SHARE_LOCATION)
&& !entry.getSelectedState()) {
Secure.putIntForUser(context.getContentResolver(),
Secure.LOCATION_MODE, Secure.LOCATION_MODE_OFF, user.getIdentifier());
}
}
um.setUserRestrictions(userRestrictions, user);
}
}

View File

@@ -123,7 +123,8 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (Boolean.TRUE.equals(newValue)) {
showDialog(mGuestUser? DIALOG_CONFIRM_ENABLE_CALLING : DIALOG_CONFIRM_ENABLE_CALLING_AND_SMS);
showDialog(mGuestUser ? DIALOG_CONFIRM_ENABLE_CALLING
: DIALOG_CONFIRM_ENABLE_CALLING_AND_SMS);
return false;
}
enableCallsAndSms(false);
@@ -137,14 +138,17 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
// SMS is always disabled for guest
mDefaultGuestRestrictions.putBoolean(UserManager.DISALLOW_SMS, true);
mUserManager.setDefaultGuestRestrictions(mDefaultGuestRestrictions);
// Update the guest's restrictions, if there is a guest
// TODO: Maybe setDefaultGuestRestrictions() can internally just set the restrictions
// on any existing guest rather than do it here with multiple Binder calls.
List<UserInfo> users = mUserManager.getUsers(true);
for (UserInfo user: users) {
if (user.isGuest()) {
UserHandle userHandle = new UserHandle(user.id);
Bundle userRestrictions = mUserManager.getUserRestrictions(userHandle);
userRestrictions.putAll(mDefaultGuestRestrictions);
mUserManager.setUserRestrictions(userRestrictions, userHandle);
for (String key : mDefaultGuestRestrictions.keySet()) {
mUserManager.setUserRestriction(
key, mDefaultGuestRestrictions.getBoolean(key));
}
}
}
} else {