Add input flags for event verification
We will try to roll them out to improve the correctness of the input
streams.
Bug: 271455682
Test: atest inputflinger_tests
Change-Id: I03ad327cf86b19220b5a6344b77b446dd7360ab9
diff --git a/libs/input/Android.bp b/libs/input/Android.bp
index 8656b26..36a01d3 100644
--- a/libs/input/Android.bp
+++ b/libs/input/Android.bp
@@ -33,6 +33,21 @@
],
}
+/////////////////////////////////////////////////
+// flags
+/////////////////////////////////////////////////
+aconfig_declarations {
+ name: "aconfig_input_flags",
+ package: "com.android.input.flags",
+ srcs: ["input_flags.aconfig"],
+}
+
+cc_aconfig_library {
+ name: "aconfig_input_flags_c_lib",
+ aconfig_declarations: "aconfig_input_flags",
+ host_supported: true,
+}
+
aidl_interface {
name: "inputconstants",
host_supported: true,
@@ -176,6 +191,7 @@
"libtinyxml2",
"libutils",
"libvintf",
+ "server_configurable_flags",
],
ldflags: [
@@ -196,6 +212,7 @@
],
whole_static_libs: [
+ "aconfig_input_flags_c_lib",
"libinput_rust_ffi",
],
diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp
index bbbebf7..1f14396 100644
--- a/libs/input/InputTransport.cpp
+++ b/libs/input/InputTransport.cpp
@@ -23,9 +23,12 @@
#include <log/log.h>
#include <utils/Trace.h>
+#include <com_android_input_flags.h>
#include <input/InputTransport.h>
#include <input/TraceTools.h>
+namespace input_flags = com::android::input::flags;
+
namespace {
/**
@@ -139,7 +142,8 @@
* Enable this via "adb shell setprop log.tag.InputTransportVerifyEvents DEBUG"
*/
static bool verifyEvents() {
- return __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "VerifyEvents", ANDROID_LOG_INFO);
+ return input_flags::enable_outbound_event_verification() ||
+ __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "VerifyEvents", ANDROID_LOG_INFO);
}
template<typename T>
diff --git a/libs/input/input_flags.aconfig b/libs/input/input_flags.aconfig
new file mode 100644
index 0000000..1f29a00
--- /dev/null
+++ b/libs/input/input_flags.aconfig
@@ -0,0 +1,15 @@
+package: "com.android.input.flags"
+
+flag {
+ name: "enable_outbound_event_verification"
+ namespace: "input"
+ description: "Set to true to enable crashing whenever bad outbound events are detected inside InputTransport"
+ bug: "271455682"
+}
+
+flag {
+ name: "enable_inbound_event_verification"
+ namespace: "input"
+ description: "Set to true to enable crashing whenever bad inbound events are going into InputDispatcher"
+ bug: "271455682"
+}
diff --git a/libs/input/tests/Android.bp b/libs/input/tests/Android.bp
index e7224ff..138898f 100644
--- a/libs/input/tests/Android.bp
+++ b/libs/input/tests/Android.bp
@@ -62,6 +62,7 @@
"libtinyxml2",
"libutils",
"libvintf",
+ "server_configurable_flags",
],
data: [
"data/*",
diff --git a/services/inputflinger/dispatcher/DebugConfig.h b/services/inputflinger/dispatcher/DebugConfig.h
index 7a41d68..c7d98ab 100644
--- a/services/inputflinger/dispatcher/DebugConfig.h
+++ b/services/inputflinger/dispatcher/DebugConfig.h
@@ -19,6 +19,9 @@
#define LOG_TAG "InputDispatcher"
#include <android-base/logging.h>
+#include <com_android_input_flags.h>
+
+namespace input_flags = com::android::input::flags;
namespace android::inputdispatcher {
@@ -102,7 +105,7 @@
* Crash if a bad stream from InputListener is detected.
* Enable this via "adb shell setprop log.tag.InputDispatcherVerifyEvents DEBUG" (requires restart)
*/
-const bool DEBUG_VERIFY_EVENTS =
+const bool DEBUG_VERIFY_EVENTS = input_flags::enable_inbound_event_verification() ||
android::base::ShouldLog(android::base::LogSeverity::DEBUG, LOG_TAG "VerifyEvents");
} // namespace android::inputdispatcher