Adding StorageStats API to get external cache size

Test: atest StorageHostTest and also manually using StorageTestApp
to use the API and display the cache size.

Bug: 175016452
Change-Id: Iff0503c1643ee5fc501037e413aa4b5461ca3388
This commit is contained in:
Saumya Pathak
2021-01-08 16:00:59 +00:00
parent 0d76523686
commit d2486196e6
3 changed files with 16 additions and 0 deletions

View File

@@ -8163,6 +8163,7 @@ package android.app.usage {
method public long getAppBytes();
method public long getCacheBytes();
method public long getDataBytes();
method public long getExternalCacheBytes();
method public void writeToParcel(android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.app.usage.StorageStats> CREATOR;
}

View File

@@ -32,6 +32,7 @@ public final class StorageStats implements Parcelable {
/** {@hide} */ public long codeBytes;
/** {@hide} */ public long dataBytes;
/** {@hide} */ public long cacheBytes;
/** {@hide} */ public long externalCacheBytes;
/**
* Return the size of app. This includes {@code APK} files, optimized
@@ -77,6 +78,17 @@ public final class StorageStats implements Parcelable {
return cacheBytes;
}
/**
* Return the size of all cached data in the primary external/shared storage.
* This includes files stored under
* {@link Context#getExternalCacheDir()}.
* <p>
* Cached data is isolated for each user on a multiuser device.
*/
public @BytesLong long getExternalCacheBytes() {
return externalCacheBytes;
}
/** {@hide} */
public StorageStats() {
}
@@ -86,6 +98,7 @@ public final class StorageStats implements Parcelable {
this.codeBytes = in.readLong();
this.dataBytes = in.readLong();
this.cacheBytes = in.readLong();
this.externalCacheBytes = in.readLong();
}
@Override
@@ -98,6 +111,7 @@ public final class StorageStats implements Parcelable {
dest.writeLong(codeBytes);
dest.writeLong(dataBytes);
dest.writeLong(cacheBytes);
dest.writeLong(externalCacheBytes);
}
public static final @android.annotation.NonNull Creator<StorageStats> CREATOR = new Creator<StorageStats>() {

View File

@@ -514,6 +514,7 @@ public class StorageStatsService extends IStorageStatsManager.Stub {
res.codeBytes = stats.codeSize + stats.externalCodeSize;
res.dataBytes = stats.dataSize + stats.externalDataSize;
res.cacheBytes = stats.cacheSize + stats.externalCacheSize;
res.externalCacheBytes = stats.externalCacheSize;
return res;
}