isForegroundUserAdmin public API
Introduce an API by which callers can determine whether the foreground
user is an admin (even though the caller may not know who the foreground
user is). Foreground is synonymous with current.
Also adds an additional Flag for future communal development, where this
API is expected to be useful.
Test: atest android.multiuser.cts.UserManagerTest#testIsForegroundUserAdminUser_withAdditionalUser
Test: atest android.multiuser.cts.UserManagerTest#testIsForegroundUserAdminUser_admin
Change-Id: I2f2d74681b302a64991b11b32382558118ba798b
diff --git a/core/api/current.txt b/core/api/current.txt
index 2a22e85..1e310ef 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -33378,6 +33378,7 @@
method public boolean isAdminUser();
method @FlaggedApi("android.multiuser.support_communal_profile") public boolean isCommunalProfile();
method public boolean isDemoUser();
+ method @FlaggedApi("android.multiuser.support_communal_profile_nextgen") public boolean isForegroundUserAdmin();
method public static boolean isHeadlessSystemUserMode();
method public boolean isManagedProfile();
method public boolean isProfile();
diff --git a/core/java/android/content/pm/multiuser.aconfig b/core/java/android/content/pm/multiuser.aconfig
index 3ec239c..43cf97f 100644
--- a/core/java/android/content/pm/multiuser.aconfig
+++ b/core/java/android/content/pm/multiuser.aconfig
@@ -28,3 +28,10 @@
description: "Framework support for communal profile."
bug: "285426179"
}
+
+flag {
+ name: "support_communal_profile_nextgen"
+ namespace: "multiuser"
+ description: "Further framework support for communal profile, beyond the basics, for later releases."
+ bug: "285426179"
+}
diff --git a/core/java/android/os/IUserManager.aidl b/core/java/android/os/IUserManager.aidl
index 839c56f..330b992 100644
--- a/core/java/android/os/IUserManager.aidl
+++ b/core/java/android/os/IUserManager.aidl
@@ -137,6 +137,7 @@
boolean isUserVisible(int userId);
int[] getVisibleUsers();
int getMainDisplayIdAssignedToUser();
+ boolean isForegroundUserAdmin();
boolean isUserNameSet(int userId);
boolean hasRestrictedProfiles(int userId);
boolean requestQuietModeEnabled(String callingPackage, boolean enableQuietMode, int userId, in IntentSender target, int flags);
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index 1c9a349..4d385e4 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -2857,6 +2857,23 @@
}
/**
+ * Used to check if the user currently running in the <b>foreground</b> is an
+ * {@link #isAdminUser() admin} user.
+ *
+ * @return whether the foreground user is an admin user.
+ * @see #isAdminUser()
+ * @see #isUserForeground()
+ */
+ @FlaggedApi(android.multiuser.Flags.FLAG_SUPPORT_COMMUNAL_PROFILE_NEXTGEN)
+ public boolean isForegroundUserAdmin() {
+ try {
+ return mService.isForegroundUserAdmin();
+ } catch (RemoteException re) {
+ throw re.rethrowFromSystemServer();
+ }
+ }
+
+ /**
* Returns whether the context user is of the given user type.
*
* @param userType the name of the user's user type, e.g.
diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java
index 68a8e40..c64a8c6 100644
--- a/services/core/java/com/android/server/pm/UserManagerService.java
+++ b/services/core/java/com/android/server/pm/UserManagerService.java
@@ -2141,6 +2141,19 @@
}
@Override
+ public boolean isForegroundUserAdmin() {
+ // No permission requirements for this API.
+ synchronized (mUsersLock) {
+ final int currentUserId = getCurrentUserId();
+ if (currentUserId != UserHandle.USER_NULL) {
+ final UserInfo userInfo = getUserInfoLU(currentUserId);
+ return userInfo != null && userInfo.isAdmin();
+ }
+ }
+ return false;
+ }
+
+ @Override
public @NonNull String getUserName() {
final int callingUid = Binder.getCallingUid();
if (!hasQueryOrCreateUsersPermission()