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

Commit 82a44050 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Fix NPE

I think this is probably a race condition with canceling alarms, but I'm adding a wtf log so we can monitor it

Change-Id: Icc49c6d285c1bcb0595cd7d52867c6e9ce2ecb2a
Test: TimeToLiveHelperTest
Fixes: 324886485
Flag: EXEMPT bug fix
parent 75c9966a
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -188,7 +188,11 @@ public class TimeToLiveHelper {
                        timeoutKey = earliest.second;
                    }
                }
                if (timeoutKey != null) {
                    mNm.timeoutNotification(timeoutKey);
                } else {
                    Slog.wtf(TAG, "Alarm triggered but should have been cleaned up already");
                }
            }
        }
    };
+16 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import static com.android.server.notification.TimeToLiveHelper.EXTRA_KEY;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -107,6 +108,21 @@ public class TimeToLiveHelperTest extends UiServiceTestCase {
        assertThat(mHelper.mKeys).isEmpty();
    }

    @Test
    public void testTimeoutExpiresButNotifEntryGone() {
        NotificationRecord r = getRecord("testTimeoutExpires", 1);

        mHelper.scheduleTimeoutLocked(r, 1);
        ArgumentCaptor<PendingIntent> captor = ArgumentCaptor.forClass(PendingIntent.class);
        verify(mAm).setExactAndAllowWhileIdle(anyInt(), eq(2L), captor.capture());

        mHelper.mKeys.clear();

        mHelper.mNotificationTimeoutReceiver.onReceive(mContext, captor.getValue().getIntent());

        verify(mNm, never()).timeoutNotification(anyString());
    }

    @Test
    public void testTimeoutExpires_twoEntries() {
        NotificationRecord first = getRecord("testTimeoutFirst", 1);