blob: 42c956789b8dc23eed7d5d70e82e011a8b45a27e [file] [log] [blame]
Harry Cutts6b5fbc52022-11-28 16:37:43 +00001/*
2 * Copyright 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#pragma once
18
19#include <condition_variable>
20#include <memory>
21#include <mutex>
22#include <optional>
23#include <string>
24#include <vector>
25
26#include <InputDevice.h>
27#include <InputReaderBase.h>
28
Harry Cutts6b5fbc52022-11-28 16:37:43 +000029#include "input/DisplayViewport.h"
30#include "input/InputDevice.h"
31
32namespace android {
33
34class FakeInputReaderPolicy : public InputReaderPolicyInterface {
35protected:
36 virtual ~FakeInputReaderPolicy() {}
37
38public:
39 FakeInputReaderPolicy() {}
40
41 void assertInputDevicesChanged();
42 void assertInputDevicesNotChanged();
43 void assertStylusGestureNotified(int32_t deviceId);
44 void assertStylusGestureNotNotified();
Abdelrahman Awadalla8c4160d2024-08-05 16:26:10 +000045 void assertTouchpadHardwareStateNotified();
Harry Cutts2a0210e2024-10-18 19:12:59 +000046 void assertTouchpadThreeFingerTapNotified();
Harry Cutts6b5fbc52022-11-28 16:37:43 +000047
48 virtual void clearViewports();
49 std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueId) const;
50 std::optional<DisplayViewport> getDisplayViewportByType(ViewportType type) const;
51 std::optional<DisplayViewport> getDisplayViewportByPort(uint8_t displayPort) const;
52 void addDisplayViewport(DisplayViewport viewport);
Linnan Li13bf76a2024-05-05 19:18:02 +080053 void addDisplayViewport(ui::LogicalDisplayId displayId, int32_t width, int32_t height,
Michael Wrighta9cf4192022-12-01 23:46:39 +000054 ui::Rotation orientation, bool isActive, const std::string& uniqueId,
Harry Cutts6b5fbc52022-11-28 16:37:43 +000055 std::optional<uint8_t> physicalPort, ViewportType type);
56 bool updateViewport(const DisplayViewport& viewport);
57 void addExcludedDeviceName(const std::string& deviceName);
58 void addInputPortAssociation(const std::string& inputPort, uint8_t displayPort);
Ambrus Weisz7bc23bf2022-10-04 13:13:07 +000059 void addDeviceTypeAssociation(const std::string& inputPort, const std::string& type);
Harry Cutts6b5fbc52022-11-28 16:37:43 +000060 void addInputUniqueIdAssociation(const std::string& inputUniqueId,
61 const std::string& displayUniqueId);
Zixuan Qufecb6062022-11-12 04:44:31 +000062 void addKeyboardLayoutAssociation(const std::string& inputUniqueId,
63 const KeyboardLayoutInfo& layoutInfo);
Harry Cutts6b5fbc52022-11-28 16:37:43 +000064 void addDisabledDevice(int32_t deviceId);
65 void removeDisabledDevice(int32_t deviceId);
Arpit Singhed6c3de2023-04-05 19:24:37 +000066 const InputReaderConfiguration& getReaderConfiguration() const;
Siarhei Vishniakou66b82f92023-08-16 14:42:06 -070067 const std::vector<InputDeviceInfo> getInputDevices() const;
Harry Cutts6b5fbc52022-11-28 16:37:43 +000068 TouchAffineTransformation getTouchAffineTransformation(const std::string& inputDeviceDescriptor,
Michael Wrighta9cf4192022-12-01 23:46:39 +000069 ui::Rotation surfaceRotation);
Harry Cutts6b5fbc52022-11-28 16:37:43 +000070 void setTouchAffineTransformation(const TouchAffineTransformation t);
Hiroki Sato25040232024-02-22 17:21:22 +090071 PointerCaptureRequest setPointerCapture(const sp<IBinder>& window);
Linnan Li13bf76a2024-05-05 19:18:02 +080072 void setDefaultPointerDisplayId(ui::LogicalDisplayId pointerDisplayId);
Harry Cutts6b5fbc52022-11-28 16:37:43 +000073 void setPointerGestureEnabled(bool enabled);
74 float getPointerGestureMovementSpeedRatio();
75 float getPointerGestureZoomSpeedRatio();
76 void setVelocityControlParams(const VelocityControlParameters& params);
Prabir Pradhan7aa7ff02022-12-21 21:05:38 +000077 void setStylusButtonMotionEventsEnabled(bool enabled);
Seunghwan Choi356026c2023-02-01 14:37:25 +090078 void setStylusPointerIconEnabled(bool enabled);
Arpit Singhb3b3f732023-07-04 14:30:05 +000079 void setIsInputMethodConnectionActive(bool active);
80 bool isInputMethodConnectionActive() override;
Prabir Pradhan19767602023-11-03 16:53:31 +000081 std::optional<DisplayViewport> getPointerViewportForAssociatedDisplay(
Linnan Li13bf76a2024-05-05 19:18:02 +080082 ui::LogicalDisplayId associatedDisplayId) override;
Harry Cutts6b5fbc52022-11-28 16:37:43 +000083
84private:
85 void getReaderConfiguration(InputReaderConfiguration* outConfig) override;
Harry Cutts6b5fbc52022-11-28 16:37:43 +000086 void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) override;
Abdelrahman Awadalla8c4160d2024-08-05 16:26:10 +000087 void notifyTouchpadHardwareState(const SelfContainedHardwareState& schs,
88 int32_t deviceId) override;
Omar Abdelmonem5ebf21f2024-09-12 11:44:15 +000089 void notifyTouchpadGestureInfo(GestureType type, int32_t deviceId) override;
Harry Cutts2a0210e2024-10-18 19:12:59 +000090 void notifyTouchpadThreeFingerTap() override;
Harry Cutts6b5fbc52022-11-28 16:37:43 +000091 std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay(
Vaibhav Devmuraridec30802023-07-11 15:02:03 +000092 const InputDeviceIdentifier&, const std::optional<KeyboardLayoutInfo>) override;
Harry Cutts6b5fbc52022-11-28 16:37:43 +000093 std::string getDeviceAlias(const InputDeviceIdentifier&) override;
Siarhei Vishniakoubfd75112024-09-04 00:29:42 +000094 void waitForInputDevices(std::function<void(bool)> processDevicesChanged,
95 std::chrono::milliseconds timeout);
Harry Cutts6b5fbc52022-11-28 16:37:43 +000096 void notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) override;
97
Siarhei Vishniakou66b82f92023-08-16 14:42:06 -070098 mutable std::mutex mLock;
Harry Cutts6b5fbc52022-11-28 16:37:43 +000099 std::condition_variable mDevicesChangedCondition;
100
101 InputReaderConfiguration mConfig;
Harry Cutts6b5fbc52022-11-28 16:37:43 +0000102 std::vector<InputDeviceInfo> mInputDevices GUARDED_BY(mLock);
103 bool mInputDevicesChanged GUARDED_BY(mLock){false};
104 std::vector<DisplayViewport> mViewports;
105 TouchAffineTransformation transform;
Arpit Singhb3b3f732023-07-04 14:30:05 +0000106 bool mIsInputMethodConnectionActive{false};
Harry Cutts6b5fbc52022-11-28 16:37:43 +0000107
Prabir Pradhan40aee532024-02-08 00:47:23 +0000108 std::condition_variable mStylusGestureNotifiedCondition;
109 std::optional<DeviceId> mDeviceIdOfNotifiedStylusGesture GUARDED_BY(mLock){};
110
Abdelrahman Awadalla8c4160d2024-08-05 16:26:10 +0000111 std::condition_variable mTouchpadHardwareStateNotified;
112 std::optional<SelfContainedHardwareState> mTouchpadHardwareState GUARDED_BY(mLock){};
113
Harry Cutts2a0210e2024-10-18 19:12:59 +0000114 std::condition_variable mTouchpadThreeFingerTapNotified;
115 bool mTouchpadThreeFingerTapHasBeenReported{false};
116
Harry Cutts6b5fbc52022-11-28 16:37:43 +0000117 uint32_t mNextPointerCaptureSequenceNumber{0};
118};
119
120} // namespace android