Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2023 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 | #pragma once |
| 18 | |
Harry Cutts | cf62d96 | 2023-08-30 15:48:05 +0000 | [diff] [blame] | 19 | #include <cstdint> |
| 20 | #include <list> |
| 21 | #include <memory> |
| 22 | #include <optional> |
| 23 | #include <string> |
| 24 | #include <unordered_map> |
| 25 | #include <utility> |
| 26 | #include <vector> |
| 27 | |
| 28 | #include <EventHub.h> |
| 29 | #include <InputReaderBase.h> |
Arpit Singh | bd49b28 | 2024-05-23 18:02:54 +0000 | [diff] [blame^] | 30 | #include <InputReaderContext.h> |
Harry Cutts | cf62d96 | 2023-08-30 15:48:05 +0000 | [diff] [blame] | 31 | #include <NotifyArgs.h> |
Arpit Singh | bd49b28 | 2024-05-23 18:02:54 +0000 | [diff] [blame^] | 32 | #include <PointerChoreographerPolicyInterface.h> |
Harry Cutts | cf62d96 | 2023-08-30 15:48:05 +0000 | [diff] [blame] | 33 | #include <StylusState.h> |
| 34 | #include <VibrationElement.h> |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 35 | #include <android-base/logging.h> |
Harry Cutts | cf62d96 | 2023-08-30 15:48:05 +0000 | [diff] [blame] | 36 | #include <android-base/result.h> |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 37 | #include <gmock/gmock.h> |
Harry Cutts | cf62d96 | 2023-08-30 15:48:05 +0000 | [diff] [blame] | 38 | #include <input/InputDevice.h> |
| 39 | #include <input/KeyCharacterMap.h> |
| 40 | #include <input/KeyLayoutMap.h> |
| 41 | #include <input/PropertyMap.h> |
| 42 | #include <input/TouchVideoFrame.h> |
| 43 | #include <input/VirtualKeyMap.h> |
| 44 | #include <utils/Errors.h> |
| 45 | #include <utils/Timers.h> |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 46 | |
| 47 | namespace android { |
| 48 | |
| 49 | class MockInputReaderContext : public InputReaderContext { |
| 50 | public: |
| 51 | MOCK_METHOD(void, updateGlobalMetaState, (), (override)); |
Harry Cutts | 7ecbb99 | 2023-12-18 14:45:09 +0000 | [diff] [blame] | 52 | MOCK_METHOD(int32_t, getGlobalMetaState, (), (override)); |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 53 | |
| 54 | MOCK_METHOD(void, disableVirtualKeysUntil, (nsecs_t time), (override)); |
| 55 | MOCK_METHOD(bool, shouldDropVirtualKey, (nsecs_t now, int32_t keyCode, int32_t scanCode), |
| 56 | (override)); |
| 57 | |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 58 | MOCK_METHOD(void, requestTimeoutAtTime, (nsecs_t when), (override)); |
Siarhei Vishniakou | 5197ce6 | 2023-09-19 08:27:05 -0700 | [diff] [blame] | 59 | int32_t bumpGeneration() override { return ++mGeneration; } |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 60 | |
| 61 | MOCK_METHOD(void, getExternalStylusDevices, (std::vector<InputDeviceInfo> & outDevices), |
| 62 | (override)); |
| 63 | MOCK_METHOD(std::list<NotifyArgs>, dispatchExternalStylusState, (const StylusState& outState), |
| 64 | (override)); |
| 65 | |
| 66 | MOCK_METHOD(InputReaderPolicyInterface*, getPolicy, (), (override)); |
| 67 | MOCK_METHOD(EventHubInterface*, getEventHub, (), (override)); |
| 68 | |
| 69 | int32_t getNextId() override { return 1; }; |
| 70 | |
| 71 | MOCK_METHOD(void, updateLedMetaState, (int32_t metaState), (override)); |
| 72 | MOCK_METHOD(int32_t, getLedMetaState, (), (override)); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 73 | |
| 74 | MOCK_METHOD(void, setPreventingTouchpadTaps, (bool prevent), (override)); |
| 75 | MOCK_METHOD(bool, isPreventingTouchpadTaps, (), (override)); |
Siarhei Vishniakou | 5197ce6 | 2023-09-19 08:27:05 -0700 | [diff] [blame] | 76 | |
Arpit Singh | 82e413e | 2023-10-10 19:30:58 +0000 | [diff] [blame] | 77 | MOCK_METHOD(void, setLastKeyDownTimestamp, (nsecs_t when)); |
| 78 | MOCK_METHOD(nsecs_t, getLastKeyDownTimestamp, ()); |
| 79 | |
Siarhei Vishniakou | 5197ce6 | 2023-09-19 08:27:05 -0700 | [diff] [blame] | 80 | private: |
| 81 | int32_t mGeneration = 0; |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | class MockEventHubInterface : public EventHubInterface { |
| 85 | public: |
| 86 | MOCK_METHOD(ftl::Flags<InputDeviceClass>, getDeviceClasses, (int32_t deviceId), (const)); |
| 87 | MOCK_METHOD(InputDeviceIdentifier, getDeviceIdentifier, (int32_t deviceId), (const)); |
| 88 | MOCK_METHOD(int32_t, getDeviceControllerNumber, (int32_t deviceId), (const)); |
| 89 | MOCK_METHOD(std::optional<PropertyMap>, getConfiguration, (int32_t deviceId), (const)); |
| 90 | MOCK_METHOD(status_t, getAbsoluteAxisInfo, |
| 91 | (int32_t deviceId, int axis, RawAbsoluteAxisInfo* outAxisInfo), (const)); |
| 92 | MOCK_METHOD(bool, hasRelativeAxis, (int32_t deviceId, int axis), (const)); |
| 93 | MOCK_METHOD(bool, hasInputProperty, (int32_t deviceId, int property), (const)); |
| 94 | MOCK_METHOD(bool, hasMscEvent, (int32_t deviceId, int mscEvent), (const)); |
| 95 | MOCK_METHOD(void, addKeyRemapping, (int32_t deviceId, int fromKeyCode, int toKeyCode), (const)); |
| 96 | MOCK_METHOD(status_t, mapKey, |
| 97 | (int32_t deviceId, int scanCode, int usageCode, int32_t metaState, |
| 98 | int32_t* outKeycode, int32_t* outMetaState, uint32_t* outFlags), |
| 99 | (const)); |
| 100 | MOCK_METHOD(status_t, mapAxis, (int32_t deviceId, int scanCode, AxisInfo* outAxisInfo), |
| 101 | (const)); |
| 102 | MOCK_METHOD(void, setExcludedDevices, (const std::vector<std::string>& devices)); |
| 103 | MOCK_METHOD(std::vector<RawEvent>, getEvents, (int timeoutMillis)); |
| 104 | MOCK_METHOD(std::vector<TouchVideoFrame>, getVideoFrames, (int32_t deviceId)); |
| 105 | MOCK_METHOD((base::Result<std::pair<InputDeviceSensorType, int32_t>>), mapSensor, |
| 106 | (int32_t deviceId, int32_t absCode), (const, override)); |
| 107 | MOCK_METHOD(std::vector<int32_t>, getRawBatteryIds, (int32_t deviceId), (const, override)); |
| 108 | MOCK_METHOD(std::optional<RawBatteryInfo>, getRawBatteryInfo, |
| 109 | (int32_t deviceId, int32_t BatteryId), (const, override)); |
| 110 | MOCK_METHOD(std::vector<int32_t>, getRawLightIds, (int32_t deviceId), (const, override)); |
| 111 | MOCK_METHOD(std::optional<RawLightInfo>, getRawLightInfo, (int32_t deviceId, int32_t lightId), |
| 112 | (const, override)); |
| 113 | MOCK_METHOD(std::optional<int32_t>, getLightBrightness, (int32_t deviceId, int32_t lightId), |
| 114 | (const, override)); |
| 115 | MOCK_METHOD(void, setLightBrightness, (int32_t deviceId, int32_t lightId, int32_t brightness), |
| 116 | (override)); |
| 117 | MOCK_METHOD((std::optional<std::unordered_map<LightColor, int32_t>>), getLightIntensities, |
| 118 | (int32_t deviceId, int32_t lightId), (const, override)); |
| 119 | MOCK_METHOD(void, setLightIntensities, |
| 120 | (int32_t deviceId, int32_t lightId, |
| 121 | (std::unordered_map<LightColor, int32_t>)intensities), |
| 122 | (override)); |
| 123 | |
| 124 | MOCK_METHOD(std::optional<RawLayoutInfo>, getRawLayoutInfo, (int32_t deviceId), |
| 125 | (const, override)); |
| 126 | MOCK_METHOD(int32_t, getScanCodeState, (int32_t deviceId, int32_t scanCode), (const, override)); |
| 127 | MOCK_METHOD(int32_t, getKeyCodeState, (int32_t deviceId, int32_t keyCode), (const, override)); |
| 128 | MOCK_METHOD(int32_t, getSwitchState, (int32_t deviceId, int32_t sw), (const, override)); |
| 129 | |
| 130 | MOCK_METHOD(status_t, getAbsoluteAxisValue, (int32_t deviceId, int32_t axis, int32_t* outValue), |
| 131 | (const, override)); |
Arpit Singh | 4b4a457 | 2023-11-24 18:19:56 +0000 | [diff] [blame] | 132 | MOCK_METHOD(base::Result<std::vector<int32_t>>, getMtSlotValues, |
| 133 | (int32_t deviceId, int32_t axis, size_t slotCount), (const, override)); |
| 134 | |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 135 | MOCK_METHOD(int32_t, getKeyCodeForKeyLocation, (int32_t deviceId, int32_t locationKeyCode), |
| 136 | (const, override)); |
| 137 | MOCK_METHOD(bool, markSupportedKeyCodes, |
| 138 | (int32_t deviceId, const std::vector<int32_t>& keyCodes, uint8_t* outFlags), |
| 139 | (const, override)); |
| 140 | |
| 141 | MOCK_METHOD(bool, hasScanCode, (int32_t deviceId, int32_t scanCode), (const, override)); |
| 142 | |
| 143 | MOCK_METHOD(bool, hasKeyCode, (int32_t deviceId, int32_t keyCode), (const, override)); |
| 144 | |
| 145 | MOCK_METHOD(bool, hasLed, (int32_t deviceId, int32_t led), (const, override)); |
| 146 | |
| 147 | MOCK_METHOD(void, setLedState, (int32_t deviceId, int32_t led, bool on), (override)); |
| 148 | |
| 149 | MOCK_METHOD(void, getVirtualKeyDefinitions, |
| 150 | (int32_t deviceId, std::vector<VirtualKeyDefinition>& outVirtualKeys), |
| 151 | (const, override)); |
| 152 | |
| 153 | MOCK_METHOD(const std::shared_ptr<KeyCharacterMap>, getKeyCharacterMap, (int32_t deviceId), |
| 154 | (const, override)); |
| 155 | |
| 156 | MOCK_METHOD(bool, setKeyboardLayoutOverlay, |
| 157 | (int32_t deviceId, std::shared_ptr<KeyCharacterMap> map), (override)); |
| 158 | |
| 159 | MOCK_METHOD(void, vibrate, (int32_t deviceId, const VibrationElement& effect), (override)); |
| 160 | MOCK_METHOD(void, cancelVibrate, (int32_t deviceId), (override)); |
| 161 | |
| 162 | MOCK_METHOD(std::vector<int32_t>, getVibratorIds, (int32_t deviceId), (const, override)); |
| 163 | MOCK_METHOD(std::optional<int32_t>, getBatteryCapacity, (int32_t deviceId, int32_t batteryId), |
| 164 | (const, override)); |
| 165 | |
| 166 | MOCK_METHOD(std::optional<int32_t>, getBatteryStatus, (int32_t deviceId, int32_t batteryId), |
| 167 | (const, override)); |
| 168 | MOCK_METHOD(void, requestReopenDevices, (), (override)); |
| 169 | MOCK_METHOD(void, wake, (), (override)); |
| 170 | |
| 171 | MOCK_METHOD(void, dump, (std::string & dump), (const, override)); |
| 172 | MOCK_METHOD(void, monitor, (), (const, override)); |
| 173 | MOCK_METHOD(bool, isDeviceEnabled, (int32_t deviceId), (const, override)); |
| 174 | MOCK_METHOD(status_t, enableDevice, (int32_t deviceId), (override)); |
| 175 | MOCK_METHOD(status_t, disableDevice, (int32_t deviceId), (override)); |
| 176 | MOCK_METHOD(void, sysfsNodeChanged, (const std::string& sysfsNodePath), (override)); |
| 177 | }; |
| 178 | |
Arpit Singh | bd49b28 | 2024-05-23 18:02:54 +0000 | [diff] [blame^] | 179 | class MockPointerChoreographerPolicyInterface : public PointerChoreographerPolicyInterface { |
| 180 | public: |
| 181 | MOCK_METHOD(std::shared_ptr<PointerControllerInterface>, createPointerController, |
| 182 | (PointerControllerInterface::ControllerType), (override)); |
| 183 | MOCK_METHOD(void, notifyPointerDisplayIdChanged, |
| 184 | (ui::LogicalDisplayId displayId, const FloatPoint& position), (override)); |
| 185 | }; |
| 186 | |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 187 | } // namespace android |