[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 <chrispaulo@google.com>
This commit is contained in:
Chris Paulo 2022-12-15 21:19:02 +00:00
parent 9d89188c67
commit 8f4e8161ee

View file

@ -30,10 +30,6 @@ namespace chre {
namespace { // anonymous namespace for file-local definitions 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. * Called when onConnected() to send NanoappList request.
*/ */
@ -166,19 +162,22 @@ void CapoDetector::enable() {
// Create CHRE message with serialized message // Create CHRE message with serialized message
flatbuffers::FlatBufferBuilder builder, config_builder, force_builder; flatbuffers::FlatBufferBuilder builder, config_builder, force_builder;
config_data.set_still_time_threshold_nanosecond(mCapoDetectorMDParameters.still_time_threshold_ns); auto config_data = std::make_unique<capo::ConfigureDetector_ConfigData>();
config_data.set_window_width_nanosecond(mCapoDetectorMDParameters.window_width_ns); auto msg = std::make_unique<capo::ConfigureDetector>();
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);
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<uint8_t[]>(pb_size); auto pb_data = std::make_unique<uint8_t[]>(pb_size);
if (!msg.SerializeToArray(pb_data.get(), pb_size)) { if (!msg->SerializeToArray(pb_data.get(), pb_size)) {
ALOGE("Failed to serialize message."); ALOGE("Failed to serialize message.");
} }