Loading services/core/java/com/android/server/pm/UserManagerService.java +54 −9 Original line number Diff line number Diff line Loading @@ -407,6 +407,10 @@ public class UserManagerService extends IUserManager.Stub { @GuardedBy("mUsersLock") private int[] mUserIds; @GuardedBy("mUsersLock") private int[] mUserIdsIncludingPreCreated; @GuardedBy("mPackagesLock") private int mNextSerialNumber; private int mUserVersion = 0; Loading Loading @@ -2496,16 +2500,35 @@ public class UserManagerService extends IUserManager.Stub { } /** * Returns an array of user ids. This array is cached here for quick access, so do not modify or * cache it elsewhere. * Returns an array of user ids. * * <p>This array is cached here for quick access, so do not modify or cache it elsewhere. * * @return the array of user ids. */ public int[] getUserIds() { public @NonNull int[] getUserIds() { synchronized (mUsersLock) { return mUserIds; } } /** * Returns an array of user ids, including pre-created users. * * <p>This method should only used for the specific cases that need to handle pre-created users; * most callers should call {@link #getUserIds()} instead. * * <p>This array is cached here for quick access, so do not modify or * cache it elsewhere. * * @return the array of user ids. */ public @NonNull int[] getUserIdsIncludingPreCreated() { synchronized (mUsersLock) { return mUserIdsIncludingPreCreated; } } @GuardedBy({"mRestrictionsLock", "mPackagesLock"}) private void readUserListLP() { if (!mUserListFile.exists()) { Loading Loading @@ -4361,23 +4384,43 @@ public class UserManagerService extends IUserManager.Stub { */ private void updateUserIds() { int num = 0; int numIncludingPreCreated = 0; synchronized (mUsersLock) { final int userSize = mUsers.size(); for (int i = 0; i < userSize; i++) { UserInfo userInfo = mUsers.valueAt(i).info; if (!userInfo.partial && !userInfo.preCreated) { final UserInfo userInfo = mUsers.valueAt(i).info; if (!userInfo.partial) { numIncludingPreCreated++; if (!userInfo.preCreated) { num++; } } } if (DBG) { Slog.d(LOG_TAG, "updateUserIds(): numberUsers= " + num + " includingPreCreated=" + numIncludingPreCreated); } final int[] newUsers = new int[num]; final int[] newUsersIncludingPreCreated = new int[numIncludingPreCreated]; int n = 0; int nIncludingPreCreated = 0; for (int i = 0; i < userSize; i++) { UserInfo userInfo = mUsers.valueAt(i).info; if (!userInfo.partial && !userInfo.preCreated) { newUsers[n++] = mUsers.keyAt(i); final UserInfo userInfo = mUsers.valueAt(i).info; if (!userInfo.partial) { final int userId = mUsers.keyAt(i); newUsersIncludingPreCreated[nIncludingPreCreated++] = userId; if (!userInfo.preCreated) { newUsers[n++] = userId; } } } mUserIds = newUsers; mUserIdsIncludingPreCreated = newUsersIncludingPreCreated; if (DBG) { Slog.d(LOG_TAG, "updateUserIds(): userIds= " + Arrays.toString(mUserIds) + " includingPreCreated=" + Arrays.toString(mUserIdsIncludingPreCreated)); } } } Loading Loading @@ -4841,6 +4884,8 @@ public class UserManagerService extends IUserManager.Stub { synchronized (mUsersLock) { pw.print(" Cached user IDs: "); pw.println(Arrays.toString(mUserIds)); pw.print(" Cached user IDs (including pre-created): "); pw.println(Arrays.toString(mUserIdsIncludingPreCreated)); } } // synchronized (mPackagesLock) Loading services/core/java/com/android/server/pm/permission/PermissionManagerService.java +1 −13 Original line number Diff line number Diff line Loading @@ -83,7 +83,6 @@ import android.content.pm.PackageParser; import android.content.pm.ParceledListSlice; import android.content.pm.PermissionGroupInfo; import android.content.pm.PermissionInfo; import android.content.pm.UserInfo; import android.content.pm.parsing.component.ParsedPermission; import android.content.pm.parsing.component.ParsedPermissionGroup; import android.content.pm.permission.SplitPermissionInfoParcelable; Loading Loading @@ -121,7 +120,6 @@ import android.util.Log; import android.util.Slog; import android.util.SparseArray; import android.util.SparseBooleanArray; import android.util.TimingsTraceLog; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; Loading Loading @@ -3146,17 +3144,7 @@ public class PermissionManagerService extends IPermissionManager.Stub { * @return user ids for created users and pre-created users */ private int[] getAllUserIds() { final TimingsTraceLog t = new TimingsTraceLog(TAG, Trace.TRACE_TAG_SYSTEM_SERVER); t.traceBegin("getAllUserIds"); List<UserInfo> users = UserManagerService.getInstance().getUsers( /*excludePartial=*/ true, /*excludeDying=*/ true, /*excludePreCreated=*/ false); int size = users.size(); final int[] userIds = new int[size]; for (int i = 0; i < size; i++) { userIds[i] = users.get(i).id; } t.traceEnd(); return userIds; return UserManagerService.getInstance().getUserIdsIncludingPreCreated(); } /** Loading Loading
services/core/java/com/android/server/pm/UserManagerService.java +54 −9 Original line number Diff line number Diff line Loading @@ -407,6 +407,10 @@ public class UserManagerService extends IUserManager.Stub { @GuardedBy("mUsersLock") private int[] mUserIds; @GuardedBy("mUsersLock") private int[] mUserIdsIncludingPreCreated; @GuardedBy("mPackagesLock") private int mNextSerialNumber; private int mUserVersion = 0; Loading Loading @@ -2496,16 +2500,35 @@ public class UserManagerService extends IUserManager.Stub { } /** * Returns an array of user ids. This array is cached here for quick access, so do not modify or * cache it elsewhere. * Returns an array of user ids. * * <p>This array is cached here for quick access, so do not modify or cache it elsewhere. * * @return the array of user ids. */ public int[] getUserIds() { public @NonNull int[] getUserIds() { synchronized (mUsersLock) { return mUserIds; } } /** * Returns an array of user ids, including pre-created users. * * <p>This method should only used for the specific cases that need to handle pre-created users; * most callers should call {@link #getUserIds()} instead. * * <p>This array is cached here for quick access, so do not modify or * cache it elsewhere. * * @return the array of user ids. */ public @NonNull int[] getUserIdsIncludingPreCreated() { synchronized (mUsersLock) { return mUserIdsIncludingPreCreated; } } @GuardedBy({"mRestrictionsLock", "mPackagesLock"}) private void readUserListLP() { if (!mUserListFile.exists()) { Loading Loading @@ -4361,23 +4384,43 @@ public class UserManagerService extends IUserManager.Stub { */ private void updateUserIds() { int num = 0; int numIncludingPreCreated = 0; synchronized (mUsersLock) { final int userSize = mUsers.size(); for (int i = 0; i < userSize; i++) { UserInfo userInfo = mUsers.valueAt(i).info; if (!userInfo.partial && !userInfo.preCreated) { final UserInfo userInfo = mUsers.valueAt(i).info; if (!userInfo.partial) { numIncludingPreCreated++; if (!userInfo.preCreated) { num++; } } } if (DBG) { Slog.d(LOG_TAG, "updateUserIds(): numberUsers= " + num + " includingPreCreated=" + numIncludingPreCreated); } final int[] newUsers = new int[num]; final int[] newUsersIncludingPreCreated = new int[numIncludingPreCreated]; int n = 0; int nIncludingPreCreated = 0; for (int i = 0; i < userSize; i++) { UserInfo userInfo = mUsers.valueAt(i).info; if (!userInfo.partial && !userInfo.preCreated) { newUsers[n++] = mUsers.keyAt(i); final UserInfo userInfo = mUsers.valueAt(i).info; if (!userInfo.partial) { final int userId = mUsers.keyAt(i); newUsersIncludingPreCreated[nIncludingPreCreated++] = userId; if (!userInfo.preCreated) { newUsers[n++] = userId; } } } mUserIds = newUsers; mUserIdsIncludingPreCreated = newUsersIncludingPreCreated; if (DBG) { Slog.d(LOG_TAG, "updateUserIds(): userIds= " + Arrays.toString(mUserIds) + " includingPreCreated=" + Arrays.toString(mUserIdsIncludingPreCreated)); } } } Loading Loading @@ -4841,6 +4884,8 @@ public class UserManagerService extends IUserManager.Stub { synchronized (mUsersLock) { pw.print(" Cached user IDs: "); pw.println(Arrays.toString(mUserIds)); pw.print(" Cached user IDs (including pre-created): "); pw.println(Arrays.toString(mUserIdsIncludingPreCreated)); } } // synchronized (mPackagesLock) Loading
services/core/java/com/android/server/pm/permission/PermissionManagerService.java +1 −13 Original line number Diff line number Diff line Loading @@ -83,7 +83,6 @@ import android.content.pm.PackageParser; import android.content.pm.ParceledListSlice; import android.content.pm.PermissionGroupInfo; import android.content.pm.PermissionInfo; import android.content.pm.UserInfo; import android.content.pm.parsing.component.ParsedPermission; import android.content.pm.parsing.component.ParsedPermissionGroup; import android.content.pm.permission.SplitPermissionInfoParcelable; Loading Loading @@ -121,7 +120,6 @@ import android.util.Log; import android.util.Slog; import android.util.SparseArray; import android.util.SparseBooleanArray; import android.util.TimingsTraceLog; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; Loading Loading @@ -3146,17 +3144,7 @@ public class PermissionManagerService extends IPermissionManager.Stub { * @return user ids for created users and pre-created users */ private int[] getAllUserIds() { final TimingsTraceLog t = new TimingsTraceLog(TAG, Trace.TRACE_TAG_SYSTEM_SERVER); t.traceBegin("getAllUserIds"); List<UserInfo> users = UserManagerService.getInstance().getUsers( /*excludePartial=*/ true, /*excludeDying=*/ true, /*excludePreCreated=*/ false); int size = users.size(); final int[] userIds = new int[size]; for (int i = 0; i < size; i++) { userIds[i] = users.get(i).id; } t.traceEnd(); return userIds; return UserManagerService.getInstance().getUserIdsIncludingPreCreated(); } /** Loading