List of usage examples for android.os.storage StorageVolume getPath
@UnsupportedAppUsage
public String getPath()
From source file:com.android.server.MountService.java
public void setUsbMassStorageEnabled(boolean enable) { waitForReady();// w w w.j av a 2 s .c o m validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS); validateUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER); final StorageVolume primary = getPrimaryPhysicalVolume(); if (primary == null) return; // TODO: Add support for multiple share methods /* * If the volume is mounted and we're enabling then unmount it */ String path = primary.getPath(); String vs = getVolumeState(path); String method = "ums"; if (enable && vs.equals(Environment.MEDIA_MOUNTED)) { // Override for isUsbMassStorageEnabled() setUmsEnabling(enable); UmsEnableCallBack umscb = new UmsEnableCallBack(path, method, true); mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, umscb)); // Clear override setUmsEnabling(false); } /* * If we disabled UMS then mount the volume */ if (!enable) { doShareUnshareVolume(path, method, enable); if (doMountVolume(path) != StorageResultCode.OperationSucceeded) { Slog.e(TAG, "Failed to remount " + path + " after disabling share method " + method); /* * Even though the mount failed, the unshare didn't so don't indicate an error. * The mountVolume() call will have set the storage state and sent the necessary * broadcasts. */ } } }
From source file:com.android.server.MountService.java
/** * Create and add new {@link StorageVolume} for given {@link UserHandle} * using {@link #mEmulatedTemplate} as template. */// w ww .j a v a 2s . c o m private void createEmulatedVolumeForUserLocked(UserHandle user) { if (mEmulatedTemplate == null) { throw new IllegalStateException("Missing emulated volume multi-user template"); } final UserEnvironment userEnv = new UserEnvironment(user.getIdentifier()); final File path = userEnv.getExternalStorageDirectory(); final StorageVolume volume = StorageVolume.fromTemplate(mEmulatedTemplate, path, user); volume.setStorageId(0); addVolumeLocked(volume); if (mSystemReady) { updatePublicVolumeState(volume, Environment.MEDIA_MOUNTED); } else { // Place stub status for early callers to find mVolumeStates.put(volume.getPath(), Environment.MEDIA_MOUNTED); volume.setState(Environment.MEDIA_MOUNTED); } }
From source file:com.android.server.MountService.java
private void readStorageListLocked() { mVolumes.clear();/*w ww .j a va2 s. 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(); } }