Debian Codegraph @

core/java/android/content/pm/PackageStats.java

raw symbols SCIP
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 /**
59 * Size of the secure container on external storage holding the
60 * application's code.
61 */
62 public long externalCodeSize;
63
64 /**
65 * Size of the external data used by the application (e.g.,
66 * <sdcard>/Android/data/<app>)
67 */
68 public long externalDataSize;
69
70 /**
71 * Size of the external cache used by the application (i.e., on the SD
72 * card). If this is a subdirectory of the data directory, this size will be
73 * subtracted out of the external data size.
74 */
75 public long externalCacheSize;
76
77 /** Size of the external media size used by the application. */
78 public long externalMediaSize;
79
80 /** Size of the package's OBBs placed on external media. */
81 public long externalObbSize;
82
83 public static final @android.annotation.NonNull Parcelable.Creator<PackageStats> CREATOR
84 = new Parcelable.Creator<PackageStats>() {
85 public PackageStats createFromParcel(Parcel in) {
86 return new PackageStats(in);
87 }
88
89 public PackageStats[] newArray(int size) {
90 return new PackageStats[size];
91 }
92 };
93
94 public String toString() {
95 final StringBuilder sb = new StringBuilder("PackageStats{");
96 sb.append(Integer.toHexString(System.identityHashCode(this)));
97 sb.append(" ");
98 sb.append(packageName);
99 if (codeSize != 0) {
100 sb.append(" code=");
101 sb.append(codeSize);
102 }
103 if (dataSize != 0) {
104 sb.append(" data=");
105 sb.append(dataSize);
106 }
107 if (cacheSize != 0) {
108 sb.append(" cache=");
109 sb.append(cacheSize);
110 }
111 if (externalCodeSize != 0) {
112 sb.append(" extCode=");
113 sb.append(externalCodeSize);
114 }
115 if (externalDataSize != 0) {
116 sb.append(" extData=");
117 sb.append(externalDataSize);
118 }
119 if (externalCacheSize != 0) {
120 sb.append(" extCache=");
121 sb.append(externalCacheSize);
122 }
123 if (externalMediaSize != 0) {
124 sb.append(" media=");
125 sb.append(externalMediaSize);
126 }
127 if (externalObbSize != 0) {
128 sb.append(" obb=");
129 sb.append(externalObbSize);
130 }
131 sb.append("}");
132 return sb.toString();
133 }
134
135 public PackageStats(String pkgName) {
136 packageName = pkgName;
137 userHandle = UserHandle.myUserId();
138 }
139
140 /** @hide */
141 public PackageStats(String pkgName, int userHandle) {
142 this.packageName = pkgName;
143 this.userHandle = userHandle;
144 }
145
146 public PackageStats(Parcel source) {
147 packageName = source.readString();
148 userHandle = source.readInt();
149 codeSize = source.readLong();
150 dataSize = source.readLong();
151 cacheSize = source.readLong();
152 externalCodeSize = source.readLong();
153 externalDataSize = source.readLong();
154 externalCacheSize = source.readLong();
155 externalMediaSize = source.readLong();
156 externalObbSize = source.readLong();
157 }
158
159 public PackageStats(PackageStats pStats) {
160 packageName = pStats.packageName;
161 userHandle = pStats.userHandle;
162 codeSize = pStats.codeSize;
163 dataSize = pStats.dataSize;
164 cacheSize = pStats.cacheSize;
165 externalCodeSize = pStats.externalCodeSize;
166 externalDataSize = pStats.externalDataSize;
167 externalCacheSize = pStats.externalCacheSize;
168 externalMediaSize = pStats.externalMediaSize;
169 externalObbSize = pStats.externalObbSize;
170 }
171
172 public int describeContents() {
173 return 0;
174 }
175
176 public void writeToParcel(Parcel dest, int parcelableFlags){
177 dest.writeString(packageName);
178 dest.writeInt(userHandle);
179 dest.writeLong(codeSize);
180 dest.writeLong(dataSize);
181 dest.writeLong(cacheSize);
182 dest.writeLong(externalCodeSize);
183 dest.writeLong(externalDataSize);
184 dest.writeLong(externalCacheSize);
185 dest.writeLong(externalMediaSize);
186 dest.writeLong(externalObbSize);
187 }
188
189 @Override
190 public boolean equals(@Nullable Object obj) {
191 if (!(obj instanceof PackageStats)) {
192 return false;
193 }
194
195 final PackageStats otherStats = (PackageStats) obj;
196 return ((TextUtils.equals(packageName, otherStats.packageName))
197 && userHandle == otherStats.userHandle
198 && codeSize == otherStats.codeSize
199 && dataSize == otherStats.dataSize
200 && cacheSize == otherStats.cacheSize
201 && externalCodeSize == otherStats.externalCodeSize
202 && externalDataSize == otherStats.externalDataSize
203 && externalCacheSize == otherStats.externalCacheSize
204 && externalMediaSize == otherStats.externalMediaSize
205 && externalObbSize == otherStats.externalObbSize);
206 }
207
208 @Override
209 public int hashCode() {
210 return Objects.hash(packageName, userHandle, codeSize, dataSize,
211 cacheSize, externalCodeSize, externalDataSize, externalCacheSize, externalMediaSize,
212 externalObbSize);
213 }
214
215 }