Use libstatssocket_lazy to report stylus metrics
Report stylus prediction metrics using libstatssocket_lazy
as an interim solution while I working on untangling the
build dependency issues (b/338106546) that prevent us from using
libstatslog within libinput.
Test: `adb reboot`, then `adb logcat | egrep -i "statssocket|MotionPredictor"`
→ Shows no bootanimation linker error, and no other errors
Test: `statsd_testdrive -d 3000 718`, then draw with stylus
→ Shows reasonable metrics logged
Bug: 338106546
Bug: 311066949
Change-Id: I05ae5ffdd774d0b25cb7b2435015245d5f712c01
diff --git a/libs/input/Android.bp b/libs/input/Android.bp
index cc0649c..8f44b3a 100644
--- a/libs/input/Android.bp
+++ b/libs/input/Android.bp
@@ -289,6 +289,10 @@
"motion_predictor_model_prebuilt",
"motion_predictor_model_config",
],
+ static_libs: [
+ "libstatslog_libinput",
+ "libstatssocket_lazy",
+ ],
},
host: {
include_dirs: [
@@ -299,6 +303,46 @@
},
}
+cc_library_static {
+ name: "libstatslog_libinput",
+ generated_sources: ["statslog_libinput.cpp"],
+ generated_headers: ["statslog_libinput.h"],
+ cflags: [
+ "-Wall",
+ "-Werror",
+ ],
+ export_generated_headers: ["statslog_libinput.h"],
+ shared_libs: [
+ "libcutils",
+ "liblog",
+ "libutils",
+ ],
+ static_libs: [
+ "libstatssocket_lazy",
+ ],
+}
+
+genrule {
+ name: "statslog_libinput.h",
+ tools: ["stats-log-api-gen"],
+ cmd: "$(location stats-log-api-gen) --header $(genDir)/statslog_libinput.h " +
+ "--module libinput --namespace android,libinput",
+ out: [
+ "statslog_libinput.h",
+ ],
+}
+
+genrule {
+ name: "statslog_libinput.cpp",
+ tools: ["stats-log-api-gen"],
+ cmd: "$(location stats-log-api-gen) --cpp $(genDir)/statslog_libinput.cpp " +
+ "--module libinput --namespace android,libinput " +
+ "--importHeader statslog_libinput.h",
+ out: [
+ "statslog_libinput.cpp",
+ ],
+}
+
cc_defaults {
name: "libinput_fuzz_defaults",
cpp_std: "c++20",
diff --git a/libs/input/MotionPredictorMetricsManager.cpp b/libs/input/MotionPredictorMetricsManager.cpp
index cda39ce..ccf018e 100644
--- a/libs/input/MotionPredictorMetricsManager.cpp
+++ b/libs/input/MotionPredictorMetricsManager.cpp
@@ -21,6 +21,9 @@
#include <algorithm>
#include <android-base/logging.h>
+#ifdef __ANDROID__
+#include <statslog_libinput.h>
+#endif // __ANDROID__
#include "Eigen/Core"
#include "Eigen/Geometry"
@@ -44,9 +47,20 @@
void MotionPredictorMetricsManager::defaultReportAtomFunction(
const MotionPredictorMetricsManager::AtomFields& atomFields) {
- // TODO(b/338106546): Fix bootanimation build dependency issue, then re-add
- // the stats_write function call here.
- (void)atomFields;
+#ifdef __ANDROID__
+ android::libinput::stats_write(android::libinput::STYLUS_PREDICTION_METRICS_REPORTED,
+ /*stylus_vendor_id=*/0,
+ /*stylus_product_id=*/0,
+ atomFields.deltaTimeBucketMilliseconds,
+ atomFields.alongTrajectoryErrorMeanMillipixels,
+ atomFields.alongTrajectoryErrorStdMillipixels,
+ atomFields.offTrajectoryRmseMillipixels,
+ atomFields.pressureRmseMilliunits,
+ atomFields.highVelocityAlongTrajectoryRmse,
+ atomFields.highVelocityOffTrajectoryRmse,
+ atomFields.scaleInvariantAlongTrajectoryRmse,
+ atomFields.scaleInvariantOffTrajectoryRmse);
+#endif // __ANDROID__
}
MotionPredictorMetricsManager::MotionPredictorMetricsManager(
diff --git a/libs/input/tests/Android.bp b/libs/input/tests/Android.bp
index 6e724ac..e9d799e 100644
--- a/libs/input/tests/Android.bp
+++ b/libs/input/tests/Android.bp
@@ -79,6 +79,12 @@
},
test_suites: ["device-tests"],
target: {
+ android: {
+ static_libs: [
+ "libstatslog_libinput",
+ "libstatssocket_lazy",
+ ],
+ },
host: {
sanitize: {
address: true,