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> |
Prabir Pradhan | 31d05c4 | 2024-07-24 21:19:08 +0000 | [diff] [blame] | 29 | #include <InputDevice.h> |
Harry Cutts | cf62d96 | 2023-08-30 15:48:05 +0000 | [diff] [blame] | 30 | #include <InputReaderBase.h> |
Arpit Singh | bd49b28 | 2024-05-23 18:02:54 +0000 | [diff] [blame] | 31 | #include <InputReaderContext.h> |
Harry Cutts | cf62d96 | 2023-08-30 15:48:05 +0000 | [diff] [blame] | 32 | #include <NotifyArgs.h> |
Arpit Singh | bd49b28 | 2024-05-23 18:02:54 +0000 | [diff] [blame] | 33 | #include <PointerChoreographerPolicyInterface.h> |
Harry Cutts | cf62d96 | 2023-08-30 15:48:05 +0000 | [diff] [blame] | 34 | #include <StylusState.h> |
| 35 | #include <VibrationElement.h> |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 36 | #include <android-base/logging.h> |
Harry Cutts | cf62d96 | 2023-08-30 15:48:05 +0000 | [diff] [blame] | 37 | #include <android-base/result.h> |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 38 | #include <gmock/gmock.h> |
Harry Cutts | cf62d96 | 2023-08-30 15:48:05 +0000 | [diff] [blame] | 39 | #include <input/InputDevice.h> |
| 40 | #include <input/KeyCharacterMap.h> |
| 41 | #include <input/KeyLayoutMap.h> |
Vaibhav Devmurari | e58ffb9 | 2024-05-22 17:38:25 +0000 | [diff] [blame] | 42 | #include <input/KeyboardClassifier.h> |
Harry Cutts | cf62d96 | 2023-08-30 15:48:05 +0000 | [diff] [blame] | 43 | #include <input/PropertyMap.h> |
| 44 | #include <input/TouchVideoFrame.h> |
| 45 | #include <input/VirtualKeyMap.h> |
| 46 | #include <utils/Errors.h> |
| 47 | #include <utils/Timers.h> |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 48 | |
| 49 | namespace android { |
| 50 | |
| 51 | class MockInputReaderContext : public InputReaderContext { |
| 52 | public: |
| 53 | MOCK_METHOD(void, updateGlobalMetaState, (), (override)); |
Harry Cutts | 7ecbb99 | 2023-12-18 14:45:09 +0000 | [diff] [blame] | 54 | MOCK_METHOD(int32_t, getGlobalMetaState, (), (override)); |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 55 | |
| 56 | MOCK_METHOD(void, disableVirtualKeysUntil, (nsecs_t time), (override)); |
| 57 | MOCK_METHOD(bool, shouldDropVirtualKey, (nsecs_t now, int32_t keyCode, int32_t scanCode), |
| 58 | (override)); |
| 59 | |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 60 | MOCK_METHOD(void, requestTimeoutAtTime, (nsecs_t when), (override)); |
Siarhei Vishniakou | 5197ce6 | 2023-09-19 08:27:05 -0700 | [diff] [blame] | 61 | int32_t bumpGeneration() override { return ++mGeneration; } |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 62 | |
Prabir Pradhan | 31d05c4 | 2024-07-24 21:19:08 +0000 | [diff] [blame] | 63 | MOCK_METHOD(void, getExternalStylusDevices, (std::vector<InputDeviceInfo>& outDevices), |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 64 | (override)); |
| 65 | MOCK_METHOD(std::list<NotifyArgs>, dispatchExternalStylusState, (const StylusState& outState), |
| 66 | (override)); |
| 67 | |
| 68 | MOCK_METHOD(InputReaderPolicyInterface*, getPolicy, (), (override)); |
| 69 | MOCK_METHOD(EventHubInterface*, getEventHub, (), (override)); |
| 70 | |
| 71 | int32_t getNextId() override { return 1; }; |
| 72 | |
| 73 | MOCK_METHOD(void, updateLedMetaState, (int32_t metaState), (override)); |
| 74 | MOCK_METHOD(int32_t, getLedMetaState, (), (override)); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 75 | |
| 76 | MOCK_METHOD(void, setPreventingTouchpadTaps, (bool prevent), (override)); |
| 77 | MOCK_METHOD(bool, isPreventingTouchpadTaps, (), (override)); |
Siarhei Vishniakou | 5197ce6 | 2023-09-19 08:27:05 -0700 | [diff] [blame] | 78 | |
Arpit Singh | 82e413e | 2023-10-10 19:30:58 +0000 | [diff] [blame] | 79 | MOCK_METHOD(void, setLastKeyDownTimestamp, (nsecs_t when)); |
| 80 | MOCK_METHOD(nsecs_t, getLastKeyDownTimestamp, ()); |
| 81 | |
Vaibhav Devmurari | e58ffb9 | 2024-05-22 17:38:25 +0000 | [diff] [blame] | 82 | KeyboardClassifier& getKeyboardClassifier() override { return *mClassifier; }; |
| 83 | |
Siarhei Vishniakou | 5197ce6 | 2023-09-19 08:27:05 -0700 | [diff] [blame] | 84 | private: |
| 85 | int32_t mGeneration = 0; |
Vaibhav Devmurari | e58ffb9 | 2024-05-22 17:38:25 +0000 | [diff] [blame] | 86 | std::unique_ptr<KeyboardClassifier> mClassifier = std::make_unique<KeyboardClassifier>(); |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | class MockEventHubInterface : public EventHubInterface { |
| 90 | public: |
| 91 | MOCK_METHOD(ftl::Flags<InputDeviceClass>, getDeviceClasses, (int32_t deviceId), (const)); |
| 92 | MOCK_METHOD(InputDeviceIdentifier, getDeviceIdentifier, (int32_t deviceId), (const)); |
| 93 | MOCK_METHOD(int32_t, getDeviceControllerNumber, (int32_t deviceId), (const)); |
| 94 | MOCK_METHOD(std::optional<PropertyMap>, getConfiguration, (int32_t deviceId), (const)); |
Harry Cutts | 207674d | 2024-06-06 18:53:41 +0000 | [diff] [blame] | 95 | MOCK_METHOD(std::optional<RawAbsoluteAxisInfo>, getAbsoluteAxisInfo, |
| 96 | (int32_t deviceId, int axis), (const)); |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 97 | MOCK_METHOD(bool, hasRelativeAxis, (int32_t deviceId, int axis), (const)); |
| 98 | MOCK_METHOD(bool, hasInputProperty, (int32_t deviceId, int property), (const)); |
| 99 | MOCK_METHOD(bool, hasMscEvent, (int32_t deviceId, int mscEvent), (const)); |
Linnan Li | e5657f2 | 2024-09-13 21:54:37 +0800 | [diff] [blame] | 100 | MOCK_METHOD(void, setKeyRemapping, |
| 101 | (int32_t deviceId, (const std::map<int32_t, int32_t>& keyRemapping)), (const)); |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 102 | MOCK_METHOD(status_t, mapKey, |
| 103 | (int32_t deviceId, int scanCode, int usageCode, int32_t metaState, |
| 104 | int32_t* outKeycode, int32_t* outMetaState, uint32_t* outFlags), |
| 105 | (const)); |
| 106 | MOCK_METHOD(status_t, mapAxis, (int32_t deviceId, int scanCode, AxisInfo* outAxisInfo), |
| 107 | (const)); |
| 108 | MOCK_METHOD(void, setExcludedDevices, (const std::vector<std::string>& devices)); |
| 109 | MOCK_METHOD(std::vector<RawEvent>, getEvents, (int timeoutMillis)); |
| 110 | MOCK_METHOD(std::vector<TouchVideoFrame>, getVideoFrames, (int32_t deviceId)); |
| 111 | MOCK_METHOD((base::Result<std::pair<InputDeviceSensorType, int32_t>>), mapSensor, |
| 112 | (int32_t deviceId, int32_t absCode), (const, override)); |
| 113 | MOCK_METHOD(std::vector<int32_t>, getRawBatteryIds, (int32_t deviceId), (const, override)); |
| 114 | MOCK_METHOD(std::optional<RawBatteryInfo>, getRawBatteryInfo, |
| 115 | (int32_t deviceId, int32_t BatteryId), (const, override)); |
| 116 | MOCK_METHOD(std::vector<int32_t>, getRawLightIds, (int32_t deviceId), (const, override)); |
| 117 | MOCK_METHOD(std::optional<RawLightInfo>, getRawLightInfo, (int32_t deviceId, int32_t lightId), |
| 118 | (const, override)); |
| 119 | MOCK_METHOD(std::optional<int32_t>, getLightBrightness, (int32_t deviceId, int32_t lightId), |
| 120 | (const, override)); |
| 121 | MOCK_METHOD(void, setLightBrightness, (int32_t deviceId, int32_t lightId, int32_t brightness), |
| 122 | (override)); |
| 123 | MOCK_METHOD((std::optional<std::unordered_map<LightColor, int32_t>>), getLightIntensities, |
| 124 | (int32_t deviceId, int32_t lightId), (const, override)); |
| 125 | MOCK_METHOD(void, setLightIntensities, |
| 126 | (int32_t deviceId, int32_t lightId, |
| 127 | (std::unordered_map<LightColor, int32_t>)intensities), |
| 128 | (override)); |
| 129 | |
| 130 | MOCK_METHOD(std::optional<RawLayoutInfo>, getRawLayoutInfo, (int32_t deviceId), |
| 131 | (const, override)); |
| 132 | MOCK_METHOD(int32_t, getScanCodeState, (int32_t deviceId, int32_t scanCode), (const, override)); |
| 133 | MOCK_METHOD(int32_t, getKeyCodeState, (int32_t deviceId, int32_t keyCode), (const, override)); |
| 134 | MOCK_METHOD(int32_t, getSwitchState, (int32_t deviceId, int32_t sw), (const, override)); |
| 135 | |
Harry Cutts | e2c5e20 | 2024-06-21 17:08:48 +0000 | [diff] [blame] | 136 | MOCK_METHOD(std::optional<int32_t>, getAbsoluteAxisValue, (int32_t deviceId, int32_t axis), |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 137 | (const, override)); |
Arpit Singh | 4b4a457 | 2023-11-24 18:19:56 +0000 | [diff] [blame] | 138 | MOCK_METHOD(base::Result<std::vector<int32_t>>, getMtSlotValues, |
| 139 | (int32_t deviceId, int32_t axis, size_t slotCount), (const, override)); |
| 140 | |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 141 | MOCK_METHOD(int32_t, getKeyCodeForKeyLocation, (int32_t deviceId, int32_t locationKeyCode), |
| 142 | (const, override)); |
| 143 | MOCK_METHOD(bool, markSupportedKeyCodes, |
| 144 | (int32_t deviceId, const std::vector<int32_t>& keyCodes, uint8_t* outFlags), |
| 145 | (const, override)); |
| 146 | |
| 147 | MOCK_METHOD(bool, hasScanCode, (int32_t deviceId, int32_t scanCode), (const, override)); |
| 148 | |
| 149 | MOCK_METHOD(bool, hasKeyCode, (int32_t deviceId, int32_t keyCode), (const, override)); |
| 150 | |
| 151 | MOCK_METHOD(bool, hasLed, (int32_t deviceId, int32_t led), (const, override)); |
| 152 | |
| 153 | MOCK_METHOD(void, setLedState, (int32_t deviceId, int32_t led, bool on), (override)); |
| 154 | |
| 155 | MOCK_METHOD(void, getVirtualKeyDefinitions, |
| 156 | (int32_t deviceId, std::vector<VirtualKeyDefinition>& outVirtualKeys), |
| 157 | (const, override)); |
| 158 | |
| 159 | MOCK_METHOD(const std::shared_ptr<KeyCharacterMap>, getKeyCharacterMap, (int32_t deviceId), |
| 160 | (const, override)); |
| 161 | |
| 162 | MOCK_METHOD(bool, setKeyboardLayoutOverlay, |
| 163 | (int32_t deviceId, std::shared_ptr<KeyCharacterMap> map), (override)); |
| 164 | |
| 165 | MOCK_METHOD(void, vibrate, (int32_t deviceId, const VibrationElement& effect), (override)); |
| 166 | MOCK_METHOD(void, cancelVibrate, (int32_t deviceId), (override)); |
| 167 | |
| 168 | MOCK_METHOD(std::vector<int32_t>, getVibratorIds, (int32_t deviceId), (const, override)); |
| 169 | MOCK_METHOD(std::optional<int32_t>, getBatteryCapacity, (int32_t deviceId, int32_t batteryId), |
| 170 | (const, override)); |
| 171 | |
| 172 | MOCK_METHOD(std::optional<int32_t>, getBatteryStatus, (int32_t deviceId, int32_t batteryId), |
| 173 | (const, override)); |
| 174 | MOCK_METHOD(void, requestReopenDevices, (), (override)); |
| 175 | MOCK_METHOD(void, wake, (), (override)); |
| 176 | |
Prabir Pradhan | 31d05c4 | 2024-07-24 21:19:08 +0000 | [diff] [blame] | 177 | MOCK_METHOD(void, dump, (std::string& dump), (const, override)); |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 178 | MOCK_METHOD(void, monitor, (), (const, override)); |
| 179 | MOCK_METHOD(bool, isDeviceEnabled, (int32_t deviceId), (const, override)); |
| 180 | MOCK_METHOD(status_t, enableDevice, (int32_t deviceId), (override)); |
| 181 | MOCK_METHOD(status_t, disableDevice, (int32_t deviceId), (override)); |
| 182 | MOCK_METHOD(void, sysfsNodeChanged, (const std::string& sysfsNodePath), (override)); |
Yanye Li | 81a590c | 2024-10-22 19:25:54 +0000 | [diff] [blame^] | 183 | MOCK_METHOD(bool, setKernelWakeEnabled, (int32_t deviceId, bool enabled), (override)); |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 184 | }; |
| 185 | |
Arpit Singh | bd49b28 | 2024-05-23 18:02:54 +0000 | [diff] [blame] | 186 | class MockPointerChoreographerPolicyInterface : public PointerChoreographerPolicyInterface { |
| 187 | public: |
| 188 | MOCK_METHOD(std::shared_ptr<PointerControllerInterface>, createPointerController, |
| 189 | (PointerControllerInterface::ControllerType), (override)); |
| 190 | MOCK_METHOD(void, notifyPointerDisplayIdChanged, |
| 191 | (ui::LogicalDisplayId displayId, const FloatPoint& position), (override)); |
Arpit Singh | b65e2bd | 2024-06-03 09:48:16 +0000 | [diff] [blame] | 192 | MOCK_METHOD(bool, isInputMethodConnectionActive, (), (override)); |
Arpit Singh | 849beb4 | 2024-06-06 07:14:17 +0000 | [diff] [blame] | 193 | MOCK_METHOD(void, notifyMouseCursorFadedOnTyping, (), (override)); |
Arpit Singh | bd49b28 | 2024-05-23 18:02:54 +0000 | [diff] [blame] | 194 | }; |
| 195 | |
Prabir Pradhan | 31d05c4 | 2024-07-24 21:19:08 +0000 | [diff] [blame] | 196 | class MockInputDevice : public InputDevice { |
| 197 | public: |
| 198 | MockInputDevice(InputReaderContext* context, int32_t id, int32_t generation, |
| 199 | const InputDeviceIdentifier& identifier) |
| 200 | : InputDevice(context, id, generation, identifier) {} |
| 201 | |
| 202 | MOCK_METHOD(uint32_t, getSources, (), (const, override)); |
Harry Cutts | 511ce6a | 2024-07-24 11:38:25 +0000 | [diff] [blame] | 203 | MOCK_METHOD(std::optional<DisplayViewport>, getAssociatedViewport, (), (const)); |
Prabir Pradhan | 31d05c4 | 2024-07-24 21:19:08 +0000 | [diff] [blame] | 204 | MOCK_METHOD(bool, isEnabled, (), ()); |
| 205 | |
| 206 | MOCK_METHOD(void, dump, (std::string& dump, const std::string& eventHubDevStr), ()); |
| 207 | MOCK_METHOD(void, addEmptyEventHubDevice, (int32_t eventHubId), ()); |
| 208 | MOCK_METHOD(std::list<NotifyArgs>, addEventHubDevice, |
| 209 | (nsecs_t when, int32_t eventHubId, const InputReaderConfiguration& readerConfig), |
| 210 | ()); |
| 211 | MOCK_METHOD(void, removeEventHubDevice, (int32_t eventHubId), ()); |
| 212 | MOCK_METHOD(std::list<NotifyArgs>, configure, |
| 213 | (nsecs_t when, const InputReaderConfiguration& readerConfig, |
| 214 | ConfigurationChanges changes), |
| 215 | ()); |
| 216 | MOCK_METHOD(std::list<NotifyArgs>, reset, (nsecs_t when), ()); |
| 217 | MOCK_METHOD(std::list<NotifyArgs>, process, (const RawEvent* rawEvents, size_t count), ()); |
| 218 | MOCK_METHOD(std::list<NotifyArgs>, timeoutExpired, (nsecs_t when), ()); |
| 219 | MOCK_METHOD(std::list<NotifyArgs>, updateExternalStylusState, (const StylusState& state), ()); |
| 220 | |
| 221 | MOCK_METHOD(InputDeviceInfo, getDeviceInfo, (), ()); |
| 222 | MOCK_METHOD(int32_t, getKeyCodeState, (uint32_t sourceMask, int32_t keyCode), ()); |
| 223 | MOCK_METHOD(int32_t, getScanCodeState, (uint32_t sourceMask, int32_t scanCode), ()); |
| 224 | MOCK_METHOD(int32_t, getSwitchState, (uint32_t sourceMask, int32_t switchCode), ()); |
| 225 | MOCK_METHOD(int32_t, getKeyCodeForKeyLocation, (int32_t locationKeyCode), (const)); |
| 226 | MOCK_METHOD(bool, markSupportedKeyCodes, |
| 227 | (uint32_t sourceMask, const std::vector<int32_t>& keyCodes, uint8_t* outFlags), ()); |
| 228 | MOCK_METHOD(std::list<NotifyArgs>, vibrate, |
| 229 | (const VibrationSequence& sequence, ssize_t repeat, int32_t token), ()); |
| 230 | MOCK_METHOD(std::list<NotifyArgs>, cancelVibrate, (int32_t token), ()); |
| 231 | MOCK_METHOD(bool, isVibrating, (), ()); |
| 232 | MOCK_METHOD(std::vector<int32_t>, getVibratorIds, (), ()); |
| 233 | MOCK_METHOD(std::list<NotifyArgs>, cancelTouch, (nsecs_t when, nsecs_t readTime), ()); |
| 234 | MOCK_METHOD(bool, enableSensor, |
| 235 | (InputDeviceSensorType sensorType, std::chrono::microseconds samplingPeriod, |
| 236 | std::chrono::microseconds maxBatchReportLatency), |
| 237 | ()); |
| 238 | |
| 239 | MOCK_METHOD(void, disableSensor, (InputDeviceSensorType sensorType), ()); |
| 240 | MOCK_METHOD(void, flushSensor, (InputDeviceSensorType sensorType), ()); |
| 241 | |
| 242 | MOCK_METHOD(std::optional<int32_t>, getBatteryEventHubId, (), (const)); |
| 243 | |
| 244 | MOCK_METHOD(bool, setLightColor, (int32_t lightId, int32_t color), ()); |
| 245 | MOCK_METHOD(bool, setLightPlayerId, (int32_t lightId, int32_t playerId), ()); |
| 246 | MOCK_METHOD(std::optional<int32_t>, getLightColor, (int32_t lightId), ()); |
| 247 | MOCK_METHOD(std::optional<int32_t>, getLightPlayerId, (int32_t lightId), ()); |
| 248 | |
| 249 | MOCK_METHOD(int32_t, getMetaState, (), ()); |
Prabir Pradhan | 31d05c4 | 2024-07-24 21:19:08 +0000 | [diff] [blame] | 250 | MOCK_METHOD(void, setKeyboardType, (KeyboardType keyboardType), ()); |
| 251 | |
| 252 | MOCK_METHOD(void, bumpGeneration, (), ()); |
| 253 | |
| 254 | MOCK_METHOD(const PropertyMap&, getConfiguration, (), (const, override)); |
| 255 | |
| 256 | MOCK_METHOD(NotifyDeviceResetArgs, notifyReset, (nsecs_t when), ()); |
| 257 | |
| 258 | MOCK_METHOD(std::optional<ui::LogicalDisplayId>, getAssociatedDisplayId, (), ()); |
| 259 | |
| 260 | MOCK_METHOD(void, updateLedState, (bool reset), ()); |
| 261 | |
| 262 | MOCK_METHOD(size_t, getMapperCount, (), ()); |
| 263 | }; |
Siarhei Vishniakou | 979f2d8 | 2023-05-16 14:26:24 -0700 | [diff] [blame] | 264 | } // namespace android |