Search in sources :

Example 21 with DiskInfo

use of android.os.storage.DiskInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class StorageSettings method refresh.

private void refresh() {
    final Context context = getPrefContext();
    getPreferenceScreen().removeAll();
    mInternalCategory.removeAll();
    mExternalCategory.removeAll();
    mInternalCategory.addPreference(mInternalSummary);
    int privateCount = 0;
    long privateUsedBytes = 0;
    long privateTotalBytes = 0;
    final List<VolumeInfo> volumes = mStorageManager.getVolumes();
    Collections.sort(volumes, VolumeInfo.getDescriptionComparator());
    for (VolumeInfo vol : volumes) {
        if (vol.getType() == VolumeInfo.TYPE_PRIVATE) {
            final long volumeTotalBytes = PrivateStorageInfo.getTotalSize(vol, sTotalInternalStorage);
            final int color = COLOR_PRIVATE[privateCount++ % COLOR_PRIVATE.length];
            mInternalCategory.addPreference(new StorageVolumePreference(context, vol, color, volumeTotalBytes));
            if (vol.isMountedReadable()) {
                final File path = vol.getPath();
                privateUsedBytes += (volumeTotalBytes - path.getFreeSpace());
                privateTotalBytes += volumeTotalBytes;
            }
        } else if (vol.getType() == VolumeInfo.TYPE_PUBLIC) {
            StorageVolumePreference ExStorageVolumePreference = new StorageVolumePreference(context, vol, COLOR_PUBLIC, 0);
            //Disable preference when in change
            ExStorageVolumePreference.setEnabled(vol.getState() != VolumeInfo.STATE_CHECKING && vol.getState() != VolumeInfo.STATE_EJECTING);
            mExternalCategory.addPreference(ExStorageVolumePreference);
        }
    }
    // Show missing private volumes
    final List<VolumeRecord> recs = mStorageManager.getVolumeRecords();
    for (VolumeRecord rec : recs) {
        if (rec.getType() == VolumeInfo.TYPE_PRIVATE && mStorageManager.findVolumeByUuid(rec.getFsUuid()) == null) {
            // TODO: add actual storage type to record
            final Drawable icon = context.getDrawable(R.drawable.ic_sim_sd);
            icon.mutate();
            icon.setTint(COLOR_PUBLIC);
            icon.setTintMode(PorterDuff.Mode.SRC_ATOP);
            final Preference pref = new Preference(context);
            pref.setKey(rec.getFsUuid());
            pref.setTitle(rec.getNickname());
            pref.setSummary(com.android.internal.R.string.ext_media_status_missing);
            pref.setIcon(icon);
            mInternalCategory.addPreference(pref);
        }
    }
    // Show unsupported disks to give a chance to init
    final List<DiskInfo> disks = mStorageManager.getDisks();
    for (DiskInfo disk : disks) {
        if (disk.volumeCount == 0 && disk.size > 0) {
            final Preference pref = new Preference(context);
            pref.setKey(disk.getId());
            pref.setTitle(disk.getDescription());
            pref.setSummary(com.android.internal.R.string.ext_media_status_unsupported);
            pref.setIcon(R.drawable.ic_sim_sd);
            mExternalCategory.addPreference(pref);
        }
    }
    final BytesResult result = Formatter.formatBytes(getResources(), privateUsedBytes, 0);
    mInternalSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large), result.value, result.units));
    mInternalSummary.setSummary(getString(R.string.storage_volume_used_total, Formatter.formatFileSize(context, privateTotalBytes)));
    if (mInternalCategory.getPreferenceCount() > 0) {
        getPreferenceScreen().addPreference(mInternalCategory);
    }
    if (mExternalCategory.getPreferenceCount() > 0) {
        getPreferenceScreen().addPreference(mExternalCategory);
    }
    if (mInternalCategory.getPreferenceCount() == 2 && mExternalCategory.getPreferenceCount() == 0) {
        // Only showing primary internal storage, so just shortcut
        final Bundle args = new Bundle();
        args.putString(VolumeInfo.EXTRA_VOLUME_ID, VolumeInfo.ID_PRIVATE_INTERNAL);
        PrivateVolumeSettings.setVolumeSize(args, sTotalInternalStorage);
        Intent intent = Utils.onBuildStartFragmentIntent(getActivity(), PrivateVolumeSettings.class.getName(), args, null, R.string.apps_storage, null, false);
        intent.putExtra(SettingsDrawerActivity.EXTRA_SHOW_MENU, true);
        getActivity().startActivity(intent);
        finish();
    }
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) Drawable(android.graphics.drawable.Drawable) DiskInfo(android.os.storage.DiskInfo) VolumeInfo(android.os.storage.VolumeInfo) Intent(android.content.Intent) BytesResult(android.text.format.Formatter.BytesResult) VolumeRecord(android.os.storage.VolumeRecord) Preference(android.support.v7.preference.Preference) File(java.io.File)

Example 22 with DiskInfo

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

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 23 with DiskInfo

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

the class StorageNotification method onVolumeEjecting.

private Notification onVolumeEjecting(VolumeInfo vol) {
    final DiskInfo disk = vol.getDisk();
    final CharSequence title = mContext.getString(R.string.ext_media_unmounting_notification_title, disk.getDescription());
    final CharSequence text = mContext.getString(R.string.ext_media_unmounting_notification_message, disk.getDescription());
    return buildNotificationBuilder(vol, title, text).setCategory(Notification.CATEGORY_PROGRESS).setPriority(Notification.PRIORITY_LOW).setOngoing(true).build();
}
Also used : DiskInfo(android.os.storage.DiskInfo)

Example 24 with DiskInfo

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

the class StorageNotification method onVolumeRemoved.

private Notification onVolumeRemoved(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_nomedia_notification_title, disk.getDescription());
    final CharSequence text = mContext.getString(R.string.ext_media_nomedia_notification_message, disk.getDescription());
    return buildNotificationBuilder(vol, title, text).setCategory(Notification.CATEGORY_ERROR).build();
}
Also used : DiskInfo(android.os.storage.DiskInfo)

Example 25 with DiskInfo

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

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