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

Commit 7dfc8dfc authored by Fan Zhang's avatar Fan Zhang
Browse files

Display storage summary with correct used/total size.

Fixes: 30421727

We need to first initialize sTotalInternalStorage in order to compute
used size for both full blown storage fragment and storage tile summary.

Also fixed a bug where sTotalInteralStorage is incorrectly added
multiple times when there are multiple private volumes.

Change-Id: Iabb869c3184ec0c468aeacea34c804b90b4965f1
parent 503a7514
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -109,7 +109,9 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
        mStorageManager = context.getSystemService(StorageManager.class);
        mStorageManager.registerListener(mStorageListener);

        if (sTotalInternalStorage <= 0) {
            sTotalInternalStorage = mStorageManager.getPrimaryStorageSize();
        }

        addPreferencesFromResource(R.xml.device_info_storage);

@@ -169,8 +171,11 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
                if (vol.isMountedReadable()) {
                    final File path = vol.getPath();
                    privateUsedBytes += path.getTotalSpace() - path.getFreeSpace();
                    privateTotalBytes += sTotalInternalStorage > 0
                            ? sTotalInternalStorage : path.getTotalSpace();
                    if (sTotalInternalStorage > 0) {
                        privateTotalBytes = sTotalInternalStorage;
                    } else {
                        privateTotalBytes += path.getTotalSpace();
                    }
                }
            } else if (vol.getType() == VolumeInfo.TYPE_PUBLIC) {
                mExternalCategory.addPreference(
@@ -215,7 +220,6 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
                result.value, result.units));
        mInternalSummary.setSummary(getString(R.string.storage_volume_used_total,
                Formatter.formatFileSize(context, privateTotalBytes)));

        if (mInternalCategory.getPreferenceCount() > 0) {
            getPreferenceScreen().addPreference(mInternalCategory);
        }
@@ -483,9 +487,12 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index

        private void updateSummary() {
            // TODO: Register listener.
            StorageManager storageManager = mContext.getSystemService(StorageManager.class);
            final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
            if (sTotalInternalStorage <= 0) {
                sTotalInternalStorage = storageManager.getPrimaryStorageSize();
            }
            final List<VolumeInfo> volumes = storageManager.getVolumes();
            long privateUsedBytes = 0;
            long privateFreeBytes = 0;
            long privateTotalBytes = 0;
            for (VolumeInfo info : volumes) {
                if (info.getType() != VolumeInfo.TYPE_PUBLIC
@@ -496,13 +503,14 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
                if (path == null) {
                    continue;
                }
                privateUsedBytes += path.getTotalSpace() - path.getFreeSpace();
                if (info.getType() == VolumeInfo.TYPE_PRIVATE && sTotalInternalStorage > 0) {
                    privateTotalBytes = sTotalInternalStorage;
                } else {
                    privateTotalBytes += path.getTotalSpace();
                }
                privateFreeBytes += path.getFreeSpace();
            }
            long privateUsedBytes = privateTotalBytes - privateFreeBytes;
            mLoader.setSummary(this, mContext.getString(R.string.storage_summary,
                    Formatter.formatFileSize(mContext, privateUsedBytes),
                    Formatter.formatFileSize(mContext, privateTotalBytes)));