| Siarhei Vishniakou | a47a4d4 | 2019-05-06 17:14:11 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2019 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 | #include "InputClassifierConverter.h" | 
|  | 18 |  | 
|  | 19 | using android::hardware::hidl_bitfield; | 
|  | 20 | using namespace android::hardware::input; | 
|  | 21 |  | 
|  | 22 | namespace android { | 
|  | 23 |  | 
|  | 24 | static common::V1_0::Source getSource(uint32_t source) { | 
|  | 25 | static_assert(static_cast<common::V1_0::Source>(AINPUT_SOURCE_UNKNOWN) == | 
|  | 26 | common::V1_0::Source::UNKNOWN, "SOURCE_UNKNOWN mismatch"); | 
|  | 27 | static_assert(static_cast<common::V1_0::Source>(AINPUT_SOURCE_KEYBOARD) == | 
|  | 28 | common::V1_0::Source::KEYBOARD, "SOURCE_KEYBOARD mismatch"); | 
|  | 29 | static_assert(static_cast<common::V1_0::Source>(AINPUT_SOURCE_DPAD) == | 
|  | 30 | common::V1_0::Source::DPAD, "SOURCE_DPAD mismatch"); | 
|  | 31 | static_assert(static_cast<common::V1_0::Source>(AINPUT_SOURCE_GAMEPAD) == | 
|  | 32 | common::V1_0::Source::GAMEPAD, "SOURCE_GAMEPAD mismatch"); | 
|  | 33 | static_assert(static_cast<common::V1_0::Source>(AINPUT_SOURCE_TOUCHSCREEN) == | 
|  | 34 | common::V1_0::Source::TOUCHSCREEN, "SOURCE_TOUCHSCREEN mismatch"); | 
|  | 35 | static_assert(static_cast<common::V1_0::Source>(AINPUT_SOURCE_MOUSE) == | 
|  | 36 | common::V1_0::Source::MOUSE, "SOURCE_MOUSE mismatch"); | 
|  | 37 | static_assert(static_cast<common::V1_0::Source>(AINPUT_SOURCE_STYLUS) == | 
|  | 38 | common::V1_0::Source::STYLUS, "SOURCE_STYLUS mismatch"); | 
|  | 39 | static_assert(static_cast<common::V1_0::Source>(AINPUT_SOURCE_BLUETOOTH_STYLUS) == | 
|  | 40 | common::V1_0::Source::BLUETOOTH_STYLUS, "SOURCE_BLUETOOTH_STYLUS mismatch"); | 
|  | 41 | static_assert(static_cast<common::V1_0::Source>(AINPUT_SOURCE_TRACKBALL) == | 
|  | 42 | common::V1_0::Source::TRACKBALL, "SOURCE_TRACKBALL mismatch"); | 
|  | 43 | static_assert(static_cast<common::V1_0::Source>(AINPUT_SOURCE_MOUSE_RELATIVE) == | 
|  | 44 | common::V1_0::Source::MOUSE_RELATIVE, "SOURCE_MOUSE_RELATIVE mismatch"); | 
|  | 45 | static_assert(static_cast<common::V1_0::Source>(AINPUT_SOURCE_TOUCHPAD) == | 
|  | 46 | common::V1_0::Source::TOUCHPAD, "SOURCE_TOUCHPAD mismatch"); | 
|  | 47 | static_assert(static_cast<common::V1_0::Source>(AINPUT_SOURCE_TOUCH_NAVIGATION) == | 
|  | 48 | common::V1_0::Source::TOUCH_NAVIGATION, "SOURCE_TOUCH_NAVIGATION mismatch"); | 
|  | 49 | static_assert(static_cast<common::V1_0::Source>(AINPUT_SOURCE_JOYSTICK) == | 
|  | 50 | common::V1_0::Source::JOYSTICK, "SOURCE_JOYSTICK mismatch"); | 
|  | 51 | static_assert(static_cast<common::V1_0::Source>(AINPUT_SOURCE_ROTARY_ENCODER) == | 
|  | 52 | common::V1_0::Source::ROTARY_ENCODER, "SOURCE_ROTARY_ENCODER mismatch"); | 
|  | 53 | static_assert(static_cast<common::V1_0::Source>(AINPUT_SOURCE_ANY) == | 
|  | 54 | common::V1_0::Source::ANY, "SOURCE_ANY mismatch"); | 
|  | 55 | return static_cast<common::V1_0::Source>(source); | 
|  | 56 | } | 
|  | 57 |  | 
|  | 58 | static common::V1_0::Action getAction(int32_t actionMasked) { | 
|  | 59 | static_assert(static_cast<common::V1_0::Action>(AMOTION_EVENT_ACTION_DOWN) == | 
|  | 60 | common::V1_0::Action::DOWN, "ACTION_DOWN mismatch"); | 
|  | 61 | static_assert(static_cast<common::V1_0::Action>(AMOTION_EVENT_ACTION_UP) == | 
|  | 62 | common::V1_0::Action::UP, "ACTION_UP mismatch"); | 
|  | 63 | static_assert(static_cast<common::V1_0::Action>(AMOTION_EVENT_ACTION_MOVE) == | 
|  | 64 | common::V1_0::Action::MOVE, "ACTION_MOVE mismatch"); | 
|  | 65 | static_assert(static_cast<common::V1_0::Action>(AMOTION_EVENT_ACTION_CANCEL) == | 
|  | 66 | common::V1_0::Action::CANCEL, "ACTION_CANCEL mismatch"); | 
|  | 67 | static_assert(static_cast<common::V1_0::Action>(AMOTION_EVENT_ACTION_OUTSIDE) == | 
|  | 68 | common::V1_0::Action::OUTSIDE, "ACTION_OUTSIDE mismatch"); | 
|  | 69 | static_assert(static_cast<common::V1_0::Action>(AMOTION_EVENT_ACTION_POINTER_DOWN) == | 
|  | 70 | common::V1_0::Action::POINTER_DOWN, "ACTION_POINTER_DOWN mismatch"); | 
|  | 71 | static_assert(static_cast<common::V1_0::Action>(AMOTION_EVENT_ACTION_POINTER_UP) == | 
|  | 72 | common::V1_0::Action::POINTER_UP, "ACTION_POINTER_UP mismatch"); | 
|  | 73 | static_assert(static_cast<common::V1_0::Action>( AMOTION_EVENT_ACTION_HOVER_MOVE) == | 
|  | 74 | common::V1_0::Action::HOVER_MOVE, "ACTION_HOVER_MOVE mismatch"); | 
|  | 75 | static_assert(static_cast<common::V1_0::Action>(AMOTION_EVENT_ACTION_SCROLL) == | 
|  | 76 | common::V1_0::Action::SCROLL, "ACTION_SCROLL mismatch"); | 
|  | 77 | static_assert(static_cast<common::V1_0::Action>(AMOTION_EVENT_ACTION_HOVER_ENTER) == | 
|  | 78 | common::V1_0::Action::HOVER_ENTER, "ACTION_HOVER_ENTER mismatch"); | 
|  | 79 | static_assert(static_cast<common::V1_0::Action>(AMOTION_EVENT_ACTION_HOVER_EXIT) == | 
|  | 80 | common::V1_0::Action::HOVER_EXIT, "ACTION_HOVER_EXIT mismatch"); | 
|  | 81 | static_assert(static_cast<common::V1_0::Action>(AMOTION_EVENT_ACTION_BUTTON_PRESS) == | 
|  | 82 | common::V1_0::Action::BUTTON_PRESS, "ACTION_BUTTON_PRESS mismatch"); | 
|  | 83 | static_assert(static_cast<common::V1_0::Action>(AMOTION_EVENT_ACTION_BUTTON_RELEASE) == | 
|  | 84 | common::V1_0::Action::BUTTON_RELEASE, "ACTION_BUTTON_RELEASE mismatch"); | 
|  | 85 | return static_cast<common::V1_0::Action>(actionMasked); | 
|  | 86 | } | 
|  | 87 |  | 
|  | 88 | static common::V1_0::Button getActionButton(int32_t actionButton) { | 
|  | 89 | static_assert(static_cast<common::V1_0::Button>(0) == | 
|  | 90 | common::V1_0::Button::NONE, "BUTTON_NONE mismatch"); | 
|  | 91 | static_assert(static_cast<common::V1_0::Button>(AMOTION_EVENT_BUTTON_PRIMARY) == | 
|  | 92 | common::V1_0::Button::PRIMARY, "BUTTON_PRIMARY mismatch"); | 
|  | 93 | static_assert(static_cast<common::V1_0::Button>(AMOTION_EVENT_BUTTON_SECONDARY) == | 
|  | 94 | common::V1_0::Button::SECONDARY, "BUTTON_SECONDARY mismatch"); | 
|  | 95 | static_assert(static_cast<common::V1_0::Button>(AMOTION_EVENT_BUTTON_TERTIARY) == | 
|  | 96 | common::V1_0::Button::TERTIARY, "BUTTON_TERTIARY mismatch"); | 
|  | 97 | static_assert(static_cast<common::V1_0::Button>(AMOTION_EVENT_BUTTON_BACK) == | 
|  | 98 | common::V1_0::Button::BACK, "BUTTON_BACK mismatch"); | 
|  | 99 | static_assert(static_cast<common::V1_0::Button>(AMOTION_EVENT_BUTTON_FORWARD) == | 
|  | 100 | common::V1_0::Button::FORWARD, "BUTTON_FORWARD mismatch"); | 
|  | 101 | static_assert(static_cast<common::V1_0::Button>(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY) == | 
|  | 102 | common::V1_0::Button::STYLUS_PRIMARY, "BUTTON_STYLUS_PRIMARY mismatch"); | 
|  | 103 | static_assert(static_cast<common::V1_0::Button>(AMOTION_EVENT_BUTTON_STYLUS_SECONDARY) == | 
|  | 104 | common::V1_0::Button::STYLUS_SECONDARY, "BUTTON_STYLUS_SECONDARY mismatch"); | 
|  | 105 | return static_cast<common::V1_0::Button>(actionButton); | 
|  | 106 | } | 
|  | 107 |  | 
|  | 108 | static hidl_bitfield<common::V1_0::Flag> getFlags(int32_t flags) { | 
|  | 109 | static_assert(static_cast<common::V1_0::Flag>(AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED) == | 
|  | 110 | common::V1_0::Flag::WINDOW_IS_OBSCURED); | 
|  | 111 | static_assert(static_cast<common::V1_0::Flag>(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE) == | 
|  | 112 | common::V1_0::Flag::IS_GENERATED_GESTURE); | 
|  | 113 | static_assert(static_cast<common::V1_0::Flag>(AMOTION_EVENT_FLAG_TAINTED) == | 
|  | 114 | common::V1_0::Flag::TAINTED); | 
|  | 115 | return static_cast<hidl_bitfield<common::V1_0::Flag>>(flags); | 
|  | 116 | } | 
|  | 117 |  | 
|  | 118 | static hidl_bitfield<common::V1_0::PolicyFlag> getPolicyFlags(int32_t flags) { | 
|  | 119 | static_assert(static_cast<common::V1_0::PolicyFlag>(POLICY_FLAG_WAKE) == | 
|  | 120 | common::V1_0::PolicyFlag::WAKE); | 
|  | 121 | static_assert(static_cast<common::V1_0::PolicyFlag>(POLICY_FLAG_VIRTUAL) == | 
|  | 122 | common::V1_0::PolicyFlag::VIRTUAL); | 
|  | 123 | static_assert(static_cast<common::V1_0::PolicyFlag>(POLICY_FLAG_FUNCTION) == | 
|  | 124 | common::V1_0::PolicyFlag::FUNCTION); | 
|  | 125 | static_assert(static_cast<common::V1_0::PolicyFlag>(POLICY_FLAG_GESTURE) == | 
|  | 126 | common::V1_0::PolicyFlag::GESTURE); | 
|  | 127 | static_assert(static_cast<common::V1_0::PolicyFlag>(POLICY_FLAG_INJECTED) == | 
|  | 128 | common::V1_0::PolicyFlag::INJECTED); | 
|  | 129 | static_assert(static_cast<common::V1_0::PolicyFlag>(POLICY_FLAG_TRUSTED) == | 
|  | 130 | common::V1_0::PolicyFlag::TRUSTED); | 
|  | 131 | static_assert(static_cast<common::V1_0::PolicyFlag>(POLICY_FLAG_FILTERED) == | 
|  | 132 | common::V1_0::PolicyFlag::FILTERED); | 
|  | 133 | static_assert(static_cast<common::V1_0::PolicyFlag>(POLICY_FLAG_DISABLE_KEY_REPEAT) == | 
|  | 134 | common::V1_0::PolicyFlag::DISABLE_KEY_REPEAT); | 
|  | 135 | static_assert(static_cast<common::V1_0::PolicyFlag>(POLICY_FLAG_INTERACTIVE) == | 
|  | 136 | common::V1_0::PolicyFlag::INTERACTIVE); | 
|  | 137 | static_assert(static_cast<common::V1_0::PolicyFlag>(POLICY_FLAG_PASS_TO_USER) == | 
|  | 138 | common::V1_0::PolicyFlag::PASS_TO_USER); | 
|  | 139 | return static_cast<hidl_bitfield<common::V1_0::PolicyFlag>>(flags); | 
|  | 140 | } | 
|  | 141 |  | 
|  | 142 | static hidl_bitfield<common::V1_0::EdgeFlag> getEdgeFlags(int32_t flags) { | 
|  | 143 | static_assert(static_cast<common::V1_0::EdgeFlag>(AMOTION_EVENT_EDGE_FLAG_NONE) == | 
|  | 144 | common::V1_0::EdgeFlag::NONE); | 
|  | 145 | static_assert(static_cast<common::V1_0::EdgeFlag>(AMOTION_EVENT_EDGE_FLAG_TOP) == | 
|  | 146 | common::V1_0::EdgeFlag::TOP); | 
|  | 147 | static_assert(static_cast<common::V1_0::EdgeFlag>(AMOTION_EVENT_EDGE_FLAG_BOTTOM) == | 
|  | 148 | common::V1_0::EdgeFlag::BOTTOM); | 
|  | 149 | static_assert(static_cast<common::V1_0::EdgeFlag>(AMOTION_EVENT_EDGE_FLAG_LEFT) == | 
|  | 150 | common::V1_0::EdgeFlag::LEFT); | 
|  | 151 | static_assert(static_cast<common::V1_0::EdgeFlag>(AMOTION_EVENT_EDGE_FLAG_RIGHT) == | 
|  | 152 | common::V1_0::EdgeFlag::RIGHT); | 
|  | 153 | return static_cast<hidl_bitfield<common::V1_0::EdgeFlag>>(flags); | 
|  | 154 | } | 
|  | 155 |  | 
|  | 156 | static hidl_bitfield<common::V1_0::Meta> getMetastate(int32_t state) { | 
|  | 157 | static_assert(static_cast<common::V1_0::Meta>(AMETA_NONE) == | 
|  | 158 | common::V1_0::Meta::NONE); | 
|  | 159 | static_assert(static_cast<common::V1_0::Meta>(AMETA_ALT_ON) == | 
|  | 160 | common::V1_0::Meta::ALT_ON); | 
|  | 161 | static_assert(static_cast<common::V1_0::Meta>(AMETA_ALT_LEFT_ON) == | 
|  | 162 | common::V1_0::Meta::ALT_LEFT_ON); | 
|  | 163 | static_assert(static_cast<common::V1_0::Meta>(AMETA_ALT_RIGHT_ON) == | 
|  | 164 | common::V1_0::Meta::ALT_RIGHT_ON); | 
|  | 165 | static_assert(static_cast<common::V1_0::Meta>(AMETA_SHIFT_ON) == | 
|  | 166 | common::V1_0::Meta::SHIFT_ON); | 
|  | 167 | static_assert(static_cast<common::V1_0::Meta>(AMETA_SHIFT_LEFT_ON) == | 
|  | 168 | common::V1_0::Meta::SHIFT_LEFT_ON); | 
|  | 169 | static_assert(static_cast<common::V1_0::Meta>(AMETA_SHIFT_RIGHT_ON) == | 
|  | 170 | common::V1_0::Meta::SHIFT_RIGHT_ON); | 
|  | 171 | static_assert(static_cast<common::V1_0::Meta>(AMETA_SYM_ON) == | 
|  | 172 | common::V1_0::Meta::SYM_ON); | 
|  | 173 | static_assert(static_cast<common::V1_0::Meta>(AMETA_FUNCTION_ON) == | 
|  | 174 | common::V1_0::Meta::FUNCTION_ON); | 
|  | 175 | static_assert(static_cast<common::V1_0::Meta>(AMETA_CTRL_ON) == | 
|  | 176 | common::V1_0::Meta::CTRL_ON); | 
|  | 177 | static_assert(static_cast<common::V1_0::Meta>(AMETA_CTRL_LEFT_ON) == | 
|  | 178 | common::V1_0::Meta::CTRL_LEFT_ON); | 
|  | 179 | static_assert(static_cast<common::V1_0::Meta>(AMETA_CTRL_RIGHT_ON) == | 
|  | 180 | common::V1_0::Meta::CTRL_RIGHT_ON); | 
|  | 181 | static_assert(static_cast<common::V1_0::Meta>(AMETA_META_ON) == | 
|  | 182 | common::V1_0::Meta::META_ON); | 
|  | 183 | static_assert(static_cast<common::V1_0::Meta>(AMETA_META_LEFT_ON) == | 
|  | 184 | common::V1_0::Meta::META_LEFT_ON); | 
|  | 185 | static_assert(static_cast<common::V1_0::Meta>(AMETA_META_RIGHT_ON) == | 
|  | 186 | common::V1_0::Meta::META_RIGHT_ON); | 
|  | 187 | static_assert(static_cast<common::V1_0::Meta>(AMETA_CAPS_LOCK_ON) == | 
|  | 188 | common::V1_0::Meta::CAPS_LOCK_ON); | 
|  | 189 | static_assert(static_cast<common::V1_0::Meta>(AMETA_NUM_LOCK_ON) == | 
|  | 190 | common::V1_0::Meta::NUM_LOCK_ON); | 
|  | 191 | static_assert(static_cast<common::V1_0::Meta>(AMETA_SCROLL_LOCK_ON) == | 
|  | 192 | common::V1_0::Meta::SCROLL_LOCK_ON); | 
|  | 193 | return static_cast<hidl_bitfield<common::V1_0::Meta>>(state); | 
|  | 194 | } | 
|  | 195 |  | 
|  | 196 | static hidl_bitfield<common::V1_0::Button> getButtonState(int32_t buttonState) { | 
|  | 197 | // No need for static_assert here. | 
|  | 198 | // The button values have already been asserted in getActionButton(..) above | 
|  | 199 | return static_cast<hidl_bitfield<common::V1_0::Button>>(buttonState); | 
|  | 200 | } | 
|  | 201 |  | 
|  | 202 | static common::V1_0::ToolType getToolType(int32_t toolType) { | 
|  | 203 | static_assert(static_cast<common::V1_0::ToolType>(AMOTION_EVENT_TOOL_TYPE_UNKNOWN) == | 
|  | 204 | common::V1_0::ToolType::UNKNOWN); | 
|  | 205 | static_assert(static_cast<common::V1_0::ToolType>(AMOTION_EVENT_TOOL_TYPE_FINGER) == | 
|  | 206 | common::V1_0::ToolType::FINGER); | 
|  | 207 | static_assert(static_cast<common::V1_0::ToolType>(AMOTION_EVENT_TOOL_TYPE_STYLUS) == | 
|  | 208 | common::V1_0::ToolType::STYLUS); | 
|  | 209 | static_assert(static_cast<common::V1_0::ToolType>(AMOTION_EVENT_TOOL_TYPE_MOUSE) == | 
|  | 210 | common::V1_0::ToolType::MOUSE); | 
|  | 211 | static_assert(static_cast<common::V1_0::ToolType>(AMOTION_EVENT_TOOL_TYPE_ERASER) == | 
|  | 212 | common::V1_0::ToolType::ERASER); | 
|  | 213 | return static_cast<common::V1_0::ToolType>(toolType); | 
|  | 214 | } | 
|  | 215 |  | 
|  | 216 | // MotionEvent axes asserts | 
|  | 217 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_X) == | 
|  | 218 | common::V1_0::Axis::X); | 
|  | 219 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_Y) == | 
|  | 220 | common::V1_0::Axis::Y); | 
|  | 221 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_PRESSURE) == | 
|  | 222 | common::V1_0::Axis::PRESSURE); | 
|  | 223 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_SIZE) == | 
|  | 224 | common::V1_0::Axis::SIZE); | 
|  | 225 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_TOUCH_MAJOR) == | 
|  | 226 | common::V1_0::Axis::TOUCH_MAJOR); | 
|  | 227 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_TOUCH_MINOR) == | 
|  | 228 | common::V1_0::Axis::TOUCH_MINOR); | 
|  | 229 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_TOOL_MAJOR) == | 
|  | 230 | common::V1_0::Axis::TOOL_MAJOR); | 
|  | 231 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_TOOL_MINOR) == | 
|  | 232 | common::V1_0::Axis::TOOL_MINOR); | 
|  | 233 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_ORIENTATION) == | 
|  | 234 | common::V1_0::Axis::ORIENTATION); | 
|  | 235 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_VSCROLL) == | 
|  | 236 | common::V1_0::Axis::VSCROLL); | 
|  | 237 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_HSCROLL) == | 
|  | 238 | common::V1_0::Axis::HSCROLL); | 
|  | 239 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_Z) == | 
|  | 240 | common::V1_0::Axis::Z); | 
|  | 241 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_RX) == | 
|  | 242 | common::V1_0::Axis::RX); | 
|  | 243 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_RY) == | 
|  | 244 | common::V1_0::Axis::RY); | 
|  | 245 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_RZ) == | 
|  | 246 | common::V1_0::Axis::RZ); | 
|  | 247 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_HAT_X) == | 
|  | 248 | common::V1_0::Axis::HAT_X); | 
|  | 249 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_HAT_Y) == | 
|  | 250 | common::V1_0::Axis::HAT_Y); | 
|  | 251 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_LTRIGGER) == | 
|  | 252 | common::V1_0::Axis::LTRIGGER); | 
|  | 253 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_RTRIGGER) == | 
|  | 254 | common::V1_0::Axis::RTRIGGER); | 
|  | 255 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_THROTTLE) == | 
|  | 256 | common::V1_0::Axis::THROTTLE); | 
|  | 257 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_RUDDER) == | 
|  | 258 | common::V1_0::Axis::RUDDER); | 
|  | 259 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_WHEEL) == | 
|  | 260 | common::V1_0::Axis::WHEEL); | 
|  | 261 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_GAS) == | 
|  | 262 | common::V1_0::Axis::GAS); | 
|  | 263 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_BRAKE) == | 
|  | 264 | common::V1_0::Axis::BRAKE); | 
|  | 265 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_DISTANCE) == | 
|  | 266 | common::V1_0::Axis::DISTANCE); | 
|  | 267 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_TILT) == | 
|  | 268 | common::V1_0::Axis::TILT); | 
|  | 269 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_SCROLL) == | 
|  | 270 | common::V1_0::Axis::SCROLL); | 
|  | 271 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_RELATIVE_X) == | 
|  | 272 | common::V1_0::Axis::RELATIVE_X); | 
|  | 273 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_RELATIVE_Y) == | 
|  | 274 | common::V1_0::Axis::RELATIVE_Y); | 
|  | 275 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_GENERIC_1) == | 
|  | 276 | common::V1_0::Axis::GENERIC_1); | 
|  | 277 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_GENERIC_2) == | 
|  | 278 | common::V1_0::Axis::GENERIC_2); | 
|  | 279 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_GENERIC_3) == | 
|  | 280 | common::V1_0::Axis::GENERIC_3); | 
|  | 281 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_GENERIC_4) == | 
|  | 282 | common::V1_0::Axis::GENERIC_4); | 
|  | 283 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_GENERIC_5) == | 
|  | 284 | common::V1_0::Axis::GENERIC_5); | 
|  | 285 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_GENERIC_6) == | 
|  | 286 | common::V1_0::Axis::GENERIC_6); | 
|  | 287 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_GENERIC_7) == | 
|  | 288 | common::V1_0::Axis::GENERIC_7); | 
|  | 289 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_GENERIC_8) == | 
|  | 290 | common::V1_0::Axis::GENERIC_8); | 
|  | 291 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_GENERIC_9) == | 
|  | 292 | common::V1_0::Axis::GENERIC_9); | 
|  | 293 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_GENERIC_10) == | 
|  | 294 | common::V1_0::Axis::GENERIC_10); | 
|  | 295 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_GENERIC_11) == | 
|  | 296 | common::V1_0::Axis::GENERIC_11); | 
|  | 297 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_GENERIC_12) == | 
|  | 298 | common::V1_0::Axis::GENERIC_12); | 
|  | 299 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_GENERIC_13) == | 
|  | 300 | common::V1_0::Axis::GENERIC_13); | 
|  | 301 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_GENERIC_14) == | 
|  | 302 | common::V1_0::Axis::GENERIC_14); | 
|  | 303 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_GENERIC_15) == | 
|  | 304 | common::V1_0::Axis::GENERIC_15); | 
|  | 305 | static_assert(static_cast<common::V1_0::Axis>(AMOTION_EVENT_AXIS_GENERIC_16) == | 
|  | 306 | common::V1_0::Axis::GENERIC_16); | 
|  | 307 |  | 
|  | 308 | static common::V1_0::VideoFrame getHalVideoFrame(const TouchVideoFrame& frame) { | 
|  | 309 | common::V1_0::VideoFrame out; | 
|  | 310 | out.width = frame.getWidth(); | 
|  | 311 | out.height = frame.getHeight(); | 
|  | 312 | out.data = frame.getData(); | 
|  | 313 | struct timeval timestamp = frame.getTimestamp(); | 
|  | 314 | out.timestamp = seconds_to_nanoseconds(timestamp.tv_sec) + | 
|  | 315 | microseconds_to_nanoseconds(timestamp.tv_usec); | 
|  | 316 | return out; | 
|  | 317 | } | 
|  | 318 |  | 
|  | 319 | static std::vector<common::V1_0::VideoFrame> convertVideoFrames( | 
|  | 320 | const std::vector<TouchVideoFrame>& frames) { | 
|  | 321 | std::vector<common::V1_0::VideoFrame> out; | 
|  | 322 | for (const TouchVideoFrame& frame : frames) { | 
|  | 323 | out.push_back(getHalVideoFrame(frame)); | 
|  | 324 | } | 
|  | 325 | return out; | 
|  | 326 | } | 
|  | 327 |  | 
|  | 328 | static uint8_t getActionIndex(int32_t action) { | 
|  | 329 | return (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> | 
|  | 330 | AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; | 
|  | 331 | } | 
|  | 332 |  | 
|  | 333 | static void getHidlPropertiesAndCoords(const NotifyMotionArgs& args, | 
|  | 334 | std::vector<common::V1_0::PointerProperties>* outPointerProperties, | 
|  | 335 | std::vector<common::V1_0::PointerCoords>* outPointerCoords) { | 
|  | 336 | outPointerProperties->reserve(args.pointerCount); | 
|  | 337 | outPointerCoords->reserve(args.pointerCount); | 
|  | 338 | for (size_t i = 0; i < args.pointerCount; i++) { | 
|  | 339 | common::V1_0::PointerProperties properties; | 
|  | 340 | properties.id = args.pointerProperties[i].id; | 
|  | 341 | properties.toolType = getToolType(args.pointerProperties[i].toolType); | 
|  | 342 | outPointerProperties->push_back(properties); | 
|  | 343 |  | 
|  | 344 | common::V1_0::PointerCoords coords; | 
|  | 345 | // OK to copy bits because we have static_assert for pointerCoords axes | 
|  | 346 | coords.bits = args.pointerCoords[i].bits; | 
|  | 347 | coords.values = std::vector<float>( | 
|  | 348 | args.pointerCoords[i].values, | 
|  | 349 | args.pointerCoords[i].values + BitSet64::count(args.pointerCoords[i].bits)); | 
|  | 350 | outPointerCoords->push_back(coords); | 
|  | 351 | } | 
|  | 352 | } | 
|  | 353 |  | 
|  | 354 | common::V1_0::MotionEvent notifyMotionArgsToHalMotionEvent(const NotifyMotionArgs& args) { | 
|  | 355 | common::V1_0::MotionEvent event; | 
|  | 356 | event.deviceId = args.deviceId; | 
|  | 357 | event.source = getSource(args.source); | 
|  | 358 | event.displayId = args.displayId; | 
|  | 359 | event.downTime = args.downTime; | 
|  | 360 | event.eventTime = args.eventTime; | 
| Atif Niyaz | 21da0ff | 2019-06-28 13:22:51 -0700 | [diff] [blame] | 361 | event.deviceTimestamp = 0; | 
| Siarhei Vishniakou | a47a4d4 | 2019-05-06 17:14:11 -0700 | [diff] [blame] | 362 | event.action = getAction(args.action & AMOTION_EVENT_ACTION_MASK); | 
|  | 363 | event.actionIndex = getActionIndex(args.action); | 
|  | 364 | event.actionButton = getActionButton(args.actionButton); | 
|  | 365 | event.flags = getFlags(args.flags); | 
|  | 366 | event.policyFlags = getPolicyFlags(args.policyFlags); | 
|  | 367 | event.edgeFlags = getEdgeFlags(args.edgeFlags); | 
|  | 368 | event.metaState = getMetastate(args.metaState); | 
|  | 369 | event.buttonState = getButtonState(args.buttonState); | 
|  | 370 | event.xPrecision = args.xPrecision; | 
|  | 371 | event.yPrecision = args.yPrecision; | 
|  | 372 |  | 
|  | 373 | std::vector<common::V1_0::PointerProperties> pointerProperties; | 
|  | 374 | std::vector<common::V1_0::PointerCoords> pointerCoords; | 
|  | 375 | getHidlPropertiesAndCoords(args, /*out*/&pointerProperties, /*out*/&pointerCoords); | 
|  | 376 | event.pointerProperties = pointerProperties; | 
|  | 377 | event.pointerCoords = pointerCoords; | 
|  | 378 |  | 
| Siarhei Vishniakou | a47a4d4 | 2019-05-06 17:14:11 -0700 | [diff] [blame] | 379 | event.frames = convertVideoFrames(args.videoFrames); | 
|  | 380 |  | 
|  | 381 | return event; | 
|  | 382 | } | 
|  | 383 |  | 
|  | 384 | } // namespace android |