Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | package android.content.pm; |
| 18 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 19 | import android.annotation.UnsupportedAppUsage; |
Jeff Sharkey | 60f95aa | 2017-03-08 13:57:15 -0700 | [diff] [blame] | 20 | import android.app.usage.StorageStatsManager; |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 21 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 24 | import android.os.UserHandle; |
Daniel Nishi | d7b0329 | 2017-02-27 17:16:01 -0800 | [diff] [blame] | 25 | import android.text.TextUtils; |
| 26 | |
| 27 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | /** |
Jeff Sharkey | 60f95aa | 2017-03-08 13:57:15 -0700 | [diff] [blame] | 30 | * implementation of PackageStats associated with a application package. |
| 31 | * |
| 32 | * @deprecated this class is an orphan that could never be obtained from a valid |
| 33 | * public API. If you need package storage statistics use the new |
| 34 | * {@link StorageStatsManager} APIs. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | */ |
Jeff Sharkey | 60f95aa | 2017-03-08 13:57:15 -0700 | [diff] [blame] | 36 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | public class PackageStats implements Parcelable { |
Kenny Root | 366949c | 2011-01-14 17:18:14 -0800 | [diff] [blame] | 38 | /** Name of the package to which this stats applies. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | public String packageName; |
Kenny Root | 366949c | 2011-01-14 17:18:14 -0800 | [diff] [blame] | 40 | |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 41 | /** @hide */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 42 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 43 | public int userHandle; |
| 44 | |
Kenny Root | 366949c | 2011-01-14 17:18:14 -0800 | [diff] [blame] | 45 | /** Size of the code (e.g., APK) */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | public long codeSize; |
Kenny Root | 366949c | 2011-01-14 17:18:14 -0800 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * Size of the internal data size for the application. (e.g., |
| 50 | * /data/data/<app>) |
| 51 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | public long dataSize; |
Kenny Root | 366949c | 2011-01-14 17:18:14 -0800 | [diff] [blame] | 53 | |
| 54 | /** Size of cache used by the application. (e.g., /data/data/<app>/cache) */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | public long cacheSize; |
Kenny Root | 366949c | 2011-01-14 17:18:14 -0800 | [diff] [blame] | 56 | |
| 57 | /** |
Dianne Hackborn | 292f8bc | 2011-06-27 16:27:41 -0700 | [diff] [blame] | 58 | * Size of the secure container on external storage holding the |
| 59 | * application's code. |
| 60 | */ |
| 61 | public long externalCodeSize; |
| 62 | |
| 63 | /** |
Kenny Root | 366949c | 2011-01-14 17:18:14 -0800 | [diff] [blame] | 64 | * Size of the external data used by the application (e.g., |
| 65 | * <sdcard>/Android/data/<app>) |
| 66 | */ |
| 67 | public long externalDataSize; |
| 68 | |
| 69 | /** |
| 70 | * Size of the external cache used by the application (i.e., on the SD |
| 71 | * card). If this is a subdirectory of the data directory, this size will be |
| 72 | * subtracted out of the external data size. |
| 73 | */ |
| 74 | public long externalCacheSize; |
| 75 | |
| 76 | /** Size of the external media size used by the application. */ |
| 77 | public long externalMediaSize; |
| 78 | |
Kenny Root | bcd6c96 | 2011-01-17 11:21:49 -0800 | [diff] [blame] | 79 | /** Size of the package's OBBs placed on external media. */ |
| 80 | public long externalObbSize; |
| 81 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | public static final Parcelable.Creator<PackageStats> CREATOR |
Kenny Root | 366949c | 2011-01-14 17:18:14 -0800 | [diff] [blame] | 83 | = new Parcelable.Creator<PackageStats>() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | public PackageStats createFromParcel(Parcel in) { |
| 85 | return new PackageStats(in); |
| 86 | } |
| 87 | |
| 88 | public PackageStats[] newArray(int size) { |
| 89 | return new PackageStats[size]; |
| 90 | } |
| 91 | }; |
Kenny Root | 366949c | 2011-01-14 17:18:14 -0800 | [diff] [blame] | 92 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | public String toString() { |
Kenny Root | 366949c | 2011-01-14 17:18:14 -0800 | [diff] [blame] | 94 | final StringBuilder sb = new StringBuilder("PackageStats{"); |
| 95 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 96 | sb.append(" "); |
Kenny Root | 366949c | 2011-01-14 17:18:14 -0800 | [diff] [blame] | 97 | sb.append(packageName); |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 98 | if (codeSize != 0) { |
| 99 | sb.append(" code="); |
| 100 | sb.append(codeSize); |
| 101 | } |
| 102 | if (dataSize != 0) { |
| 103 | sb.append(" data="); |
| 104 | sb.append(dataSize); |
| 105 | } |
| 106 | if (cacheSize != 0) { |
| 107 | sb.append(" cache="); |
| 108 | sb.append(cacheSize); |
| 109 | } |
| 110 | if (externalCodeSize != 0) { |
| 111 | sb.append(" extCode="); |
| 112 | sb.append(externalCodeSize); |
| 113 | } |
| 114 | if (externalDataSize != 0) { |
| 115 | sb.append(" extData="); |
| 116 | sb.append(externalDataSize); |
| 117 | } |
| 118 | if (externalCacheSize != 0) { |
| 119 | sb.append(" extCache="); |
| 120 | sb.append(externalCacheSize); |
| 121 | } |
| 122 | if (externalMediaSize != 0) { |
| 123 | sb.append(" media="); |
| 124 | sb.append(externalMediaSize); |
| 125 | } |
| 126 | if (externalObbSize != 0) { |
| 127 | sb.append(" obb="); |
| 128 | sb.append(externalObbSize); |
| 129 | } |
| 130 | sb.append("}"); |
Kenny Root | 366949c | 2011-01-14 17:18:14 -0800 | [diff] [blame] | 131 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | } |
Kenny Root | 366949c | 2011-01-14 17:18:14 -0800 | [diff] [blame] | 133 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | public PackageStats(String pkgName) { |
| 135 | packageName = pkgName; |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 136 | userHandle = UserHandle.myUserId(); |
| 137 | } |
| 138 | |
| 139 | /** @hide */ |
| 140 | public PackageStats(String pkgName, int userHandle) { |
| 141 | this.packageName = pkgName; |
| 142 | this.userHandle = userHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | } |
Kenny Root | 366949c | 2011-01-14 17:18:14 -0800 | [diff] [blame] | 144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | public PackageStats(Parcel source) { |
| 146 | packageName = source.readString(); |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 147 | userHandle = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | codeSize = source.readLong(); |
| 149 | dataSize = source.readLong(); |
| 150 | cacheSize = source.readLong(); |
Dianne Hackborn | 292f8bc | 2011-06-27 16:27:41 -0700 | [diff] [blame] | 151 | externalCodeSize = source.readLong(); |
Kenny Root | 366949c | 2011-01-14 17:18:14 -0800 | [diff] [blame] | 152 | externalDataSize = source.readLong(); |
| 153 | externalCacheSize = source.readLong(); |
| 154 | externalMediaSize = source.readLong(); |
Kenny Root | bcd6c96 | 2011-01-17 11:21:49 -0800 | [diff] [blame] | 155 | externalObbSize = source.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | } |
Kenny Root | 366949c | 2011-01-14 17:18:14 -0800 | [diff] [blame] | 157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | public PackageStats(PackageStats pStats) { |
| 159 | packageName = pStats.packageName; |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 160 | userHandle = pStats.userHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | codeSize = pStats.codeSize; |
| 162 | dataSize = pStats.dataSize; |
| 163 | cacheSize = pStats.cacheSize; |
Dianne Hackborn | 292f8bc | 2011-06-27 16:27:41 -0700 | [diff] [blame] | 164 | externalCodeSize = pStats.externalCodeSize; |
Kenny Root | 366949c | 2011-01-14 17:18:14 -0800 | [diff] [blame] | 165 | externalDataSize = pStats.externalDataSize; |
| 166 | externalCacheSize = pStats.externalCacheSize; |
| 167 | externalMediaSize = pStats.externalMediaSize; |
Kenny Root | bcd6c96 | 2011-01-17 11:21:49 -0800 | [diff] [blame] | 168 | externalObbSize = pStats.externalObbSize; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | public int describeContents() { |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | public void writeToParcel(Parcel dest, int parcelableFlags){ |
| 176 | dest.writeString(packageName); |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 177 | dest.writeInt(userHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | dest.writeLong(codeSize); |
| 179 | dest.writeLong(dataSize); |
| 180 | dest.writeLong(cacheSize); |
Dianne Hackborn | 292f8bc | 2011-06-27 16:27:41 -0700 | [diff] [blame] | 181 | dest.writeLong(externalCodeSize); |
Kenny Root | 366949c | 2011-01-14 17:18:14 -0800 | [diff] [blame] | 182 | dest.writeLong(externalDataSize); |
| 183 | dest.writeLong(externalCacheSize); |
| 184 | dest.writeLong(externalMediaSize); |
Kenny Root | bcd6c96 | 2011-01-17 11:21:49 -0800 | [diff] [blame] | 185 | dest.writeLong(externalObbSize); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | } |
Daniel Nishi | d7b0329 | 2017-02-27 17:16:01 -0800 | [diff] [blame] | 187 | |
| 188 | @Override |
| 189 | public boolean equals(Object obj) { |
| 190 | if (!(obj instanceof PackageStats)) { |
| 191 | return false; |
| 192 | } |
| 193 | |
| 194 | final PackageStats otherStats = (PackageStats) obj; |
| 195 | return ((TextUtils.equals(packageName, otherStats.packageName)) |
| 196 | && userHandle == otherStats.userHandle |
| 197 | && codeSize == otherStats.codeSize |
| 198 | && dataSize == otherStats.dataSize |
| 199 | && cacheSize == otherStats.cacheSize |
| 200 | && externalCodeSize == otherStats.externalCodeSize |
| 201 | && externalDataSize == otherStats.externalDataSize |
| 202 | && externalCacheSize == otherStats.externalCacheSize |
| 203 | && externalMediaSize == otherStats.externalMediaSize |
| 204 | && externalObbSize == otherStats.externalObbSize); |
| 205 | } |
| 206 | |
| 207 | @Override |
| 208 | public int hashCode() { |
| 209 | return Objects.hash(packageName, userHandle, codeSize, dataSize, |
| 210 | cacheSize, externalCodeSize, externalDataSize, externalCacheSize, externalMediaSize, |
| 211 | externalObbSize); |
| 212 | } |
| 213 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | } |