blob: bc2d55a92b906a5fa6c01df5e226c2d8efe7288a [file] [log] [blame]
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07001/*
2 * Copyright (C) 2015 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.os.storage;
18
Mathew Inwood98e9ad12018-08-30 13:11:50 +010019import android.annotation.UnsupportedAppUsage;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070020import android.os.Parcel;
21import android.os.Parcelable;
22import android.util.DebugUtils;
Jeff Sharkeye8a4b662015-06-27 15:43:45 -070023import android.util.TimeUtils;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070024
25import com.android.internal.util.IndentingPrintWriter;
26import com.android.internal.util.Preconditions;
27
28import java.util.Objects;
29
30/**
Jeff Sharkeyb42d6942015-04-28 22:25:26 -070031 * Metadata for a storage volume which may not be currently present.
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070032 *
33 * @hide
34 */
35public class VolumeRecord implements Parcelable {
36 public static final String EXTRA_FS_UUID =
37 "android.os.storage.extra.FS_UUID";
38
39 public static final int USER_FLAG_INITED = 1 << 0;
40 public static final int USER_FLAG_SNOOZED = 1 << 1;
41
42 public final int type;
43 public final String fsUuid;
Jeff Sharkey5cc0df22015-06-17 19:44:05 -070044 public String partGuid;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070045 public String nickname;
46 public int userFlags;
Jeff Sharkeye8a4b662015-06-27 15:43:45 -070047 public long createdMillis;
48 public long lastTrimMillis;
49 public long lastBenchMillis;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070050
51 public VolumeRecord(int type, String fsUuid) {
52 this.type = type;
53 this.fsUuid = Preconditions.checkNotNull(fsUuid);
54 }
55
Mathew Inwood98e9ad12018-08-30 13:11:50 +010056 @UnsupportedAppUsage
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070057 public VolumeRecord(Parcel parcel) {
58 type = parcel.readInt();
59 fsUuid = parcel.readString();
Jeff Sharkey5cc0df22015-06-17 19:44:05 -070060 partGuid = parcel.readString();
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070061 nickname = parcel.readString();
62 userFlags = parcel.readInt();
Jeff Sharkeye8a4b662015-06-27 15:43:45 -070063 createdMillis = parcel.readLong();
64 lastTrimMillis = parcel.readLong();
65 lastBenchMillis = parcel.readLong();
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070066 }
67
68 public int getType() {
69 return type;
70 }
71
72 public String getFsUuid() {
73 return fsUuid;
74 }
75
76 public String getNickname() {
77 return nickname;
78 }
79
80 public boolean isInited() {
81 return (userFlags & USER_FLAG_INITED) != 0;
82 }
83
84 public boolean isSnoozed() {
85 return (userFlags & USER_FLAG_SNOOZED) != 0;
86 }
87
88 public void dump(IndentingPrintWriter pw) {
89 pw.println("VolumeRecord:");
90 pw.increaseIndent();
91 pw.printPair("type", DebugUtils.valueToString(VolumeInfo.class, "TYPE_", type));
92 pw.printPair("fsUuid", fsUuid);
Jeff Sharkey5cc0df22015-06-17 19:44:05 -070093 pw.printPair("partGuid", partGuid);
94 pw.println();
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070095 pw.printPair("nickname", nickname);
96 pw.printPair("userFlags",
97 DebugUtils.flagsToString(VolumeRecord.class, "USER_FLAG_", userFlags));
Jeff Sharkeye8a4b662015-06-27 15:43:45 -070098 pw.println();
99 pw.printPair("createdMillis", TimeUtils.formatForLogging(createdMillis));
100 pw.printPair("lastTrimMillis", TimeUtils.formatForLogging(lastTrimMillis));
101 pw.printPair("lastBenchMillis", TimeUtils.formatForLogging(lastBenchMillis));
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700102 pw.decreaseIndent();
103 pw.println();
104 }
105
106 @Override
107 public VolumeRecord clone() {
108 final Parcel temp = Parcel.obtain();
109 try {
110 writeToParcel(temp, 0);
111 temp.setDataPosition(0);
112 return CREATOR.createFromParcel(temp);
113 } finally {
114 temp.recycle();
115 }
116 }
117
118 @Override
119 public boolean equals(Object o) {
120 if (o instanceof VolumeRecord) {
121 return Objects.equals(fsUuid, ((VolumeRecord) o).fsUuid);
122 } else {
123 return false;
124 }
125 }
126
127 @Override
128 public int hashCode() {
129 return fsUuid.hashCode();
130 }
131
Mathew Inwood98e9ad12018-08-30 13:11:50 +0100132 @UnsupportedAppUsage
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700133 public static final Creator<VolumeRecord> CREATOR = new Creator<VolumeRecord>() {
134 @Override
135 public VolumeRecord createFromParcel(Parcel in) {
136 return new VolumeRecord(in);
137 }
138
139 @Override
140 public VolumeRecord[] newArray(int size) {
141 return new VolumeRecord[size];
142 }
143 };
144
145 @Override
146 public int describeContents() {
147 return 0;
148 }
149
150 @Override
151 public void writeToParcel(Parcel parcel, int flags) {
152 parcel.writeInt(type);
153 parcel.writeString(fsUuid);
Jeff Sharkey5cc0df22015-06-17 19:44:05 -0700154 parcel.writeString(partGuid);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700155 parcel.writeString(nickname);
156 parcel.writeInt(userFlags);
Jeff Sharkeye8a4b662015-06-27 15:43:45 -0700157 parcel.writeLong(createdMillis);
158 parcel.writeLong(lastTrimMillis);
159 parcel.writeLong(lastBenchMillis);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700160 }
161}