Fixed storage calculation when SD card is adopted as internal storage.
am: 454d7fcca8
Change-Id: I4fa4a4c489b3f65c6aab2f012d0898442dda4c2a
This commit is contained in:
@@ -58,6 +58,7 @@ import java.io.File;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
|
|
||||||
@@ -165,17 +166,14 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
|
|||||||
|
|
||||||
for (VolumeInfo vol : volumes) {
|
for (VolumeInfo vol : volumes) {
|
||||||
if (vol.getType() == VolumeInfo.TYPE_PRIVATE) {
|
if (vol.getType() == VolumeInfo.TYPE_PRIVATE) {
|
||||||
|
final long volumeTotalBytes = getTotalSize(vol);
|
||||||
final int color = COLOR_PRIVATE[privateCount++ % COLOR_PRIVATE.length];
|
final int color = COLOR_PRIVATE[privateCount++ % COLOR_PRIVATE.length];
|
||||||
mInternalCategory.addPreference(
|
mInternalCategory.addPreference(
|
||||||
new StorageVolumePreference(context, vol, color, sTotalInternalStorage));
|
new StorageVolumePreference(context, vol, color, volumeTotalBytes));
|
||||||
if (vol.isMountedReadable()) {
|
if (vol.isMountedReadable()) {
|
||||||
final File path = vol.getPath();
|
final File path = vol.getPath();
|
||||||
privateUsedBytes += path.getTotalSpace() - path.getFreeSpace();
|
privateUsedBytes += (volumeTotalBytes - path.getFreeSpace());
|
||||||
if (sTotalInternalStorage > 0) {
|
privateTotalBytes += volumeTotalBytes;
|
||||||
privateTotalBytes = sTotalInternalStorage;
|
|
||||||
} else {
|
|
||||||
privateTotalBytes += path.getTotalSpace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (vol.getType() == VolumeInfo.TYPE_PUBLIC) {
|
} else if (vol.getType() == VolumeInfo.TYPE_PUBLIC) {
|
||||||
mExternalCategory.addPreference(
|
mExternalCategory.addPreference(
|
||||||
@@ -277,7 +275,7 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
|
|||||||
if (vol.getType() == VolumeInfo.TYPE_PRIVATE) {
|
if (vol.getType() == VolumeInfo.TYPE_PRIVATE) {
|
||||||
final Bundle args = new Bundle();
|
final Bundle args = new Bundle();
|
||||||
args.putString(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
|
args.putString(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
|
||||||
PrivateVolumeSettings.setVolumeSize(args, sTotalInternalStorage);
|
PrivateVolumeSettings.setVolumeSize(args, getTotalSize(vol));
|
||||||
startFragment(this, PrivateVolumeSettings.class.getCanonicalName(),
|
startFragment(this, PrivateVolumeSettings.class.getCanonicalName(),
|
||||||
-1, 0, args);
|
-1, 0, args);
|
||||||
return true;
|
return true;
|
||||||
@@ -495,19 +493,11 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
|
|||||||
long privateFreeBytes = 0;
|
long privateFreeBytes = 0;
|
||||||
long privateTotalBytes = 0;
|
long privateTotalBytes = 0;
|
||||||
for (VolumeInfo info : volumes) {
|
for (VolumeInfo info : volumes) {
|
||||||
if (info.getType() != VolumeInfo.TYPE_PUBLIC
|
|
||||||
&& info.getType() != VolumeInfo.TYPE_PRIVATE) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
final File path = info.getPath();
|
final File path = info.getPath();
|
||||||
if (path == null) {
|
if (info.getType() != VolumeInfo.TYPE_PRIVATE || path == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (info.getType() == VolumeInfo.TYPE_PRIVATE && sTotalInternalStorage > 0) {
|
privateTotalBytes += getTotalSize(info);
|
||||||
privateTotalBytes = sTotalInternalStorage;
|
|
||||||
} else {
|
|
||||||
privateTotalBytes += path.getTotalSpace();
|
|
||||||
}
|
|
||||||
privateFreeBytes += path.getFreeSpace();
|
privateFreeBytes += path.getFreeSpace();
|
||||||
}
|
}
|
||||||
long privateUsedBytes = privateTotalBytes - privateFreeBytes;
|
long privateUsedBytes = privateTotalBytes - privateFreeBytes;
|
||||||
@@ -517,6 +507,27 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static long getTotalSize(VolumeInfo info) {
|
||||||
|
// Device could have more than one primary storage, which could be located in the
|
||||||
|
// internal flash (UUID_PRIVATE_INTERNAL) or in an external disk.
|
||||||
|
// If it's internal, try to get its total size from StorageManager first
|
||||||
|
// (sTotalInternalStorage), since that size is more precise because it accounts for
|
||||||
|
// the system partition.
|
||||||
|
if (info.getType() == VolumeInfo.TYPE_PRIVATE
|
||||||
|
&& Objects.equals(info.getFsUuid(), StorageManager.UUID_PRIVATE_INTERNAL)
|
||||||
|
&& sTotalInternalStorage > 0) {
|
||||||
|
return sTotalInternalStorage;
|
||||||
|
} else {
|
||||||
|
final File path = info.getPath();
|
||||||
|
if (path == null) {
|
||||||
|
// Should not happen, caller should have checked.
|
||||||
|
Log.e(TAG, "info's path is null on getTotalSize(): " + info);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return path.getTotalSpace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
|
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
|
||||||
= new SummaryLoader.SummaryProviderFactory() {
|
= new SummaryLoader.SummaryProviderFactory() {
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user