Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.os.storage; |
| 18 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 19 | import android.annotation.UnsupportedAppUsage; |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | import android.util.DebugUtils; |
Jeff Sharkey | e8a4b66 | 2015-06-27 15:43:45 -0700 | [diff] [blame] | 23 | import android.util.TimeUtils; |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 24 | |
| 25 | import com.android.internal.util.IndentingPrintWriter; |
| 26 | import com.android.internal.util.Preconditions; |
| 27 | |
| 28 | import java.util.Objects; |
| 29 | |
| 30 | /** |
Jeff Sharkey | b42d694 | 2015-04-28 22:25:26 -0700 | [diff] [blame] | 31 | * Metadata for a storage volume which may not be currently present. |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 32 | * |
| 33 | * @hide |
| 34 | */ |
| 35 | public 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 Sharkey | 5cc0df2 | 2015-06-17 19:44:05 -0700 | [diff] [blame] | 44 | public String partGuid; |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 45 | public String nickname; |
| 46 | public int userFlags; |
Jeff Sharkey | e8a4b66 | 2015-06-27 15:43:45 -0700 | [diff] [blame] | 47 | public long createdMillis; |
| 48 | public long lastTrimMillis; |
| 49 | public long lastBenchMillis; |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 50 | |
| 51 | public VolumeRecord(int type, String fsUuid) { |
| 52 | this.type = type; |
| 53 | this.fsUuid = Preconditions.checkNotNull(fsUuid); |
| 54 | } |
| 55 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 56 | @UnsupportedAppUsage |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 57 | public VolumeRecord(Parcel parcel) { |
| 58 | type = parcel.readInt(); |
| 59 | fsUuid = parcel.readString(); |
Jeff Sharkey | 5cc0df2 | 2015-06-17 19:44:05 -0700 | [diff] [blame] | 60 | partGuid = parcel.readString(); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 61 | nickname = parcel.readString(); |
| 62 | userFlags = parcel.readInt(); |
Jeff Sharkey | e8a4b66 | 2015-06-27 15:43:45 -0700 | [diff] [blame] | 63 | createdMillis = parcel.readLong(); |
| 64 | lastTrimMillis = parcel.readLong(); |
| 65 | lastBenchMillis = parcel.readLong(); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 66 | } |
| 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 Sharkey | 5cc0df2 | 2015-06-17 19:44:05 -0700 | [diff] [blame] | 93 | pw.printPair("partGuid", partGuid); |
| 94 | pw.println(); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 95 | pw.printPair("nickname", nickname); |
| 96 | pw.printPair("userFlags", |
| 97 | DebugUtils.flagsToString(VolumeRecord.class, "USER_FLAG_", userFlags)); |
Jeff Sharkey | e8a4b66 | 2015-06-27 15:43:45 -0700 | [diff] [blame] | 98 | pw.println(); |
| 99 | pw.printPair("createdMillis", TimeUtils.formatForLogging(createdMillis)); |
| 100 | pw.printPair("lastTrimMillis", TimeUtils.formatForLogging(lastTrimMillis)); |
| 101 | pw.printPair("lastBenchMillis", TimeUtils.formatForLogging(lastBenchMillis)); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 102 | 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 Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 132 | @UnsupportedAppUsage |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 133 | 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 Sharkey | 5cc0df2 | 2015-06-17 19:44:05 -0700 | [diff] [blame] | 154 | parcel.writeString(partGuid); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 155 | parcel.writeString(nickname); |
| 156 | parcel.writeInt(userFlags); |
Jeff Sharkey | e8a4b66 | 2015-06-27 15:43:45 -0700 | [diff] [blame] | 157 | parcel.writeLong(createdMillis); |
| 158 | parcel.writeLong(lastTrimMillis); |
| 159 | parcel.writeLong(lastBenchMillis); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 160 | } |
| 161 | } |