• 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 #include "../Macros.h"
18 
19 #include <algorithm>
20 #include <chrono>
21 #include <iterator>
22 #include <limits>
23 #include <map>
24 #include <mutex>
25 #include <optional>
26 
27 #include <android-base/logging.h>
28 #include <android-base/stringprintf.h>
29 #include <android-base/thread_annotations.h>
30 #include <android/input.h>
31 #include <com_android_input_flags.h>
32 #include <ftl/enum.h>
33 #include <input/AccelerationCurve.h>
34 #include <input/PrintTools.h>
35 #include <linux/input-event-codes.h>
36 #include <log/log_main.h>
37 #include <stats_pull_atom_callback.h>
38 #include <statslog.h>
39 #include "TouchCursorInputMapperCommon.h"
40 #include "TouchpadInputMapper.h"
41 #include "gestures/HardwareProperties.h"
42 #include "gestures/TimerProvider.h"
43 #include "ui/Rotation.h"
44 
45 namespace input_flags = com::android::input::flags;
46 
47 namespace android {
48 
49 namespace {
50 
51 /**
52  * Log details of each gesture output by the gestures library.
53  * Enable this via "adb shell setprop log.tag.TouchpadInputMapperGestures DEBUG" (requires
54  * restarting the shell)
55  */
56 const bool DEBUG_TOUCHPAD_GESTURES =
57         __android_log_is_loggable(ANDROID_LOG_DEBUG, "TouchpadInputMapperGestures",
58                                   ANDROID_LOG_INFO);
59 
createAccelerationCurveForSensitivity(int32_t sensitivity,size_t propertySize)60 std::vector<double> createAccelerationCurveForSensitivity(int32_t sensitivity,
61                                                           size_t propertySize) {
62     std::vector<AccelerationCurveSegment> segments =
63             createAccelerationCurveForPointerSensitivity(sensitivity);
64     LOG_ALWAYS_FATAL_IF(propertySize < 4 * segments.size());
65     std::vector<double> output(propertySize, 0);
66 
67     // The Gestures library uses functions of the following form to define curve segments, where a,
68     // b, and c can be specified by us:
69     //     output_speed(input_speed_mm) = a * input_speed_mm ^ 2 + b * input_speed_mm + c
70     //
71     // (a, b, and c are also called sqr_, mul_, and int_ in the Gestures library code.)
72     //
73     // createAccelerationCurveForPointerSensitivity gives us parameters for a function of the form:
74     //     gain(input_speed_mm) = baseGain + reciprocal / input_speed_mm
75     // Where "gain" is a multiplier applied to the input speed to produce the output speed:
76     //     output_speed(input_speed_mm) = input_speed_mm * gain(input_speed_mm)
77     //
78     // To put our function in the library's form, we substitute it into the function above:
79     //     output_speed(input_speed_mm) = input_speed_mm * (baseGain + reciprocal / input_speed_mm)
80     // then expand the brackets so that input_speed_mm cancels out for the reciprocal term:
81     //     gain(input_speed_mm) = baseGain * input_speed_mm + reciprocal
82     //
83     // This gives us the following parameters for the Gestures library function form:
84     //     a = 0
85     //     b = baseGain
86     //     c = reciprocal
87 
88     size_t i = 0;
89     for (AccelerationCurveSegment seg : segments) {
90         // The library's curve format consists of four doubles per segment:
91         // * maximum pointer speed for the segment (mm/s)
92         // * multiplier for the x² term (a.k.a. "a" or "sqr")
93         // * multiplier for the x term (a.k.a. "b" or "mul")
94         // * the intercept (a.k.a. "c" or "int")
95         // (see struct CurveSegment in the library's AccelFilterInterpreter)
96         output[i + 0] = seg.maxPointerSpeedMmPerS;
97         output[i + 1] = 0;
98         output[i + 2] = seg.baseGain;
99         output[i + 3] = seg.reciprocal;
100         i += 4;
101     }
102 
103     return output;
104 }
105 
gestureInterpreterCallback(void * clientData,const Gesture * gesture)106 void gestureInterpreterCallback(void* clientData, const Gesture* gesture) {
107     TouchpadInputMapper* mapper = static_cast<TouchpadInputMapper*>(clientData);
108     mapper->consumeGesture(gesture);
109 }
110 
linuxBusToInputDeviceBusEnum(int32_t linuxBus,bool isUsiStylus)111 int32_t linuxBusToInputDeviceBusEnum(int32_t linuxBus, bool isUsiStylus) {
112     if (isUsiStylus) {
113         // This is a stylus connected over the Universal Stylus Initiative (USI) protocol.
114         // For metrics purposes, we treat this protocol as a separate bus.
115         return util::INPUT_DEVICE_USAGE_REPORTED__DEVICE_BUS__USI;
116     }
117 
118     // When adding cases to this switch, also add them to the copy of this method in
119     // InputDeviceMetricsCollector.cpp.
120     // TODO(b/286394420): deduplicate this method with the one in InputDeviceMetricsCollector.cpp.
121     switch (linuxBus) {
122         case BUS_USB:
123             return util::INPUT_DEVICE_USAGE_REPORTED__DEVICE_BUS__USB;
124         case BUS_BLUETOOTH:
125             return util::INPUT_DEVICE_USAGE_REPORTED__DEVICE_BUS__BLUETOOTH;
126         default:
127             return util::INPUT_DEVICE_USAGE_REPORTED__DEVICE_BUS__OTHER;
128     }
129 }
130 
131 class MetricsAccumulator {
132 public:
getInstance()133     static MetricsAccumulator& getInstance() {
134         static MetricsAccumulator sAccumulator;
135         return sAccumulator;
136     }
137 
recordFinger(const TouchpadInputMapper::MetricsIdentifier & id)138     void recordFinger(const TouchpadInputMapper::MetricsIdentifier& id) {
139         std::scoped_lock lock(mLock);
140         mCounters[id].fingers++;
141     }
142 
recordPalm(const TouchpadInputMapper::MetricsIdentifier & id)143     void recordPalm(const TouchpadInputMapper::MetricsIdentifier& id) {
144         std::scoped_lock lock(mLock);
145         mCounters[id].palms++;
146     }
147 
148     // Checks whether a Gesture struct is for the end of a gesture that we log metrics for, and
149     // records it if so.
processGesture(const TouchpadInputMapper::MetricsIdentifier & id,const Gesture & gesture)150     void processGesture(const TouchpadInputMapper::MetricsIdentifier& id, const Gesture& gesture) {
151         std::scoped_lock lock(mLock);
152         switch (gesture.type) {
153             case kGestureTypeFling:
154                 if (gesture.details.fling.fling_state == GESTURES_FLING_START) {
155                     // Indicates the end of a two-finger scroll gesture.
156                     mCounters[id].twoFingerSwipeGestures++;
157                 }
158                 break;
159             case kGestureTypeSwipeLift:
160                 mCounters[id].threeFingerSwipeGestures++;
161                 break;
162             case kGestureTypeFourFingerSwipeLift:
163                 mCounters[id].fourFingerSwipeGestures++;
164                 break;
165             case kGestureTypePinch:
166                 if (gesture.details.pinch.zoom_state == GESTURES_ZOOM_END) {
167                     mCounters[id].pinchGestures++;
168                 }
169                 break;
170             default:
171                 // We're not interested in any other gestures.
172                 break;
173         }
174     }
175 
176 private:
MetricsAccumulator()177     MetricsAccumulator() {
178         AStatsManager_setPullAtomCallback(android::util::TOUCHPAD_USAGE, /*metadata=*/nullptr,
179                                           MetricsAccumulator::pullAtomCallback, /*cookie=*/nullptr);
180     }
181 
~MetricsAccumulator()182     ~MetricsAccumulator() { AStatsManager_clearPullAtomCallback(android::util::TOUCHPAD_USAGE); }
183 
pullAtomCallback(int32_t atomTag,AStatsEventList * outEventList,void * cookie)184     static AStatsManager_PullAtomCallbackReturn pullAtomCallback(int32_t atomTag,
185                                                                  AStatsEventList* outEventList,
186                                                                  void* cookie) {
187         LOG_ALWAYS_FATAL_IF(atomTag != android::util::TOUCHPAD_USAGE);
188         MetricsAccumulator& accumulator = MetricsAccumulator::getInstance();
189         accumulator.produceAtomsAndReset(*outEventList);
190         return AStatsManager_PULL_SUCCESS;
191     }
192 
produceAtomsAndReset(AStatsEventList & outEventList)193     void produceAtomsAndReset(AStatsEventList& outEventList) {
194         std::scoped_lock lock(mLock);
195         produceAtomsLocked(outEventList);
196         resetCountersLocked();
197     }
198 
produceAtomsLocked(AStatsEventList & outEventList) const199     void produceAtomsLocked(AStatsEventList& outEventList) const REQUIRES(mLock) {
200         for (auto& [id, counters] : mCounters) {
201             auto [busId, vendorId, productId, versionId] = id;
202             addAStatsEvent(&outEventList, android::util::TOUCHPAD_USAGE, vendorId, productId,
203                            versionId, linuxBusToInputDeviceBusEnum(busId, /*isUsi=*/false),
204                            counters.fingers, counters.palms, counters.twoFingerSwipeGestures,
205                            counters.threeFingerSwipeGestures, counters.fourFingerSwipeGestures,
206                            counters.pinchGestures);
207         }
208     }
209 
resetCountersLocked()210     void resetCountersLocked() REQUIRES(mLock) { mCounters.clear(); }
211 
212     // Stores the counters for a specific touchpad model. Fields have the same meanings as those of
213     // the TouchpadUsage atom; see that definition for detailed documentation.
214     struct Counters {
215         int32_t fingers = 0;
216         int32_t palms = 0;
217 
218         int32_t twoFingerSwipeGestures = 0;
219         int32_t threeFingerSwipeGestures = 0;
220         int32_t fourFingerSwipeGestures = 0;
221         int32_t pinchGestures = 0;
222     };
223 
224     // Metrics are aggregated by device model and version, so if two devices of the same model and
225     // version are connected at once, they will have the same counters.
226     std::map<TouchpadInputMapper::MetricsIdentifier, Counters> mCounters GUARDED_BY(mLock);
227 
228     // Metrics are pulled by a binder thread, so we need to guard them with a mutex.
229     mutable std::mutex mLock;
230 };
231 
232 } // namespace
233 
TouchpadInputMapper(InputDeviceContext & deviceContext,const InputReaderConfiguration & readerConfig)234 TouchpadInputMapper::TouchpadInputMapper(InputDeviceContext& deviceContext,
235                                          const InputReaderConfiguration& readerConfig)
236       : InputMapper(deviceContext, readerConfig),
237         mGestureInterpreter(NewGestureInterpreter(), DeleteGestureInterpreter),
238         mTimerProvider(*getContext()),
239         mStateConverter(deviceContext, mMotionAccumulator),
240         mGestureConverter(*getContext(), deviceContext, getDeviceId()),
241         mCapturedEventConverter(*getContext(), deviceContext, mMotionAccumulator, getDeviceId()),
242         mMetricsId(metricsIdFromInputDeviceIdentifier(deviceContext.getDeviceIdentifier())) {
243     RawAbsoluteAxisInfo slotAxisInfo;
244     deviceContext.getAbsoluteAxisInfo(ABS_MT_SLOT, &slotAxisInfo);
245     if (!slotAxisInfo.valid || slotAxisInfo.maxValue < 0) {
246         LOG(WARNING) << "Touchpad " << deviceContext.getName()
247                      << " doesn't have a valid ABS_MT_SLOT axis, and probably won't work properly.";
248         slotAxisInfo.maxValue = 0;
249     }
250     mMotionAccumulator.configure(deviceContext, slotAxisInfo.maxValue + 1, true);
251 
252     mGestureInterpreter->Initialize(GESTURES_DEVCLASS_TOUCHPAD);
253     mGestureInterpreter->SetHardwareProperties(createHardwareProperties(deviceContext));
254     // Even though we don't explicitly delete copy/move semantics, it's safe to
255     // give away pointers to TouchpadInputMapper and its members here because
256     // 1) mGestureInterpreter's lifecycle is determined by TouchpadInputMapper, and
257     // 2) TouchpadInputMapper is stored as a unique_ptr and not moved.
258     mGestureInterpreter->SetPropProvider(const_cast<GesturesPropProvider*>(&gesturePropProvider),
259                                          &mPropertyProvider);
260     if (input_flags::enable_gestures_library_timer_provider()) {
261         mGestureInterpreter->SetTimerProvider(const_cast<GesturesTimerProvider*>(
262                                                       &kGestureTimerProvider),
263                                               &mTimerProvider);
264     }
265     mGestureInterpreter->SetCallback(gestureInterpreterCallback, this);
266 }
267 
~TouchpadInputMapper()268 TouchpadInputMapper::~TouchpadInputMapper() {
269     // The gesture interpreter's destructor will try to free its property and timer providers,
270     // calling PropertyProvider::freeProperty and TimerProvider::freeTimer using a raw pointers.
271     // Depending on the declaration order in TouchpadInputMapper.h, those providers may have already
272     // been freed, causing allocation errors or use-after-free bugs. Depending on declaration order
273     // to avoid this seems rather fragile, so explicitly clear the providers here to ensure all the
274     // freeProperty and freeTimer calls happen before the providers are destructed.
275     mGestureInterpreter->SetPropProvider(nullptr, nullptr);
276     mGestureInterpreter->SetTimerProvider(nullptr, nullptr);
277 }
278 
getSources() const279 uint32_t TouchpadInputMapper::getSources() const {
280     return AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD;
281 }
282 
populateDeviceInfo(InputDeviceInfo & info)283 void TouchpadInputMapper::populateDeviceInfo(InputDeviceInfo& info) {
284     InputMapper::populateDeviceInfo(info);
285     if (mPointerCaptured) {
286         mCapturedEventConverter.populateMotionRanges(info);
287     } else {
288         mGestureConverter.populateMotionRanges(info);
289     }
290 }
291 
dump(std::string & dump)292 void TouchpadInputMapper::dump(std::string& dump) {
293     dump += INDENT2 "Touchpad Input Mapper:\n";
294     if (mResettingInterpreter) {
295         dump += INDENT3 "Currently resetting gesture interpreter\n";
296     }
297     dump += StringPrintf(INDENT3 "Pointer captured: %s\n", toString(mPointerCaptured));
298     dump += INDENT3 "Gesture converter:\n";
299     dump += addLinePrefix(mGestureConverter.dump(), INDENT4);
300     dump += INDENT3 "Gesture properties:\n";
301     dump += addLinePrefix(mPropertyProvider.dump(), INDENT4);
302     if (input_flags::enable_gestures_library_timer_provider()) {
303         dump += INDENT3 "Timer provider:\n";
304         dump += addLinePrefix(mTimerProvider.dump(), INDENT4);
305     } else {
306         dump += INDENT3 "Timer provider: disabled by flag\n";
307     }
308     dump += INDENT3 "Captured event converter:\n";
309     dump += addLinePrefix(mCapturedEventConverter.dump(), INDENT4);
310     dump += StringPrintf(INDENT3 "DisplayId: %s\n",
311                          toString(mDisplayId, streamableToString).c_str());
312 }
313 
reconfigure(nsecs_t when,const InputReaderConfiguration & config,ConfigurationChanges changes)314 std::list<NotifyArgs> TouchpadInputMapper::reconfigure(nsecs_t when,
315                                                        const InputReaderConfiguration& config,
316                                                        ConfigurationChanges changes) {
317     if (!changes.any()) {
318         // First time configuration
319         mPropertyProvider.loadPropertiesFromIdcFile(getDeviceContext().getConfiguration());
320     }
321 
322     if (!changes.any() || changes.test(InputReaderConfiguration::Change::DISPLAY_INFO)) {
323         mDisplayId = ui::LogicalDisplayId::INVALID;
324         std::optional<DisplayViewport> resolvedViewport;
325         std::optional<FloatRect> boundsInLogicalDisplay;
326         if (auto assocViewport = mDeviceContext.getAssociatedViewport(); assocViewport) {
327             // This InputDevice is associated with a viewport.
328             // Only generate events for the associated display.
329             mDisplayId = assocViewport->displayId;
330             resolvedViewport = *assocViewport;
331         } else {
332             // The InputDevice is not associated with a viewport, but it controls the mouse pointer.
333             // Always use DISPLAY_ID_NONE for touchpad events.
334             // PointerChoreographer will make it target the correct the displayId later.
335             resolvedViewport = getContext()->getPolicy()->getPointerViewportForAssociatedDisplay();
336             mDisplayId = resolvedViewport ? std::make_optional(ui::LogicalDisplayId::INVALID)
337                                           : std::nullopt;
338         }
339 
340         mGestureConverter.setDisplayId(mDisplayId);
341         mGestureConverter.setOrientation(resolvedViewport
342                                                  ? getInverseRotation(resolvedViewport->orientation)
343                                                  : ui::ROTATION_0);
344 
345         if (!boundsInLogicalDisplay) {
346             boundsInLogicalDisplay = resolvedViewport
347                     ? FloatRect{static_cast<float>(resolvedViewport->logicalLeft),
348                                 static_cast<float>(resolvedViewport->logicalTop),
349                                 static_cast<float>(resolvedViewport->logicalRight - 1),
350                                 static_cast<float>(resolvedViewport->logicalBottom - 1)}
351                     : FloatRect{0, 0, 0, 0};
352         }
353         mGestureConverter.setBoundsInLogicalDisplay(*boundsInLogicalDisplay);
354 
355         bumpGeneration();
356     }
357     if (!changes.any() || changes.test(InputReaderConfiguration::Change::TOUCHPAD_SETTINGS)) {
358         mPropertyProvider.getProperty("Use Custom Touchpad Pointer Accel Curve")
359                 .setBoolValues({true});
360         GesturesProp accelCurveProp = mPropertyProvider.getProperty("Pointer Accel Curve");
361         accelCurveProp.setRealValues(
362                 createAccelerationCurveForSensitivity(config.touchpadPointerSpeed,
363                                                       accelCurveProp.getCount()));
364         mPropertyProvider.getProperty("Use Custom Touchpad Scroll Accel Curve")
365                 .setBoolValues({true});
366         GesturesProp scrollCurveProp = mPropertyProvider.getProperty("Scroll Accel Curve");
367         scrollCurveProp.setRealValues(
368                 createAccelerationCurveForSensitivity(config.touchpadPointerSpeed,
369                                                       scrollCurveProp.getCount()));
370         mPropertyProvider.getProperty("Scroll X Out Scale").setRealValues({1.0});
371         mPropertyProvider.getProperty("Scroll Y Out Scale").setRealValues({1.0});
372         mPropertyProvider.getProperty("Invert Scrolling")
373                 .setBoolValues({config.touchpadNaturalScrollingEnabled});
374         mPropertyProvider.getProperty("Tap Enable")
375                 .setBoolValues({config.touchpadTapToClickEnabled});
376         mPropertyProvider.getProperty("Tap Drag Enable")
377                 .setBoolValues({config.touchpadTapDraggingEnabled});
378         mPropertyProvider.getProperty("Button Right Click Zone Enable")
379                 .setBoolValues({config.touchpadRightClickZoneEnabled});
380     }
381     std::list<NotifyArgs> out;
382     if ((!changes.any() && config.pointerCaptureRequest.isEnable()) ||
383         changes.test(InputReaderConfiguration::Change::POINTER_CAPTURE)) {
384         mPointerCaptured = config.pointerCaptureRequest.isEnable();
385         // The motion ranges are going to change, so bump the generation to clear the cached ones.
386         bumpGeneration();
387         if (mPointerCaptured) {
388             // The touchpad is being captured, so we need to tidy up any fake fingers etc. that are
389             // still being reported for a gesture in progress.
390             out += reset(when);
391         } else {
392             // We're transitioning from captured to uncaptured.
393             mCapturedEventConverter.reset();
394         }
395         if (changes.any()) {
396             out.push_back(NotifyDeviceResetArgs(getContext()->getNextId(), when, getDeviceId()));
397         }
398     }
399     return out;
400 }
401 
reset(nsecs_t when)402 std::list<NotifyArgs> TouchpadInputMapper::reset(nsecs_t when) {
403     mStateConverter.reset();
404     resetGestureInterpreter(when);
405     std::list<NotifyArgs> out = mGestureConverter.reset(when);
406     out += InputMapper::reset(when);
407     return out;
408 }
409 
resetGestureInterpreter(nsecs_t when)410 void TouchpadInputMapper::resetGestureInterpreter(nsecs_t when) {
411     // The GestureInterpreter has no official reset method, but sending a HardwareState with no
412     // fingers down or buttons pressed should get it into a clean state.
413     HardwareState state;
414     state.timestamp = std::chrono::duration<stime_t>(std::chrono::nanoseconds(when)).count();
415     mResettingInterpreter = true;
416     mGestureInterpreter->PushHardwareState(&state);
417     mResettingInterpreter = false;
418 }
419 
process(const RawEvent & rawEvent)420 std::list<NotifyArgs> TouchpadInputMapper::process(const RawEvent& rawEvent) {
421     if (mPointerCaptured) {
422         return mCapturedEventConverter.process(rawEvent);
423     }
424     if (mMotionAccumulator.getActiveSlotsCount() == 0) {
425         mGestureStartTime = rawEvent.when;
426     }
427     std::optional<SelfContainedHardwareState> state = mStateConverter.processRawEvent(rawEvent);
428     if (state) {
429         updatePalmDetectionMetrics();
430         return sendHardwareState(rawEvent.when, rawEvent.readTime, *state);
431     } else {
432         return {};
433     }
434 }
435 
updatePalmDetectionMetrics()436 void TouchpadInputMapper::updatePalmDetectionMetrics() {
437     std::set<int32_t> currentTrackingIds;
438     for (size_t i = 0; i < mMotionAccumulator.getSlotCount(); i++) {
439         const MultiTouchMotionAccumulator::Slot& slot = mMotionAccumulator.getSlot(i);
440         if (!slot.isInUse()) {
441             continue;
442         }
443         currentTrackingIds.insert(slot.getTrackingId());
444         if (slot.getToolType() == ToolType::PALM) {
445             mPalmTrackingIds.insert(slot.getTrackingId());
446         }
447     }
448     std::vector<int32_t> liftedTouches;
449     std::set_difference(mLastFrameTrackingIds.begin(), mLastFrameTrackingIds.end(),
450                         currentTrackingIds.begin(), currentTrackingIds.end(),
451                         std::inserter(liftedTouches, liftedTouches.begin()));
452     for (int32_t trackingId : liftedTouches) {
453         if (mPalmTrackingIds.erase(trackingId) > 0) {
454             MetricsAccumulator::getInstance().recordPalm(mMetricsId);
455         } else {
456             MetricsAccumulator::getInstance().recordFinger(mMetricsId);
457         }
458     }
459     mLastFrameTrackingIds = currentTrackingIds;
460 }
461 
sendHardwareState(nsecs_t when,nsecs_t readTime,SelfContainedHardwareState schs)462 std::list<NotifyArgs> TouchpadInputMapper::sendHardwareState(nsecs_t when, nsecs_t readTime,
463                                                              SelfContainedHardwareState schs) {
464     ALOGD_IF(DEBUG_TOUCHPAD_GESTURES, "New hardware state: %s", schs.state.String().c_str());
465     mGestureInterpreter->PushHardwareState(&schs.state);
466     return processGestures(when, readTime);
467 }
468 
timeoutExpired(nsecs_t when)469 std::list<NotifyArgs> TouchpadInputMapper::timeoutExpired(nsecs_t when) {
470     if (!input_flags::enable_gestures_library_timer_provider()) {
471         return {};
472     }
473     mTimerProvider.triggerCallbacks(when);
474     return processGestures(when, when);
475 }
476 
consumeGesture(const Gesture * gesture)477 void TouchpadInputMapper::consumeGesture(const Gesture* gesture) {
478     ALOGD_IF(DEBUG_TOUCHPAD_GESTURES, "Gesture ready: %s", gesture->String().c_str());
479     if (mResettingInterpreter) {
480         // We already handle tidying up fake fingers etc. in GestureConverter::reset, so we should
481         // ignore any gestures produced from the interpreter while we're resetting it.
482         return;
483     }
484     mGesturesToProcess.push_back(*gesture);
485 }
486 
processGestures(nsecs_t when,nsecs_t readTime)487 std::list<NotifyArgs> TouchpadInputMapper::processGestures(nsecs_t when, nsecs_t readTime) {
488     std::list<NotifyArgs> out = {};
489     if (mDisplayId) {
490         MetricsAccumulator& metricsAccumulator = MetricsAccumulator::getInstance();
491         for (Gesture& gesture : mGesturesToProcess) {
492             out += mGestureConverter.handleGesture(when, readTime, mGestureStartTime, gesture);
493             metricsAccumulator.processGesture(mMetricsId, gesture);
494         }
495     }
496     mGesturesToProcess.clear();
497     return out;
498 }
499 
getAssociatedDisplayId()500 std::optional<ui::LogicalDisplayId> TouchpadInputMapper::getAssociatedDisplayId() {
501     return mDisplayId;
502 }
503 
504 } // namespace android
505