blob: 3a2b4e9ed94051085ca2ac45334ae5b27d4b1f2f [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 Cutts6b5fbc52022-11-28 16:37:43 +000046
47 virtual void clearViewports();
48 std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueId) const;
49 std::optional<DisplayViewport> getDisplayViewportByType(ViewportType type) const;
50 std::optional<DisplayViewport> getDisplayViewportByPort(uint8_t displayPort) const;
51 void addDisplayViewport(DisplayViewport viewport);
Linnan Li13bf76a2024-05-05 19:18:02 +080052 void addDisplayViewport(ui::LogicalDisplayId displayId, int32_t width, int32_t height,
Michael Wrighta9cf4192022-12-01 23:46:39 +000053 ui::Rotation orientation, bool isActive, const std::string& uniqueId,
Harry Cutts6b5fbc52022-11-28 16:37:43 +000054 std::optional<uint8_t> physicalPort, ViewportType type);
55 bool updateViewport(const DisplayViewport& viewport);
56 void addExcludedDeviceName(const std::string& deviceName);
57 void addInputPortAssociation(const std::string& inputPort, uint8_t displayPort);
Ambrus Weisz7bc23bf2022-10-04 13:13:07 +000058 void addDeviceTypeAssociation(const std::string& inputPort, const std::string& type);
Harry Cutts6b5fbc52022-11-28 16:37:43 +000059 void addInputUniqueIdAssociation(const std::string& inputUniqueId,
60 const std::string& displayUniqueId);
Zixuan Qufecb6062022-11-12 04:44:31 +000061 void addKeyboardLayoutAssociation(const std::string& inputUniqueId,
62 const KeyboardLayoutInfo& layoutInfo);
Harry Cutts6b5fbc52022-11-28 16:37:43 +000063 void addDisabledDevice(int32_t deviceId);
64 void removeDisabledDevice(int32_t deviceId);
Arpit Singhed6c3de2023-04-05 19:24:37 +000065 const InputReaderConfiguration& getReaderConfiguration() const;
Siarhei Vishniakou66b82f92023-08-16 14:42:06 -070066 const std::vector<InputDeviceInfo> getInputDevices() const;
Harry Cutts6b5fbc52022-11-28 16:37:43 +000067 TouchAffineTransformation getTouchAffineTransformation(const std::string& inputDeviceDescriptor,
Michael Wrighta9cf4192022-12-01 23:46:39 +000068 ui::Rotation surfaceRotation);
Harry Cutts6b5fbc52022-11-28 16:37:43 +000069 void setTouchAffineTransformation(const TouchAffineTransformation t);
Hiroki Sato25040232024-02-22 17:21:22 +090070 PointerCaptureRequest setPointerCapture(const sp<IBinder>& window);
Linnan Li13bf76a2024-05-05 19:18:02 +080071 void setDefaultPointerDisplayId(ui::LogicalDisplayId pointerDisplayId);
Harry Cutts6b5fbc52022-11-28 16:37:43 +000072 void setPointerGestureEnabled(bool enabled);
73 float getPointerGestureMovementSpeedRatio();
74 float getPointerGestureZoomSpeedRatio();
75 void setVelocityControlParams(const VelocityControlParameters& params);
Prabir Pradhan7aa7ff02022-12-21 21:05:38 +000076 void setStylusButtonMotionEventsEnabled(bool enabled);
Seunghwan Choi356026c2023-02-01 14:37:25 +090077 void setStylusPointerIconEnabled(bool enabled);
Arpit Singhb3b3f732023-07-04 14:30:05 +000078 void setIsInputMethodConnectionActive(bool active);
79 bool isInputMethodConnectionActive() override;
Prabir Pradhan19767602023-11-03 16:53:31 +000080 std::optional<DisplayViewport> getPointerViewportForAssociatedDisplay(
Linnan Li13bf76a2024-05-05 19:18:02 +080081 ui::LogicalDisplayId associatedDisplayId) override;
Harry Cutts6b5fbc52022-11-28 16:37:43 +000082
83private:
84 void getReaderConfiguration(InputReaderConfiguration* outConfig) override;
Harry Cutts6b5fbc52022-11-28 16:37:43 +000085 void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) override;
Abdelrahman Awadalla8c4160d2024-08-05 16:26:10 +000086 void notifyTouchpadHardwareState(const SelfContainedHardwareState& schs,
87 int32_t deviceId) override;
Omar Abdelmonem5ebf21f2024-09-12 11:44:15 +000088 void notifyTouchpadGestureInfo(GestureType type, int32_t deviceId) override;
Harry Cutts6b5fbc52022-11-28 16:37:43 +000089 std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay(
Vaibhav Devmuraridec30802023-07-11 15:02:03 +000090 const InputDeviceIdentifier&, const std::optional<KeyboardLayoutInfo>) override;
Harry Cutts6b5fbc52022-11-28 16:37:43 +000091 std::string getDeviceAlias(const InputDeviceIdentifier&) override;
Siarhei Vishniakoubfd75112024-09-04 00:29:42 +000092 void waitForInputDevices(std::function<void(bool)> processDevicesChanged,
93 std::chrono::milliseconds timeout);
Harry Cutts6b5fbc52022-11-28 16:37:43 +000094 void notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) override;
95
Siarhei Vishniakou66b82f92023-08-16 14:42:06 -070096 mutable std::mutex mLock;
Harry Cutts6b5fbc52022-11-28 16:37:43 +000097 std::condition_variable mDevicesChangedCondition;
98
99 InputReaderConfiguration mConfig;
Harry Cutts6b5fbc52022-11-28 16:37:43 +0000100 std::vector<InputDeviceInfo> mInputDevices GUARDED_BY(mLock);
101 bool mInputDevicesChanged GUARDED_BY(mLock){false};
102 std::vector<DisplayViewport> mViewports;
103 TouchAffineTransformation transform;
Arpit Singhb3b3f732023-07-04 14:30:05 +0000104 bool mIsInputMethodConnectionActive{false};
Harry Cutts6b5fbc52022-11-28 16:37:43 +0000105
Prabir Pradhan40aee532024-02-08 00:47:23 +0000106 std::condition_variable mStylusGestureNotifiedCondition;
107 std::optional<DeviceId> mDeviceIdOfNotifiedStylusGesture GUARDED_BY(mLock){};
108
Abdelrahman Awadalla8c4160d2024-08-05 16:26:10 +0000109 std::condition_variable mTouchpadHardwareStateNotified;
110 std::optional<SelfContainedHardwareState> mTouchpadHardwareState GUARDED_BY(mLock){};
111
Harry Cutts6b5fbc52022-11-28 16:37:43 +0000112 uint32_t mNextPointerCaptureSequenceNumber{0};
113};
114
115} // namespace android