Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2d4f581f authored by Akshay Joshi's avatar Akshay Joshi Committed by Android (Google) Code Review
Browse files

Merge "Update storage usage to be consistent in settings"

parents ba1ca0d5 787bca62
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -160,8 +160,11 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
        mInternalCategory.addPreference(mInternalSummary);

        int privateCount = 0;
        long privateUsedBytes = 0;
        long privateTotalBytes = 0;

        final StorageManagerVolumeProvider smvp = new StorageManagerVolumeProvider(mStorageManager);
        final PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(smvp);
        final long privateTotalBytes = info.totalBytes;
        final long privateUsedBytes = info.totalBytes - info.freeBytes;

        final List<VolumeInfo> volumes = mStorageManager.getVolumes();
        Collections.sort(volumes, VolumeInfo.getDescriptionComparator());
@@ -173,11 +176,6 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
                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) {
                mExternalCategory.addPreference(
                        new StorageVolumePreference(context, vol, COLOR_PUBLIC, 0));
+26 −4
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.settings.deviceinfo;

import android.app.usage.StorageStatsManager;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
@@ -25,6 +26,7 @@ import android.os.storage.VolumeInfo;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.text.format.Formatter;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
@@ -34,6 +36,7 @@ import com.android.settings.R;
import com.android.settings.deviceinfo.StorageSettings.UnmountTask;
import com.android.settingslib.Utils;

import java.io.IOException;
import java.io.File;

/**
@@ -41,6 +44,8 @@ import java.io.File;
 * quick actions like unmounting.
 */
public class StorageVolumePreference extends Preference {
    private static final String TAG = StorageVolumePreference.class.getSimpleName();

    private final StorageManager mStorageManager;
    private final VolumeInfo mVolume;

@@ -70,11 +75,28 @@ public class StorageVolumePreference extends Preference {
        if (volume.isMountedReadable()) {
            // TODO: move statfs() to background thread
            final File path = volume.getPath();

            long freeBytes = 0;
            long usedBytes = 0;
            if (volume.getType() == VolumeInfo.TYPE_PRIVATE) {
                final StorageStatsManager stats =
                        context.getSystemService(StorageStatsManager.class);
                try {
                    totalBytes = stats.getTotalBytes(volume.getFsUuid());
                    freeBytes = stats.getFreeBytes(volume.getFsUuid());
                    usedBytes = totalBytes - freeBytes;
                } catch (IOException e) {
                    Log.w(TAG, e);
                }
            } else {
                // StorageStatsManager can only query private volumes.
                // Default to previous storage calculation for public volumes.
                if (totalBytes <= 0) {
                    totalBytes = path.getTotalSpace();
                }
            final long freeBytes = path.getFreeSpace();
            final long usedBytes = totalBytes - freeBytes;
                freeBytes = path.getFreeSpace();
                usedBytes = totalBytes - freeBytes;
            }

            final String used = Formatter.formatFileSize(context, usedBytes);
            final String total = Formatter.formatFileSize(context, totalBytes);