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