blob: 9ca00e1956cb40b8d84e4fff1084871d07931cb3 [file] [log] [blame]
Daichi Hirono0b494662015-09-10 20:38:15 +09001/*
2 * Copyright (C) 2015 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
19/**
20 * This class encapsulates information about a MTP event.
Daichi Hirono2a9a4332016-01-11 13:33:41 +090021 * This corresponds to the events described in appendix G of the MTP specification.
Daichi Hirono0b494662015-09-10 20:38:15 +090022 */
23public class MtpEvent {
Daichi Hirono399df702016-04-13 11:07:44 +090024 /** Event code for UNDEFINED event */
25 public static final int EVENT_UNDEFINED = 0x4000;
26 /** Event code for CANCEL_TRANSACTION event */
27 public static final int EVENT_CANCEL_TRANSACTION = 0x4001;
28 /** Event code for OBJECT_ADDED event */
29 public static final int EVENT_OBJECT_ADDED = 0x4002;
30 /** Event code for OBJECT_REMOVED event */
31 public static final int EVENT_OBJECT_REMOVED = 0x4003;
32 /** Event code for STORE_ADDED event */
33 public static final int EVENT_STORE_ADDED = 0x4004;
34 /** Event code for STORE_REMOVED event */
35 public static final int EVENT_STORE_REMOVED = 0x4005;
36 /** Event code for DEVICE_PROP_CHANGED event */
37 public static final int EVENT_DEVICE_PROP_CHANGED = 0x4006;
38 /** Event code for OBJECT_INFO_CHANGED event */
39 public static final int EVENT_OBJECT_INFO_CHANGED = 0x4007;
40 /** Event code for DEVICE_INFO_CHANGED event */
41 public static final int EVENT_DEVICE_INFO_CHANGED = 0x4008;
42 /** Event code for REQUEST_OBJECT_TRANSFER event */
43 public static final int EVENT_REQUEST_OBJECT_TRANSFER = 0x4009;
44 /** Event code for STORE_FULL event */
45 public static final int EVENT_STORE_FULL = 0x400A;
46 /** Event code for DEVICE_RESET event */
47 public static final int EVENT_DEVICE_RESET = 0x400B;
48 /** Event code for STORAGE_INFO_CHANGED event */
49 public static final int EVENT_STORAGE_INFO_CHANGED = 0x400C;
50 /** Event code for CAPTURE_COMPLETE event */
51 public static final int EVENT_CAPTURE_COMPLETE = 0x400D;
52 /** Event code for UNREPORTED_STATUS event */
53 public static final int EVENT_UNREPORTED_STATUS = 0x400E;
54 /** Event code for OBJECT_PROP_CHANGED event */
55 public static final int EVENT_OBJECT_PROP_CHANGED = 0xC801;
56 /** Event code for OBJECT_PROP_DESC_CHANGED event */
57 public static final int EVENT_OBJECT_PROP_DESC_CHANGED = 0xC802;
58 /** Event code for OBJECT_REFERENCES_CHANGED event */
59 public static final int EVENT_OBJECT_REFERENCES_CHANGED = 0xC803;
60
61 private int mEventCode = EVENT_UNDEFINED;
Daichi Hirono0b494662015-09-10 20:38:15 +090062
Daichi Hirono2a9a4332016-01-11 13:33:41 +090063 // Parameters for event. The interpretation of event parameters depends upon mEventCode.
64 private int mParameter1;
65 private int mParameter2;
66 private int mParameter3;
67
Daichi Hirono0b494662015-09-10 20:38:15 +090068 /**
Daichi Hirono399df702016-04-13 11:07:44 +090069 * MtpEvent is instantiated by JNI.
70 */
71 private MtpEvent() {}
72
73 /**
Daichi Hirono0b494662015-09-10 20:38:15 +090074 * Returns event code of MTP event.
Daichi Hirono85f70782015-10-07 08:12:33 -070075 * See the USB-IF MTP specification for the details of event constants.
Daichi Hirono0b494662015-09-10 20:38:15 +090076 * @return event code
77 */
78 public int getEventCode() { return mEventCode; }
Daichi Hirono2a9a4332016-01-11 13:33:41 +090079
80 /**
81 * Obtains the first event parameter.
82 */
83 public int getParameter1() { return mParameter1; }
84
85 /**
86 * Obtains the second event parameter.
87 */
88 public int getParameter2() { return mParameter2; }
89
90 /**
91 * Obtains the third event parameter.
92 */
93 public int getParameter3() { return mParameter3; }
94
95 /**
96 * Obtains objectHandle event parameter.
97 *
Daichi Hirono399df702016-04-13 11:07:44 +090098 * @see #EVENT_OBJECT_ADDED
99 * @see #EVENT_OBJECT_REMOVED
100 * @see #EVENT_OBJECT_INFO_CHANGED
101 * @see #EVENT_REQUEST_OBJECT_TRANSFER
102 * @see #EVENT_OBJECT_PROP_CHANGED
103 * @see #EVENT_OBJECT_REFERENCES_CHANGED
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900104 */
105 public int getObjectHandle() {
106 switch (mEventCode) {
Daichi Hirono399df702016-04-13 11:07:44 +0900107 case EVENT_OBJECT_ADDED:
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900108 return mParameter1;
Daichi Hirono399df702016-04-13 11:07:44 +0900109 case EVENT_OBJECT_REMOVED:
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900110 return mParameter1;
Daichi Hirono399df702016-04-13 11:07:44 +0900111 case EVENT_OBJECT_INFO_CHANGED:
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900112 return mParameter1;
Daichi Hirono399df702016-04-13 11:07:44 +0900113 case EVENT_REQUEST_OBJECT_TRANSFER:
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900114 return mParameter1;
Daichi Hirono399df702016-04-13 11:07:44 +0900115 case EVENT_OBJECT_PROP_CHANGED:
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900116 return mParameter1;
Daichi Hirono399df702016-04-13 11:07:44 +0900117 case EVENT_OBJECT_REFERENCES_CHANGED:
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900118 return mParameter1;
119 default:
120 throw new IllegalParameterAccess("objectHandle", mEventCode);
121 }
122 }
123
124 /**
125 * Obtains storageID event parameter.
126 *
Daichi Hirono399df702016-04-13 11:07:44 +0900127 * @see #EVENT_STORE_ADDED
128 * @see #EVENT_STORE_REMOVED
129 * @see #EVENT_STORE_FULL
130 * @see #EVENT_STORAGE_INFO_CHANGED
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900131 */
132 public int getStorageId() {
133 switch (mEventCode) {
Daichi Hirono399df702016-04-13 11:07:44 +0900134 case EVENT_STORE_ADDED:
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900135 return mParameter1;
Daichi Hirono399df702016-04-13 11:07:44 +0900136 case EVENT_STORE_REMOVED:
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900137 return mParameter1;
Daichi Hirono399df702016-04-13 11:07:44 +0900138 case EVENT_STORE_FULL:
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900139 return mParameter1;
Daichi Hirono399df702016-04-13 11:07:44 +0900140 case EVENT_STORAGE_INFO_CHANGED:
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900141 return mParameter1;
142 default:
143 throw new IllegalParameterAccess("storageID", mEventCode);
144 }
145 }
146
147 /**
148 * Obtains devicePropCode event parameter.
149 *
Daichi Hirono399df702016-04-13 11:07:44 +0900150 * @see #EVENT_DEVICE_PROP_CHANGED
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900151 */
152 public int getDevicePropCode() {
153 switch (mEventCode) {
Daichi Hirono399df702016-04-13 11:07:44 +0900154 case EVENT_DEVICE_PROP_CHANGED:
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900155 return mParameter1;
156 default:
157 throw new IllegalParameterAccess("devicePropCode", mEventCode);
158 }
159 }
160
161 /**
162 * Obtains transactionID event parameter.
163 *
Daichi Hirono399df702016-04-13 11:07:44 +0900164 * @see #EVENT_CAPTURE_COMPLETE
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900165 */
166 public int getTransactionId() {
167 switch (mEventCode) {
Daichi Hirono399df702016-04-13 11:07:44 +0900168 case EVENT_CAPTURE_COMPLETE:
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900169 return mParameter1;
170 default:
171 throw new IllegalParameterAccess("transactionID", mEventCode);
172 }
173 }
174
175 /**
176 * Obtains objectPropCode event parameter.
177 *
Daichi Hirono399df702016-04-13 11:07:44 +0900178 * @see #EVENT_OBJECT_PROP_CHANGED
179 * @see #EVENT_OBJECT_PROP_DESC_CHANGED
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900180 */
181 public int getObjectPropCode() {
182 switch (mEventCode) {
Daichi Hirono399df702016-04-13 11:07:44 +0900183 case EVENT_OBJECT_PROP_CHANGED:
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900184 return mParameter2;
Daichi Hirono399df702016-04-13 11:07:44 +0900185 case EVENT_OBJECT_PROP_DESC_CHANGED:
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900186 return mParameter1;
187 default:
188 throw new IllegalParameterAccess("objectPropCode", mEventCode);
189 }
190 }
191
192 /**
193 * Obtains objectFormatCode event parameter.
194 *
Daichi Hirono399df702016-04-13 11:07:44 +0900195 * @see #EVENT_OBJECT_PROP_DESC_CHANGED
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900196 */
197 public int getObjectFormatCode() {
198 switch (mEventCode) {
Daichi Hirono399df702016-04-13 11:07:44 +0900199 case EVENT_OBJECT_PROP_DESC_CHANGED:
Daichi Hirono2a9a4332016-01-11 13:33:41 +0900200 return mParameter2;
201 default:
202 throw new IllegalParameterAccess("objectFormatCode", mEventCode);
203 }
204 }
205
206 private static class IllegalParameterAccess extends UnsupportedOperationException {
207 public IllegalParameterAccess(String propertyName, int eventCode) {
208 super("Cannot obtain " + propertyName + " for the event: " + eventCode + ".");
209 }
210 }
Daichi Hirono0b494662015-09-10 20:38:15 +0900211}