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