Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 14 | * limitations under the License |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 15 | */ |
| 16 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.collection; |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 18 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 19 | import static android.app.AppOpsManager.OP_ACCEPT_HANDOVER; |
| 20 | import static android.app.AppOpsManager.OP_CAMERA; |
Julia Reynolds | 25926af | 2018-05-01 17:05:33 -0400 | [diff] [blame] | 21 | import static android.app.Notification.CATEGORY_ALARM; |
| 22 | import static android.app.Notification.CATEGORY_CALL; |
| 23 | import static android.app.Notification.CATEGORY_EVENT; |
| 24 | import static android.app.Notification.CATEGORY_MESSAGE; |
| 25 | import static android.app.Notification.CATEGORY_REMINDER; |
Julia Reynolds | efcd8bd | 2019-02-06 08:56:15 -0500 | [diff] [blame] | 26 | import static android.app.NotificationManager.IMPORTANCE_LOW; |
| 27 | import static android.app.NotificationManager.IMPORTANCE_MIN; |
| 28 | |
| 29 | import static com.android.systemui.statusbar.notification.collection.NotificationDataTest.TestableNotificationData.OVERRIDE_CHANNEL; |
| 30 | import static com.android.systemui.statusbar.notification.collection.NotificationDataTest.TestableNotificationData.OVERRIDE_IMPORTANCE; |
Julia Reynolds | 2b88ecd | 2019-05-29 18:09:41 -0400 | [diff] [blame] | 31 | import static com.android.systemui.statusbar.notification.collection.NotificationDataTest.TestableNotificationData.OVERRIDE_RANK; |
Julia Reynolds | efcd8bd | 2019-02-06 08:56:15 -0500 | [diff] [blame] | 32 | import static com.android.systemui.statusbar.notification.collection.NotificationDataTest.TestableNotificationData.OVERRIDE_VIS_EFFECTS; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 33 | |
| 34 | import static junit.framework.Assert.assertEquals; |
| 35 | |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 36 | import static org.junit.Assert.assertFalse; |
| 37 | import static org.junit.Assert.assertTrue; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 38 | import static org.mockito.ArgumentMatchers.any; |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 39 | import static org.mockito.Matchers.eq; |
| 40 | import static org.mockito.Mockito.mock; |
| 41 | import static org.mockito.Mockito.when; |
| 42 | |
| 43 | import android.Manifest; |
| 44 | import android.app.Notification; |
Selim Cinek | 608a57a | 2017-04-28 16:50:41 -0700 | [diff] [blame] | 45 | import android.app.NotificationChannel; |
Julia Reynolds | efcd8bd | 2019-02-06 08:56:15 -0500 | [diff] [blame] | 46 | import android.app.NotificationManager; |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 47 | import android.app.PendingIntent; |
Beverly | e98937a | 2018-11-15 10:18:57 -0500 | [diff] [blame] | 48 | import android.app.Person; |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 49 | import android.content.Intent; |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 50 | import android.content.pm.IPackageManager; |
| 51 | import android.content.pm.PackageManager; |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 52 | import android.graphics.drawable.Icon; |
Julia Reynolds | 5bbb6da | 2018-03-28 10:48:37 -0400 | [diff] [blame] | 53 | import android.media.session.MediaSession; |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 54 | import android.os.Bundle; |
Yohei Yukawa | 7276946 | 2019-01-20 09:28:08 -0800 | [diff] [blame] | 55 | import android.os.Process; |
Selim Cinek | 608a57a | 2017-04-28 16:50:41 -0700 | [diff] [blame] | 56 | import android.service.notification.NotificationListenerService; |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 57 | import android.service.notification.NotificationListenerService.Ranking; |
| 58 | import android.service.notification.SnoozeCriterion; |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 59 | import android.service.notification.StatusBarNotification; |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 60 | import android.testing.AndroidTestingRunner; |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 61 | import android.testing.TestableLooper; |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 62 | import android.testing.TestableLooper.RunWithLooper; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 63 | import android.util.ArraySet; |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 64 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 65 | import com.android.systemui.Dependency; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 66 | import com.android.systemui.ForegroundServiceController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 67 | import com.android.systemui.InitController; |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 68 | import com.android.systemui.SysuiTestCase; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 69 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 70 | import com.android.systemui.statusbar.NotificationTestHelper; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 71 | import com.android.systemui.statusbar.notification.collection.NotificationData.KeyguardEnvironment; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 72 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Selim Cinek | 608a57a | 2017-04-28 16:50:41 -0700 | [diff] [blame] | 73 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 74 | import com.android.systemui.statusbar.phone.ShadeController; |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 75 | |
| 76 | import org.junit.Before; |
| 77 | import org.junit.Test; |
| 78 | import org.junit.runner.RunWith; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 79 | import org.mockito.Mock; |
| 80 | import org.mockito.MockitoAnnotations; |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 81 | |
Dieter Hsu | 36e1ebc | 2018-06-06 15:41:46 +0800 | [diff] [blame] | 82 | import java.util.ArrayList; |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 83 | import java.util.Collections; |
Julia Reynolds | 2b88ecd | 2019-05-29 18:09:41 -0400 | [diff] [blame] | 84 | import java.util.HashMap; |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 85 | import java.util.List; |
Julia Reynolds | 2b88ecd | 2019-05-29 18:09:41 -0400 | [diff] [blame] | 86 | import java.util.Map; |
| 87 | |
| 88 | import androidx.test.filters.SmallTest; |
Dieter Hsu | 36e1ebc | 2018-06-06 15:41:46 +0800 | [diff] [blame] | 89 | |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 90 | @SmallTest |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 91 | @RunWith(AndroidTestingRunner.class) |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 92 | @RunWithLooper |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 93 | public class NotificationDataTest extends SysuiTestCase { |
| 94 | |
| 95 | private static final int UID_NORMAL = 123; |
| 96 | private static final int UID_ALLOW_DURING_SETUP = 456; |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 97 | private static final NotificationChannel NOTIFICATION_CHANNEL = |
| 98 | new NotificationChannel("id", "name", NotificationChannel.USER_LOCKED_IMPORTANCE); |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 99 | |
| 100 | private final StatusBarNotification mMockStatusBarNotification = |
| 101 | mock(StatusBarNotification.class); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 102 | @Mock |
| 103 | ForegroundServiceController mFsc; |
| 104 | @Mock |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 105 | NotificationData.KeyguardEnvironment mEnvironment; |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 106 | |
| 107 | private final IPackageManager mMockPackageManager = mock(IPackageManager.class); |
Julia Reynolds | efcd8bd | 2019-02-06 08:56:15 -0500 | [diff] [blame] | 108 | private TestableNotificationData mNotificationData; |
Selim Cinek | 608a57a | 2017-04-28 16:50:41 -0700 | [diff] [blame] | 109 | private ExpandableNotificationRow mRow; |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 110 | |
| 111 | @Before |
| 112 | public void setUp() throws Exception { |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 113 | com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper(); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 114 | MockitoAnnotations.initMocks(this); |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 115 | when(mMockStatusBarNotification.getUid()).thenReturn(UID_NORMAL); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 116 | when(mMockStatusBarNotification.cloneLight()).thenReturn(mMockStatusBarNotification); |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 117 | |
| 118 | when(mMockPackageManager.checkUidPermission( |
| 119 | eq(Manifest.permission.NOTIFICATION_DURING_SETUP), |
| 120 | eq(UID_NORMAL))) |
| 121 | .thenReturn(PackageManager.PERMISSION_DENIED); |
| 122 | when(mMockPackageManager.checkUidPermission( |
| 123 | eq(Manifest.permission.NOTIFICATION_DURING_SETUP), |
| 124 | eq(UID_ALLOW_DURING_SETUP))) |
| 125 | .thenReturn(PackageManager.PERMISSION_GRANTED); |
Selim Cinek | 608a57a | 2017-04-28 16:50:41 -0700 | [diff] [blame] | 126 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 127 | mDependency.injectTestDependency(ForegroundServiceController.class, mFsc); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 128 | mDependency.injectTestDependency(NotificationGroupManager.class, |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 129 | new NotificationGroupManager(mock(StatusBarStateController.class))); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 130 | mDependency.injectMockDependency(ShadeController.class); |
| 131 | mDependency.injectTestDependency(KeyguardEnvironment.class, mEnvironment); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 132 | when(mEnvironment.isDeviceProvisioned()).thenReturn(true); |
| 133 | when(mEnvironment.isNotificationForCurrentProfiles(any())).thenReturn(true); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 134 | mNotificationData = new TestableNotificationData(); |
Selim Cinek | 608a57a | 2017-04-28 16:50:41 -0700 | [diff] [blame] | 135 | mNotificationData.updateRanking(mock(NotificationListenerService.RankingMap.class)); |
| 136 | mRow = new NotificationTestHelper(getContext()).createRow(); |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 137 | Dependency.get(InitController.class).executePostInitTasks(); |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | @Test |
Selim Cinek | 608a57a | 2017-04-28 16:50:41 -0700 | [diff] [blame] | 141 | public void testChannelSetWhenAdded() { |
Julia Reynolds | 2b88ecd | 2019-05-29 18:09:41 -0400 | [diff] [blame] | 142 | Bundle override = new Bundle(); |
| 143 | override.putParcelable(OVERRIDE_CHANNEL, NOTIFICATION_CHANNEL); |
| 144 | mNotificationData.rankingOverrides.put(mRow.getEntry().key, override); |
Selim Cinek | 608a57a | 2017-04-28 16:50:41 -0700 | [diff] [blame] | 145 | mNotificationData.add(mRow.getEntry()); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 146 | assertEquals(NOTIFICATION_CHANNEL, mRow.getEntry().channel); |
Selim Cinek | 608a57a | 2017-04-28 16:50:41 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 149 | @Test |
| 150 | public void testAllRelevantNotisTaggedWithAppOps() throws Exception { |
| 151 | mNotificationData.add(mRow.getEntry()); |
| 152 | ExpandableNotificationRow row2 = new NotificationTestHelper(getContext()).createRow(); |
| 153 | mNotificationData.add(row2.getEntry()); |
| 154 | ExpandableNotificationRow diffPkg = |
Yohei Yukawa | 7276946 | 2019-01-20 09:28:08 -0800 | [diff] [blame] | 155 | new NotificationTestHelper(getContext()).createRow("pkg", 4000, |
| 156 | Process.myUserHandle()); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 157 | mNotificationData.add(diffPkg.getEntry()); |
| 158 | |
| 159 | ArraySet<Integer> expectedOps = new ArraySet<>(); |
| 160 | expectedOps.add(OP_CAMERA); |
| 161 | expectedOps.add(OP_ACCEPT_HANDOVER); |
| 162 | |
| 163 | for (int op : expectedOps) { |
| 164 | mNotificationData.updateAppOp(op, NotificationTestHelper.UID, |
Julia Reynolds | 9159006 | 2018-04-02 16:24:11 -0400 | [diff] [blame] | 165 | NotificationTestHelper.PKG, mRow.getEntry().key, true); |
| 166 | mNotificationData.updateAppOp(op, NotificationTestHelper.UID, |
| 167 | NotificationTestHelper.PKG, row2.getEntry().key, true); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 168 | } |
| 169 | for (int op : expectedOps) { |
| 170 | assertTrue(mRow.getEntry().key + " doesn't have op " + op, |
| 171 | mNotificationData.get(mRow.getEntry().key).mActiveAppOps.contains(op)); |
| 172 | assertTrue(row2.getEntry().key + " doesn't have op " + op, |
| 173 | mNotificationData.get(row2.getEntry().key).mActiveAppOps.contains(op)); |
| 174 | assertFalse(diffPkg.getEntry().key + " has op " + op, |
| 175 | mNotificationData.get(diffPkg.getEntry().key).mActiveAppOps.contains(op)); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | @Test |
| 180 | public void testAppOpsRemoval() throws Exception { |
| 181 | mNotificationData.add(mRow.getEntry()); |
| 182 | ExpandableNotificationRow row2 = new NotificationTestHelper(getContext()).createRow(); |
| 183 | mNotificationData.add(row2.getEntry()); |
| 184 | |
| 185 | ArraySet<Integer> expectedOps = new ArraySet<>(); |
| 186 | expectedOps.add(OP_CAMERA); |
| 187 | expectedOps.add(OP_ACCEPT_HANDOVER); |
| 188 | |
| 189 | for (int op : expectedOps) { |
| 190 | mNotificationData.updateAppOp(op, NotificationTestHelper.UID, |
Julia Reynolds | 9159006 | 2018-04-02 16:24:11 -0400 | [diff] [blame] | 191 | NotificationTestHelper.PKG, row2.getEntry().key, true); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | expectedOps.remove(OP_ACCEPT_HANDOVER); |
| 195 | mNotificationData.updateAppOp(OP_ACCEPT_HANDOVER, NotificationTestHelper.UID, |
Julia Reynolds | 9159006 | 2018-04-02 16:24:11 -0400 | [diff] [blame] | 196 | NotificationTestHelper.PKG, row2.getEntry().key, false); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 197 | |
| 198 | assertTrue(mRow.getEntry().key + " doesn't have op " + OP_CAMERA, |
| 199 | mNotificationData.get(mRow.getEntry().key).mActiveAppOps.contains(OP_CAMERA)); |
| 200 | assertTrue(row2.getEntry().key + " doesn't have op " + OP_CAMERA, |
| 201 | mNotificationData.get(row2.getEntry().key).mActiveAppOps.contains(OP_CAMERA)); |
| 202 | assertFalse(mRow.getEntry().key + " has op " + OP_ACCEPT_HANDOVER, |
| 203 | mNotificationData.get(mRow.getEntry().key) |
| 204 | .mActiveAppOps.contains(OP_ACCEPT_HANDOVER)); |
| 205 | assertFalse(row2.getEntry().key + " has op " + OP_ACCEPT_HANDOVER, |
| 206 | mNotificationData.get(row2.getEntry().key) |
| 207 | .mActiveAppOps.contains(OP_ACCEPT_HANDOVER)); |
| 208 | } |
| 209 | |
| 210 | @Test |
Dieter Hsu | 36e1ebc | 2018-06-06 15:41:46 +0800 | [diff] [blame] | 211 | public void testGetNotificationsForCurrentUser_shouldFilterNonCurrentUserNotifications() |
| 212 | throws Exception { |
| 213 | mNotificationData.add(mRow.getEntry()); |
| 214 | ExpandableNotificationRow row2 = new NotificationTestHelper(getContext()).createRow(); |
| 215 | mNotificationData.add(row2.getEntry()); |
| 216 | |
| 217 | when(mEnvironment.isNotificationForCurrentProfiles( |
| 218 | mRow.getEntry().notification)).thenReturn(false); |
| 219 | when(mEnvironment.isNotificationForCurrentProfiles( |
| 220 | row2.getEntry().notification)).thenReturn(true); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 221 | ArrayList<NotificationEntry> result = |
Dieter Hsu | 36e1ebc | 2018-06-06 15:41:46 +0800 | [diff] [blame] | 222 | mNotificationData.getNotificationsForCurrentUser(); |
| 223 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 224 | assertEquals(result.size(), 1); |
| 225 | junit.framework.Assert.assertEquals(result.get(0), row2.getEntry()); |
Dieter Hsu | 36e1ebc | 2018-06-06 15:41:46 +0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | @Test |
Julia Reynolds | 5bbb6da | 2018-03-28 10:48:37 -0400 | [diff] [blame] | 229 | public void testIsExemptFromDndVisualSuppression_foreground() { |
| 230 | initStatusBarNotification(false); |
Julia Reynolds | efcd8bd | 2019-02-06 08:56:15 -0500 | [diff] [blame] | 231 | |
Julia Reynolds | 5bbb6da | 2018-03-28 10:48:37 -0400 | [diff] [blame] | 232 | Notification n = mMockStatusBarNotification.getNotification(); |
| 233 | n.flags = Notification.FLAG_FOREGROUND_SERVICE; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 234 | NotificationEntry entry = new NotificationEntry(mMockStatusBarNotification); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 235 | mNotificationData.add(entry); |
Julia Reynolds | 2b88ecd | 2019-05-29 18:09:41 -0400 | [diff] [blame] | 236 | Bundle override = new Bundle(); |
| 237 | override.putInt(OVERRIDE_VIS_EFFECTS, 255); |
| 238 | mNotificationData.rankingOverrides.put(entry.key, override); |
Julia Reynolds | 5bbb6da | 2018-03-28 10:48:37 -0400 | [diff] [blame] | 239 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 240 | assertTrue(entry.isExemptFromDndVisualSuppression()); |
| 241 | assertFalse(entry.shouldSuppressAmbient()); |
Julia Reynolds | 5bbb6da | 2018-03-28 10:48:37 -0400 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | @Test |
| 245 | public void testIsExemptFromDndVisualSuppression_media() { |
| 246 | initStatusBarNotification(false); |
Julia Reynolds | 5bbb6da | 2018-03-28 10:48:37 -0400 | [diff] [blame] | 247 | Notification n = mMockStatusBarNotification.getNotification(); |
| 248 | Notification.Builder nb = Notification.Builder.recoverBuilder(mContext, n); |
| 249 | nb.setStyle(new Notification.MediaStyle().setMediaSession(mock(MediaSession.Token.class))); |
| 250 | n = nb.build(); |
| 251 | when(mMockStatusBarNotification.getNotification()).thenReturn(n); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 252 | NotificationEntry entry = new NotificationEntry(mMockStatusBarNotification); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 253 | mNotificationData.add(entry); |
Julia Reynolds | 2b88ecd | 2019-05-29 18:09:41 -0400 | [diff] [blame] | 254 | Bundle override = new Bundle(); |
| 255 | override.putInt(OVERRIDE_VIS_EFFECTS, 255); |
| 256 | mNotificationData.rankingOverrides.put(entry.key, override); |
Julia Reynolds | 5bbb6da | 2018-03-28 10:48:37 -0400 | [diff] [blame] | 257 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 258 | assertTrue(entry.isExemptFromDndVisualSuppression()); |
| 259 | assertFalse(entry.shouldSuppressAmbient()); |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | @Test |
| 263 | public void testIsExemptFromDndVisualSuppression_system() { |
| 264 | initStatusBarNotification(false); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 265 | NotificationEntry entry = new NotificationEntry(mMockStatusBarNotification); |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 266 | entry.mIsSystemNotification = true; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 267 | mNotificationData.add(entry); |
Julia Reynolds | 2b88ecd | 2019-05-29 18:09:41 -0400 | [diff] [blame] | 268 | Bundle override = new Bundle(); |
| 269 | override.putInt(OVERRIDE_VIS_EFFECTS, 255); |
| 270 | mNotificationData.rankingOverrides.put(entry.key, override); |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 271 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 272 | assertTrue(entry.isExemptFromDndVisualSuppression()); |
| 273 | assertFalse(entry.shouldSuppressAmbient()); |
Julia Reynolds | 5bbb6da | 2018-03-28 10:48:37 -0400 | [diff] [blame] | 274 | } |
| 275 | |
Julia Reynolds | 25926af | 2018-05-01 17:05:33 -0400 | [diff] [blame] | 276 | @Test |
| 277 | public void testIsNotExemptFromDndVisualSuppression_hiddenCategories() { |
| 278 | initStatusBarNotification(false); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 279 | NotificationEntry entry = new NotificationEntry(mMockStatusBarNotification); |
Julia Reynolds | 25926af | 2018-05-01 17:05:33 -0400 | [diff] [blame] | 280 | entry.mIsSystemNotification = true; |
Julia Reynolds | 2b88ecd | 2019-05-29 18:09:41 -0400 | [diff] [blame] | 281 | Bundle override = new Bundle(); |
| 282 | override.putInt(OVERRIDE_VIS_EFFECTS, NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT); |
| 283 | mNotificationData.rankingOverrides.put(entry.key, override); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 284 | mNotificationData.add(entry); |
| 285 | |
Julia Reynolds | 25926af | 2018-05-01 17:05:33 -0400 | [diff] [blame] | 286 | when(mMockStatusBarNotification.getNotification()).thenReturn( |
| 287 | new Notification.Builder(mContext, "").setCategory(CATEGORY_CALL).build()); |
| 288 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 289 | assertFalse(entry.isExemptFromDndVisualSuppression()); |
| 290 | assertTrue(entry.shouldSuppressAmbient()); |
Julia Reynolds | 25926af | 2018-05-01 17:05:33 -0400 | [diff] [blame] | 291 | |
| 292 | when(mMockStatusBarNotification.getNotification()).thenReturn( |
| 293 | new Notification.Builder(mContext, "").setCategory(CATEGORY_REMINDER).build()); |
| 294 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 295 | assertFalse(entry.isExemptFromDndVisualSuppression()); |
Julia Reynolds | 25926af | 2018-05-01 17:05:33 -0400 | [diff] [blame] | 296 | |
| 297 | when(mMockStatusBarNotification.getNotification()).thenReturn( |
| 298 | new Notification.Builder(mContext, "").setCategory(CATEGORY_ALARM).build()); |
| 299 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 300 | assertFalse(entry.isExemptFromDndVisualSuppression()); |
Julia Reynolds | 25926af | 2018-05-01 17:05:33 -0400 | [diff] [blame] | 301 | |
| 302 | when(mMockStatusBarNotification.getNotification()).thenReturn( |
| 303 | new Notification.Builder(mContext, "").setCategory(CATEGORY_EVENT).build()); |
| 304 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 305 | assertFalse(entry.isExemptFromDndVisualSuppression()); |
Julia Reynolds | 25926af | 2018-05-01 17:05:33 -0400 | [diff] [blame] | 306 | |
| 307 | when(mMockStatusBarNotification.getNotification()).thenReturn( |
| 308 | new Notification.Builder(mContext, "").setCategory(CATEGORY_MESSAGE).build()); |
| 309 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 310 | assertFalse(entry.isExemptFromDndVisualSuppression()); |
Julia Reynolds | 25926af | 2018-05-01 17:05:33 -0400 | [diff] [blame] | 311 | } |
| 312 | |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 313 | @Test |
| 314 | public void testCreateNotificationDataEntry_RankingUpdate() { |
| 315 | Ranking ranking = mock(Ranking.class); |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 316 | initStatusBarNotification(false); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 317 | |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 318 | List<Notification.Action> appGeneratedSmartActions = |
| 319 | Collections.singletonList(createContextualAction("appGeneratedAction")); |
| 320 | mMockStatusBarNotification.getNotification().actions = |
| 321 | appGeneratedSmartActions.toArray(new Notification.Action[0]); |
| 322 | |
| 323 | List<Notification.Action> systemGeneratedSmartActions = |
| 324 | Collections.singletonList(createAction("systemGeneratedAction")); |
| 325 | when(ranking.getSmartActions()).thenReturn(systemGeneratedSmartActions); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 326 | |
| 327 | when(ranking.getChannel()).thenReturn(NOTIFICATION_CHANNEL); |
| 328 | |
| 329 | when(ranking.getUserSentiment()).thenReturn(Ranking.USER_SENTIMENT_NEGATIVE); |
| 330 | |
| 331 | SnoozeCriterion snoozeCriterion = new SnoozeCriterion("id", "explanation", "confirmation"); |
| 332 | ArrayList<SnoozeCriterion> snoozeCriterions = new ArrayList<>(); |
| 333 | snoozeCriterions.add(snoozeCriterion); |
| 334 | when(ranking.getSnoozeCriteria()).thenReturn(snoozeCriterions); |
| 335 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 336 | NotificationEntry entry = |
| 337 | new NotificationEntry(mMockStatusBarNotification, ranking); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 338 | |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 339 | assertEquals(systemGeneratedSmartActions, entry.systemGeneratedSmartActions); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 340 | assertEquals(NOTIFICATION_CHANNEL, entry.channel); |
| 341 | assertEquals(Ranking.USER_SENTIMENT_NEGATIVE, entry.userSentiment); |
| 342 | assertEquals(snoozeCriterions, entry.snoozeCriteria); |
| 343 | } |
| 344 | |
Beverly | e98937a | 2018-11-15 10:18:57 -0500 | [diff] [blame] | 345 | @Test |
| 346 | public void notificationDataEntry_testIsLastMessageFromReply() { |
| 347 | Person.Builder person = new Person.Builder() |
| 348 | .setName("name") |
| 349 | .setKey("abc") |
| 350 | .setUri("uri") |
| 351 | .setBot(true); |
| 352 | |
| 353 | // EXTRA_MESSAGING_PERSON is the same Person as the sender in last message in EXTRA_MESSAGES |
| 354 | Bundle bundle = new Bundle(); |
| 355 | bundle.putParcelable(Notification.EXTRA_MESSAGING_PERSON, person.build()); |
| 356 | Bundle[] messagesBundle = new Bundle[]{ new Notification.MessagingStyle.Message( |
| 357 | "text", 0, person.build()).toBundle() }; |
| 358 | bundle.putParcelableArray(Notification.EXTRA_MESSAGES, messagesBundle); |
| 359 | |
| 360 | Notification notification = new Notification.Builder(mContext, "test") |
| 361 | .addExtras(bundle) |
| 362 | .build(); |
| 363 | StatusBarNotification sbn = new StatusBarNotification("pkg", "pkg", 0, "tag", 0, 0, |
| 364 | notification, mContext.getUser(), "", 0); |
| 365 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 366 | NotificationEntry entry = new NotificationEntry(sbn); |
Beverly | e98937a | 2018-11-15 10:18:57 -0500 | [diff] [blame] | 367 | entry.setHasSentReply(); |
| 368 | |
| 369 | assertTrue(entry.isLastMessageFromReply()); |
| 370 | } |
| 371 | |
Julia Reynolds | efcd8bd | 2019-02-06 08:56:15 -0500 | [diff] [blame] | 372 | @Test |
| 373 | public void personHighPriority() { |
| 374 | Person person = new Person.Builder() |
| 375 | .setName("name") |
| 376 | .setKey("abc") |
| 377 | .setUri("uri") |
| 378 | .setBot(true) |
| 379 | .build(); |
| 380 | |
| 381 | Notification notification = new Notification.Builder(mContext, "test") |
| 382 | .addPerson(person) |
| 383 | .build(); |
| 384 | |
| 385 | StatusBarNotification sbn = new StatusBarNotification("pkg", "pkg", 0, "tag", 0, 0, |
| 386 | notification, mContext.getUser(), "", 0); |
| 387 | |
| 388 | assertTrue(mNotificationData.isHighPriority(sbn)); |
| 389 | } |
| 390 | |
| 391 | @Test |
| 392 | public void messagingStyleHighPriority() { |
| 393 | |
| 394 | Notification notification = new Notification.Builder(mContext, "test") |
| 395 | .setStyle(new Notification.MessagingStyle("")) |
| 396 | .build(); |
| 397 | |
| 398 | StatusBarNotification sbn = new StatusBarNotification("pkg", "pkg", 0, "tag", 0, 0, |
| 399 | notification, mContext.getUser(), "", 0); |
| 400 | |
| 401 | assertTrue(mNotificationData.isHighPriority(sbn)); |
| 402 | } |
| 403 | |
| 404 | @Test |
| 405 | public void minForegroundNotHighPriority() { |
| 406 | Notification notification = mock(Notification.class); |
| 407 | when(notification.isForegroundService()).thenReturn(true); |
| 408 | |
Julia Reynolds | efcd8bd | 2019-02-06 08:56:15 -0500 | [diff] [blame] | 409 | StatusBarNotification sbn = new StatusBarNotification("pkg", "pkg", 0, "tag", 0, 0, |
| 410 | notification, mContext.getUser(), "", 0); |
| 411 | |
Julia Reynolds | 2b88ecd | 2019-05-29 18:09:41 -0400 | [diff] [blame] | 412 | Bundle override = new Bundle(); |
| 413 | override.putInt(OVERRIDE_IMPORTANCE, IMPORTANCE_MIN); |
| 414 | mNotificationData.rankingOverrides.put(sbn.getKey(), override); |
| 415 | |
Julia Reynolds | efcd8bd | 2019-02-06 08:56:15 -0500 | [diff] [blame] | 416 | assertFalse(mNotificationData.isHighPriority(sbn)); |
| 417 | } |
| 418 | |
| 419 | @Test |
| 420 | public void lowForegroundHighPriority() { |
| 421 | Notification notification = mock(Notification.class); |
| 422 | when(notification.isForegroundService()).thenReturn(true); |
| 423 | |
Julia Reynolds | 2b88ecd | 2019-05-29 18:09:41 -0400 | [diff] [blame] | 424 | StatusBarNotification sbn = new StatusBarNotification("pkg", "pkg", 0, "tag", 0, 0, |
| 425 | notification, mContext.getUser(), "", 0); |
| 426 | |
| 427 | Bundle override = new Bundle(); |
| 428 | override.putInt(OVERRIDE_IMPORTANCE, IMPORTANCE_LOW); |
| 429 | mNotificationData.rankingOverrides.put(sbn.getKey(), override); |
| 430 | |
| 431 | assertTrue(mNotificationData.isHighPriority(sbn)); |
| 432 | } |
| 433 | |
| 434 | @Test |
| 435 | public void userChangeTrumpsHighPriorityCharacteristics() { |
| 436 | Person person = new Person.Builder() |
| 437 | .setName("name") |
| 438 | .setKey("abc") |
| 439 | .setUri("uri") |
| 440 | .setBot(true) |
| 441 | .build(); |
| 442 | |
| 443 | Notification notification = new Notification.Builder(mContext, "test") |
| 444 | .addPerson(person) |
| 445 | .setStyle(new Notification.MessagingStyle("")) |
| 446 | .setFlag(Notification.FLAG_FOREGROUND_SERVICE, true) |
| 447 | .build(); |
Julia Reynolds | efcd8bd | 2019-02-06 08:56:15 -0500 | [diff] [blame] | 448 | |
| 449 | StatusBarNotification sbn = new StatusBarNotification("pkg", "pkg", 0, "tag", 0, 0, |
| 450 | notification, mContext.getUser(), "", 0); |
| 451 | |
Julia Reynolds | 2b88ecd | 2019-05-29 18:09:41 -0400 | [diff] [blame] | 452 | NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_LOW); |
| 453 | channel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE); |
| 454 | |
| 455 | Bundle override = new Bundle(); |
| 456 | override.putParcelable(OVERRIDE_CHANNEL, channel); |
| 457 | mNotificationData.rankingOverrides.put(sbn.getKey(), override); |
| 458 | |
| 459 | assertFalse(mNotificationData.isHighPriority(sbn)); |
| 460 | } |
| 461 | |
| 462 | @Test |
| 463 | public void testSort_highPriorityTrumpsNMSRank() { |
| 464 | // NMS rank says A and then B. But A is not high priority and B is, so B should sort in |
| 465 | // front |
| 466 | Notification aN = new Notification.Builder(mContext, "test") |
| 467 | .setStyle(new Notification.MessagingStyle("")) |
| 468 | .build(); |
| 469 | StatusBarNotification aSbn = new StatusBarNotification("pkg", "pkg", 0, "tag", 0, 0, |
| 470 | aN, mContext.getUser(), "", 0); |
| 471 | NotificationEntry a = new NotificationEntry(aSbn); |
| 472 | a.setRow(mock(ExpandableNotificationRow.class)); |
| 473 | a.setIsHighPriority(false); |
| 474 | |
| 475 | Bundle override = new Bundle(); |
| 476 | override.putInt(OVERRIDE_IMPORTANCE, IMPORTANCE_LOW); |
| 477 | override.putInt(OVERRIDE_RANK, 1); |
| 478 | mNotificationData.rankingOverrides.put(a.key, override); |
| 479 | |
| 480 | Notification bN = new Notification.Builder(mContext, "test") |
| 481 | .setStyle(new Notification.MessagingStyle("")) |
| 482 | .build(); |
| 483 | StatusBarNotification bSbn = new StatusBarNotification("pkg2", "pkg2", 0, "tag", 0, 0, |
| 484 | bN, mContext.getUser(), "", 0); |
| 485 | NotificationEntry b = new NotificationEntry(bSbn); |
| 486 | b.setIsHighPriority(true); |
| 487 | b.setRow(mock(ExpandableNotificationRow.class)); |
| 488 | |
| 489 | Bundle bOverride = new Bundle(); |
| 490 | bOverride.putInt(OVERRIDE_IMPORTANCE, IMPORTANCE_LOW); |
| 491 | bOverride.putInt(OVERRIDE_RANK, 2); |
| 492 | mNotificationData.rankingOverrides.put(b.key, bOverride); |
| 493 | |
| 494 | assertEquals(1, mNotificationData.mRankingComparator.compare(a, b)); |
| 495 | } |
| 496 | |
| 497 | @Test |
| 498 | public void testSort_samePriorityUsesNMSRank() { |
| 499 | // NMS rank says A and then B. But A is not high priority and B is, so B should sort in |
| 500 | // front |
| 501 | Notification aN = new Notification.Builder(mContext, "test") |
| 502 | .setStyle(new Notification.MessagingStyle("")) |
| 503 | .build(); |
| 504 | StatusBarNotification aSbn = new StatusBarNotification("pkg", "pkg", 0, "tag", 0, 0, |
| 505 | aN, mContext.getUser(), "", 0); |
| 506 | NotificationEntry a = new NotificationEntry(aSbn); |
| 507 | a.setRow(mock(ExpandableNotificationRow.class)); |
| 508 | a.setIsHighPriority(false); |
| 509 | |
| 510 | Bundle override = new Bundle(); |
| 511 | override.putInt(OVERRIDE_IMPORTANCE, IMPORTANCE_LOW); |
| 512 | override.putInt(OVERRIDE_RANK, 1); |
| 513 | mNotificationData.rankingOverrides.put(a.key, override); |
| 514 | |
| 515 | Notification bN = new Notification.Builder(mContext, "test") |
| 516 | .setStyle(new Notification.MessagingStyle("")) |
| 517 | .build(); |
| 518 | StatusBarNotification bSbn = new StatusBarNotification("pkg2", "pkg2", 0, "tag", 0, 0, |
| 519 | bN, mContext.getUser(), "", 0); |
| 520 | NotificationEntry b = new NotificationEntry(bSbn); |
| 521 | b.setRow(mock(ExpandableNotificationRow.class)); |
| 522 | b.setIsHighPriority(false); |
| 523 | |
| 524 | Bundle bOverride = new Bundle(); |
| 525 | bOverride.putInt(OVERRIDE_IMPORTANCE, IMPORTANCE_LOW); |
| 526 | bOverride.putInt(OVERRIDE_RANK, 2); |
| 527 | mNotificationData.rankingOverrides.put(b.key, bOverride); |
| 528 | |
| 529 | assertEquals(-1, mNotificationData.mRankingComparator.compare(a, b)); |
Julia Reynolds | efcd8bd | 2019-02-06 08:56:15 -0500 | [diff] [blame] | 530 | } |
| 531 | |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 532 | private void initStatusBarNotification(boolean allowDuringSetup) { |
| 533 | Bundle bundle = new Bundle(); |
| 534 | bundle.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, allowDuringSetup); |
| 535 | Notification notification = new Notification.Builder(mContext, "test") |
| 536 | .addExtras(bundle) |
| 537 | .build(); |
| 538 | when(mMockStatusBarNotification.getNotification()).thenReturn(notification); |
| 539 | } |
Selim Cinek | 608a57a | 2017-04-28 16:50:41 -0700 | [diff] [blame] | 540 | |
Julia Reynolds | efcd8bd | 2019-02-06 08:56:15 -0500 | [diff] [blame] | 541 | public static class TestableNotificationData extends NotificationData { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 542 | public TestableNotificationData() { |
| 543 | super(); |
Selim Cinek | 608a57a | 2017-04-28 16:50:41 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Julia Reynolds | efcd8bd | 2019-02-06 08:56:15 -0500 | [diff] [blame] | 546 | public static final String OVERRIDE_RANK = "r"; |
| 547 | public static final String OVERRIDE_DND = "dnd"; |
| 548 | public static final String OVERRIDE_VIS_OVERRIDE = "vo"; |
| 549 | public static final String OVERRIDE_VIS_EFFECTS = "ve"; |
| 550 | public static final String OVERRIDE_IMPORTANCE = "i"; |
| 551 | public static final String OVERRIDE_IMP_EXP = "ie"; |
| 552 | public static final String OVERRIDE_GROUP = "g"; |
| 553 | public static final String OVERRIDE_CHANNEL = "c"; |
| 554 | public static final String OVERRIDE_PEOPLE = "p"; |
| 555 | public static final String OVERRIDE_SNOOZE_CRITERIA = "sc"; |
| 556 | public static final String OVERRIDE_BADGE = "b"; |
| 557 | public static final String OVERRIDE_USER_SENTIMENT = "us"; |
| 558 | public static final String OVERRIDE_HIDDEN = "h"; |
| 559 | public static final String OVERRIDE_LAST_ALERTED = "la"; |
| 560 | public static final String OVERRIDE_NOISY = "n"; |
| 561 | public static final String OVERRIDE_SMART_ACTIONS = "sa"; |
| 562 | public static final String OVERRIDE_SMART_REPLIES = "sr"; |
| 563 | public static final String OVERRIDE_BUBBLE = "cb"; |
| 564 | |
Julia Reynolds | 2b88ecd | 2019-05-29 18:09:41 -0400 | [diff] [blame] | 565 | public Map<String, Bundle> rankingOverrides = new HashMap<>(); |
Julia Reynolds | efcd8bd | 2019-02-06 08:56:15 -0500 | [diff] [blame] | 566 | |
Selim Cinek | 608a57a | 2017-04-28 16:50:41 -0700 | [diff] [blame] | 567 | @Override |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 568 | protected boolean getRanking(String key, Ranking outRanking) { |
Kensuke Matsui | efa1a74 | 2017-08-03 12:12:36 +0900 | [diff] [blame] | 569 | super.getRanking(key, outRanking); |
Julia Reynolds | efcd8bd | 2019-02-06 08:56:15 -0500 | [diff] [blame] | 570 | |
| 571 | ArrayList<String> currentAdditionalPeople = new ArrayList<>(); |
| 572 | if (outRanking.getAdditionalPeople() != null) { |
| 573 | currentAdditionalPeople.addAll(outRanking.getAdditionalPeople()); |
Beverly | 5a20a5e | 2018-03-06 15:02:44 -0500 | [diff] [blame] | 574 | } |
Julia Reynolds | efcd8bd | 2019-02-06 08:56:15 -0500 | [diff] [blame] | 575 | |
| 576 | ArrayList<SnoozeCriterion> currentSnooze = new ArrayList<>(); |
| 577 | if (outRanking.getSnoozeCriteria() != null) { |
| 578 | currentSnooze.addAll(outRanking.getSnoozeCriteria()); |
| 579 | } |
| 580 | |
| 581 | ArrayList<Notification.Action> currentActions = new ArrayList<>(); |
| 582 | if (outRanking.getSmartActions() != null) { |
| 583 | currentActions.addAll(outRanking.getSmartActions()); |
| 584 | } |
| 585 | |
| 586 | ArrayList<CharSequence> currentReplies = new ArrayList<>(); |
| 587 | if (outRanking.getSmartReplies() != null) { |
| 588 | currentReplies.addAll(outRanking.getSmartReplies()); |
| 589 | } |
| 590 | |
Julia Reynolds | 2b88ecd | 2019-05-29 18:09:41 -0400 | [diff] [blame] | 591 | if (rankingOverrides.get(key) != null) { |
| 592 | Bundle overrides = rankingOverrides.get(key); |
| 593 | outRanking.populate(key, |
| 594 | overrides.getInt(OVERRIDE_RANK, outRanking.getRank()), |
| 595 | overrides.getBoolean(OVERRIDE_DND, outRanking.matchesInterruptionFilter()), |
| 596 | overrides.getInt(OVERRIDE_VIS_OVERRIDE, outRanking.getVisibilityOverride()), |
| 597 | overrides.getInt(OVERRIDE_VIS_EFFECTS, |
| 598 | outRanking.getSuppressedVisualEffects()), |
| 599 | overrides.getInt(OVERRIDE_IMPORTANCE, outRanking.getImportance()), |
| 600 | overrides.getCharSequence(OVERRIDE_IMP_EXP, |
| 601 | outRanking.getImportanceExplanation()), |
| 602 | overrides.getString(OVERRIDE_GROUP, outRanking.getOverrideGroupKey()), |
| 603 | overrides.containsKey(OVERRIDE_CHANNEL) |
| 604 | ? (NotificationChannel) overrides.getParcelable(OVERRIDE_CHANNEL) |
| 605 | : outRanking.getChannel(), |
| 606 | overrides.containsKey(OVERRIDE_PEOPLE) |
| 607 | ? overrides.getStringArrayList(OVERRIDE_PEOPLE) |
| 608 | : currentAdditionalPeople, |
| 609 | overrides.containsKey(OVERRIDE_SNOOZE_CRITERIA) |
| 610 | ? overrides.getParcelableArrayList(OVERRIDE_SNOOZE_CRITERIA) |
| 611 | : currentSnooze, |
| 612 | overrides.getBoolean(OVERRIDE_BADGE, outRanking.canShowBadge()), |
| 613 | overrides.getInt(OVERRIDE_USER_SENTIMENT, outRanking.getUserSentiment()), |
| 614 | overrides.getBoolean(OVERRIDE_HIDDEN, outRanking.isSuspended()), |
| 615 | overrides.getLong(OVERRIDE_LAST_ALERTED, |
| 616 | outRanking.getLastAudiblyAlertedMillis()), |
| 617 | overrides.getBoolean(OVERRIDE_NOISY, outRanking.isNoisy()), |
| 618 | overrides.containsKey(OVERRIDE_SMART_ACTIONS) |
| 619 | ? overrides.getParcelableArrayList(OVERRIDE_SMART_ACTIONS) |
| 620 | : currentActions, |
| 621 | overrides.containsKey(OVERRIDE_SMART_REPLIES) |
| 622 | ? overrides.getCharSequenceArrayList(OVERRIDE_SMART_REPLIES) |
| 623 | : currentReplies, |
| 624 | overrides.getBoolean(OVERRIDE_BUBBLE, outRanking.canBubble())); |
| 625 | } |
Kensuke Matsui | efa1a74 | 2017-08-03 12:12:36 +0900 | [diff] [blame] | 626 | return true; |
| 627 | } |
Selim Cinek | 608a57a | 2017-04-28 16:50:41 -0700 | [diff] [blame] | 628 | } |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 629 | |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 630 | private Notification.Action createContextualAction(String title) { |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 631 | return new Notification.Action.Builder( |
| 632 | Icon.createWithResource(getContext(), android.R.drawable.sym_def_app_icon), |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 633 | title, |
| 634 | PendingIntent.getBroadcast(getContext(), 0, new Intent("Action"), 0)) |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 635 | .setContextual(true) |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 636 | .build(); |
| 637 | } |
| 638 | |
| 639 | private Notification.Action createAction(String title) { |
| 640 | return new Notification.Action.Builder( |
| 641 | Icon.createWithResource(getContext(), android.R.drawable.sym_def_app_icon), |
| 642 | title, |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 643 | PendingIntent.getBroadcast(getContext(), 0, new Intent("Action"), 0)).build(); |
| 644 | } |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 645 | } |