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

Commit e6fa48fc authored by Nikhil Kumar's avatar Nikhil Kumar
Browse files

Remove default Calls and SMS restrictions from the MAIN user.

Main user is a secondary user and in turns enherit the restriction of
DISALLOW_OUTGOING_CALLS and DISALLOW_SMS.
Refactored the user creation flow to ignore applying these
restrictions if the user being created is a MAIN user.

Bug: 294821532
Test: atest UserManagerTest#testMainUser_hasNoCallsOrSMSRestrictions -c
Change-Id: I7b2baa80c86400a1cb64dfcf12c4c93faa15b556
parent 39863d79
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);