blob: d3e86a35170e9e0b7dd98f7b718b89d00fe9c969 [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
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 Project9066cfe2009-03-03 19:31:44 -080017package android.content.pm;
18
Mathew Inwood5c0d3542018-08-14 13:54:31 +010019import android.annotation.UnsupportedAppUsage;
Jeff Sharkey60f95aa2017-03-08 13:57:15 -070020import android.app.usage.StorageStatsManager;
Mathew Inwood31755f92018-12-20 13:53:36 +000021import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.os.Parcel;
23import android.os.Parcelable;
Dianne Hackborn0c380492012-08-20 17:23:30 -070024import android.os.UserHandle;
Daniel Nishid7b03292017-02-27 17:16:01 -080025import android.text.TextUtils;
26
27import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029/**
Jeff Sharkey60f95aa2017-03-08 13:57:15 -070030 * 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 Project9066cfe2009-03-03 19:31:44 -080035 */
Jeff Sharkey60f95aa2017-03-08 13:57:15 -070036@Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037public class PackageStats implements Parcelable {
Kenny Root366949c2011-01-14 17:18:14 -080038 /** Name of the package to which this stats applies. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039 public String packageName;
Kenny Root366949c2011-01-14 17:18:14 -080040
Dianne Hackborn0c380492012-08-20 17:23:30 -070041 /** @hide */
Mathew Inwood31755f92018-12-20 13:53:36 +000042 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Dianne Hackborn0c380492012-08-20 17:23:30 -070043 public int userHandle;
44
Kenny Root366949c2011-01-14 17:18:14 -080045 /** Size of the code (e.g., APK) */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046 public long codeSize;
Kenny Root366949c2011-01-14 17:18:14 -080047
48 /**
49 * Size of the internal data size for the application. (e.g.,
50 * /data/data/<app>)
51 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 public long dataSize;
Kenny Root366949c2011-01-14 17:18:14 -080053
54 /** Size of cache used by the application. (e.g., /data/data/<app>/cache) */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 public long cacheSize;
Kenny Root366949c2011-01-14 17:18:14 -080056
57 /**
Dianne Hackborn292f8bc2011-06-27 16:27:41 -070058 * Size of the secure container on external storage holding the
59 * application's code.
60 */
61 public long externalCodeSize;
62
63 /**
Kenny Root366949c2011-01-14 17:18:14 -080064 * 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 Rootbcd6c962011-01-17 11:21:49 -080079 /** Size of the package's OBBs placed on external media. */
80 public long externalObbSize;
81
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 public static final Parcelable.Creator<PackageStats> CREATOR
Kenny Root366949c2011-01-14 17:18:14 -080083 = new Parcelable.Creator<PackageStats>() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 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 Root366949c2011-01-14 17:18:14 -080092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 public String toString() {
Kenny Root366949c2011-01-14 17:18:14 -080094 final StringBuilder sb = new StringBuilder("PackageStats{");
95 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackborn0c380492012-08-20 17:23:30 -070096 sb.append(" ");
Kenny Root366949c2011-01-14 17:18:14 -080097 sb.append(packageName);
Dianne Hackborn0c380492012-08-20 17:23:30 -070098 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 Root366949c2011-01-14 17:18:14 -0800131 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 }
Kenny Root366949c2011-01-14 17:18:14 -0800133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 public PackageStats(String pkgName) {
135 packageName = pkgName;
Dianne Hackborn0c380492012-08-20 17:23:30 -0700136 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 Project9066cfe2009-03-03 19:31:44 -0800143 }
Kenny Root366949c2011-01-14 17:18:14 -0800144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 public PackageStats(Parcel source) {
146 packageName = source.readString();
Dianne Hackborn0c380492012-08-20 17:23:30 -0700147 userHandle = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 codeSize = source.readLong();
149 dataSize = source.readLong();
150 cacheSize = source.readLong();
Dianne Hackborn292f8bc2011-06-27 16:27:41 -0700151 externalCodeSize = source.readLong();
Kenny Root366949c2011-01-14 17:18:14 -0800152 externalDataSize = source.readLong();
153 externalCacheSize = source.readLong();
154 externalMediaSize = source.readLong();
Kenny Rootbcd6c962011-01-17 11:21:49 -0800155 externalObbSize = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 }
Kenny Root366949c2011-01-14 17:18:14 -0800157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 public PackageStats(PackageStats pStats) {
159 packageName = pStats.packageName;
Dianne Hackborn0c380492012-08-20 17:23:30 -0700160 userHandle = pStats.userHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 codeSize = pStats.codeSize;
162 dataSize = pStats.dataSize;
163 cacheSize = pStats.cacheSize;
Dianne Hackborn292f8bc2011-06-27 16:27:41 -0700164 externalCodeSize = pStats.externalCodeSize;
Kenny Root366949c2011-01-14 17:18:14 -0800165 externalDataSize = pStats.externalDataSize;
166 externalCacheSize = pStats.externalCacheSize;
167 externalMediaSize = pStats.externalMediaSize;
Kenny Rootbcd6c962011-01-17 11:21:49 -0800168 externalObbSize = pStats.externalObbSize;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 }
170
171 public int describeContents() {
172 return 0;
173 }
174
175 public void writeToParcel(Parcel dest, int parcelableFlags){
176 dest.writeString(packageName);
Dianne Hackborn0c380492012-08-20 17:23:30 -0700177 dest.writeInt(userHandle);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 dest.writeLong(codeSize);
179 dest.writeLong(dataSize);
180 dest.writeLong(cacheSize);
Dianne Hackborn292f8bc2011-06-27 16:27:41 -0700181 dest.writeLong(externalCodeSize);
Kenny Root366949c2011-01-14 17:18:14 -0800182 dest.writeLong(externalDataSize);
183 dest.writeLong(externalCacheSize);
184 dest.writeLong(externalMediaSize);
Kenny Rootbcd6c962011-01-17 11:21:49 -0800185 dest.writeLong(externalObbSize);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 }
Daniel Nishid7b03292017-02-27 17:16:01 -0800187
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 Project9066cfe2009-03-03 19:31:44 -0800214}