| Daichi Hirono | 0b49466 | 2015-09-10 20:38:15 +0900 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.mtp; |
| 18 | |
| 19 | /** |
| 20 | * This class encapsulates information about a MTP event. |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 21 | * This corresponds to the events described in appendix G of the MTP specification. |
| Daichi Hirono | 0b49466 | 2015-09-10 20:38:15 +0900 | [diff] [blame] | 22 | */ |
| 23 | public class MtpEvent { |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 24 | /** 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 Hirono | 0b49466 | 2015-09-10 20:38:15 +0900 | [diff] [blame] | 62 | |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 63 | // 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 Hirono | 0b49466 | 2015-09-10 20:38:15 +0900 | [diff] [blame] | 68 | /** |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 69 | * MtpEvent is instantiated by JNI. |
| 70 | */ |
| 71 | private MtpEvent() {} |
| 72 | |
| 73 | /** |
| Daichi Hirono | 0b49466 | 2015-09-10 20:38:15 +0900 | [diff] [blame] | 74 | * Returns event code of MTP event. |
| Daichi Hirono | 85f7078 | 2015-10-07 08:12:33 -0700 | [diff] [blame] | 75 | * See the USB-IF MTP specification for the details of event constants. |
| Daichi Hirono | 0b49466 | 2015-09-10 20:38:15 +0900 | [diff] [blame] | 76 | * @return event code |
| 77 | */ |
| 78 | public int getEventCode() { return mEventCode; } |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 79 | |
| 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 Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 98 | * @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 Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 104 | */ |
| 105 | public int getObjectHandle() { |
| 106 | switch (mEventCode) { |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 107 | case EVENT_OBJECT_ADDED: |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 108 | return mParameter1; |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 109 | case EVENT_OBJECT_REMOVED: |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 110 | return mParameter1; |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 111 | case EVENT_OBJECT_INFO_CHANGED: |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 112 | return mParameter1; |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 113 | case EVENT_REQUEST_OBJECT_TRANSFER: |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 114 | return mParameter1; |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 115 | case EVENT_OBJECT_PROP_CHANGED: |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 116 | return mParameter1; |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 117 | case EVENT_OBJECT_REFERENCES_CHANGED: |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 118 | return mParameter1; |
| 119 | default: |
| 120 | throw new IllegalParameterAccess("objectHandle", mEventCode); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Obtains storageID event parameter. |
| 126 | * |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 127 | * @see #EVENT_STORE_ADDED |
| 128 | * @see #EVENT_STORE_REMOVED |
| 129 | * @see #EVENT_STORE_FULL |
| 130 | * @see #EVENT_STORAGE_INFO_CHANGED |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 131 | */ |
| 132 | public int getStorageId() { |
| 133 | switch (mEventCode) { |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 134 | case EVENT_STORE_ADDED: |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 135 | return mParameter1; |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 136 | case EVENT_STORE_REMOVED: |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 137 | return mParameter1; |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 138 | case EVENT_STORE_FULL: |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 139 | return mParameter1; |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 140 | case EVENT_STORAGE_INFO_CHANGED: |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 141 | return mParameter1; |
| 142 | default: |
| 143 | throw new IllegalParameterAccess("storageID", mEventCode); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Obtains devicePropCode event parameter. |
| 149 | * |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 150 | * @see #EVENT_DEVICE_PROP_CHANGED |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 151 | */ |
| 152 | public int getDevicePropCode() { |
| 153 | switch (mEventCode) { |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 154 | case EVENT_DEVICE_PROP_CHANGED: |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 155 | return mParameter1; |
| 156 | default: |
| 157 | throw new IllegalParameterAccess("devicePropCode", mEventCode); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Obtains transactionID event parameter. |
| 163 | * |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 164 | * @see #EVENT_CAPTURE_COMPLETE |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 165 | */ |
| 166 | public int getTransactionId() { |
| 167 | switch (mEventCode) { |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 168 | case EVENT_CAPTURE_COMPLETE: |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 169 | return mParameter1; |
| 170 | default: |
| 171 | throw new IllegalParameterAccess("transactionID", mEventCode); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Obtains objectPropCode event parameter. |
| 177 | * |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 178 | * @see #EVENT_OBJECT_PROP_CHANGED |
| 179 | * @see #EVENT_OBJECT_PROP_DESC_CHANGED |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 180 | */ |
| 181 | public int getObjectPropCode() { |
| 182 | switch (mEventCode) { |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 183 | case EVENT_OBJECT_PROP_CHANGED: |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 184 | return mParameter2; |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 185 | case EVENT_OBJECT_PROP_DESC_CHANGED: |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 186 | return mParameter1; |
| 187 | default: |
| 188 | throw new IllegalParameterAccess("objectPropCode", mEventCode); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Obtains objectFormatCode event parameter. |
| 194 | * |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 195 | * @see #EVENT_OBJECT_PROP_DESC_CHANGED |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 196 | */ |
| 197 | public int getObjectFormatCode() { |
| 198 | switch (mEventCode) { |
| Daichi Hirono | 399df70 | 2016-04-13 11:07:44 +0900 | [diff] [blame] | 199 | case EVENT_OBJECT_PROP_DESC_CHANGED: |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame] | 200 | 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 Hirono | 0b49466 | 2015-09-10 20:38:15 +0900 | [diff] [blame] | 211 | } |