| Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
| Daichi Hirono | 0639fe0 | 2016-07-07 17:36:26 +0900 | [diff] [blame] | 19 | import android.annotation.NonNull; |
| 20 | |
| Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 21 | /** |
| 22 | * This class encapsulates information about an MTP device. |
| 23 | * This corresponds to the DeviceInfo Dataset described in |
| 24 | * section 5.1.1 of the MTP specification. |
| Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 25 | */ |
| 26 | public class MtpDeviceInfo { |
| 27 | |
| 28 | private String mManufacturer; |
| 29 | private String mModel; |
| 30 | private String mVersion; |
| 31 | private String mSerialNumber; |
| Daichi Hirono | 1d4779c | 2016-01-06 16:43:32 +0900 | [diff] [blame] | 32 | private int[] mOperationsSupported; |
| Daichi Hirono | 148954a | 2016-01-21 19:55:45 +0900 | [diff] [blame] | 33 | private int[] mEventsSupported; |
| Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 34 | |
| 35 | // only instantiated via JNI |
| 36 | private MtpDeviceInfo() { |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Returns the manufacturer's name for the MTP device |
| 41 | * |
| 42 | * @return the manufacturer name |
| 43 | */ |
| Daichi Hirono | 0639fe0 | 2016-07-07 17:36:26 +0900 | [diff] [blame] | 44 | public final @NonNull String getManufacturer() { |
| Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 45 | return mManufacturer; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Returns the model name for the MTP device |
| 50 | * |
| 51 | * @return the model name |
| 52 | */ |
| Daichi Hirono | 0639fe0 | 2016-07-07 17:36:26 +0900 | [diff] [blame] | 53 | public final @NonNull String getModel() { |
| Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 54 | return mModel; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Returns the version string the MTP device |
| 59 | * |
| 60 | * @return the device version |
| 61 | */ |
| Daichi Hirono | 0639fe0 | 2016-07-07 17:36:26 +0900 | [diff] [blame] | 62 | public final @NonNull String getVersion() { |
| Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 63 | return mVersion; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Returns the unique serial number for the MTP device |
| 68 | * |
| 69 | * @return the serial number |
| 70 | */ |
| Daichi Hirono | 0639fe0 | 2016-07-07 17:36:26 +0900 | [diff] [blame] | 71 | public final @NonNull String getSerialNumber() { |
| Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 72 | return mSerialNumber; |
| 73 | } |
| Daichi Hirono | 1d4779c | 2016-01-06 16:43:32 +0900 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Returns operation code supported by the device. |
| 77 | * |
| Daichi Hirono | 148954a | 2016-01-21 19:55:45 +0900 | [diff] [blame] | 78 | * @return supported operation code. Can be null if device does not provide the property. |
| 79 | * @see MtpConstants#OPERATION_GET_DEVICE_INFO |
| 80 | * @see MtpConstants#OPERATION_OPEN_SESSION |
| 81 | * @see MtpConstants#OPERATION_CLOSE_SESSION |
| 82 | * @see MtpConstants#OPERATION_GET_STORAGE_I_DS |
| 83 | * @see MtpConstants#OPERATION_GET_STORAGE_INFO |
| 84 | * @see MtpConstants#OPERATION_GET_NUM_OBJECTS |
| 85 | * @see MtpConstants#OPERATION_GET_OBJECT_HANDLES |
| 86 | * @see MtpConstants#OPERATION_GET_OBJECT_INFO |
| 87 | * @see MtpConstants#OPERATION_GET_OBJECT |
| 88 | * @see MtpConstants#OPERATION_GET_THUMB |
| 89 | * @see MtpConstants#OPERATION_DELETE_OBJECT |
| 90 | * @see MtpConstants#OPERATION_SEND_OBJECT_INFO |
| 91 | * @see MtpConstants#OPERATION_SEND_OBJECT |
| 92 | * @see MtpConstants#OPERATION_INITIATE_CAPTURE |
| 93 | * @see MtpConstants#OPERATION_FORMAT_STORE |
| 94 | * @see MtpConstants#OPERATION_RESET_DEVICE |
| 95 | * @see MtpConstants#OPERATION_SELF_TEST |
| 96 | * @see MtpConstants#OPERATION_SET_OBJECT_PROTECTION |
| 97 | * @see MtpConstants#OPERATION_POWER_DOWN |
| 98 | * @see MtpConstants#OPERATION_GET_DEVICE_PROP_DESC |
| 99 | * @see MtpConstants#OPERATION_GET_DEVICE_PROP_VALUE |
| 100 | * @see MtpConstants#OPERATION_SET_DEVICE_PROP_VALUE |
| 101 | * @see MtpConstants#OPERATION_RESET_DEVICE_PROP_VALUE |
| 102 | * @see MtpConstants#OPERATION_TERMINATE_OPEN_CAPTURE |
| 103 | * @see MtpConstants#OPERATION_MOVE_OBJECT |
| 104 | * @see MtpConstants#OPERATION_COPY_OBJECT |
| 105 | * @see MtpConstants#OPERATION_GET_PARTIAL_OBJECT |
| 106 | * @see MtpConstants#OPERATION_INITIATE_OPEN_CAPTURE |
| 107 | * @see MtpConstants#OPERATION_GET_OBJECT_PROPS_SUPPORTED |
| 108 | * @see MtpConstants#OPERATION_GET_OBJECT_PROP_DESC |
| 109 | * @see MtpConstants#OPERATION_GET_OBJECT_PROP_VALUE |
| 110 | * @see MtpConstants#OPERATION_SET_OBJECT_PROP_VALUE |
| 111 | * @see MtpConstants#OPERATION_GET_OBJECT_REFERENCES |
| 112 | * @see MtpConstants#OPERATION_SET_OBJECT_REFERENCES |
| 113 | * @see MtpConstants#OPERATION_SKIP |
| Daichi Hirono | 1d4779c | 2016-01-06 16:43:32 +0900 | [diff] [blame] | 114 | */ |
| Daichi Hirono | 0639fe0 | 2016-07-07 17:36:26 +0900 | [diff] [blame] | 115 | public final @NonNull int[] getOperationsSupported() { |
| Daichi Hirono | 1d4779c | 2016-01-06 16:43:32 +0900 | [diff] [blame] | 116 | return mOperationsSupported; |
| 117 | } |
| Daichi Hirono | 148954a | 2016-01-21 19:55:45 +0900 | [diff] [blame] | 118 | |
| 119 | /** |
| 120 | * Returns event code supported by the device. |
| 121 | * |
| 122 | * @return supported event code. Can be null if device does not provide the property. |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 123 | * @see MtpEvent#EVENT_UNDEFINED |
| 124 | * @see MtpEvent#EVENT_CANCEL_TRANSACTION |
| 125 | * @see MtpEvent#EVENT_OBJECT_ADDED |
| 126 | * @see MtpEvent#EVENT_OBJECT_REMOVED |
| 127 | * @see MtpEvent#EVENT_STORE_ADDED |
| 128 | * @see MtpEvent#EVENT_STORE_REMOVED |
| 129 | * @see MtpEvent#EVENT_DEVICE_PROP_CHANGED |
| 130 | * @see MtpEvent#EVENT_OBJECT_INFO_CHANGED |
| 131 | * @see MtpEvent#EVENT_DEVICE_INFO_CHANGED |
| 132 | * @see MtpEvent#EVENT_REQUEST_OBJECT_TRANSFER |
| 133 | * @see MtpEvent#EVENT_STORE_FULL |
| 134 | * @see MtpEvent#EVENT_DEVICE_RESET |
| 135 | * @see MtpEvent#EVENT_STORAGE_INFO_CHANGED |
| 136 | * @see MtpEvent#EVENT_CAPTURE_COMPLETE |
| 137 | * @see MtpEvent#EVENT_UNREPORTED_STATUS |
| 138 | * @see MtpEvent#EVENT_OBJECT_PROP_CHANGED |
| 139 | * @see MtpEvent#EVENT_OBJECT_PROP_DESC_CHANGED |
| 140 | * @see MtpEvent#EVENT_OBJECT_REFERENCES_CHANGED |
| Daichi Hirono | 148954a | 2016-01-21 19:55:45 +0900 | [diff] [blame] | 141 | */ |
| Daichi Hirono | 0639fe0 | 2016-07-07 17:36:26 +0900 | [diff] [blame] | 142 | public final @NonNull int[] getEventsSupported() { |
| Daichi Hirono | 148954a | 2016-01-21 19:55:45 +0900 | [diff] [blame] | 143 | return mEventsSupported; |
| 144 | } |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 145 | |
| 146 | /** |
| 147 | * Returns if the given operation is supported by the device or not. |
| 148 | * @param code Operation code. |
| 149 | * @return If the given operation is supported by the device or not. |
| 150 | */ |
| 151 | public boolean isOperationSupported(int code) { |
| 152 | return isSupported(mOperationsSupported, code); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Returns if the given event is supported by the device or not. |
| 157 | * @param code Event code. |
| 158 | * @return If the given event is supported by the device or not. |
| 159 | */ |
| 160 | public boolean isEventSupported(int code) { |
| 161 | return isSupported(mEventsSupported, code); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Returns if the code set contains code. |
| 166 | * @hide |
| 167 | */ |
| Daichi Hirono | 0639fe0 | 2016-07-07 17:36:26 +0900 | [diff] [blame] | 168 | private static boolean isSupported(@NonNull int[] set, int code) { |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 169 | for (final int element : set) { |
| 170 | if (element == code) { |
| 171 | return true; |
| 172 | } |
| 173 | } |
| 174 | return false; |
| 175 | } |
| Daichi Hirono | 1d4779c | 2016-01-06 16:43:32 +0900 | [diff] [blame] | 176 | } |