Skip to content

Commit f4fb328

Browse files
Treehugger RobotAndroid (Google) Code Review
authored andcommitted
Merge "Allow touchpad debug logs to be enabled on the fly" into main
2 parents 01884db + ae91cf1 commit f4fb328

5 files changed

Lines changed: 82 additions & 26 deletions

File tree

services/inputflinger/reader/Android.bp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ filegroup {
6666
"mapper/accumulator/SingleTouchMotionAccumulator.cpp",
6767
"mapper/accumulator/TouchButtonAccumulator.cpp",
6868
"mapper/gestures/GestureConverter.cpp",
69-
"mapper/gestures/GesturesLogging.cpp",
69+
"mapper/gestures/GesturesLogcatAdapter.cpp",
7070
"mapper/gestures/HardwareProperties.cpp",
7171
"mapper/gestures/HardwareStateConverter.cpp",
72+
"mapper/gestures/Logging.cpp",
7273
"mapper/gestures/PropertyProvider.cpp",
7374
"mapper/gestures/TimerProvider.cpp",
7475
],

services/inputflinger/reader/mapper/TouchpadInputMapper.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "TouchCursorInputMapperCommon.h"
4141
#include "TouchpadInputMapper.h"
4242
#include "gestures/HardwareProperties.h"
43+
#include "gestures/Logging.h"
4344
#include "gestures/TimerProvider.h"
4445
#include "ui/Rotation.h"
4546

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

5051
namespace {
5152

52-
/**
53-
* Log details of each gesture output by the gestures library.
54-
* Enable this via "adb shell setprop log.tag.TouchpadInputMapperGestures DEBUG" (requires
55-
* restarting the shell)
56-
*/
57-
const bool DEBUG_TOUCHPAD_GESTURES =
58-
__android_log_is_loggable(ANDROID_LOG_DEBUG, "TouchpadInputMapperGestures",
59-
ANDROID_LOG_INFO);
60-
6153
std::vector<double> createAccelerationCurveForSensitivity(int32_t sensitivity,
6254
bool accelerationEnabled,
6355
size_t propertySize) {
@@ -470,7 +462,7 @@ void TouchpadInputMapper::updatePalmDetectionMetrics() {
470462

471463
std::list<NotifyArgs> TouchpadInputMapper::sendHardwareState(nsecs_t when, nsecs_t readTime,
472464
SelfContainedHardwareState schs) {
473-
ALOGD_IF(DEBUG_TOUCHPAD_GESTURES, "New hardware state: %s", schs.state.String().c_str());
465+
ALOGD_IF(debugTouchpadGestures(), "New hardware state: %s", schs.state.String().c_str());
474466
mGestureInterpreter->PushHardwareState(&schs.state);
475467
return processGestures(when, readTime);
476468
}
@@ -481,7 +473,7 @@ std::list<NotifyArgs> TouchpadInputMapper::timeoutExpired(nsecs_t when) {
481473
}
482474

483475
void TouchpadInputMapper::consumeGesture(const Gesture* gesture) {
484-
ALOGD_IF(DEBUG_TOUCHPAD_GESTURES, "Gesture ready: %s", gesture->String().c_str());
476+
ALOGD_IF(debugTouchpadGestures(), "Gesture ready: %s", gesture->String().c_str());
485477
if (mResettingInterpreter) {
486478
// We already handle tidying up fake fingers etc. in GestureConverter::reset, so we should
487479
// ignore any gestures produced from the interpreter while we're resetting it.

services/inputflinger/reader/mapper/gestures/GesturesLogging.cpp renamed to services/inputflinger/reader/mapper/gestures/GesturesLogcatAdapter.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,17 @@
2222

2323
#include <log/log.h>
2424

25+
#include "Logging.h"
2526
#include "include/gestures.h"
2627

2728
extern "C" {
2829

29-
namespace {
30-
31-
/**
32-
* Log details of each gesture output by the gestures library.
33-
* Enable this via "adb shell setprop log.tag.TouchpadInputMapperGestures DEBUG" (requires
34-
* restarting the shell)
35-
*/
36-
const bool DEBUG_TOUCHPAD_GESTURES =
37-
__android_log_is_loggable(ANDROID_LOG_DEBUG, "TouchpadInputMapperGestures",
38-
ANDROID_LOG_INFO);
39-
40-
} // namespace
41-
4230
void gestures_log(int verb, const char* fmt, ...) {
4331
va_list args;
4432
va_start(args, fmt);
4533
if (verb == GESTURES_LOG_ERROR) {
4634
LOG_PRI_VA(ANDROID_LOG_ERROR, LOG_TAG, fmt, args);
47-
} else if (DEBUG_TOUCHPAD_GESTURES) {
35+
} else if (android::debugTouchpadGestures()) {
4836
if (verb == GESTURES_LOG_INFO) {
4937
LOG_PRI_VA(ANDROID_LOG_INFO, LOG_TAG, fmt, args);
5038
} else {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2025 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+
#include "Logging.h"
18+
19+
#include <android-base/properties.h>
20+
#include <log/log.h>
21+
22+
namespace {
23+
24+
const bool IS_DEBUGGABLE_BUILD =
25+
#if defined(__ANDROID__)
26+
android::base::GetBoolProperty("ro.debuggable", false);
27+
#else
28+
true;
29+
#endif
30+
31+
} // namespace
32+
33+
namespace android {
34+
35+
bool debugTouchpadGestures() {
36+
if (!IS_DEBUGGABLE_BUILD) {
37+
static const bool DEBUG_RAW_EVENTS =
38+
__android_log_is_loggable(ANDROID_LOG_DEBUG, "TouchpadInputMapperGestures",
39+
ANDROID_LOG_INFO);
40+
return DEBUG_RAW_EVENTS;
41+
}
42+
return __android_log_is_loggable(ANDROID_LOG_DEBUG, "TouchpadInputMapperGestures",
43+
ANDROID_LOG_INFO);
44+
}
45+
46+
} // namespace android
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2025 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+
namespace android {
20+
21+
/**
22+
* Log details of touchpad gesture library input, output, and processing.
23+
* Enable this via "adb shell setprop log.tag.TouchpadInputMapperGestures DEBUG".
24+
* This requires a restart on non-debuggable (e.g. user) builds, but should take effect immediately
25+
* on debuggable builds (e.g. userdebug).
26+
*/
27+
bool debugTouchpadGestures();
28+
29+
} // namespace android

0 commit comments

Comments
 (0)