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