Search in sources :

Example 1 with StorageUtils

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

the class AppsProvider method queryRoots.

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    StorageUtils storageUtils = new StorageUtils(getContext());
    final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
    final RowBuilder row = result.newRow();
    row.add(Root.COLUMN_ROOT_ID, ROOT_ID_USER_APP);
    row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED | Root.FLAG_SUPER_ADVANCED | Root.FLAG_SUPPORTS_SEARCH);
    row.add(Root.COLUMN_ICON, R.drawable.ic_root_apps);
    row.add(Root.COLUMN_TITLE, getContext().getString(R.string.root_apps));
    row.add(Root.COLUMN_DOCUMENT_ID, ROOT_ID_USER_APP);
    row.add(Root.COLUMN_AVAILABLE_BYTES, storageUtils.getPartionSize(StorageUtils.PARTITION_DATA, false));
    row.add(Root.COLUMN_CAPACITY_BYTES, storageUtils.getPartionSize(StorageUtils.PARTITION_DATA, true));
    final RowBuilder row1 = result.newRow();
    row1.add(Root.COLUMN_ROOT_ID, ROOT_ID_SYSTEM_APP);
    row1.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED | Root.FLAG_SUPER_ADVANCED | Root.FLAG_SUPPORTS_SEARCH);
    row1.add(Root.COLUMN_ICON, R.drawable.ic_root_apps);
    row1.add(Root.COLUMN_TITLE, getContext().getString(R.string.root_system_apps));
    row1.add(Root.COLUMN_DOCUMENT_ID, ROOT_ID_SYSTEM_APP);
    row1.add(Root.COLUMN_AVAILABLE_BYTES, storageUtils.getPartionSize(StorageUtils.PARTITION_DATA, false));
    row1.add(Root.COLUMN_CAPACITY_BYTES, storageUtils.getPartionSize(StorageUtils.PARTITION_DATA, true));
    final RowBuilder row2 = result.newRow();
    row2.add(Root.COLUMN_ROOT_ID, ROOT_ID_PROCESS);
    row2.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED | Root.FLAG_SUPER_ADVANCED | Root.FLAG_SUPPORTS_SEARCH);
    row2.add(Root.COLUMN_ICON, R.drawable.ic_root_process);
    row2.add(Root.COLUMN_TITLE, getContext().getString(R.string.root_processes));
    row2.add(Root.COLUMN_DOCUMENT_ID, ROOT_ID_PROCESS);
    row2.add(Root.COLUMN_AVAILABLE_BYTES, storageUtils.getPartionSize(StorageUtils.PARTITION_RAM, false));
    row2.add(Root.COLUMN_CAPACITY_BYTES, storageUtils.getPartionSize(StorageUtils.PARTITION_RAM, true));
    return result;
}
Also used : StorageUtils(dev.dworks.apps.anexplorer.misc.StorageUtils) RowBuilder(dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Example 2 with StorageUtils

use of dev.dworks.apps.anexplorer.misc.StorageUtils 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 3 with StorageUtils

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

the class ExternalStorageProvider method updateVolumesLocked2.

private void updateVolumesLocked2() {
    mRoots.clear();
    VolumeInfo primaryVolume = null;
    // UserHandle.myUserId();
    final int userId = 0;
    StorageUtils storageUtils = new StorageUtils(getContext());
    for (VolumeInfo volume : storageUtils.getVolumes()) {
        if (!volume.isMountedReadable())
            continue;
        final String rootId;
        final String title;
        if (volume.getType() == VolumeInfo.TYPE_EMULATED) {
            // We currently only support a single emulated volume mounted at
            // a time, and it's always considered the primary
            rootId = ROOT_ID_PRIMARY_EMULATED;
            if (VolumeInfo.ID_EMULATED_INTERNAL.equals(volume.getId())) {
                title = getContext().getString(R.string.root_internal_storage);
            } else {
                // This should cover all other storage devices, like an SD card
                // or USB OTG drive plugged in. Using getBestVolumeDescription()
                // will give us a nice string like "Samsung SD card" or "SanDisk USB drive"
                final VolumeInfo privateVol = storageUtils.findPrivateForEmulated(volume);
                title = StorageUtils.getBestVolumeDescription(getContext(), privateVol);
            }
        } else if (volume.getType() == VolumeInfo.TYPE_PUBLIC) {
            rootId = ROOT_ID_SECONDARY + volume.getFsUuid();
            title = StorageUtils.getBestVolumeDescription(getContext(), volume);
        } else {
            // Unsupported volume; ignore
            continue;
        }
        if (TextUtils.isEmpty(rootId)) {
            Log.d(TAG, "Missing UUID for " + volume.getId() + "; skipping");
            continue;
        }
        if (mRoots.containsKey(rootId)) {
            Log.w(TAG, "Duplicate UUID " + rootId + " for " + volume.getId() + "; skipping");
            continue;
        }
        final RootInfo root = new RootInfo();
        mRoots.put(rootId, root);
        root.rootId = rootId;
        root.flags = Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_SEARCH | Root.FLAG_SUPPORTS_IS_CHILD;
        final DiskInfo disk = volume.getDisk();
        Log.d(TAG, "Disk for root " + rootId + " is " + disk);
        if (disk != null && disk.isSd()) {
            root.flags |= Root.FLAG_REMOVABLE_SD;
        } else if (disk != null && disk.isUsb()) {
            root.flags |= Root.FLAG_REMOVABLE_USB;
        }
        if (volume.isPrimary()) {
            // save off the primary volume for subsequent "Home" dir initialization.
            primaryVolume = volume;
            root.flags |= Root.FLAG_ADVANCED;
        }
        // Dunno when this would NOT be the case, but never hurts to be correct.
        if (volume.isMountedWritable()) {
            root.flags |= Root.FLAG_SUPPORTS_CREATE;
        }
        root.title = title;
        if (volume.getType() == VolumeInfo.TYPE_PUBLIC) {
            root.flags |= Root.FLAG_HAS_SETTINGS;
        }
        if (volume.isVisibleForRead(userId)) {
            root.visiblePath = volume.getPathForUser(userId);
        } else {
            root.visiblePath = null;
        }
        root.path = volume.getInternalPathForUser(userId);
        try {
            root.docId = getDocIdForFile(root.path);
        } catch (FileNotFoundException e) {
            throw new IllegalStateException(e);
        }
    }
    // by calling either getPathForUser, or getInternalPathForUser.
    if (primaryVolume != null && primaryVolume.isVisible()) {
        final RootInfo root = new RootInfo();
        mRoots.put(root.rootId, root);
        root.rootId = ROOT_ID_HOME;
        root.title = getContext().getString(R.string.root_documents);
        // Only report bytes on *volumes*...as a matter of policy.
        root.reportAvailableBytes = false;
        root.flags = Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_SEARCH | Root.FLAG_SUPPORTS_IS_CHILD;
        // Dunno when this would NOT be the case, but never hurts to be correct.
        if (primaryVolume.isMountedWritable()) {
            root.flags |= Root.FLAG_SUPPORTS_CREATE;
        }
        // Create the "Documents" directory on disk (don't use the localized title).
        root.visiblePath = new File(primaryVolume.getPathForUser(userId), Environment.DIRECTORY_DOCUMENTS);
        root.path = new File(primaryVolume.getInternalPathForUser(userId), Environment.DIRECTORY_DOCUMENTS);
        root.path = new File(primaryVolume.getInternalPathForUser(userId), Environment.DIRECTORY_DOCUMENTS);
        try {
            root.docId = getDocIdForFile(root.path);
        } catch (FileNotFoundException e) {
            throw new IllegalStateException(e);
        }
    }
    Log.d(TAG, "After updating volumes, found " + mRoots.size() + " active roots");
    // Note this affects content://com.android.externalstorage.documents/root/39BD-07C5
    // as well as content://com.android.externalstorage.documents/document/*/children,
    // so just notify on content://com.android.externalstorage.documents/.
    notifyRootsChanged(getContext());
}
Also used : FileNotFoundException(java.io.FileNotFoundException) DiskInfo(dev.dworks.apps.anexplorer.misc.DiskInfo) VolumeInfo(dev.dworks.apps.anexplorer.misc.VolumeInfo) 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)

Example 4 with StorageUtils

use of dev.dworks.apps.anexplorer.misc.StorageUtils 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

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