1 /* 2 * Copyright (C) 2008 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.content.pm; 18 19 import android.annotation.Nullable; 20 import android.app.usage.StorageStatsManager; 21 import android.compat.annotation.UnsupportedAppUsage; 22 import android.os.Build; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 import android.os.UserHandle; 26 import android.text.TextUtils; 27 28 import java.util.Objects; 29 30 /** 31 * implementation of PackageStats associated with a application package. 32 * 33 * @deprecated this class is an orphan that could never be obtained from a valid 34 * public API. If you need package storage statistics use the new 35 * {@link StorageStatsManager} APIs. 36 */ 37 @Deprecated 38 public class PackageStats implements Parcelable { 39 /** Name of the package to which this stats applies. */ 40 public String packageName; 41 42 /** @hide */ 43 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) 44 public int userHandle; 45 46 /** Size of the code (e.g., APK) */ 47 public long codeSize; 48 49 /** 50 * Size of the internal data size for the application. (e.g., 51 * /data/data/<app>) 52 */ 53 public long dataSize; 54 55 /** Size of cache used by the application. (e.g., /data/data/<app>/cache) */ 56 public long cacheSize; 57 58 /** Size of .apk files of the application. */ 59 /** @hide */ 60 public long apkSize; 61 62 /** Size of the libraries of the application. */ 63 /** @hide */ 64 public long libSize; 65 66 /** Size of the .dm files of the application. */ 67 /** @hide */ 68 public long dmSize; 69 70 /** Size of dexopt artifacts of the application. */ 71 /** @hide */ 72 public long dexoptSize; 73 74 /** Size of the current profile of the application. */ 75 /** @hide */ 76 public long curProfSize; 77 78 /** Size of the reference profile of the application. */ 79 /** @hide */ 80 public long refProfSize; 81 82 /** 83 * Size of the secure container on external storage holding the 84 * application's code. 85 */ 86 public long externalCodeSize; 87 88 /** 89 * Size of the external data used by the application (e.g., 90 * <sdcard>/Android/data/<app>) 91 */ 92 public long externalDataSize; 93 94 /** 95 * Size of the external cache used by the application (i.e., on the SD 96 * card). If this is a subdirectory of the data directory, this size will be 97 * subtracted out of the external data size. 98 */ 99 public long externalCacheSize; 100 101 /** Size of the external media size used by the application. */ 102 public long externalMediaSize; 103 104 /** Size of the package's OBBs placed on external media. */ 105 public long externalObbSize; 106 107 public static final @android.annotation.NonNull Parcelable.Creator<PackageStats> CREATOR 108 = new Parcelable.Creator<PackageStats>() { 109 public PackageStats createFromParcel(Parcel in) { 110 return new PackageStats(in); 111 } 112 113 public PackageStats[] newArray(int size) { 114 return new PackageStats[size]; 115 } 116 }; 117 toString()118 public String toString() { 119 final StringBuilder sb = new StringBuilder("PackageStats{"); 120 sb.append(Integer.toHexString(System.identityHashCode(this))); 121 sb.append(" "); 122 sb.append(packageName); 123 if (codeSize != 0) { 124 sb.append(" code="); 125 sb.append(codeSize); 126 } 127 if (dataSize != 0) { 128 sb.append(" data="); 129 sb.append(dataSize); 130 } 131 if (cacheSize != 0) { 132 sb.append(" cache="); 133 sb.append(cacheSize); 134 } 135 if (apkSize != 0) { 136 sb.append(" apk="); 137 sb.append(apkSize); 138 } 139 if (libSize != 0) { 140 sb.append(" lib="); 141 sb.append(libSize); 142 } 143 if (dmSize != 0) { 144 sb.append(" dm="); 145 sb.append(dmSize); 146 } 147 if (dexoptSize != 0) { 148 sb.append(" dexopt="); 149 sb.append(dexoptSize); 150 } 151 if (curProfSize != 0) { 152 sb.append(" curProf="); 153 sb.append(curProfSize); 154 } 155 if (refProfSize != 0) { 156 sb.append(" refProf="); 157 sb.append(refProfSize); 158 } 159 if (externalCodeSize != 0) { 160 sb.append(" extCode="); 161 sb.append(externalCodeSize); 162 } 163 if (externalDataSize != 0) { 164 sb.append(" extData="); 165 sb.append(externalDataSize); 166 } 167 if (externalCacheSize != 0) { 168 sb.append(" extCache="); 169 sb.append(externalCacheSize); 170 } 171 if (externalMediaSize != 0) { 172 sb.append(" media="); 173 sb.append(externalMediaSize); 174 } 175 if (externalObbSize != 0) { 176 sb.append(" obb="); 177 sb.append(externalObbSize); 178 } 179 sb.append("}"); 180 return sb.toString(); 181 } 182 PackageStats(String pkgName)183 public PackageStats(String pkgName) { 184 packageName = pkgName; 185 userHandle = UserHandle.myUserId(); 186 } 187 188 /** @hide */ PackageStats(String pkgName, int userHandle)189 public PackageStats(String pkgName, int userHandle) { 190 this.packageName = pkgName; 191 this.userHandle = userHandle; 192 } 193 PackageStats(Parcel source)194 public PackageStats(Parcel source) { 195 packageName = source.readString(); 196 userHandle = source.readInt(); 197 codeSize = source.readLong(); 198 dataSize = source.readLong(); 199 cacheSize = source.readLong(); 200 apkSize = source.readLong(); 201 libSize = source.readLong(); 202 dmSize = source.readLong(); 203 dexoptSize = source.readLong(); 204 curProfSize = source.readLong(); 205 refProfSize = source.readLong(); 206 externalCodeSize = source.readLong(); 207 externalDataSize = source.readLong(); 208 externalCacheSize = source.readLong(); 209 externalMediaSize = source.readLong(); 210 externalObbSize = source.readLong(); 211 } 212 PackageStats(PackageStats pStats)213 public PackageStats(PackageStats pStats) { 214 packageName = pStats.packageName; 215 userHandle = pStats.userHandle; 216 codeSize = pStats.codeSize; 217 dataSize = pStats.dataSize; 218 cacheSize = pStats.cacheSize; 219 apkSize = pStats.apkSize; 220 libSize = pStats.libSize; 221 dmSize = pStats.dmSize; 222 dexoptSize = pStats.dexoptSize; 223 curProfSize = pStats.curProfSize; 224 refProfSize = pStats.refProfSize; 225 externalCodeSize = pStats.externalCodeSize; 226 externalDataSize = pStats.externalDataSize; 227 externalCacheSize = pStats.externalCacheSize; 228 externalMediaSize = pStats.externalMediaSize; 229 externalObbSize = pStats.externalObbSize; 230 } 231 describeContents()232 public int describeContents() { 233 return 0; 234 } 235 writeToParcel(Parcel dest, int parcelableFlags)236 public void writeToParcel(Parcel dest, int parcelableFlags){ 237 dest.writeString(packageName); 238 dest.writeInt(userHandle); 239 dest.writeLong(codeSize); 240 dest.writeLong(dataSize); 241 dest.writeLong(cacheSize); 242 dest.writeLong(apkSize); 243 dest.writeLong(libSize); 244 dest.writeLong(dmSize); 245 dest.writeLong(dexoptSize); 246 dest.writeLong(curProfSize); 247 dest.writeLong(refProfSize); 248 dest.writeLong(externalCodeSize); 249 dest.writeLong(externalDataSize); 250 dest.writeLong(externalCacheSize); 251 dest.writeLong(externalMediaSize); 252 dest.writeLong(externalObbSize); 253 } 254 255 @Override equals(@ullable Object obj)256 public boolean equals(@Nullable Object obj) { 257 if (!(obj instanceof PackageStats)) { 258 return false; 259 } 260 261 final PackageStats otherStats = (PackageStats) obj; 262 return ((TextUtils.equals(packageName, otherStats.packageName)) 263 && userHandle == otherStats.userHandle 264 && codeSize == otherStats.codeSize 265 && dataSize == otherStats.dataSize 266 && cacheSize == otherStats.cacheSize 267 && apkSize == otherStats.apkSize 268 && libSize == otherStats.libSize 269 && dmSize == otherStats.dmSize 270 && dexoptSize == otherStats.dexoptSize 271 && curProfSize == otherStats.curProfSize 272 && refProfSize == otherStats.refProfSize 273 && externalCodeSize == otherStats.externalCodeSize 274 && externalDataSize == otherStats.externalDataSize 275 && externalCacheSize == otherStats.externalCacheSize 276 && externalMediaSize == otherStats.externalMediaSize 277 && externalObbSize == otherStats.externalObbSize); 278 } 279 280 @Override hashCode()281 public int hashCode() { 282 return Objects.hash(packageName, userHandle, codeSize, dataSize, 283 apkSize, libSize, dmSize, dexoptSize, curProfSize, 284 refProfSize, cacheSize, externalCodeSize, 285 externalDataSize, externalCacheSize, externalMediaSize, 286 externalObbSize); 287 } 288 289 } 290