diff options
-rw-r--r-- | services/core/java/com/android/server/notification/SnoozeHelper.java | 1 | ||||
-rw-r--r-- | services/tests/uiservicestests/src/com/android/server/notification/SnoozeHelperTest.java | 101 |
2 files changed, 102 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/notification/SnoozeHelper.java b/services/core/java/com/android/server/notification/SnoozeHelper.java index a178a525cede..732a58774b78 100644 --- a/services/core/java/com/android/server/notification/SnoozeHelper.java +++ b/services/core/java/com/android/server/notification/SnoozeHelper.java @@ -309,6 +309,7 @@ public class SnoozeHelper { return PendingIntent.getBroadcast(mContext, REQUEST_CODE_REPOST, new Intent(REPOST_ACTION) + .setPackage("android") .setData(new Uri.Builder().scheme(REPOST_SCHEME).appendPath(key).build()) .addFlags(Intent.FLAG_RECEIVER_FOREGROUND) .putExtra(EXTRA_KEY, key) diff --git a/services/tests/uiservicestests/src/com/android/server/notification/SnoozeHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/SnoozeHelperTest.java new file mode 100644 index 000000000000..aff0bfd9b6c8 --- /dev/null +++ b/services/tests/uiservicestests/src/com/android/server/notification/SnoozeHelperTest.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.server.notification; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import android.app.AlarmManager; +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.os.SystemClock; +import android.os.UserHandle; +import android.service.notification.StatusBarNotification; +import android.support.test.runner.AndroidJUnit4; +import android.test.suitebuilder.annotation.SmallTest; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Matchers.anyLong; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.android.server.UiServiceTestCase; + + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class SnoozeHelperTest extends UiServiceTestCase { + private static final String TEST_CHANNEL_ID = "test_channel_id"; + + @Mock SnoozeHelper.Callback mCallback; + @Mock AlarmManager mAm; + @Mock ManagedServices.UserProfiles mUserProfiles; + + private SnoozeHelper mSnoozeHelper; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + + mSnoozeHelper = new SnoozeHelper(getContext(), mCallback, mUserProfiles); + mSnoozeHelper.setAlarmManager(mAm); + } + + @Test + public void testSnoozeSentToAndroid() throws Exception { + NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); + mSnoozeHelper.snooze(r, 1000); + ArgumentCaptor<PendingIntent> captor = ArgumentCaptor.forClass(PendingIntent.class); + verify(mAm, times(1)).setExactAndAllowWhileIdle( + anyInt(), anyLong(), captor.capture()); + assertEquals("android", captor.getValue().getIntent().getPackage()); + } + + private NotificationRecord getNotificationRecord(String pkg, int id, String tag, + UserHandle user, String groupKey, boolean groupSummary) { + Notification n = new Notification.Builder(getContext(), TEST_CHANNEL_ID) + .setContentTitle("A") + .setGroup("G") + .setSortKey("A") + .setWhen(1205) + .setGroup(groupKey) + .setGroupSummary(groupSummary) + .build(); + final NotificationChannel notificationChannel = new NotificationChannel( + TEST_CHANNEL_ID, "name", NotificationManager.IMPORTANCE_LOW); + return new NotificationRecord(getContext(), new StatusBarNotification( + pkg, pkg, id, tag, 0, 0, n, user, null, + System.currentTimeMillis()), notificationChannel); + } + + private NotificationRecord getNotificationRecord(String pkg, int id, String tag, + UserHandle user) { + return getNotificationRecord(pkg, id, tag, user, null, false); + } +} |