blob: 94f1311a1e45df2bb4a9f182a000b1ca48860f2c [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();
45
46 virtual void clearViewports();
47 std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueId) const;
48 std::optional<DisplayViewport> getDisplayViewportByType(ViewportType type) const;
49 std::optional<DisplayViewport> getDisplayViewportByPort(uint8_t displayPort) const;
50 void addDisplayViewport(DisplayViewport viewport);
Linnan Li13bf76a2024-05-05 19:18:02 +080051 void addDisplayViewport(ui::LogicalDisplayId displayId, int32_t width, int32_t height,
Michael Wrighta9cf4192022-12-01 23:46:39 +000052 ui::Rotation orientation, bool isActive, const std::string& uniqueId,
Harry Cutts6b5fbc52022-11-28 16:37:43 +000053 std::optional<uint8_t> physicalPort, ViewportType type);
54 bool updateViewport(const DisplayViewport& viewport);
55 void addExcludedDeviceName(const std::string& deviceName);
56 void addInputPortAssociation(const std::string& inputPort, uint8_t displayPort);
Ambrus Weisz7bc23bf2022-10-04 13:13:07 +000057 void addDeviceTypeAssociation(const std::string& inputPort, const std::string& type);
Harry Cutts6b5fbc52022-11-28 16:37:43 +000058 void addInputUniqueIdAssociation(const std::string& inputUniqueId,
59 const std::string& displayUniqueId);
Zixuan Qufecb6062022-11-12 04:44:31 +000060 void addKeyboardLayoutAssociation(const std::string& inputUniqueId,
61 const KeyboardLayoutInfo& layoutInfo);
Harry Cutts6b5fbc52022-11-28 16:37:43 +000062 void addDisabledDevice(int32_t deviceId);
63 void removeDisabledDevice(int32_t deviceId);
Arpit Singhed6c3de2023-04-05 19:24:37 +000064 const InputReaderConfiguration& getReaderConfiguration() const;
Siarhei Vishniakou66b82f92023-08-16 14:42:06 -070065 const std::vector<InputDeviceInfo> getInputDevices() const;
Harry Cutts6b5fbc52022-11-28 16:37:43 +000066 TouchAffineTransformation getTouchAffineTransformation(const std::string& inputDeviceDescriptor,
Michael Wrighta9cf4192022-12-01 23:46:39 +000067 ui::Rotation surfaceRotation);
Harry Cutts6b5fbc52022-11-28 16:37:43 +000068 void setTouchAffineTransformation(const TouchAffineTransformation t);
Hiroki Sato25040232024-02-22 17:21:22 +090069 PointerCaptureRequest setPointerCapture(const sp<IBinder>& window);
Linnan Li13bf76a2024-05-05 19:18:02 +080070 void setDefaultPointerDisplayId(ui::LogicalDisplayId pointerDisplayId);
Harry Cutts6b5fbc52022-11-28 16:37:43 +000071 void setPointerGestureEnabled(bool enabled);
72 float getPointerGestureMovementSpeedRatio();
73 float getPointerGestureZoomSpeedRatio();
74 void setVelocityControlParams(const VelocityControlParameters& params);
Prabir Pradhan7aa7ff02022-12-21 21:05:38 +000075 void setStylusButtonMotionEventsEnabled(bool enabled);
Seunghwan Choi356026c2023-02-01 14:37:25 +090076 void setStylusPointerIconEnabled(bool enabled);
Arpit Singhb3b3f732023-07-04 14:30:05 +000077 void setIsInputMethodConnectionActive(bool active);
78 bool isInputMethodConnectionActive() override;
Prabir Pradhan19767602023-11-03 16:53:31 +000079 std::optional<DisplayViewport> getPointerViewportForAssociatedDisplay(
Linnan Li13bf76a2024-05-05 19:18:02 +080080 ui::LogicalDisplayId associatedDisplayId) override;
Harry Cutts6b5fbc52022-11-28 16:37:43 +000081
82private:
83 void getReaderConfiguration(InputReaderConfiguration* outConfig) override;
Harry Cutts6b5fbc52022-11-28 16:37:43 +000084 void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) override;
85 std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay(
Vaibhav Devmuraridec30802023-07-11 15:02:03 +000086 const InputDeviceIdentifier&, const std::optional<KeyboardLayoutInfo>) override;
Harry Cutts6b5fbc52022-11-28 16:37:43 +000087 std::string getDeviceAlias(const InputDeviceIdentifier&) override;
88 void waitForInputDevices(std::function<void(bool)> processDevicesChanged);
89 void notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) override;
90
Siarhei Vishniakou66b82f92023-08-16 14:42:06 -070091 mutable std::mutex mLock;
Harry Cutts6b5fbc52022-11-28 16:37:43 +000092 std::condition_variable mDevicesChangedCondition;
93
94 InputReaderConfiguration mConfig;
Harry Cutts6b5fbc52022-11-28 16:37:43 +000095 std::vector<InputDeviceInfo> mInputDevices GUARDED_BY(mLock);
96 bool mInputDevicesChanged GUARDED_BY(mLock){false};
97 std::vector<DisplayViewport> mViewports;
98 TouchAffineTransformation transform;
Arpit Singhb3b3f732023-07-04 14:30:05 +000099 bool mIsInputMethodConnectionActive{false};
Harry Cutts6b5fbc52022-11-28 16:37:43 +0000100
Prabir Pradhan40aee532024-02-08 00:47:23 +0000101 std::condition_variable mStylusGestureNotifiedCondition;
102 std::optional<DeviceId> mDeviceIdOfNotifiedStylusGesture GUARDED_BY(mLock){};
103
Harry Cutts6b5fbc52022-11-28 16:37:43 +0000104 uint32_t mNextPointerCaptureSequenceNumber{0};
105};
106
107} // namespace android