Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 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 | |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 19 | import android.annotation.BytesLong; |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 20 | import android.content.Context; |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
Jeff Sharkey | 8dedad3 | 2017-01-09 18:21:21 -0700 | [diff] [blame] | 23 | import android.os.UserHandle; |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
Jeff Sharkey | 0034788 | 2017-04-17 16:44:12 -0600 | [diff] [blame] | 26 | * Storage statistics for a UID, package, or {@link UserHandle} on a single |
| 27 | * storage volume. |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 28 | * |
| 29 | * @see StorageStatsManager |
| 30 | */ |
| 31 | public final class StorageStats implements Parcelable { |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 32 | /** {@hide} */ public long codeBytes; |
| 33 | /** {@hide} */ public long dataBytes; |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 34 | /** {@hide} */ public long cacheBytes; |
| 35 | |
| 36 | /** |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 37 | * Return the size of app. This includes {@code APK} files, optimized |
| 38 | * compiler output, and unpacked native libraries. |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 39 | * <p> |
Jeff Sharkey | 0034788 | 2017-04-17 16:44:12 -0600 | [diff] [blame] | 40 | * 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 Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 43 | * Code is shared between all users on a multiuser device. |
| 44 | */ |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 45 | public @BytesLong long getAppBytes() { |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 46 | return codeBytes; |
| 47 | } |
| 48 | |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 49 | /** @removed */ |
| 50 | @Deprecated |
| 51 | public long getCodeBytes() { |
| 52 | return getAppBytes(); |
| 53 | } |
| 54 | |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 55 | /** |
Jeff Sharkey | 8dedad3 | 2017-01-09 18:21:21 -0700 | [diff] [blame] | 56 | * Return the size of all data. This includes files stored under |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 57 | * {@link Context#getDataDir()}, {@link Context#getCacheDir()}, |
| 58 | * {@link Context#getCodeCacheDir()}. |
| 59 | * <p> |
Jeff Sharkey | 0034788 | 2017-04-17 16:44:12 -0600 | [diff] [blame] | 60 | * 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 Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 66 | * Data is isolated for each user on a multiuser device. |
| 67 | */ |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 68 | public @BytesLong long getDataBytes() { |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 69 | return dataBytes; |
| 70 | } |
| 71 | |
| 72 | /** |
Jeff Sharkey | 8dedad3 | 2017-01-09 18:21:21 -0700 | [diff] [blame] | 73 | * Return the size of all cached data. This includes files stored under |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 74 | * {@link Context#getCacheDir()} and {@link Context#getCodeCacheDir()}. |
| 75 | * <p> |
Jeff Sharkey | 0034788 | 2017-04-17 16:44:12 -0600 | [diff] [blame] | 76 | * 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 Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 80 | * Cached data is isolated for each user on a multiuser device. |
| 81 | */ |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 82 | public @BytesLong long getCacheBytes() { |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 83 | return cacheBytes; |
| 84 | } |
| 85 | |
| 86 | /** {@hide} */ |
Jeff Sharkey | 8dedad3 | 2017-01-09 18:21:21 -0700 | [diff] [blame] | 87 | public StorageStats() { |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /** {@hide} */ |
| 91 | public StorageStats(Parcel in) { |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 92 | this.codeBytes = in.readLong(); |
| 93 | this.dataBytes = in.readLong(); |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 94 | 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 Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 104 | dest.writeLong(codeBytes); |
| 105 | dest.writeLong(dataBytes); |
Jeff Sharkey | e8cece9 | 2017-01-04 11:33:33 -0700 | [diff] [blame] | 106 | dest.writeLong(cacheBytes); |
| 107 | } |
| 108 | |
| 109 | public static final Creator<StorageStats> CREATOR = new Creator<StorageStats>() { |
| 110 | @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 | } |