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 19 import android.annotation.NonNull; 20 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. 25 */ 26 public class MtpDeviceInfo { 27 28 private String mManufacturer; 29 private String mModel; 30 private String mVersion; 31 private String mSerialNumber; 32 private int[] mOperationsSupported; 33 private int[] mEventsSupported; 34 private int[] mDevicePropertySupported; 35 36 // only instantiated via JNI MtpDeviceInfo()37 private MtpDeviceInfo() { 38 } 39 40 /** 41 * Returns the manufacturer's name for the MTP device 42 * 43 * @return the manufacturer name 44 */ getManufacturer()45 public final @NonNull String getManufacturer() { 46 return mManufacturer; 47 } 48 49 /** 50 * Returns the model name for the MTP device 51 * 52 * @return the model name 53 */ getModel()54 public final @NonNull String getModel() { 55 return mModel; 56 } 57 58 /** 59 * Returns the version string the MTP device 60 * 61 * @return the device version 62 */ getVersion()63 public final @NonNull String getVersion() { 64 return mVersion; 65 } 66 67 /** 68 * Returns the unique serial number for the MTP device 69 * 70 * @return the serial number 71 */ getSerialNumber()72 public final @NonNull String getSerialNumber() { 73 return mSerialNumber; 74 } 75 76 /** 77 * Returns operation code supported by the device. 78 * 79 * @return supported operation code. Can be null if device does not provide the property. 80 * @see MtpConstants#OPERATION_GET_DEVICE_INFO 81 * @see MtpConstants#OPERATION_OPEN_SESSION 82 * @see MtpConstants#OPERATION_CLOSE_SESSION 83 * @see MtpConstants#OPERATION_GET_STORAGE_I_DS 84 * @see MtpConstants#OPERATION_GET_STORAGE_INFO 85 * @see MtpConstants#OPERATION_GET_NUM_OBJECTS 86 * @see MtpConstants#OPERATION_GET_OBJECT_HANDLES 87 * @see MtpConstants#OPERATION_GET_OBJECT_INFO 88 * @see MtpConstants#OPERATION_GET_OBJECT 89 * @see MtpConstants#OPERATION_GET_THUMB 90 * @see MtpConstants#OPERATION_DELETE_OBJECT 91 * @see MtpConstants#OPERATION_SEND_OBJECT_INFO 92 * @see MtpConstants#OPERATION_SEND_OBJECT 93 * @see MtpConstants#OPERATION_INITIATE_CAPTURE 94 * @see MtpConstants#OPERATION_FORMAT_STORE 95 * @see MtpConstants#OPERATION_RESET_DEVICE 96 * @see MtpConstants#OPERATION_SELF_TEST 97 * @see MtpConstants#OPERATION_SET_OBJECT_PROTECTION 98 * @see MtpConstants#OPERATION_POWER_DOWN 99 * @see MtpConstants#OPERATION_GET_DEVICE_PROP_DESC 100 * @see MtpConstants#OPERATION_GET_DEVICE_PROP_VALUE 101 * @see MtpConstants#OPERATION_SET_DEVICE_PROP_VALUE 102 * @see MtpConstants#OPERATION_RESET_DEVICE_PROP_VALUE 103 * @see MtpConstants#OPERATION_TERMINATE_OPEN_CAPTURE 104 * @see MtpConstants#OPERATION_MOVE_OBJECT 105 * @see MtpConstants#OPERATION_COPY_OBJECT 106 * @see MtpConstants#OPERATION_GET_PARTIAL_OBJECT 107 * @see MtpConstants#OPERATION_INITIATE_OPEN_CAPTURE 108 * @see MtpConstants#OPERATION_GET_OBJECT_PROPS_SUPPORTED 109 * @see MtpConstants#OPERATION_GET_OBJECT_PROP_DESC 110 * @see MtpConstants#OPERATION_GET_OBJECT_PROP_VALUE 111 * @see MtpConstants#OPERATION_SET_OBJECT_PROP_VALUE 112 * @see MtpConstants#OPERATION_GET_OBJECT_REFERENCES 113 * @see MtpConstants#OPERATION_SET_OBJECT_REFERENCES 114 * @see MtpConstants#OPERATION_SKIP 115 */ getOperationsSupported()116 public final @NonNull int[] getOperationsSupported() { 117 return mOperationsSupported; 118 } 119 120 /** 121 * Returns event code supported by the device. 122 * 123 * @return supported event code. Can be null if device does not provide the property. 124 * @see MtpEvent#EVENT_UNDEFINED 125 * @see MtpEvent#EVENT_CANCEL_TRANSACTION 126 * @see MtpEvent#EVENT_OBJECT_ADDED 127 * @see MtpEvent#EVENT_OBJECT_REMOVED 128 * @see MtpEvent#EVENT_STORE_ADDED 129 * @see MtpEvent#EVENT_STORE_REMOVED 130 * @see MtpEvent#EVENT_DEVICE_PROP_CHANGED 131 * @see MtpEvent#EVENT_OBJECT_INFO_CHANGED 132 * @see MtpEvent#EVENT_DEVICE_INFO_CHANGED 133 * @see MtpEvent#EVENT_REQUEST_OBJECT_TRANSFER 134 * @see MtpEvent#EVENT_STORE_FULL 135 * @see MtpEvent#EVENT_DEVICE_RESET 136 * @see MtpEvent#EVENT_STORAGE_INFO_CHANGED 137 * @see MtpEvent#EVENT_CAPTURE_COMPLETE 138 * @see MtpEvent#EVENT_UNREPORTED_STATUS 139 * @see MtpEvent#EVENT_OBJECT_PROP_CHANGED 140 * @see MtpEvent#EVENT_OBJECT_PROP_DESC_CHANGED 141 * @see MtpEvent#EVENT_OBJECT_REFERENCES_CHANGED 142 */ getEventsSupported()143 public final @NonNull int[] getEventsSupported() { 144 return mEventsSupported; 145 } 146 147 /** 148 * Returns Device property code supported by the device. 149 * 150 * @return supported Device property code. Can be null if device does not provide the property. 151 * 152 * @see MtpConstants#DEVICE_PROPERTY_SYNCHRONIZATION_PARTNER 153 * @see MtpConstants#DEVICE_PROPERTY_DEVICE_FRIENDLY_NAME 154 * @see MtpConstants#DEVICE_PROPERTY_SESSION_INITIATOR_VERSION_INFO 155 * 156 * {@hide} 157 */ getDevicePropertySupported()158 public final @NonNull int[] getDevicePropertySupported() { 159 return mDevicePropertySupported; 160 } 161 162 /** 163 * Returns if the given operation is supported by the device or not. 164 * @param code Operation code. 165 * @return If the given operation is supported by the device or not. 166 */ isOperationSupported(int code)167 public boolean isOperationSupported(int code) { 168 return isSupported(mOperationsSupported, code); 169 } 170 171 /** 172 * Returns if the given event is supported by the device or not. 173 * @param code Event code. 174 * @return If the given event is supported by the device or not. 175 */ isEventSupported(int code)176 public boolean isEventSupported(int code) { 177 return isSupported(mEventsSupported, code); 178 } 179 180 /** 181 * Returns if the given Device property is supported by the device or not. 182 * @param code Device property code. 183 * @return If the given Device property is supported by the device or not. 184 * 185 * {@hide} 186 */ isDevicePropertySupported(int code)187 public boolean isDevicePropertySupported(int code) { 188 return isSupported(mDevicePropertySupported, code); 189 } 190 191 /** 192 * Returns if the code set contains code. 193 * @hide 194 */ isSupported(@onNull int[] set, int code)195 private static boolean isSupported(@NonNull int[] set, int code) { 196 for (final int element : set) { 197 if (element == code) { 198 return true; 199 } 200 } 201 return false; 202 } 203 } 204