Browse Source

[DO NOT MERGE] lynx/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 - adb shell 'echo mem dump 0 > /dev/acd-debug'
Change-Id: I48d94b721fc3ba689a48e415d04fa4152f4f8865
Signed-off-by: Chris Paulo <[email protected]>
Chris Paulo 2 years ago
parent
commit
ad95139b97
1 changed files with 12 additions and 13 deletions
  1. 12 13
      vibrator/cs40l26/CapoDetector.cpp

+ 12 - 13
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<capo::ConfigureDetector_ConfigData>();
+    auto msg = std::make_unique<capo::ConfigureDetector>();
+
+    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);
 
-    msg.set_allocated_config_data(&config_data);
+    msg->set_allocated_config_data(config_data.release());
 
-    auto pb_size = msg.ByteSizeLong();
+    auto pb_size = msg->ByteSizeLong();
     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.");
     }