StorageVolume.java revision fbfe55512596fd00c1fb51caa851e17dae60fd43
1/* 2 * Copyright (C) 2011 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.Bundle; 20import android.os.Parcel; 21import android.os.Parcelable; 22import android.util.Log; 23 24/** 25 * A class representing a storage volume 26 * @hide 27 */ 28public class StorageVolume implements Parcelable { 29 30 private static final String TAG = "StorageVolume"; 31 32 private final String mPath; 33 private final String mDescription; 34 private final boolean mRemovable; 35 private final boolean mEmulated; 36 private final int mMtpReserveSpace; 37 private int mStorageId; 38 39 public StorageVolume(String path, String description, 40 boolean removable, boolean emulated, int mtpReserveSpace) { 41 mPath = path; 42 mDescription = description; 43 mRemovable = removable; 44 mEmulated = emulated; 45 mMtpReserveSpace = mtpReserveSpace; 46 } 47 48 // for parcelling only 49 private StorageVolume(String path, String description, 50 boolean removable, boolean emulated, int mtpReserveSpace, int storageId) { 51 mPath = path; 52 mDescription = description; 53 mRemovable = removable; 54 mEmulated = emulated; 55 mMtpReserveSpace = mtpReserveSpace; 56 mStorageId = storageId; 57 } 58 59 /** 60 * Returns the mount path for the volume. 61 * 62 * @return the mount path 63 */ 64 public String getPath() { 65 return mPath; 66 } 67 68 /** 69 * Returns a user visible description of the volume. 70 * 71 * @return the volume description 72 */ 73 public String getDescription() { 74 return mDescription; 75 } 76 77 /** 78 * Returns true if the volume is removable. 79 * 80 * @return is removable 81 */ 82 public boolean isRemovable() { 83 return mRemovable; 84 } 85 86 /** 87 * Returns true if the volume is emulated. 88 * 89 * @return is removable 90 */ 91 public boolean isEmulated() { 92 return mEmulated; 93 } 94 95 /** 96 * Returns the MTP storage ID for the volume. 97 * this is also used for the storage_id column in the media provider. 98 * 99 * @return MTP storage ID 100 */ 101 public int getStorageId() { 102 return mStorageId; 103 } 104 105 /** 106 * Do not call this unless you are MountService 107 */ 108 public void setStorageId(int index) { 109 // storage ID is 0x00010001 for primary storage, 110 // then 0x00020001, 0x00030001, etc. for secondary storages 111 mStorageId = ((index + 1) << 16) + 1; 112 } 113 114 /** 115 * Number of megabytes of space to leave unallocated by MTP. 116 * MTP will subtract this value from the free space it reports back 117 * to the host via GetStorageInfo, and will not allow new files to 118 * be added via MTP if there is less than this amount left free in the storage. 119 * If MTP has dedicated storage this value should be zero, but if MTP is 120 * sharing storage with the rest of the system, set this to a positive value 121 * to ensure that MTP activity does not result in the storage being 122 * too close to full. 123 * 124 * @return MTP reserve space 125 */ 126 public int getMtpReserveSpace() { 127 return mMtpReserveSpace; 128 } 129 130 @Override 131 public boolean equals(Object obj) { 132 if (obj instanceof StorageVolume && mPath != null) { 133 StorageVolume volume = (StorageVolume)obj; 134 return (mPath.equals(volume.mPath)); 135 } 136 return false; 137 } 138 139 @Override 140 public int hashCode() { 141 return mPath.hashCode(); 142 } 143 144 @Override 145 public String toString() { 146 return mPath; 147 } 148 149 public static final Parcelable.Creator<StorageVolume> CREATOR = 150 new Parcelable.Creator<StorageVolume>() { 151 public StorageVolume createFromParcel(Parcel in) { 152 String path = in.readString(); 153 String description = in.readString(); 154 int removable = in.readInt(); 155 int emulated = in.readInt(); 156 int storageId = in.readInt(); 157 int mtpReserveSpace = in.readInt(); 158 return new StorageVolume(path, description, 159 removable == 1, emulated == 1, 160 mtpReserveSpace, storageId); 161 } 162 163 public StorageVolume[] newArray(int size) { 164 return new StorageVolume[size]; 165 } 166 }; 167 168 public int describeContents() { 169 return 0; 170 } 171 172 public void writeToParcel(Parcel parcel, int flags) { 173 parcel.writeString(mPath); 174 parcel.writeString(mDescription); 175 parcel.writeInt(mRemovable ? 1 : 0); 176 parcel.writeInt(mEmulated ? 1 : 0); 177 parcel.writeInt(mStorageId); 178 parcel.writeInt(mMtpReserveSpace); 179 } 180} 181