Search in sources :

Example 1 with StorageVolume

use of dev.dworks.apps.anexplorer.misc.StorageVolume in project AnExplorer by 1hakr.

the class ExternalStorageProvider method updateVolumesLocked.

@TargetApi(Build.VERSION_CODES.KITKAT)
private void updateVolumesLocked() {
    mRoots.clear();
    int count = 0;
    StorageUtils storageUtils = new StorageUtils(getContext());
    for (StorageVolume storageVolume : storageUtils.getStorageMounts()) {
        final File path = storageVolume.getPathFile();
        String state = EnvironmentCompat.getStorageState(path);
        final boolean mounted = Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state);
        if (!mounted)
            continue;
        final String rootId;
        final String title;
        if (storageVolume.isPrimary()) {
            rootId = ROOT_ID_PRIMARY_EMULATED;
            title = getContext().getString(R.string.root_internal_storage);
        } else if (storageVolume.getUuid() != null) {
            rootId = ROOT_ID_SECONDARY + storageVolume.getUuid();
            String label = storageVolume.getUserLabel();
            title = !TextUtils.isEmpty(label) ? label : getContext().getString(R.string.root_external_storage) + (count > 0 ? " " + count : "");
            count++;
        } else {
            Log.d(TAG, "Missing UUID for " + storageVolume.getPath() + "; skipping");
            continue;
        }
        if (mRoots.containsKey(rootId)) {
            Log.w(TAG, "Duplicate UUID " + rootId + "; skipping");
            continue;
        }
        try {
            if (null == path.listFiles()) {
                continue;
            }
            final RootInfo root = new RootInfo();
            mRoots.put(rootId, root);
            root.rootId = rootId;
            root.flags = Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_EDIT | Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED | Root.FLAG_SUPPORTS_SEARCH | Root.FLAG_SUPPORTS_IS_CHILD;
            root.title = title;
            root.path = path;
            root.docId = getDocIdForFile(path);
        } catch (FileNotFoundException e) {
            throw new IllegalStateException(e);
        }
    }
}
Also used : StorageVolume(dev.dworks.apps.anexplorer.misc.StorageVolume) FileNotFoundException(java.io.FileNotFoundException) StorageUtils(dev.dworks.apps.anexplorer.misc.StorageUtils) DocumentInfo.getCursorString(dev.dworks.apps.anexplorer.model.DocumentInfo.getCursorString) FileUtils.getTypeForFile(dev.dworks.apps.anexplorer.misc.FileUtils.getTypeForFile) DocumentFile(android.support.provider.DocumentFile) File(java.io.File) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) TargetApi(android.annotation.TargetApi)

Example 2 with StorageVolume

use of dev.dworks.apps.anexplorer.misc.StorageVolume in project AnExplorer by 1hakr.

the class HeatMapProvider method updateVolumesLocked.

@TargetApi(Build.VERSION_CODES.KITKAT)
private void updateVolumesLocked() {
    mRoots.clear();
    mIdToPath.clear();
    mIdToRoot.clear();
    int count = 0;
    StorageUtils storageUtils = new StorageUtils(getContext());
    for (StorageVolume volume : storageUtils.getStorageMounts()) {
        final File path = volume.getPathFile();
        if (Utils.hasKitKat()) {
            String state = Environment.getStorageState(path);
            final boolean mounted = Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state);
            if (!mounted)
                continue;
        }
        final String rootId;
        if (volume.isPrimary() && volume.isEmulated()) {
            rootId = ROOT_ID_PRIMARY_EMULATED;
        } else if (volume.getUuid() != null) {
            rootId = ROOT_ID_SECONDARY + volume.getUserLabel();
        } else {
            Log.d(TAG, "Missing UUID for " + volume.getPath() + "; skipping");
            continue;
        }
        if (mIdToPath.containsKey(rootId)) {
            Log.w(TAG, "Duplicate UUID " + rootId + "; skipping");
            continue;
        }
        try {
            if (null == path.listFiles()) {
                continue;
            }
            mIdToPath.put(rootId, path);
            final RootInfo root = new RootInfo();
            root.rootId = rootId;
            root.flags = Document.FLAG_SUPPORTS_THUMBNAIL;
            if (ROOT_ID_PRIMARY_EMULATED.equals(rootId)) {
                root.title = getContext().getString(R.string.root_internal_storage);
            } else {
                count++;
                // + volume.getLabel();
                root.title = getContext().getString(R.string.root_external_storage) + " " + count;
            }
            root.docId = getDocIdForFile(path);
            mRoots.add(root);
            mIdToRoot.put(rootId, root);
        } catch (FileNotFoundException e) {
            throw new IllegalStateException(e);
        }
    }
    Log.d(TAG, "After updating volumes, found " + mRoots.size() + " active roots");
    getContext().getContentResolver().notifyChange(DocumentsContract.buildRootsUri(AUTHORITY), null, false);
}
Also used : StorageVolume(dev.dworks.apps.anexplorer.misc.StorageVolume) FileNotFoundException(java.io.FileNotFoundException) StorageUtils(dev.dworks.apps.anexplorer.misc.StorageUtils) File(java.io.File) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) TargetApi(android.annotation.TargetApi)

Aggregations

SuppressLint (android.annotation.SuppressLint)2 TargetApi (android.annotation.TargetApi)2 Point (android.graphics.Point)2 StorageUtils (dev.dworks.apps.anexplorer.misc.StorageUtils)2 StorageVolume (dev.dworks.apps.anexplorer.misc.StorageVolume)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 DocumentFile (android.support.provider.DocumentFile)1 FileUtils.getTypeForFile (dev.dworks.apps.anexplorer.misc.FileUtils.getTypeForFile)1 DocumentInfo.getCursorString (dev.dworks.apps.anexplorer.model.DocumentInfo.getCursorString)1