From 8f4e8161ee22dd446e4341cce8719b006d0ac277 Mon Sep 17 00:00:00 2001 From: Chris Paulo Date: Thu, 15 Dec 2022 21:19:02 +0000 Subject: [PATCH] [DO NOT MERGE] bluejay/vibrator: Fix Capodetector on AoC restart Update pointers used in protobuf interface for configuring the detector. When AoC has an SSR, it causes CapoDetector to go down by null pointer dereference. Bug: 261349596 Test: Verified 10x forced AoC SSR Change-Id: Ifd7fcbbff4639f552c6708b5b171f0b3c9164c03 Signed-off-by: Chris Paulo --- vibrator/cs40l26/CapoDetector.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/vibrator/cs40l26/CapoDetector.cpp b/vibrator/cs40l26/CapoDetector.cpp index 1b8ba89..0fc4d4b 100644 --- a/vibrator/cs40l26/CapoDetector.cpp +++ b/vibrator/cs40l26/CapoDetector.cpp @@ -30,10 +30,6 @@ namespace chre { namespace { // anonymous namespace for file-local definitions -static capo::ConfigureDetector_ConfigData config_data = capo::ConfigureDetector_ConfigData(); -static capo::ConfigureDetector msg = capo::ConfigureDetector(); - - /** * Called when onConnected() to send NanoappList request. */ @@ -166,19 +162,22 @@ void CapoDetector::enable() { // Create CHRE message with serialized message flatbuffers::FlatBufferBuilder builder, config_builder, force_builder; - config_data.set_still_time_threshold_nanosecond(mCapoDetectorMDParameters.still_time_threshold_ns); - config_data.set_window_width_nanosecond(mCapoDetectorMDParameters.window_width_ns); - config_data.set_motion_confidence_threshold(mCapoDetectorMDParameters.motion_confidence_threshold); - config_data.set_still_confidence_threshold(mCapoDetectorMDParameters.still_confidence_threshold); - config_data.set_var_threshold(mCapoDetectorMDParameters.var_threshold); - config_data.set_var_threshold_delta(mCapoDetectorMDParameters.var_threshold_delta); + auto config_data = std::make_unique(); + auto msg = std::make_unique(); - msg.set_allocated_config_data(&config_data); + config_data->set_still_time_threshold_nanosecond(mCapoDetectorMDParameters.still_time_threshold_ns); + config_data->set_window_width_nanosecond(mCapoDetectorMDParameters.window_width_ns); + config_data->set_motion_confidence_threshold(mCapoDetectorMDParameters.motion_confidence_threshold); + config_data->set_still_confidence_threshold(mCapoDetectorMDParameters.still_confidence_threshold); + config_data->set_var_threshold(mCapoDetectorMDParameters.var_threshold); + config_data->set_var_threshold_delta(mCapoDetectorMDParameters.var_threshold_delta); - auto pb_size = msg.ByteSizeLong(); + msg->set_allocated_config_data(config_data.release()); + + auto pb_size = msg->ByteSizeLong(); auto pb_data = std::make_unique(pb_size); - if (!msg.SerializeToArray(pb_data.get(), pb_size)) { + if (!msg->SerializeToArray(pb_data.get(), pb_size)) { ALOGE("Failed to serialize message."); }