blob: 0304ee386ace4f00c6490dd6c86f0425204e7dfb [file] [log] [blame]
Mike Lockwood8182e722010-12-30 15:38:45 -05001/*
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
17package android.mtp;
18
Daichi Hirono0639fe02016-07-07 17:36:26 +090019import android.annotation.NonNull;
20
Mike Lockwood8182e722010-12-30 15:38:45 -050021/**
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 Lockwood8182e722010-12-30 15:38:45 -050025 */
26public class MtpDeviceInfo {
27
28 private String mManufacturer;
29 private String mModel;
30 private String mVersion;
31 private String mSerialNumber;
Daichi Hirono1d4779c2016-01-06 16:43:32 +090032 private int[] mOperationsSupported;
Daichi Hirono148954a2016-01-21 19:55:45 +090033 private int[] mEventsSupported;
Mike Lockwood8182e722010-12-30 15:38:45 -050034
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 Hirono0639fe02016-07-07 17:36:26 +090044 public final @NonNull String getManufacturer() {
Mike Lockwood8182e722010-12-30 15:38:45 -050045 return mManufacturer;
46 }
47
48 /**
49 * Returns the model name for the MTP device
50 *
51 * @return the model name
52 */
Daichi Hirono0639fe02016-07-07 17:36:26 +090053 public final @NonNull String getModel() {
Mike Lockwood8182e722010-12-30 15:38:45 -050054 return mModel;
55 }
56
57 /**
58 * Returns the version string the MTP device
59 *
60 * @return the device version
61 */
Daichi Hirono0639fe02016-07-07 17:36:26 +090062 public final @NonNull String getVersion() {
Mike Lockwood8182e722010-12-30 15:38:45 -050063 return mVersion;
64 }
65
66 /**
67 * Returns the unique serial number for the MTP device
68 *
69 * @return the serial number
70 */
Daichi Hirono0639fe02016-07-07 17:36:26 +090071 public final @NonNull String getSerialNumber() {
Mike Lockwood8182e722010-12-30 15:38:45 -050072 return mSerialNumber;
73 }
Daichi Hirono1d4779c2016-01-06 16:43:32 +090074
75 /**
76 * Returns operation code supported by the device.
77 *
Daichi Hirono148954a2016-01-21 19:55:45 +090078 * @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 Hirono1d4779c2016-01-06 16:43:32 +0900114 */
Daichi Hirono0639fe02016-07-07 17:36:26 +0900115 public final @NonNull int[] getOperationsSupported() {
Daichi Hirono1d4779c2016-01-06 16:43:32 +0900116 return mOperationsSupported;
117 }
Daichi Hirono148954a2016-01-21 19:55:45 +0900118
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 Hirono399df702016-04-13 11:07:44 +0900123 * @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 Hirono148954a2016-01-21 19:55:45 +0900141 */
Daichi Hirono0639fe02016-07-07 17:36:26 +0900142 public final @NonNull int[] getEventsSupported() {
Daichi Hirono148954a2016-01-21 19:55:45 +0900143 return mEventsSupported;
144 }
Daichi Hirono399df702016-04-13 11:07:44 +0900145
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 Hirono0639fe02016-07-07 17:36:26 +0900168 private static boolean isSupported(@NonNull int[] set, int code) {
Daichi Hirono399df702016-04-13 11:07:44 +0900169 for (final int element : set) {
170 if (element == code) {
171 return true;
172 }
173 }
174 return false;
175 }
Daichi Hirono1d4779c2016-01-06 16:43:32 +0900176}