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, public static void setRestrictions(Context context, ArrayList<RestrictionEntry> entries,
UserHandle user) { UserHandle user) {
UserManager um = UserManager.get(context); UserManager um = UserManager.get(context);
Bundle userRestrictions = um.getUserRestrictions(user);
for (RestrictionEntry entry : entries) { 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) if (entry.getKey().equals(UserManager.DISALLOW_SHARE_LOCATION)
&& !entry.getSelectedState()) { && !entry.getSelectedState()) {
Secure.putIntForUser(context.getContentResolver(), Secure.putIntForUser(context.getContentResolver(),
Secure.LOCATION_MODE, Secure.LOCATION_MODE_OFF, user.getIdentifier()); 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 @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
if (Boolean.TRUE.equals(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; return false;
} }
enableCallsAndSms(false); enableCallsAndSms(false);
@@ -137,14 +138,17 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
// SMS is always disabled for guest // SMS is always disabled for guest
mDefaultGuestRestrictions.putBoolean(UserManager.DISALLOW_SMS, true); mDefaultGuestRestrictions.putBoolean(UserManager.DISALLOW_SMS, true);
mUserManager.setDefaultGuestRestrictions(mDefaultGuestRestrictions); mUserManager.setDefaultGuestRestrictions(mDefaultGuestRestrictions);
// Update the guest's restrictions, if there is a guest // 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); List<UserInfo> users = mUserManager.getUsers(true);
for (UserInfo user: users) { for (UserInfo user: users) {
if (user.isGuest()) { if (user.isGuest()) {
UserHandle userHandle = new UserHandle(user.id); for (String key : mDefaultGuestRestrictions.keySet()) {
Bundle userRestrictions = mUserManager.getUserRestrictions(userHandle); mUserManager.setUserRestriction(
userRestrictions.putAll(mDefaultGuestRestrictions); key, mDefaultGuestRestrictions.getBoolean(key));
mUserManager.setUserRestrictions(userRestrictions, userHandle); }
} }
} }
} else { } else {