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