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

Commit 3b56778b authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Introduce the InputDeviceMetricsCollector stage" into udc-qpr-dev am:...

Merge "Introduce the InputDeviceMetricsCollector stage" into udc-qpr-dev am: 3a549bba am: 734c270a

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/23225740



Change-Id: I89a7cf148d1e0ca598a4d8da3c76c7121fbe602a
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 1cb6e78e 734c270a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ filegroup {
    name: "libinputflinger_sources",
    srcs: [
        "InputCommonConverter.cpp",
        "InputDeviceMetricsCollector.cpp",
        "InputProcessor.cpp",
        "PreferStylusOverTouchBlocker.cpp",
        "UnwantedInteractionBlocker.cpp",
@@ -129,6 +130,7 @@ cc_library_shared {
        "libinputflinger_base",
        "libinputreader",
        "libinputreporter",
        "libPlatformProperties",
    ],
    static_libs: [
        "libinputdispatcher",
+68 −0
Original line number Diff line number Diff line
/*
 * Copyright 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "InputDeviceMetricsCollector"
#include "InputDeviceMetricsCollector.h"

namespace android {

InputDeviceMetricsCollector::InputDeviceMetricsCollector(InputListenerInterface& listener)
      : mNextListener(listener){};

void InputDeviceMetricsCollector::notifyInputDevicesChanged(
        const NotifyInputDevicesChangedArgs& args) {
    mNextListener.notify(args);
}

void InputDeviceMetricsCollector::notifyConfigurationChanged(
        const NotifyConfigurationChangedArgs& args) {
    mNextListener.notify(args);
}

void InputDeviceMetricsCollector::notifyKey(const NotifyKeyArgs& args) {
    mNextListener.notify(args);
}

void InputDeviceMetricsCollector::notifyMotion(const NotifyMotionArgs& args) {
    mNextListener.notify(args);
}

void InputDeviceMetricsCollector::notifySwitch(const NotifySwitchArgs& args) {
    mNextListener.notify(args);
}

void InputDeviceMetricsCollector::notifySensor(const NotifySensorArgs& args) {
    mNextListener.notify(args);
}

void InputDeviceMetricsCollector::notifyVibratorState(const NotifyVibratorStateArgs& args) {
    mNextListener.notify(args);
}

void InputDeviceMetricsCollector::notifyDeviceReset(const NotifyDeviceResetArgs& args) {
    mNextListener.notify(args);
}

void InputDeviceMetricsCollector::notifyPointerCaptureChanged(
        const NotifyPointerCaptureChangedArgs& args) {
    mNextListener.notify(args);
}

void InputDeviceMetricsCollector::dump(std::string& dump) {
    dump += "InputDeviceMetricsCollector:\n";
}

} // namespace android
+58 −0
Original line number Diff line number Diff line
/*
 * Copyright 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include "InputListener.h"

namespace android {

/**
 * Logs metrics about registered input devices and their usages.
 *
 * Not thread safe. Must be called from a single thread.
 */
class InputDeviceMetricsCollectorInterface : public InputListenerInterface {
public:
    /**
     * Dump the state of the interaction blocker.
     * This method may be called on any thread (usually by the input manager on a binder thread).
     */
    virtual void dump(std::string& dump) = 0;
};

class InputDeviceMetricsCollector : public InputDeviceMetricsCollectorInterface {
public:
    explicit InputDeviceMetricsCollector(InputListenerInterface& listener);
    ~InputDeviceMetricsCollector() override = default;

    void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override;
    void notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) override;
    void notifyKey(const NotifyKeyArgs& args) override;
    void notifyMotion(const NotifyMotionArgs& args) override;
    void notifySwitch(const NotifySwitchArgs& args) override;
    void notifySensor(const NotifySensorArgs& args) override;
    void notifyVibratorState(const NotifyVibratorStateArgs& args) override;
    void notifyDeviceReset(const NotifyDeviceResetArgs& args) override;
    void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) override;

    void dump(std::string& dump) override;

private:
    InputListenerInterface& mNextListener;
};

} // namespace android
+20 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include "InputReaderFactory.h"
#include "UnwantedInteractionBlocker.h"

#include <android/sysprop/InputProperties.sysprop.h>
#include <binder/IPCThreadState.h>

#include <log/log.h>
@@ -32,6 +33,9 @@

namespace android {

static const bool ENABLE_INPUT_DEVICE_USAGE_METRICS =
        sysprop::InputProperties::enable_input_device_usage_metrics().value_or(false);

using gui::FocusRequest;

static int32_t exceptionCodeFromStatusT(status_t status) {
@@ -55,12 +59,22 @@ static int32_t exceptionCodeFromStatusT(status_t status) {

/**
 * The event flow is via the "InputListener" interface, as follows:
 * InputReader -> UnwantedInteractionBlocker -> InputProcessor -> InputDispatcher
 *   InputReader
 *     -> UnwantedInteractionBlocker
 *     -> InputProcessor
 *     -> InputDeviceMetricsCollector
 *     -> InputDispatcher
 */
InputManager::InputManager(const sp<InputReaderPolicyInterface>& readerPolicy,
                           InputDispatcherPolicyInterface& dispatcherPolicy) {
    mDispatcher = createInputDispatcher(dispatcherPolicy);
    mProcessor = std::make_unique<InputProcessor>(*mDispatcher);

    if (ENABLE_INPUT_DEVICE_USAGE_METRICS) {
        mCollector = std::make_unique<InputDeviceMetricsCollector>(*mDispatcher);
    }

    mProcessor = ENABLE_INPUT_DEVICE_USAGE_METRICS ? std::make_unique<InputProcessor>(*mCollector)
                                                   : std::make_unique<InputProcessor>(*mDispatcher);
    mBlocker = std::make_unique<UnwantedInteractionBlocker>(*mProcessor);
    mReader = createInputReader(readerPolicy, *mBlocker);
}
@@ -131,6 +145,10 @@ void InputManager::dump(std::string& dump) {
    dump += '\n';
    mProcessor->dump(dump);
    dump += '\n';
    if (ENABLE_INPUT_DEVICE_USAGE_METRICS) {
        mCollector->dump(dump);
        dump += '\n';
    }
    mDispatcher->dump(dump);
    dump += '\n';
}
+4 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
 * Native input manager.
 */

#include "InputDeviceMetricsCollector.h"
#include "InputProcessor.h"
#include "InputReaderBase.h"
#include "include/UnwantedInteractionBlockerInterface.h"
@@ -82,7 +83,7 @@ public:
    /* Gets the input reader. */
    virtual InputReaderInterface& getReader() = 0;

    /* Gets the input processor */
    /* Gets the input processor. */
    virtual InputProcessorInterface& getProcessor() = 0;

    /* Gets the input dispatcher. */
@@ -124,6 +125,8 @@ private:

    std::unique_ptr<InputProcessorInterface> mProcessor;

    std::unique_ptr<InputDeviceMetricsCollectorInterface> mCollector;

    std::unique_ptr<InputDispatcherInterface> mDispatcher;
};