blob: dc89a56cf0b31122772301fe81a80988f57df44d [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 Hironocf62fdc2016-01-06 14:55:47 +090024 private int mEventCode = MtpConstants.EVENT_UNDEFINED;
Daichi Hirono0b494662015-09-10 20:38:15 +090025
Daichi Hirono2a9a4332016-01-11 13:33:41 +090026 // Parameters for event. The interpretation of event parameters depends upon mEventCode.
27 private int mParameter1;
28 private int mParameter2;
29 private int mParameter3;
30
Daichi Hirono0b494662015-09-10 20:38:15 +090031 /**
32 * Returns event code of MTP event.
Daichi Hirono85f70782015-10-07 08:12:33 -070033 * See the USB-IF MTP specification for the details of event constants.
Daichi Hirono0b494662015-09-10 20:38:15 +090034 * @return event code
35 */
36 public int getEventCode() { return mEventCode; }
Daichi Hirono2a9a4332016-01-11 13:33:41 +090037
38 /**
39 * Obtains the first event parameter.
40 */
41 public int getParameter1() { return mParameter1; }
42
43 /**
44 * Obtains the second event parameter.
45 */
46 public int getParameter2() { return mParameter2; }
47
48 /**
49 * Obtains the third event parameter.
50 */
51 public int getParameter3() { return mParameter3; }
52
53 /**
54 * Obtains objectHandle event parameter.
55 *
56 * @see MtpConstants#EVENT_OBJECT_ADDED
57 * @see MtpConstants#EVENT_OBJECT_REMOVED
58 * @see MtpConstants#EVENT_OBJECT_INFO_CHANGED
59 * @see MtpConstants#EVENT_REQUEST_OBJECT_TRANSFER
60 * @see MtpConstants#EVENT_OBJECT_PROP_CHANGED
61 * @see MtpConstants#EVENT_OBJECT_REFERENCES_CHANGED
62 */
63 public int getObjectHandle() {
64 switch (mEventCode) {
65 case MtpConstants.EVENT_OBJECT_ADDED:
66 return mParameter1;
67 case MtpConstants.EVENT_OBJECT_REMOVED:
68 return mParameter1;
69 case MtpConstants.EVENT_OBJECT_INFO_CHANGED:
70 return mParameter1;
71 case MtpConstants.EVENT_REQUEST_OBJECT_TRANSFER:
72 return mParameter1;
73 case MtpConstants.EVENT_OBJECT_PROP_CHANGED:
74 return mParameter1;
75 case MtpConstants.EVENT_OBJECT_REFERENCES_CHANGED:
76 return mParameter1;
77 default:
78 throw new IllegalParameterAccess("objectHandle", mEventCode);
79 }
80 }
81
82 /**
83 * Obtains storageID event parameter.
84 *
85 * @see MtpConstants#EVENT_STORE_ADDED
86 * @see MtpConstants#EVENT_STORE_REMOVED
87 * @see MtpConstants#EVENT_STORE_FULL
88 * @see MtpConstants#EVENT_STORAGE_INFO_CHANGED
89 */
90 public int getStorageId() {
91 switch (mEventCode) {
92 case MtpConstants.EVENT_STORE_ADDED:
93 return mParameter1;
94 case MtpConstants.EVENT_STORE_REMOVED:
95 return mParameter1;
96 case MtpConstants.EVENT_STORE_FULL:
97 return mParameter1;
98 case MtpConstants.EVENT_STORAGE_INFO_CHANGED:
99 return mParameter1;
100 default:
101 throw new IllegalParameterAccess("storageID", mEventCode);
102 }
103 }
104
105 /**
106 * Obtains devicePropCode event parameter.
107 *
108 * @see MtpConstants#EVENT_DEVICE_PROP_CHANGED
109 */
110 public int getDevicePropCode() {
111 switch (mEventCode) {
112 case MtpConstants.EVENT_DEVICE_PROP_CHANGED:
113 return mParameter1;
114 default:
115 throw new IllegalParameterAccess("devicePropCode", mEventCode);
116 }
117 }
118
119 /**
120 * Obtains transactionID event parameter.
121 *
122 * @see MtpConstants#EVENT_CAPTURE_COMPLETE
123 */
124 public int getTransactionId() {
125 switch (mEventCode) {
126 case MtpConstants.EVENT_CAPTURE_COMPLETE:
127 return mParameter1;
128 default:
129 throw new IllegalParameterAccess("transactionID", mEventCode);
130 }
131 }
132
133 /**
134 * Obtains objectPropCode event parameter.
135 *
136 * @see MtpConstants#EVENT_OBJECT_PROP_CHANGED
137 * @see MtpConstants#EVENT_OBJECT_PROP_DESC_CHANGED
138 */
139 public int getObjectPropCode() {
140 switch (mEventCode) {
141 case MtpConstants.EVENT_OBJECT_PROP_CHANGED:
142 return mParameter2;
143 case MtpConstants.EVENT_OBJECT_PROP_DESC_CHANGED:
144 return mParameter1;
145 default:
146 throw new IllegalParameterAccess("objectPropCode", mEventCode);
147 }
148 }
149
150 /**
151 * Obtains objectFormatCode event parameter.
152 *
153 * @see MtpConstants#EVENT_OBJECT_PROP_DESC_CHANGED
154 */
155 public int getObjectFormatCode() {
156 switch (mEventCode) {
157 case MtpConstants.EVENT_OBJECT_PROP_DESC_CHANGED:
158 return mParameter2;
159 default:
160 throw new IllegalParameterAccess("objectFormatCode", mEventCode);
161 }
162 }
163
164 private static class IllegalParameterAccess extends UnsupportedOperationException {
165 public IllegalParameterAccess(String propertyName, int eventCode) {
166 super("Cannot obtain " + propertyName + " for the event: " + eventCode + ".");
167 }
168 }
Daichi Hirono0b494662015-09-10 20:38:15 +0900169}