| Mike Lockwood | 7ae938be | 2011-04-05 10:21:27 -0400 | [diff] [blame] | 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 | |
| Fabrice Di Meglio | 13fe2a5 | 2012-05-18 18:08:58 -0700 | [diff] [blame] | 19 | import android.content.Context; |
| Mike Lockwood | fbfe555 | 2011-05-17 17:19:37 -0400 | [diff] [blame] | 20 | import android.os.storage.StorageVolume; |
| 21 | |
| Mike Lockwood | 7ae938be | 2011-04-05 10:21:27 -0400 | [diff] [blame] | 22 | /** |
| 23 | * This class represents a storage unit on an MTP device. |
| 24 | * Used only for MTP support in USB responder mode. |
| 25 | * MtpStorageInfo is used in MTP host mode |
| 26 | * |
| 27 | * @hide |
| 28 | */ |
| 29 | public class MtpStorage { |
| 30 | |
| 31 | private final int mStorageId; |
| 32 | private final String mPath; |
| 33 | private final String mDescription; |
| 34 | private final long mReserveSpace; |
| Mike Lockwood | 5169054 | 2011-05-09 20:16:05 -0700 | [diff] [blame] | 35 | private final boolean mRemovable; |
| Mike Lockwood | 7a59dd2 | 2011-07-11 09:18:03 -0400 | [diff] [blame] | 36 | private final long mMaxFileSize; |
| Mike Lockwood | 7ae938be | 2011-04-05 10:21:27 -0400 | [diff] [blame] | 37 | |
| Fabrice Di Meglio | 13fe2a5 | 2012-05-18 18:08:58 -0700 | [diff] [blame] | 38 | public MtpStorage(StorageVolume volume, Context context) { |
| Mike Lockwood | fbfe555 | 2011-05-17 17:19:37 -0400 | [diff] [blame] | 39 | mStorageId = volume.getStorageId(); |
| 40 | mPath = volume.getPath(); |
| Fabrice Di Meglio | 13fe2a5 | 2012-05-18 18:08:58 -0700 | [diff] [blame] | 41 | mDescription = context.getResources().getString(volume.getDescriptionId()); |
| Henrik Engström | 6393b071 | 2012-11-29 15:29:35 +0100 | [diff] [blame] | 42 | mReserveSpace = volume.getMtpReserveSpace() * 1024L * 1024L; |
| Mike Lockwood | fbfe555 | 2011-05-17 17:19:37 -0400 | [diff] [blame] | 43 | mRemovable = volume.isRemovable(); |
| Mike Lockwood | 7a59dd2 | 2011-07-11 09:18:03 -0400 | [diff] [blame] | 44 | mMaxFileSize = volume.getMaxFileSize(); |
| Mike Lockwood | 7ae938be | 2011-04-05 10:21:27 -0400 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns the storage ID for the storage unit |
| 49 | * |
| 50 | * @return the storage ID |
| 51 | */ |
| 52 | public final int getStorageId() { |
| 53 | return mStorageId; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Generates a storage ID for storage of given index. |
| 58 | * Index 0 is for primary external storage |
| 59 | * |
| 60 | * @return the storage ID |
| 61 | */ |
| 62 | public static int getStorageId(int index) { |
| 63 | // storage ID is 0x00010001 for primary storage, |
| 64 | // then 0x00020001, 0x00030001, etc. for secondary storages |
| 65 | return ((index + 1) << 16) + 1; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Returns the file path for the storage unit's storage in the file system |
| 70 | * |
| 71 | * @return the storage file path |
| 72 | */ |
| 73 | public final String getPath() { |
| 74 | return mPath; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Returns the description string for the storage unit |
| 79 | * |
| 80 | * @return the storage unit description |
| 81 | */ |
| 82 | public final String getDescription() { |
| 83 | return mDescription; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Returns the amount of space to reserve on the storage file system. |
| 88 | * This can be set to a non-zero value to prevent MTP from filling up the entire storage. |
| 89 | * |
| bo huang | 3b60dac | 2012-08-06 13:16:57 +0800 | [diff] [blame] | 90 | * @return reserved space in bytes. |
| Mike Lockwood | 7ae938be | 2011-04-05 10:21:27 -0400 | [diff] [blame] | 91 | */ |
| 92 | public final long getReserveSpace() { |
| 93 | return mReserveSpace; |
| 94 | } |
| 95 | |
| Mike Lockwood | 5169054 | 2011-05-09 20:16:05 -0700 | [diff] [blame] | 96 | /** |
| 97 | * Returns true if the storage is removable. |
| 98 | * |
| 99 | * @return is removable |
| 100 | */ |
| 101 | public final boolean isRemovable() { |
| 102 | return mRemovable; |
| 103 | } |
| Mike Lockwood | 7a59dd2 | 2011-07-11 09:18:03 -0400 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * Returns maximum file size for the storage, or zero if it is unbounded. |
| 107 | * |
| 108 | * @return maximum file size |
| 109 | */ |
| 110 | public long getMaxFileSize() { |
| 111 | return mMaxFileSize; |
| 112 | } |
| Mike Lockwood | 7ae938be | 2011-04-05 10:21:27 -0400 | [diff] [blame] | 113 | } |