Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a53e1e89 authored by Suprabh Shukla's avatar Suprabh Shukla Committed by Android (Google) Code Review
Browse files

Merge "Release alarm wakelock if send fails" into main

parents 8dea4977 caea5510
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -5367,6 +5367,9 @@ public class AlarmManagerService extends SystemService {
                        // to do any wakelock or stats tracking, so we have nothing
                        // to do any wakelock or stats tracking, so we have nothing
                        // left to do here but go on to the next thing.
                        // left to do here but go on to the next thing.
                        mSendFinishCount++;
                        mSendFinishCount++;
                        if (Flags.acquireWakelockBeforeSend()) {
                            mWakeLock.release();
                        }
                        return;
                        return;
                    }
                    }
                } else {
                } else {
@@ -5404,6 +5407,9 @@ public class AlarmManagerService extends SystemService {
                        // stats management to do.  It threw before we posted the delayed
                        // stats management to do.  It threw before we posted the delayed
                        // timeout message, so we're done here.
                        // timeout message, so we're done here.
                        mListenerFinishCount++;
                        mListenerFinishCount++;
                        if (Flags.acquireWakelockBeforeSend()) {
                            mWakeLock.release();
                        }
                        return;
                        return;
                    }
                    }
                }
                }
+35 −0
Original line number Original line Diff line number Diff line
@@ -973,6 +973,41 @@ public final class AlarmManagerServiceTest {
        inOrder.verify(mWakeLock).release();
        inOrder.verify(mWakeLock).release();
    }
    }


    @Test
    @EnableFlags(Flags.FLAG_ACQUIRE_WAKELOCK_BEFORE_SEND)
    public void testWakelockReleasedWhenSendFails() throws Exception {
        final long triggerTime = mNowElapsedTest + 5000;
        final PendingIntent alarmPi = getNewMockPendingIntent();
        setTestAlarm(ELAPSED_REALTIME_WAKEUP, triggerTime, alarmPi);

        doThrow(new PendingIntent.CanceledException("test")).when(alarmPi).send(eq(mMockContext),
                eq(0), any(Intent.class), any(), any(Handler.class), isNull(), any());

        mNowElapsedTest = mTestTimer.getElapsed();
        mTestTimer.expire();

        final InOrder inOrder = Mockito.inOrder(mWakeLock);
        inOrder.verify(mWakeLock).acquire();
        inOrder.verify(mWakeLock).release();
    }

    @Test
    @EnableFlags(Flags.FLAG_ACQUIRE_WAKELOCK_BEFORE_SEND)
    public void testWakelockReleasedOnListenerException() throws Exception {
        final long triggerTime = mNowElapsedTest + 5000;
        final IAlarmListener listener = getNewListener(() -> {
            throw new RuntimeException("test");
        });
        setTestAlarmWithListener(ELAPSED_REALTIME_WAKEUP, triggerTime, listener);

        mNowElapsedTest = mTestTimer.getElapsed();
        mTestTimer.expire();

        final InOrder inOrder = Mockito.inOrder(mWakeLock);
        inOrder.verify(mWakeLock).acquire();
        inOrder.verify(mWakeLock).release();
    }

    @Test
    @Test
    public void testMinFuturityCoreUid() {
    public void testMinFuturityCoreUid() {
        setDeviceConfigLong(KEY_MIN_FUTURITY, 10L);
        setDeviceConfigLong(KEY_MIN_FUTURITY, 10L);