use of android.content.pm.UserInfo in project platform_frameworks_base by android.
the class Am method runGetCurrentUser.
private void runGetCurrentUser() throws Exception {
UserInfo currentUser = Preconditions.checkNotNull(mAm.getCurrentUser(), "Current user not set");
System.out.println(currentUser.id);
}
use of android.content.pm.UserInfo in project platform_frameworks_base by android.
the class Pm method runCreateUser.
public int runCreateUser() {
String name;
int userId = -1;
int flags = 0;
String opt;
while ((opt = nextOption()) != null) {
if ("--profileOf".equals(opt)) {
String optionData = nextOptionData();
if (optionData == null || !isNumber(optionData)) {
System.err.println("Error: no USER_ID specified");
return showUsage();
} else {
userId = Integer.parseInt(optionData);
}
} else if ("--managed".equals(opt)) {
flags |= UserInfo.FLAG_MANAGED_PROFILE;
} else if ("--restricted".equals(opt)) {
flags |= UserInfo.FLAG_RESTRICTED;
} else if ("--ephemeral".equals(opt)) {
flags |= UserInfo.FLAG_EPHEMERAL;
} else if ("--guest".equals(opt)) {
flags |= UserInfo.FLAG_GUEST;
} else if ("--demo".equals(opt)) {
flags |= UserInfo.FLAG_DEMO;
} else {
System.err.println("Error: unknown option " + opt);
return showUsage();
}
}
String arg = nextArg();
if (arg == null) {
System.err.println("Error: no user name specified.");
return 1;
}
name = arg;
try {
UserInfo info;
if ((flags & UserInfo.FLAG_RESTRICTED) != 0) {
// In non-split user mode, userId can only be SYSTEM
int parentUserId = userId >= 0 ? userId : UserHandle.USER_SYSTEM;
info = mUm.createRestrictedProfile(name, parentUserId);
mAm.addSharedAccountsFromParentUser(parentUserId, userId);
} else if (userId < 0) {
info = mUm.createUser(name, flags);
} else {
info = mUm.createProfileForUser(name, flags, userId);
}
if (info != null) {
System.out.println("Success: created user id " + info.id);
return 1;
} else {
System.err.println("Error: couldn't create User.");
return 1;
}
} catch (RemoteException e) {
System.err.println(e.toString());
System.err.println(PM_NOT_RUNNING_ERR);
return 1;
}
}
use of android.content.pm.UserInfo in project platform_frameworks_base by android.
the class StorageMeasurement method measureExactStorage.
private void measureExactStorage(IMediaContainerService imcs) {
final UserManager userManager = mContext.getSystemService(UserManager.class);
final PackageManager packageManager = mContext.getPackageManager();
final List<UserInfo> users = userManager.getUsers();
final List<UserInfo> currentProfiles = userManager.getEnabledProfiles(ActivityManager.getCurrentUser());
final MeasurementDetails details = new MeasurementDetails();
final Message finished = mMeasurementHandler.obtainMessage(MeasurementHandler.MSG_COMPLETED, details);
if (mVolume == null || !mVolume.isMountedReadable()) {
finished.sendToTarget();
return;
}
if (mSharedVolume != null && mSharedVolume.isMountedReadable()) {
for (UserInfo currentUserInfo : currentProfiles) {
final int userId = currentUserInfo.id;
final File basePath = mSharedVolume.getPathForUser(userId);
HashMap<String, Long> mediaMap = new HashMap<>(sMeasureMediaTypes.size());
details.mediaSize.put(userId, mediaMap);
// external volume
for (String type : sMeasureMediaTypes) {
final File path = new File(basePath, type);
final long size = getDirectorySize(imcs, path);
mediaMap.put(type, size);
}
// Measure misc files not counted under media
addValue(details.miscSize, userId, measureMisc(imcs, basePath));
}
if (mSharedVolume.getType() == VolumeInfo.TYPE_EMULATED) {
// will be spliced in later
for (UserInfo user : users) {
final File userPath = mSharedVolume.getPathForUser(user.id);
final long size = getDirectorySize(imcs, userPath);
addValue(details.usersSize, user.id, size);
}
}
}
final File file = mVolume.getPath();
if (file != null) {
details.totalSize = file.getTotalSpace();
details.availSize = file.getFreeSpace();
}
// Measure all apps hosted on this volume for all users
if (mVolume.getType() == VolumeInfo.TYPE_PRIVATE) {
final List<ApplicationInfo> apps = packageManager.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
final List<ApplicationInfo> volumeApps = new ArrayList<>();
for (ApplicationInfo app : apps) {
if (Objects.equals(app.volumeUuid, mVolume.getFsUuid())) {
volumeApps.add(app);
}
}
final int count = users.size() * volumeApps.size();
if (count == 0) {
finished.sendToTarget();
return;
}
final StatsObserver observer = new StatsObserver(true, details, ActivityManager.getCurrentUser(), currentProfiles, finished, count);
for (UserInfo user : users) {
for (ApplicationInfo app : volumeApps) {
packageManager.getPackageSizeInfoAsUser(app.packageName, user.id, observer);
}
}
} else {
finished.sendToTarget();
return;
}
}
use of android.content.pm.UserInfo in project platform_frameworks_base by android.
the class RestrictedLockUtils method isAdminInCurrentUserOrProfile.
public static boolean isAdminInCurrentUserOrProfile(Context context, ComponentName admin) {
DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
UserManager um = UserManager.get(context);
for (UserInfo userInfo : um.getProfiles(UserHandle.myUserId())) {
if (dpm.isAdminActiveAsUser(admin, userInfo.id)) {
return true;
}
}
return false;
}
use of android.content.pm.UserInfo in project platform_frameworks_base by android.
the class RestrictedLockUtils method checkIfKeyguardFeaturesDisabled.
/**
* Checks if keyguard features are disabled by policy.
*
* @param keyguardFeatures Could be any of keyguard features that can be
* disabled by {@link android.app.admin.DevicePolicyManager#setKeyguardDisabledFeatures}.
* @return EnforcedAdmin Object containing the enforced admin component and admin user details,
* or {@code null} If the notification features are not disabled. If the restriction is set by
* multiple admins, then the admin component will be set to {@code null} and userId to
* {@link UserHandle#USER_NULL}.
*/
public static EnforcedAdmin checkIfKeyguardFeaturesDisabled(Context context, int keyguardFeatures, int userId) {
final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
if (dpm == null) {
return null;
}
final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
EnforcedAdmin enforcedAdmin = null;
if (um.getUserInfo(userId).isManagedProfile()) {
final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userId);
if (admins == null) {
return null;
}
for (ComponentName admin : admins) {
if ((dpm.getKeyguardDisabledFeatures(admin, userId) & keyguardFeatures) != 0) {
if (enforcedAdmin == null) {
enforcedAdmin = new EnforcedAdmin(admin, userId);
} else {
return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
}
}
}
} else {
// user that do not use a separate work challenge.
for (UserInfo userInfo : um.getProfiles(userId)) {
final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userInfo.id);
if (admins == null) {
continue;
}
final boolean isSeparateProfileChallengeEnabled = lockPatternUtils.isSeparateProfileChallengeEnabled(userInfo.id);
for (ComponentName admin : admins) {
if (!isSeparateProfileChallengeEnabled) {
if ((dpm.getKeyguardDisabledFeatures(admin, userInfo.id) & keyguardFeatures) != 0) {
if (enforcedAdmin == null) {
enforcedAdmin = new EnforcedAdmin(admin, userInfo.id);
} else {
return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
}
// has set policy on the parent admin.
continue;
}
}
if (userInfo.isManagedProfile()) {
// If userInfo.id is a managed profile, we also need to look at
// the policies set on the parent.
DevicePolicyManager parentDpm = dpm.getParentProfileInstance(userInfo);
if ((parentDpm.getKeyguardDisabledFeatures(admin, userInfo.id) & keyguardFeatures) != 0) {
if (enforcedAdmin == null) {
enforcedAdmin = new EnforcedAdmin(admin, userInfo.id);
} else {
return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
}
}
}
}
}
}
return enforcedAdmin;
}
Aggregations