Loading core/java/android/content/pm/UserInfo.java +24 −2 Original line number Diff line number Diff line Loading @@ -369,6 +369,14 @@ public class UserInfo implements Parcelable { @UnsupportedAppUsage @Deprecated public boolean isPrimary() { UserManager.logStaticDeprecation(); return isPrimaryUnlogged(); } /** * @hide */ public boolean isPrimaryUnlogged() { return (flags & FLAG_PRIMARY) == FLAG_PRIMARY; } Loading Loading @@ -451,6 +459,20 @@ public class UserInfo implements Parcelable { * @see #FLAG_MAIN */ public boolean isMain() { UserManager.logStaticDeprecation(); return isMainUnlogged(); } /** * Same as {@link #isMain()}, but doesn't log the call (when logging multi-user violations is * enabled). * * <p>Should be called by methods that don't need to log (for example, because they're internal * to user infra) or already logged (to avoid duplicate entries). * * @hide */ public boolean isMainUnlogged() { return (flags & FLAG_MAIN) == FLAG_MAIN; } Loading Loading @@ -512,7 +534,7 @@ public class UserInfo implements Parcelable { // NOTE: profiles used to be restricted just to the system user (and later to the main // user), but from the framework point of view there is no need for such restriction, hence // it's lifted return isMain() return isMainUnlogged() || (android.multiuser.Flags.profilesForAll() && Resources.getSystem().getBoolean( com.android.internal.R.bool.config_supportProfilesOnNonMainUser)); Loading @@ -529,7 +551,7 @@ public class UserInfo implements Parcelable { if (UserManager.isUserTypePrivateProfile(userType)) { // Even if we eventually allow other users to have profiles too, only MainUsers are // eligible to have a Private Space, for some reason. return isMain(); return isMainUnlogged(); } return true; } Loading core/java/android/os/UserManager.java +40 −2 Original line number Diff line number Diff line Loading @@ -101,6 +101,10 @@ public class UserManager { private static final String TAG = "UserManager"; private static final String DEPRECATION_LOG_TAG = "MultiuserDeprecation"; private static final boolean DEBUG_LOG_DEPRECATION = Build.isDebuggable() && Log.isLoggable(DEPRECATION_LOG_TAG, Log.VERBOSE); @UnsupportedAppUsage private final IUserManager mService; /** Holding the Application context (not constructor param context). */ Loading Loading @@ -3030,8 +3034,9 @@ public class UserManager { Manifest.permission.QUERY_USERS}) @UserHandleAware(enabledSinceTargetSdkVersion = Build.VERSION_CODES.TIRAMISU) public boolean isPrimaryUser() { logDeprecation(); final UserInfo user = getUserInfo(getContextUserIfAppropriate()); return user != null && user.isPrimary(); return user != null && user.isPrimaryUnlogged(); } /** Loading Loading @@ -3075,8 +3080,9 @@ public class UserManager { Manifest.permission.QUERY_USERS}) @UserHandleAware public boolean isMainUser() { logDeprecation(); final UserInfo user = getUserInfo(mUserId); return user != null && user.isMain(); return user != null && user.isMainUnlogged(); } /** Loading @@ -3097,6 +3103,7 @@ public class UserManager { Manifest.permission.CREATE_USERS, Manifest.permission.QUERY_USERS}) public @Nullable UserHandle getMainUser() { logDeprecation(); try { final int mainUserId = mService.getMainUserId(); if (mainUserId == UserHandle.USER_NULL) { Loading @@ -3107,6 +3114,7 @@ public class UserManager { throw re.rethrowFromSystemServer(); } } /** * Returns the designated "communal profile" of the device, or {@code null} if there is none. * @hide Loading Loading @@ -6970,6 +6978,36 @@ public class UserManager { } } /** * Logs a call to a deprecated multi-user API. * * <p>NOTE: it's a no-op if build is not debuggable or log level of * {@value #DEPRECATION_LOG_TAG} is not verbose. * * @hide */ public void logDeprecation() { if (!DEBUG_LOG_DEPRECATION) { return; } Log.v(DEPRECATION_LOG_TAG, "deprecated call on pkg " + mContext.getPackageName() + " (from user " + mUserId + "):", new Exception()); } /** * Same as {@link #logDeprecation()}, but for cases where the caller doesn't have a reference * to a {@link UserManager} (like methods from system server components or POJOs like * {@code UserInfo}. * * @hide */ public static void logStaticDeprecation() { if (!DEBUG_LOG_DEPRECATION) { return; } Log.v(DEPRECATION_LOG_TAG, "deprecated call:", new Exception()); } /* Cache key for anything that assumes that userIds cannot be re-used without rebooting. */ private static final String CACHE_KEY_STATIC_USER_PROPERTIES = PropertyInvalidatedCache.createPropertyName( Loading services/core/java/com/android/server/pm/UserManagerService.java +3 −2 Original line number Diff line number Diff line Loading @@ -1384,7 +1384,7 @@ public class UserManagerService extends IUserManager.Stub { int userSize = mUsers.size(); for (int i = 0; i < userSize; i++) { UserInfo user = mUsers.valueAt(i).info; if (user.isMain() && !mRemovingUserIds.get(user.id)) { if (user.isMainUnlogged() && !mRemovingUserIds.get(user.id)) { return user; } } Loading Loading @@ -2536,7 +2536,7 @@ public class UserManagerService extends IUserManager.Stub { } return getOwnerName(); } if (user.isMain()) { if (user.isMainUnlogged()) { return getOwnerName(); } if (user.isGuest()) { Loading Loading @@ -8812,6 +8812,7 @@ public class UserManagerService extends IUserManager.Stub { @Override public @UserIdInt int getMainUserId() { UserManager.logStaticDeprecation(); return getMainUserIdUnchecked(); } Loading Loading
core/java/android/content/pm/UserInfo.java +24 −2 Original line number Diff line number Diff line Loading @@ -369,6 +369,14 @@ public class UserInfo implements Parcelable { @UnsupportedAppUsage @Deprecated public boolean isPrimary() { UserManager.logStaticDeprecation(); return isPrimaryUnlogged(); } /** * @hide */ public boolean isPrimaryUnlogged() { return (flags & FLAG_PRIMARY) == FLAG_PRIMARY; } Loading Loading @@ -451,6 +459,20 @@ public class UserInfo implements Parcelable { * @see #FLAG_MAIN */ public boolean isMain() { UserManager.logStaticDeprecation(); return isMainUnlogged(); } /** * Same as {@link #isMain()}, but doesn't log the call (when logging multi-user violations is * enabled). * * <p>Should be called by methods that don't need to log (for example, because they're internal * to user infra) or already logged (to avoid duplicate entries). * * @hide */ public boolean isMainUnlogged() { return (flags & FLAG_MAIN) == FLAG_MAIN; } Loading Loading @@ -512,7 +534,7 @@ public class UserInfo implements Parcelable { // NOTE: profiles used to be restricted just to the system user (and later to the main // user), but from the framework point of view there is no need for such restriction, hence // it's lifted return isMain() return isMainUnlogged() || (android.multiuser.Flags.profilesForAll() && Resources.getSystem().getBoolean( com.android.internal.R.bool.config_supportProfilesOnNonMainUser)); Loading @@ -529,7 +551,7 @@ public class UserInfo implements Parcelable { if (UserManager.isUserTypePrivateProfile(userType)) { // Even if we eventually allow other users to have profiles too, only MainUsers are // eligible to have a Private Space, for some reason. return isMain(); return isMainUnlogged(); } return true; } Loading
core/java/android/os/UserManager.java +40 −2 Original line number Diff line number Diff line Loading @@ -101,6 +101,10 @@ public class UserManager { private static final String TAG = "UserManager"; private static final String DEPRECATION_LOG_TAG = "MultiuserDeprecation"; private static final boolean DEBUG_LOG_DEPRECATION = Build.isDebuggable() && Log.isLoggable(DEPRECATION_LOG_TAG, Log.VERBOSE); @UnsupportedAppUsage private final IUserManager mService; /** Holding the Application context (not constructor param context). */ Loading Loading @@ -3030,8 +3034,9 @@ public class UserManager { Manifest.permission.QUERY_USERS}) @UserHandleAware(enabledSinceTargetSdkVersion = Build.VERSION_CODES.TIRAMISU) public boolean isPrimaryUser() { logDeprecation(); final UserInfo user = getUserInfo(getContextUserIfAppropriate()); return user != null && user.isPrimary(); return user != null && user.isPrimaryUnlogged(); } /** Loading Loading @@ -3075,8 +3080,9 @@ public class UserManager { Manifest.permission.QUERY_USERS}) @UserHandleAware public boolean isMainUser() { logDeprecation(); final UserInfo user = getUserInfo(mUserId); return user != null && user.isMain(); return user != null && user.isMainUnlogged(); } /** Loading @@ -3097,6 +3103,7 @@ public class UserManager { Manifest.permission.CREATE_USERS, Manifest.permission.QUERY_USERS}) public @Nullable UserHandle getMainUser() { logDeprecation(); try { final int mainUserId = mService.getMainUserId(); if (mainUserId == UserHandle.USER_NULL) { Loading @@ -3107,6 +3114,7 @@ public class UserManager { throw re.rethrowFromSystemServer(); } } /** * Returns the designated "communal profile" of the device, or {@code null} if there is none. * @hide Loading Loading @@ -6970,6 +6978,36 @@ public class UserManager { } } /** * Logs a call to a deprecated multi-user API. * * <p>NOTE: it's a no-op if build is not debuggable or log level of * {@value #DEPRECATION_LOG_TAG} is not verbose. * * @hide */ public void logDeprecation() { if (!DEBUG_LOG_DEPRECATION) { return; } Log.v(DEPRECATION_LOG_TAG, "deprecated call on pkg " + mContext.getPackageName() + " (from user " + mUserId + "):", new Exception()); } /** * Same as {@link #logDeprecation()}, but for cases where the caller doesn't have a reference * to a {@link UserManager} (like methods from system server components or POJOs like * {@code UserInfo}. * * @hide */ public static void logStaticDeprecation() { if (!DEBUG_LOG_DEPRECATION) { return; } Log.v(DEPRECATION_LOG_TAG, "deprecated call:", new Exception()); } /* Cache key for anything that assumes that userIds cannot be re-used without rebooting. */ private static final String CACHE_KEY_STATIC_USER_PROPERTIES = PropertyInvalidatedCache.createPropertyName( Loading
services/core/java/com/android/server/pm/UserManagerService.java +3 −2 Original line number Diff line number Diff line Loading @@ -1384,7 +1384,7 @@ public class UserManagerService extends IUserManager.Stub { int userSize = mUsers.size(); for (int i = 0; i < userSize; i++) { UserInfo user = mUsers.valueAt(i).info; if (user.isMain() && !mRemovingUserIds.get(user.id)) { if (user.isMainUnlogged() && !mRemovingUserIds.get(user.id)) { return user; } } Loading Loading @@ -2536,7 +2536,7 @@ public class UserManagerService extends IUserManager.Stub { } return getOwnerName(); } if (user.isMain()) { if (user.isMainUnlogged()) { return getOwnerName(); } if (user.isGuest()) { Loading Loading @@ -8812,6 +8812,7 @@ public class UserManagerService extends IUserManager.Stub { @Override public @UserIdInt int getMainUserId() { UserManager.logStaticDeprecation(); return getMainUserIdUnchecked(); } Loading