• 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 class FakeInputReaderPolicy : public InputReaderPolicyInterface {
35 protected:
~FakeInputReaderPolicy()36     virtual ~FakeInputReaderPolicy() {}
37 
38 public:
FakeInputReaderPolicy()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);
51     void addDisplayViewport(ui::LogicalDisplayId displayId, int32_t width, int32_t height,
52                             ui::Rotation orientation, bool isActive, const std::string& uniqueId,
53                             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);
57     void addDeviceTypeAssociation(const std::string& inputPort, const std::string& type);
58     void addInputUniqueIdAssociation(const std::string& inputUniqueId,
59                                      const std::string& displayUniqueId);
60     void addKeyboardLayoutAssociation(const std::string& inputUniqueId,
61                                       const KeyboardLayoutInfo& layoutInfo);
62     void addDisabledDevice(int32_t deviceId);
63     void removeDisabledDevice(int32_t deviceId);
64     const InputReaderConfiguration& getReaderConfiguration() const;
65     const std::vector<InputDeviceInfo> getInputDevices() const;
66     TouchAffineTransformation getTouchAffineTransformation(const std::string& inputDeviceDescriptor,
67                                                            ui::Rotation surfaceRotation);
68     void setTouchAffineTransformation(const TouchAffineTransformation t);
69     PointerCaptureRequest setPointerCapture(const sp<IBinder>& window);
70     void setDefaultPointerDisplayId(ui::LogicalDisplayId pointerDisplayId);
71     void setPointerGestureEnabled(bool enabled);
72     float getPointerGestureMovementSpeedRatio();
73     float getPointerGestureZoomSpeedRatio();
74     void setVelocityControlParams(const VelocityControlParameters& params);
75     void setStylusButtonMotionEventsEnabled(bool enabled);
76     void setStylusPointerIconEnabled(bool enabled);
77     void setIsInputMethodConnectionActive(bool active);
78     bool isInputMethodConnectionActive() override;
79     std::optional<DisplayViewport> getPointerViewportForAssociatedDisplay(
80             ui::LogicalDisplayId associatedDisplayId) override;
81 
82 private:
83     void getReaderConfiguration(InputReaderConfiguration* outConfig) override;
84     void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) override;
85     std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay(
86             const InputDeviceIdentifier&, const std::optional<KeyboardLayoutInfo>) override;
87     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 
91     mutable std::mutex mLock;
92     std::condition_variable mDevicesChangedCondition;
93 
94     InputReaderConfiguration mConfig;
95     std::vector<InputDeviceInfo> mInputDevices GUARDED_BY(mLock);
GUARDED_BY(mLock)96     bool mInputDevicesChanged GUARDED_BY(mLock){false};
97     std::vector<DisplayViewport> mViewports;
98     TouchAffineTransformation transform;
99     bool mIsInputMethodConnectionActive{false};
100 
101     std::condition_variable mStylusGestureNotifiedCondition;
GUARDED_BY(mLock)102     std::optional<DeviceId> mDeviceIdOfNotifiedStylusGesture GUARDED_BY(mLock){};
103 
104     uint32_t mNextPointerCaptureSequenceNumber{0};
105 };
106 
107 } // namespace android
108