Merge "Added getProfileIds method returning array of userIds" into nyc-dev

This commit is contained in:
Fyodor Kupolov
2016-04-11 16:40:54 +00:00
committed by Android (Google) Code Review
15 changed files with 175 additions and 170 deletions

View File

@ -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);

View File

@ -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 */);
}
/**

View File

@ -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();
}
}
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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(

View File

@ -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

View File

@ -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);
}
}

View File

@ -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 {

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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

View File

@ -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,

View File

@ -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);

View File

@ -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,31 +342,25 @@ 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 ret;
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 results;
}
}
);
// Create a data directory.
final File dir = new File(dataDir, "user" + userId);
@ -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.
*/