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