Loading core/java/android/app/ActivityManager.java +1 −3 Original line number Diff line number Diff line Loading @@ -4167,10 +4167,8 @@ public class ActivityManager { "android.permission.INTERACT_ACROSS_USERS_FULL" }) public static int getCurrentUser() { UserInfo ui; try { ui = getService().getCurrentUser(); return ui != null ? ui.id : 0; return getService().getCurrentUserId(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading core/java/android/app/IActivityManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -363,6 +363,7 @@ interface IActivityManager { boolean killProcessesBelowForeground(in String reason); @UnsupportedAppUsage UserInfo getCurrentUser(); int getCurrentUserId(); // This is not public because you need to be very careful in how you // manage your activity to make sure it is always the uid you expect. @UnsupportedAppUsage Loading services/core/java/com/android/server/am/ActivityManagerService.java +5 −0 Original line number Diff line number Diff line Loading @@ -15704,6 +15704,11 @@ public class ActivityManagerService extends IActivityManager.Stub return mUserController.getCurrentUser(); } @Override public @UserIdInt int getCurrentUserId() { return mUserController.getCurrentUserIdChecked(); } String getStartedUserState(int userId) { final UserState userState = mUserController.getStartedUserState(userId); return UserState.stateToString(userState.state); services/core/java/com/android/server/am/ActivityManagerShellCommand.java +5 −4 Original line number Diff line number Diff line Loading @@ -118,7 +118,6 @@ import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Objects; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; Loading Loading @@ -1842,9 +1841,11 @@ final class ActivityManagerShellCommand extends ShellCommand { } int runGetCurrentUser(PrintWriter pw) throws RemoteException { UserInfo currentUser = Objects.requireNonNull(mInterface.getCurrentUser(), "Current user not set"); pw.println(currentUser.id); int userId = mInterface.getCurrentUserId(); if (userId == UserHandle.USER_NULL) { throw new IllegalStateException("Current user not set"); } pw.println(userId); return 0; } Loading services/core/java/com/android/server/am/UserController.java +21 −4 Original line number Diff line number Diff line Loading @@ -2173,7 +2173,7 @@ class UserController implements Handler.Callback { } } UserInfo getCurrentUser() { private void checkGetCurrentUserPermissions() { if ((mInjector.checkCallingPermission(INTERACT_ACROSS_USERS) != PackageManager.PERMISSION_GRANTED) && ( mInjector.checkCallingPermission(INTERACT_ACROSS_USERS_FULL) Loading @@ -2185,8 +2185,12 @@ class UserController implements Handler.Callback { Slog.w(TAG, msg); throw new SecurityException(msg); } } // Optimization - if there is no pending user switch, return current id UserInfo getCurrentUser() { checkGetCurrentUserPermissions(); // Optimization - if there is no pending user switch, return user for current id // (no need to acquire lock because mTargetUserId and mCurrentUserId are volatile) if (mTargetUserId == UserHandle.USER_NULL) { return getUserInfo(mCurrentUserId); Loading @@ -2196,9 +2200,23 @@ class UserController implements Handler.Callback { } } /** * Gets the current user id, but checking that caller has the proper permissions. */ int getCurrentUserIdChecked() { checkGetCurrentUserPermissions(); // Optimization - if there is no pending user switch, return current id // (no need to acquire lock because mTargetUserId and mCurrentUserId are volatile) if (mTargetUserId == UserHandle.USER_NULL) { return mCurrentUserId; } return getCurrentOrTargetUserId(); } @GuardedBy("mLock") UserInfo getCurrentUserLU() { int userId = mTargetUserId != UserHandle.USER_NULL ? mTargetUserId : mCurrentUserId; int userId = getCurrentOrTargetUserIdLU(); return getUserInfo(userId); } Loading @@ -2213,7 +2231,6 @@ class UserController implements Handler.Callback { return mTargetUserId != UserHandle.USER_NULL ? mTargetUserId : mCurrentUserId; } @GuardedBy("mLock") int getCurrentUserIdLU() { return mCurrentUserId; Loading Loading
core/java/android/app/ActivityManager.java +1 −3 Original line number Diff line number Diff line Loading @@ -4167,10 +4167,8 @@ public class ActivityManager { "android.permission.INTERACT_ACROSS_USERS_FULL" }) public static int getCurrentUser() { UserInfo ui; try { ui = getService().getCurrentUser(); return ui != null ? ui.id : 0; return getService().getCurrentUserId(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading
core/java/android/app/IActivityManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -363,6 +363,7 @@ interface IActivityManager { boolean killProcessesBelowForeground(in String reason); @UnsupportedAppUsage UserInfo getCurrentUser(); int getCurrentUserId(); // This is not public because you need to be very careful in how you // manage your activity to make sure it is always the uid you expect. @UnsupportedAppUsage Loading
services/core/java/com/android/server/am/ActivityManagerService.java +5 −0 Original line number Diff line number Diff line Loading @@ -15704,6 +15704,11 @@ public class ActivityManagerService extends IActivityManager.Stub return mUserController.getCurrentUser(); } @Override public @UserIdInt int getCurrentUserId() { return mUserController.getCurrentUserIdChecked(); } String getStartedUserState(int userId) { final UserState userState = mUserController.getStartedUserState(userId); return UserState.stateToString(userState.state);
services/core/java/com/android/server/am/ActivityManagerShellCommand.java +5 −4 Original line number Diff line number Diff line Loading @@ -118,7 +118,6 @@ import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Objects; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; Loading Loading @@ -1842,9 +1841,11 @@ final class ActivityManagerShellCommand extends ShellCommand { } int runGetCurrentUser(PrintWriter pw) throws RemoteException { UserInfo currentUser = Objects.requireNonNull(mInterface.getCurrentUser(), "Current user not set"); pw.println(currentUser.id); int userId = mInterface.getCurrentUserId(); if (userId == UserHandle.USER_NULL) { throw new IllegalStateException("Current user not set"); } pw.println(userId); return 0; } Loading
services/core/java/com/android/server/am/UserController.java +21 −4 Original line number Diff line number Diff line Loading @@ -2173,7 +2173,7 @@ class UserController implements Handler.Callback { } } UserInfo getCurrentUser() { private void checkGetCurrentUserPermissions() { if ((mInjector.checkCallingPermission(INTERACT_ACROSS_USERS) != PackageManager.PERMISSION_GRANTED) && ( mInjector.checkCallingPermission(INTERACT_ACROSS_USERS_FULL) Loading @@ -2185,8 +2185,12 @@ class UserController implements Handler.Callback { Slog.w(TAG, msg); throw new SecurityException(msg); } } // Optimization - if there is no pending user switch, return current id UserInfo getCurrentUser() { checkGetCurrentUserPermissions(); // Optimization - if there is no pending user switch, return user for current id // (no need to acquire lock because mTargetUserId and mCurrentUserId are volatile) if (mTargetUserId == UserHandle.USER_NULL) { return getUserInfo(mCurrentUserId); Loading @@ -2196,9 +2200,23 @@ class UserController implements Handler.Callback { } } /** * Gets the current user id, but checking that caller has the proper permissions. */ int getCurrentUserIdChecked() { checkGetCurrentUserPermissions(); // Optimization - if there is no pending user switch, return current id // (no need to acquire lock because mTargetUserId and mCurrentUserId are volatile) if (mTargetUserId == UserHandle.USER_NULL) { return mCurrentUserId; } return getCurrentOrTargetUserId(); } @GuardedBy("mLock") UserInfo getCurrentUserLU() { int userId = mTargetUserId != UserHandle.USER_NULL ? mTargetUserId : mCurrentUserId; int userId = getCurrentOrTargetUserIdLU(); return getUserInfo(userId); } Loading @@ -2213,7 +2231,6 @@ class UserController implements Handler.Callback { return mTargetUserId != UserHandle.USER_NULL ? mTargetUserId : mCurrentUserId; } @GuardedBy("mLock") int getCurrentUserIdLU() { return mCurrentUserId; Loading