Search in sources :

Example 6 with DiskInfo

use of android.os.storage.DiskInfo in project platform_frameworks_base by android.

the class ExternalStorageProvider method updateVolumesLocked.

private void updateVolumesLocked() {
    mRoots.clear();
    VolumeInfo primaryVolume = null;
    final int userId = UserHandle.myUserId();
    final List<VolumeInfo> volumes = mStorageManager.getVolumes();
    for (VolumeInfo volume : volumes) {
        if (!volume.isMountedReadable())
            continue;
        final String rootId;
        final String title;
        if (volume.getType() == VolumeInfo.TYPE_EMULATED) {
            // a time, and it's always considered the primary
            if (DEBUG)
                Log.d(TAG, "Found primary volume: " + volume);
            rootId = ROOT_ID_PRIMARY_EMULATED;
            if (VolumeInfo.ID_EMULATED_INTERNAL.equals(volume.getId())) {
                // This is basically the user's primary device storage.
                // Use device name for the volume since this is likely same thing
                // the user sees when they mount their phone on another device.
                String deviceName = Settings.Global.getString(getContext().getContentResolver(), Settings.Global.DEVICE_NAME);
                // Device name should always be set. In case it isn't, though,
                // fall back to a localized "Internal Storage" string.
                title = !TextUtils.isEmpty(deviceName) ? deviceName : 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 = mStorageManager.findPrivateForEmulated(volume);
                title = mStorageManager.getBestVolumeDescription(privateVol);
            }
        } else if (volume.getType() == VolumeInfo.TYPE_PUBLIC) {
            rootId = volume.getFsUuid();
            title = mStorageManager.getBestVolumeDescription(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();
        if (DEBUG)
            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();
        root.rootId = ROOT_ID_HOME;
        mRoots.put(root.rootId, root);
        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);
        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/.
    getContext().getContentResolver().notifyChange(BASE_URI, null, false);
}
Also used : FileNotFoundException(java.io.FileNotFoundException) DiskInfo(android.os.storage.DiskInfo) VolumeInfo(android.os.storage.VolumeInfo) File(java.io.File) Point(android.graphics.Point)

Example 7 with DiskInfo

use of android.os.storage.DiskInfo in project android_frameworks_base by DirtyUnicorns.

the class ExternalStorageProvider method updateVolumesLocked.

private void updateVolumesLocked() {
    mRoots.clear();
    VolumeInfo primaryVolume = null;
    final int userId = UserHandle.myUserId();
    final List<VolumeInfo> volumes = mStorageManager.getVolumes();
    for (VolumeInfo volume : volumes) {
        if (!volume.isMountedReadable())
            continue;
        final String rootId;
        final String title;
        if (volume.getType() == VolumeInfo.TYPE_EMULATED) {
            // a time, and it's always considered the primary
            if (DEBUG)
                Log.d(TAG, "Found primary volume: " + volume);
            rootId = ROOT_ID_PRIMARY_EMULATED;
            if (VolumeInfo.ID_EMULATED_INTERNAL.equals(volume.getId())) {
                // This is basically the user's primary device storage.
                // Use device name for the volume since this is likely same thing
                // the user sees when they mount their phone on another device.
                String deviceName = Settings.Global.getString(getContext().getContentResolver(), Settings.Global.DEVICE_NAME);
                // Device name should always be set. In case it isn't, though,
                // fall back to a localized "Internal Storage" string.
                title = !TextUtils.isEmpty(deviceName) ? deviceName : 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 = mStorageManager.findPrivateForEmulated(volume);
                title = mStorageManager.getBestVolumeDescription(privateVol);
            }
        } else if (volume.getType() == VolumeInfo.TYPE_PUBLIC && volume.getMountUserId() == userId) {
            rootId = volume.getFsUuid();
            title = mStorageManager.getBestVolumeDescription(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();
        if (DEBUG)
            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();
        root.rootId = ROOT_ID_HOME;
        mRoots.put(root.rootId, root);
        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);
        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/.
    getContext().getContentResolver().notifyChange(BASE_URI, null, false);
}
Also used : FileNotFoundException(java.io.FileNotFoundException) DiskInfo(android.os.storage.DiskInfo) VolumeInfo(android.os.storage.VolumeInfo) File(java.io.File) Point(android.graphics.Point)

Example 8 with DiskInfo

use of android.os.storage.DiskInfo in project android_frameworks_base by DirtyUnicorns.

the class Sm method runListDisks.

public void runListDisks() throws RemoteException {
    final boolean onlyAdoptable = "adoptable".equals(nextArg());
    final DiskInfo[] disks = mSm.getDisks();
    for (DiskInfo disk : disks) {
        if (!onlyAdoptable || disk.isAdoptable()) {
            System.out.println(disk.getId());
        }
    }
}
Also used : DiskInfo(android.os.storage.DiskInfo)

Example 9 with DiskInfo

use of android.os.storage.DiskInfo in project android_frameworks_base by DirtyUnicorns.

the class StorageNotification method start.

@Override
public void start() {
    mNotificationManager = mContext.getSystemService(NotificationManager.class);
    mStorageManager = mContext.getSystemService(StorageManager.class);
    mStorageManager.registerListener(mListener);
    mContext.registerReceiver(mSnoozeReceiver, new IntentFilter(ACTION_SNOOZE_VOLUME), android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS, null);
    mContext.registerReceiver(mFinishReceiver, new IntentFilter(ACTION_FINISH_WIZARD), android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS, null);
    // Kick current state into place
    final List<DiskInfo> disks = mStorageManager.getDisks();
    for (DiskInfo disk : disks) {
        onDiskScannedInternal(disk, disk.volumeCount);
    }
    final List<VolumeInfo> vols = mStorageManager.getVolumes();
    for (VolumeInfo vol : vols) {
        onVolumeStateChangedInternal(vol);
    }
    mContext.getPackageManager().registerMoveCallback(mMoveCallback, new Handler());
    updateMissingPrivateVolumes();
}
Also used : IntentFilter(android.content.IntentFilter) NotificationManager(android.app.NotificationManager) StorageManager(android.os.storage.StorageManager) DiskInfo(android.os.storage.DiskInfo) Handler(android.os.Handler) VolumeInfo(android.os.storage.VolumeInfo)

Example 10 with DiskInfo

use of android.os.storage.DiskInfo in project android_frameworks_base by DirtyUnicorns.

the class StorageNotification method onVolumeBadRemoval.

private Notification onVolumeBadRemoval(VolumeInfo vol) {
    if (!vol.isPrimary()) {
        // Ignore non-primary media
        return null;
    }
    final DiskInfo disk = vol.getDisk();
    final CharSequence title = mContext.getString(R.string.ext_media_badremoval_notification_title, disk.getDescription());
    final CharSequence text = mContext.getString(R.string.ext_media_badremoval_notification_message, disk.getDescription());
    return buildNotificationBuilder(vol, title, text).setCategory(Notification.CATEGORY_ERROR).build();
}
Also used : DiskInfo(android.os.storage.DiskInfo)

Aggregations

DiskInfo (android.os.storage.DiskInfo)51 VolumeInfo (android.os.storage.VolumeInfo)16 VolumeRecord (android.os.storage.VolumeRecord)11 File (java.io.File)6 Notification (android.app.Notification)5 Action (android.app.Notification.Action)5 NotificationManager (android.app.NotificationManager)5 PendingIntent (android.app.PendingIntent)5 IntentFilter (android.content.IntentFilter)5 Point (android.graphics.Point)5 Handler (android.os.Handler)5 IBinder (android.os.IBinder)5 RemoteCallbackList (android.os.RemoteCallbackList)5 StorageManager (android.os.storage.StorageManager)5 IndentingPrintWriter (com.android.internal.util.IndentingPrintWriter)5 FileNotFoundException (java.io.FileNotFoundException)5 ArrayList (java.util.ArrayList)5 LinkedList (java.util.LinkedList)5 List (java.util.List)5 Entry (java.util.Map.Entry)5