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