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