From f6c8cd3a24b3a185bf1d47cbc89e5e464f5b3a6f Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Thu, 17 Oct 2019 13:03:18 -0700 Subject: [PATCH] UserManager: Add new @SystemApis There are already public versions of these APIs which allow these queries for the calling app's user. Need to expose a version that allows single instance apps, i.e user 0 (like wifi) to query info for different users. The exposed APIs are: a) isUserUnlockingOrUnlocked b) isSameProfileGroup Bug: 142024973 Test: Device boots up & connects to wifi networks Change-Id: I77cd31a2344a6cbb272196523c10ad259aea74ce --- api/system-current.txt | 2 ++ core/java/android/os/UserManager.java | 42 +++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/api/system-current.txt b/api/system-current.txt index c6b6fff76a52c..892e34ec0ae35 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -5631,6 +5631,8 @@ package android.os { method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public boolean isPrimaryUser(); method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public boolean isRestrictedProfile(); method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public boolean isRestrictedProfile(@NonNull android.os.UserHandle); + method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public boolean isSameProfileGroup(@NonNull android.os.UserHandle, @NonNull android.os.UserHandle); + method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS}) public boolean isUserUnlockingOrUnlocked(@NonNull android.os.UserHandle); method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public boolean removeUser(@NonNull android.os.UserHandle); method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public void setUserIcon(@NonNull android.graphics.Bitmap); method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public void setUserName(@Nullable String); diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java index 3296f11298c83..54f704a02030b 100644 --- a/core/java/android/os/UserManager.java +++ b/core/java/android/os/UserManager.java @@ -1748,8 +1748,30 @@ public class UserManager { } } - /** {@hide} */ - public boolean isUserUnlockingOrUnlocked(UserHandle user) { + /** + * Return whether the provided user is already running in an + * "unlocked" state or in the process of unlocking. + *

+ * On devices with direct boot, a user is unlocked only after they've + * entered their credentials (such as a lock pattern or PIN). On devices + * without direct boot, a user is unlocked as soon as it starts. + *

+ * When a user is locked, only device-protected data storage is available. + * When a user is unlocked, both device-protected and credential-protected + * private app data storage is available. + * + *

Requires {@code android.permission.MANAGE_USERS} or + * {@code android.permission.INTERACT_ACROSS_USERS}, otherwise specified {@link UserHandle user} + * must be the calling user or a profile associated with it. + * + * @hide + */ + @SystemApi + @RequiresPermission(anyOf = { + Manifest.permission.MANAGE_USERS, + Manifest.permission.INTERACT_ACROSS_USERS + }) + public boolean isUserUnlockingOrUnlocked(@NonNull UserHandle user) { return isUserUnlockingOrUnlocked(user.getIdentifier()); } @@ -2535,6 +2557,22 @@ public class UserManager { } } + /** + * Checks if the 2 provided user handles belong to the same profile group. + * + * @param user one of the two user handles to check. + * @param otherUser one of the two user handles to check. + * @return true if the two users are in the same profile group. + * + * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. + * @hide + */ + @SystemApi + @RequiresPermission(android.Manifest.permission.MANAGE_USERS) + public boolean isSameProfileGroup(@NonNull UserHandle user, @NonNull UserHandle otherUser) { + return isSameProfileGroup(user.getIdentifier(), otherUser.getIdentifier()); + } + /** * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. * @param userId one of the two user ids to check.