List of usage examples for android.content.pm UserInfo getUserHandle
@UnsupportedAppUsage
public UserHandle getUserHandle()
From source file:com.android.managedprovisioning.ProfileOwnerPreProvisioningActivity.java
/** * @return The User id of an already existing managed profile or -1 if none * exists/*from w w w . j a v a 2 s . com*/ */ int alreadyHasManagedProfile() { UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE); List<UserInfo> profiles = userManager.getProfiles(getUserId()); for (UserInfo userInfo : profiles) { if (userInfo.isManagedProfile()) { return userInfo.getUserHandle().getIdentifier(); } } return -1; }
From source file:com.android.server.MountService.java
private void readStorageListLocked() { mVolumes.clear();/*from w ww . j a va 2s .c o m*/ mVolumeStates.clear(); Resources resources = mContext.getResources(); int id = com.android.internal.R.xml.storage_list; XmlResourceParser parser = resources.getXml(id); AttributeSet attrs = Xml.asAttributeSet(parser); try { XmlUtils.beginDocument(parser, TAG_STORAGE_LIST); while (true) { XmlUtils.nextElement(parser); String element = parser.getName(); if (element == null) break; if (TAG_STORAGE.equals(element)) { TypedArray a = resources.obtainAttributes(attrs, com.android.internal.R.styleable.Storage); String path = a.getString(com.android.internal.R.styleable.Storage_mountPoint); int descriptionId = a.getResourceId(com.android.internal.R.styleable.Storage_storageDescription, -1); CharSequence description = a .getText(com.android.internal.R.styleable.Storage_storageDescription); boolean primary = a.getBoolean(com.android.internal.R.styleable.Storage_primary, false); boolean removable = a.getBoolean(com.android.internal.R.styleable.Storage_removable, false); boolean emulated = a.getBoolean(com.android.internal.R.styleable.Storage_emulated, false); int mtpReserve = a.getInt(com.android.internal.R.styleable.Storage_mtpReserve, 0); boolean allowMassStorage = a .getBoolean(com.android.internal.R.styleable.Storage_allowMassStorage, false); boolean allowMtp = a.getBoolean(com.android.internal.R.styleable.Storage_allowMtp, true); // resource parser does not support longs, so XML value is in megabytes long maxFileSize = a.getInt(com.android.internal.R.styleable.Storage_maxFileSize, 0) * 1024L * 1024L; Slog.d(TAG, "got storage path: " + path + " description: " + description + " primary: " + primary + " removable: " + removable + " emulated: " + emulated + " mtpReserve: " + mtpReserve + " allowMassStorage: " + allowMassStorage + " maxFileSize: " + maxFileSize + " allowMtp: " + allowMtp); if (emulated) { // For devices with emulated storage, we create separate // volumes for each known user. mEmulatedTemplate = new StorageVolume(null, descriptionId, true, false, true, mtpReserve, false, maxFileSize, null, allowMtp); final UserManagerService userManager = UserManagerService.getInstance(); for (UserInfo user : userManager.getUsers(false)) { createEmulatedVolumeForUserLocked(user.getUserHandle()); } } else { if (path == null || description == null) { Slog.e(TAG, "Missing storage path or description in readStorageList"); } else { final StorageVolume volume = new StorageVolume(new File(path), descriptionId, primary, removable, emulated, mtpReserve, allowMassStorage, maxFileSize, null, allowMtp); addVolumeLocked(volume); // Until we hear otherwise, treat as unmounted mVolumeStates.put(volume.getPath(), Environment.MEDIA_UNMOUNTED); volume.setState(Environment.MEDIA_UNMOUNTED); } } a.recycle(); } } } catch (XmlPullParserException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } finally { // Compute storage ID for each physical volume; emulated storage is // always 0 when defined. int index = isExternalStorageEmulated() ? 1 : 0; for (StorageVolume volume : mVolumes) { if (!volume.isEmulated()) { volume.setStorageId(index++); } } parser.close(); } }