MtpStorage.java revision d3e4290c0442b6dcf24bcf642f4fc26d12d8e7aa
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.mtp;
18
19/**
20 * This class represents a storage unit on an MTP device.
21 * Used only for MTP support in USB responder mode.
22 * MtpStorageInfo is used in MTP host mode
23 *
24 * @hide
25 */
26public class MtpStorage {
27
28    private final int mStorageId;
29    private final String mPath;
30    private final String mDescription;
31    private final long mReserveSpace;
32
33    public MtpStorage(int id, String path, String description, long reserveSpace) {
34        mStorageId = id;
35        mPath = path;
36        mDescription = description;
37        mReserveSpace = reserveSpace;
38    }
39
40    /**
41     * Returns the storage ID for the storage unit
42     *
43     * @return the storage ID
44     */
45    public final int getStorageId() {
46        return mStorageId;
47    }
48
49    /**
50     * Generates a storage ID for storage of given index.
51     * Index 0 is for primary external storage
52     *
53     * @return the storage ID
54     */
55    public static int getStorageId(int index) {
56        // storage ID is 0x00010001 for primary storage,
57        // then 0x00020001, 0x00030001, etc. for secondary storages
58        return ((index + 1) << 16) + 1;
59    }
60
61   /**
62     * Returns the file path for the storage unit's storage in the file system
63     *
64     * @return the storage file path
65     */
66    public final String getPath() {
67        return mPath;
68    }
69
70   /**
71     * Returns the description string for the storage unit
72     *
73     * @return the storage unit description
74     */
75    public final String getDescription() {
76        return mDescription;
77    }
78
79   /**
80     * Returns the amount of space to reserve on the storage file system.
81     * This can be set to a non-zero value to prevent MTP from filling up the entire storage.
82     *
83     * @return the storage unit description
84     */
85    public final long getReserveSpace() {
86        return mReserveSpace;
87    }
88
89}
90