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

Commit d2486196 authored by Saumya Pathak's avatar Saumya Pathak
Browse files

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
parent 0d765236
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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;
  }
+14 −0
Original line number Diff line number Diff line
@@ -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>() {
+1 −0
Original line number Diff line number Diff line
@@ -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;
    }