• 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 #pragma once
18 
19 #include <list>
20 #include <memory>
21 #include <set>
22 #include <vector>
23 
24 #include <PointerControllerInterface.h>
25 #include <utils/Timers.h>
26 
27 #include "CapturedTouchpadEventConverter.h"
28 #include "EventHub.h"
29 #include "InputDevice.h"
30 #include "InputMapper.h"
31 #include "InputReaderBase.h"
32 #include "NotifyArgs.h"
33 #include "accumulator/MultiTouchMotionAccumulator.h"
34 #include "gestures/GestureConverter.h"
35 #include "gestures/HardwareStateConverter.h"
36 #include "gestures/PropertyProvider.h"
37 
38 #include "include/gestures.h"
39 
40 namespace android {
41 
42 class TouchpadInputMapper : public InputMapper {
43 public:
44     template <class T, class... Args>
45     friend std::unique_ptr<T> createInputMapper(InputDeviceContext& deviceContext,
46                                                 const InputReaderConfiguration& readerConfig,
47                                                 Args... args);
48     ~TouchpadInputMapper();
49 
50     uint32_t getSources() const override;
51     void populateDeviceInfo(InputDeviceInfo& deviceInfo) override;
52     void dump(std::string& dump) override;
53 
54     [[nodiscard]] std::list<NotifyArgs> reconfigure(nsecs_t when,
55                                                     const InputReaderConfiguration& config,
56                                                     ConfigurationChanges changes) override;
57     [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override;
58     [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override;
59 
60     void consumeGesture(const Gesture* gesture);
61 
62     // A subset of InputDeviceIdentifier used for logging metrics, to avoid storing a copy of the
63     // strings in that bigger struct.
64     using MetricsIdentifier = std::tuple<uint16_t /*busId*/, uint16_t /*vendorId*/,
65                                          uint16_t /*productId*/, uint16_t /*version*/>;
66 
67 private:
68     void resetGestureInterpreter(nsecs_t when);
69     explicit TouchpadInputMapper(InputDeviceContext& deviceContext,
70                                  const InputReaderConfiguration& readerConfig);
71     void updatePalmDetectionMetrics();
72     [[nodiscard]] std::list<NotifyArgs> sendHardwareState(nsecs_t when, nsecs_t readTime,
73                                                           SelfContainedHardwareState schs);
74     [[nodiscard]] std::list<NotifyArgs> processGestures(nsecs_t when, nsecs_t readTime);
75 
76     std::unique_ptr<gestures::GestureInterpreter, void (*)(gestures::GestureInterpreter*)>
77             mGestureInterpreter;
78     std::shared_ptr<PointerControllerInterface> mPointerController;
79 
80     PropertyProvider mPropertyProvider;
81 
82     // The MultiTouchMotionAccumulator is shared between the HardwareStateConverter and
83     // CapturedTouchpadEventConverter, so that if the touchpad is captured or released while touches
84     // are down, the relevant converter can still benefit from the current axis values stored in the
85     // accumulator.
86     MultiTouchMotionAccumulator mMotionAccumulator;
87 
88     HardwareStateConverter mStateConverter;
89     GestureConverter mGestureConverter;
90     CapturedTouchpadEventConverter mCapturedEventConverter;
91 
92     bool mPointerCaptured = false;
93     bool mProcessing = false;
94     bool mResettingInterpreter = false;
95     std::vector<Gesture> mGesturesToProcess;
96 
metricsIdFromInputDeviceIdentifier(const InputDeviceIdentifier & id)97     static MetricsIdentifier metricsIdFromInputDeviceIdentifier(const InputDeviceIdentifier& id) {
98         return std::make_tuple(id.bus, id.vendor, id.product, id.version);
99     }
100     const MetricsIdentifier mMetricsId;
101     // Tracking IDs for touches on the pad in the last evdev frame.
102     std::set<int32_t> mLastFrameTrackingIds;
103     // Tracking IDs for touches that have at some point been reported as palms by the touchpad.
104     std::set<int32_t> mPalmTrackingIds;
105 };
106 
107 } // namespace android
108