blob: a2ff159fa3a82f749ac57230a4c39e09467105b2 [file] [log] [blame]
Jeff Sharkeye8cece92017-01-04 11:33:33 -07001/*
2 * Copyright (C) 2017 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
17package android.app.usage;
18
Jeff Sharkeya4d34d92017-04-27 11:21:41 -060019import android.annotation.BytesLong;
Jeff Sharkeye8cece92017-01-04 11:33:33 -070020import android.content.Context;
Jeff Sharkeye8cece92017-01-04 11:33:33 -070021import android.os.Parcel;
22import android.os.Parcelable;
Jeff Sharkey8dedad32017-01-09 18:21:21 -070023import android.os.UserHandle;
Jeff Sharkeye8cece92017-01-04 11:33:33 -070024
25/**
Jeff Sharkey00347882017-04-17 16:44:12 -060026 * Storage statistics for a UID, package, or {@link UserHandle} on a single
27 * storage volume.
Jeff Sharkeye8cece92017-01-04 11:33:33 -070028 *
29 * @see StorageStatsManager
30 */
31public final class StorageStats implements Parcelable {
Jeff Sharkeye8cece92017-01-04 11:33:33 -070032 /** {@hide} */ public long codeBytes;
33 /** {@hide} */ public long dataBytes;
Jeff Sharkeye8cece92017-01-04 11:33:33 -070034 /** {@hide} */ public long cacheBytes;
35
36 /**
Jeff Sharkeya4d34d92017-04-27 11:21:41 -060037 * Return the size of app. This includes {@code APK} files, optimized
38 * compiler output, and unpacked native libraries.
Jeff Sharkeye8cece92017-01-04 11:33:33 -070039 * <p>
Jeff Sharkey00347882017-04-17 16:44:12 -060040 * If the primary external/shared storage is hosted on this storage device,
41 * then this includes files stored under {@link Context#getObbDir()}.
42 * <p>
Jeff Sharkeye8cece92017-01-04 11:33:33 -070043 * Code is shared between all users on a multiuser device.
44 */
Jeff Sharkeya4d34d92017-04-27 11:21:41 -060045 public @BytesLong long getAppBytes() {
Jeff Sharkeye8cece92017-01-04 11:33:33 -070046 return codeBytes;
47 }
48
Jeff Sharkeya4d34d92017-04-27 11:21:41 -060049 /** @removed */
50 @Deprecated
51 public long getCodeBytes() {
52 return getAppBytes();
53 }
54
Jeff Sharkeye8cece92017-01-04 11:33:33 -070055 /**
Jeff Sharkey8dedad32017-01-09 18:21:21 -070056 * Return the size of all data. This includes files stored under
Jeff Sharkeye8cece92017-01-04 11:33:33 -070057 * {@link Context#getDataDir()}, {@link Context#getCacheDir()},
58 * {@link Context#getCodeCacheDir()}.
59 * <p>
Jeff Sharkey00347882017-04-17 16:44:12 -060060 * If the primary external/shared storage is hosted on this storage device,
61 * then this includes files stored under
62 * {@link Context#getExternalFilesDir(String)},
63 * {@link Context#getExternalCacheDir()}, and
64 * {@link Context#getExternalMediaDirs()}.
65 * <p>
Jeff Sharkeye8cece92017-01-04 11:33:33 -070066 * Data is isolated for each user on a multiuser device.
67 */
Jeff Sharkeya4d34d92017-04-27 11:21:41 -060068 public @BytesLong long getDataBytes() {
Jeff Sharkeye8cece92017-01-04 11:33:33 -070069 return dataBytes;
70 }
71
72 /**
Jeff Sharkey8dedad32017-01-09 18:21:21 -070073 * Return the size of all cached data. This includes files stored under
Jeff Sharkeye8cece92017-01-04 11:33:33 -070074 * {@link Context#getCacheDir()} and {@link Context#getCodeCacheDir()}.
75 * <p>
Jeff Sharkey00347882017-04-17 16:44:12 -060076 * If the primary external/shared storage is hosted on this storage device,
77 * then this includes files stored under
78 * {@link Context#getExternalCacheDir()}.
79 * <p>
Jeff Sharkeye8cece92017-01-04 11:33:33 -070080 * Cached data is isolated for each user on a multiuser device.
81 */
Jeff Sharkeya4d34d92017-04-27 11:21:41 -060082 public @BytesLong long getCacheBytes() {
Jeff Sharkeye8cece92017-01-04 11:33:33 -070083 return cacheBytes;
84 }
85
86 /** {@hide} */
Jeff Sharkey8dedad32017-01-09 18:21:21 -070087 public StorageStats() {
Jeff Sharkeye8cece92017-01-04 11:33:33 -070088 }
89
90 /** {@hide} */
91 public StorageStats(Parcel in) {
Jeff Sharkeye8cece92017-01-04 11:33:33 -070092 this.codeBytes = in.readLong();
93 this.dataBytes = in.readLong();
Jeff Sharkeye8cece92017-01-04 11:33:33 -070094 this.cacheBytes = in.readLong();
95 }
96
97 @Override
98 public int describeContents() {
99 return 0;
100 }
101
102 @Override
103 public void writeToParcel(Parcel dest, int flags) {
Jeff Sharkeye8cece92017-01-04 11:33:33 -0700104 dest.writeLong(codeBytes);
105 dest.writeLong(dataBytes);
Jeff Sharkeye8cece92017-01-04 11:33:33 -0700106 dest.writeLong(cacheBytes);
107 }
108
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700109 public static final @android.annotation.NonNull Creator<StorageStats> CREATOR = new Creator<StorageStats>() {
Jeff Sharkeye8cece92017-01-04 11:33:33 -0700110 @Override
111 public StorageStats createFromParcel(Parcel in) {
112 return new StorageStats(in);
113 }
114
115 @Override
116 public StorageStats[] newArray(int size) {
117 return new StorageStats[size];
118 }
119 };
120}