OSDN Git Service

btaa: null check btaa instance when receiving callback from SystemSuspend
authorMichael Sun <michaelfsun@google.com>
Mon, 16 Nov 2020 21:53:12 +0000 (21:53 +0000)
committerMichael Sun <michaelfsun@google.com>
Mon, 16 Nov 2020 21:54:41 +0000 (21:54 +0000)
Perform null pointer check upon receive callbacks from SystemSuspend
to mitigation the exception caused crash.

Tag: #feature
Bug: 173435736
Test: m
Change-Id: Ie15d179ebce82fdd91f32b3d8a98bb9bf8c66e84

btaa/src/activity_attribution.cc

index 3ccc882..213b277 100644 (file)
@@ -69,18 +69,24 @@ void ActivityAttributionImpl::onWakeup(
     bool success, const std::vector<std::string>& wakeupReasons) {}
 
 Status WakelockCallback::notifyAcquired(void) {
-  instance->onWakelockAcquired();
+  if (instance) {
+    instance->onWakelockAcquired();
+  }
   return Status::ok();
 }
 
 Status WakelockCallback::notifyReleased(void) {
-  instance->onWakelockReleased();
+  if (instance) {
+    instance->onWakelockReleased();
+  }
   return Status::ok();
 }
 
 Status WakeupCallback::notifyWakeup(
     bool success, const std::vector<std::string>& wakeupReasons) {
-  instance->onWakeup(success, wakeupReasons);
+  if (instance) {
+    instance->onWakeup(success, wakeupReasons);
+  }
   return Status::ok();
 }