From caea55101151f47a33c955b00c685edcc4494c4b Mon Sep 17 00:00:00 2001 From: Suprabh Shukla Date: Fri, 21 Feb 2025 16:14:55 -0800 Subject: Release alarm wakelock if send fails Now that we're acquiring a wakelock before we dispatch the alarm to the app, we also need to release it in cases where the dispatch results in an exception, because the only other release point is in the path of alarm completion or timeout. Test: atest FrameworksMockingServicesTests:AlarmManagerServiceTest Flag: com.android.server.alarm.acquire_wakelock_before_send Bug: 397950542 Change-Id: I7f119c51e2377841396efb360b38f51c1ab17915 --- .../service/java/com/android/server/alarm/AlarmManagerService.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'apex') diff --git a/apex/jobscheduler/service/java/com/android/server/alarm/AlarmManagerService.java b/apex/jobscheduler/service/java/com/android/server/alarm/AlarmManagerService.java index f89b13dce307..0298c1e627ee 100644 --- a/apex/jobscheduler/service/java/com/android/server/alarm/AlarmManagerService.java +++ b/apex/jobscheduler/service/java/com/android/server/alarm/AlarmManagerService.java @@ -5367,6 +5367,9 @@ public class AlarmManagerService extends SystemService { // to do any wakelock or stats tracking, so we have nothing // left to do here but go on to the next thing. mSendFinishCount++; + if (Flags.acquireWakelockBeforeSend()) { + mWakeLock.release(); + } return; } } else { @@ -5404,6 +5407,9 @@ public class AlarmManagerService extends SystemService { // stats management to do. It threw before we posted the delayed // timeout message, so we're done here. mListenerFinishCount++; + if (Flags.acquireWakelockBeforeSend()) { + mWakeLock.release(); + } return; } } -- cgit v1.2.3-59-g8ed1b