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.os.Parcel; 20 import android.os.Parcelable; 21 import android.os.UserHandle; 22 23 /** 24 * implementation of PackageStats associated with a 25 * application package. 26 */ 27 public class PackageStats implements Parcelable { 28 /** Name of the package to which this stats applies. */ 29 public String packageName; 30 31 /** @hide */ 32 public int userHandle; 33 34 /** Size of the code (e.g., APK) */ 35 public long codeSize; 36 37 /** 38 * Size of the internal data size for the application. (e.g., 39 * /data/data/<app>) 40 */ 41 public long dataSize; 42 43 /** Size of cache used by the application. (e.g., /data/data/<app>/cache) */ 44 public long cacheSize; 45 46 /** 47 * Size of the secure container on external storage holding the 48 * application's code. 49 */ 50 public long externalCodeSize; 51 52 /** 53 * Size of the external data used by the application (e.g., 54 * <sdcard>/Android/data/<app>) 55 */ 56 public long externalDataSize; 57 58 /** 59 * Size of the external cache used by the application (i.e., on the SD 60 * card). If this is a subdirectory of the data directory, this size will be 61 * subtracted out of the external data size. 62 */ 63 public long externalCacheSize; 64 65 /** Size of the external media size used by the application. */ 66 public long externalMediaSize; 67 68 /** Size of the package's OBBs placed on external media. */ 69 public long externalObbSize; 70 71 public static final Parcelable.Creator<PackageStats> CREATOR 72 = new Parcelable.Creator<PackageStats>() { 73 public PackageStats createFromParcel(Parcel in) { 74 return new PackageStats(in); 75 } 76 77 public PackageStats[] newArray(int size) { 78 return new PackageStats[size]; 79 } 80 }; 81 toString()82 public String toString() { 83 final StringBuilder sb = new StringBuilder("PackageStats{"); 84 sb.append(Integer.toHexString(System.identityHashCode(this))); 85 sb.append(" "); 86 sb.append(packageName); 87 if (codeSize != 0) { 88 sb.append(" code="); 89 sb.append(codeSize); 90 } 91 if (dataSize != 0) { 92 sb.append(" data="); 93 sb.append(dataSize); 94 } 95 if (cacheSize != 0) { 96 sb.append(" cache="); 97 sb.append(cacheSize); 98 } 99 if (externalCodeSize != 0) { 100 sb.append(" extCode="); 101 sb.append(externalCodeSize); 102 } 103 if (externalDataSize != 0) { 104 sb.append(" extData="); 105 sb.append(externalDataSize); 106 } 107 if (externalCacheSize != 0) { 108 sb.append(" extCache="); 109 sb.append(externalCacheSize); 110 } 111 if (externalMediaSize != 0) { 112 sb.append(" media="); 113 sb.append(externalMediaSize); 114 } 115 if (externalObbSize != 0) { 116 sb.append(" obb="); 117 sb.append(externalObbSize); 118 } 119 sb.append("}"); 120 return sb.toString(); 121 } 122 PackageStats(String pkgName)123 public PackageStats(String pkgName) { 124 packageName = pkgName; 125 userHandle = UserHandle.myUserId(); 126 } 127 128 /** @hide */ PackageStats(String pkgName, int userHandle)129 public PackageStats(String pkgName, int userHandle) { 130 this.packageName = pkgName; 131 this.userHandle = userHandle; 132 } 133 PackageStats(Parcel source)134 public PackageStats(Parcel source) { 135 packageName = source.readString(); 136 userHandle = source.readInt(); 137 codeSize = source.readLong(); 138 dataSize = source.readLong(); 139 cacheSize = source.readLong(); 140 externalCodeSize = source.readLong(); 141 externalDataSize = source.readLong(); 142 externalCacheSize = source.readLong(); 143 externalMediaSize = source.readLong(); 144 externalObbSize = source.readLong(); 145 } 146 PackageStats(PackageStats pStats)147 public PackageStats(PackageStats pStats) { 148 packageName = pStats.packageName; 149 userHandle = pStats.userHandle; 150 codeSize = pStats.codeSize; 151 dataSize = pStats.dataSize; 152 cacheSize = pStats.cacheSize; 153 externalCodeSize = pStats.externalCodeSize; 154 externalDataSize = pStats.externalDataSize; 155 externalCacheSize = pStats.externalCacheSize; 156 externalMediaSize = pStats.externalMediaSize; 157 externalObbSize = pStats.externalObbSize; 158 } 159 describeContents()160 public int describeContents() { 161 return 0; 162 } 163 writeToParcel(Parcel dest, int parcelableFlags)164 public void writeToParcel(Parcel dest, int parcelableFlags){ 165 dest.writeString(packageName); 166 dest.writeInt(userHandle); 167 dest.writeLong(codeSize); 168 dest.writeLong(dataSize); 169 dest.writeLong(cacheSize); 170 dest.writeLong(externalCodeSize); 171 dest.writeLong(externalDataSize); 172 dest.writeLong(externalCacheSize); 173 dest.writeLong(externalMediaSize); 174 dest.writeLong(externalObbSize); 175 } 176 } 177