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

Commit 00347888 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Fix code accounting bugs, track external app data.

When counting code size, don't include APKs baked into the system.

Settings already accounts external storage used by apps, so they
need a way to exclude that from the total space used by external
storage; give them new getAppSize() API.

Refine docs to explain that emulated storage might be included in
measured statistics.

Resolve symlinks as part of matching getUuidForPath().

Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.StorageHostTest
Bug: 35812899, 35844919, 37193650
Change-Id: Iec3ce8b336b71dc98a7d25fdd30fa78e9ee826dc
parent 2b499e4e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6924,6 +6924,7 @@ package android.app.usage {
  public final class ExternalStorageStats implements android.os.Parcelable {
    method public int describeContents();
    method public long getAppBytes();
    method public long getAudioBytes();
    method public long getImageBytes();
    method public long getTotalBytes();
+1 −0
Original line number Diff line number Diff line
@@ -7389,6 +7389,7 @@ package android.app.usage {
  public final class ExternalStorageStats implements android.os.Parcelable {
    method public int describeContents();
    method public long getAppBytes();
    method public long getAudioBytes();
    method public long getImageBytes();
    method public long getTotalBytes();
+1 −0
Original line number Diff line number Diff line
@@ -6954,6 +6954,7 @@ package android.app.usage {
  public final class ExternalStorageStats implements android.os.Parcelable {
    method public int describeContents();
    method public long getAppBytes();
    method public long getAudioBytes();
    method public long getImageBytes();
    method public long getTotalBytes();
+14 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ public final class ExternalStorageStats implements Parcelable {
    /** {@hide} */ public long audioBytes;
    /** {@hide} */ public long videoBytes;
    /** {@hide} */ public long imageBytes;
    /** {@hide} */ public long appBytes;

    /**
     * Return the total bytes used by all files in the shared/external storage
@@ -64,6 +65,17 @@ public final class ExternalStorageStats implements Parcelable {
        return imageBytes;
    }

    /**
     * Return the total bytes used by app files in the shared/external storage
     * hosted on this volume.
     * <p>
     * This data is already accounted against individual apps as returned
     * through {@link StorageStats}.
     */
    public long getAppBytes() {
        return appBytes;
    }

    /** {@hide} */
    public ExternalStorageStats() {
    }
@@ -74,6 +86,7 @@ public final class ExternalStorageStats implements Parcelable {
        this.audioBytes = in.readLong();
        this.videoBytes = in.readLong();
        this.imageBytes = in.readLong();
        this.appBytes = in.readLong();
    }

    @Override
@@ -87,6 +100,7 @@ public final class ExternalStorageStats implements Parcelable {
        dest.writeLong(audioBytes);
        dest.writeLong(videoBytes);
        dest.writeLong(imageBytes);
        dest.writeLong(appBytes);
    }

    public static final Creator<ExternalStorageStats> CREATOR = new Creator<ExternalStorageStats>() {
+15 −6
Original line number Diff line number Diff line
@@ -22,12 +22,8 @@ import android.os.Parcelable;
import android.os.UserHandle;

/**
 * Storage statistics for a UID or {@link UserHandle} on a single storage
 * volume.
 * <p class="note">
 * Note: multiple packages using the same {@code sharedUserId} in their manifest
 * will be merged into a single UID.
 * </p>
 * Storage statistics for a UID, package, or {@link UserHandle} on a single
 * storage volume.
 *
 * @see StorageStatsManager
 */
@@ -40,6 +36,9 @@ public final class StorageStats implements Parcelable {
     * Return the size of all code. This includes {@code APK} files and
     * optimized compiler output.
     * <p>
     * If the primary external/shared storage is hosted on this storage device,
     * then this includes files stored under {@link Context#getObbDir()}.
     * <p>
     * Code is shared between all users on a multiuser device.
     */
    public long getCodeBytes() {
@@ -51,6 +50,12 @@ public final class StorageStats implements Parcelable {
     * {@link Context#getDataDir()}, {@link Context#getCacheDir()},
     * {@link Context#getCodeCacheDir()}.
     * <p>
     * If the primary external/shared storage is hosted on this storage device,
     * then this includes files stored under
     * {@link Context#getExternalFilesDir(String)},
     * {@link Context#getExternalCacheDir()}, and
     * {@link Context#getExternalMediaDirs()}.
     * <p>
     * Data is isolated for each user on a multiuser device.
     */
    public long getDataBytes() {
@@ -61,6 +66,10 @@ public final class StorageStats implements Parcelable {
     * Return the size of all cached data. This includes files stored under
     * {@link Context#getCacheDir()} and {@link Context#getCodeCacheDir()}.
     * <p>
     * If the primary external/shared storage is hosted on this storage device,
     * then this includes files stored under
     * {@link Context#getExternalCacheDir()}.
     * <p>
     * Cached data is isolated for each user on a multiuser device.
     */
    public long getCacheBytes() {
Loading