• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 "input/DisplayViewport.h"
30 #include "input/InputDevice.h"
31 
32 namespace android {
33 
34 DisplayViewport createViewport(ui::LogicalDisplayId displayId, int32_t width, int32_t height,
35                                ui::Rotation orientation, bool isActive, const std::string& uniqueId,
36                                std::optional<uint8_t> physicalPort, ViewportType type);
37 
38 class FakeInputReaderPolicy : public InputReaderPolicyInterface {
39 protected:
~FakeInputReaderPolicy()40     virtual ~FakeInputReaderPolicy() {}
41 
42 public:
FakeInputReaderPolicy()43     FakeInputReaderPolicy() {}
44 
45     void assertInputDevicesChanged();
46     void assertInputDevicesNotChanged();
47     void assertStylusGestureNotified(int32_t deviceId);
48     void assertStylusGestureNotNotified();
49     void assertTouchpadHardwareStateNotified();
50     void assertTouchpadThreeFingerTapNotified();
51 
52     virtual void clearViewports();
53     std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueId) const;
54     std::optional<DisplayViewport> getDisplayViewportByType(ViewportType type) const;
55     std::optional<DisplayViewport> getDisplayViewportByPort(uint8_t displayPort) const;
56     void addDisplayViewport(DisplayViewport viewport);
57     bool updateViewport(const DisplayViewport& viewport);
58     void addExcludedDeviceName(const std::string& deviceName);
59     void addInputPortAssociation(const std::string& inputPort, uint8_t displayPort);
60     void addDeviceTypeAssociation(const std::string& inputPort, const std::string& type);
61     void addInputUniqueIdAssociation(const std::string& inputUniqueId,
62                                      const std::string& displayUniqueId);
63     void addKeyboardLayoutAssociation(const std::string& inputUniqueId,
64                                       const KeyboardLayoutInfo& layoutInfo);
65     void addDisabledDevice(int32_t deviceId);
66     void removeDisabledDevice(int32_t deviceId);
67     const InputReaderConfiguration& getReaderConfiguration() const;
68     const std::vector<InputDeviceInfo> getInputDevices() const;
69     TouchAffineTransformation getTouchAffineTransformation(const std::string& inputDeviceDescriptor,
70                                                            ui::Rotation surfaceRotation);
71     void setTouchAffineTransformation(const TouchAffineTransformation t);
72     PointerCaptureRequest setPointerCapture(const sp<IBinder>& window);
73     void setDefaultPointerDisplayId(ui::LogicalDisplayId pointerDisplayId);
74     void setPointerGestureEnabled(bool enabled);
75     float getPointerGestureMovementSpeedRatio();
76     float getPointerGestureZoomSpeedRatio();
77     void setVelocityControlParams(const VelocityControlParameters& params);
78     void setStylusButtonMotionEventsEnabled(bool enabled);
79     void setStylusPointerIconEnabled(bool enabled);
80     void setIsInputMethodConnectionActive(bool active);
81     bool isInputMethodConnectionActive() override;
82     std::optional<DisplayViewport> getPointerViewportForAssociatedDisplay(
83             ui::LogicalDisplayId associatedDisplayId) override;
84 
85 private:
86     void getReaderConfiguration(InputReaderConfiguration* outConfig) override;
87     void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) override;
88     void notifyTouchpadHardwareState(const SelfContainedHardwareState& schs,
89                                      int32_t deviceId) override;
90     void notifyTouchpadGestureInfo(GestureType type, int32_t deviceId) override;
91     void notifyTouchpadThreeFingerTap() override;
92     std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay(
93             const InputDeviceIdentifier&, const std::optional<KeyboardLayoutInfo>) override;
94     std::string getDeviceAlias(const InputDeviceIdentifier&) override;
95     void waitForInputDevices(std::function<void(bool)> processDevicesChanged,
96                              std::chrono::milliseconds timeout);
97     void notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) override;
98 
99     mutable std::mutex mLock;
100     std::condition_variable mDevicesChangedCondition;
101 
102     InputReaderConfiguration mConfig;
103     std::vector<InputDeviceInfo> mInputDevices GUARDED_BY(mLock);
GUARDED_BY(mLock)104     bool mInputDevicesChanged GUARDED_BY(mLock){false};
105     std::vector<DisplayViewport> mViewports;
106     TouchAffineTransformation transform;
107     bool mIsInputMethodConnectionActive{false};
108 
109     std::condition_variable mStylusGestureNotifiedCondition;
GUARDED_BY(mLock)110     std::optional<DeviceId> mDeviceIdOfNotifiedStylusGesture GUARDED_BY(mLock){};
111 
112     std::condition_variable mTouchpadHardwareStateNotified;
GUARDED_BY(mLock)113     std::optional<SelfContainedHardwareState> mTouchpadHardwareState GUARDED_BY(mLock){};
114 
115     std::condition_variable mTouchpadThreeFingerTapNotified;
116     bool mTouchpadThreeFingerTapHasBeenReported{false};
117 
118     uint32_t mNextPointerCaptureSequenceNumber{0};
119 };
120 
121 } // namespace android
122