Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package com.android.server.notification; |
| 17 | |
Gus Prevas | 2c963d2 | 2018-12-03 15:49:06 -0500 | [diff] [blame] | 18 | import static org.hamcrest.Matchers.contains; |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 19 | import static org.junit.Assert.assertFalse; |
Gus Prevas | 2c963d2 | 2018-12-03 15:49:06 -0500 | [diff] [blame] | 20 | import static org.junit.Assert.assertThat; |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 21 | import static org.junit.Assert.assertTrue; |
| 22 | import static org.mockito.Matchers.anyInt; |
| 23 | import static org.mockito.Matchers.anyString; |
| 24 | import static org.mockito.Matchers.eq; |
| 25 | import static org.mockito.Mockito.when; |
| 26 | |
| 27 | import android.app.Notification; |
| 28 | import android.app.NotificationChannel; |
| 29 | import android.app.NotificationManager; |
| 30 | import android.content.Context; |
| 31 | import android.content.pm.ApplicationInfo; |
| 32 | import android.content.pm.PackageManager; |
| 33 | import android.media.session.MediaSession; |
| 34 | import android.os.Build; |
| 35 | import android.os.UserHandle; |
| 36 | import android.provider.Settings; |
| 37 | import android.service.notification.StatusBarNotification; |
Gus Prevas | 2c963d2 | 2018-12-03 15:49:06 -0500 | [diff] [blame] | 38 | import android.telecom.TelecomManager; |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 39 | import android.test.suitebuilder.annotation.SmallTest; |
| 40 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 41 | import androidx.test.runner.AndroidJUnit4; |
| 42 | |
Jason Monk | 74f5e36 | 2017-12-06 08:56:33 -0500 | [diff] [blame] | 43 | import com.android.server.UiServiceTestCase; |
| 44 | |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 45 | import org.junit.Before; |
| 46 | import org.junit.Test; |
| 47 | import org.junit.runner.RunWith; |
| 48 | import org.mockito.Mock; |
| 49 | import org.mockito.MockitoAnnotations; |
| 50 | |
| 51 | import java.util.ArrayList; |
| 52 | import java.util.Collections; |
| 53 | import java.util.List; |
| 54 | |
| 55 | @SmallTest |
| 56 | @RunWith(AndroidJUnit4.class) |
Jason Monk | 74f5e36 | 2017-12-06 08:56:33 -0500 | [diff] [blame] | 57 | public class NotificationComparatorTest extends UiServiceTestCase { |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 58 | @Mock Context mContext; |
| 59 | @Mock TelecomManager mTm; |
| 60 | @Mock RankingHandler handler; |
| 61 | @Mock PackageManager mPm; |
| 62 | |
| 63 | private final String callPkg = "com.android.server.notification"; |
| 64 | private final int callUid = 10; |
| 65 | private String smsPkg; |
| 66 | private final int smsUid = 11; |
| 67 | private final String pkg2 = "pkg2"; |
| 68 | private final int uid2 = 1111111; |
Geoffrey Pitsch | af759c5 | 2017-02-15 09:35:38 -0500 | [diff] [blame] | 69 | private static final String TEST_CHANNEL_ID = "test_channel_id"; |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 70 | |
| 71 | private NotificationRecord mRecordMinCall; |
| 72 | private NotificationRecord mRecordHighCall; |
| 73 | private NotificationRecord mRecordDefaultMedia; |
| 74 | private NotificationRecord mRecordEmail; |
| 75 | private NotificationRecord mRecordInlineReply; |
| 76 | private NotificationRecord mRecordSms; |
| 77 | private NotificationRecord mRecordStarredContact; |
| 78 | private NotificationRecord mRecordContact; |
| 79 | private NotificationRecord mRecordUrgent; |
| 80 | private NotificationRecord mRecordCheater; |
Julia Reynolds | 889280c | 2017-04-12 12:27:00 -0400 | [diff] [blame] | 81 | private NotificationRecord mRecordCheaterColorized; |
Selim Cinek | c6c639cb | 2017-05-05 19:49:22 -0700 | [diff] [blame] | 82 | private NotificationRecord mNoMediaSessionMedia; |
Julia Reynolds | 472f01c | 2018-01-18 09:25:44 -0500 | [diff] [blame] | 83 | private NotificationRecord mRecordColorized; |
| 84 | private NotificationRecord mRecordColorizedCall; |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 85 | |
| 86 | @Before |
| 87 | public void setUp() { |
| 88 | MockitoAnnotations.initMocks(this); |
| 89 | int userId = UserHandle.myUserId(); |
| 90 | |
Chris Wren | 89aa226 | 2017-05-05 18:05:56 -0400 | [diff] [blame] | 91 | when(mContext.getResources()).thenReturn(getContext().getResources()); |
| 92 | when(mContext.getContentResolver()).thenReturn(getContext().getContentResolver()); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 93 | when(mContext.getPackageManager()).thenReturn(mPm); |
| 94 | when(mContext.getSystemService(eq(Context.TELECOM_SERVICE))).thenReturn(mTm); |
| 95 | when(mTm.getDefaultDialerPackage()).thenReturn(callPkg); |
| 96 | final ApplicationInfo legacy = new ApplicationInfo(); |
| 97 | legacy.targetSdkVersion = Build.VERSION_CODES.N_MR1; |
| 98 | try { |
| 99 | when(mPm.getApplicationInfoAsUser(anyString(), anyInt(), anyInt())).thenReturn(legacy); |
| 100 | when(mContext.getApplicationInfo()).thenReturn(legacy); |
| 101 | } catch (PackageManager.NameNotFoundException e) { |
| 102 | // let's hope not |
| 103 | } |
| 104 | |
| 105 | smsPkg = Settings.Secure.getString(mContext.getContentResolver(), |
| 106 | Settings.Secure.SMS_DEFAULT_APPLICATION); |
| 107 | |
Geoffrey Pitsch | af759c5 | 2017-02-15 09:35:38 -0500 | [diff] [blame] | 108 | Notification n1 = new Notification.Builder(mContext, TEST_CHANNEL_ID) |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 109 | .setCategory(Notification.CATEGORY_CALL) |
| 110 | .setFlag(Notification.FLAG_FOREGROUND_SERVICE, true) |
| 111 | .build(); |
| 112 | mRecordMinCall = new NotificationRecord(mContext, new StatusBarNotification(callPkg, |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 113 | callPkg, 1, "minCall", callUid, callUid, n1, |
| 114 | new UserHandle(userId), "", 2000), getDefaultChannel()); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 115 | mRecordMinCall.setSystemImportance(NotificationManager.IMPORTANCE_MIN); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 116 | |
Geoffrey Pitsch | af759c5 | 2017-02-15 09:35:38 -0500 | [diff] [blame] | 117 | Notification n2 = new Notification.Builder(mContext, TEST_CHANNEL_ID) |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 118 | .setCategory(Notification.CATEGORY_CALL) |
| 119 | .setFlag(Notification.FLAG_FOREGROUND_SERVICE, true) |
| 120 | .build(); |
| 121 | mRecordHighCall = new NotificationRecord(mContext, new StatusBarNotification(callPkg, |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 122 | callPkg, 1, "highcall", callUid, callUid, n2, |
| 123 | new UserHandle(userId), "", 1999), getDefaultChannel()); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 124 | mRecordHighCall.setSystemImportance(NotificationManager.IMPORTANCE_HIGH); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 125 | |
Geoffrey Pitsch | af759c5 | 2017-02-15 09:35:38 -0500 | [diff] [blame] | 126 | Notification n3 = new Notification.Builder(mContext, TEST_CHANNEL_ID) |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 127 | .setStyle(new Notification.MediaStyle() |
| 128 | .setMediaSession(new MediaSession.Token(null))) |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 129 | .build(); |
| 130 | mRecordDefaultMedia = new NotificationRecord(mContext, new StatusBarNotification(pkg2, |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 131 | pkg2, 1, "media", uid2, uid2, n3, new UserHandle(userId), |
| 132 | "", 1499), getDefaultChannel()); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 133 | mRecordDefaultMedia.setSystemImportance(NotificationManager.IMPORTANCE_DEFAULT); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 134 | |
Geoffrey Pitsch | af759c5 | 2017-02-15 09:35:38 -0500 | [diff] [blame] | 135 | Notification n4 = new Notification.Builder(mContext, TEST_CHANNEL_ID) |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 136 | .setStyle(new Notification.MessagingStyle("sender!")).build(); |
| 137 | mRecordInlineReply = new NotificationRecord(mContext, new StatusBarNotification(pkg2, |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 138 | pkg2, 1, "inlinereply", uid2, uid2, n4, new UserHandle(userId), |
| 139 | "", 1599), getDefaultChannel()); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 140 | mRecordInlineReply.setSystemImportance(NotificationManager.IMPORTANCE_HIGH); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 141 | mRecordInlineReply.setPackagePriority(Notification.PRIORITY_MAX); |
| 142 | |
Kristian Monsen | 05f3479 | 2018-04-09 10:27:16 +0200 | [diff] [blame] | 143 | if (smsPkg != null) { |
| 144 | Notification n5 = new Notification.Builder(mContext, TEST_CHANNEL_ID) |
| 145 | .setCategory(Notification.CATEGORY_MESSAGE).build(); |
| 146 | mRecordSms = new NotificationRecord(mContext, new StatusBarNotification(smsPkg, |
| 147 | smsPkg, 1, "sms", smsUid, smsUid, n5, new UserHandle(userId), |
| 148 | "", 1299), getDefaultChannel()); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 149 | mRecordSms.setSystemImportance(NotificationManager.IMPORTANCE_DEFAULT); |
Kristian Monsen | 05f3479 | 2018-04-09 10:27:16 +0200 | [diff] [blame] | 150 | } |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 151 | |
Geoffrey Pitsch | af759c5 | 2017-02-15 09:35:38 -0500 | [diff] [blame] | 152 | Notification n6 = new Notification.Builder(mContext, TEST_CHANNEL_ID).build(); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 153 | mRecordStarredContact = new NotificationRecord(mContext, new StatusBarNotification(pkg2, |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 154 | pkg2, 1, "starred", uid2, uid2, n6, new UserHandle(userId), |
| 155 | "", 1259), getDefaultChannel()); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 156 | mRecordStarredContact.setContactAffinity(ValidateNotificationPeople.STARRED_CONTACT); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 157 | mRecordStarredContact.setSystemImportance(NotificationManager.IMPORTANCE_DEFAULT); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 158 | |
Geoffrey Pitsch | af759c5 | 2017-02-15 09:35:38 -0500 | [diff] [blame] | 159 | Notification n7 = new Notification.Builder(mContext, TEST_CHANNEL_ID).build(); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 160 | mRecordContact = new NotificationRecord(mContext, new StatusBarNotification(pkg2, |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 161 | pkg2, 1, "contact", uid2, uid2, n7, new UserHandle(userId), |
| 162 | "", 1259), getDefaultChannel()); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 163 | mRecordContact.setContactAffinity(ValidateNotificationPeople.VALID_CONTACT); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 164 | mRecordContact.setSystemImportance(NotificationManager.IMPORTANCE_DEFAULT); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 165 | |
Geoffrey Pitsch | af759c5 | 2017-02-15 09:35:38 -0500 | [diff] [blame] | 166 | Notification n8 = new Notification.Builder(mContext, TEST_CHANNEL_ID).build(); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 167 | mRecordUrgent = new NotificationRecord(mContext, new StatusBarNotification(pkg2, |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 168 | pkg2, 1, "urgent", uid2, uid2, n8, new UserHandle(userId), |
| 169 | "", 1258), getDefaultChannel()); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 170 | mRecordUrgent.setSystemImportance(NotificationManager.IMPORTANCE_HIGH); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 171 | |
Geoffrey Pitsch | af759c5 | 2017-02-15 09:35:38 -0500 | [diff] [blame] | 172 | Notification n9 = new Notification.Builder(mContext, TEST_CHANNEL_ID) |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 173 | .setCategory(Notification.CATEGORY_MESSAGE) |
| 174 | .setFlag(Notification.FLAG_ONGOING_EVENT |
| 175 | |Notification.FLAG_FOREGROUND_SERVICE, true) |
| 176 | .build(); |
| 177 | mRecordCheater = new NotificationRecord(mContext, new StatusBarNotification(pkg2, |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 178 | pkg2, 1, "cheater", uid2, uid2, n9, new UserHandle(userId), |
| 179 | "", 9258), getDefaultChannel()); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 180 | mRecordCheater.setSystemImportance(NotificationManager.IMPORTANCE_LOW); |
Julia Reynolds | 889280c | 2017-04-12 12:27:00 -0400 | [diff] [blame] | 181 | mRecordCheater.setPackagePriority(Notification.PRIORITY_MAX); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 182 | |
Geoffrey Pitsch | af759c5 | 2017-02-15 09:35:38 -0500 | [diff] [blame] | 183 | Notification n10 = new Notification.Builder(mContext, TEST_CHANNEL_ID) |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 184 | .setStyle(new Notification.InboxStyle().setSummaryText("message!")).build(); |
| 185 | mRecordEmail = new NotificationRecord(mContext, new StatusBarNotification(pkg2, |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 186 | pkg2, 1, "email", uid2, uid2, n10, new UserHandle(userId), |
| 187 | "", 1599), getDefaultChannel()); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 188 | mRecordEmail.setSystemImportance(NotificationManager.IMPORTANCE_HIGH); |
Julia Reynolds | 889280c | 2017-04-12 12:27:00 -0400 | [diff] [blame] | 189 | |
| 190 | Notification n11 = new Notification.Builder(mContext, TEST_CHANNEL_ID) |
| 191 | .setCategory(Notification.CATEGORY_MESSAGE) |
| 192 | .setColorized(true) |
| 193 | .build(); |
| 194 | mRecordCheaterColorized = new NotificationRecord(mContext, new StatusBarNotification(pkg2, |
| 195 | pkg2, 1, "cheater", uid2, uid2, n11, new UserHandle(userId), |
| 196 | "", 9258), getDefaultChannel()); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 197 | mRecordCheaterColorized.setSystemImportance(NotificationManager.IMPORTANCE_LOW); |
Selim Cinek | c6c639cb | 2017-05-05 19:49:22 -0700 | [diff] [blame] | 198 | |
| 199 | Notification n12 = new Notification.Builder(mContext, TEST_CHANNEL_ID) |
| 200 | .setCategory(Notification.CATEGORY_MESSAGE) |
| 201 | .setColorized(true) |
| 202 | .setStyle(new Notification.MediaStyle()) |
| 203 | .build(); |
| 204 | mNoMediaSessionMedia = new NotificationRecord(mContext, new StatusBarNotification( |
| 205 | pkg2, pkg2, 1, "cheater", uid2, uid2, n12, new UserHandle(userId), |
| 206 | "", 9258), getDefaultChannel()); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 207 | mNoMediaSessionMedia.setSystemImportance(NotificationManager.IMPORTANCE_DEFAULT); |
Julia Reynolds | 472f01c | 2018-01-18 09:25:44 -0500 | [diff] [blame] | 208 | |
| 209 | Notification n13 = new Notification.Builder(mContext, TEST_CHANNEL_ID) |
| 210 | .setFlag(Notification.FLAG_FOREGROUND_SERVICE, true) |
| 211 | .setColorized(true /* colorized */) |
| 212 | .build(); |
| 213 | mRecordColorized = new NotificationRecord(mContext, new StatusBarNotification(pkg2, |
| 214 | pkg2, 1, "colorized", uid2, uid2, n13, |
| 215 | new UserHandle(userId), "", 1999), getDefaultChannel()); |
Gus Prevas | 2c963d2 | 2018-12-03 15:49:06 -0500 | [diff] [blame] | 216 | mRecordColorized.setSystemImportance(NotificationManager.IMPORTANCE_HIGH); |
Julia Reynolds | 472f01c | 2018-01-18 09:25:44 -0500 | [diff] [blame] | 217 | |
| 218 | Notification n14 = new Notification.Builder(mContext, TEST_CHANNEL_ID) |
| 219 | .setCategory(Notification.CATEGORY_CALL) |
| 220 | .setColorized(true) |
| 221 | .setFlag(Notification.FLAG_FOREGROUND_SERVICE, true) |
| 222 | .build(); |
| 223 | mRecordColorizedCall = new NotificationRecord(mContext, new StatusBarNotification(callPkg, |
| 224 | callPkg, 1, "colorizedCall", callUid, callUid, n14, |
| 225 | new UserHandle(userId), "", 1999), getDefaultChannel()); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 226 | mRecordColorizedCall.setSystemImportance(NotificationManager.IMPORTANCE_HIGH); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | @Test |
Gus Prevas | 2c963d2 | 2018-12-03 15:49:06 -0500 | [diff] [blame] | 230 | public void testOrdering() { |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 231 | final List<NotificationRecord> expected = new ArrayList<>(); |
Julia Reynolds | 472f01c | 2018-01-18 09:25:44 -0500 | [diff] [blame] | 232 | expected.add(mRecordColorizedCall); |
Julia Reynolds | 472f01c | 2018-01-18 09:25:44 -0500 | [diff] [blame] | 233 | expected.add(mRecordColorized); |
Gus Prevas | 2c963d2 | 2018-12-03 15:49:06 -0500 | [diff] [blame] | 234 | expected.add(mRecordDefaultMedia); |
Julia Reynolds | 472f01c | 2018-01-18 09:25:44 -0500 | [diff] [blame] | 235 | expected.add(mRecordHighCall); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 236 | expected.add(mRecordInlineReply); |
Kristian Monsen | 05f3479 | 2018-04-09 10:27:16 +0200 | [diff] [blame] | 237 | if (mRecordSms != null) { |
| 238 | expected.add(mRecordSms); |
| 239 | } |
Selim Cinek | 3f146d0 | 2017-02-06 13:32:47 -0800 | [diff] [blame] | 240 | expected.add(mRecordStarredContact); |
| 241 | expected.add(mRecordContact); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 242 | expected.add(mRecordEmail); |
| 243 | expected.add(mRecordUrgent); |
Selim Cinek | c6c639cb | 2017-05-05 19:49:22 -0700 | [diff] [blame] | 244 | expected.add(mNoMediaSessionMedia); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 245 | expected.add(mRecordCheater); |
Julia Reynolds | 889280c | 2017-04-12 12:27:00 -0400 | [diff] [blame] | 246 | expected.add(mRecordCheaterColorized); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 247 | expected.add(mRecordMinCall); |
| 248 | |
| 249 | List<NotificationRecord> actual = new ArrayList<>(); |
| 250 | actual.addAll(expected); |
| 251 | Collections.shuffle(actual); |
| 252 | |
| 253 | Collections.sort(actual, new NotificationComparator(mContext)); |
| 254 | |
Gus Prevas | 2c963d2 | 2018-12-03 15:49:06 -0500 | [diff] [blame] | 255 | assertThat(actual, contains(expected.toArray())); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | @Test |
Gus Prevas | 2c963d2 | 2018-12-03 15:49:06 -0500 | [diff] [blame] | 259 | public void testMessaging() { |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 260 | NotificationComparator comp = new NotificationComparator(mContext); |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 261 | assertTrue(comp.isImportantMessaging(mRecordInlineReply)); |
Kristian Monsen | 05f3479 | 2018-04-09 10:27:16 +0200 | [diff] [blame] | 262 | if (mRecordSms != null) { |
| 263 | assertTrue(comp.isImportantMessaging(mRecordSms)); |
| 264 | } |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 265 | assertFalse(comp.isImportantMessaging(mRecordEmail)); |
| 266 | assertFalse(comp.isImportantMessaging(mRecordCheater)); |
| 267 | } |
| 268 | |
Selim Cinek | 3f146d0 | 2017-02-06 13:32:47 -0800 | [diff] [blame] | 269 | @Test |
Gus Prevas | 2c963d2 | 2018-12-03 15:49:06 -0500 | [diff] [blame] | 270 | public void testPeople() { |
Selim Cinek | 3f146d0 | 2017-02-06 13:32:47 -0800 | [diff] [blame] | 271 | NotificationComparator comp = new NotificationComparator(mContext); |
| 272 | assertTrue(comp.isImportantPeople(mRecordStarredContact)); |
| 273 | assertTrue(comp.isImportantPeople(mRecordContact)); |
| 274 | } |
| 275 | |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 276 | private NotificationChannel getDefaultChannel() { |
| 277 | return new NotificationChannel(NotificationChannel.DEFAULT_CHANNEL_ID, "name", |
| 278 | NotificationManager.IMPORTANCE_LOW); |
| 279 | } |
| 280 | } |