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 19 import android.compat.annotation.UnsupportedAppUsage; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 import android.util.DebugUtils; 23 import android.util.TimeUtils; 24 25 import com.android.internal.util.IndentingPrintWriter; 26 import com.android.internal.util.Preconditions; 27 28 import java.util.Locale; 29 import java.util.Objects; 30 31 /** 32 * Metadata for a storage volume which may not be currently present. 33 * 34 * @hide 35 */ 36 public class VolumeRecord implements Parcelable { 37 public static final String EXTRA_FS_UUID = 38 "android.os.storage.extra.FS_UUID"; 39 40 public static final int USER_FLAG_INITED = 1 << 0; 41 public static final int USER_FLAG_SNOOZED = 1 << 1; 42 43 public final int type; 44 public final String fsUuid; 45 public String partGuid; 46 public String nickname; 47 public int userFlags; 48 public long createdMillis; 49 public long lastSeenMillis; 50 public long lastTrimMillis; 51 public long lastBenchMillis; 52 VolumeRecord(int type, String fsUuid)53 public VolumeRecord(int type, String fsUuid) { 54 this.type = type; 55 this.fsUuid = Preconditions.checkNotNull(fsUuid); 56 } 57 58 @UnsupportedAppUsage VolumeRecord(Parcel parcel)59 public VolumeRecord(Parcel parcel) { 60 type = parcel.readInt(); 61 fsUuid = parcel.readString(); 62 partGuid = parcel.readString(); 63 nickname = parcel.readString(); 64 userFlags = parcel.readInt(); 65 createdMillis = parcel.readLong(); 66 lastSeenMillis = parcel.readLong(); 67 lastTrimMillis = parcel.readLong(); 68 lastBenchMillis = parcel.readLong(); 69 } 70 getType()71 public int getType() { 72 return type; 73 } 74 getFsUuid()75 public String getFsUuid() { 76 return fsUuid; 77 } 78 getNormalizedFsUuid()79 public String getNormalizedFsUuid() { 80 return fsUuid != null ? fsUuid.toLowerCase(Locale.US) : null; 81 } 82 getNickname()83 public String getNickname() { 84 return nickname; 85 } 86 isInited()87 public boolean isInited() { 88 return (userFlags & USER_FLAG_INITED) != 0; 89 } 90 isSnoozed()91 public boolean isSnoozed() { 92 return (userFlags & USER_FLAG_SNOOZED) != 0; 93 } 94 dump(IndentingPrintWriter pw)95 public void dump(IndentingPrintWriter pw) { 96 pw.println("VolumeRecord:"); 97 pw.increaseIndent(); 98 pw.printPair("type", DebugUtils.valueToString(VolumeInfo.class, "TYPE_", type)); 99 pw.printPair("fsUuid", fsUuid); 100 pw.printPair("partGuid", partGuid); 101 pw.println(); 102 pw.printPair("nickname", nickname); 103 pw.printPair("userFlags", 104 DebugUtils.flagsToString(VolumeRecord.class, "USER_FLAG_", userFlags)); 105 pw.println(); 106 pw.printPair("createdMillis", TimeUtils.formatForLogging(createdMillis)); 107 pw.printPair("lastSeenMillis", TimeUtils.formatForLogging(lastSeenMillis)); 108 pw.printPair("lastTrimMillis", TimeUtils.formatForLogging(lastTrimMillis)); 109 pw.printPair("lastBenchMillis", TimeUtils.formatForLogging(lastBenchMillis)); 110 pw.decreaseIndent(); 111 pw.println(); 112 } 113 114 @Override clone()115 public VolumeRecord clone() { 116 final Parcel temp = Parcel.obtain(); 117 try { 118 writeToParcel(temp, 0); 119 temp.setDataPosition(0); 120 return CREATOR.createFromParcel(temp); 121 } finally { 122 temp.recycle(); 123 } 124 } 125 126 @Override equals(Object o)127 public boolean equals(Object o) { 128 if (o instanceof VolumeRecord) { 129 return Objects.equals(fsUuid, ((VolumeRecord) o).fsUuid); 130 } else { 131 return false; 132 } 133 } 134 135 @Override hashCode()136 public int hashCode() { 137 return fsUuid.hashCode(); 138 } 139 140 @UnsupportedAppUsage 141 public static final @android.annotation.NonNull Creator<VolumeRecord> CREATOR = new Creator<VolumeRecord>() { 142 @Override 143 public VolumeRecord createFromParcel(Parcel in) { 144 return new VolumeRecord(in); 145 } 146 147 @Override 148 public VolumeRecord[] newArray(int size) { 149 return new VolumeRecord[size]; 150 } 151 }; 152 153 @Override describeContents()154 public int describeContents() { 155 return 0; 156 } 157 158 @Override writeToParcel(Parcel parcel, int flags)159 public void writeToParcel(Parcel parcel, int flags) { 160 parcel.writeInt(type); 161 parcel.writeString(fsUuid); 162 parcel.writeString(partGuid); 163 parcel.writeString(nickname); 164 parcel.writeInt(userFlags); 165 parcel.writeLong(createdMillis); 166 parcel.writeLong(lastSeenMillis); 167 parcel.writeLong(lastTrimMillis); 168 parcel.writeLong(lastBenchMillis); 169 } 170 } 171