Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c1a86f1d authored by Makoto Onuki's avatar Makoto Onuki Committed by Android (Google) Code Review
Browse files

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

parents dd9b3aa5 b761ad1c
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -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);
    }
}
+9 −5
Original line number Diff line number Diff line
@@ -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 {