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

Commit d3a1cb40 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Fix NPE" into main

parents 4d82f97a 82a44050
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);