Loading services/core/java/com/android/server/notification/NotificationManagerService.java +27 −24 Original line number Diff line number Diff line Loading @@ -8237,11 +8237,10 @@ public class NotificationManagerService extends SystemService { } } @VisibleForTesting @GuardedBy("mNotificationLock") void scheduleTimeoutLocked(NotificationRecord record) { if (record.getNotification().getTimeoutAfter() > 0) { final PendingIntent pi = PendingIntent.getBroadcast(getContext(), private PendingIntent getNotificationTimeoutPendingIntent(NotificationRecord record, int flags) { flags |= PendingIntent.FLAG_IMMUTABLE; return PendingIntent.getBroadcast(getContext(), REQUEST_CODE_TIMEOUT, new Intent(ACTION_NOTIFICATION_TIMEOUT) .setPackage(PackageManagerService.PLATFORM_PACKAGE_NAME) Loading @@ -8249,12 +8248,30 @@ public class NotificationManagerService extends SystemService { .appendPath(record.getKey()).build()) .addFlags(Intent.FLAG_RECEIVER_FOREGROUND) .putExtra(EXTRA_KEY, record.getKey()), PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); flags); } @VisibleForTesting @GuardedBy("mNotificationLock") void scheduleTimeoutLocked(NotificationRecord record) { if (record.getNotification().getTimeoutAfter() > 0) { final PendingIntent pi = getNotificationTimeoutPendingIntent( record, PendingIntent.FLAG_UPDATE_CURRENT); mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + record.getNotification().getTimeoutAfter(), pi); } } @VisibleForTesting @GuardedBy("mNotificationLock") void cancelScheduledTimeoutLocked(NotificationRecord record) { final PendingIntent pi = getNotificationTimeoutPendingIntent( record, PendingIntent.FLAG_CANCEL_CURRENT); if (pi != null) { mAlarmManager.cancel(pi); } } @VisibleForTesting @GuardedBy("mNotificationLock") /** Loading Loading @@ -9249,21 +9266,7 @@ public class NotificationManagerService extends SystemService { int rank, int count, boolean wasPosted, String listenerName, @ElapsedRealtimeLong long cancellationElapsedTimeMs) { final String canceledKey = r.getKey(); // Get pending intent used to create alarm, use FLAG_NO_CREATE if PendingIntent // does not already exist, then null will be returned. final PendingIntent pi = PendingIntent.getBroadcast(getContext(), REQUEST_CODE_TIMEOUT, new Intent(ACTION_NOTIFICATION_TIMEOUT) .setData(new Uri.Builder().scheme(SCHEME_TIMEOUT) .appendPath(r.getKey()).build()) .addFlags(Intent.FLAG_RECEIVER_FOREGROUND), PendingIntent.FLAG_NO_CREATE | PendingIntent.FLAG_IMMUTABLE); // Cancel alarm corresponding to pi. if (pi != null) { mAlarmManager.cancel(pi); } cancelScheduledTimeoutLocked(r); // Record caller. recordCallerLocked(r); Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +5 −0 Original line number Diff line number Diff line Loading @@ -1104,6 +1104,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { verify(mAlarmManager).setExactAndAllowWhileIdle(anyInt(), anyLong(), captor.capture()); assertEquals(PackageManagerService.PLATFORM_PACKAGE_NAME, captor.getValue().getIntent().getPackage()); mService.cancelScheduledTimeoutLocked(r); verify(mAlarmManager).cancel(captor.capture()); assertEquals(PackageManagerService.PLATFORM_PACKAGE_NAME, captor.getValue().getIntent().getPackage()); } @Test Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +27 −24 Original line number Diff line number Diff line Loading @@ -8237,11 +8237,10 @@ public class NotificationManagerService extends SystemService { } } @VisibleForTesting @GuardedBy("mNotificationLock") void scheduleTimeoutLocked(NotificationRecord record) { if (record.getNotification().getTimeoutAfter() > 0) { final PendingIntent pi = PendingIntent.getBroadcast(getContext(), private PendingIntent getNotificationTimeoutPendingIntent(NotificationRecord record, int flags) { flags |= PendingIntent.FLAG_IMMUTABLE; return PendingIntent.getBroadcast(getContext(), REQUEST_CODE_TIMEOUT, new Intent(ACTION_NOTIFICATION_TIMEOUT) .setPackage(PackageManagerService.PLATFORM_PACKAGE_NAME) Loading @@ -8249,12 +8248,30 @@ public class NotificationManagerService extends SystemService { .appendPath(record.getKey()).build()) .addFlags(Intent.FLAG_RECEIVER_FOREGROUND) .putExtra(EXTRA_KEY, record.getKey()), PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); flags); } @VisibleForTesting @GuardedBy("mNotificationLock") void scheduleTimeoutLocked(NotificationRecord record) { if (record.getNotification().getTimeoutAfter() > 0) { final PendingIntent pi = getNotificationTimeoutPendingIntent( record, PendingIntent.FLAG_UPDATE_CURRENT); mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + record.getNotification().getTimeoutAfter(), pi); } } @VisibleForTesting @GuardedBy("mNotificationLock") void cancelScheduledTimeoutLocked(NotificationRecord record) { final PendingIntent pi = getNotificationTimeoutPendingIntent( record, PendingIntent.FLAG_CANCEL_CURRENT); if (pi != null) { mAlarmManager.cancel(pi); } } @VisibleForTesting @GuardedBy("mNotificationLock") /** Loading Loading @@ -9249,21 +9266,7 @@ public class NotificationManagerService extends SystemService { int rank, int count, boolean wasPosted, String listenerName, @ElapsedRealtimeLong long cancellationElapsedTimeMs) { final String canceledKey = r.getKey(); // Get pending intent used to create alarm, use FLAG_NO_CREATE if PendingIntent // does not already exist, then null will be returned. final PendingIntent pi = PendingIntent.getBroadcast(getContext(), REQUEST_CODE_TIMEOUT, new Intent(ACTION_NOTIFICATION_TIMEOUT) .setData(new Uri.Builder().scheme(SCHEME_TIMEOUT) .appendPath(r.getKey()).build()) .addFlags(Intent.FLAG_RECEIVER_FOREGROUND), PendingIntent.FLAG_NO_CREATE | PendingIntent.FLAG_IMMUTABLE); // Cancel alarm corresponding to pi. if (pi != null) { mAlarmManager.cancel(pi); } cancelScheduledTimeoutLocked(r); // Record caller. recordCallerLocked(r); Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +5 −0 Original line number Diff line number Diff line Loading @@ -1104,6 +1104,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { verify(mAlarmManager).setExactAndAllowWhileIdle(anyInt(), anyLong(), captor.capture()); assertEquals(PackageManagerService.PLATFORM_PACKAGE_NAME, captor.getValue().getIntent().getPackage()); mService.cancelScheduledTimeoutLocked(r); verify(mAlarmManager).cancel(captor.capture()); assertEquals(PackageManagerService.PLATFORM_PACKAGE_NAME, captor.getValue().getIntent().getPackage()); } @Test Loading