Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3fa1ff80 authored by Harry Cutts's avatar Harry Cutts Committed by Android (Google) Code Review
Browse files

Merge "TouchpadInputMapper: add timer provider" into main

parents 7edcf433 8c7cb593
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -75,11 +75,12 @@ std::string dumpSet(const std::set<T>& v, std::string (*toString)(const T&) = co
}

/**
 * Convert a map to string. Both keys and values of the map should be integral type.
 * Convert a map or multimap to string. Both keys and values of the map should be integral type.
 */
template <typename K, typename V>
std::string dumpMap(const std::map<K, V>& map, std::string (*keyToString)(const K&) = constToString,
                    std::string (*valueToString)(const V&) = constToString) {
template <typename T>
std::string dumpMap(const T& map,
                    std::string (*keyToString)(const typename T::key_type&) = constToString,
                    std::string (*valueToString)(const typename T::mapped_type&) = constToString) {
    std::string out;
    for (const auto& [k, v] : map) {
        if (!out.empty()) {
@@ -104,15 +105,13 @@ std::string dumpMapKeys(const std::map<K, V>& map,
    return out.empty() ? "{}" : (out + "}");
}

/**
 * Convert a vector to a string. The values of the vector should be of a type supported by
 * constToString.
 */
/** Convert a vector to a string. */
template <typename T>
std::string dumpVector(std::vector<T> values) {
    std::string dump = constToString(values[0]);
std::string dumpVector(const std::vector<T>& values,
                       std::string (*valueToString)(const T&) = constToString) {
    std::string dump = valueToString(values[0]);
    for (size_t i = 1; i < values.size(); i++) {
        dump += ", " + constToString(values[i]);
        dump += ", " + valueToString(values[i]);
    }
    return dump;
}
+7 −0
Original line number Diff line number Diff line
@@ -20,3 +20,10 @@ flag {
  description: "Set to true to enable PointerChoreographer: the new pipeline for showing pointer icons"
  bug: "293587049"
}

flag {
  name: "enable_gestures_library_timer_provider"
  namespace: "input"
  description: "Set to true to enable timer support for the touchpad Gestures library"
  bug: "297192727"
}
+1 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ filegroup {
        "mapper/gestures/HardwareProperties.cpp",
        "mapper/gestures/HardwareStateConverter.cpp",
        "mapper/gestures/PropertyProvider.cpp",
        "mapper/gestures/TimerProvider.cpp",
    ],
}

+1 −0
Original line number Diff line number Diff line
@@ -946,6 +946,7 @@ void InputReader::dump(std::string& dump) {
        device->dump(dump, eventHubDevStr);
    }

    dump += StringPrintf(INDENT "NextTimeout: %" PRId64 "\n", mNextTimeout);
    dump += INDENT "Configuration:\n";
    dump += INDENT2 "ExcludedDeviceNames: [";
    for (size_t i = 0; i < mConfig.excludedDeviceNames.size(); i++) {
+31 −18
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@

#include <android-base/stringprintf.h>
#include <android/input.h>
#include <com_android_input_flags.h>
#include <ftl/enum.h>
#include <input/PrintTools.h>
#include <linux/input-event-codes.h>
@@ -34,8 +35,11 @@
#include "TouchCursorInputMapperCommon.h"
#include "TouchpadInputMapper.h"
#include "gestures/HardwareProperties.h"
#include "gestures/TimerProvider.h"
#include "ui/Rotation.h"

namespace input_flags = com::android::input::flags;

namespace android {

namespace {
@@ -238,6 +242,7 @@ TouchpadInputMapper::TouchpadInputMapper(InputDeviceContext& deviceContext,
      : InputMapper(deviceContext, readerConfig),
        mGestureInterpreter(NewGestureInterpreter(), DeleteGestureInterpreter),
        mPointerController(getContext()->getPointerController(getDeviceId())),
        mTimerProvider(*getContext()),
        mStateConverter(deviceContext, mMotionAccumulator),
        mGestureConverter(*getContext(), deviceContext, getDeviceId()),
        mCapturedEventConverter(*getContext(), deviceContext, mMotionAccumulator, getDeviceId()),
@@ -259,8 +264,12 @@ TouchpadInputMapper::TouchpadInputMapper(InputDeviceContext& deviceContext,
    // 2) TouchpadInputMapper is stored as a unique_ptr and not moved.
    mGestureInterpreter->SetPropProvider(const_cast<GesturesPropProvider*>(&gesturePropProvider),
                                         &mPropertyProvider);
    if (input_flags::enable_gestures_library_timer_provider()) {
        mGestureInterpreter->SetTimerProvider(const_cast<GesturesTimerProvider*>(
                                                      &kGestureTimerProvider),
                                              &mTimerProvider);
    }
    mGestureInterpreter->SetCallback(gestureInterpreterCallback, this);
    // TODO(b/251196347): set a timer provider, so the library can use timers.
}

TouchpadInputMapper::~TouchpadInputMapper() {
@@ -268,14 +277,14 @@ TouchpadInputMapper::~TouchpadInputMapper() {
        mPointerController->fade(PointerControllerInterface::Transition::IMMEDIATE);
    }

    // The gesture interpreter's destructor will call its property provider's free function for all
    // gesture properties, in this case calling PropertyProvider::freeProperty using a raw pointer
    // to mPropertyProvider. Depending on the declaration order in TouchpadInputMapper.h, this may
    // happen after mPropertyProvider has been destructed, causing allocation errors. Depending on
    // declaration order to avoid crashes seems rather fragile, so explicitly clear the property
    // provider here to ensure all the freeProperty calls happen before mPropertyProvider is
    // destructed.
    // The gesture interpreter's destructor will try to free its property and timer providers,
    // calling PropertyProvider::freeProperty and TimerProvider::freeTimer using a raw pointers.
    // Depending on the declaration order in TouchpadInputMapper.h, those providers may have already
    // been freed, causing allocation errors or use-after-free bugs. Depending on declaration order
    // to avoid this seems rather fragile, so explicitly clear the providers here to ensure all the
    // freeProperty and freeTimer calls happen before the providers are destructed.
    mGestureInterpreter->SetPropProvider(nullptr, nullptr);
    mGestureInterpreter->SetTimerProvider(nullptr, nullptr);
}

uint32_t TouchpadInputMapper::getSources() const {
@@ -293,9 +302,6 @@ void TouchpadInputMapper::populateDeviceInfo(InputDeviceInfo& info) {

void TouchpadInputMapper::dump(std::string& dump) {
    dump += INDENT2 "Touchpad Input Mapper:\n";
    if (mProcessing) {
        dump += INDENT3 "Currently processing a hardware state\n";
    }
    if (mResettingInterpreter) {
        dump += INDENT3 "Currently resetting gesture interpreter\n";
    }
@@ -304,6 +310,12 @@ void TouchpadInputMapper::dump(std::string& dump) {
    dump += addLinePrefix(mGestureConverter.dump(), INDENT4);
    dump += INDENT3 "Gesture properties:\n";
    dump += addLinePrefix(mPropertyProvider.dump(), INDENT4);
    if (input_flags::enable_gestures_library_timer_provider()) {
        dump += INDENT3 "Timer provider:\n";
        dump += addLinePrefix(mTimerProvider.dump(), INDENT4);
    } else {
        dump += INDENT3 "Timer provider: disabled by flag\n";
    }
    dump += INDENT3 "Captured event converter:\n";
    dump += addLinePrefix(mCapturedEventConverter.dump(), INDENT4);
    dump += StringPrintf(INDENT3 "DisplayId: %s\n", toString(mDisplayId).c_str());
@@ -449,13 +461,18 @@ void TouchpadInputMapper::updatePalmDetectionMetrics() {
std::list<NotifyArgs> TouchpadInputMapper::sendHardwareState(nsecs_t when, nsecs_t readTime,
                                                             SelfContainedHardwareState schs) {
    ALOGD_IF(DEBUG_TOUCHPAD_GESTURES, "New hardware state: %s", schs.state.String().c_str());
    mProcessing = true;
    mGestureInterpreter->PushHardwareState(&schs.state);
    mProcessing = false;

    return processGestures(when, readTime);
}

std::list<NotifyArgs> TouchpadInputMapper::timeoutExpired(nsecs_t when) {
    if (!input_flags::enable_gestures_library_timer_provider()) {
        return {};
    }
    mTimerProvider.triggerCallbacks(when);
    return processGestures(when, when);
}

void TouchpadInputMapper::consumeGesture(const Gesture* gesture) {
    ALOGD_IF(DEBUG_TOUCHPAD_GESTURES, "Gesture ready: %s", gesture->String().c_str());
    if (mResettingInterpreter) {
@@ -463,10 +480,6 @@ void TouchpadInputMapper::consumeGesture(const Gesture* gesture) {
        // ignore any gestures produced from the interpreter while we're resetting it.
        return;
    }
    if (!mProcessing) {
        ALOGE("Received gesture outside of the normal processing flow; ignoring it.");
        return;
    }
    mGesturesToProcess.push_back(*gesture);
}

Loading