yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.row; |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 18 | |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 19 | import static android.app.AppOpsManager.OP_CAMERA; |
| 20 | import static android.app.AppOpsManager.OP_RECORD_AUDIO; |
| 21 | import static android.app.AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 22 | import static android.app.NotificationManager.IMPORTANCE_DEFAULT; |
Gus Prevas | 5a70a4e | 2018-11-26 17:16:05 -0500 | [diff] [blame] | 23 | import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE; |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 24 | |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 25 | import static junit.framework.Assert.assertNotNull; |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 26 | import static junit.framework.Assert.assertNull; |
| 27 | import static junit.framework.Assert.assertTrue; |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 28 | |
| 29 | import static org.junit.Assert.assertEquals; |
| 30 | import static org.junit.Assert.fail; |
| 31 | import static org.mockito.ArgumentMatchers.any; |
| 32 | import static org.mockito.ArgumentMatchers.anyBoolean; |
| 33 | import static org.mockito.ArgumentMatchers.anyInt; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 34 | import static org.mockito.ArgumentMatchers.eq; |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 35 | import static org.mockito.Mockito.doNothing; |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 36 | import static org.mockito.Mockito.doReturn; |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 37 | import static org.mockito.Mockito.mock; |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 38 | import static org.mockito.Mockito.spy; |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 39 | import static org.mockito.Mockito.times; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 40 | import static org.mockito.Mockito.verify; |
| 41 | import static org.mockito.Mockito.when; |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 42 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 43 | import android.app.INotificationManager; |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 44 | import android.app.Notification; |
| 45 | import android.app.NotificationChannel; |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 46 | import android.content.Intent; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 47 | import android.content.pm.PackageManager; |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 48 | import android.os.Binder; |
| 49 | import android.os.Handler; |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 50 | import android.provider.Settings; |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 51 | import android.service.notification.StatusBarNotification; |
| 52 | import android.support.test.filters.SmallTest; |
| 53 | import android.testing.AndroidTestingRunner; |
| 54 | import android.testing.TestableLooper; |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 55 | import android.util.ArraySet; |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 56 | import android.view.View; |
| 57 | |
TreeHugger Robot | ee8e1ae | 2019-01-18 19:26:40 +0000 | [diff] [blame] | 58 | import com.android.internal.logging.MetricsLogger; |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 59 | import com.android.systemui.SysuiTestCase; |
| 60 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 61 | import com.android.systemui.statusbar.NotificationPresenter; |
| 62 | import com.android.systemui.statusbar.NotificationTestHelper; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 63 | import com.android.systemui.statusbar.notification.NotificationActivityStarter; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 64 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Gus Prevas | 5a70a4e | 2018-11-26 17:16:05 -0500 | [diff] [blame] | 65 | import com.android.systemui.statusbar.notification.row.NotificationGutsManager.OnSettingsClickListener; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 66 | import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 67 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 68 | import com.android.systemui.util.Assert; |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 69 | |
| 70 | import org.junit.Before; |
| 71 | import org.junit.Rule; |
| 72 | import org.junit.Test; |
| 73 | import org.junit.runner.RunWith; |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 74 | import org.mockito.ArgumentCaptor; |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 75 | import org.mockito.Mock; |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 76 | import org.mockito.junit.MockitoJUnit; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 77 | import org.mockito.junit.MockitoRule; |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 78 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 79 | /** |
| 80 | * Tests for {@link NotificationGutsManager}. |
| 81 | */ |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 82 | @SmallTest |
| 83 | @RunWith(AndroidTestingRunner.class) |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 84 | @TestableLooper.RunWithLooper |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 85 | public class NotificationGutsManagerTest extends SysuiTestCase { |
| 86 | private static final String TEST_CHANNEL_ID = "NotificationManagerServiceTestChannelId"; |
| 87 | |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 88 | private NotificationChannel mTestNotificationChannel = new NotificationChannel( |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 89 | TEST_CHANNEL_ID, TEST_CHANNEL_ID, IMPORTANCE_DEFAULT); |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 90 | private TestableLooper mTestableLooper; |
| 91 | private Handler mHandler; |
| 92 | private NotificationTestHelper mHelper; |
| 93 | private NotificationGutsManager mGutsManager; |
| 94 | |
| 95 | @Rule public MockitoRule mockito = MockitoJUnit.rule(); |
TreeHugger Robot | ee8e1ae | 2019-01-18 19:26:40 +0000 | [diff] [blame] | 96 | @Mock private MetricsLogger mMetricsLogger; |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 97 | @Mock private NotificationPresenter mPresenter; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 98 | @Mock private NotificationActivityStarter mNotificationActivityStarter; |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 99 | @Mock private NotificationStackScrollLayout mStackScroller; |
| 100 | @Mock private NotificationInfo.CheckSaveListener mCheckSaveListener; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 101 | @Mock private OnSettingsClickListener mOnSettingsClickListener; |
| 102 | @Mock private DeviceProvisionedController mDeviceProvisionedController; |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 103 | |
| 104 | @Before |
| 105 | public void setUp() { |
| 106 | mTestableLooper = TestableLooper.get(this); |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 107 | Assert.sMainLooper = TestableLooper.get(this).getLooper(); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 108 | mDependency.injectTestDependency(DeviceProvisionedController.class, |
| 109 | mDeviceProvisionedController); |
TreeHugger Robot | ee8e1ae | 2019-01-18 19:26:40 +0000 | [diff] [blame] | 110 | mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 111 | mHandler = Handler.createAsync(mTestableLooper.getLooper()); |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 112 | |
| 113 | mHelper = new NotificationTestHelper(mContext); |
| 114 | |
| 115 | mGutsManager = new NotificationGutsManager(mContext); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 116 | mGutsManager.setUpWithPresenter(mPresenter, mStackScroller, |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 117 | mCheckSaveListener, mOnSettingsClickListener); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 118 | mGutsManager.setNotificationActivityStarter(mNotificationActivityStarter); |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | //////////////////////////////////////////////////////////////////////////////////////////////// |
| 122 | // Test methods: |
| 123 | |
| 124 | @Test |
| 125 | public void testOpenAndCloseGuts() { |
| 126 | NotificationGuts guts = spy(new NotificationGuts(mContext)); |
| 127 | when(guts.post(any())).thenAnswer(invocation -> { |
| 128 | mHandler.post(((Runnable) invocation.getArguments()[0])); |
| 129 | return null; |
| 130 | }); |
| 131 | |
| 132 | // Test doesn't support animation since the guts view is not attached. |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 133 | doNothing().when(guts).openControls( |
| 134 | eq(true) /* shouldDoCircularReveal */, |
| 135 | anyInt(), |
| 136 | anyInt(), |
| 137 | anyBoolean(), |
| 138 | any(Runnable.class)); |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 139 | |
| 140 | ExpandableNotificationRow realRow = createTestNotificationRow(); |
| 141 | NotificationMenuRowPlugin.MenuItem menuItem = createTestMenuItem(realRow); |
| 142 | |
| 143 | ExpandableNotificationRow row = spy(realRow); |
| 144 | when(row.getWindowToken()).thenReturn(new Binder()); |
| 145 | when(row.getGuts()).thenReturn(guts); |
| 146 | |
TreeHugger Robot | ee8e1ae | 2019-01-18 19:26:40 +0000 | [diff] [blame] | 147 | assertTrue(mGutsManager.openGuts(row, 0, 0, menuItem)); |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 148 | assertEquals(View.INVISIBLE, guts.getVisibility()); |
| 149 | mTestableLooper.processAllMessages(); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 150 | verify(guts).openControls( |
| 151 | eq(true), |
| 152 | anyInt(), |
| 153 | anyInt(), |
| 154 | anyBoolean(), |
| 155 | any(Runnable.class)); |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 156 | |
| 157 | assertEquals(View.VISIBLE, guts.getVisibility()); |
| 158 | mGutsManager.closeAndSaveGuts(false, false, false, 0, 0, false); |
| 159 | |
| 160 | verify(guts).closeControls(anyBoolean(), anyBoolean(), anyInt(), anyInt(), anyBoolean()); |
| 161 | verify(row, times(1)).setGutsView(any()); |
| 162 | } |
| 163 | |
| 164 | @Test |
| 165 | public void testChangeDensityOrFontScale() { |
| 166 | NotificationGuts guts = spy(new NotificationGuts(mContext)); |
| 167 | when(guts.post(any())).thenAnswer(invocation -> { |
| 168 | mHandler.post(((Runnable) invocation.getArguments()[0])); |
| 169 | return null; |
| 170 | }); |
| 171 | |
| 172 | // Test doesn't support animation since the guts view is not attached. |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 173 | doNothing().when(guts).openControls( |
| 174 | eq(true) /* shouldDoCircularReveal */, |
| 175 | anyInt(), |
| 176 | anyInt(), |
| 177 | anyBoolean(), |
| 178 | any(Runnable.class)); |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 179 | |
| 180 | ExpandableNotificationRow realRow = createTestNotificationRow(); |
| 181 | NotificationMenuRowPlugin.MenuItem menuItem = createTestMenuItem(realRow); |
| 182 | |
| 183 | ExpandableNotificationRow row = spy(realRow); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 184 | |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 185 | when(row.getWindowToken()).thenReturn(new Binder()); |
| 186 | when(row.getGuts()).thenReturn(guts); |
| 187 | doNothing().when(row).inflateGuts(); |
| 188 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 189 | NotificationEntry realEntry = realRow.getEntry(); |
| 190 | NotificationEntry entry = spy(realEntry); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 191 | |
| 192 | when(entry.getRow()).thenReturn(row); |
| 193 | when(entry.getGuts()).thenReturn(guts); |
| 194 | |
TreeHugger Robot | ee8e1ae | 2019-01-18 19:26:40 +0000 | [diff] [blame] | 195 | assertTrue(mGutsManager.openGuts(row, 0, 0, menuItem)); |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 196 | mTestableLooper.processAllMessages(); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 197 | verify(guts).openControls( |
| 198 | eq(true), |
| 199 | anyInt(), |
| 200 | anyInt(), |
| 201 | anyBoolean(), |
| 202 | any(Runnable.class)); |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 203 | |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 204 | // called once by mGutsManager.bindGuts() in mGutsManager.openGuts() |
| 205 | verify(row).setGutsView(any()); |
| 206 | |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 207 | row.onDensityOrFontScaleChanged(); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 208 | mGutsManager.onDensityOrFontScaleChanged(entry); |
| 209 | |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 210 | mTestableLooper.processAllMessages(); |
| 211 | |
| 212 | mGutsManager.closeAndSaveGuts(false, false, false, 0, 0, false); |
| 213 | |
| 214 | verify(guts).closeControls(anyBoolean(), anyBoolean(), anyInt(), anyInt(), anyBoolean()); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 215 | |
| 216 | // called again by mGutsManager.bindGuts(), in mGutsManager.onDensityOrFontScaleChanged() |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 217 | verify(row, times(2)).setGutsView(any()); |
| 218 | } |
| 219 | |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 220 | @Test |
| 221 | public void testAppOpsSettingsIntent_camera() { |
| 222 | ArraySet<Integer> ops = new ArraySet<>(); |
| 223 | ops.add(OP_CAMERA); |
| 224 | mGutsManager.startAppOpsSettingsActivity("", 0, ops, null); |
| 225 | ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 226 | verify(mNotificationActivityStarter, times(1)) |
| 227 | .startNotificationGutsIntent(captor.capture(), anyInt(), any()); |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 228 | assertEquals(Intent.ACTION_MANAGE_APP_PERMISSIONS, captor.getValue().getAction()); |
| 229 | } |
| 230 | |
| 231 | @Test |
| 232 | public void testAppOpsSettingsIntent_mic() { |
| 233 | ArraySet<Integer> ops = new ArraySet<>(); |
| 234 | ops.add(OP_RECORD_AUDIO); |
| 235 | mGutsManager.startAppOpsSettingsActivity("", 0, ops, null); |
| 236 | ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 237 | verify(mNotificationActivityStarter, times(1)) |
| 238 | .startNotificationGutsIntent(captor.capture(), anyInt(), any()); |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 239 | assertEquals(Intent.ACTION_MANAGE_APP_PERMISSIONS, captor.getValue().getAction()); |
| 240 | } |
| 241 | |
| 242 | @Test |
| 243 | public void testAppOpsSettingsIntent_camera_mic() { |
| 244 | ArraySet<Integer> ops = new ArraySet<>(); |
| 245 | ops.add(OP_CAMERA); |
| 246 | ops.add(OP_RECORD_AUDIO); |
| 247 | mGutsManager.startAppOpsSettingsActivity("", 0, ops, null); |
| 248 | ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 249 | verify(mNotificationActivityStarter, times(1)) |
| 250 | .startNotificationGutsIntent(captor.capture(), anyInt(), any()); |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 251 | assertEquals(Intent.ACTION_MANAGE_APP_PERMISSIONS, captor.getValue().getAction()); |
| 252 | } |
| 253 | |
| 254 | @Test |
| 255 | public void testAppOpsSettingsIntent_overlay() { |
| 256 | ArraySet<Integer> ops = new ArraySet<>(); |
| 257 | ops.add(OP_SYSTEM_ALERT_WINDOW); |
| 258 | mGutsManager.startAppOpsSettingsActivity("", 0, ops, null); |
| 259 | ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 260 | verify(mNotificationActivityStarter, times(1)) |
| 261 | .startNotificationGutsIntent(captor.capture(), anyInt(), any()); |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 262 | assertEquals(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, captor.getValue().getAction()); |
| 263 | } |
| 264 | |
| 265 | @Test |
| 266 | public void testAppOpsSettingsIntent_camera_mic_overlay() { |
| 267 | ArraySet<Integer> ops = new ArraySet<>(); |
| 268 | ops.add(OP_CAMERA); |
| 269 | ops.add(OP_RECORD_AUDIO); |
| 270 | ops.add(OP_SYSTEM_ALERT_WINDOW); |
| 271 | mGutsManager.startAppOpsSettingsActivity("", 0, ops, null); |
| 272 | ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 273 | verify(mNotificationActivityStarter, times(1)) |
| 274 | .startNotificationGutsIntent(captor.capture(), anyInt(), any()); |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 275 | assertEquals(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, captor.getValue().getAction()); |
| 276 | } |
| 277 | |
| 278 | @Test |
| 279 | public void testAppOpsSettingsIntent_camera_overlay() { |
| 280 | ArraySet<Integer> ops = new ArraySet<>(); |
| 281 | ops.add(OP_CAMERA); |
| 282 | ops.add(OP_SYSTEM_ALERT_WINDOW); |
| 283 | mGutsManager.startAppOpsSettingsActivity("", 0, ops, null); |
| 284 | ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 285 | verify(mNotificationActivityStarter, times(1)) |
| 286 | .startNotificationGutsIntent(captor.capture(), anyInt(), any()); |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 287 | assertEquals(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, captor.getValue().getAction()); |
| 288 | } |
| 289 | |
| 290 | @Test |
| 291 | public void testAppOpsSettingsIntent_mic_overlay() { |
| 292 | ArraySet<Integer> ops = new ArraySet<>(); |
| 293 | ops.add(OP_RECORD_AUDIO); |
| 294 | ops.add(OP_SYSTEM_ALERT_WINDOW); |
| 295 | mGutsManager.startAppOpsSettingsActivity("", 0, ops, null); |
| 296 | ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 297 | verify(mNotificationActivityStarter, times(1)) |
| 298 | .startNotificationGutsIntent(captor.capture(), anyInt(), any()); |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 299 | assertEquals(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, captor.getValue().getAction()); |
| 300 | } |
| 301 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 302 | @Test |
| 303 | public void testInitializeNotificationInfoView_showBlockingHelper() throws Exception { |
| 304 | NotificationInfo notificationInfoView = mock(NotificationInfo.class); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 305 | ExpandableNotificationRow row = spy(mHelper.createRow()); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 306 | row.setBlockingHelperShowing(true); |
| 307 | row.getEntry().userSentiment = USER_SENTIMENT_NEGATIVE; |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 308 | when(row.getIsNonblockable()).thenReturn(false); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 309 | StatusBarNotification statusBarNotification = row.getStatusBarNotification(); |
| 310 | |
Gus Prevas | 5a70a4e | 2018-11-26 17:16:05 -0500 | [diff] [blame] | 311 | mGutsManager.initializeNotificationInfo(row, notificationInfoView); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 312 | |
| 313 | verify(notificationInfoView).bindNotification( |
| 314 | any(PackageManager.class), |
| 315 | any(INotificationManager.class), |
| 316 | eq(statusBarNotification.getPackageName()), |
Julia Reynolds | 0abae11 | 2018-06-08 10:36:57 -0400 | [diff] [blame] | 317 | any(NotificationChannel.class), |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 318 | anyInt(), |
| 319 | eq(statusBarNotification), |
| 320 | any(NotificationInfo.CheckSaveListener.class), |
| 321 | any(NotificationInfo.OnSettingsClickListener.class), |
| 322 | any(NotificationInfo.OnAppSettingsClickListener.class), |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 323 | eq(false), |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 324 | eq(false), |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 325 | eq(true) /* isForBlockingHelper */, |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 326 | eq(true) /* isUserSentimentNegative */, |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 327 | eq(0), |
| 328 | eq(false) /* wasShownHighPriority */); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | @Test |
| 332 | public void testInitializeNotificationInfoView_dontShowBlockingHelper() throws Exception { |
| 333 | NotificationInfo notificationInfoView = mock(NotificationInfo.class); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 334 | ExpandableNotificationRow row = spy(mHelper.createRow()); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 335 | row.setBlockingHelperShowing(false); |
| 336 | row.getEntry().userSentiment = USER_SENTIMENT_NEGATIVE; |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 337 | when(row.getIsNonblockable()).thenReturn(false); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 338 | StatusBarNotification statusBarNotification = row.getStatusBarNotification(); |
| 339 | |
Gus Prevas | 5a70a4e | 2018-11-26 17:16:05 -0500 | [diff] [blame] | 340 | mGutsManager.initializeNotificationInfo(row, notificationInfoView); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 341 | |
| 342 | verify(notificationInfoView).bindNotification( |
| 343 | any(PackageManager.class), |
| 344 | any(INotificationManager.class), |
| 345 | eq(statusBarNotification.getPackageName()), |
Julia Reynolds | 0abae11 | 2018-06-08 10:36:57 -0400 | [diff] [blame] | 346 | any(NotificationChannel.class), |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 347 | anyInt(), |
| 348 | eq(statusBarNotification), |
| 349 | any(NotificationInfo.CheckSaveListener.class), |
| 350 | any(NotificationInfo.OnSettingsClickListener.class), |
| 351 | any(NotificationInfo.OnAppSettingsClickListener.class), |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 352 | eq(false), |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 353 | eq(false), |
| 354 | eq(false) /* isForBlockingHelper */, |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 355 | eq(true) /* isUserSentimentNegative */, |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 356 | eq(0), |
| 357 | eq(false) /* wasShownHighPriority */); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | @Test |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 361 | public void testInitializeNotificationInfoView_highPriority() throws Exception { |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 362 | NotificationInfo notificationInfoView = mock(NotificationInfo.class); |
| 363 | ExpandableNotificationRow row = spy(mHelper.createRow()); |
| 364 | row.setBlockingHelperShowing(true); |
| 365 | row.getEntry().userSentiment = USER_SENTIMENT_NEGATIVE; |
| 366 | row.getEntry().importance = IMPORTANCE_DEFAULT; |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 367 | row.getEntry().setIsHighPriority(true); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 368 | when(row.getIsNonblockable()).thenReturn(false); |
| 369 | StatusBarNotification statusBarNotification = row.getStatusBarNotification(); |
| 370 | |
Gus Prevas | 5a70a4e | 2018-11-26 17:16:05 -0500 | [diff] [blame] | 371 | mGutsManager.initializeNotificationInfo(row, notificationInfoView); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 372 | |
| 373 | verify(notificationInfoView).bindNotification( |
| 374 | any(PackageManager.class), |
| 375 | any(INotificationManager.class), |
| 376 | eq(statusBarNotification.getPackageName()), |
| 377 | any(NotificationChannel.class), |
| 378 | anyInt(), |
| 379 | eq(statusBarNotification), |
| 380 | any(NotificationInfo.CheckSaveListener.class), |
| 381 | any(NotificationInfo.OnSettingsClickListener.class), |
| 382 | any(NotificationInfo.OnAppSettingsClickListener.class), |
| 383 | eq(false), |
| 384 | eq(false), |
| 385 | eq(true) /* isForBlockingHelper */, |
| 386 | eq(true) /* isUserSentimentNegative */, |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 387 | eq(IMPORTANCE_DEFAULT), |
| 388 | eq(true) /* wasShownHighPriority */); |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | @Test |
| 392 | public void testInitializeNotificationInfoView_PassesAlongProvisionedState() throws Exception { |
| 393 | NotificationInfo notificationInfoView = mock(NotificationInfo.class); |
| 394 | ExpandableNotificationRow row = spy(mHelper.createRow()); |
| 395 | row.setBlockingHelperShowing(false); |
| 396 | row.getEntry().userSentiment = USER_SENTIMENT_NEGATIVE; |
| 397 | when(row.getIsNonblockable()).thenReturn(false); |
| 398 | StatusBarNotification statusBarNotification = row.getStatusBarNotification(); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 399 | when(mDeviceProvisionedController.isDeviceProvisioned()).thenReturn(true); |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 400 | |
Gus Prevas | 5a70a4e | 2018-11-26 17:16:05 -0500 | [diff] [blame] | 401 | mGutsManager.initializeNotificationInfo(row, notificationInfoView); |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 402 | |
| 403 | verify(notificationInfoView).bindNotification( |
| 404 | any(PackageManager.class), |
| 405 | any(INotificationManager.class), |
| 406 | eq(statusBarNotification.getPackageName()), |
| 407 | any(NotificationChannel.class), |
| 408 | anyInt(), |
| 409 | eq(statusBarNotification), |
| 410 | any(NotificationInfo.CheckSaveListener.class), |
| 411 | any(NotificationInfo.OnSettingsClickListener.class), |
| 412 | any(NotificationInfo.OnAppSettingsClickListener.class), |
| 413 | eq(true), |
| 414 | eq(false), |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 415 | eq(false) /* isForBlockingHelper */, |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 416 | eq(true) /* isUserSentimentNegative */, |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 417 | eq(0), |
| 418 | eq(false) /* wasShownHighPriority */); |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | @Test |
| 422 | public void testInitializeNotificationInfoView_withInitialAction() throws Exception { |
| 423 | NotificationInfo notificationInfoView = mock(NotificationInfo.class); |
| 424 | ExpandableNotificationRow row = spy(mHelper.createRow()); |
| 425 | row.setBlockingHelperShowing(true); |
| 426 | row.getEntry().userSentiment = USER_SENTIMENT_NEGATIVE; |
| 427 | when(row.getIsNonblockable()).thenReturn(false); |
| 428 | StatusBarNotification statusBarNotification = row.getStatusBarNotification(); |
| 429 | |
Gus Prevas | 5a70a4e | 2018-11-26 17:16:05 -0500 | [diff] [blame] | 430 | mGutsManager.initializeNotificationInfo(row, notificationInfoView); |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 431 | |
| 432 | verify(notificationInfoView).bindNotification( |
| 433 | any(PackageManager.class), |
| 434 | any(INotificationManager.class), |
| 435 | eq(statusBarNotification.getPackageName()), |
| 436 | any(NotificationChannel.class), |
| 437 | anyInt(), |
| 438 | eq(statusBarNotification), |
| 439 | any(NotificationInfo.CheckSaveListener.class), |
| 440 | any(NotificationInfo.OnSettingsClickListener.class), |
| 441 | any(NotificationInfo.OnAppSettingsClickListener.class), |
| 442 | eq(false), |
| 443 | eq(false), |
| 444 | eq(true) /* isForBlockingHelper */, |
| 445 | eq(true) /* isUserSentimentNegative */, |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 446 | eq(0), |
| 447 | eq(false) /* wasShownHighPriority */); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 450 | @Test |
| 451 | public void testShouldExtendLifetime() { |
| 452 | NotificationGuts guts = new NotificationGuts(mContext); |
| 453 | ExpandableNotificationRow row = spy(createTestNotificationRow()); |
| 454 | doReturn(guts).when(row).getGuts(); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 455 | NotificationEntry entry = row.getEntry(); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 456 | entry.setRow(row); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 457 | mGutsManager.setExposedGuts(guts); |
| 458 | |
| 459 | assertTrue(mGutsManager.shouldExtendLifetime(entry)); |
| 460 | } |
| 461 | |
| 462 | @Test |
Kevin | e9e938c | 2018-09-06 13:38:11 -0700 | [diff] [blame] | 463 | public void testSetShouldManageLifetime_setShouldManage() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 464 | NotificationEntry entry = createTestNotificationRow().getEntry(); |
Kevin | e9e938c | 2018-09-06 13:38:11 -0700 | [diff] [blame] | 465 | mGutsManager.setShouldManageLifetime(entry, true /* shouldManage */); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 466 | |
| 467 | assertTrue(entry.key.equals(mGutsManager.mKeyToRemoveOnGutsClosed)); |
| 468 | } |
| 469 | |
| 470 | @Test |
Kevin | e9e938c | 2018-09-06 13:38:11 -0700 | [diff] [blame] | 471 | public void testSetShouldManageLifetime_setShouldNotManage() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 472 | NotificationEntry entry = createTestNotificationRow().getEntry(); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 473 | mGutsManager.mKeyToRemoveOnGutsClosed = entry.key; |
Kevin | e9e938c | 2018-09-06 13:38:11 -0700 | [diff] [blame] | 474 | mGutsManager.setShouldManageLifetime(entry, false /* shouldManage */); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 475 | |
| 476 | assertNull(mGutsManager.mKeyToRemoveOnGutsClosed); |
| 477 | } |
| 478 | |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 479 | //////////////////////////////////////////////////////////////////////////////////////////////// |
| 480 | // Utility methods: |
| 481 | |
| 482 | private ExpandableNotificationRow createTestNotificationRow() { |
| 483 | Notification.Builder nb = new Notification.Builder(mContext, |
| 484 | mTestNotificationChannel.getId()) |
| 485 | .setContentTitle("foo") |
| 486 | .setColorized(true) |
| 487 | .setFlag(Notification.FLAG_CAN_COLORIZE, true) |
| 488 | .setSmallIcon(android.R.drawable.sym_def_app_icon); |
| 489 | |
| 490 | try { |
| 491 | ExpandableNotificationRow row = mHelper.createRow(nb.build()); |
| 492 | row.getEntry().channel = mTestNotificationChannel; |
| 493 | return row; |
| 494 | } catch (Exception e) { |
| 495 | fail(); |
| 496 | return null; |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | private NotificationMenuRowPlugin.MenuItem createTestMenuItem(ExpandableNotificationRow row) { |
| 501 | NotificationMenuRowPlugin menuRow = new NotificationMenuRow(mContext); |
| 502 | menuRow.createMenu(row, row.getStatusBarNotification()); |
| 503 | |
| 504 | NotificationMenuRowPlugin.MenuItem menuItem = menuRow.getLongpressMenuItem(mContext); |
| 505 | assertNotNull(menuItem); |
| 506 | return menuItem; |
| 507 | } |
| 508 | } |