android.os.storage.StorageManager Java Examples

The following examples show how to use android.os.storage.StorageManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileUtils.java    From sealrtc-android with MIT License 9 votes vote down vote up
/**
 * 获取外置 SD根目录
 *
 * @return
 */
private static String getSDCardStoragePath(Context appContext) {
    if (TextUtils.isEmpty(SDCardPath)) {
        try {
            StorageManager sm =
                    (StorageManager) appContext.getSystemService(Context.STORAGE_SERVICE);
            Method getVolumePathsMethod = StorageManager.class.getMethod("getVolumePaths");
            String[] paths = (String[]) getVolumePathsMethod.invoke(sm);
            // second element in paths[] is secondary storage path
            SDCardPath = paths.length <= 1 ? paths[0] : null;
            return SDCardPath;
        } catch (Exception e) {
            Log.e(TAG, "getSecondaryStoragePath() failed", e);
        }
    } else {
        return SDCardPath;
    }
    return null;
}
 
Example #2
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public int movePackage(String packageName, VolumeInfo vol) {
    try {
        final String volumeUuid;
        if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
            volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
        } else if (vol.isPrimaryPhysical()) {
            volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
        } else {
            volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
        }

        return mPM.movePackage(packageName, volumeUuid);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #3
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
    final StorageManager storage = mContext.getSystemService(StorageManager.class);
    final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
    final List<VolumeInfo> vols = storage.getVolumes();
    final List<VolumeInfo> candidates = new ArrayList<>();
    if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
            storage.getPrimaryStorageUuid()) && currentVol != null) {
        // TODO: support moving primary physical to emulated volume
        candidates.add(currentVol);
    } else {
        for (VolumeInfo vol : vols) {
            if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
                candidates.add(vol);
            }
        }
    }
    return candidates;
}
 
Example #4
Source File: FileUtils.java    From AndroidDownload with Apache License 2.0 6 votes vote down vote up
/**
 * 得到所有的存储路径(内部存储+外部存储)
 *
 * @param context context
 * @return 路径列表
 */
public static List<String> getAllSdPaths(Context context) {
    Method mMethodGetPaths = null;
    String[] paths = null;
    //通过调用类的实例mStorageManager的getClass()获取StorageManager类对应的Class对象
    //getMethod("getVolumePaths")返回StorageManager类对应的Class对象的getVolumePaths方法,这里不带参数
    StorageManager mStorageManager = (StorageManager) context
            .getSystemService(context.STORAGE_SERVICE);//storage
    try {
        mMethodGetPaths = mStorageManager.getClass().getMethod("getVolumePaths");
        paths = (String[]) mMethodGetPaths.invoke(mStorageManager);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (paths != null) {
        return Arrays.asList(paths);
    }
    return new ArrayList<String>();
}
 
Example #5
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public int movePrimaryStorage(VolumeInfo vol) {
    try {
        final String volumeUuid;
        if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
            volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
        } else if (vol.isPrimaryPhysical()) {
            volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
        } else {
            volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
        }

        return mPM.movePrimaryStorage(volumeUuid);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #6
Source File: StorageActivity.java    From AndroidDemo with MIT License 6 votes vote down vote up
/**
 * API 26 android O
 * 获取总共容量大小,包括系统大小
 */
@RequiresApi(api = 26)
public long getTotalSize(String fsUuid) {
    try {
        UUID id;
        if (fsUuid == null) {
            id = StorageManager.UUID_DEFAULT;
        } else {
            id = UUID.fromString(fsUuid);
        }
        StorageStatsManager stats = (StorageStatsManager) getSystemService(Context.STORAGE_STATS_SERVICE);
        return stats.getTotalBytes(id);
    } catch (NoSuchFieldError | NoClassDefFoundError | NullPointerException | IOException e) {
        e.printStackTrace();
        ToastUtils.show(this, "获取存储大小失败");
        return -1;
    }
}
 
Example #7
Source File: FileUtils.java    From a with GNU General Public License v3.0 6 votes vote down vote up
public static ArrayList<String> getStorageData(Context pContext) {

        final StorageManager storageManager = (StorageManager) pContext.getSystemService(Context.STORAGE_SERVICE);

        try {
            final Method getVolumeList = storageManager.getClass().getMethod("getVolumeList");

            final Class<?> storageValumeClazz = Class.forName("android.os.storage.StorageVolume");
            final Method getPath = storageValumeClazz.getMethod("getPath");

            final Object invokeVolumeList = getVolumeList.invoke(storageManager);
            final int length = Array.getLength(invokeVolumeList);

            ArrayList<String> list = new ArrayList<>();
            for (int i = 0; i < length; i++) {
                final Object storageValume = Array.get(invokeVolumeList, i);//得到StorageVolume对象
                final String path = (String) getPath.invoke(storageValume);

                list.add(path);
            }
            return list;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
 
Example #8
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public int movePackage(String packageName, VolumeInfo vol) {
    try {
        final String volumeUuid;
        if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
            volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
        } else if (vol.isPrimaryPhysical()) {
            volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
        } else {
            volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
        }

        return mPM.movePackage(packageName, volumeUuid);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #9
Source File: StorageManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void forgetAllVolumes() {
    enforcePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);

    synchronized (mLock) {
        for (int i = 0; i < mRecords.size(); i++) {
            final String fsUuid = mRecords.keyAt(i);
            final VolumeRecord rec = mRecords.valueAt(i);
            if (!TextUtils.isEmpty(rec.partGuid)) {
                mHandler.obtainMessage(H_PARTITION_FORGET, rec).sendToTarget();
            }
            mCallbacks.notifyVolumeForgotten(fsUuid);
        }
        mRecords.clear();

        if (!Objects.equals(StorageManager.UUID_PRIVATE_INTERNAL, mPrimaryStorageUuid)) {
            mPrimaryStorageUuid = getDefaultPrimaryStorageUuid();
        }

        writeSettingsLocked();
        mHandler.obtainMessage(H_RESET).sendToTarget();
    }
}
 
Example #10
Source File: FileCollector.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the file categorization result for the primary internal storage UUID.
 *
 * @param context
 */
public static MeasurementResult getMeasurementResult(Context context) {
    MeasurementResult result = new MeasurementResult();
    StorageStatsManager ssm =
            (StorageStatsManager) context.getSystemService(Context.STORAGE_STATS_SERVICE);
    ExternalStorageStats stats = null;
    try {
        stats =
                ssm.queryExternalStatsForUser(
                        StorageManager.UUID_PRIVATE_INTERNAL,
                        UserHandle.of(context.getUserId()));
        result.imagesSize = stats.getImageBytes();
        result.videosSize = stats.getVideoBytes();
        result.audioSize = stats.getAudioBytes();
        result.miscSize =
                stats.getTotalBytes()
                        - result.imagesSize
                        - result.videosSize
                        - result.audioSize;
    } catch (IOException e) {
        throw new IllegalStateException("Could not query storage");
    }

    return result;
}
 
Example #11
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public int movePackage(String packageName, VolumeInfo vol) {
    try {
        final String volumeUuid;
        if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
            volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
        } else if (vol.isPrimaryPhysical()) {
            volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
        } else {
            volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
        }

        return mPM.movePackage(packageName, volumeUuid);
    } catch (RemoteException e) {
        throw e.rethrowAsRuntimeException();
    }
}
 
Example #12
Source File: MimiUtil.java    From mimi-reader with Apache License 2.0 6 votes vote down vote up
private static Uri getFileUri(StorageManager sm, String type, String[] split) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    if (volumes == null) {
        Method getVolumeListMethod = sm.getClass().getMethod("getVolumeList", new Class[0]);
        volumes = (Object[]) getVolumeListMethod.invoke(sm);
    }

    for (Object volume : volumes) {
        Method getUuidMethod = volume.getClass().getMethod("getUuid", new Class[0]);
        String uuid = (String) getUuidMethod.invoke(volume);

        if (uuid != null && uuid.equalsIgnoreCase(type)) {
            Method getPathMethod = volume.getClass().getMethod("getPath", new Class[0]);
            String path = (String) getPathMethod.invoke(volume);
            File file = new File(path, split[1]);
            return Uri.fromFile(file);
        }
    }

    return null;
}
 
Example #13
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public int movePrimaryStorage(VolumeInfo vol) {
    try {
        final String volumeUuid;
        if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
            volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
        } else if (vol.isPrimaryPhysical()) {
            volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
        } else {
            volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
        }

        return mPM.movePrimaryStorage(volumeUuid);
    } catch (RemoteException e) {
        throw e.rethrowAsRuntimeException();
    }
}
 
Example #14
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
    final StorageManager storage = mContext.getSystemService(StorageManager.class);
    final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
    final List<VolumeInfo> vols = storage.getVolumes();
    final List<VolumeInfo> candidates = new ArrayList<>();
    if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
            storage.getPrimaryStorageUuid()) && currentVol != null) {
        // TODO: support moving primary physical to emulated volume
        candidates.add(currentVol);
    } else {
        for (VolumeInfo vol : vols) {
            if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
                candidates.add(vol);
            }
        }
    }
    return candidates;
}
 
Example #15
Source File: StorageQueryUtil.java    From AndroidDemo with MIT License 6 votes vote down vote up
/**
 * API 26 android O
 * 获取总共容量大小,包括系统大小
 */
@RequiresApi(Build.VERSION_CODES.O)
public static long getTotalSize(Context context, String fsUuid) {
    try {
        UUID id;
        if (fsUuid == null) {
            id = StorageManager.UUID_DEFAULT;
        } else {
            id = UUID.fromString(fsUuid);
        }
        StorageStatsManager stats = context.getSystemService(StorageStatsManager.class);
        return stats.getTotalBytes(id);
    } catch (NoSuchFieldError | NoClassDefFoundError | NullPointerException | IOException e) {
        e.printStackTrace();
        return -1;
    }
}
 
Example #16
Source File: ContextImpl.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Ensure that given directories exist, trying to create them if missing. If
 * unable to create, they are filtered by replacing with {@code null}.
 */
private File[] ensureExternalDirsExistOrFilter(File[] dirs) {
    final StorageManager sm = getSystemService(StorageManager.class);
    final File[] result = new File[dirs.length];
    for (int i = 0; i < dirs.length; i++) {
        File dir = dirs[i];
        if (!dir.exists()) {
            if (!dir.mkdirs()) {
                // recheck existence in case of cross-process race
                if (!dir.exists()) {
                    // Failing to mkdir() may be okay, since we might not have
                    // enough permissions; ask vold to create on our behalf.
                    try {
                        sm.mkdirs(dir);
                    } catch (Exception e) {
                        Log.w(TAG, "Failed to ensure " + dir + ": " + e);
                        dir = null;
                    }
                }
            }
        }
        result[i] = dir;
    }
    return result;
}
 
Example #17
Source File: MemoryInfo.java    From MobileInfo with Apache License 2.0 6 votes vote down vote up
/**
 * API 26 android O
 * 获取总共容量大小,包括系统大小
 */
@SuppressLint("NewApi")
public static long getTotalSize(Context context, String fsUuid) {
    try {
        UUID id;
        if (fsUuid == null) {
            id = StorageManager.UUID_DEFAULT;
        } else {
            id = UUID.fromString(fsUuid);
        }
        StorageStatsManager stats = context.getSystemService(StorageStatsManager.class);
        return stats.getTotalBytes(id);
    } catch (NoSuchFieldError | NoClassDefFoundError | NullPointerException | IOException e) {
        e.printStackTrace();
        return -1;
    }
}
 
Example #18
Source File: ApplicationPackageManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
    final StorageManager storage = mContext.getSystemService(StorageManager.class);
    final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
    final List<VolumeInfo> vols = storage.getVolumes();
    final List<VolumeInfo> candidates = new ArrayList<>();
    if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
            storage.getPrimaryStorageUuid()) && currentVol != null) {
        // TODO: support moving primary physical to emulated volume
        candidates.add(currentVol);
    } else {
        for (VolumeInfo vol : vols) {
            if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
                candidates.add(vol);
            }
        }
    }
    return candidates;
}
 
Example #19
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public int movePrimaryStorage(VolumeInfo vol) {
    try {
        final String volumeUuid;
        if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
            volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
        } else if (vol.isPrimaryPhysical()) {
            volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
        } else {
            volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
        }

        return mPM.movePrimaryStorage(volumeUuid);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #20
Source File: LockSettingsService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void showEncryptionNotification(UserHandle user, CharSequence title,
        CharSequence message, CharSequence detail, PendingIntent intent) {
    if (DEBUG) Slog.v(TAG, "showing encryption notification, user: " + user.getIdentifier());

    // Suppress all notifications on non-FBE devices for now
    if (!StorageManager.isFileEncryptedNativeOrEmulated()) return;

    Notification notification =
            new Notification.Builder(mContext, SystemNotificationChannels.SECURITY)
                    .setSmallIcon(com.android.internal.R.drawable.ic_user_secure)
                    .setWhen(0)
                    .setOngoing(true)
                    .setTicker(title)
                    .setColor(mContext.getColor(
                            com.android.internal.R.color.system_notification_accent_color))
                    .setContentTitle(title)
                    .setContentText(message)
                    .setSubText(detail)
                    .setVisibility(Notification.VISIBILITY_PUBLIC)
                    .setContentIntent(intent)
                    .build();
    mNotificationManager.notifyAsUser(null, SystemMessage.NOTE_FBE_ENCRYPTED_NOTIFICATION,
        notification, user);
}
 
Example #21
Source File: ApplicationPackageManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public int movePackage(String packageName, VolumeInfo vol) {
    try {
        final String volumeUuid;
        if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
            volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
        } else if (vol.isPrimaryPhysical()) {
            volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
        } else {
            volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
        }

        return mPM.movePackage(packageName, volumeUuid);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #22
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public int movePrimaryStorage(VolumeInfo vol) {
    try {
        final String volumeUuid;
        if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
            volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
        } else if (vol.isPrimaryPhysical()) {
            volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
        } else {
            volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
        }

        return mPM.movePrimaryStorage(volumeUuid);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #23
Source File: SystemUtils.java    From letv with Apache License 2.0 6 votes vote down vote up
private static int isSdcardMounted(String path, Context context) {
    StorageManager managerStorage = (StorageManager) context.getSystemService("storage");
    if (managerStorage == null) {
        return -1;
    }
    try {
        Method method = managerStorage.getClass().getDeclaredMethod("getVolumeState", new Class[]{String.class});
        method.setAccessible(true);
        if ("mounted".equalsIgnoreCase((String) method.invoke(managerStorage, new Object[]{path}))) {
            return 1;
        }
        return 0;
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
        return -1;
    } catch (IllegalArgumentException e2) {
        e2.printStackTrace();
        return -1;
    } catch (IllegalAccessException e3) {
        e3.printStackTrace();
        return -1;
    } catch (InvocationTargetException e4) {
        e4.printStackTrace();
        return -1;
    }
}
 
Example #24
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public int movePrimaryStorage(VolumeInfo vol) {
    try {
        final String volumeUuid;
        if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
            volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
        } else if (vol.isPrimaryPhysical()) {
            volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
        } else {
            volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
        }

        return mPM.movePrimaryStorage(volumeUuid);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #25
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
    final StorageManager storage = mContext.getSystemService(StorageManager.class);
    final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
    final List<VolumeInfo> vols = storage.getVolumes();
    final List<VolumeInfo> candidates = new ArrayList<>();
    if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
            storage.getPrimaryStorageUuid()) && currentVol != null) {
        // TODO: support moving primary physical to emulated volume
        candidates.add(currentVol);
    } else {
        for (VolumeInfo vol : vols) {
            if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
                candidates.add(vol);
            }
        }
    }
    return candidates;
}
 
Example #26
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public int movePackage(String packageName, VolumeInfo vol) {
    try {
        final String volumeUuid;
        if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
            volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
        } else if (vol.isPrimaryPhysical()) {
            volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
        } else {
            volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
        }

        return mPM.movePackage(packageName, volumeUuid);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #27
Source File: TreeUriUtils.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("ObsoleteSdkInt")
private static String getVolumePath(final String volumeId, Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return null;
    try {
        StorageManager mStorageManager =
                (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
        Class<?> storageVolumeClazz = Class.forName("android.os.storage.StorageVolume");
        Method getVolumeList = mStorageManager.getClass().getMethod("getVolumeList");
        Method getUuid = storageVolumeClazz.getMethod("getUuid");
        Method getPath = storageVolumeClazz.getMethod("getPath");
        Method isPrimary = storageVolumeClazz.getMethod("isPrimary");
        Object result = getVolumeList.invoke(mStorageManager);

        final int length = Array.getLength(result);
        for (int i = 0; i < length; i++) {
            Object storageVolumeElement = Array.get(result, i);
            String uuid = (String) getUuid.invoke(storageVolumeElement);
            Boolean primary = (Boolean) isPrimary.invoke(storageVolumeElement);

            // primary volume?
            if (primary && PRIMARY_VOLUME_NAME.equals(volumeId))
                return (String) getPath.invoke(storageVolumeElement);

            // other volumes?
            if (uuid != null && uuid.equals(volumeId))
                return (String) getPath.invoke(storageVolumeElement);
        }
        // not found.
        return null;
    } catch (Exception ex) {
        return null;
    }
}
 
Example #28
Source File: StorageActivity.java    From AndroidDemo with MIT License 5 votes vote down vote up
/**
 * 获取存储块id
 *
 * @param fsUuid
 * @return
 */

private UUID getUuid(String fsUuid) {
    UUID id;
    if (fsUuid == null) {
        try {
            id = StorageManager.UUID_DEFAULT;
        } catch (NoSuchFieldError e) {
            id = UUID.fromString("41217664-9172-527a-b3d5-edabb50a7d69");
        }
    } else {
        id = UUID.fromString(fsUuid);
    }
    return id;
}
 
Example #29
Source File: UserDataPreparer.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Destroy storage areas for given user on all mounted devices.
 */
void destroyUserData(int userId, int flags) {
    synchronized (mInstallLock) {
        final StorageManager storage = mContext.getSystemService(StorageManager.class);
        for (VolumeInfo vol : storage.getWritablePrivateVolumes()) {
            final String volumeUuid = vol.getFsUuid();
            destroyUserDataLI(volumeUuid, userId, flags);
        }
    }
}
 
Example #30
Source File: StorageManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onDiskCreated(String diskId, int flags) {
    synchronized (mLock) {
        final String value = SystemProperties.get(StorageManager.PROP_ADOPTABLE);
        switch (value) {
            case "force_on":
                flags |= DiskInfo.FLAG_ADOPTABLE;
                break;
            case "force_off":
                flags &= ~DiskInfo.FLAG_ADOPTABLE;
                break;
        }
        mDisks.put(diskId, new DiskInfo(diskId, flags));
    }
}