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

Commit 7403c8d2 authored by Jonathan Scott's avatar Jonathan Scott
Browse files

Add FOR_TESTING UserInfo Flag.

This is used to allow the setting of DeviceOwner and Device Policy
Management Role Holder during tests.

The purpose is to ensure that we don't allow setting of Device Owner on
any devices which have user data.

Test: atest CtsDevicePolicyTestCases
Bug: 256655297
Change-Id: I2f792076d6250d94b688eef361d72196f7115965
parent f3506e6c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -897,6 +897,7 @@ package android.content.pm {
    method public boolean isDemo();
    method public boolean isEnabled();
    method public boolean isEphemeral();
    method public boolean isForTesting();
    method public boolean isFull();
    method public boolean isGuest();
    method public boolean isInitialized();
+18 −1
Original line number Diff line number Diff line
@@ -170,6 +170,16 @@ public class UserInfo implements Parcelable {
     */
    public static final int FLAG_MAIN = 0x00004000;

    /**
     * Indicates that this user was created for the purposes of testing.
     *
     * <p>These users are subject to removal during tests and should not be used on actual devices
     * used by humans.
     *
     * @hide
     */
    public static final int FLAG_FOR_TESTING = 0x00008000;

    /**
     * @hide
     */
@@ -188,7 +198,8 @@ public class UserInfo implements Parcelable {
            FLAG_SYSTEM,
            FLAG_PROFILE,
            FLAG_EPHEMERAL_ON_CREATE,
            FLAG_MAIN
            FLAG_MAIN,
            FLAG_FOR_TESTING
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface UserInfoFlag {
@@ -369,6 +380,12 @@ public class UserInfo implements Parcelable {
        return (flags & FLAG_EPHEMERAL) == FLAG_EPHEMERAL;
    }

    /** @hide */
    @TestApi
    public boolean isForTesting() {
        return (flags & FLAG_FOR_TESTING) == FLAG_FOR_TESTING;
    }

    public boolean isInitialized() {
        return (flags & FLAG_INITIALIZED) == FLAG_INITIALIZED;
    }
+4 −2
Original line number Diff line number Diff line
@@ -2875,6 +2875,8 @@ class PackageManagerShellCommand extends ShellCommand {
                newUserType = UserManager.USER_TYPE_FULL_DEMO;
            } else if ("--ephemeral".equals(opt)) {
                flags |= UserInfo.FLAG_EPHEMERAL;
            } else if ("--for-testing".equals(opt)) {
                flags |= UserInfo.FLAG_FOR_TESTING;
            } else if ("--pre-create-only".equals(opt)) {
                preCreateOnly = true;
            } else if ("--user-type".equals(opt)) {
@@ -4269,8 +4271,8 @@ class PackageManagerShellCommand extends ShellCommand {
        pw.println("  list users");
        pw.println("    Lists the current users.");
        pw.println("");
        pw.println("  create-user [--profileOf USER_ID] [--managed] [--restricted] [--ephemeral]");
        pw.println("      [--guest] [--pre-create-only] [--user-type USER_TYPE] USER_NAME");
        pw.println("  create-user [--profileOf USER_ID] [--managed] [--restricted] [--guest]");
        pw.println("       [--user-type USER_TYPE] [--ephemeral] [--for-testing] [--pre-create-only]   USER_NAME");
        pw.println("    Create a new user with the given USER_NAME, printing the new user identifier");
        pw.println("    of the user.");
        // TODO(b/142482943): Consider fetching the list of user types from UMS.
+2 −1
Original line number Diff line number Diff line
@@ -254,7 +254,8 @@ public class UserManagerService extends IUserManager.Stub {
            | UserInfo.FLAG_RESTRICTED
            | UserInfo.FLAG_GUEST
            | UserInfo.FLAG_DEMO
            | UserInfo.FLAG_FULL;
            | UserInfo.FLAG_FULL
            | UserInfo.FLAG_FOR_TESTING;

    @VisibleForTesting
    static final int MIN_USER_ID = UserHandle.MIN_SECONDARY_USER_ID;