xref: /aosp_15_r20/frameworks/native/services/inputflinger/tests/FakeInputReaderPolicy.cpp (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright 2022 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #include "FakeInputReaderPolicy.h"
18*38e8c45fSAndroid Build Coastguard Worker 
19*38e8c45fSAndroid Build Coastguard Worker #include <android-base/properties.h>
20*38e8c45fSAndroid Build Coastguard Worker #include <android-base/thread_annotations.h>
21*38e8c45fSAndroid Build Coastguard Worker #include <gtest/gtest.h>
22*38e8c45fSAndroid Build Coastguard Worker 
23*38e8c45fSAndroid Build Coastguard Worker #include "TestConstants.h"
24*38e8c45fSAndroid Build Coastguard Worker #include "ui/Rotation.h"
25*38e8c45fSAndroid Build Coastguard Worker 
26*38e8c45fSAndroid Build Coastguard Worker namespace android {
27*38e8c45fSAndroid Build Coastguard Worker 
28*38e8c45fSAndroid Build Coastguard Worker namespace {
29*38e8c45fSAndroid Build Coastguard Worker 
30*38e8c45fSAndroid Build Coastguard Worker static const int HW_TIMEOUT_MULTIPLIER = base::GetIntProperty("ro.hw_timeout_multiplier", 1);
31*38e8c45fSAndroid Build Coastguard Worker 
32*38e8c45fSAndroid Build Coastguard Worker } // namespace
33*38e8c45fSAndroid Build Coastguard Worker 
assertInputDevicesChanged()34*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::assertInputDevicesChanged() {
35*38e8c45fSAndroid Build Coastguard Worker     waitForInputDevices(
36*38e8c45fSAndroid Build Coastguard Worker             [](bool devicesChanged) {
37*38e8c45fSAndroid Build Coastguard Worker                 if (!devicesChanged) {
38*38e8c45fSAndroid Build Coastguard Worker                     FAIL() << "Timed out waiting for notifyInputDevicesChanged() to be called.";
39*38e8c45fSAndroid Build Coastguard Worker                 }
40*38e8c45fSAndroid Build Coastguard Worker             },
41*38e8c45fSAndroid Build Coastguard Worker             ADD_INPUT_DEVICE_TIMEOUT);
42*38e8c45fSAndroid Build Coastguard Worker }
43*38e8c45fSAndroid Build Coastguard Worker 
assertInputDevicesNotChanged()44*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::assertInputDevicesNotChanged() {
45*38e8c45fSAndroid Build Coastguard Worker     waitForInputDevices(
46*38e8c45fSAndroid Build Coastguard Worker             [](bool devicesChanged) {
47*38e8c45fSAndroid Build Coastguard Worker                 if (devicesChanged) {
48*38e8c45fSAndroid Build Coastguard Worker                     FAIL() << "Expected notifyInputDevicesChanged() to not be called.";
49*38e8c45fSAndroid Build Coastguard Worker                 }
50*38e8c45fSAndroid Build Coastguard Worker             },
51*38e8c45fSAndroid Build Coastguard Worker             INPUT_DEVICES_DIDNT_CHANGE_TIMEOUT);
52*38e8c45fSAndroid Build Coastguard Worker }
53*38e8c45fSAndroid Build Coastguard Worker 
assertStylusGestureNotified(int32_t deviceId)54*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::assertStylusGestureNotified(int32_t deviceId) {
55*38e8c45fSAndroid Build Coastguard Worker     std::unique_lock lock(mLock);
56*38e8c45fSAndroid Build Coastguard Worker     base::ScopedLockAssertion assumeLocked(mLock);
57*38e8c45fSAndroid Build Coastguard Worker 
58*38e8c45fSAndroid Build Coastguard Worker     const bool success =
59*38e8c45fSAndroid Build Coastguard Worker             mStylusGestureNotifiedCondition.wait_for(lock, WAIT_TIMEOUT, [this]() REQUIRES(mLock) {
60*38e8c45fSAndroid Build Coastguard Worker                 return mDeviceIdOfNotifiedStylusGesture.has_value();
61*38e8c45fSAndroid Build Coastguard Worker             });
62*38e8c45fSAndroid Build Coastguard Worker     ASSERT_TRUE(success) << "Timed out waiting for stylus gesture to be notified";
63*38e8c45fSAndroid Build Coastguard Worker     ASSERT_EQ(deviceId, *mDeviceIdOfNotifiedStylusGesture);
64*38e8c45fSAndroid Build Coastguard Worker     mDeviceIdOfNotifiedStylusGesture.reset();
65*38e8c45fSAndroid Build Coastguard Worker }
66*38e8c45fSAndroid Build Coastguard Worker 
assertStylusGestureNotNotified()67*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::assertStylusGestureNotNotified() {
68*38e8c45fSAndroid Build Coastguard Worker     std::scoped_lock lock(mLock);
69*38e8c45fSAndroid Build Coastguard Worker     ASSERT_FALSE(mDeviceIdOfNotifiedStylusGesture);
70*38e8c45fSAndroid Build Coastguard Worker }
71*38e8c45fSAndroid Build Coastguard Worker 
assertTouchpadHardwareStateNotified()72*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::assertTouchpadHardwareStateNotified() {
73*38e8c45fSAndroid Build Coastguard Worker     std::unique_lock lock(mLock);
74*38e8c45fSAndroid Build Coastguard Worker     base::ScopedLockAssertion assumeLocked(mLock);
75*38e8c45fSAndroid Build Coastguard Worker 
76*38e8c45fSAndroid Build Coastguard Worker     const bool success =
77*38e8c45fSAndroid Build Coastguard Worker             mTouchpadHardwareStateNotified.wait_for(lock, WAIT_TIMEOUT, [this]() REQUIRES(mLock) {
78*38e8c45fSAndroid Build Coastguard Worker                 return mTouchpadHardwareState.has_value();
79*38e8c45fSAndroid Build Coastguard Worker             });
80*38e8c45fSAndroid Build Coastguard Worker     ASSERT_TRUE(success) << "Timed out waiting for hardware state to be notified";
81*38e8c45fSAndroid Build Coastguard Worker }
82*38e8c45fSAndroid Build Coastguard Worker 
assertTouchpadThreeFingerTapNotified()83*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::assertTouchpadThreeFingerTapNotified() {
84*38e8c45fSAndroid Build Coastguard Worker     std::unique_lock lock(mLock);
85*38e8c45fSAndroid Build Coastguard Worker     base::ScopedLockAssertion assumeLocked(mLock);
86*38e8c45fSAndroid Build Coastguard Worker 
87*38e8c45fSAndroid Build Coastguard Worker     const bool success =
88*38e8c45fSAndroid Build Coastguard Worker             mTouchpadThreeFingerTapNotified.wait_for(lock, WAIT_TIMEOUT, [this]() REQUIRES(mLock) {
89*38e8c45fSAndroid Build Coastguard Worker                 return mTouchpadThreeFingerTapHasBeenReported;
90*38e8c45fSAndroid Build Coastguard Worker             });
91*38e8c45fSAndroid Build Coastguard Worker     ASSERT_TRUE(success) << "Timed out waiting for three-finger tap to be notified";
92*38e8c45fSAndroid Build Coastguard Worker }
93*38e8c45fSAndroid Build Coastguard Worker 
clearViewports()94*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::clearViewports() {
95*38e8c45fSAndroid Build Coastguard Worker     mViewports.clear();
96*38e8c45fSAndroid Build Coastguard Worker     mConfig.setDisplayViewports(mViewports);
97*38e8c45fSAndroid Build Coastguard Worker }
98*38e8c45fSAndroid Build Coastguard Worker 
getDisplayViewportByUniqueId(const std::string & uniqueId) const99*38e8c45fSAndroid Build Coastguard Worker std::optional<DisplayViewport> FakeInputReaderPolicy::getDisplayViewportByUniqueId(
100*38e8c45fSAndroid Build Coastguard Worker         const std::string& uniqueId) const {
101*38e8c45fSAndroid Build Coastguard Worker     return mConfig.getDisplayViewportByUniqueId(uniqueId);
102*38e8c45fSAndroid Build Coastguard Worker }
getDisplayViewportByType(ViewportType type) const103*38e8c45fSAndroid Build Coastguard Worker std::optional<DisplayViewport> FakeInputReaderPolicy::getDisplayViewportByType(
104*38e8c45fSAndroid Build Coastguard Worker         ViewportType type) const {
105*38e8c45fSAndroid Build Coastguard Worker     return mConfig.getDisplayViewportByType(type);
106*38e8c45fSAndroid Build Coastguard Worker }
107*38e8c45fSAndroid Build Coastguard Worker 
getDisplayViewportByPort(uint8_t displayPort) const108*38e8c45fSAndroid Build Coastguard Worker std::optional<DisplayViewport> FakeInputReaderPolicy::getDisplayViewportByPort(
109*38e8c45fSAndroid Build Coastguard Worker         uint8_t displayPort) const {
110*38e8c45fSAndroid Build Coastguard Worker     return mConfig.getDisplayViewportByPort(displayPort);
111*38e8c45fSAndroid Build Coastguard Worker }
112*38e8c45fSAndroid Build Coastguard Worker 
addDisplayViewport(DisplayViewport viewport)113*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::addDisplayViewport(DisplayViewport viewport) {
114*38e8c45fSAndroid Build Coastguard Worker     mViewports.push_back(std::move(viewport));
115*38e8c45fSAndroid Build Coastguard Worker     mConfig.setDisplayViewports(mViewports);
116*38e8c45fSAndroid Build Coastguard Worker }
117*38e8c45fSAndroid Build Coastguard Worker 
addDisplayViewport(ui::LogicalDisplayId displayId,int32_t width,int32_t height,ui::Rotation orientation,bool isActive,const std::string & uniqueId,std::optional<uint8_t> physicalPort,ViewportType type)118*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::addDisplayViewport(ui::LogicalDisplayId displayId, int32_t width,
119*38e8c45fSAndroid Build Coastguard Worker                                                int32_t height, ui::Rotation orientation,
120*38e8c45fSAndroid Build Coastguard Worker                                                bool isActive, const std::string& uniqueId,
121*38e8c45fSAndroid Build Coastguard Worker                                                std::optional<uint8_t> physicalPort,
122*38e8c45fSAndroid Build Coastguard Worker                                                ViewportType type) {
123*38e8c45fSAndroid Build Coastguard Worker     const bool isRotated = orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270;
124*38e8c45fSAndroid Build Coastguard Worker     DisplayViewport v;
125*38e8c45fSAndroid Build Coastguard Worker     v.displayId = displayId;
126*38e8c45fSAndroid Build Coastguard Worker     v.orientation = orientation;
127*38e8c45fSAndroid Build Coastguard Worker     v.logicalLeft = 0;
128*38e8c45fSAndroid Build Coastguard Worker     v.logicalTop = 0;
129*38e8c45fSAndroid Build Coastguard Worker     v.logicalRight = isRotated ? height : width;
130*38e8c45fSAndroid Build Coastguard Worker     v.logicalBottom = isRotated ? width : height;
131*38e8c45fSAndroid Build Coastguard Worker     v.physicalLeft = 0;
132*38e8c45fSAndroid Build Coastguard Worker     v.physicalTop = 0;
133*38e8c45fSAndroid Build Coastguard Worker     v.physicalRight = isRotated ? height : width;
134*38e8c45fSAndroid Build Coastguard Worker     v.physicalBottom = isRotated ? width : height;
135*38e8c45fSAndroid Build Coastguard Worker     v.deviceWidth = isRotated ? height : width;
136*38e8c45fSAndroid Build Coastguard Worker     v.deviceHeight = isRotated ? width : height;
137*38e8c45fSAndroid Build Coastguard Worker     v.isActive = isActive;
138*38e8c45fSAndroid Build Coastguard Worker     v.uniqueId = uniqueId;
139*38e8c45fSAndroid Build Coastguard Worker     v.physicalPort = physicalPort;
140*38e8c45fSAndroid Build Coastguard Worker     v.type = type;
141*38e8c45fSAndroid Build Coastguard Worker 
142*38e8c45fSAndroid Build Coastguard Worker     addDisplayViewport(v);
143*38e8c45fSAndroid Build Coastguard Worker }
144*38e8c45fSAndroid Build Coastguard Worker 
updateViewport(const DisplayViewport & viewport)145*38e8c45fSAndroid Build Coastguard Worker bool FakeInputReaderPolicy::updateViewport(const DisplayViewport& viewport) {
146*38e8c45fSAndroid Build Coastguard Worker     size_t count = mViewports.size();
147*38e8c45fSAndroid Build Coastguard Worker     for (size_t i = 0; i < count; i++) {
148*38e8c45fSAndroid Build Coastguard Worker         const DisplayViewport& currentViewport = mViewports[i];
149*38e8c45fSAndroid Build Coastguard Worker         if (currentViewport.displayId == viewport.displayId) {
150*38e8c45fSAndroid Build Coastguard Worker             mViewports[i] = viewport;
151*38e8c45fSAndroid Build Coastguard Worker             mConfig.setDisplayViewports(mViewports);
152*38e8c45fSAndroid Build Coastguard Worker             return true;
153*38e8c45fSAndroid Build Coastguard Worker         }
154*38e8c45fSAndroid Build Coastguard Worker     }
155*38e8c45fSAndroid Build Coastguard Worker     // no viewport found.
156*38e8c45fSAndroid Build Coastguard Worker     return false;
157*38e8c45fSAndroid Build Coastguard Worker }
158*38e8c45fSAndroid Build Coastguard Worker 
addExcludedDeviceName(const std::string & deviceName)159*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::addExcludedDeviceName(const std::string& deviceName) {
160*38e8c45fSAndroid Build Coastguard Worker     mConfig.excludedDeviceNames.push_back(deviceName);
161*38e8c45fSAndroid Build Coastguard Worker }
162*38e8c45fSAndroid Build Coastguard Worker 
addInputPortAssociation(const std::string & inputPort,uint8_t displayPort)163*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::addInputPortAssociation(const std::string& inputPort,
164*38e8c45fSAndroid Build Coastguard Worker                                                     uint8_t displayPort) {
165*38e8c45fSAndroid Build Coastguard Worker     mConfig.inputPortToDisplayPortAssociations.insert({inputPort, displayPort});
166*38e8c45fSAndroid Build Coastguard Worker }
167*38e8c45fSAndroid Build Coastguard Worker 
addDeviceTypeAssociation(const std::string & inputPort,const std::string & type)168*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::addDeviceTypeAssociation(const std::string& inputPort,
169*38e8c45fSAndroid Build Coastguard Worker                                                      const std::string& type) {
170*38e8c45fSAndroid Build Coastguard Worker     mConfig.deviceTypeAssociations.insert({inputPort, type});
171*38e8c45fSAndroid Build Coastguard Worker }
172*38e8c45fSAndroid Build Coastguard Worker 
addInputUniqueIdAssociation(const std::string & inputUniqueId,const std::string & displayUniqueId)173*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::addInputUniqueIdAssociation(const std::string& inputUniqueId,
174*38e8c45fSAndroid Build Coastguard Worker                                                         const std::string& displayUniqueId) {
175*38e8c45fSAndroid Build Coastguard Worker     mConfig.inputPortToDisplayUniqueIdAssociations.insert({inputUniqueId, displayUniqueId});
176*38e8c45fSAndroid Build Coastguard Worker }
177*38e8c45fSAndroid Build Coastguard Worker 
addKeyboardLayoutAssociation(const std::string & inputUniqueId,const KeyboardLayoutInfo & layoutInfo)178*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::addKeyboardLayoutAssociation(const std::string& inputUniqueId,
179*38e8c45fSAndroid Build Coastguard Worker                                                          const KeyboardLayoutInfo& layoutInfo) {
180*38e8c45fSAndroid Build Coastguard Worker     mConfig.keyboardLayoutAssociations.insert({inputUniqueId, layoutInfo});
181*38e8c45fSAndroid Build Coastguard Worker }
182*38e8c45fSAndroid Build Coastguard Worker 
addDisabledDevice(int32_t deviceId)183*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::addDisabledDevice(int32_t deviceId) {
184*38e8c45fSAndroid Build Coastguard Worker     mConfig.disabledDevices.insert(deviceId);
185*38e8c45fSAndroid Build Coastguard Worker }
186*38e8c45fSAndroid Build Coastguard Worker 
removeDisabledDevice(int32_t deviceId)187*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::removeDisabledDevice(int32_t deviceId) {
188*38e8c45fSAndroid Build Coastguard Worker     mConfig.disabledDevices.erase(deviceId);
189*38e8c45fSAndroid Build Coastguard Worker }
190*38e8c45fSAndroid Build Coastguard Worker 
getReaderConfiguration() const191*38e8c45fSAndroid Build Coastguard Worker const InputReaderConfiguration& FakeInputReaderPolicy::getReaderConfiguration() const {
192*38e8c45fSAndroid Build Coastguard Worker     return mConfig;
193*38e8c45fSAndroid Build Coastguard Worker }
194*38e8c45fSAndroid Build Coastguard Worker 
getInputDevices() const195*38e8c45fSAndroid Build Coastguard Worker const std::vector<InputDeviceInfo> FakeInputReaderPolicy::getInputDevices() const {
196*38e8c45fSAndroid Build Coastguard Worker     std::scoped_lock lock(mLock);
197*38e8c45fSAndroid Build Coastguard Worker     return mInputDevices;
198*38e8c45fSAndroid Build Coastguard Worker }
199*38e8c45fSAndroid Build Coastguard Worker 
getTouchAffineTransformation(const std::string & inputDeviceDescriptor,ui::Rotation surfaceRotation)200*38e8c45fSAndroid Build Coastguard Worker TouchAffineTransformation FakeInputReaderPolicy::getTouchAffineTransformation(
201*38e8c45fSAndroid Build Coastguard Worker         const std::string& inputDeviceDescriptor, ui::Rotation surfaceRotation) {
202*38e8c45fSAndroid Build Coastguard Worker     return transform;
203*38e8c45fSAndroid Build Coastguard Worker }
204*38e8c45fSAndroid Build Coastguard Worker 
setTouchAffineTransformation(const TouchAffineTransformation t)205*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::setTouchAffineTransformation(const TouchAffineTransformation t) {
206*38e8c45fSAndroid Build Coastguard Worker     transform = t;
207*38e8c45fSAndroid Build Coastguard Worker }
208*38e8c45fSAndroid Build Coastguard Worker 
setPointerCapture(const sp<IBinder> & window)209*38e8c45fSAndroid Build Coastguard Worker PointerCaptureRequest FakeInputReaderPolicy::setPointerCapture(const sp<IBinder>& window) {
210*38e8c45fSAndroid Build Coastguard Worker     mConfig.pointerCaptureRequest = {window, mNextPointerCaptureSequenceNumber++};
211*38e8c45fSAndroid Build Coastguard Worker     return mConfig.pointerCaptureRequest;
212*38e8c45fSAndroid Build Coastguard Worker }
213*38e8c45fSAndroid Build Coastguard Worker 
setDefaultPointerDisplayId(ui::LogicalDisplayId pointerDisplayId)214*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::setDefaultPointerDisplayId(ui::LogicalDisplayId pointerDisplayId) {
215*38e8c45fSAndroid Build Coastguard Worker     mConfig.defaultPointerDisplayId = pointerDisplayId;
216*38e8c45fSAndroid Build Coastguard Worker }
217*38e8c45fSAndroid Build Coastguard Worker 
setPointerGestureEnabled(bool enabled)218*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::setPointerGestureEnabled(bool enabled) {
219*38e8c45fSAndroid Build Coastguard Worker     mConfig.pointerGesturesEnabled = enabled;
220*38e8c45fSAndroid Build Coastguard Worker }
221*38e8c45fSAndroid Build Coastguard Worker 
getPointerGestureMovementSpeedRatio()222*38e8c45fSAndroid Build Coastguard Worker float FakeInputReaderPolicy::getPointerGestureMovementSpeedRatio() {
223*38e8c45fSAndroid Build Coastguard Worker     return mConfig.pointerGestureMovementSpeedRatio;
224*38e8c45fSAndroid Build Coastguard Worker }
225*38e8c45fSAndroid Build Coastguard Worker 
getPointerGestureZoomSpeedRatio()226*38e8c45fSAndroid Build Coastguard Worker float FakeInputReaderPolicy::getPointerGestureZoomSpeedRatio() {
227*38e8c45fSAndroid Build Coastguard Worker     return mConfig.pointerGestureZoomSpeedRatio;
228*38e8c45fSAndroid Build Coastguard Worker }
229*38e8c45fSAndroid Build Coastguard Worker 
setVelocityControlParams(const VelocityControlParameters & params)230*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::setVelocityControlParams(const VelocityControlParameters& params) {
231*38e8c45fSAndroid Build Coastguard Worker     mConfig.wheelVelocityControlParameters = params;
232*38e8c45fSAndroid Build Coastguard Worker }
233*38e8c45fSAndroid Build Coastguard Worker 
setStylusButtonMotionEventsEnabled(bool enabled)234*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::setStylusButtonMotionEventsEnabled(bool enabled) {
235*38e8c45fSAndroid Build Coastguard Worker     mConfig.stylusButtonMotionEventsEnabled = enabled;
236*38e8c45fSAndroid Build Coastguard Worker }
237*38e8c45fSAndroid Build Coastguard Worker 
setStylusPointerIconEnabled(bool enabled)238*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::setStylusPointerIconEnabled(bool enabled) {
239*38e8c45fSAndroid Build Coastguard Worker     mConfig.stylusPointerIconEnabled = enabled;
240*38e8c45fSAndroid Build Coastguard Worker }
241*38e8c45fSAndroid Build Coastguard Worker 
setIsInputMethodConnectionActive(bool active)242*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::setIsInputMethodConnectionActive(bool active) {
243*38e8c45fSAndroid Build Coastguard Worker     mIsInputMethodConnectionActive = active;
244*38e8c45fSAndroid Build Coastguard Worker }
245*38e8c45fSAndroid Build Coastguard Worker 
isInputMethodConnectionActive()246*38e8c45fSAndroid Build Coastguard Worker bool FakeInputReaderPolicy::isInputMethodConnectionActive() {
247*38e8c45fSAndroid Build Coastguard Worker     return mIsInputMethodConnectionActive;
248*38e8c45fSAndroid Build Coastguard Worker }
249*38e8c45fSAndroid Build Coastguard Worker 
getReaderConfiguration(InputReaderConfiguration * outConfig)250*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::getReaderConfiguration(InputReaderConfiguration* outConfig) {
251*38e8c45fSAndroid Build Coastguard Worker     *outConfig = mConfig;
252*38e8c45fSAndroid Build Coastguard Worker }
253*38e8c45fSAndroid Build Coastguard Worker 
notifyInputDevicesChanged(const std::vector<InputDeviceInfo> & inputDevices)254*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::notifyInputDevicesChanged(
255*38e8c45fSAndroid Build Coastguard Worker         const std::vector<InputDeviceInfo>& inputDevices) {
256*38e8c45fSAndroid Build Coastguard Worker     std::scoped_lock lock(mLock);
257*38e8c45fSAndroid Build Coastguard Worker     mInputDevices = inputDevices;
258*38e8c45fSAndroid Build Coastguard Worker     mInputDevicesChanged = true;
259*38e8c45fSAndroid Build Coastguard Worker     mDevicesChangedCondition.notify_all();
260*38e8c45fSAndroid Build Coastguard Worker }
261*38e8c45fSAndroid Build Coastguard Worker 
notifyTouchpadHardwareState(const SelfContainedHardwareState & schs,int32_t deviceId)262*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::notifyTouchpadHardwareState(const SelfContainedHardwareState& schs,
263*38e8c45fSAndroid Build Coastguard Worker                                                         int32_t deviceId) {
264*38e8c45fSAndroid Build Coastguard Worker     std::scoped_lock lock(mLock);
265*38e8c45fSAndroid Build Coastguard Worker     mTouchpadHardwareState = schs;
266*38e8c45fSAndroid Build Coastguard Worker     mTouchpadHardwareStateNotified.notify_all();
267*38e8c45fSAndroid Build Coastguard Worker }
268*38e8c45fSAndroid Build Coastguard Worker 
notifyTouchpadGestureInfo(GestureType type,int32_t deviceId)269*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::notifyTouchpadGestureInfo(GestureType type, int32_t deviceId) {
270*38e8c45fSAndroid Build Coastguard Worker     std::scoped_lock lock(mLock);
271*38e8c45fSAndroid Build Coastguard Worker }
272*38e8c45fSAndroid Build Coastguard Worker 
notifyTouchpadThreeFingerTap()273*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::notifyTouchpadThreeFingerTap() {
274*38e8c45fSAndroid Build Coastguard Worker     std::scoped_lock lock(mLock);
275*38e8c45fSAndroid Build Coastguard Worker     mTouchpadThreeFingerTapHasBeenReported = true;
276*38e8c45fSAndroid Build Coastguard Worker     mTouchpadThreeFingerTapNotified.notify_all();
277*38e8c45fSAndroid Build Coastguard Worker }
278*38e8c45fSAndroid Build Coastguard Worker 
getKeyboardLayoutOverlay(const InputDeviceIdentifier &,const std::optional<KeyboardLayoutInfo>)279*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<KeyCharacterMap> FakeInputReaderPolicy::getKeyboardLayoutOverlay(
280*38e8c45fSAndroid Build Coastguard Worker         const InputDeviceIdentifier&, const std::optional<KeyboardLayoutInfo>) {
281*38e8c45fSAndroid Build Coastguard Worker     return nullptr;
282*38e8c45fSAndroid Build Coastguard Worker }
283*38e8c45fSAndroid Build Coastguard Worker 
getDeviceAlias(const InputDeviceIdentifier &)284*38e8c45fSAndroid Build Coastguard Worker std::string FakeInputReaderPolicy::getDeviceAlias(const InputDeviceIdentifier&) {
285*38e8c45fSAndroid Build Coastguard Worker     return "";
286*38e8c45fSAndroid Build Coastguard Worker }
287*38e8c45fSAndroid Build Coastguard Worker 
waitForInputDevices(std::function<void (bool)> processDevicesChanged,std::chrono::milliseconds timeout)288*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::waitForInputDevices(std::function<void(bool)> processDevicesChanged,
289*38e8c45fSAndroid Build Coastguard Worker                                                 std::chrono::milliseconds timeout) {
290*38e8c45fSAndroid Build Coastguard Worker     std::unique_lock<std::mutex> lock(mLock);
291*38e8c45fSAndroid Build Coastguard Worker     base::ScopedLockAssertion assumeLocked(mLock);
292*38e8c45fSAndroid Build Coastguard Worker 
293*38e8c45fSAndroid Build Coastguard Worker     const bool devicesChanged =
294*38e8c45fSAndroid Build Coastguard Worker             mDevicesChangedCondition.wait_for(lock, timeout * HW_TIMEOUT_MULTIPLIER,
295*38e8c45fSAndroid Build Coastguard Worker                                               [this]() REQUIRES(mLock) {
296*38e8c45fSAndroid Build Coastguard Worker                                                   return mInputDevicesChanged;
297*38e8c45fSAndroid Build Coastguard Worker                                               });
298*38e8c45fSAndroid Build Coastguard Worker     ASSERT_NO_FATAL_FAILURE(processDevicesChanged(devicesChanged));
299*38e8c45fSAndroid Build Coastguard Worker     mInputDevicesChanged = false;
300*38e8c45fSAndroid Build Coastguard Worker }
301*38e8c45fSAndroid Build Coastguard Worker 
notifyStylusGestureStarted(int32_t deviceId,nsecs_t eventTime)302*38e8c45fSAndroid Build Coastguard Worker void FakeInputReaderPolicy::notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) {
303*38e8c45fSAndroid Build Coastguard Worker     std::scoped_lock lock(mLock);
304*38e8c45fSAndroid Build Coastguard Worker     mDeviceIdOfNotifiedStylusGesture = deviceId;
305*38e8c45fSAndroid Build Coastguard Worker     mStylusGestureNotifiedCondition.notify_all();
306*38e8c45fSAndroid Build Coastguard Worker }
307*38e8c45fSAndroid Build Coastguard Worker 
getPointerViewportForAssociatedDisplay(ui::LogicalDisplayId associatedDisplayId)308*38e8c45fSAndroid Build Coastguard Worker std::optional<DisplayViewport> FakeInputReaderPolicy::getPointerViewportForAssociatedDisplay(
309*38e8c45fSAndroid Build Coastguard Worker         ui::LogicalDisplayId associatedDisplayId) {
310*38e8c45fSAndroid Build Coastguard Worker     if (!associatedDisplayId.isValid()) {
311*38e8c45fSAndroid Build Coastguard Worker         associatedDisplayId = mConfig.defaultPointerDisplayId;
312*38e8c45fSAndroid Build Coastguard Worker     }
313*38e8c45fSAndroid Build Coastguard Worker     for (auto& viewport : mViewports) {
314*38e8c45fSAndroid Build Coastguard Worker         if (viewport.displayId == associatedDisplayId) {
315*38e8c45fSAndroid Build Coastguard Worker             return std::make_optional(viewport);
316*38e8c45fSAndroid Build Coastguard Worker         }
317*38e8c45fSAndroid Build Coastguard Worker     }
318*38e8c45fSAndroid Build Coastguard Worker     return std::nullopt;
319*38e8c45fSAndroid Build Coastguard Worker }
320*38e8c45fSAndroid Build Coastguard Worker 
321*38e8c45fSAndroid Build Coastguard Worker } // namespace android
322