1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.app.usage; 18 19 import android.annotation.BytesLong; 20 import android.content.Context; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 import android.os.UserHandle; 24 25 /** 26 * Storage statistics for a UID, package, or {@link UserHandle} on a single 27 * storage volume. 28 * 29 * @see StorageStatsManager 30 */ 31 public final class StorageStats implements Parcelable { 32 /** {@hide} */ public long codeBytes; 33 /** {@hide} */ public long dataBytes; 34 /** {@hide} */ public long cacheBytes; 35 36 /** 37 * Return the size of app. This includes {@code APK} files, optimized 38 * compiler output, and unpacked native libraries. 39 * <p> 40 * If the primary external/shared storage is hosted on this storage device, 41 * then this includes files stored under {@link Context#getObbDir()}. 42 * <p> 43 * Code is shared between all users on a multiuser device. 44 */ getAppBytes()45 public @BytesLong long getAppBytes() { 46 return codeBytes; 47 } 48 49 /** @removed */ 50 @Deprecated getCodeBytes()51 public long getCodeBytes() { 52 return getAppBytes(); 53 } 54 55 /** 56 * Return the size of all data. This includes files stored under 57 * {@link Context#getDataDir()}, {@link Context#getCacheDir()}, 58 * {@link Context#getCodeCacheDir()}. 59 * <p> 60 * If the primary external/shared storage is hosted on this storage device, 61 * then this includes files stored under 62 * {@link Context#getExternalFilesDir(String)}, 63 * {@link Context#getExternalCacheDir()}, and 64 * {@link Context#getExternalMediaDirs()}. 65 * <p> 66 * Data is isolated for each user on a multiuser device. 67 */ getDataBytes()68 public @BytesLong long getDataBytes() { 69 return dataBytes; 70 } 71 72 /** 73 * Return the size of all cached data. This includes files stored under 74 * {@link Context#getCacheDir()} and {@link Context#getCodeCacheDir()}. 75 * <p> 76 * If the primary external/shared storage is hosted on this storage device, 77 * then this includes files stored under 78 * {@link Context#getExternalCacheDir()}. 79 * <p> 80 * Cached data is isolated for each user on a multiuser device. 81 */ getCacheBytes()82 public @BytesLong long getCacheBytes() { 83 return cacheBytes; 84 } 85 86 /** {@hide} */ StorageStats()87 public StorageStats() { 88 } 89 90 /** {@hide} */ StorageStats(Parcel in)91 public StorageStats(Parcel in) { 92 this.codeBytes = in.readLong(); 93 this.dataBytes = in.readLong(); 94 this.cacheBytes = in.readLong(); 95 } 96 97 @Override describeContents()98 public int describeContents() { 99 return 0; 100 } 101 102 @Override writeToParcel(Parcel dest, int flags)103 public void writeToParcel(Parcel dest, int flags) { 104 dest.writeLong(codeBytes); 105 dest.writeLong(dataBytes); 106 dest.writeLong(cacheBytes); 107 } 108 109 public static final Creator<StorageStats> CREATOR = new Creator<StorageStats>() { 110 @Override 111 public StorageStats createFromParcel(Parcel in) { 112 return new StorageStats(in); 113 } 114 115 @Override 116 public StorageStats[] newArray(int size) { 117 return new StorageStats[size]; 118 } 119 }; 120 } 121