|
84 | 84 |
|
85 | 85 | import android.app.ActivityManager; |
86 | 86 | import android.app.ActivityManagerInternal; |
| 87 | +import android.app.AlarmManager; |
87 | 88 | import android.app.AppOpsManager; |
88 | 89 | import android.app.AutomaticZenRule; |
89 | 90 | import android.app.IActivityManager; |
|
172 | 173 | import com.android.server.lights.LogicalLight; |
173 | 174 | import com.android.server.notification.NotificationManagerService.NotificationAssistants; |
174 | 175 | import com.android.server.notification.NotificationManagerService.NotificationListeners; |
| 176 | +import com.android.server.pm.PackageManagerService; |
175 | 177 | import com.android.server.statusbar.StatusBarManagerInternal; |
176 | 178 | import com.android.server.uri.UriGrantsManagerInternal; |
177 | 179 | import com.android.server.wm.ActivityTaskManagerInternal; |
@@ -285,6 +287,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { |
285 | 287 | NotificationHistoryManager mHistoryManager; |
286 | 288 | @Mock |
287 | 289 | StatsManager mStatsManager; |
| 290 | + @Mock |
| 291 | + AlarmManager mAlarmManager; |
288 | 292 | NotificationRecordLoggerFake mNotificationRecordLogger = new NotificationRecordLoggerFake(); |
289 | 293 | private InstanceIdSequence mNotificationInstanceIdSequence = new InstanceIdSequenceFake( |
290 | 294 | 1 << 30); |
@@ -426,6 +430,8 @@ public void setUp() throws Exception { |
426 | 430 | LocalServices.addService(DeviceIdleInternal.class, deviceIdleInternal); |
427 | 431 | LocalServices.removeServiceForTest(ActivityManagerInternal.class); |
428 | 432 | LocalServices.addService(ActivityManagerInternal.class, activityManagerInternal); |
| 433 | + mContext.addMockSystemService(Context.ALARM_SERVICE, mAlarmManager); |
| 434 | + |
429 | 435 |
|
430 | 436 | doNothing().when(mContext).sendBroadcastAsUser(any(), any(), any()); |
431 | 437 |
|
@@ -833,6 +839,26 @@ private NotificationRecord addGroupWithBubblesAndValidateAdded(boolean summaryAu |
833 | 839 | return nrSummary; |
834 | 840 | } |
835 | 841 |
|
| 842 | + @Test |
| 843 | + public void testLimitTimeOutBroadcast() { |
| 844 | + NotificationChannel channel = new NotificationChannel("id", "name", |
| 845 | + NotificationManager.IMPORTANCE_HIGH); |
| 846 | + Notification.Builder nb = new Notification.Builder(mContext, channel.getId()) |
| 847 | + .setContentTitle("foo") |
| 848 | + .setSmallIcon(android.R.drawable.sym_def_app_icon) |
| 849 | + .setTimeoutAfter(1); |
| 850 | + |
| 851 | + StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, |
| 852 | + nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); |
| 853 | + NotificationRecord r = new NotificationRecord(mContext, sbn, channel); |
| 854 | + |
| 855 | + mService.scheduleTimeoutLocked(r); |
| 856 | + ArgumentCaptor<PendingIntent> captor = ArgumentCaptor.forClass(PendingIntent.class); |
| 857 | + verify(mAlarmManager).setExactAndAllowWhileIdle(anyInt(), anyLong(), captor.capture()); |
| 858 | + assertEquals(PackageManagerService.PLATFORM_PACKAGE_NAME, |
| 859 | + captor.getValue().getIntent().getPackage()); |
| 860 | + } |
| 861 | + |
836 | 862 | @Test |
837 | 863 | public void testDefaultAssistant_overrideDefault() { |
838 | 864 | final int userId = 0; |
|
0 commit comments