diff options
15 files changed, 174 insertions, 169 deletions
diff --git a/core/java/android/os/IUserManager.aidl b/core/java/android/os/IUserManager.aidl index c38bf3c74852..67d395954e1e 100644 --- a/core/java/android/os/IUserManager.aidl +++ b/core/java/android/os/IUserManager.aidl @@ -45,6 +45,7 @@ interface IUserManager { UserInfo getPrimaryUser(); List<UserInfo> getUsers(boolean excludeDying); List<UserInfo> getProfiles(int userHandle, boolean enabledOnly); + int[] getProfileIds(int userId, boolean enabledOnly); boolean canAddMoreManagedProfiles(int userHandle, boolean allowedToRemoveOne); UserInfo getProfileParent(int userHandle); boolean isSameProfileGroup(int userHandle, int otherUserHandle); diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java index 707d5f561ac2..d5b3b3518701 100644 --- a/core/java/android/os/UserManager.java +++ b/core/java/android/os/UserManager.java @@ -1590,18 +1590,46 @@ public class UserManager { * @return A non-empty list of UserHandles associated with the calling user. */ public List<UserHandle> getUserProfiles() { - ArrayList<UserHandle> profiles = new ArrayList<UserHandle>(); - List<UserInfo> users; + int[] userIds = getProfileIds(UserHandle.myUserId(), true /* enabledOnly */); + List<UserHandle> result = new ArrayList<>(userIds.length); + for (int userId : userIds) { + result.add(UserHandle.of(userId)); + } + return result; + } + + /** + * Returns a list of ids for profiles associated with the specified user including the user + * itself. + * + * @param userId id of the user to return profiles for + * @param enabledOnly whether return only {@link UserInfo#isEnabled() enabled} profiles + * @return A non-empty list of ids of profiles associated with the specified user. + * + * @hide + */ + public int[] getProfileIds(@UserIdInt int userId, boolean enabledOnly) { try { - users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */); + return mService.getProfileIds(userId, enabledOnly); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } - for (UserInfo info : users) { - UserHandle userHandle = new UserHandle(info.id); - profiles.add(userHandle); - } - return profiles; + } + + /** + * @see #getProfileIds(int, boolean) + * @hide + */ + public int[] getProfileIdsWithDisabled(@UserIdInt int userId) { + return getProfileIds(userId, false /* enabledOnly */); + } + + /** + * @see #getProfileIds(int, boolean) + * @hide + */ + public int[] getEnabledProfileIds(@UserIdInt int userId) { + return getProfileIds(userId, true /* enabledOnly */); } /** diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java index 61c9f2b15c82..92a3de7c5977 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java @@ -1831,14 +1831,11 @@ public class SettingsProvider extends ContentProvider { private void maybeNotifyProfiles(int userId, Uri uri, String name, Set<String> keysCloned) { if (keysCloned.contains(name)) { - List<UserInfo> profiles = mUserManager.getProfiles(userId); - int size = profiles.size(); - for (int i = 0; i < size; i++) { - UserInfo profile = profiles.get(i); + for (int profileId : mUserManager.getProfileIdsWithDisabled(userId)) { // the notification for userId has already been sent. - if (profile.id != userId) { + if (profileId != userId) { mHandler.obtainMessage(MyHandler.MSG_NOTIFY_URI_CHANGED, - profile.id, 0, uri).sendToTarget(); + profileId, 0, uri).sendToTarget(); } } } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java index 66754a7fa80c..f892fd641792 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java @@ -847,17 +847,16 @@ public class KeyguardViewMediator extends SystemUI { private void doKeyguardLaterForChildProfilesLocked() { UserManager um = UserManager.get(mContext); - List<UserInfo> profiles = um.getEnabledProfiles(UserHandle.myUserId()); - for (UserInfo info : profiles) { - if (mLockPatternUtils.isSeparateProfileChallengeEnabled(info.id)) { - long userTimeout = getLockTimeout(info.id); + for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) { + if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) { + long userTimeout = getLockTimeout(profileId); if (userTimeout == 0) { doKeyguardForChildProfilesLocked(); } else { long userWhen = SystemClock.elapsedRealtime() + userTimeout; Intent lockIntent = new Intent(DELAYED_LOCK_PROFILE_ACTION); lockIntent.putExtra("seq", mDelayedProfileShowingSequence); - lockIntent.putExtra(Intent.EXTRA_USER_ID, info.id); + lockIntent.putExtra(Intent.EXTRA_USER_ID, profileId); PendingIntent lockSender = PendingIntent.getBroadcast( mContext, 0, lockIntent, PendingIntent.FLAG_CANCEL_CURRENT); mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, @@ -869,10 +868,9 @@ public class KeyguardViewMediator extends SystemUI { private void doKeyguardForChildProfilesLocked() { UserManager um = UserManager.get(mContext); - List<UserInfo> profiles = um.getEnabledProfiles(UserHandle.myUserId()); - for (UserInfo info : profiles) { - if (mLockPatternUtils.isSeparateProfileChallengeEnabled(info.id)) { - lockProfile(info.id); + for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) { + if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) { + lockProfile(profileId); } } } @@ -1482,9 +1480,8 @@ public class KeyguardViewMediator extends SystemUI { final UserHandle currentUser = new UserHandle(KeyguardUpdateMonitor.getCurrentUser()); final UserManager um = (UserManager) mContext.getSystemService( Context.USER_SERVICE); - List <UserInfo> userHandles = um.getProfiles(currentUser.getIdentifier()); - for (UserInfo ui : userHandles) { - mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, ui.getUserHandle()); + for (int profileId : um.getProfileIdsWithDisabled(currentUser.getIdentifier())) { + mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, UserHandle.of(profileId)); } } else { mBootSendUserPresent = true; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java index a85fe0d36769..5046456f70f8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java @@ -114,8 +114,8 @@ public class SecurityControllerImpl implements SecurityController { @Override public String getProfileOwnerName() { - for (UserInfo profile : mUserManager.getProfiles(mCurrentUserId)) { - String name = mDevicePolicyManager.getProfileOwnerNameAsUser(profile.id); + for (int profileId : mUserManager.getProfileIdsWithDisabled(mCurrentUserId)) { + String name = mDevicePolicyManager.getProfileOwnerNameAsUser(profileId); if (name != null) { return name; } @@ -135,13 +135,13 @@ public class SecurityControllerImpl implements SecurityController { @Override public String getProfileVpnName() { - for (UserInfo profile : mUserManager.getProfiles(mVpnUserId)) { - if (profile.id == mVpnUserId) { + for (int profileId : mUserManager.getProfileIdsWithDisabled(mVpnUserId)) { + if (profileId == mVpnUserId) { continue; } - VpnConfig cfg = mCurrentVpns.get(profile.id); + VpnConfig cfg = mCurrentVpns.get(profileId); if (cfg != null) { - return getNameForVpnConfig(cfg, profile.getUserHandle()); + return getNameForVpnConfig(cfg, UserHandle.of(profileId)); } } return null; @@ -149,8 +149,8 @@ public class SecurityControllerImpl implements SecurityController { @Override public boolean isVpnEnabled() { - for (UserInfo profile : mUserManager.getProfiles(mVpnUserId)) { - if (mCurrentVpns.get(profile.id) != null) { + for (int profileId : mUserManager.getProfileIdsWithDisabled(mVpnUserId)) { + if (mCurrentVpns.get(profileId) != null) { return true; } } diff --git a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java index f93fb1b0f975..6ca3af8219da 100644 --- a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java +++ b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java @@ -460,12 +460,9 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku } synchronized (mLock) { reloadWidgetsMaskedState(userId); - List<UserInfo> profiles = mUserManager.getEnabledProfiles(userId); - if (profiles != null) { - for (int i = 0; i < profiles.size(); i++) { - UserInfo user = profiles.get(i); - reloadWidgetsMaskedState(user.id); - } + int[] profileIds = mUserManager.getEnabledProfileIds(userId); + for (int profileId : profileIds) { + reloadWidgetsMaskedState(profileId); } } } @@ -3458,33 +3455,12 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku public int[] getEnabledGroupProfileIds(int userId) { final int parentId = getGroupParent(userId); - final List<UserInfo> profiles; final long identity = Binder.clearCallingIdentity(); try { - profiles = mUserManager.getProfiles(parentId); + return mUserManager.getEnabledProfileIds(parentId); } finally { Binder.restoreCallingIdentity(identity); } - - int enabledProfileCount = 0; - final int profileCount = profiles.size(); - for (int i = 0; i < profileCount; i++) { - if (profiles.get(i).isEnabled()) { - enabledProfileCount++; - } - } - - int enabledProfileIndex = 0; - final int[] profileIds = new int[enabledProfileCount]; - for (int i = 0; i < profileCount; i++) { - UserInfo profile = profiles.get(i); - if (profile.isEnabled()) { - profileIds[enabledProfileIndex] = profile.getUserHandle().getIdentifier(); - enabledProfileIndex++; - } - } - - return profileIds; } public void enforceServiceExistsAndRequiresBindRemoteViewsPermission( diff --git a/services/core/java/com/android/server/InputMethodManagerService.java b/services/core/java/com/android/server/InputMethodManagerService.java index ac7872a94bf8..da65daefcbb6 100644 --- a/services/core/java/com/android/server/InputMethodManagerService.java +++ b/services/core/java/com/android/server/InputMethodManagerService.java @@ -66,7 +66,6 @@ import android.content.pm.IPackageManager; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; -import android.content.pm.UserInfo; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; @@ -1050,12 +1049,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } void updateCurrentProfileIds() { - List<UserInfo> profiles = mUserManager.getProfiles(mSettings.getCurrentUserId()); - int[] currentProfileIds = new int[profiles.size()]; // profiles will not be null - for (int i = 0; i < currentProfileIds.length; i++) { - currentProfileIds[i] = profiles.get(i).id; - } - mSettings.setCurrentProfileIds(currentProfileIds); + mSettings.setCurrentProfileIds( + mUserManager.getProfileIdsWithDisabled(mSettings.getCurrentUserId())); } @Override diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java index 9884a70a2ca9..7c48634c8d56 100644 --- a/services/core/java/com/android/server/LocationManagerService.java +++ b/services/core/java/com/android/server/LocationManagerService.java @@ -21,6 +21,7 @@ import com.android.internal.content.PackageMonitor; import com.android.internal.location.ProviderProperties; import com.android.internal.location.ProviderRequest; import com.android.internal.os.BackgroundThread; +import com.android.internal.util.ArrayUtils; import com.android.server.location.ActivityRecognitionProxy; import com.android.server.location.FlpHardwareProvider; import com.android.server.location.FusedProxy; @@ -53,7 +54,6 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ResolveInfo; import android.content.pm.Signature; -import android.content.pm.UserInfo; import android.content.res.Resources; import android.database.ContentObserver; import android.hardware.location.ActivityRecognitionHardware; @@ -359,12 +359,9 @@ public class LocationManagerService extends ILocationManager.Stub { * @param currentUserId the current user, who might have an alter-ego. */ void updateUserProfiles(int currentUserId) { - List<UserInfo> profiles = mUserManager.getProfiles(currentUserId); + int[] profileIds = mUserManager.getProfileIdsWithDisabled(currentUserId); synchronized (mLock) { - mCurrentUserProfiles = new int[profiles.size()]; - for (int i = 0; i < mCurrentUserProfiles.length; i++) { - mCurrentUserProfiles[i] = profiles.get(i).id; - } + mCurrentUserProfiles = profileIds; } } @@ -374,12 +371,7 @@ public class LocationManagerService extends ILocationManager.Stub { */ private boolean isCurrentProfile(int userId) { synchronized (mLock) { - for (int i = 0; i < mCurrentUserProfiles.length; i++) { - if (mCurrentUserProfiles[i] == userId) { - return true; - } - } - return false; + return ArrayUtils.contains(mCurrentUserProfiles, userId); } } diff --git a/services/core/java/com/android/server/TextServicesManagerService.java b/services/core/java/com/android/server/TextServicesManagerService.java index 3eb20a0c580e..801d6e090c1a 100644 --- a/services/core/java/com/android/server/TextServicesManagerService.java +++ b/services/core/java/com/android/server/TextServicesManagerService.java @@ -43,7 +43,6 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; -import android.content.pm.UserInfo; import android.os.Binder; import android.os.Bundle; import android.os.IBinder; @@ -195,12 +194,8 @@ public class TextServicesManagerService extends ITextServicesManager.Stub { } void updateCurrentProfileIds() { - final List<UserInfo> profiles = mUserManager.getProfiles(mSettings.getCurrentUserId()); - int[] currentProfileIds = new int[profiles.size()]; // profiles will not be null - for (int i = 0; i < currentProfileIds.length; i++) { - currentProfileIds[i] = profiles.get(i).id; - } - mSettings.setCurrentProfileIds(currentProfileIds); + mSettings.setCurrentProfileIds( + mUserManager.getProfileIdsWithDisabled(mSettings.getCurrentUserId())); } private class TextServicesMonitor extends PackageMonitor { diff --git a/services/core/java/com/android/server/camera/CameraService.java b/services/core/java/com/android/server/camera/CameraService.java index cd8eb4e3bb3c..7d9adf28314b 100644 --- a/services/core/java/com/android/server/camera/CameraService.java +++ b/services/core/java/com/android/server/camera/CameraService.java @@ -15,32 +15,28 @@ */ package com.android.server.camera; -import android.app.ActivityManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.pm.UserInfo; import android.hardware.ICameraService; import android.hardware.ICameraServiceProxy; import android.nfc.INfcAdapter; +import android.os.Binder; import android.os.Handler; import android.os.IBinder; -import android.os.Binder; import android.os.Message; import android.os.Process; import android.os.RemoteException; -import android.os.UserManager; import android.os.SystemProperties; -import android.util.Slog; +import android.os.UserManager; import android.util.ArraySet; +import android.util.Slog; import com.android.server.ServiceThread; import com.android.server.SystemService; import java.util.Collection; -import java.util.HashSet; -import java.util.List; import java.util.Set; /** @@ -225,11 +221,11 @@ public class CameraService extends SystemService } private Set<Integer> getEnabledUserHandles(int currentUserHandle) { - List<UserInfo> userProfiles = mUserManager.getEnabledProfiles(currentUserHandle); - Set<Integer> handles = new HashSet<>(userProfiles.size()); + int[] userProfiles = mUserManager.getEnabledProfileIds(currentUserHandle); + Set<Integer> handles = new ArraySet<>(userProfiles.length); - for (UserInfo i : userProfiles) { - handles.add(i.id); + for (int id : userProfiles) { + handles.add(id); } return handles; diff --git a/services/core/java/com/android/server/fingerprint/FingerprintService.java b/services/core/java/com/android/server/fingerprint/FingerprintService.java index 3d8bf5126638..e3f3849c79d3 100644 --- a/services/core/java/com/android/server/fingerprint/FingerprintService.java +++ b/services/core/java/com/android/server/fingerprint/FingerprintService.java @@ -541,10 +541,8 @@ public class FingerprintService extends SystemService implements IBinder.DeathRe UserManager um = UserManager.get(mContext); // Allow current user or profiles of the current user... - List<UserInfo> profiles = um.getEnabledProfiles(userId); - final int n = profiles.size(); - for (int i = 0; i < n; i++) { - if (profiles.get(i).id == userId) { + for (int profileId : um.getEnabledProfileIds(userId)) { + if (profileId == userId) { return true; } } diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java index 60a0d6282483..60ea2544cadc 100644 --- a/services/core/java/com/android/server/pm/UserManagerService.java +++ b/services/core/java/com/android/server/pm/UserManagerService.java @@ -65,6 +65,7 @@ import android.system.ErrnoException; import android.system.Os; import android.system.OsConstants; import android.util.AtomicFile; +import android.util.IntArray; import android.util.Log; import android.util.Slog; import android.util.SparseArray; @@ -483,13 +484,50 @@ public class UserManagerService extends IUserManager.Stub { } } + @Override + public int[] getProfileIds(int userId, boolean enabledOnly) { + if (userId != UserHandle.getCallingUserId()) { + checkManageUsersPermission("getting profiles related to user " + userId); + } + final long ident = Binder.clearCallingIdentity(); + try { + synchronized (mUsersLock) { + return getProfileIdsLU(userId, enabledOnly).toArray(); + } + } finally { + Binder.restoreCallingIdentity(ident); + } + } + /** Assume permissions already checked and caller's identity cleared */ private List<UserInfo> getProfilesLU(int userId, boolean enabledOnly, boolean fullInfo) { + IntArray profileIds = getProfileIdsLU(userId, enabledOnly); + ArrayList<UserInfo> users = new ArrayList<>(profileIds.size()); + for (int i = 0; i < profileIds.size(); i++) { + int profileId = profileIds.get(i); + UserInfo userInfo = mUsers.get(profileId).info; + // If full info is not required - clear PII data to prevent 3P apps from reading it + if (!fullInfo) { + userInfo = new UserInfo(userInfo); + userInfo.name = null; + userInfo.iconPath = null; + } else { + userInfo = userWithName(userInfo); + } + users.add(userInfo); + } + return users; + } + + /** + * Assume permissions already checked and caller's identity cleared + */ + private IntArray getProfileIdsLU(int userId, boolean enabledOnly) { UserInfo user = getUserInfoLU(userId); - ArrayList<UserInfo> users = new ArrayList<UserInfo>(mUsers.size()); + IntArray result = new IntArray(mUsers.size()); if (user == null) { // Probably a dying user - return users; + return result; } final int userSize = mUsers.size(); for (int i = 0; i < userSize; i++) { @@ -506,16 +544,9 @@ public class UserManagerService extends IUserManager.Stub { if (profile.partial) { continue; } - UserInfo userInfo = userWithName(profile); - // If full info is not required - clear PII data to prevent 3P apps from reading it - if (!fullInfo) { - userInfo = new UserInfo(userInfo); - userInfo.name = null; - userInfo.iconPath = null; - } - users.add(userInfo); + result.add(profile.id); } - return users; + return result; } @Override diff --git a/services/core/java/com/android/server/vr/EnabledComponentsObserver.java b/services/core/java/com/android/server/vr/EnabledComponentsObserver.java index eb926c1ab2c7..30194bf87c78 100644 --- a/services/core/java/com/android/server/vr/EnabledComponentsObserver.java +++ b/services/core/java/com/android/server/vr/EnabledComponentsObserver.java @@ -24,7 +24,6 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; -import android.content.pm.UserInfo; import android.os.Handler; import android.os.Looper; import android.os.UserHandle; @@ -213,18 +212,7 @@ public class EnabledComponentsObserver implements SettingChangeListener { if (userManager == null) { return null; } - int currentUserId = ActivityManager.getCurrentUser(); - List<UserInfo> profiles = userManager.getProfiles(currentUserId); - if (profiles == null) { - return null; - } - final int s = profiles.size(); - int[] userIds = new int[s]; - int ctr = 0; - for (UserInfo info : profiles) { - userIds[ctr++] = info.id; - } - return userIds; + return userManager.getProfileIdsWithDisabled(ActivityManager.getCurrentUser()); } public static ArraySet<ComponentName> loadComponentNames(PackageManager pm, int userId, diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index fdea84b4c2a4..dd75eac5c594 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -21,8 +21,6 @@ import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_COMPLEX; import static android.app.admin.DevicePolicyManager.WIPE_EXTERNAL_STORAGE; import static android.app.admin.DevicePolicyManager.WIPE_RESET_PROTECTION_DATA; import static android.content.pm.PackageManager.GET_UNINSTALLED_PACKAGES; -import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE; -import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE; import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW; import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT; @@ -57,7 +55,6 @@ import android.app.admin.SystemUpdatePolicy; import android.app.backup.IBackupManager; import android.content.BroadcastReceiver; import android.content.ComponentName; -import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; @@ -85,7 +82,6 @@ import android.net.wifi.WifiManager; import android.os.AsyncTask; import android.os.Binder; import android.os.Build; -import android.os.Build.VERSION_CODES; import android.os.Bundle; import android.os.Environment; import android.os.FileUtils; @@ -2065,10 +2061,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { */ private void sendAdminCommandToSelfAndProfilesLocked(String action, int reqPolicy, int userHandle) { - List<UserInfo> profiles = mUserManager.getProfiles(userHandle); - for (UserInfo ui : profiles) { - int id = ui.id; - sendAdminCommandLocked(action, reqPolicy, id); + int[] profileIds = mUserManager.getProfileIdsWithDisabled(userHandle); + for (int profileId : profileIds) { + sendAdminCommandLocked(action, reqPolicy, profileId); } } @@ -3968,9 +3963,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { // moment so we set the screen off timeout regardless of whether it affects the parent user // or the profile challenge only. long timeMs = Long.MAX_VALUE; - List<UserInfo> profiles = mUserManager.getProfiles(userHandle); - for (UserInfo userInfo : profiles) { - DevicePolicyData policy = getUserDataUnchecked(userInfo.id); + int[] profileIds = mUserManager.getProfileIdsWithDisabled(userHandle); + for (int profileId : profileIds) { + DevicePolicyData policy = getUserDataUnchecked(profileId); final int N = policy.mAdminList.size(); for (int i = 0; i < N; i++) { ActiveAdmin admin = policy.mAdminList.get(i); @@ -6708,19 +6703,18 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { // If we have multiple profiles we return the intersection of the // permitted lists. This can happen in cases where we have a device // and profile owner. - List<UserInfo> profiles = mUserManager.getProfiles(userId); - final int PROFILES_SIZE = profiles.size(); - for (int i = 0; i < PROFILES_SIZE; ++i) { + int[] profileIds = mUserManager.getProfileIdsWithDisabled(userId); + for (int profileId : profileIds) { // Just loop though all admins, only device or profiles // owners can have permitted lists set. - DevicePolicyData policy = getUserDataUnchecked(profiles.get(i).id); + DevicePolicyData policy = getUserDataUnchecked(profileId); final int N = policy.mAdminList.size(); for (int j = 0; j < N; j++) { ActiveAdmin admin = policy.mAdminList.get(j); List<String> fromAdmin = admin.permittedAccessiblityServices; if (fromAdmin != null) { if (result == null) { - result = new ArrayList<String>(fromAdmin); + result = new ArrayList<>(fromAdmin); } else { result.retainAll(fromAdmin); } @@ -6888,12 +6882,11 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { // If we have multiple profiles we return the intersection of the // permitted lists. This can happen in cases where we have a device // and profile owner. - List<UserInfo> profiles = mUserManager.getProfiles(userId); - final int PROFILES_SIZE = profiles.size(); - for (int i = 0; i < PROFILES_SIZE; ++i) { + int[] profileIds = mUserManager.getProfileIdsWithDisabled(userId); + for (int profileId : profileIds) { // Just loop though all admins, only device or profiles // owners can have permitted lists set. - DevicePolicyData policy = getUserDataUnchecked(profiles.get(i).id); + DevicePolicyData policy = getUserDataUnchecked(profileId); final int N = policy.mAdminList.size(); for (int j = 0; j < N; j++) { ActiveAdmin admin = policy.mAdminList.get(j); diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DpmMockContext.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DpmMockContext.java index 60d7382a7233..f6e35f54f7d4 100644 --- a/services/tests/servicestests/src/com/android/server/devicepolicy/DpmMockContext.java +++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DpmMockContext.java @@ -39,7 +39,6 @@ import android.os.PowerManagerInternal; import android.os.UserHandle; import android.os.UserManager; import android.os.UserManagerInternal; -import android.os.storage.StorageManager; import android.telephony.TelephonyManager; import android.test.mock.MockContentResolver; import android.test.mock.MockContext; @@ -343,32 +342,26 @@ public class DpmMockContext extends MockContext { @Override public List<UserInfo> answer(InvocationOnMock invocation) throws Throwable { final int userId = (int) invocation.getArguments()[0]; - final ArrayList<UserInfo> ret = new ArrayList<UserInfo>(); - UserInfo parent = null; - for (UserInfo ui : mUserInfos) { - if (ui.id == userId) { - parent = ui; - break; - } - } - if (parent == null) { - return ret; - } - ret.add(parent); - for (UserInfo ui : mUserInfos) { - if (ui.id == userId) { - continue; - } - if (ui.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID - && ui.profileGroupId == parent.profileGroupId) { - ret.add(ui); - } + return getProfiles(userId); + } + } + ); + when(userManager.getProfileIdsWithDisabled(anyInt())).thenAnswer( + new Answer<int[]>() { + @Override + public int[] answer(InvocationOnMock invocation) throws Throwable { + final int userId = (int) invocation.getArguments()[0]; + List<UserInfo> profiles = getProfiles(userId); + int[] results = new int[profiles.size()]; + for (int i = 0; i < results.length; i++) { + results[i] = profiles.get(i).id; } - return ret; + return results; } } ); + // Create a data directory. final File dir = new File(dataDir, "user" + userId); DpmTestUtils.clearDir(dir); @@ -377,6 +370,31 @@ public class DpmMockContext extends MockContext { return dir; } + private List<UserInfo> getProfiles(int userId) { + final ArrayList<UserInfo> ret = new ArrayList<UserInfo>(); + UserInfo parent = null; + for (UserInfo ui : mUserInfos) { + if (ui.id == userId) { + parent = ui; + break; + } + } + if (parent == null) { + return ret; + } + ret.add(parent); + for (UserInfo ui : mUserInfos) { + if (ui.id == userId) { + continue; + } + if (ui.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID + && ui.profileGroupId == parent.profileGroupId) { + ret.add(ui); + } + } + return ret; + } + /** * Add multiple users at once. They'll all have flag 0. */ |