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 35 // only instantiated via JNI MtpDeviceInfo()36 private MtpDeviceInfo() { 37 } 38 39 /** 40 * Returns the manufacturer's name for the MTP device 41 * 42 * @return the manufacturer name 43 */ getManufacturer()44 public final @NonNull String getManufacturer() { 45 return mManufacturer; 46 } 47 48 /** 49 * Returns the model name for the MTP device 50 * 51 * @return the model name 52 */ getModel()53 public final @NonNull String getModel() { 54 return mModel; 55 } 56 57 /** 58 * Returns the version string the MTP device 59 * 60 * @return the device version 61 */ getVersion()62 public final @NonNull String getVersion() { 63 return mVersion; 64 } 65 66 /** 67 * Returns the unique serial number for the MTP device 68 * 69 * @return the serial number 70 */ getSerialNumber()71 public final @NonNull String getSerialNumber() { 72 return mSerialNumber; 73 } 74 75 /** 76 * Returns operation code supported by the device. 77 * 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 114 */ getOperationsSupported()115 public final @NonNull int[] getOperationsSupported() { 116 return mOperationsSupported; 117 } 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. 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 141 */ getEventsSupported()142 public final @NonNull int[] getEventsSupported() { 143 return mEventsSupported; 144 } 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 */ isOperationSupported(int code)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 */ isEventSupported(int code)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 */ isSupported(@onNull int[] set, int code)168 private static boolean isSupported(@NonNull int[] set, int code) { 169 for (final int element : set) { 170 if (element == code) { 171 return true; 172 } 173 } 174 return false; 175 } 176 } 177