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

Commit a6690c49 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove handler callbacks correctly" into main

parents 9ad90b8d b81fc8cf
Loading
Loading
Loading
Loading
+17 −7
Original line number Diff line number Diff line
@@ -9363,10 +9363,15 @@ public class NotificationManagerService extends SystemService {
                                            // a group summary or children (complete a group)
                                            mHandler.postDelayed(() -> {
                                                synchronized (mNotificationLock) {
                                                    NotificationRecord record =
                                                            mNotificationsByKey.get(key);
                                                    if (record != null) {
                                                        mGroupHelper.onNotificationPostedWithDelay(
                                                        r, mNotificationList, mSummaryByGroupKey);
                                                                record, mNotificationList,
                                                                mSummaryByGroupKey);
                                                    }
                                                }
                                            }, r.getKey(), DELAY_FORCE_REGROUP_TIME);
                                            }, key, DELAY_FORCE_REGROUP_TIME);
                                        }
                                    }
@@ -9412,10 +9417,15 @@ public class NotificationManagerService extends SystemService {
                                    if (notificationForceGrouping()) {
                                        mHandler.postDelayed(() -> {
                                            synchronized (mNotificationLock) {
                                                mGroupHelper.onNotificationPostedWithDelay(r,
                                                        mNotificationList, mSummaryByGroupKey);
                                                NotificationRecord record =
                                                        mNotificationsByKey.get(key);
                                                if (record != null) {
                                                    mGroupHelper.onNotificationPostedWithDelay(
                                                            record, mNotificationList,
                                                            mSummaryByGroupKey);
                                                }
                                            }
                                        }, r.getKey(), DELAY_FORCE_REGROUP_TIME);
                                        }, key, DELAY_FORCE_REGROUP_TIME);
                                    }
                                }
                            }
@@ -10395,7 +10405,7 @@ public class NotificationManagerService extends SystemService {
                }
                mListeners.notifyRemovedLocked(r, reason, r.getStats());
                if (notificationForceGrouping()) {
                    mHandler.removeCallbacksAndMessages(r.getKey());
                    mHandler.removeCallbacksAndEqualMessages(r.getKey());
                    mHandler.post(() -> {
                        synchronized (NotificationManagerService.this.mNotificationLock) {
                            mGroupHelper.onNotificationRemoved(r, mNotificationList);
+38 −0
Original line number Diff line number Diff line
@@ -2894,6 +2894,44 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        verify(mGroupHelper, never()).onNotificationPostedWithDelay(eq(r), any(), any());
    }
    @Test
    @EnableFlags({FLAG_NOTIFICATION_FORCE_GROUPING,
            android.app.Flags.FLAG_CHECK_AUTOGROUP_BEFORE_POST})
    public void testRemoveScheduledForceGroup_onNotificationCanceled() throws Exception {
        NotificationRecord r = generateNotificationRecord(mTestNotificationChannel, 0, "tag", null,
                false);
        when(mGroupHelper.onNotificationPosted(any(), anyBoolean())).thenReturn(false);
        mService.addEnqueuedNotification(r);
        NotificationManagerService.PostNotificationRunnable runnable =
                mService.new PostNotificationRunnable(r.getKey(), r.getSbn().getPackageName(),
                r.getUid(), mPostNotificationTrackerFactory.newTracker(null));
        runnable.run();
        waitForIdle();
        // Post an update to the notification
        NotificationRecord r_update =
                generateNotificationRecord(mTestNotificationChannel, 0, "tag", null, false);
        mService.addEnqueuedNotification(r_update);
        runnable = mService.new PostNotificationRunnable(r_update.getKey(),
                r_update.getSbn().getPackageName(), r_update.getUid(),
                mPostNotificationTrackerFactory.newTracker(null));
        runnable.run();
        waitForIdle();
        // Cancel the notification
        mBinderService.cancelNotificationWithTag(r.getSbn().getPackageName(),
                r.getSbn().getPackageName(), r.getSbn().getTag(),
                r.getSbn().getId(), r.getSbn().getUserId());
        waitForIdle();
        mTestableLooper.moveTimeForward(DELAY_FORCE_REGROUP_TIME);
        waitForIdle();
        // Check that onNotificationPostedWithDelay was canceled
        verify(mGroupHelper, times(1)).onNotificationPosted(any(), anyBoolean());
        verify(mGroupHelper, never()).onNotificationPostedWithDelay(any(), any(), any());
    }
    @Test
    @EnableFlags(FLAG_NOTIFICATION_FORCE_GROUPING)
    public void testEnqueueNotification_forceGrouped_clearsSummaryFlag() throws Exception {