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
This commit is contained in:
@@ -109,7 +109,9 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
|
|||||||
mStorageManager = context.getSystemService(StorageManager.class);
|
mStorageManager = context.getSystemService(StorageManager.class);
|
||||||
mStorageManager.registerListener(mStorageListener);
|
mStorageManager.registerListener(mStorageListener);
|
||||||
|
|
||||||
sTotalInternalStorage = mStorageManager.getPrimaryStorageSize();
|
if (sTotalInternalStorage <= 0) {
|
||||||
|
sTotalInternalStorage = mStorageManager.getPrimaryStorageSize();
|
||||||
|
}
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.device_info_storage);
|
addPreferencesFromResource(R.xml.device_info_storage);
|
||||||
|
|
||||||
@@ -169,8 +171,11 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
|
|||||||
if (vol.isMountedReadable()) {
|
if (vol.isMountedReadable()) {
|
||||||
final File path = vol.getPath();
|
final File path = vol.getPath();
|
||||||
privateUsedBytes += path.getTotalSpace() - path.getFreeSpace();
|
privateUsedBytes += path.getTotalSpace() - path.getFreeSpace();
|
||||||
privateTotalBytes += sTotalInternalStorage > 0
|
if (sTotalInternalStorage > 0) {
|
||||||
? sTotalInternalStorage : path.getTotalSpace();
|
privateTotalBytes = sTotalInternalStorage;
|
||||||
|
} else {
|
||||||
|
privateTotalBytes += path.getTotalSpace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (vol.getType() == VolumeInfo.TYPE_PUBLIC) {
|
} else if (vol.getType() == VolumeInfo.TYPE_PUBLIC) {
|
||||||
mExternalCategory.addPreference(
|
mExternalCategory.addPreference(
|
||||||
@@ -215,7 +220,6 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
|
|||||||
result.value, result.units));
|
result.value, result.units));
|
||||||
mInternalSummary.setSummary(getString(R.string.storage_volume_used_total,
|
mInternalSummary.setSummary(getString(R.string.storage_volume_used_total,
|
||||||
Formatter.formatFileSize(context, privateTotalBytes)));
|
Formatter.formatFileSize(context, privateTotalBytes)));
|
||||||
|
|
||||||
if (mInternalCategory.getPreferenceCount() > 0) {
|
if (mInternalCategory.getPreferenceCount() > 0) {
|
||||||
getPreferenceScreen().addPreference(mInternalCategory);
|
getPreferenceScreen().addPreference(mInternalCategory);
|
||||||
}
|
}
|
||||||
@@ -483,9 +487,12 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
|
|||||||
|
|
||||||
private void updateSummary() {
|
private void updateSummary() {
|
||||||
// TODO: Register listener.
|
// 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();
|
final List<VolumeInfo> volumes = storageManager.getVolumes();
|
||||||
long privateUsedBytes = 0;
|
long privateFreeBytes = 0;
|
||||||
long privateTotalBytes = 0;
|
long privateTotalBytes = 0;
|
||||||
for (VolumeInfo info : volumes) {
|
for (VolumeInfo info : volumes) {
|
||||||
if (info.getType() != VolumeInfo.TYPE_PUBLIC
|
if (info.getType() != VolumeInfo.TYPE_PUBLIC
|
||||||
@@ -496,13 +503,14 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
|
|||||||
if (path == null) {
|
if (path == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
privateUsedBytes += path.getTotalSpace() - path.getFreeSpace();
|
|
||||||
if (info.getType() == VolumeInfo.TYPE_PRIVATE && sTotalInternalStorage > 0) {
|
if (info.getType() == VolumeInfo.TYPE_PRIVATE && sTotalInternalStorage > 0) {
|
||||||
privateTotalBytes = sTotalInternalStorage;
|
privateTotalBytes = sTotalInternalStorage;
|
||||||
} else {
|
} else {
|
||||||
privateTotalBytes += path.getTotalSpace();
|
privateTotalBytes += path.getTotalSpace();
|
||||||
}
|
}
|
||||||
|
privateFreeBytes += path.getFreeSpace();
|
||||||
}
|
}
|
||||||
|
long privateUsedBytes = privateTotalBytes - privateFreeBytes;
|
||||||
mLoader.setSummary(this, mContext.getString(R.string.storage_summary,
|
mLoader.setSummary(this, mContext.getString(R.string.storage_summary,
|
||||||
Formatter.formatFileSize(mContext, privateUsedBytes),
|
Formatter.formatFileSize(mContext, privateUsedBytes),
|
||||||
Formatter.formatFileSize(mContext, privateTotalBytes)));
|
Formatter.formatFileSize(mContext, privateTotalBytes)));
|
||||||
|
Reference in New Issue
Block a user