• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package android.mtp;
18 
19 import android.os.storage.StorageVolume;
20 
21 /**
22  * This class represents a storage unit on an MTP device.
23  * Used only for MTP support in USB responder mode.
24  * MtpStorageInfo is used in MTP host mode
25  *
26  * @hide
27  */
28 public class MtpStorage {
29 
30     private final int mStorageId;
31     private final String mPath;
32     private final String mDescription;
33     private final long mReserveSpace;
34     private final boolean mRemovable;
35     private final long mMaxFileSize;
36 
MtpStorage(StorageVolume volume)37     public MtpStorage(StorageVolume volume) {
38         mStorageId = volume.getStorageId();
39         mPath = volume.getPath();
40         mDescription = volume.getDescription();
41         mReserveSpace = volume.getMtpReserveSpace();
42         mRemovable = volume.isRemovable();
43         mMaxFileSize = volume.getMaxFileSize();
44     }
45 
46     /**
47      * Returns the storage ID for the storage unit
48      *
49      * @return the storage ID
50      */
getStorageId()51     public final int getStorageId() {
52         return mStorageId;
53     }
54 
55     /**
56      * Generates a storage ID for storage of given index.
57      * Index 0 is for primary external storage
58      *
59      * @return the storage ID
60      */
getStorageId(int index)61     public static int getStorageId(int index) {
62         // storage ID is 0x00010001 for primary storage,
63         // then 0x00020001, 0x00030001, etc. for secondary storages
64         return ((index + 1) << 16) + 1;
65     }
66 
67    /**
68      * Returns the file path for the storage unit's storage in the file system
69      *
70      * @return the storage file path
71      */
getPath()72     public final String getPath() {
73         return mPath;
74     }
75 
76    /**
77      * Returns the description string for the storage unit
78      *
79      * @return the storage unit description
80      */
getDescription()81     public final String getDescription() {
82         return mDescription;
83     }
84 
85    /**
86      * Returns the amount of space to reserve on the storage file system.
87      * This can be set to a non-zero value to prevent MTP from filling up the entire storage.
88      *
89      * @return the storage unit description
90      */
getReserveSpace()91     public final long getReserveSpace() {
92         return mReserveSpace;
93     }
94 
95    /**
96      * Returns true if the storage is removable.
97      *
98      * @return is removable
99      */
isRemovable()100     public final boolean isRemovable() {
101         return mRemovable;
102     }
103 
104    /**
105      * Returns maximum file size for the storage, or zero if it is unbounded.
106      *
107      * @return maximum file size
108      */
getMaxFileSize()109     public long getMaxFileSize() {
110         return mMaxFileSize;
111     }
112 }
113