Harry Cutts | 6b5fbc5 | 2022-11-28 16:37:43 +0000 | [diff] [blame] | 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 | |
Harry Cutts | 6b5fbc5 | 2022-11-28 16:37:43 +0000 | [diff] [blame] | 29 | #include "input/DisplayViewport.h" |
| 30 | #include "input/InputDevice.h" |
| 31 | |
| 32 | namespace android { |
| 33 | |
| 34 | class FakeInputReaderPolicy : public InputReaderPolicyInterface { |
| 35 | protected: |
| 36 | virtual ~FakeInputReaderPolicy() {} |
| 37 | |
| 38 | public: |
| 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 Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame^] | 51 | void addDisplayViewport(ui::LogicalDisplayId displayId, int32_t width, int32_t height, |
Michael Wright | a9cf419 | 2022-12-01 23:46:39 +0000 | [diff] [blame] | 52 | ui::Rotation orientation, bool isActive, const std::string& uniqueId, |
Harry Cutts | 6b5fbc5 | 2022-11-28 16:37:43 +0000 | [diff] [blame] | 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); |
Ambrus Weisz | 7bc23bf | 2022-10-04 13:13:07 +0000 | [diff] [blame] | 57 | void addDeviceTypeAssociation(const std::string& inputPort, const std::string& type); |
Harry Cutts | 6b5fbc5 | 2022-11-28 16:37:43 +0000 | [diff] [blame] | 58 | void addInputUniqueIdAssociation(const std::string& inputUniqueId, |
| 59 | const std::string& displayUniqueId); |
Zixuan Qu | fecb606 | 2022-11-12 04:44:31 +0000 | [diff] [blame] | 60 | void addKeyboardLayoutAssociation(const std::string& inputUniqueId, |
| 61 | const KeyboardLayoutInfo& layoutInfo); |
Harry Cutts | 6b5fbc5 | 2022-11-28 16:37:43 +0000 | [diff] [blame] | 62 | void addDisabledDevice(int32_t deviceId); |
| 63 | void removeDisabledDevice(int32_t deviceId); |
Arpit Singh | ed6c3de | 2023-04-05 19:24:37 +0000 | [diff] [blame] | 64 | const InputReaderConfiguration& getReaderConfiguration() const; |
Siarhei Vishniakou | 66b82f9 | 2023-08-16 14:42:06 -0700 | [diff] [blame] | 65 | const std::vector<InputDeviceInfo> getInputDevices() const; |
Harry Cutts | 6b5fbc5 | 2022-11-28 16:37:43 +0000 | [diff] [blame] | 66 | TouchAffineTransformation getTouchAffineTransformation(const std::string& inputDeviceDescriptor, |
Michael Wright | a9cf419 | 2022-12-01 23:46:39 +0000 | [diff] [blame] | 67 | ui::Rotation surfaceRotation); |
Harry Cutts | 6b5fbc5 | 2022-11-28 16:37:43 +0000 | [diff] [blame] | 68 | void setTouchAffineTransformation(const TouchAffineTransformation t); |
Hiroki Sato | 2504023 | 2024-02-22 17:21:22 +0900 | [diff] [blame] | 69 | PointerCaptureRequest setPointerCapture(const sp<IBinder>& window); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame^] | 70 | void setDefaultPointerDisplayId(ui::LogicalDisplayId pointerDisplayId); |
Harry Cutts | 6b5fbc5 | 2022-11-28 16:37:43 +0000 | [diff] [blame] | 71 | void setPointerGestureEnabled(bool enabled); |
| 72 | float getPointerGestureMovementSpeedRatio(); |
| 73 | float getPointerGestureZoomSpeedRatio(); |
| 74 | void setVelocityControlParams(const VelocityControlParameters& params); |
Prabir Pradhan | 7aa7ff0 | 2022-12-21 21:05:38 +0000 | [diff] [blame] | 75 | void setStylusButtonMotionEventsEnabled(bool enabled); |
Seunghwan Choi | 356026c | 2023-02-01 14:37:25 +0900 | [diff] [blame] | 76 | void setStylusPointerIconEnabled(bool enabled); |
Arpit Singh | b3b3f73 | 2023-07-04 14:30:05 +0000 | [diff] [blame] | 77 | void setIsInputMethodConnectionActive(bool active); |
| 78 | bool isInputMethodConnectionActive() override; |
Prabir Pradhan | 1976760 | 2023-11-03 16:53:31 +0000 | [diff] [blame] | 79 | std::optional<DisplayViewport> getPointerViewportForAssociatedDisplay( |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame^] | 80 | ui::LogicalDisplayId associatedDisplayId) override; |
Harry Cutts | 6b5fbc5 | 2022-11-28 16:37:43 +0000 | [diff] [blame] | 81 | |
| 82 | private: |
| 83 | void getReaderConfiguration(InputReaderConfiguration* outConfig) override; |
Harry Cutts | 6b5fbc5 | 2022-11-28 16:37:43 +0000 | [diff] [blame] | 84 | void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) override; |
| 85 | std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay( |
Vaibhav Devmurari | dec3080 | 2023-07-11 15:02:03 +0000 | [diff] [blame] | 86 | const InputDeviceIdentifier&, const std::optional<KeyboardLayoutInfo>) override; |
Harry Cutts | 6b5fbc5 | 2022-11-28 16:37:43 +0000 | [diff] [blame] | 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 | |
Siarhei Vishniakou | 66b82f9 | 2023-08-16 14:42:06 -0700 | [diff] [blame] | 91 | mutable std::mutex mLock; |
Harry Cutts | 6b5fbc5 | 2022-11-28 16:37:43 +0000 | [diff] [blame] | 92 | std::condition_variable mDevicesChangedCondition; |
| 93 | |
| 94 | InputReaderConfiguration mConfig; |
Harry Cutts | 6b5fbc5 | 2022-11-28 16:37:43 +0000 | [diff] [blame] | 95 | std::vector<InputDeviceInfo> mInputDevices GUARDED_BY(mLock); |
| 96 | bool mInputDevicesChanged GUARDED_BY(mLock){false}; |
| 97 | std::vector<DisplayViewport> mViewports; |
| 98 | TouchAffineTransformation transform; |
Arpit Singh | b3b3f73 | 2023-07-04 14:30:05 +0000 | [diff] [blame] | 99 | bool mIsInputMethodConnectionActive{false}; |
Harry Cutts | 6b5fbc5 | 2022-11-28 16:37:43 +0000 | [diff] [blame] | 100 | |
Prabir Pradhan | 40aee53 | 2024-02-08 00:47:23 +0000 | [diff] [blame] | 101 | std::condition_variable mStylusGestureNotifiedCondition; |
| 102 | std::optional<DeviceId> mDeviceIdOfNotifiedStylusGesture GUARDED_BY(mLock){}; |
| 103 | |
Harry Cutts | 6b5fbc5 | 2022-11-28 16:37:43 +0000 | [diff] [blame] | 104 | uint32_t mNextPointerCaptureSequenceNumber{0}; |
| 105 | }; |
| 106 | |
| 107 | } // namespace android |