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

Commit ae91cf16 authored by Harry Cutts's avatar Harry Cutts
Browse files

Allow touchpad debug logs to be enabled on the fly

This is needed so that we can turn them on during particular CTS tests.

The IS_DEBUGGABLE_BUILD declaration in Logging.cpp is a copy of the one
in services/inputflinger/reader/Macros.cpp, but unfortunately we can't
put debugTouchpadGestures there because Macros.h defines LOG_TAG, so we
can't include it from GesturesLogcatAdapter.cpp.

Test: $ atest android.input.cts.hostside.InputAtomsTest
      with the other CLs in this topic patched. Check that Gestures
      library logs appear with the Gestures logcat tag, and "Gesture
      ready:" and "New hardware state:" logs appear with the InputReader
      tag
Bug: 397288324
Flag: EXEMPT log only update
Change-Id: Id92581014836ba856b29741117e9f6a397d9422c
parent d442304a
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -66,9 +66,10 @@ filegroup {
        "mapper/accumulator/SingleTouchMotionAccumulator.cpp",
        "mapper/accumulator/TouchButtonAccumulator.cpp",
        "mapper/gestures/GestureConverter.cpp",
        "mapper/gestures/GesturesLogging.cpp",
        "mapper/gestures/GesturesLogcatAdapter.cpp",
        "mapper/gestures/HardwareProperties.cpp",
        "mapper/gestures/HardwareStateConverter.cpp",
        "mapper/gestures/Logging.cpp",
        "mapper/gestures/PropertyProvider.cpp",
        "mapper/gestures/TimerProvider.cpp",
    ],
+3 −11
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
#include "TouchCursorInputMapperCommon.h"
#include "TouchpadInputMapper.h"
#include "gestures/HardwareProperties.h"
#include "gestures/Logging.h"
#include "gestures/TimerProvider.h"
#include "ui/Rotation.h"

@@ -49,15 +50,6 @@ namespace android {

namespace {

/**
 * Log details of each gesture output by the gestures library.
 * Enable this via "adb shell setprop log.tag.TouchpadInputMapperGestures DEBUG" (requires
 * restarting the shell)
 */
const bool DEBUG_TOUCHPAD_GESTURES =
        __android_log_is_loggable(ANDROID_LOG_DEBUG, "TouchpadInputMapperGestures",
                                  ANDROID_LOG_INFO);

std::vector<double> createAccelerationCurveForSensitivity(int32_t sensitivity,
                                                          bool accelerationEnabled,
                                                          size_t propertySize) {
@@ -470,7 +462,7 @@ 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());
    ALOGD_IF(debugTouchpadGestures(), "New hardware state: %s", schs.state.String().c_str());
    mGestureInterpreter->PushHardwareState(&schs.state);
    return processGestures(when, readTime);
}
@@ -481,7 +473,7 @@ std::list<NotifyArgs> TouchpadInputMapper::timeoutExpired(nsecs_t when) {
}

void TouchpadInputMapper::consumeGesture(const Gesture* gesture) {
    ALOGD_IF(DEBUG_TOUCHPAD_GESTURES, "Gesture ready: %s", gesture->String().c_str());
    ALOGD_IF(debugTouchpadGestures(), "Gesture ready: %s", gesture->String().c_str());
    if (mResettingInterpreter) {
        // We already handle tidying up fake fingers etc. in GestureConverter::reset, so we should
        // ignore any gestures produced from the interpreter while we're resetting it.
+2 −14
Original line number Diff line number Diff line
@@ -22,29 +22,17 @@

#include <log/log.h>

#include "Logging.h"
#include "include/gestures.h"

extern "C" {

namespace {

/**
 * Log details of each gesture output by the gestures library.
 * Enable this via "adb shell setprop log.tag.TouchpadInputMapperGestures DEBUG" (requires
 * restarting the shell)
 */
const bool DEBUG_TOUCHPAD_GESTURES =
        __android_log_is_loggable(ANDROID_LOG_DEBUG, "TouchpadInputMapperGestures",
                                  ANDROID_LOG_INFO);

} // namespace

void gestures_log(int verb, const char* fmt, ...) {
    va_list args;
    va_start(args, fmt);
    if (verb == GESTURES_LOG_ERROR) {
        LOG_PRI_VA(ANDROID_LOG_ERROR, LOG_TAG, fmt, args);
    } else if (DEBUG_TOUCHPAD_GESTURES) {
    } else if (android::debugTouchpadGestures()) {
        if (verb == GESTURES_LOG_INFO) {
            LOG_PRI_VA(ANDROID_LOG_INFO, LOG_TAG, fmt, args);
        } else {
+46 −0
Original line number Diff line number Diff line
/*
 * Copyright 2025 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.
 */

#include "Logging.h"

#include <android-base/properties.h>
#include <log/log.h>

namespace {

const bool IS_DEBUGGABLE_BUILD =
#if defined(__ANDROID__)
        android::base::GetBoolProperty("ro.debuggable", false);
#else
        true;
#endif

} // namespace

namespace android {

bool debugTouchpadGestures() {
    if (!IS_DEBUGGABLE_BUILD) {
        static const bool DEBUG_RAW_EVENTS =
                __android_log_is_loggable(ANDROID_LOG_DEBUG, "TouchpadInputMapperGestures",
                                          ANDROID_LOG_INFO);
        return DEBUG_RAW_EVENTS;
    }
    return __android_log_is_loggable(ANDROID_LOG_DEBUG, "TouchpadInputMapperGestures",
                                     ANDROID_LOG_INFO);
}

} // namespace android
 No newline at end of file
+29 −0
Original line number Diff line number Diff line
/*
 * Copyright 2025 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

namespace android {

/**
 * Log details of touchpad gesture library input, output, and processing.
 * Enable this via "adb shell setprop log.tag.TouchpadInputMapperGestures DEBUG".
 * This requires a restart on non-debuggable (e.g. user) builds, but should take effect immediately
 * on debuggable builds (e.g. userdebug).
 */
bool debugTouchpadGestures();

} // namespace android
 No newline at end of file