StorageVolume.java revision 2f6a3885533a52758c2cd4f81f6123a712be8ae6
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
38    public StorageVolume(String path, String description,
39            boolean removable, boolean emulated,
40            int mtpReserveSpace) {
41        mPath = path;
42        mDescription = description;
43        mRemovable = removable;
44        mEmulated = emulated;
45        mMtpReserveSpace = mtpReserveSpace;
46    }
47
48    /**
49     * Returns the mount path for the volume.
50     *
51     * @return the mount path
52     */
53    public String getPath() {
54        return mPath;
55    }
56
57    /**
58     * Returns a user visible description of the volume.
59     *
60     * @return the volume description
61     */
62    public String getDescription() {
63        return mDescription;
64    }
65
66    /**
67     * Returns true if the volume is removable.
68     *
69     * @return is removable
70     */
71    public boolean isRemovable() {
72        return mRemovable;
73    }
74
75    /**
76     * Returns true if the volume is emulated.
77     *
78     * @return is removable
79     */
80    public boolean isEmulated() {
81        return mEmulated;
82    }
83
84    /**
85     * Number of megabytes of space to leave unallocated by MTP.
86     * MTP will subtract this value from the free space it reports back
87     * to the host via GetStorageInfo, and will not allow new files to
88     * be added via MTP if there is less than this amount left free in the storage.
89     * If MTP has dedicated storage this value should be zero, but if MTP is
90     * sharing storage with the rest of the system, set this to a positive value
91     * to ensure that MTP activity does not result in the storage being
92     * too close to full.
93     *
94     * @return MTP reserve space
95     */
96    public int getMtpReserveSpace() {
97        return mMtpReserveSpace;
98    }
99
100    @Override
101    public boolean equals(Object obj) {
102        if (obj instanceof StorageVolume && mPath != null) {
103            StorageVolume volume = (StorageVolume)obj;
104            return (mPath.equals(volume.mPath));
105        }
106        return false;
107    }
108
109    @Override
110    public int hashCode() {
111        return mPath.hashCode();
112    }
113
114    @Override
115    public String toString() {
116        return mPath;
117    }
118
119    public static final Parcelable.Creator<StorageVolume> CREATOR =
120        new Parcelable.Creator<StorageVolume>() {
121        public StorageVolume createFromParcel(Parcel in) {
122            String path = in.readString();
123            String description = in.readString();
124            int removable = in.readInt();
125            int emulated = in.readInt();
126            int mtpReserveSpace = in.readInt();
127            return new StorageVolume(path, description,
128                    removable == 1, emulated == 1, mtpReserveSpace);
129        }
130
131        public StorageVolume[] newArray(int size) {
132            return new StorageVolume[size];
133        }
134    };
135
136    public int describeContents() {
137        return 0;
138    }
139
140    public void writeToParcel(Parcel parcel, int flags) {
141        parcel.writeString(mPath);
142        parcel.writeString(mDescription);
143        parcel.writeInt(mRemovable ? 1 : 0);
144        parcel.writeInt(mEmulated ? 1 : 0);
145        parcel.writeInt(mMtpReserveSpace);
146    }
147}
148