| /* | |
| * Copyright 2023 The Android Open Source Project | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, | |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| * See the License for the specific language governing permissions and | |
| * limitations under the License. | |
| */ | |
| #pragma once | |
| #include "NotifyArgs.h" | |
| #include <input/InputDeviceUsageSource.h> | |
| #include <linux/input.h> | |
| #include <statslog_inputflinger.h> | |
| #include <set> | |
| #include <vector> | |
| namespace android { | |
| #define ASSERT_ENUM_EQUAL(name) \ | |
| static_assert(static_cast<int32_t>(InputDeviceUsageSource::name) == \ | |
| inputflinger::stats::INPUT_DEVICE_USAGE_REPORTED__USAGE_SOURCES__##name) | |
| ASSERT_ENUM_EQUAL(UNKNOWN); | |
| ASSERT_ENUM_EQUAL(BUTTONS); | |
| ASSERT_ENUM_EQUAL(KEYBOARD); | |
| ASSERT_ENUM_EQUAL(DPAD); | |
| ASSERT_ENUM_EQUAL(GAMEPAD); | |
| ASSERT_ENUM_EQUAL(JOYSTICK); | |
| ASSERT_ENUM_EQUAL(MOUSE); | |
| ASSERT_ENUM_EQUAL(MOUSE_CAPTURED); | |
| ASSERT_ENUM_EQUAL(TOUCHPAD); | |
| ASSERT_ENUM_EQUAL(TOUCHPAD_CAPTURED); | |
| ASSERT_ENUM_EQUAL(ROTARY_ENCODER); | |
| ASSERT_ENUM_EQUAL(STYLUS_DIRECT); | |
| ASSERT_ENUM_EQUAL(STYLUS_INDIRECT); | |
| ASSERT_ENUM_EQUAL(STYLUS_FUSED); | |
| ASSERT_ENUM_EQUAL(TOUCH_NAVIGATION); | |
| ASSERT_ENUM_EQUAL(TOUCHSCREEN); | |
| ASSERT_ENUM_EQUAL(TRACKBALL); | |
| #undef ASSERT_ENUM_EQUAL | |
| /** Returns the InputDeviceUsageSource that corresponds to the key event. */ | |
| inline InputDeviceUsageSource getUsageSourceForKeyArgs(int32_t keyboardType, | |
| const NotifyKeyArgs& keyArgs) { | |
| return getUsageSourceForKey(keyArgs.source, keyArgs.keyCode, keyboardType); | |
| } | |
| /** Returns the InputDeviceUsageSources that correspond to the key event. */ | |
| inline std::set<InputDeviceUsageSource> getUsageSourcesForKeyArgs( | |
| const NotifyKeyArgs& args, const std::vector<InputDeviceInfo>& inputDevices) { | |
| int32_t keyboardType = AINPUT_KEYBOARD_TYPE_NONE; | |
| for (const InputDeviceInfo& inputDevice : inputDevices) { | |
| if (args.deviceId == inputDevice.getId()) { | |
| keyboardType = inputDevice.getKeyboardType(); | |
| break; | |
| } | |
| } | |
| return std::set{getUsageSourceForKeyArgs(keyboardType, args)}; | |
| } | |
| /** Returns the InputDeviceUsageSources that correspond to the motion event. */ | |
| inline std::set<InputDeviceUsageSource> getUsageSourcesForMotionArgs( | |
| const NotifyMotionArgs& motionArgs) { | |
| std::set<InputDeviceUsageSource> sources; | |
| for (uint32_t i = 0; i < motionArgs.getPointerCount(); i++) { | |
| sources.emplace(getUsageSourceForMotion(motionArgs.source, | |
| motionArgs.pointerProperties[i].toolType)); | |
| } | |
| return sources; | |
| } | |
| } // namespace android |