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

Commit 34216dcf authored by Vaibhav Devmurari's avatar Vaibhav Devmurari Committed by Android (Google) Code Review
Browse files

Merge "Add bounce keys input filter" into main

parents b1cd5191 953e6a44
Loading
Loading
Loading
Loading
+24 −8
Original line number Diff line number Diff line
@@ -22,16 +22,19 @@ namespace android {

using aidl::com::android::server::inputflinger::IInputFilter;
using AidlKeyEvent = aidl::com::android::server::inputflinger::KeyEvent;
using aidl::com::android::server::inputflinger::KeyEventAction;
using AidlDeviceInfo = aidl::com::android::server::inputflinger::DeviceInfo;
using aidl::android::hardware::input::common::Source;

AidlKeyEvent notifyKeyArgsToKeyEvent(const NotifyKeyArgs& args) {
    AidlKeyEvent event;
    event.id = args.id;
    event.eventTime = args.eventTime;
    event.deviceId = args.deviceId;
    event.source = args.source;
    event.source = static_cast<Source>(args.source);
    event.displayId = args.displayId;
    event.policyFlags = args.policyFlags;
    event.action = args.action;
    event.action = static_cast<KeyEventAction>(args.action);
    event.flags = args.flags;
    event.keyCode = args.keyCode;
    event.scanCode = args.scanCode;
@@ -42,9 +45,10 @@ AidlKeyEvent notifyKeyArgsToKeyEvent(const NotifyKeyArgs& args) {
}

NotifyKeyArgs keyEventToNotifyKeyArgs(const AidlKeyEvent& event) {
    return NotifyKeyArgs(event.id, event.eventTime, event.readTime, event.deviceId, event.source,
                         event.displayId, event.policyFlags, event.action, event.flags,
                         event.keyCode, event.scanCode, event.metaState, event.downTime);
    return NotifyKeyArgs(event.id, event.eventTime, event.readTime, event.deviceId,
                         static_cast<uint32_t>(event.source), event.displayId, event.policyFlags,
                         static_cast<int32_t>(event.action), event.flags, event.keyCode,
                         event.scanCode, event.metaState, event.downTime);
}

namespace {
@@ -71,11 +75,14 @@ InputFilter::InputFilter(InputListenerInterface& listener, IInputFlingerRust& ru

void InputFilter::notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) {
    if (isFilterEnabled()) {
        std::vector<int32_t> deviceIds;
        std::vector<AidlDeviceInfo> deviceInfos;
        for (auto info : args.inputDeviceInfos) {
            deviceIds.push_back(info.getId());
            AidlDeviceInfo aidlInfo;
            aidlInfo.deviceId = info.getId();
            aidlInfo.external = info.isExternal();
            deviceInfos.push_back(aidlInfo);
        }
        LOG_ALWAYS_FATAL_IF(!mInputFilterRust->notifyInputDevicesChanged(deviceIds).isOk());
        LOG_ALWAYS_FATAL_IF(!mInputFilterRust->notifyInputDevicesChanged(deviceInfos).isOk());
    }
    mNextListener.notify(args);
}
@@ -122,6 +129,15 @@ bool InputFilter::isFilterEnabled() {
    return result;
}

void InputFilter::setAccessibilityBounceKeysThreshold(nsecs_t threshold) {
    std::scoped_lock _l(mLock);

    if (mConfig.bounceKeysThresholdNs != threshold) {
        mConfig.bounceKeysThresholdNs = threshold;
        LOG_ALWAYS_FATAL_IF(!mInputFilterRust->notifyConfigurationChanged(mConfig).isOk());
    }
}

void InputFilter::dump(std::string& dump) {
    dump += "InputFilter:\n";
}
+7 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#pragma once

#include <aidl/com/android/server/inputflinger/IInputFlingerRust.h>
#include <utils/Mutex.h>
#include "InputListener.h"
#include "NotifyArgs.h"

@@ -31,6 +32,7 @@ public:
     * This method may be called on any thread (usually by the input manager on a binder thread).
     */
    virtual void dump(std::string& dump) = 0;
    virtual void setAccessibilityBounceKeysThreshold(nsecs_t threshold) = 0;
};

class InputFilter : public InputFilterInterface {
@@ -39,6 +41,8 @@ public:
    using IInputFilter = aidl::com::android::server::inputflinger::IInputFilter;
    using IInputFilterCallbacks =
            aidl::com::android::server::inputflinger::IInputFilter::IInputFilterCallbacks;
    using InputFilterConfiguration =
            aidl::com::android::server::inputflinger::InputFilterConfiguration;

    explicit InputFilter(InputListenerInterface& listener, IInputFlingerRust&);
    ~InputFilter() override = default;
@@ -51,12 +55,15 @@ public:
    void notifyVibratorState(const NotifyVibratorStateArgs& args) override;
    void notifyDeviceReset(const NotifyDeviceResetArgs& args) override;
    void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) override;
    void setAccessibilityBounceKeysThreshold(nsecs_t threshold) override;
    void dump(std::string& dump) override;

private:
    InputListenerInterface& mNextListener;
    std::shared_ptr<IInputFilterCallbacks> mCallbacks;
    std::shared_ptr<IInputFilter> mInputFilterRust;
    mutable std::mutex mLock;
    InputFilterConfiguration mConfig GUARDED_BY(mLock);

    bool isFilterEnabled();
};
+4 −0
Original line number Diff line number Diff line
@@ -224,6 +224,10 @@ InputDispatcherInterface& InputManager::getDispatcher() {
    return *mDispatcher;
}

InputFilterInterface& InputManager::getInputFilter() {
    return *mInputFilter;
}

void InputManager::monitor() {
    mReader->monitor();
    mBlocker->monitor();
+4 −0
Original line number Diff line number Diff line
@@ -102,6 +102,9 @@ public:
    /* Gets the input dispatcher. */
    virtual InputDispatcherInterface& getDispatcher() = 0;

    /* Gets the input filter */
    virtual InputFilterInterface& getInputFilter() = 0;

    /* Check that the input stages have not deadlocked. */
    virtual void monitor() = 0;

@@ -126,6 +129,7 @@ public:
    InputProcessorInterface& getProcessor() override;
    InputDeviceMetricsCollectorInterface& getMetricsCollector() override;
    InputDispatcherInterface& getDispatcher() override;
    InputFilterInterface& getInputFilter() override;
    void monitor() override;
    void dump(std::string& dump) override;

+3 −0
Original line number Diff line number Diff line
@@ -17,6 +17,9 @@ aidl_interface {
    srcs: ["**/*.aidl"],
    unstable: true,
    host_supported: true,
    imports: [
        "android.hardware.input.common-V1",
    ],
    backend: {
        cpp: {
            enabled: false,
Loading