Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [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 |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui; |
| 18 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 19 | import static junit.framework.Assert.assertEquals; |
| 20 | import static junit.framework.Assert.assertNull; |
| 21 | |
| 22 | import static org.junit.Assert.assertFalse; |
| 23 | import static org.junit.Assert.assertTrue; |
Beverly | 201cdd5 | 2019-10-18 14:30:46 -0400 | [diff] [blame] | 24 | import static org.mockito.ArgumentMatchers.anyString; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 25 | import static org.mockito.Mockito.mock; |
Beverly | 201cdd5 | 2019-10-18 14:30:46 -0400 | [diff] [blame] | 26 | import static org.mockito.Mockito.never; |
| 27 | import static org.mockito.Mockito.times; |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 28 | import static org.mockito.Mockito.verify; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 29 | import static org.mockito.Mockito.when; |
| 30 | |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 31 | import android.annotation.UserIdInt; |
Beverly | 201cdd5 | 2019-10-18 14:30:46 -0400 | [diff] [blame] | 32 | import android.app.AppOpsManager; |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 33 | import android.app.Notification; |
| 34 | import android.app.NotificationManager; |
| 35 | import android.os.Bundle; |
| 36 | import android.os.UserHandle; |
| 37 | import android.service.notification.StatusBarNotification; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 38 | import android.widget.RemoteViews; |
| 39 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 40 | import androidx.test.filters.SmallTest; |
| 41 | import androidx.test.runner.AndroidJUnit4; |
| 42 | |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 43 | import com.android.internal.messages.nano.SystemMessageProto; |
Ned Burns | 60e9459 | 2019-09-06 14:47:25 -0400 | [diff] [blame] | 44 | import com.android.systemui.statusbar.NotificationEntryBuilder; |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 45 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
| 46 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 47 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 48 | |
Beverly | 201cdd5 | 2019-10-18 14:30:46 -0400 | [diff] [blame] | 49 | import junit.framework.Assert; |
| 50 | |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 51 | import org.junit.Before; |
| 52 | import org.junit.Test; |
| 53 | import org.junit.runner.RunWith; |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 54 | import org.mockito.ArgumentCaptor; |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 55 | |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 56 | @SmallTest |
| 57 | @RunWith(AndroidJUnit4.class) |
| 58 | public class ForegroundServiceControllerTest extends SysuiTestCase { |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 59 | private ForegroundServiceController mFsc; |
| 60 | private ForegroundServiceNotificationListener mListener; |
| 61 | private NotificationEntryListener mEntryListener; |
Beverly | 201cdd5 | 2019-10-18 14:30:46 -0400 | [diff] [blame] | 62 | private NotificationEntryManager mEntryManager; |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 63 | |
| 64 | @Before |
| 65 | public void setUp() throws Exception { |
Beverly | 201cdd5 | 2019-10-18 14:30:46 -0400 | [diff] [blame] | 66 | mEntryManager = mock(NotificationEntryManager.class); |
| 67 | mFsc = new ForegroundServiceController(mEntryManager); |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 68 | mListener = new ForegroundServiceNotificationListener( |
Beverly | 201cdd5 | 2019-10-18 14:30:46 -0400 | [diff] [blame] | 69 | mContext, mFsc, mEntryManager); |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 70 | ArgumentCaptor<NotificationEntryListener> entryListenerCaptor = |
| 71 | ArgumentCaptor.forClass(NotificationEntryListener.class); |
Beverly | 201cdd5 | 2019-10-18 14:30:46 -0400 | [diff] [blame] | 72 | verify(mEntryManager).addNotificationEntryListener( |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 73 | entryListenerCaptor.capture()); |
| 74 | mEntryListener = entryListenerCaptor.getValue(); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Test |
Beverly | 201cdd5 | 2019-10-18 14:30:46 -0400 | [diff] [blame] | 78 | public void testAppOps_appOpChangedBeforeNotificationExists() { |
| 79 | // GIVEN app op exists, but notification doesn't exist in NEM yet |
| 80 | NotificationEntry entry = createFgEntry(); |
| 81 | mFsc.onAppOpChanged( |
| 82 | AppOpsManager.OP_CAMERA, |
| 83 | entry.getSbn().getUid(), |
| 84 | entry.getSbn().getPackageName(), |
| 85 | true); |
| 86 | assertFalse(entry.mActiveAppOps.contains(AppOpsManager.OP_CAMERA)); |
| 87 | |
| 88 | // WHEN the notification is added |
| 89 | mEntryListener.onPendingEntryAdded(entry); |
| 90 | |
| 91 | // THEN the app op is added to the entry |
| 92 | Assert.assertTrue(entry.mActiveAppOps.contains(AppOpsManager.OP_CAMERA)); |
| 93 | } |
| 94 | |
| 95 | @Test |
| 96 | public void testAppOps_appOpAddedToForegroundNotif() { |
| 97 | // GIVEN a notification associated with a foreground service |
| 98 | NotificationEntry entry = addFgEntry(); |
| 99 | when(mEntryManager.getPendingOrCurrentNotif(entry.getKey())).thenReturn(entry); |
| 100 | |
| 101 | // WHEN we are notified of a new app op for this notification |
| 102 | mFsc.onAppOpChanged( |
| 103 | AppOpsManager.OP_CAMERA, |
| 104 | entry.getSbn().getUid(), |
| 105 | entry.getSbn().getPackageName(), |
| 106 | true); |
| 107 | |
| 108 | // THEN the app op is added to the entry |
| 109 | Assert.assertTrue(entry.mActiveAppOps.contains(AppOpsManager.OP_CAMERA)); |
| 110 | |
| 111 | // THEN notification views are updated since the notification is visible |
| 112 | verify(mEntryManager, times(1)).updateNotifications(anyString()); |
| 113 | } |
| 114 | |
| 115 | @Test |
| 116 | public void testAppOpsAlreadyAdded() { |
| 117 | // GIVEN a foreground service associated notification that already has the correct app op |
| 118 | NotificationEntry entry = addFgEntry(); |
| 119 | entry.mActiveAppOps.add(AppOpsManager.OP_CAMERA); |
| 120 | when(mEntryManager.getPendingOrCurrentNotif(entry.getKey())).thenReturn(entry); |
| 121 | |
| 122 | // WHEN we are notified of the same app op for this notification |
| 123 | mFsc.onAppOpChanged( |
| 124 | AppOpsManager.OP_CAMERA, |
| 125 | entry.getSbn().getUid(), |
| 126 | entry.getSbn().getPackageName(), |
| 127 | true); |
| 128 | |
| 129 | // THEN the app op still exists in the notification entry |
| 130 | Assert.assertTrue(entry.mActiveAppOps.contains(AppOpsManager.OP_CAMERA)); |
| 131 | |
| 132 | // THEN notification views aren't updated since nothing changed |
| 133 | verify(mEntryManager, never()).updateNotifications(anyString()); |
| 134 | } |
| 135 | |
| 136 | @Test |
| 137 | public void testAppOps_appOpNotAddedToUnrelatedNotif() { |
| 138 | // GIVEN no notification entries correspond to the newly updated appOp |
| 139 | NotificationEntry entry = addFgEntry(); |
| 140 | when(mEntryManager.getPendingOrCurrentNotif(entry.getKey())).thenReturn(null); |
| 141 | |
| 142 | // WHEN a new app op is detected |
| 143 | mFsc.onAppOpChanged( |
| 144 | AppOpsManager.OP_CAMERA, |
| 145 | entry.getSbn().getUid(), |
| 146 | entry.getSbn().getPackageName(), |
| 147 | true); |
| 148 | |
| 149 | // THEN we won't see appOps on the entry |
| 150 | Assert.assertFalse(entry.mActiveAppOps.contains(AppOpsManager.OP_CAMERA)); |
| 151 | |
| 152 | // THEN notification views aren't updated since nothing changed |
| 153 | verify(mEntryManager, never()).updateNotifications(anyString()); |
| 154 | } |
| 155 | |
| 156 | @Test |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 157 | public void testAppOpsCRUD() { |
| 158 | // no crash on remove that doesn't exist |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 159 | mFsc.onAppOpChanged(9, 1000, "pkg1", false); |
| 160 | assertNull(mFsc.getAppOps(0, "pkg1")); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 161 | |
| 162 | // multiuser & multipackage |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 163 | mFsc.onAppOpChanged(8, 50, "pkg1", true); |
| 164 | mFsc.onAppOpChanged(1, 60, "pkg3", true); |
| 165 | mFsc.onAppOpChanged(7, 500000, "pkg2", true); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 166 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 167 | assertEquals(1, mFsc.getAppOps(0, "pkg1").size()); |
| 168 | assertTrue(mFsc.getAppOps(0, "pkg1").contains(8)); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 169 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 170 | assertEquals(1, mFsc.getAppOps(UserHandle.getUserId(500000), "pkg2").size()); |
| 171 | assertTrue(mFsc.getAppOps(UserHandle.getUserId(500000), "pkg2").contains(7)); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 172 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 173 | assertEquals(1, mFsc.getAppOps(0, "pkg3").size()); |
| 174 | assertTrue(mFsc.getAppOps(0, "pkg3").contains(1)); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 175 | |
| 176 | // multiple ops for the same package |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 177 | mFsc.onAppOpChanged(9, 50, "pkg1", true); |
| 178 | mFsc.onAppOpChanged(5, 50, "pkg1", true); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 179 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 180 | assertEquals(3, mFsc.getAppOps(0, "pkg1").size()); |
| 181 | assertTrue(mFsc.getAppOps(0, "pkg1").contains(8)); |
| 182 | assertTrue(mFsc.getAppOps(0, "pkg1").contains(9)); |
| 183 | assertTrue(mFsc.getAppOps(0, "pkg1").contains(5)); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 184 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 185 | assertEquals(1, mFsc.getAppOps(UserHandle.getUserId(500000), "pkg2").size()); |
| 186 | assertTrue(mFsc.getAppOps(UserHandle.getUserId(500000), "pkg2").contains(7)); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 187 | |
| 188 | // remove one of the multiples |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 189 | mFsc.onAppOpChanged(9, 50, "pkg1", false); |
| 190 | assertEquals(2, mFsc.getAppOps(0, "pkg1").size()); |
| 191 | assertTrue(mFsc.getAppOps(0, "pkg1").contains(8)); |
| 192 | assertTrue(mFsc.getAppOps(0, "pkg1").contains(5)); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 193 | |
| 194 | // remove last op |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 195 | mFsc.onAppOpChanged(1, 60, "pkg3", false); |
| 196 | assertNull(mFsc.getAppOps(0, "pkg3")); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | @Test |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 200 | public void testDisclosurePredicate() { |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 201 | StatusBarNotification sbn_user1_app1 = makeMockSBN(USERID_ONE, "com.example.app1", |
| 202 | 5000, "monkeys", Notification.FLAG_AUTO_CANCEL); |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 203 | StatusBarNotification sbn_user1_disclosure = makeMockSBN(USERID_ONE, "android", |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 204 | SystemMessageProto.SystemMessage.NOTE_FOREGROUND_SERVICES, |
| 205 | null, Notification.FLAG_NO_CLEAR); |
| 206 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 207 | assertTrue(mFsc.isDisclosureNotification(sbn_user1_disclosure)); |
| 208 | assertFalse(mFsc.isDisclosureNotification(sbn_user1_app1)); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | @Test |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 212 | public void testNeedsDisclosureAfterRemovingUnrelatedNotification() { |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 213 | final String PKG1 = "com.example.app100"; |
| 214 | |
| 215 | StatusBarNotification sbn_user1_app1 = makeMockSBN(USERID_ONE, PKG1, |
| 216 | 5000, "monkeys", Notification.FLAG_AUTO_CANCEL); |
| 217 | StatusBarNotification sbn_user1_app1_fg = makeMockFgSBN(USERID_ONE, PKG1); |
| 218 | |
| 219 | // first add a normal notification |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 220 | entryAdded(sbn_user1_app1, NotificationManager.IMPORTANCE_DEFAULT); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 221 | // nothing required yet |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 222 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE)); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 223 | // now the app starts a fg service |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 224 | entryAdded(makeMockDisclosure(USERID_ONE, new String[]{PKG1}), |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 225 | NotificationManager.IMPORTANCE_DEFAULT); |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 226 | assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE)); // should be required! |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 227 | // add the fg notification |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 228 | entryAdded(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_DEFAULT); |
| 229 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE)); // app1 has got it covered |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 230 | // remove the boring notification |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 231 | entryRemoved(sbn_user1_app1); |
| 232 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE)); // app1 has STILL got it covered |
| 233 | entryRemoved(sbn_user1_app1_fg); |
| 234 | assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE)); // should be required! |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | @Test |
| 238 | public void testSimpleAddRemove() { |
| 239 | final String PKG1 = "com.example.app1"; |
| 240 | final String PKG2 = "com.example.app2"; |
| 241 | |
| 242 | StatusBarNotification sbn_user1_app1 = makeMockSBN(USERID_ONE, PKG1, |
| 243 | 5000, "monkeys", Notification.FLAG_AUTO_CANCEL); |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 244 | entryAdded(sbn_user1_app1, NotificationManager.IMPORTANCE_DEFAULT); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 245 | |
| 246 | // no services are "running" |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 247 | entryAdded(makeMockDisclosure(USERID_ONE, null), |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 248 | NotificationManager.IMPORTANCE_DEFAULT); |
| 249 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 250 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE)); |
| 251 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO)); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 252 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 253 | entryUpdated(makeMockDisclosure(USERID_ONE, new String[]{PKG1}), |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 254 | NotificationManager.IMPORTANCE_DEFAULT); |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 255 | assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE)); // should be required! |
| 256 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO)); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 257 | |
| 258 | // switch to different package |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 259 | entryUpdated(makeMockDisclosure(USERID_ONE, new String[]{PKG2}), |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 260 | NotificationManager.IMPORTANCE_DEFAULT); |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 261 | assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE)); |
| 262 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO)); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 263 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 264 | entryUpdated(makeMockDisclosure(USERID_TWO, new String[]{PKG1}), |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 265 | NotificationManager.IMPORTANCE_DEFAULT); |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 266 | assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE)); |
| 267 | assertTrue(mFsc.isDisclosureNeededForUser(USERID_TWO)); // finally user2 needs one too |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 268 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 269 | entryUpdated(makeMockDisclosure(USERID_ONE, new String[]{PKG2, PKG1}), |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 270 | NotificationManager.IMPORTANCE_DEFAULT); |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 271 | assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE)); |
| 272 | assertTrue(mFsc.isDisclosureNeededForUser(USERID_TWO)); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 273 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 274 | entryRemoved(makeMockDisclosure(USERID_ONE, null /*unused*/)); |
| 275 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE)); |
| 276 | assertTrue(mFsc.isDisclosureNeededForUser(USERID_TWO)); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 277 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 278 | entryRemoved(makeMockDisclosure(USERID_TWO, null /*unused*/)); |
| 279 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE)); |
| 280 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO)); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | @Test |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 284 | public void testDisclosureBasic() { |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 285 | final String PKG1 = "com.example.app0"; |
| 286 | |
| 287 | StatusBarNotification sbn_user1_app1 = makeMockSBN(USERID_ONE, PKG1, |
| 288 | 5000, "monkeys", Notification.FLAG_AUTO_CANCEL); |
| 289 | StatusBarNotification sbn_user1_app1_fg = makeMockFgSBN(USERID_ONE, PKG1); |
| 290 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 291 | entryAdded(sbn_user1_app1, NotificationManager.IMPORTANCE_DEFAULT); // not fg |
| 292 | entryAdded(makeMockDisclosure(USERID_ONE, new String[]{PKG1}), |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 293 | NotificationManager.IMPORTANCE_DEFAULT); |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 294 | assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE)); // should be required! |
| 295 | entryAdded(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_DEFAULT); |
| 296 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE)); // app1 has got it covered |
| 297 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO)); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 298 | |
| 299 | // let's take out the other notification and see what happens. |
| 300 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 301 | entryRemoved(sbn_user1_app1); |
| 302 | assertFalse( |
| 303 | mFsc.isDisclosureNeededForUser(USERID_ONE)); // still covered by sbn_user1_app1_fg |
| 304 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO)); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 305 | |
| 306 | // let's attempt to downgrade the notification from FLAG_FOREGROUND and see what we get |
| 307 | StatusBarNotification sbn_user1_app1_fg_sneaky = makeMockFgSBN(USERID_ONE, PKG1); |
| 308 | sbn_user1_app1_fg_sneaky.getNotification().flags = 0; |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 309 | entryUpdated(sbn_user1_app1_fg_sneaky, |
| 310 | NotificationManager.IMPORTANCE_DEFAULT); |
| 311 | assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE)); // should be required! |
| 312 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO)); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 313 | |
| 314 | // ok, ok, we'll put it back |
| 315 | sbn_user1_app1_fg_sneaky.getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE; |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 316 | entryUpdated(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_DEFAULT); |
| 317 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE)); |
| 318 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO)); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 319 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 320 | entryRemoved(sbn_user1_app1_fg_sneaky); |
| 321 | assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE)); // should be required! |
| 322 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO)); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 323 | |
| 324 | // now let's test an upgrade |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 325 | entryAdded(sbn_user1_app1, NotificationManager.IMPORTANCE_DEFAULT); |
| 326 | assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE)); |
| 327 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO)); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 328 | sbn_user1_app1.getNotification().flags |= Notification.FLAG_FOREGROUND_SERVICE; |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 329 | entryUpdated(sbn_user1_app1, |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 330 | NotificationManager.IMPORTANCE_DEFAULT); // this is now a fg notification |
| 331 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 332 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO)); |
| 333 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE)); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 334 | |
| 335 | // remove it, make sure we're out of compliance again |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 336 | entryRemoved(sbn_user1_app1); // was fg, should return true |
| 337 | entryRemoved(sbn_user1_app1); |
| 338 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO)); |
| 339 | assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE)); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 340 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 341 | // importance upgrade |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 342 | entryAdded(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_MIN); |
| 343 | assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE)); |
| 344 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO)); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 345 | sbn_user1_app1.getNotification().flags |= Notification.FLAG_FOREGROUND_SERVICE; |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 346 | entryUpdated(sbn_user1_app1_fg, |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 347 | NotificationManager.IMPORTANCE_DEFAULT); // this is now a fg notification |
| 348 | |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 349 | // finally, let's turn off the service |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 350 | entryAdded(makeMockDisclosure(USERID_ONE, null), |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 351 | NotificationManager.IMPORTANCE_DEFAULT); |
| 352 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 353 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE)); |
| 354 | assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO)); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 355 | } |
| 356 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 357 | @Test |
Julia Reynolds | af78a79 | 2018-03-06 14:27:00 -0500 | [diff] [blame] | 358 | public void testOverlayPredicate() { |
| 359 | StatusBarNotification sbn_user1_app1 = makeMockSBN(USERID_ONE, "com.example.app1", |
| 360 | 5000, "monkeys", Notification.FLAG_AUTO_CANCEL); |
| 361 | StatusBarNotification sbn_user1_overlay = makeMockSBN(USERID_ONE, "android", |
| 362 | 0, "AlertWindowNotification", Notification.FLAG_NO_CLEAR); |
| 363 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 364 | assertTrue(mFsc.isSystemAlertNotification(sbn_user1_overlay)); |
| 365 | assertFalse(mFsc.isSystemAlertNotification(sbn_user1_app1)); |
Julia Reynolds | af78a79 | 2018-03-06 14:27:00 -0500 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | @Test |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 369 | public void testStdLayoutBasic() { |
| 370 | final String PKG1 = "com.example.app0"; |
| 371 | |
| 372 | StatusBarNotification sbn_user1_app1 = makeMockFgSBN(USERID_ONE, PKG1, 0, true); |
| 373 | sbn_user1_app1.getNotification().flags = 0; |
| 374 | StatusBarNotification sbn_user1_app1_fg = makeMockFgSBN(USERID_ONE, PKG1, 1, true); |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 375 | entryAdded(sbn_user1_app1, NotificationManager.IMPORTANCE_MIN); // not fg |
| 376 | assertTrue(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); // should be required! |
| 377 | entryAdded(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_MIN); |
| 378 | assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); // app1 has got it covered |
| 379 | assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_TWO, "otherpkg")); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 380 | // let's take out the non-fg notification and see what happens. |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 381 | entryRemoved(sbn_user1_app1); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 382 | // still covered by sbn_user1_app1_fg |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 383 | assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); |
| 384 | assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_TWO, "anyPkg")); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 385 | |
| 386 | // let's attempt to downgrade the notification from FLAG_FOREGROUND and see what we get |
| 387 | StatusBarNotification sbn_user1_app1_fg_sneaky = makeMockFgSBN(USERID_ONE, PKG1, 1, true); |
| 388 | sbn_user1_app1_fg_sneaky.getNotification().flags = 0; |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 389 | entryUpdated(sbn_user1_app1_fg_sneaky, NotificationManager.IMPORTANCE_MIN); |
| 390 | assertTrue(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); // should be required! |
| 391 | assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_TWO, "anything")); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 392 | // ok, ok, we'll put it back |
| 393 | sbn_user1_app1_fg_sneaky.getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE; |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 394 | entryUpdated(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_MIN); |
| 395 | assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); |
| 396 | assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_TWO, "whatever")); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 397 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 398 | entryRemoved(sbn_user1_app1_fg_sneaky); |
| 399 | assertTrue(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); // should be required! |
| 400 | assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_TWO, "a")); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 401 | |
| 402 | // let's try a custom layout |
| 403 | sbn_user1_app1_fg_sneaky = makeMockFgSBN(USERID_ONE, PKG1, 1, false); |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 404 | entryUpdated(sbn_user1_app1_fg_sneaky, NotificationManager.IMPORTANCE_MIN); |
| 405 | assertTrue(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); // should be required! |
| 406 | assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_TWO, "anything")); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 407 | // now let's test an upgrade (non fg to fg) |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 408 | entryAdded(sbn_user1_app1, NotificationManager.IMPORTANCE_MIN); |
| 409 | assertTrue(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); |
| 410 | assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_TWO, "b")); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 411 | sbn_user1_app1.getNotification().flags |= Notification.FLAG_FOREGROUND_SERVICE; |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 412 | entryUpdated(sbn_user1_app1, |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 413 | NotificationManager.IMPORTANCE_MIN); // this is now a fg notification |
| 414 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 415 | assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_TWO, PKG1)); |
| 416 | assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 417 | |
| 418 | // remove it, make sure we're out of compliance again |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 419 | entryRemoved(sbn_user1_app1); // was fg, should return true |
| 420 | entryRemoved(sbn_user1_app1); |
| 421 | assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_TWO, PKG1)); |
| 422 | assertTrue(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 423 | } |
| 424 | |
Beverly | 201cdd5 | 2019-10-18 14:30:46 -0400 | [diff] [blame] | 425 | private StatusBarNotification makeMockSBN(int userId, String pkg, int id, String tag, |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 426 | int flags) { |
| 427 | final Notification n = mock(Notification.class); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 428 | n.extras = new Bundle(); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 429 | n.flags = flags; |
Beverly | 201cdd5 | 2019-10-18 14:30:46 -0400 | [diff] [blame] | 430 | return makeMockSBN(userId, pkg, id, tag, n); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 431 | } |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 432 | |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 433 | private StatusBarNotification makeMockSBN(int userid, String pkg, int id, String tag, |
| 434 | Notification n) { |
| 435 | final StatusBarNotification sbn = mock(StatusBarNotification.class); |
| 436 | when(sbn.getNotification()).thenReturn(n); |
| 437 | when(sbn.getId()).thenReturn(id); |
| 438 | when(sbn.getPackageName()).thenReturn(pkg); |
Julia Reynolds | af78a79 | 2018-03-06 14:27:00 -0500 | [diff] [blame] | 439 | when(sbn.getTag()).thenReturn(tag); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 440 | when(sbn.getUserId()).thenReturn(userid); |
| 441 | when(sbn.getUser()).thenReturn(new UserHandle(userid)); |
| 442 | when(sbn.getKey()).thenReturn("MOCK:"+userid+"|"+pkg+"|"+id+"|"+tag); |
| 443 | return sbn; |
| 444 | } |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 445 | |
Beverly | 201cdd5 | 2019-10-18 14:30:46 -0400 | [diff] [blame] | 446 | private StatusBarNotification makeMockFgSBN(int uid, String pkg, int id, |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 447 | boolean usesStdLayout) { |
| 448 | StatusBarNotification sbn = |
Beverly | 201cdd5 | 2019-10-18 14:30:46 -0400 | [diff] [blame] | 449 | makeMockSBN(uid, pkg, id, "foo", Notification.FLAG_FOREGROUND_SERVICE); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 450 | if (usesStdLayout) { |
| 451 | sbn.getNotification().contentView = null; |
| 452 | sbn.getNotification().headsUpContentView = null; |
| 453 | sbn.getNotification().bigContentView = null; |
| 454 | } else { |
| 455 | sbn.getNotification().contentView = mock(RemoteViews.class); |
| 456 | } |
| 457 | return sbn; |
| 458 | } |
| 459 | |
Beverly | 201cdd5 | 2019-10-18 14:30:46 -0400 | [diff] [blame] | 460 | private StatusBarNotification makeMockFgSBN(int uid, String pkg) { |
| 461 | return makeMockSBN(uid, pkg, 1000, "foo", Notification.FLAG_FOREGROUND_SERVICE); |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 462 | } |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 463 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 464 | private StatusBarNotification makeMockDisclosure(int userid, String[] pkgs) { |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 465 | final Notification n = mock(Notification.class); |
| 466 | n.flags = Notification.FLAG_ONGOING_EVENT; |
| 467 | final Bundle extras = new Bundle(); |
| 468 | if (pkgs != null) extras.putStringArray(Notification.EXTRA_FOREGROUND_APPS, pkgs); |
| 469 | n.extras = extras; |
Dan Sandler | 9830b5a | 2017-10-26 23:27:57 -0400 | [diff] [blame] | 470 | n.when = System.currentTimeMillis() - 10000; // ten seconds ago |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 471 | final StatusBarNotification sbn = makeMockSBN(userid, "android", |
| 472 | SystemMessageProto.SystemMessage.NOTE_FOREGROUND_SERVICES, |
| 473 | null, n); |
| 474 | sbn.getNotification().extras = extras; |
| 475 | return sbn; |
| 476 | } |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 477 | |
Beverly | 201cdd5 | 2019-10-18 14:30:46 -0400 | [diff] [blame] | 478 | private NotificationEntry addFgEntry() { |
| 479 | NotificationEntry entry = createFgEntry(); |
| 480 | mEntryListener.onPendingEntryAdded(entry); |
| 481 | return entry; |
| 482 | } |
| 483 | |
| 484 | private NotificationEntry createFgEntry() { |
| 485 | return new NotificationEntryBuilder() |
| 486 | .setSbn(makeMockFgSBN(0, TEST_PACKAGE_NAME, 1000, true)) |
| 487 | .setImportance(NotificationManager.IMPORTANCE_DEFAULT) |
| 488 | .build(); |
| 489 | } |
| 490 | |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 491 | private void entryRemoved(StatusBarNotification notification) { |
Ned Burns | 636c379 | 2019-09-11 16:59:07 -0400 | [diff] [blame] | 492 | mEntryListener.onEntryRemoved( |
| 493 | new NotificationEntryBuilder() |
| 494 | .setSbn(notification) |
| 495 | .build(), |
| 496 | null, |
| 497 | false); |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | private void entryAdded(StatusBarNotification notification, int importance) { |
Ned Burns | 60e9459 | 2019-09-06 14:47:25 -0400 | [diff] [blame] | 501 | NotificationEntry entry = new NotificationEntryBuilder() |
| 502 | .setSbn(notification) |
| 503 | .setImportance(importance) |
| 504 | .build(); |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 505 | mEntryListener.onPendingEntryAdded(entry); |
| 506 | } |
| 507 | |
| 508 | private void entryUpdated(StatusBarNotification notification, int importance) { |
Ned Burns | 60e9459 | 2019-09-06 14:47:25 -0400 | [diff] [blame] | 509 | NotificationEntry entry = new NotificationEntryBuilder() |
| 510 | .setSbn(notification) |
| 511 | .setImportance(importance) |
| 512 | .build(); |
Beverly | 201cdd5 | 2019-10-18 14:30:46 -0400 | [diff] [blame] | 513 | mEntryListener.onPreEntryUpdated(entry); |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 514 | } |
Beverly | 201cdd5 | 2019-10-18 14:30:46 -0400 | [diff] [blame] | 515 | |
| 516 | @UserIdInt private static final int USERID_ONE = 10; // UserManagerService.MIN_USER_ID; |
| 517 | @UserIdInt private static final int USERID_TWO = USERID_ONE + 1; |
| 518 | private static final String TEST_PACKAGE_NAME = "test"; |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 519 | } |