• 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.annotation.UnsupportedAppUsage;
20 import android.os.storage.StorageVolume;
21 import android.provider.MediaStore;
22 
23 /**
24  * This class represents a storage unit on an MTP device.
25  * Used only for MTP support in USB responder mode.
26  * MtpStorageInfo is used in MTP host mode
27  *
28  * @hide
29  */
30 public class MtpStorage {
31     private final int mStorageId;
32     private final String mPath;
33     private final String mDescription;
34     private final boolean mRemovable;
35     private final long mMaxFileSize;
36     private final String mVolumeName;
37 
MtpStorage(StorageVolume volume, int storageId)38     public MtpStorage(StorageVolume volume, int storageId) {
39         mStorageId = storageId;
40         mPath = volume.getInternalPath();
41         mDescription = volume.getDescription(null);
42         mRemovable = volume.isRemovable();
43         mMaxFileSize = volume.getMaxFileSize();
44         if (volume.isPrimary()) {
45             mVolumeName = MediaStore.VOLUME_EXTERNAL_PRIMARY;
46         } else {
47             mVolumeName = volume.getNormalizedUuid();
48         }
49     }
50 
51     /**
52      * Returns the storage ID for the storage unit
53      *
54      * @return the storage ID
55      */
56     @UnsupportedAppUsage
getStorageId()57     public final int getStorageId() {
58         return mStorageId;
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     @UnsupportedAppUsage
getPath()67     public final String getPath() {
68         return mPath;
69     }
70 
71    /**
72      * Returns the description string for the storage unit
73      *
74      * @return the storage unit description
75      */
getDescription()76     public final String getDescription() {
77         return mDescription;
78     }
79 
80    /**
81      * Returns true if the storage is removable.
82      *
83      * @return is removable
84      */
isRemovable()85     public final boolean isRemovable() {
86         return mRemovable;
87     }
88 
89    /**
90      * Returns maximum file size for the storage, or zero if it is unbounded.
91      *
92      * @return maximum file size
93      */
getMaxFileSize()94     public long getMaxFileSize() {
95         return mMaxFileSize;
96     }
97 
getVolumeName()98     public String getVolumeName() {
99         return mVolumeName;
100     }
101 }
102