From b0b5b6c5727dff214964963b57a4338d799529c1 Mon Sep 17 00:00:00 2001 From: Cody Heiner Date: Thu, 9 May 2024 18:31:12 -0700 Subject: Use libstatssocket_lazy to report stylus metrics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- libs/input/Android.bp | 44 ++++++++++++++++++++++++++++ libs/input/MotionPredictorMetricsManager.cpp | 20 +++++++++++-- libs/input/tests/Android.bp | 6 ++++ 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/libs/input/Android.bp b/libs/input/Android.bp index cc0649cc91..8f44b3a0e1 100644 --- a/libs/input/Android.bp +++ b/libs/input/Android.bp @@ -289,6 +289,10 @@ cc_library { "motion_predictor_model_prebuilt", "motion_predictor_model_config", ], + static_libs: [ + "libstatslog_libinput", + "libstatssocket_lazy", + ], }, host: { include_dirs: [ @@ -299,6 +303,46 @@ cc_library { }, } +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 cda39ce601..ccf018e56a 100644 --- a/libs/input/MotionPredictorMetricsManager.cpp +++ b/libs/input/MotionPredictorMetricsManager.cpp @@ -21,6 +21,9 @@ #include #include +#ifdef __ANDROID__ +#include +#endif // __ANDROID__ #include "Eigen/Core" #include "Eigen/Geometry" @@ -44,9 +47,20 @@ inline constexpr float PATH_LENGTH_EPSILON = 0.001; 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 6e724acc3c..e9d799ed3f 100644 --- a/libs/input/tests/Android.bp +++ b/libs/input/tests/Android.bp @@ -79,6 +79,12 @@ cc_test { }, test_suites: ["device-tests"], target: { + android: { + static_libs: [ + "libstatslog_libinput", + "libstatssocket_lazy", + ], + }, host: { sanitize: { address: true, -- cgit v1.2.3-59-g8ed1b