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

Commit 112bf90c authored by Felipe Leme's avatar Felipe Leme
Browse files

Added profile-owner and device-owner on cmd user list.

Examples:

$ adb shell cmd user list -v
3 users:

0: id=0, name=Driver, flags=ADMIN|INITIALIZED|PRIMARY|SYSTEM (running) (device-owner)
1: id=10, name=Driver, flags=ADMIN|FULL|INITIALIZED
2: id=11, name=HomerSimpson, flags=FULL|INITIALIZED (running) (converted) (profile-owner) (current)

Test: see above
Bug: 156263735
Bug: 175860401

Change-Id: I68a3394eb48ef11d6a4d71ad90df3df137af3874
parent 39ab15d7
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -231,7 +231,13 @@ public abstract class DevicePolicyManagerInternal {
     * Returns the profile owner component for the given user, or {@code null} if there is not one.
     */
    @Nullable
    public abstract ComponentName getProfileOwnerAsUser(int userHandle);
    public abstract ComponentName getProfileOwnerAsUser(@UserIdInt int userId);

    /**
     * Returns the user id of the device owner, or {@link UserHandle#USER_NULL} if there is not one.
     */
    @UserIdInt
    public abstract int getDeviceOwnerUserId();

    /**
     * Returns whether the given package is a device owner or a profile owner in the calling user.
+20 −1
Original line number Diff line number Diff line
@@ -4760,13 +4760,32 @@ public class UserManagerService extends IUserManager.Stub {
                final boolean hasParent = user.profileGroupId != user.id
                        && user.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID;
                if (verbose) {
                    pw.printf("%d: id=%d, name=%s, flags=%s%s%s%s%s%s%s\n", i, user.id, user.name,
                    final DevicePolicyManagerInternal dpm = getDevicePolicyManagerInternal();
                    String deviceOwner = "";
                    String profileOwner = "";
                    if (dpm != null) {
                        final long ident = Binder.clearCallingIdentity();
                        // NOTE: dpm methods below CANNOT be called while holding the mUsersLock
                        try {
                            if (dpm.getDeviceOwnerUserId() == user.id) {
                                deviceOwner = " (device-owner)";
                            }
                            if (dpm.getProfileOwnerAsUser(user.id) != null) {
                                profileOwner = " (profile-owner)";
                            }
                        } finally {
                            Binder.restoreCallingIdentity(ident);
                        }
                    }
                    pw.printf("%d: id=%d, name=%s, flags=%s%s%s%s%s%s%s%s%s\n", i, user.id,
                            user.name,
                            UserInfo.flagsToString(user.flags),
                            hasParent ? " (parentId=" + user.profileGroupId + ")" : "",
                            running ? " (running)" : "",
                            user.partial ? " (partial)" : "",
                            user.preCreated ? " (pre-created)" : "",
                            user.convertedFromPreCreated ? " (converted)" : "",
                            deviceOwner, profileOwner,
                            current ? " (current)" : "");
                } else {
                    // NOTE: the standard "list users" command is used by integration tests and
+7 −2
Original line number Diff line number Diff line
@@ -11763,8 +11763,13 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        }
        @Override
        public ComponentName getProfileOwnerAsUser(int userHandle) {
            return DevicePolicyManagerService.this.getProfileOwnerAsUser(userHandle);
        public ComponentName getProfileOwnerAsUser(@UserIdInt int userId) {
            return DevicePolicyManagerService.this.getProfileOwnerAsUser(userId);
        }
        @Override
        public int getDeviceOwnerUserId() {
            return DevicePolicyManagerService.this.getDeviceOwnerUserId();
        }
        @Override