Treat cache storage usage as available space.
Bug: 7123160 Change-Id: I1b3f36622be557d7c47f1452832f67da40893a02
This commit is contained in:
@@ -96,6 +96,9 @@ public class StorageMeasurement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class MeasurementDetails {
|
public static class MeasurementDetails {
|
||||||
|
public long totalSize;
|
||||||
|
public long availSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Total apps disk usage.
|
* Total apps disk usage.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -110,6 +113,11 @@ public class StorageMeasurement {
|
|||||||
*/
|
*/
|
||||||
public long appsSize;
|
public long appsSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Total cache disk usage by apps.
|
||||||
|
*/
|
||||||
|
public long cacheSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Total media disk usage, categorized by types such as
|
* Total media disk usage, categorized by types such as
|
||||||
* {@link Environment#DIRECTORY_MUSIC}.
|
* {@link Environment#DIRECTORY_MUSIC}.
|
||||||
@@ -237,34 +245,36 @@ public class StorageMeasurement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addStatsLocked(PackageStats stats) {
|
private void addStatsLocked(PackageStats stats) {
|
||||||
final long externalSize = stats.externalCodeSize + stats.externalDataSize
|
|
||||||
+ stats.externalCacheSize + stats.externalMediaSize;
|
|
||||||
|
|
||||||
if (mIsInternal) {
|
if (mIsInternal) {
|
||||||
final long codeSize;
|
long codeSize = stats.codeSize;
|
||||||
final long dataSize;
|
long dataSize = stats.dataSize;
|
||||||
|
long cacheSize = stats.cacheSize;
|
||||||
if (Environment.isExternalStorageEmulated()) {
|
if (Environment.isExternalStorageEmulated()) {
|
||||||
// OBB is shared on emulated storage, so count once as code,
|
// Include emulated storage when measuring internal. OBB is
|
||||||
// and data includes emulated storage.
|
// shared on emulated storage, so treat as code.
|
||||||
codeSize = stats.codeSize + stats.externalObbSize;
|
codeSize += stats.externalCodeSize + stats.externalObbSize;
|
||||||
dataSize = stats.dataSize + externalSize;
|
dataSize += stats.externalDataSize + stats.externalMediaSize;
|
||||||
} else {
|
cacheSize += stats.externalCacheSize;
|
||||||
codeSize = stats.codeSize;
|
|
||||||
dataSize = stats.dataSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include code and combined data for current user
|
// Count code and data for current user
|
||||||
if (stats.userHandle == mCurrentUser) {
|
if (stats.userHandle == mCurrentUser) {
|
||||||
mDetails.appsSize += codeSize;
|
mDetails.appsSize += codeSize;
|
||||||
mDetails.appsSize += dataSize;
|
mDetails.appsSize += dataSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include combined data for user summary
|
// User summary only includes data (code is only counted once
|
||||||
|
// for the current user)
|
||||||
addValue(mDetails.usersSize, stats.userHandle, dataSize);
|
addValue(mDetails.usersSize, stats.userHandle, dataSize);
|
||||||
|
|
||||||
|
// Include cache for all users
|
||||||
|
mDetails.cacheSize += cacheSize;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Physical storage; only count external sizes
|
// Physical storage; only count external sizes
|
||||||
mDetails.appsSize += externalSize + stats.externalObbSize;
|
mDetails.appsSize += stats.externalCodeSize + stats.externalDataSize
|
||||||
|
+ stats.externalMediaSize + stats.externalObbSize;
|
||||||
|
mDetails.cacheSize += stats.externalCacheSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -389,6 +399,9 @@ public class StorageMeasurement {
|
|||||||
final MeasurementDetails details = new MeasurementDetails();
|
final MeasurementDetails details = new MeasurementDetails();
|
||||||
final Message finished = obtainMessage(MSG_COMPLETED, details);
|
final Message finished = obtainMessage(MSG_COMPLETED, details);
|
||||||
|
|
||||||
|
details.totalSize = mTotalSize;
|
||||||
|
details.availSize = mAvailSize;
|
||||||
|
|
||||||
final UserManager userManager = (UserManager) context.getSystemService(
|
final UserManager userManager = (UserManager) context.getSystemService(
|
||||||
Context.USER_SERVICE);
|
Context.USER_SERVICE);
|
||||||
final List<UserInfo> users = userManager.getUsers();
|
final List<UserInfo> users = userManager.getUsers();
|
||||||
|
@@ -312,6 +312,10 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory {
|
|||||||
final boolean showDetails = mVolume == null || mVolume.isPrimary();
|
final boolean showDetails = mVolume == null || mVolume.isPrimary();
|
||||||
if (!showDetails) return;
|
if (!showDetails) return;
|
||||||
|
|
||||||
|
// Count caches as available space, since system manages them
|
||||||
|
mItemTotal.setSummary(formatSize(details.totalSize));
|
||||||
|
mItemAvailable.setSummary(formatSize(details.availSize + details.cacheSize));
|
||||||
|
|
||||||
mUsageBarPreference.clear();
|
mUsageBarPreference.clear();
|
||||||
|
|
||||||
updatePreference(mItemApps, details.appsSize);
|
updatePreference(mItemApps, details.appsSize);
|
||||||
@@ -326,7 +330,7 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory {
|
|||||||
updatePreference(mItemMusic, musicSize);
|
updatePreference(mItemMusic, musicSize);
|
||||||
|
|
||||||
final long downloadsSize = totalValues(details.mediaSize, Environment.DIRECTORY_DOWNLOADS);
|
final long downloadsSize = totalValues(details.mediaSize, Environment.DIRECTORY_DOWNLOADS);
|
||||||
updatePreference(mItemDownloads, musicSize);
|
updatePreference(mItemDownloads, downloadsSize);
|
||||||
|
|
||||||
updatePreference(mItemMisc, details.miscSize);
|
updatePreference(mItemMisc, details.miscSize);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user