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

Commit 8518f407 authored by Nikhil Kumar's avatar Nikhil Kumar Committed by Android (Google) Code Review
Browse files

Merge "Remove default Calls and SMS restrictions from the MAIN user." into main

parents 1cb95c93 e6fa48fc
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -4882,6 +4882,7 @@ public class UserManagerService extends IUserManager.Stub {
                    UserManager.USER_OPERATION_ERROR_LOW_STORAGE);
        }

        final boolean isMainUser = (flags & UserInfo.FLAG_MAIN) != 0;
        final boolean isProfile = userTypeDetails.isProfile();
        final boolean isGuest = UserManager.isUserTypeGuest(userType);
        final boolean isRestricted = UserManager.isUserTypeRestricted(userType);
@@ -5028,6 +5029,10 @@ public class UserManagerService extends IUserManager.Stub {
                }
            } else {
                userTypeDetails.addDefaultRestrictionsTo(restrictions);
                if (isMainUser) {
                    restrictions.remove(UserManager.DISALLOW_OUTGOING_CALLS);
                    restrictions.remove(UserManager.DISALLOW_SMS);
                }
            }
            synchronized (mRestrictionsLock) {
                mBaseUserRestrictions.updateRestrictions(userId, restrictions);
+14 −0
Original line number Diff line number Diff line
@@ -15,7 +15,10 @@
 */
package com.android.server.pm;

import static android.os.UserManager.DISALLOW_OUTGOING_CALLS;
import static android.os.UserManager.DISALLOW_SMS;
import static android.os.UserManager.DISALLOW_USER_SWITCH;
import static android.os.UserManager.USER_TYPE_FULL_SECONDARY;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
@@ -490,6 +493,17 @@ public final class UserManagerServiceTest {
        assertThat(mUms.isUserSwitcherEnabled(USER_ID)).isTrue();
    }

    @Test
    public void testMainUser_hasNoCallsOrSMSRestrictionsByDefault() {
        UserInfo mainUser = mUms.createUserWithThrow("main user", USER_TYPE_FULL_SECONDARY,
                UserInfo.FLAG_FULL | UserInfo.FLAG_MAIN);

        assertThat(mUms.hasUserRestriction(DISALLOW_OUTGOING_CALLS, mainUser.id))
                .isFalse();
        assertThat(mUms.hasUserRestriction(DISALLOW_SMS, mainUser.id))
                .isFalse();
    }

    private void resetUserSwitcherEnabled() {
        mUms.putUserInfo(new UserInfo(USER_ID, "Test User", 0));
        mUms.setUserRestriction(DISALLOW_USER_SWITCH, false, USER_ID);