| 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 | cf62fdc | 2016-01-06 14:55:47 +0900 | [diff] [blame] | 24 | private int mEventCode = MtpConstants.EVENT_UNDEFINED; |
| Daichi Hirono | 0b49466 | 2015-09-10 20:38:15 +0900 | [diff] [blame] | 25 | |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame^] | 26 | // 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 Hirono | 0b49466 | 2015-09-10 20:38:15 +0900 | [diff] [blame] | 31 | /** |
| 32 | * Returns event code of MTP event. |
| Daichi Hirono | 85f7078 | 2015-10-07 08:12:33 -0700 | [diff] [blame] | 33 | * See the USB-IF MTP specification for the details of event constants. |
| Daichi Hirono | 0b49466 | 2015-09-10 20:38:15 +0900 | [diff] [blame] | 34 | * @return event code |
| 35 | */ |
| 36 | public int getEventCode() { return mEventCode; } |
| Daichi Hirono | 2a9a433 | 2016-01-11 13:33:41 +0900 | [diff] [blame^] | 37 | |
| 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 Hirono | 0b49466 | 2015-09-10 20:38:15 +0900 | [diff] [blame] | 169 | } |