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

Commit 2a64dbce authored by Fyodor Kupolov's avatar Fyodor Kupolov Committed by Android (Google) Code Review
Browse files

Merge "Additional System APIs for restricted profiles"

parents 8971229a ca177562
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -34828,11 +34828,13 @@ package android.os {
    method public java.util.List<android.os.UserManager.EnforcingUser> getUserRestrictionSources(java.lang.String, android.os.UserHandle);
    method public android.os.Bundle getUserRestrictions();
    method public android.os.Bundle getUserRestrictions(android.os.UserHandle);
    method public boolean hasRestrictedProfiles();
    method public boolean hasUserRestriction(java.lang.String);
    method public boolean isDemoUser();
    method public boolean isManagedProfile();
    method public boolean isManagedProfile(int);
    method public boolean isQuietModeEnabled(android.os.UserHandle);
    method public boolean isRestrictedProfile();
    method public boolean isSystemUser();
    method public boolean isUserAGoat();
    method public boolean isUserRunning(android.os.UserHandle);
+1 −0
Original line number Diff line number Diff line
@@ -94,4 +94,5 @@ interface IUserManager {
    boolean isUserUnlocked(int userId);
    boolean isUserRunning(int userId);
    boolean isUserNameSet(int userHandle);
    boolean hasRestrictedProfiles();
}
+27 −2
Original line number Diff line number Diff line
@@ -1049,12 +1049,22 @@ public class UserManager {
    }

    /**
     * Used to check if the user making this call is linked to another user. Linked users may have
     * @hide
     * @deprecated Use {@link #isRestrictedProfile()}
     */
    @Deprecated
    public boolean isLinkedUser() {
        return isRestrictedProfile();
    }

    /**
     * Returns whether the caller is running as restricted profile. Restricted profile may have
     * a reduced number of available apps, app restrictions and account restrictions.
     * @return whether the user making this call is a linked user
     * @hide
     */
    public boolean isLinkedUser() {
    @SystemApi
    public boolean isRestrictedProfile() {
        try {
            return mService.isRestricted();
        } catch (RemoteException re) {
@@ -1074,6 +1084,20 @@ public class UserManager {
        }
    }

    /**
     * Returns whether the calling user has at least one restricted profile associated with it.
     * @return
     * @hide
     */
    @SystemApi
    public boolean hasRestrictedProfiles() {
        try {
            return mService.hasRestrictedProfiles();
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Checks if a user is a guest user.
     * @return whether user is a guest user.
@@ -1094,6 +1118,7 @@ public class UserManager {
        return user != null && user.isGuest();
    }


    /**
     * Checks if the calling app is running in a demo user. When running in a demo user,
     * apps can be more helpful to the user, or explain their features in more detail.
+17 −0
Original line number Diff line number Diff line
@@ -1010,6 +1010,23 @@ public class UserManagerService extends IUserManager.Stub {
        }
    }

    @Override
    public boolean hasRestrictedProfiles() {
        checkManageUsersPermission("hasRestrictedProfiles");
        final int callingUserId = UserHandle.getCallingUserId();
        synchronized (mUsersLock) {
            final int userSize = mUsers.size();
            for (int i = 0; i < userSize; i++) {
                UserInfo profile = mUsers.valueAt(i).info;
                if (callingUserId != profile.id
                        && profile.restrictedProfileParentId == callingUserId) {
                    return true;
                }
            }
            return false;
        }
    }

    /*
     * Should be locked on mUsers before calling this.
     */
+5 −0
Original line number Diff line number Diff line
@@ -309,6 +309,8 @@ public class UserManagerTest extends AndroidTestCase {

    @MediumTest
    public void testAddRestrictedProfile() throws Exception {
        assertFalse("There should be no associated restricted profiles before the test",
                mUserManager.hasRestrictedProfiles());
        UserInfo userInfo = createRestrictedProfile("Profile");
        assertNotNull(userInfo);

@@ -324,6 +326,9 @@ public class UserManagerTest extends AndroidTestCase {
                userInfo.id);
        assertEquals("Restricted profile should have setting LOCATION_MODE set to "
                + "LOCATION_MODE_OFF by default", locationMode, Settings.Secure.LOCATION_MODE_OFF);

        assertTrue("Newly created profile should be associated with the current user",
                mUserManager.hasRestrictedProfiles());
    }

    @MediumTest