Fix race condition on cancelling alarms

There was a race condition in which pulling alarms can be cancellled
after they are initialized, causing bucket boundary pulls to fail.

Test: manually verifified alarm consistently cancelled before being set
Test: manually verified alarms were properly cancelled on statsd crash
Fix: 156855909
Change-Id: I913b6f3e3d03269fb9283199f8b9d666a298e145
This commit is contained in:
Stanislav Zholnin
2020-05-18 02:37:23 +01:00
committed by Tej Singh
parent 1ecd4528fb
commit eec8ee430c

View File

@@ -662,14 +662,19 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
return;
}
// Cleann up from previous statsd - cancel any alarms that had been set. Do this here
// instead of in binder death because statsd can come back and set different alarms, or not
// want to set an alarm when it had been set. This guarantees that when we get a new statsd,
// we cancel any alarms before it is able to set them.
cancelAnomalyAlarm();
cancelPullingAlarm();
cancelAlarmForSubscriberTriggering();
if (DEBUG) Log.d(TAG, "Saying hi to statsd");
mStatsManagerService.statsdReady(statsd);
try {
statsd.statsCompanionReady();
cancelAnomalyAlarm();
cancelPullingAlarm();
BroadcastReceiver appUpdateReceiver = new AppUpdateReceiver();
BroadcastReceiver userUpdateReceiver = new UserUpdateReceiver();
BroadcastReceiver shutdownEventReceiver = new ShutdownEventReceiver();