1 /*
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 
17 package android.app.usage;
18 
19 import android.annotation.BytesLong;
20 import android.content.Context;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 import android.os.UserHandle;
24 
25 /**
26  * Storage statistics for a UID, package, or {@link UserHandle} on a single
27  * storage volume.
28  *
29  * @see StorageStatsManager
30  */
31 public final class StorageStats implements Parcelable {
32     /** {@hide} */ public long codeBytes;
33     /** {@hide} */ public long dataBytes;
34     /** {@hide} */ public long cacheBytes;
35     /** {@hide} */ public long externalCacheBytes;
36 
37     /**
38      * Return the size of app. This includes {@code APK} files, optimized
39      * compiler output, and unpacked native libraries.
40      * <p>
41      * If the primary external/shared storage is hosted on this storage device,
42      * then this includes files stored under {@link Context#getObbDir()}.
43      * <p>
44      * Code is shared between all users on a multiuser device.
45      */
getAppBytes()46     public @BytesLong long getAppBytes() {
47         return codeBytes;
48     }
49 
50     /**
51      * Return the size of all data. This includes files stored under
52      * {@link Context#getDataDir()}, {@link Context#getCacheDir()},
53      * {@link Context#getCodeCacheDir()}.
54      * <p>
55      * If the primary external/shared storage is hosted on this storage device,
56      * then this includes files stored under
57      * {@link Context#getExternalFilesDir(String)},
58      * {@link Context#getExternalCacheDir()}, and
59      * {@link Context#getExternalMediaDirs()}.
60      * <p>
61      * Data is isolated for each user on a multiuser device.
62      */
getDataBytes()63     public @BytesLong long getDataBytes() {
64         return dataBytes;
65     }
66 
67     /**
68      * Return the size of all cached data. This includes files stored under
69      * {@link Context#getCacheDir()} and {@link Context#getCodeCacheDir()}.
70      * <p>
71      * If the primary external/shared storage is hosted on this storage device,
72      * then this includes files stored under
73      * {@link Context#getExternalCacheDir()}.
74      * <p>
75      * Cached data is isolated for each user on a multiuser device.
76      */
getCacheBytes()77     public @BytesLong long getCacheBytes() {
78         return cacheBytes;
79     }
80 
81     /**
82      * Return the size of all cached data in the primary external/shared storage.
83      * This includes files stored under
84      * {@link Context#getExternalCacheDir()}.
85      * <p>
86      * Cached data is isolated for each user on a multiuser device.
87      */
getExternalCacheBytes()88     public @BytesLong long getExternalCacheBytes() {
89         return externalCacheBytes;
90     }
91 
92     /** {@hide} */
StorageStats()93     public StorageStats() {
94     }
95 
96     /** {@hide} */
StorageStats(Parcel in)97     public StorageStats(Parcel in) {
98         this.codeBytes = in.readLong();
99         this.dataBytes = in.readLong();
100         this.cacheBytes = in.readLong();
101         this.externalCacheBytes = in.readLong();
102     }
103 
104     @Override
describeContents()105     public int describeContents() {
106         return 0;
107     }
108 
109     @Override
writeToParcel(Parcel dest, int flags)110     public void writeToParcel(Parcel dest, int flags) {
111         dest.writeLong(codeBytes);
112         dest.writeLong(dataBytes);
113         dest.writeLong(cacheBytes);
114         dest.writeLong(externalCacheBytes);
115     }
116 
117     public static final @android.annotation.NonNull Creator<StorageStats> CREATOR = new Creator<StorageStats>() {
118         @Override
119         public StorageStats createFromParcel(Parcel in) {
120             return new StorageStats(in);
121         }
122 
123         @Override
124         public StorageStats[] newArray(int size) {
125             return new StorageStats[size];
126         }
127     };
128 }
129