blob: c16cda404ef9f6d5c7023698f82309f8f73c8c26 [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
29#include "FakePointerController.h"
30#include "input/DisplayViewport.h"
31#include "input/InputDevice.h"
32
33namespace android {
34
35class FakeInputReaderPolicy : public InputReaderPolicyInterface {
36protected:
37 virtual ~FakeInputReaderPolicy() {}
38
39public:
40 FakeInputReaderPolicy() {}
41
42 void assertInputDevicesChanged();
43 void assertInputDevicesNotChanged();
44 void assertStylusGestureNotified(int32_t deviceId);
45 void assertStylusGestureNotNotified();
46
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);
Michael Wrighta9cf4192022-12-01 23:46:39 +000052 void addDisplayViewport(int32_t displayId, int32_t width, int32_t height,
53 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);
58 void addInputUniqueIdAssociation(const std::string& inputUniqueId,
59 const std::string& displayUniqueId);
60 void addDisabledDevice(int32_t deviceId);
61 void removeDisabledDevice(int32_t deviceId);
62 void setPointerController(std::shared_ptr<FakePointerController> controller);
63 const InputReaderConfiguration* getReaderConfiguration() const;
64 const std::vector<InputDeviceInfo>& getInputDevices() const;
65 TouchAffineTransformation getTouchAffineTransformation(const std::string& inputDeviceDescriptor,
Michael Wrighta9cf4192022-12-01 23:46:39 +000066 ui::Rotation surfaceRotation);
Harry Cutts6b5fbc52022-11-28 16:37:43 +000067 void setTouchAffineTransformation(const TouchAffineTransformation t);
68 PointerCaptureRequest setPointerCapture(bool enabled);
69 void setShowTouches(bool enabled);
70 void setDefaultPointerDisplayId(int32_t pointerDisplayId);
71 void setPointerGestureEnabled(bool enabled);
72 float getPointerGestureMovementSpeedRatio();
73 float getPointerGestureZoomSpeedRatio();
74 void setVelocityControlParams(const VelocityControlParameters& params);
75
76private:
77 void getReaderConfiguration(InputReaderConfiguration* outConfig) override;
78 std::shared_ptr<PointerControllerInterface> obtainPointerController(
79 int32_t /*deviceId*/) override;
80 void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) override;
81 std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay(
82 const InputDeviceIdentifier&) override;
83 std::string getDeviceAlias(const InputDeviceIdentifier&) override;
84 void waitForInputDevices(std::function<void(bool)> processDevicesChanged);
85 void notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) override;
86
87 std::mutex mLock;
88 std::condition_variable mDevicesChangedCondition;
89
90 InputReaderConfiguration mConfig;
91 std::shared_ptr<FakePointerController> mPointerController;
92 std::vector<InputDeviceInfo> mInputDevices GUARDED_BY(mLock);
93 bool mInputDevicesChanged GUARDED_BY(mLock){false};
94 std::vector<DisplayViewport> mViewports;
95 TouchAffineTransformation transform;
96 std::optional<int32_t /*deviceId*/> mStylusGestureNotified GUARDED_BY(mLock){};
97
98 uint32_t mNextPointerCaptureSequenceNumber{0};
99};
100
101} // namespace android