Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 14 | * limitations under the License |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 15 | */ |
| 16 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.row; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 18 | |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 19 | import static android.app.Notification.FLAG_BUBBLE; |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 20 | import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 21 | import static android.app.NotificationManager.IMPORTANCE_DEFAULT; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 22 | import static android.app.NotificationManager.IMPORTANCE_LOW; |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 23 | import static android.app.NotificationManager.IMPORTANCE_MIN; |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 24 | import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 25 | import static android.print.PrintManager.PRINT_SPOOLER_PACKAGE_NAME; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 26 | import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 27 | import static android.view.View.GONE; |
| 28 | import static android.view.View.VISIBLE; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 29 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 30 | import static junit.framework.Assert.assertEquals; |
| 31 | import static junit.framework.Assert.assertFalse; |
| 32 | import static junit.framework.Assert.assertTrue; |
Julia Reynolds | 5a31193 | 2017-03-01 16:33:44 -0500 | [diff] [blame] | 33 | |
William Brockman | 75cf66a | 2018-12-21 13:25:01 -0500 | [diff] [blame] | 34 | import static org.mockito.ArgumentMatchers.argThat; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 35 | import static org.mockito.Mockito.any; |
| 36 | import static org.mockito.Mockito.anyBoolean; |
| 37 | import static org.mockito.Mockito.anyInt; |
| 38 | import static org.mockito.Mockito.anyString; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 39 | import static org.mockito.Mockito.doCallRealMethod; |
| 40 | import static org.mockito.Mockito.doNothing; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 41 | import static org.mockito.Mockito.eq; |
| 42 | import static org.mockito.Mockito.mock; |
| 43 | import static org.mockito.Mockito.never; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 44 | import static org.mockito.Mockito.spy; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 45 | import static org.mockito.Mockito.times; |
| 46 | import static org.mockito.Mockito.verify; |
| 47 | import static org.mockito.Mockito.when; |
| 48 | |
| 49 | import android.app.INotificationManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 50 | import android.app.Notification; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 51 | import android.app.NotificationChannel; |
| 52 | import android.app.NotificationChannelGroup; |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 53 | import android.app.PendingIntent; |
| 54 | import android.content.Intent; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 55 | import android.content.pm.ApplicationInfo; |
| 56 | import android.content.pm.PackageInfo; |
| 57 | import android.content.pm.PackageManager; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 58 | import android.graphics.drawable.Drawable; |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 59 | import android.graphics.drawable.Icon; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 60 | import android.os.IBinder; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 61 | import android.os.UserHandle; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 62 | import android.provider.Settings; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 63 | import android.service.notification.StatusBarNotification; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 64 | import android.test.suitebuilder.annotation.SmallTest; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 65 | import android.testing.AndroidTestingRunner; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 66 | import android.testing.PollingCheck; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 67 | import android.testing.TestableLooper; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 68 | import android.testing.UiThreadTest; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 69 | import android.view.LayoutInflater; |
| 70 | import android.view.View; |
| 71 | import android.widget.ImageView; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 72 | import android.widget.TextView; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 73 | |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 74 | import com.android.internal.logging.MetricsLogger; |
Eyal Posener | a9cf9c7 | 2018-12-18 16:23:54 +0200 | [diff] [blame] | 75 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 76 | import com.android.systemui.Dependency; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 77 | import com.android.systemui.R; |
| 78 | import com.android.systemui.SysuiTestCase; |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 79 | import com.android.systemui.bubbles.BubbleController; |
| 80 | import com.android.systemui.bubbles.BubblesTestActivity; |
| 81 | import com.android.systemui.statusbar.NotificationEntryBuilder; |
| 82 | import com.android.systemui.statusbar.SbnBuilder; |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 83 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 84 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Jason Monk | ba36432 | 2017-03-06 11:19:20 -0500 | [diff] [blame] | 85 | |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 86 | import org.junit.After; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 87 | import org.junit.Before; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 88 | import org.junit.Rule; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 89 | import org.junit.Test; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 90 | import org.junit.runner.RunWith; |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 91 | import org.mockito.ArgumentCaptor; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 92 | import org.mockito.Mock; |
| 93 | import org.mockito.junit.MockitoJUnit; |
| 94 | import org.mockito.junit.MockitoRule; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 95 | |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 96 | import java.util.HashSet; |
| 97 | import java.util.Set; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 98 | import java.util.concurrent.CountDownLatch; |
| 99 | |
| 100 | @SmallTest |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 101 | @RunWith(AndroidTestingRunner.class) |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 102 | @TestableLooper.RunWithLooper |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 103 | public class NotificationInfoTest extends SysuiTestCase { |
| 104 | private static final String TEST_PACKAGE_NAME = "test_package"; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 105 | private static final String TEST_SYSTEM_PACKAGE_NAME = PRINT_SPOOLER_PACKAGE_NAME; |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 106 | private static final int TEST_UID = 1; |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 107 | private static final int MULTIPLE_CHANNEL_COUNT = 2; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 108 | private static final String TEST_CHANNEL = "test_channel"; |
| 109 | private static final String TEST_CHANNEL_NAME = "TEST CHANNEL NAME"; |
| 110 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 111 | private TestableLooper mTestableLooper; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 112 | private NotificationInfo mNotificationInfo; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 113 | private NotificationChannel mNotificationChannel; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 114 | private NotificationChannel mDefaultNotificationChannel; |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 115 | private Set<NotificationChannel> mNotificationChannelSet = new HashSet<>(); |
| 116 | private Set<NotificationChannel> mDefaultNotificationChannelSet = new HashSet<>(); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 117 | private StatusBarNotification mSbn; |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 118 | private NotificationEntry mEntry; |
| 119 | private StatusBarNotification mBubbleSbn; |
| 120 | private NotificationEntry mBubbleEntry; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 121 | |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 122 | @Rule |
| 123 | public MockitoRule mockito = MockitoJUnit.rule(); |
| 124 | @Mock |
| 125 | private MetricsLogger mMetricsLogger; |
| 126 | @Mock |
| 127 | private INotificationManager mMockINotificationManager; |
| 128 | @Mock |
| 129 | private PackageManager mMockPackageManager; |
| 130 | @Mock |
| 131 | private NotificationBlockingHelperManager mBlockingHelperManager; |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 132 | @Mock |
| 133 | private VisualStabilityManager mVisualStabilityManager; |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 134 | @Mock |
| 135 | private BubbleController mBubbleController; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 136 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 137 | @Before |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 138 | public void setUp() throws Exception { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 139 | mDependency.injectTestDependency( |
| 140 | NotificationBlockingHelperManager.class, |
| 141 | mBlockingHelperManager); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 142 | mTestableLooper = TestableLooper.get(this); |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 143 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 144 | mDependency.injectTestDependency(Dependency.BG_LOOPER, mTestableLooper.getLooper()); |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 145 | mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 146 | mDependency.injectTestDependency(BubbleController.class, mBubbleController); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 147 | // Inflate the layout |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 148 | final LayoutInflater layoutInflater = LayoutInflater.from(mContext); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 149 | mNotificationInfo = (NotificationInfo) layoutInflater.inflate(R.layout.notification_info, |
| 150 | null); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 151 | mNotificationInfo.setGutsParent(mock(NotificationGuts.class)); |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 152 | // Our view is never attached to a window so the View#post methods in NotificationInfo never |
| 153 | // get called. Setting this will skip the post and do the action immediately. |
| 154 | mNotificationInfo.mSkipPost = true; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 155 | |
| 156 | // PackageManager must return a packageInfo and applicationInfo. |
| 157 | final PackageInfo packageInfo = new PackageInfo(); |
| 158 | packageInfo.packageName = TEST_PACKAGE_NAME; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 159 | when(mMockPackageManager.getPackageInfo(eq(TEST_PACKAGE_NAME), anyInt())) |
| 160 | .thenReturn(packageInfo); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 161 | final ApplicationInfo applicationInfo = new ApplicationInfo(); |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 162 | applicationInfo.uid = TEST_UID; // non-zero |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 163 | when(mMockPackageManager.getApplicationInfo(eq(TEST_PACKAGE_NAME), anyInt())).thenReturn( |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 164 | applicationInfo); |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 165 | final PackageInfo systemPackageInfo = new PackageInfo(); |
| 166 | systemPackageInfo.packageName = TEST_SYSTEM_PACKAGE_NAME; |
| 167 | when(mMockPackageManager.getPackageInfo(eq(TEST_SYSTEM_PACKAGE_NAME), anyInt())) |
| 168 | .thenReturn(systemPackageInfo); |
| 169 | when(mMockPackageManager.getPackageInfo(eq("android"), anyInt())) |
| 170 | .thenReturn(packageInfo); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 171 | |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 172 | // Package has one channel by default. |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 173 | when(mMockINotificationManager.getNumNotificationChannelsForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 174 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(1); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 175 | |
| 176 | // Some test channels. |
| 177 | mNotificationChannel = new NotificationChannel( |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 178 | TEST_CHANNEL, TEST_CHANNEL_NAME, IMPORTANCE_LOW); |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 179 | mNotificationChannelSet.add(mNotificationChannel); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 180 | mDefaultNotificationChannel = new NotificationChannel( |
| 181 | NotificationChannel.DEFAULT_CHANNEL_ID, TEST_CHANNEL_NAME, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 182 | IMPORTANCE_LOW); |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 183 | mDefaultNotificationChannelSet.add(mDefaultNotificationChannel); |
Julia Reynolds | 33bef2c | 2017-09-05 11:07:18 -0400 | [diff] [blame] | 184 | mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, 0, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 185 | new Notification(), UserHandle.CURRENT, null, 0); |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 186 | mEntry = new NotificationEntryBuilder().setSbn(mSbn).build(); |
| 187 | |
| 188 | PendingIntent bubbleIntent = PendingIntent.getActivity(mContext, 0, |
| 189 | new Intent(mContext, BubblesTestActivity.class), 0); |
| 190 | mBubbleSbn = new SbnBuilder(mSbn).setBubbleMetadata( |
| 191 | new Notification.BubbleMetadata.Builder() |
| 192 | .setIntent(bubbleIntent) |
| 193 | .setIcon(Icon.createWithResource(mContext, R.drawable.android)).build()) |
| 194 | .build(); |
| 195 | mBubbleEntry = new NotificationEntryBuilder().setSbn(mBubbleSbn).build(); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 196 | |
| 197 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 198 | NOTIFICATION_NEW_INTERRUPTION_MODEL, 1); |
| 199 | } |
| 200 | |
| 201 | @After |
| 202 | public void tearDown() { |
| 203 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 204 | NOTIFICATION_NEW_INTERRUPTION_MODEL, 0); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 205 | } |
| 206 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 207 | // TODO: if tests are taking too long replace this with something that makes the animation |
| 208 | // finish instantly. |
| 209 | private void waitForUndoButton() { |
| 210 | PollingCheck.waitFor(1000, |
| 211 | () -> VISIBLE == mNotificationInfo.findViewById(R.id.confirmation).getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 212 | } |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 213 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 214 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 215 | public void testBindNotification_SetsTextApplicationName() throws Exception { |
| 216 | when(mMockPackageManager.getApplicationLabel(any())).thenReturn("App Name"); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 217 | mNotificationInfo.bindNotification( |
| 218 | mMockPackageManager, |
| 219 | mMockINotificationManager, |
| 220 | mVisualStabilityManager, |
| 221 | TEST_PACKAGE_NAME, |
| 222 | mNotificationChannel, |
| 223 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 224 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 225 | null, |
| 226 | null, |
| 227 | null, |
| 228 | true, |
| 229 | false, |
| 230 | IMPORTANCE_DEFAULT, |
| 231 | true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 232 | final TextView textView = mNotificationInfo.findViewById(R.id.pkgname); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 233 | assertTrue(textView.getText().toString().contains("App Name")); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 234 | assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 238 | public void testBindNotification_SetsPackageIcon() throws Exception { |
| 239 | final Drawable iconDrawable = mock(Drawable.class); |
| 240 | when(mMockPackageManager.getApplicationIcon(any(ApplicationInfo.class))) |
| 241 | .thenReturn(iconDrawable); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 242 | mNotificationInfo.bindNotification( |
| 243 | mMockPackageManager, |
| 244 | mMockINotificationManager, |
| 245 | mVisualStabilityManager, |
| 246 | TEST_PACKAGE_NAME, |
| 247 | mNotificationChannel, |
| 248 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 249 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 250 | null, |
| 251 | null, |
| 252 | null, |
| 253 | true, |
| 254 | false, |
| 255 | IMPORTANCE_DEFAULT, |
| 256 | true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 257 | final ImageView iconView = mNotificationInfo.findViewById(R.id.pkgicon); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 258 | assertEquals(iconDrawable, iconView.getDrawable()); |
| 259 | } |
| 260 | |
| 261 | @Test |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 262 | public void testBindNotification_noDelegate() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 263 | mNotificationInfo.bindNotification( |
| 264 | mMockPackageManager, |
| 265 | mMockINotificationManager, |
| 266 | mVisualStabilityManager, |
| 267 | TEST_PACKAGE_NAME, |
| 268 | mNotificationChannel, |
| 269 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 270 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 271 | null, |
| 272 | null, |
| 273 | null, |
| 274 | true, |
| 275 | false, |
| 276 | IMPORTANCE_DEFAULT, |
| 277 | true); |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 278 | final TextView nameView = mNotificationInfo.findViewById(R.id.delegate_name); |
| 279 | assertEquals(GONE, nameView.getVisibility()); |
| 280 | final TextView dividerView = mNotificationInfo.findViewById(R.id.pkg_divider); |
| 281 | assertEquals(GONE, dividerView.getVisibility()); |
| 282 | } |
| 283 | |
| 284 | @Test |
| 285 | public void testBindNotification_delegate() throws Exception { |
| 286 | mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, "other", 0, null, TEST_UID, 0, |
| 287 | new Notification(), UserHandle.CURRENT, null, 0); |
| 288 | final ApplicationInfo applicationInfo = new ApplicationInfo(); |
| 289 | applicationInfo.uid = 7; // non-zero |
| 290 | when(mMockPackageManager.getApplicationInfo(eq("other"), anyInt())).thenReturn( |
| 291 | applicationInfo); |
| 292 | when(mMockPackageManager.getApplicationLabel(any())).thenReturn("Other"); |
| 293 | |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 294 | NotificationEntry entry = new NotificationEntryBuilder().setSbn(mSbn).build(); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 295 | mNotificationInfo.bindNotification( |
| 296 | mMockPackageManager, |
| 297 | mMockINotificationManager, |
| 298 | mVisualStabilityManager, |
| 299 | TEST_PACKAGE_NAME, |
| 300 | mNotificationChannel, |
| 301 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 302 | entry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 303 | null, |
| 304 | null, |
| 305 | null, |
| 306 | true, |
| 307 | false, |
| 308 | IMPORTANCE_DEFAULT, |
| 309 | true); |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 310 | final TextView nameView = mNotificationInfo.findViewById(R.id.delegate_name); |
| 311 | assertEquals(VISIBLE, nameView.getVisibility()); |
Julia Reynolds | 25b27f5 | 2019-04-24 11:58:38 -0400 | [diff] [blame] | 312 | assertTrue(nameView.getText().toString().contains("Proxied")); |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 313 | final TextView dividerView = mNotificationInfo.findViewById(R.id.pkg_divider); |
| 314 | assertEquals(VISIBLE, dividerView.getVisibility()); |
| 315 | } |
| 316 | |
| 317 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 318 | public void testBindNotification_GroupNameHiddenIfNoGroup() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 319 | mNotificationInfo.bindNotification( |
| 320 | mMockPackageManager, |
| 321 | mMockINotificationManager, |
| 322 | mVisualStabilityManager, |
| 323 | TEST_PACKAGE_NAME, |
| 324 | mNotificationChannel, |
| 325 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 326 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 327 | null, |
| 328 | null, |
| 329 | null, |
| 330 | true, |
| 331 | false, |
| 332 | IMPORTANCE_DEFAULT, |
| 333 | true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 334 | final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name); |
| 335 | assertEquals(GONE, groupNameView.getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 339 | public void testBindNotification_SetsGroupNameIfNonNull() throws Exception { |
| 340 | mNotificationChannel.setGroup("test_group_id"); |
| 341 | final NotificationChannelGroup notificationChannelGroup = |
| 342 | new NotificationChannelGroup("test_group_id", "Test Group Name"); |
| 343 | when(mMockINotificationManager.getNotificationChannelGroupForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 344 | eq("test_group_id"), eq(TEST_PACKAGE_NAME), eq(TEST_UID))) |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 345 | .thenReturn(notificationChannelGroup); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 346 | mNotificationInfo.bindNotification( |
| 347 | mMockPackageManager, |
| 348 | mMockINotificationManager, |
| 349 | mVisualStabilityManager, |
| 350 | TEST_PACKAGE_NAME, |
| 351 | mNotificationChannel, |
| 352 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 353 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 354 | null, |
| 355 | null, |
| 356 | null, |
| 357 | true, |
| 358 | false, |
| 359 | IMPORTANCE_DEFAULT, |
| 360 | true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 361 | final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 362 | assertEquals(View.VISIBLE, groupNameView.getVisibility()); |
| 363 | assertEquals("Test Group Name", groupNameView.getText()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 367 | public void testBindNotification_SetsTextChannelName() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 368 | mNotificationInfo.bindNotification( |
| 369 | mMockPackageManager, |
| 370 | mMockINotificationManager, |
| 371 | mVisualStabilityManager, |
| 372 | TEST_PACKAGE_NAME, |
| 373 | mNotificationChannel, |
| 374 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 375 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 376 | null, |
| 377 | null, |
| 378 | null, |
| 379 | true, |
| 380 | false, |
| 381 | IMPORTANCE_DEFAULT, |
| 382 | true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 383 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 384 | assertEquals(TEST_CHANNEL_NAME, textView.getText()); |
| 385 | } |
| 386 | |
| 387 | @Test |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 388 | public void testBindNotification_DefaultChannelDoesNotUseChannelName() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 389 | mNotificationInfo.bindNotification( |
| 390 | mMockPackageManager, |
| 391 | mMockINotificationManager, |
| 392 | mVisualStabilityManager, |
| 393 | TEST_PACKAGE_NAME, |
| 394 | mDefaultNotificationChannel, |
| 395 | mDefaultNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 396 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 397 | null, |
| 398 | null, |
| 399 | null, |
| 400 | true, |
| 401 | false, |
| 402 | IMPORTANCE_DEFAULT, |
| 403 | true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 404 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 405 | assertEquals(GONE, textView.getVisibility()); |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | @Test |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame] | 409 | public void testBindNotification_DefaultChannelUsesChannelNameIfMoreChannelsExist() |
| 410 | throws Exception { |
| 411 | // Package has one channel by default. |
| 412 | when(mMockINotificationManager.getNumNotificationChannelsForPackage( |
| 413 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(10); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 414 | mNotificationInfo.bindNotification( |
| 415 | mMockPackageManager, |
| 416 | mMockINotificationManager, |
| 417 | mVisualStabilityManager, |
| 418 | TEST_PACKAGE_NAME, |
| 419 | mDefaultNotificationChannel, |
| 420 | mDefaultNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 421 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 422 | null, |
| 423 | null, |
| 424 | null, |
| 425 | true, |
| 426 | false, |
| 427 | IMPORTANCE_DEFAULT, |
| 428 | true); |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame] | 429 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 430 | assertEquals(VISIBLE, textView.getVisibility()); |
| 431 | } |
| 432 | |
| 433 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 434 | public void testBindNotification_UnblockablePackageUsesChannelName() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 435 | mNotificationInfo.bindNotification( |
| 436 | mMockPackageManager, |
| 437 | mMockINotificationManager, |
| 438 | mVisualStabilityManager, |
| 439 | TEST_PACKAGE_NAME, |
| 440 | mNotificationChannel, |
| 441 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 442 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 443 | null, |
| 444 | null, |
| 445 | null, |
| 446 | true, |
| 447 | true, |
| 448 | IMPORTANCE_DEFAULT, |
| 449 | true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 450 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 451 | assertEquals(VISIBLE, textView.getVisibility()); |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | @Test |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 455 | public void testBindNotification_BlockLink_BlockingHelper() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 456 | mNotificationInfo.bindNotification( |
| 457 | mMockPackageManager, |
| 458 | mMockINotificationManager, |
| 459 | mVisualStabilityManager, |
| 460 | TEST_PACKAGE_NAME, |
| 461 | mNotificationChannel, |
| 462 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 463 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 464 | null, |
| 465 | mock(NotificationInfo.OnSettingsClickListener.class), |
| 466 | null, |
| 467 | true, |
| 468 | false, |
| 469 | true /* isBlockingHelper */, |
| 470 | IMPORTANCE_DEFAULT, |
| 471 | true); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 472 | final View block = |
| 473 | mNotificationInfo.findViewById(R.id.blocking_helper_turn_off_notifications); |
Gus Prevas | 82ad059 | 2018-11-28 14:27:40 -0500 | [diff] [blame] | 474 | final View interruptivenessSettings = mNotificationInfo.findViewById( |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 475 | R.id.inline_controls); |
Gus Prevas | 82ad059 | 2018-11-28 14:27:40 -0500 | [diff] [blame] | 476 | assertEquals(VISIBLE, block.getVisibility()); |
| 477 | assertEquals(GONE, interruptivenessSettings.getVisibility()); |
| 478 | } |
| 479 | |
| 480 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 481 | public void testBindNotification_SetsOnClickListenerForSettings() throws Exception { |
| 482 | final CountDownLatch latch = new CountDownLatch(1); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 483 | mNotificationInfo.bindNotification( |
| 484 | mMockPackageManager, |
| 485 | mMockINotificationManager, |
| 486 | mVisualStabilityManager, |
| 487 | TEST_PACKAGE_NAME, |
| 488 | mNotificationChannel, |
| 489 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 490 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 491 | null, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 492 | (View v, NotificationChannel c, int appUid) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 493 | assertEquals(mNotificationChannel, c); |
| 494 | latch.countDown(); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 495 | }, |
| 496 | null, |
| 497 | true, |
| 498 | false, |
| 499 | IMPORTANCE_DEFAULT, |
| 500 | true); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 501 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 502 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 503 | settingsButton.performClick(); |
| 504 | // Verify that listener was triggered. |
| 505 | assertEquals(0, latch.getCount()); |
| 506 | } |
| 507 | |
| 508 | @Test |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 509 | public void testBindNotification_SettingsButtonInvisibleWhenNoClickListener() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 510 | mNotificationInfo.bindNotification( |
| 511 | mMockPackageManager, |
| 512 | mMockINotificationManager, |
| 513 | mVisualStabilityManager, |
| 514 | TEST_PACKAGE_NAME, |
| 515 | mNotificationChannel, |
| 516 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 517 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 518 | null, |
| 519 | null, |
| 520 | null, |
| 521 | true, |
| 522 | false, |
| 523 | IMPORTANCE_DEFAULT, |
| 524 | true); |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 525 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
| 526 | assertTrue(settingsButton.getVisibility() != View.VISIBLE); |
| 527 | } |
| 528 | |
| 529 | @Test |
| 530 | public void testBindNotification_SettingsButtonInvisibleWhenDeviceUnprovisioned() |
| 531 | throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 532 | mNotificationInfo.bindNotification( |
| 533 | mMockPackageManager, |
| 534 | mMockINotificationManager, |
| 535 | mVisualStabilityManager, |
| 536 | TEST_PACKAGE_NAME, |
| 537 | mNotificationChannel, |
| 538 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 539 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 540 | null, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 541 | (View v, NotificationChannel c, int appUid) -> { |
| 542 | assertEquals(mNotificationChannel, c); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 543 | }, |
| 544 | null, |
| 545 | false, |
| 546 | false, |
| 547 | IMPORTANCE_DEFAULT, |
| 548 | true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 549 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 550 | assertTrue(settingsButton.getVisibility() != View.VISIBLE); |
| 551 | } |
| 552 | |
| 553 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 554 | public void testBindNotification_SettingsButtonReappearsAfterSecondBind() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 555 | mNotificationInfo.bindNotification( |
| 556 | mMockPackageManager, |
| 557 | mMockINotificationManager, |
| 558 | mVisualStabilityManager, |
| 559 | TEST_PACKAGE_NAME, |
| 560 | mNotificationChannel, |
| 561 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 562 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 563 | null, |
| 564 | null, |
| 565 | null, |
| 566 | true, |
| 567 | false, |
| 568 | IMPORTANCE_DEFAULT, |
| 569 | true); |
| 570 | mNotificationInfo.bindNotification( |
| 571 | mMockPackageManager, |
| 572 | mMockINotificationManager, |
| 573 | mVisualStabilityManager, |
| 574 | TEST_PACKAGE_NAME, |
| 575 | mNotificationChannel, |
| 576 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 577 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 578 | null, |
| 579 | (View v, NotificationChannel c, int appUid) -> { }, |
| 580 | null, |
| 581 | true, |
| 582 | false, |
| 583 | IMPORTANCE_DEFAULT, |
| 584 | true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 585 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 586 | assertEquals(View.VISIBLE, settingsButton.getVisibility()); |
| 587 | } |
| 588 | |
| 589 | @Test |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 590 | public void testBindNotificationLogging_notBlockingHelper() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 591 | mNotificationInfo.bindNotification( |
| 592 | mMockPackageManager, |
| 593 | mMockINotificationManager, |
| 594 | mVisualStabilityManager, |
| 595 | TEST_PACKAGE_NAME, |
| 596 | mNotificationChannel, |
| 597 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 598 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 599 | null, |
| 600 | null, |
| 601 | null, |
| 602 | true, |
| 603 | false, |
| 604 | IMPORTANCE_DEFAULT, |
| 605 | true); |
Eyal Posener | a9cf9c7 | 2018-12-18 16:23:54 +0200 | [diff] [blame] | 606 | verify(mMetricsLogger).write(argThat(logMaker -> |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 607 | logMaker.getCategory() == MetricsEvent.ACTION_NOTE_CONTROLS |
| 608 | && logMaker.getType() == MetricsEvent.TYPE_OPEN |
| 609 | && logMaker.getSubtype() == MetricsEvent.BLOCKING_HELPER_UNKNOWN |
| 610 | )); |
| 611 | } |
| 612 | |
| 613 | @Test |
| 614 | public void testBindNotificationLogging_BlockingHelper() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 615 | mNotificationInfo.bindNotification( |
| 616 | mMockPackageManager, |
| 617 | mMockINotificationManager, |
| 618 | mVisualStabilityManager, |
| 619 | TEST_PACKAGE_NAME, |
| 620 | mNotificationChannel, |
| 621 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 622 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 623 | null, |
| 624 | null, |
| 625 | null, |
| 626 | false, |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 627 | true, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 628 | true, |
| 629 | IMPORTANCE_DEFAULT, |
| 630 | true); |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 631 | verify(mMetricsLogger).write(argThat(logMaker -> |
| 632 | logMaker.getCategory() == MetricsEvent.ACTION_NOTE_CONTROLS |
Eyal Posener | aea29ed | 2019-01-24 09:54:08 +0200 | [diff] [blame] | 633 | && logMaker.getType() == MetricsEvent.TYPE_OPEN |
Eyal Posener | a9cf9c7 | 2018-12-18 16:23:54 +0200 | [diff] [blame] | 634 | && logMaker.getSubtype() == MetricsEvent.BLOCKING_HELPER_DISPLAY |
| 635 | )); |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | @Test |
| 639 | public void testLogBlockingHelperCounter_logsForBlockingHelper() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 640 | mNotificationInfo.bindNotification( |
| 641 | mMockPackageManager, |
| 642 | mMockINotificationManager, |
| 643 | mVisualStabilityManager, |
| 644 | TEST_PACKAGE_NAME, |
| 645 | mNotificationChannel, |
| 646 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 647 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 648 | null, |
| 649 | null, |
| 650 | null, |
| 651 | false, |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 652 | true, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 653 | true, |
| 654 | IMPORTANCE_DEFAULT, |
| 655 | true); |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 656 | mNotificationInfo.logBlockingHelperCounter("HowCanNotifsBeRealIfAppsArent"); |
William Brockman | 75cf66a | 2018-12-21 13:25:01 -0500 | [diff] [blame] | 657 | verify(mMetricsLogger).count(eq("HowCanNotifsBeRealIfAppsArent"), eq(1)); |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 661 | public void testOnClickListenerPassesNullChannelForBundle() throws Exception { |
| 662 | final CountDownLatch latch = new CountDownLatch(1); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 663 | mNotificationInfo.bindNotification( |
| 664 | mMockPackageManager, |
| 665 | mMockINotificationManager, |
| 666 | mVisualStabilityManager, |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 667 | TEST_PACKAGE_NAME, mNotificationChannel, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 668 | createMultipleChannelSet(MULTIPLE_CHANNEL_COUNT), |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 669 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 670 | null, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 671 | (View v, NotificationChannel c, int appUid) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 672 | assertEquals(null, c); |
| 673 | latch.countDown(); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 674 | }, |
| 675 | null, |
| 676 | true, |
| 677 | true, |
| 678 | IMPORTANCE_DEFAULT, |
| 679 | true); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 680 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 681 | mNotificationInfo.findViewById(R.id.info).performClick(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 682 | // Verify that listener was triggered. |
| 683 | assertEquals(0, latch.getCount()); |
| 684 | } |
| 685 | |
| 686 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 687 | @UiThreadTest |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 688 | public void testBindNotification_ChannelNameInvisibleWhenBundleFromDifferentChannels() |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 689 | throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 690 | mNotificationInfo.bindNotification( |
| 691 | mMockPackageManager, |
| 692 | mMockINotificationManager, |
| 693 | mVisualStabilityManager, |
| 694 | TEST_PACKAGE_NAME, |
| 695 | mNotificationChannel, |
| 696 | createMultipleChannelSet(MULTIPLE_CHANNEL_COUNT), |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 697 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 698 | null, |
| 699 | null, |
| 700 | null, |
| 701 | true, |
| 702 | false, |
| 703 | IMPORTANCE_DEFAULT, |
| 704 | true); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 705 | final TextView channelNameView = |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 706 | mNotificationInfo.findViewById(R.id.channel_name); |
| 707 | assertEquals(GONE, channelNameView.getVisibility()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | @Test |
| 711 | @UiThreadTest |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 712 | public void testStopInvisibleIfBundleFromDifferentChannels() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 713 | mNotificationInfo.bindNotification( |
| 714 | mMockPackageManager, |
| 715 | mMockINotificationManager, |
| 716 | mVisualStabilityManager, |
| 717 | TEST_PACKAGE_NAME, |
| 718 | mNotificationChannel, |
| 719 | createMultipleChannelSet(MULTIPLE_CHANNEL_COUNT), |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 720 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 721 | null, |
| 722 | null, |
| 723 | null, |
| 724 | true, |
| 725 | false, |
| 726 | IMPORTANCE_DEFAULT, |
| 727 | true); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 728 | assertEquals(GONE, mNotificationInfo.findViewById( |
| 729 | R.id.interruptiveness_settings).getVisibility()); |
| 730 | assertEquals(VISIBLE, mNotificationInfo.findViewById( |
| 731 | R.id.non_configurable_multichannel_text).getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | @Test |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 735 | public void testBindNotification_whenAppUnblockable() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 736 | mNotificationInfo.bindNotification( |
| 737 | mMockPackageManager, |
| 738 | mMockINotificationManager, |
| 739 | mVisualStabilityManager, |
| 740 | TEST_PACKAGE_NAME, |
| 741 | mNotificationChannel, |
| 742 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 743 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 744 | null, |
| 745 | null, |
| 746 | null, |
| 747 | true, |
| 748 | true, |
| 749 | IMPORTANCE_DEFAULT, |
| 750 | true); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 751 | final TextView view = mNotificationInfo.findViewById(R.id.non_configurable_text); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 752 | assertEquals(View.VISIBLE, view.getVisibility()); |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 753 | assertEquals(mContext.getString(R.string.notification_unblockable_desc), |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 754 | view.getText()); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 755 | assertEquals(GONE, |
| 756 | mNotificationInfo.findViewById(R.id.interruptiveness_settings).getVisibility()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | @Test |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 760 | public void testBindNotification_alertIsSelected() throws Exception { |
| 761 | mNotificationInfo.bindNotification( |
| 762 | mMockPackageManager, |
| 763 | mMockINotificationManager, |
| 764 | mVisualStabilityManager, |
| 765 | TEST_PACKAGE_NAME, |
| 766 | mNotificationChannel, |
| 767 | mNotificationChannelSet, |
| 768 | mBubbleEntry, |
| 769 | null, |
| 770 | null, |
| 771 | null, |
| 772 | true, |
| 773 | false, |
| 774 | IMPORTANCE_DEFAULT, |
| 775 | true); |
| 776 | assertTrue(mNotificationInfo.findViewById(R.id.alert).isSelected()); |
| 777 | } |
| 778 | |
| 779 | @Test |
| 780 | public void testBindNotification_silenceIsSelected() throws Exception { |
| 781 | mNotificationInfo.bindNotification( |
| 782 | mMockPackageManager, |
| 783 | mMockINotificationManager, |
| 784 | mVisualStabilityManager, |
| 785 | TEST_PACKAGE_NAME, |
| 786 | mNotificationChannel, |
| 787 | mNotificationChannelSet, |
| 788 | mBubbleEntry, |
| 789 | null, |
| 790 | null, |
| 791 | null, |
| 792 | true, |
| 793 | false, |
| 794 | IMPORTANCE_DEFAULT, |
| 795 | false); |
| 796 | assertTrue(mNotificationInfo.findViewById(R.id.silence).isSelected()); |
| 797 | } |
| 798 | |
| 799 | @Test |
| 800 | public void testBindNotification_bubbleIsSelected() throws Exception { |
| 801 | mBubbleEntry.getSbn().getNotification().flags |= FLAG_BUBBLE; |
| 802 | mNotificationInfo.bindNotification( |
| 803 | mMockPackageManager, |
| 804 | mMockINotificationManager, |
| 805 | mVisualStabilityManager, |
| 806 | TEST_PACKAGE_NAME, |
| 807 | mNotificationChannel, |
| 808 | mNotificationChannelSet, |
| 809 | mBubbleEntry, |
| 810 | null, |
| 811 | null, |
| 812 | null, |
| 813 | true, |
| 814 | false, |
| 815 | IMPORTANCE_DEFAULT, |
| 816 | true); |
| 817 | |
| 818 | View bubbleView = mNotificationInfo.findViewById(R.id.bubble); |
| 819 | assertEquals(View.VISIBLE, bubbleView.getVisibility()); |
| 820 | assertTrue(bubbleView.isSelected()); |
| 821 | } |
| 822 | |
| 823 | @Test |
| 824 | public void testBindNotification_whenCanBubble() throws Exception { |
| 825 | mNotificationInfo.bindNotification( |
| 826 | mMockPackageManager, |
| 827 | mMockINotificationManager, |
| 828 | mVisualStabilityManager, |
| 829 | TEST_PACKAGE_NAME, |
| 830 | mNotificationChannel, |
| 831 | mNotificationChannelSet, |
| 832 | mBubbleEntry, |
| 833 | null, |
| 834 | null, |
| 835 | null, |
| 836 | true, |
| 837 | false, |
| 838 | IMPORTANCE_DEFAULT, |
| 839 | true); |
| 840 | |
| 841 | View bubbleView = mNotificationInfo.findViewById(R.id.bubble); |
| 842 | assertEquals(View.VISIBLE, bubbleView.getVisibility()); |
| 843 | assertFalse(bubbleView.isSelected()); |
| 844 | } |
| 845 | |
| 846 | @Test |
| 847 | public void testBindNotification_whenCantBubble() throws Exception { |
| 848 | mNotificationInfo.bindNotification( |
| 849 | mMockPackageManager, |
| 850 | mMockINotificationManager, |
| 851 | mVisualStabilityManager, |
| 852 | TEST_PACKAGE_NAME, |
| 853 | mNotificationChannel, |
| 854 | mNotificationChannelSet, |
| 855 | mEntry, |
| 856 | null, |
| 857 | null, |
| 858 | null, |
| 859 | true, |
| 860 | false, |
| 861 | IMPORTANCE_DEFAULT, |
| 862 | true); |
| 863 | View bubbleView = mNotificationInfo.findViewById(R.id.bubble); |
| 864 | assertEquals(View.GONE, bubbleView.getVisibility()); |
| 865 | } |
| 866 | |
| 867 | @Test |
| 868 | public void testBubble_promotesBubble() throws Exception { |
| 869 | mNotificationInfo.bindNotification( |
| 870 | mMockPackageManager, |
| 871 | mMockINotificationManager, |
| 872 | mVisualStabilityManager, |
| 873 | TEST_PACKAGE_NAME, |
| 874 | mNotificationChannel, |
| 875 | mNotificationChannelSet, |
| 876 | mBubbleEntry, |
| 877 | null, |
| 878 | null, |
| 879 | null, |
| 880 | true, |
| 881 | false, |
| 882 | IMPORTANCE_DEFAULT, |
| 883 | true); |
| 884 | |
| 885 | assertFalse(mBubbleEntry.isBubble()); |
| 886 | |
| 887 | // Promote it |
| 888 | mNotificationInfo.findViewById(R.id.bubble).performClick(); |
| 889 | mNotificationInfo.findViewById(R.id.done).performClick(); |
| 890 | mNotificationInfo.handleCloseControls(true, false); |
| 891 | |
| 892 | verify(mBubbleController, times(1)).onUserCreatedBubbleFromNotification(mBubbleEntry); |
| 893 | } |
| 894 | |
| 895 | @Test |
| 896 | public void testAlert_demotesBubble() throws Exception { |
| 897 | mBubbleEntry.getSbn().getNotification().flags |= FLAG_BUBBLE; |
| 898 | |
| 899 | mNotificationInfo.bindNotification( |
| 900 | mMockPackageManager, |
| 901 | mMockINotificationManager, |
| 902 | mVisualStabilityManager, |
| 903 | TEST_PACKAGE_NAME, |
| 904 | mNotificationChannel, |
| 905 | mNotificationChannelSet, |
| 906 | mBubbleEntry, |
| 907 | null, |
| 908 | null, |
| 909 | null, |
| 910 | true, |
| 911 | false, |
| 912 | IMPORTANCE_DEFAULT, |
| 913 | true); |
| 914 | |
| 915 | assertTrue(mBubbleEntry.isBubble()); |
| 916 | |
| 917 | // Demote it |
| 918 | mNotificationInfo.findViewById(R.id.alert).performClick(); |
| 919 | mNotificationInfo.findViewById(R.id.done).performClick(); |
| 920 | mNotificationInfo.handleCloseControls(true, false); |
| 921 | |
| 922 | verify(mBubbleController, times(1)).onUserDemotedBubbleFromNotification(mBubbleEntry); |
| 923 | } |
| 924 | |
| 925 | @Test |
| 926 | public void testSilence_demotesBubble() throws Exception { |
| 927 | mBubbleEntry.getSbn().getNotification().flags |= FLAG_BUBBLE; |
| 928 | |
| 929 | mNotificationInfo.bindNotification( |
| 930 | mMockPackageManager, |
| 931 | mMockINotificationManager, |
| 932 | mVisualStabilityManager, |
| 933 | TEST_PACKAGE_NAME, |
| 934 | mNotificationChannel, |
| 935 | mNotificationChannelSet, |
| 936 | mBubbleEntry, |
| 937 | null, |
| 938 | null, |
| 939 | null, |
| 940 | true, |
| 941 | false, |
| 942 | IMPORTANCE_DEFAULT, |
| 943 | true); |
| 944 | |
| 945 | assertTrue(mBubbleEntry.isBubble()); |
| 946 | |
| 947 | // Demote it |
| 948 | mNotificationInfo.findViewById(R.id.silence).performClick(); |
| 949 | mNotificationInfo.findViewById(R.id.done).performClick(); |
| 950 | mNotificationInfo.handleCloseControls(true, false); |
| 951 | |
| 952 | verify(mBubbleController, times(1)).onUserDemotedBubbleFromNotification(mBubbleEntry); |
| 953 | } |
| 954 | |
| 955 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 956 | public void testBindNotification_DoesNotUpdateNotificationChannel() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 957 | mNotificationInfo.bindNotification( |
| 958 | mMockPackageManager, |
| 959 | mMockINotificationManager, |
| 960 | mVisualStabilityManager, |
| 961 | TEST_PACKAGE_NAME, |
| 962 | mNotificationChannel, |
| 963 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 964 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 965 | null, |
| 966 | null, |
| 967 | null, |
| 968 | true, |
| 969 | false, |
| 970 | IMPORTANCE_DEFAULT, |
| 971 | true); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 972 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 973 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 974 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 978 | public void testDoesNotUpdateNotificationChannelAfterImportanceChanged() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 979 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 980 | mNotificationInfo.bindNotification( |
| 981 | mMockPackageManager, |
| 982 | mMockINotificationManager, |
| 983 | mVisualStabilityManager, |
| 984 | TEST_PACKAGE_NAME, |
| 985 | mNotificationChannel, |
| 986 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 987 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 988 | null, |
| 989 | null, |
| 990 | null, |
| 991 | true, |
| 992 | false, |
| 993 | IMPORTANCE_LOW, |
| 994 | false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 995 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 996 | mNotificationInfo.findViewById(R.id.alert).performClick(); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 997 | mTestableLooper.processAllMessages(); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 998 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 999 | anyString(), eq(TEST_UID), any()); |
| 1000 | } |
| 1001 | |
| 1002 | @Test |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 1003 | public void testDoesNotUpdateNotificationChannelAfterImportanceChangedSilenced() |
| 1004 | throws Exception { |
| 1005 | mNotificationChannel.setImportance(IMPORTANCE_DEFAULT); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1006 | mNotificationInfo.bindNotification( |
| 1007 | mMockPackageManager, |
| 1008 | mMockINotificationManager, |
| 1009 | mVisualStabilityManager, |
| 1010 | TEST_PACKAGE_NAME, |
| 1011 | mNotificationChannel, |
| 1012 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1013 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1014 | null, |
| 1015 | null, |
| 1016 | null, |
| 1017 | true, |
| 1018 | false, |
| 1019 | IMPORTANCE_DEFAULT, |
| 1020 | true); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 1021 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1022 | mNotificationInfo.findViewById(R.id.silence).performClick(); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 1023 | mTestableLooper.processAllMessages(); |
| 1024 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 1025 | anyString(), eq(TEST_UID), any()); |
| 1026 | } |
| 1027 | |
| 1028 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 1029 | public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnchanged() |
| 1030 | throws Exception { |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 1031 | int originalImportance = mNotificationChannel.getImportance(); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1032 | mNotificationInfo.bindNotification( |
| 1033 | mMockPackageManager, |
| 1034 | mMockINotificationManager, |
| 1035 | mVisualStabilityManager, |
| 1036 | TEST_PACKAGE_NAME, |
| 1037 | mNotificationChannel, |
| 1038 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1039 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1040 | null, |
| 1041 | null, |
| 1042 | null, |
| 1043 | true, |
| 1044 | false, |
| 1045 | IMPORTANCE_DEFAULT, |
| 1046 | true); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 1047 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 1048 | mNotificationInfo.handleCloseControls(true, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 1049 | mTestableLooper.processAllMessages(); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 1050 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 1051 | anyString(), eq(TEST_UID), any()); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 1052 | assertEquals(originalImportance, mNotificationChannel.getImportance()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 1056 | public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnspecified() |
| 1057 | throws Exception { |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 1058 | mNotificationChannel.setImportance(IMPORTANCE_UNSPECIFIED); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1059 | mNotificationInfo.bindNotification( |
| 1060 | mMockPackageManager, |
| 1061 | mMockINotificationManager, |
| 1062 | mVisualStabilityManager, |
| 1063 | TEST_PACKAGE_NAME, |
| 1064 | mNotificationChannel, |
| 1065 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1066 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1067 | null, |
| 1068 | null, |
| 1069 | null, |
| 1070 | true, |
| 1071 | false, |
| 1072 | IMPORTANCE_UNSPECIFIED, |
| 1073 | true); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 1074 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 1075 | mNotificationInfo.handleCloseControls(true, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 1076 | |
| 1077 | mTestableLooper.processAllMessages(); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 1078 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 1079 | anyString(), eq(TEST_UID), any()); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 1080 | assertEquals(IMPORTANCE_UNSPECIFIED, mNotificationChannel.getImportance()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | @Test |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 1084 | public void testCloseControls_nonNullCheckSaveListenerDoesntDelayKeepShowing_BlockingHelper() |
Rohan Shah | dd588c7 | 2018-05-09 20:32:15 -0700 | [diff] [blame] | 1085 | throws Exception { |
| 1086 | NotificationInfo.CheckSaveListener listener = |
| 1087 | mock(NotificationInfo.CheckSaveListener.class); |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1088 | mNotificationChannel.setImportance(IMPORTANCE_DEFAULT); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1089 | mNotificationInfo.bindNotification( |
| 1090 | mMockPackageManager, |
| 1091 | mMockINotificationManager, |
| 1092 | mVisualStabilityManager, |
| 1093 | TEST_PACKAGE_NAME, |
| 1094 | mNotificationChannel /* notificationChannel */, |
| 1095 | createMultipleChannelSet(10) /* numUniqueChannelsInRow */, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1096 | mEntry, |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 1097 | listener /* checkSaveListener */, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1098 | null /* onSettingsClick */, |
| 1099 | null /* onAppSettingsClick */, |
| 1100 | true /* provisioned */, |
| 1101 | false /* isNonblockable */, |
| 1102 | true /* isForBlockingHelper */, |
| 1103 | IMPORTANCE_DEFAULT, |
| 1104 | true); |
Rohan Shah | dd588c7 | 2018-05-09 20:32:15 -0700 | [diff] [blame] | 1105 | |
| 1106 | NotificationGuts guts = spy(new NotificationGuts(mContext, null)); |
| 1107 | when(guts.getWindowToken()).thenReturn(mock(IBinder.class)); |
| 1108 | doNothing().when(guts).animateClose(anyInt(), anyInt(), anyBoolean()); |
| 1109 | doNothing().when(guts).setExposed(anyBoolean(), anyBoolean()); |
| 1110 | guts.setGutsContent(mNotificationInfo); |
| 1111 | mNotificationInfo.setGutsParent(guts); |
| 1112 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 1113 | mNotificationInfo.findViewById(R.id.keep_showing).performClick(); |
Rohan Shah | dd588c7 | 2018-05-09 20:32:15 -0700 | [diff] [blame] | 1114 | |
| 1115 | verify(mBlockingHelperManager).dismissCurrentBlockingHelper(); |
| 1116 | mTestableLooper.processAllMessages(); |
| 1117 | verify(mMockINotificationManager, times(1)) |
| 1118 | .setNotificationsEnabledWithImportanceLockForPackage( |
| 1119 | anyString(), eq(TEST_UID), eq(true)); |
| 1120 | } |
| 1121 | |
Rohan Shah | 593e8f1 | 2018-05-22 10:06:23 -0700 | [diff] [blame] | 1122 | @Test |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 1123 | public void testCloseControls_nonNullCheckSaveListenerDoesntDelayDismiss_BlockingHelper() |
Rohan Shah | 593e8f1 | 2018-05-22 10:06:23 -0700 | [diff] [blame] | 1124 | throws Exception { |
| 1125 | NotificationInfo.CheckSaveListener listener = |
| 1126 | mock(NotificationInfo.CheckSaveListener.class); |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1127 | mNotificationChannel.setImportance(IMPORTANCE_DEFAULT); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1128 | mNotificationInfo.bindNotification( |
| 1129 | mMockPackageManager, |
| 1130 | mMockINotificationManager, |
| 1131 | mVisualStabilityManager, |
| 1132 | TEST_PACKAGE_NAME, |
| 1133 | mNotificationChannel /* notificationChannel */, |
| 1134 | createMultipleChannelSet(10) /* numUniqueChannelsInRow */, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1135 | mEntry, |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 1136 | listener /* checkSaveListener */, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1137 | null /* onSettingsClick */, |
| 1138 | null /* onAppSettingsClick */, |
| 1139 | false /* isNonblockable */, |
| 1140 | true /* isForBlockingHelper */, |
| 1141 | true, IMPORTANCE_DEFAULT, |
| 1142 | true); |
Rohan Shah | 593e8f1 | 2018-05-22 10:06:23 -0700 | [diff] [blame] | 1143 | |
| 1144 | mNotificationInfo.handleCloseControls(true /* save */, false /* force */); |
| 1145 | |
| 1146 | mTestableLooper.processAllMessages(); |
| 1147 | verify(listener, times(0)).checkSave(any(Runnable.class), eq(mSbn)); |
| 1148 | } |
| 1149 | |
| 1150 | @Test |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 1151 | public void testCloseControls_checkSaveListenerDelaysStopNotifications_BlockingHelper() |
Rohan Shah | 593e8f1 | 2018-05-22 10:06:23 -0700 | [diff] [blame] | 1152 | throws Exception { |
| 1153 | NotificationInfo.CheckSaveListener listener = |
| 1154 | mock(NotificationInfo.CheckSaveListener.class); |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1155 | mNotificationChannel.setImportance(IMPORTANCE_DEFAULT); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1156 | mNotificationInfo.bindNotification( |
| 1157 | mMockPackageManager, |
| 1158 | mMockINotificationManager, |
| 1159 | mVisualStabilityManager, |
| 1160 | TEST_PACKAGE_NAME, |
| 1161 | mNotificationChannel /* notificationChannel */, |
| 1162 | createMultipleChannelSet(10) /* numUniqueChannelsInRow */, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1163 | mEntry, |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 1164 | listener /* checkSaveListener */, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1165 | null /* onSettingsClick */, |
| 1166 | null /* onAppSettingsClick */, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 1167 | true /* provisioned */, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1168 | false /* isNonblockable */, |
| 1169 | true /* isForBlockingHelper */, |
| 1170 | IMPORTANCE_DEFAULT, |
| 1171 | true); |
Rohan Shah | 593e8f1 | 2018-05-22 10:06:23 -0700 | [diff] [blame] | 1172 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 1173 | mNotificationInfo.findViewById(R.id.deliver_silently).performClick(); |
Rohan Shah | 593e8f1 | 2018-05-22 10:06:23 -0700 | [diff] [blame] | 1174 | mTestableLooper.processAllMessages(); |
| 1175 | verify(listener).checkSave(any(Runnable.class), eq(mSbn)); |
| 1176 | } |
Rohan Shah | dd588c7 | 2018-05-09 20:32:15 -0700 | [diff] [blame] | 1177 | |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 1178 | @Test |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1179 | public void testCloseControls_blockingHelperDismissedIfShown() throws Exception { |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1180 | mNotificationChannel.setImportance(IMPORTANCE_DEFAULT); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1181 | mNotificationInfo.bindNotification( |
| 1182 | mMockPackageManager, |
| 1183 | mMockINotificationManager, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1184 | mVisualStabilityManager, |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1185 | TEST_PACKAGE_NAME, |
| 1186 | mNotificationChannel, |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 1187 | mNotificationChannelSet /* numChannels */, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1188 | mEntry, |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1189 | null /* checkSaveListener */, |
| 1190 | null /* onSettingsClick */, |
| 1191 | null /* onAppSettingsClick */, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 1192 | false /* isNonblockable */, |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1193 | true /* isForBlockingHelper */, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 1194 | true, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1195 | IMPORTANCE_DEFAULT, |
| 1196 | true); |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 1197 | NotificationGuts guts = mock(NotificationGuts.class); |
| 1198 | doCallRealMethod().when(guts).closeControls(anyInt(), anyInt(), anyBoolean(), anyBoolean()); |
| 1199 | mNotificationInfo.setGutsParent(guts); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1200 | |
Evan Laird | 7956fe8 | 2019-05-30 17:14:57 -0400 | [diff] [blame] | 1201 | mNotificationInfo.closeControls(mNotificationInfo, true); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1202 | |
| 1203 | verify(mBlockingHelperManager).dismissCurrentBlockingHelper(); |
| 1204 | } |
| 1205 | |
| 1206 | @Test |
Nadia Benbernou | 3b4a93a | 2019-02-06 16:16:47 -0500 | [diff] [blame] | 1207 | public void testSilentlyChangedCallsUpdateNotificationChannel_blockingHelper() |
| 1208 | throws Exception { |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1209 | mNotificationChannel.setImportance(IMPORTANCE_DEFAULT); |
Nadia Benbernou | 3b4a93a | 2019-02-06 16:16:47 -0500 | [diff] [blame] | 1210 | mNotificationInfo.bindNotification( |
| 1211 | mMockPackageManager, |
| 1212 | mMockINotificationManager, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1213 | mVisualStabilityManager, |
Nadia Benbernou | 3b4a93a | 2019-02-06 16:16:47 -0500 | [diff] [blame] | 1214 | TEST_PACKAGE_NAME, |
| 1215 | mNotificationChannel, |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 1216 | mNotificationChannelSet /* numChannels */, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1217 | mEntry, |
Nadia Benbernou | 3b4a93a | 2019-02-06 16:16:47 -0500 | [diff] [blame] | 1218 | null /* checkSaveListener */, |
| 1219 | null /* onSettingsClick */, |
| 1220 | null /* onAppSettingsClick */, |
| 1221 | true /*provisioned */, |
| 1222 | false /* isNonblockable */, |
| 1223 | true /* isForBlockingHelper */, |
Nadia Benbernou | 3b4a93a | 2019-02-06 16:16:47 -0500 | [diff] [blame] | 1224 | IMPORTANCE_DEFAULT, |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1225 | true); |
Nadia Benbernou | 3b4a93a | 2019-02-06 16:16:47 -0500 | [diff] [blame] | 1226 | |
| 1227 | mNotificationInfo.findViewById(R.id.deliver_silently).performClick(); |
| 1228 | waitForUndoButton(); |
| 1229 | mNotificationInfo.handleCloseControls(true, false); |
| 1230 | |
| 1231 | mTestableLooper.processAllMessages(); |
| 1232 | ArgumentCaptor<NotificationChannel> updated = |
| 1233 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 1234 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 1235 | anyString(), eq(TEST_UID), updated.capture()); |
| 1236 | assertTrue((updated.getValue().getUserLockedFields() |
| 1237 | & USER_LOCKED_IMPORTANCE) != 0); |
| 1238 | assertEquals(IMPORTANCE_LOW, updated.getValue().getImportance()); |
| 1239 | } |
| 1240 | |
| 1241 | @Test |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 1242 | public void testKeepUpdatesNotificationChannel_blockingHelper() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 1243 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1244 | mNotificationInfo.bindNotification( |
| 1245 | mMockPackageManager, |
| 1246 | mMockINotificationManager, |
| 1247 | mVisualStabilityManager, |
| 1248 | TEST_PACKAGE_NAME, |
| 1249 | mNotificationChannel, |
| 1250 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1251 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1252 | null, |
| 1253 | null, |
| 1254 | null, |
| 1255 | true, |
| 1256 | true, |
| 1257 | IMPORTANCE_LOW, |
| 1258 | false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 1259 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 1260 | mNotificationInfo.findViewById(R.id.keep_showing).performClick(); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 1261 | mNotificationInfo.handleCloseControls(true, false); |
| 1262 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 1263 | mTestableLooper.processAllMessages(); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 1264 | ArgumentCaptor<NotificationChannel> updated = |
| 1265 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 1266 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 1267 | anyString(), eq(TEST_UID), updated.capture()); |
| 1268 | assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE)); |
| 1269 | assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance()); |
| 1270 | } |
| 1271 | |
| 1272 | @Test |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 1273 | public void testNoActionsUpdatesNotificationChannel_blockingHelper() throws Exception { |
| 1274 | mNotificationChannel.setImportance(IMPORTANCE_DEFAULT); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1275 | mNotificationInfo.bindNotification( |
| 1276 | mMockPackageManager, |
| 1277 | mMockINotificationManager, |
| 1278 | mVisualStabilityManager, |
| 1279 | TEST_PACKAGE_NAME, |
| 1280 | mNotificationChannel, |
| 1281 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1282 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1283 | null, |
| 1284 | null, |
| 1285 | null, |
| 1286 | true, |
| 1287 | true, |
| 1288 | IMPORTANCE_DEFAULT, |
| 1289 | true); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 1290 | |
| 1291 | mNotificationInfo.handleCloseControls(true, false); |
| 1292 | |
| 1293 | mTestableLooper.processAllMessages(); |
| 1294 | ArgumentCaptor<NotificationChannel> updated = |
| 1295 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 1296 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 1297 | anyString(), eq(TEST_UID), updated.capture()); |
| 1298 | assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE)); |
| 1299 | assertEquals(IMPORTANCE_DEFAULT, mNotificationChannel.getImportance()); |
| 1300 | } |
| 1301 | |
| 1302 | @Test |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 1303 | public void testSilenceCallsUpdateNotificationChannel() throws Exception { |
| 1304 | mNotificationChannel.setImportance(IMPORTANCE_DEFAULT); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1305 | mNotificationInfo.bindNotification( |
| 1306 | mMockPackageManager, |
| 1307 | mMockINotificationManager, |
| 1308 | mVisualStabilityManager, |
| 1309 | TEST_PACKAGE_NAME, |
| 1310 | mNotificationChannel, |
| 1311 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1312 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1313 | null, |
| 1314 | null, |
| 1315 | null, |
| 1316 | true, |
| 1317 | false, |
| 1318 | IMPORTANCE_DEFAULT, |
| 1319 | true); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 1320 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1321 | mNotificationInfo.findViewById(R.id.silence).performClick(); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 1322 | mNotificationInfo.findViewById(R.id.done).performClick(); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 1323 | mNotificationInfo.handleCloseControls(true, false); |
| 1324 | |
| 1325 | mTestableLooper.processAllMessages(); |
| 1326 | ArgumentCaptor<NotificationChannel> updated = |
| 1327 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 1328 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 1329 | anyString(), eq(TEST_UID), updated.capture()); |
| 1330 | assertTrue((updated.getValue().getUserLockedFields() |
| 1331 | & USER_LOCKED_IMPORTANCE) != 0); |
| 1332 | assertEquals(IMPORTANCE_LOW, updated.getValue().getImportance()); |
| 1333 | } |
| 1334 | |
| 1335 | @Test |
| 1336 | public void testUnSilenceCallsUpdateNotificationChannel() throws Exception { |
| 1337 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1338 | mNotificationInfo.bindNotification( |
| 1339 | mMockPackageManager, |
| 1340 | mMockINotificationManager, |
| 1341 | mVisualStabilityManager, |
| 1342 | TEST_PACKAGE_NAME, |
| 1343 | mNotificationChannel, |
| 1344 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1345 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1346 | null, |
| 1347 | null, |
| 1348 | null, |
| 1349 | true, |
| 1350 | false, |
| 1351 | IMPORTANCE_LOW, |
| 1352 | false); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 1353 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1354 | mNotificationInfo.findViewById(R.id.alert).performClick(); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 1355 | mNotificationInfo.findViewById(R.id.done).performClick(); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 1356 | mNotificationInfo.handleCloseControls(true, false); |
| 1357 | |
| 1358 | mTestableLooper.processAllMessages(); |
| 1359 | ArgumentCaptor<NotificationChannel> updated = |
| 1360 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 1361 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 1362 | anyString(), eq(TEST_UID), updated.capture()); |
| 1363 | assertTrue((updated.getValue().getUserLockedFields() |
| 1364 | & USER_LOCKED_IMPORTANCE) != 0); |
Julia Reynolds | 9ae5e64 | 2019-02-06 10:19:22 -0500 | [diff] [blame] | 1365 | assertEquals(IMPORTANCE_DEFAULT, updated.getValue().getImportance()); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | @Test |
| 1369 | public void testSilenceCallsUpdateNotificationChannel_channelImportanceUnspecified() |
| 1370 | throws Exception { |
| 1371 | mNotificationChannel.setImportance(IMPORTANCE_UNSPECIFIED); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1372 | mNotificationInfo.bindNotification( |
| 1373 | mMockPackageManager, |
| 1374 | mMockINotificationManager, |
| 1375 | mVisualStabilityManager, |
| 1376 | TEST_PACKAGE_NAME, |
| 1377 | mNotificationChannel, |
| 1378 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1379 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1380 | null, |
| 1381 | null, |
| 1382 | null, |
| 1383 | true, |
| 1384 | false, |
| 1385 | IMPORTANCE_UNSPECIFIED, |
| 1386 | true); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 1387 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1388 | mNotificationInfo.findViewById(R.id.silence).performClick(); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 1389 | mNotificationInfo.findViewById(R.id.done).performClick(); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 1390 | mNotificationInfo.handleCloseControls(true, false); |
| 1391 | |
| 1392 | mTestableLooper.processAllMessages(); |
| 1393 | ArgumentCaptor<NotificationChannel> updated = |
| 1394 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 1395 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 1396 | anyString(), eq(TEST_UID), updated.capture()); |
| 1397 | assertTrue((updated.getValue().getUserLockedFields() |
| 1398 | & USER_LOCKED_IMPORTANCE) != 0); |
| 1399 | assertEquals(IMPORTANCE_LOW, updated.getValue().getImportance()); |
| 1400 | } |
| 1401 | |
| 1402 | @Test |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1403 | public void testSilenceCallsUpdateNotificationChannel_channelImportanceMin() |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 1404 | throws Exception { |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1405 | mNotificationChannel.setImportance(IMPORTANCE_MIN); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1406 | mNotificationInfo.bindNotification( |
| 1407 | mMockPackageManager, |
| 1408 | mMockINotificationManager, |
| 1409 | mVisualStabilityManager, |
| 1410 | TEST_PACKAGE_NAME, |
| 1411 | mNotificationChannel, |
| 1412 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1413 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1414 | null, |
| 1415 | null, |
| 1416 | null, |
| 1417 | true, |
| 1418 | false, |
| 1419 | IMPORTANCE_MIN, |
| 1420 | false); |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1421 | |
| 1422 | assertEquals(mContext.getString(R.string.inline_done_button), |
| 1423 | ((TextView) mNotificationInfo.findViewById(R.id.done)).getText()); |
| 1424 | mNotificationInfo.findViewById(R.id.silence).performClick(); |
| 1425 | assertEquals(mContext.getString(R.string.inline_done_button), |
| 1426 | ((TextView) mNotificationInfo.findViewById(R.id.done)).getText()); |
| 1427 | mNotificationInfo.findViewById(R.id.done).performClick(); |
| 1428 | mNotificationInfo.handleCloseControls(true, false); |
| 1429 | |
| 1430 | mTestableLooper.processAllMessages(); |
| 1431 | ArgumentCaptor<NotificationChannel> updated = |
| 1432 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 1433 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 1434 | anyString(), eq(TEST_UID), updated.capture()); |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 1435 | assertTrue((updated.getValue().getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0); |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1436 | assertEquals(IMPORTANCE_MIN, updated.getValue().getImportance()); |
| 1437 | } |
| 1438 | |
| 1439 | @Test |
| 1440 | public void testAlertCallsUpdateNotificationChannel_channelImportanceMin() |
| 1441 | throws Exception { |
| 1442 | mNotificationChannel.setImportance(IMPORTANCE_MIN); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1443 | mNotificationInfo.bindNotification( |
| 1444 | mMockPackageManager, |
| 1445 | mMockINotificationManager, |
| 1446 | mVisualStabilityManager, |
| 1447 | TEST_PACKAGE_NAME, |
| 1448 | mNotificationChannel, |
| 1449 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1450 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1451 | null, |
| 1452 | null, |
| 1453 | null, |
| 1454 | true, |
| 1455 | false, |
| 1456 | IMPORTANCE_MIN, |
| 1457 | false); |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1458 | |
| 1459 | assertEquals(mContext.getString(R.string.inline_done_button), |
| 1460 | ((TextView) mNotificationInfo.findViewById(R.id.done)).getText()); |
| 1461 | mNotificationInfo.findViewById(R.id.alert).performClick(); |
| 1462 | assertEquals(mContext.getString(R.string.inline_ok_button), |
| 1463 | ((TextView) mNotificationInfo.findViewById(R.id.done)).getText()); |
| 1464 | mNotificationInfo.findViewById(R.id.done).performClick(); |
| 1465 | mNotificationInfo.handleCloseControls(true, false); |
| 1466 | |
| 1467 | mTestableLooper.processAllMessages(); |
| 1468 | ArgumentCaptor<NotificationChannel> updated = |
| 1469 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 1470 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 1471 | anyString(), eq(TEST_UID), updated.capture()); |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 1472 | assertTrue((updated.getValue().getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0); |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1473 | assertEquals(IMPORTANCE_DEFAULT, updated.getValue().getImportance()); |
| 1474 | } |
| 1475 | |
| 1476 | @Test |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1477 | public void testAdjustImportanceTemporarilyAllowsReordering() throws Exception { |
| 1478 | mNotificationChannel.setImportance(IMPORTANCE_DEFAULT); |
| 1479 | mNotificationInfo.bindNotification( |
| 1480 | mMockPackageManager, |
| 1481 | mMockINotificationManager, |
| 1482 | mVisualStabilityManager, |
| 1483 | TEST_PACKAGE_NAME, |
| 1484 | mNotificationChannel, |
| 1485 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1486 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1487 | null, |
| 1488 | null, |
| 1489 | null, |
| 1490 | true, |
| 1491 | false, |
| 1492 | IMPORTANCE_DEFAULT, |
| 1493 | true); |
| 1494 | |
| 1495 | mNotificationInfo.findViewById(R.id.silence).performClick(); |
| 1496 | mNotificationInfo.findViewById(R.id.done).performClick(); |
| 1497 | mNotificationInfo.handleCloseControls(true, false); |
| 1498 | |
| 1499 | verify(mVisualStabilityManager).temporarilyAllowReordering(); |
| 1500 | } |
| 1501 | |
| 1502 | @Test |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1503 | public void testDoneText() |
| 1504 | throws Exception { |
| 1505 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1506 | mNotificationInfo.bindNotification( |
| 1507 | mMockPackageManager, |
| 1508 | mMockINotificationManager, |
| 1509 | mVisualStabilityManager, |
| 1510 | TEST_PACKAGE_NAME, |
| 1511 | mNotificationChannel, |
| 1512 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1513 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1514 | null, |
| 1515 | null, |
| 1516 | null, |
| 1517 | true, |
| 1518 | false, |
| 1519 | IMPORTANCE_LOW, |
| 1520 | false); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 1521 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1522 | assertEquals(mContext.getString(R.string.inline_done_button), |
| 1523 | ((TextView) mNotificationInfo.findViewById(R.id.done)).getText()); |
| 1524 | mNotificationInfo.findViewById(R.id.alert).performClick(); |
| 1525 | assertEquals(mContext.getString(R.string.inline_ok_button), |
| 1526 | ((TextView) mNotificationInfo.findViewById(R.id.done)).getText()); |
| 1527 | mNotificationInfo.findViewById(R.id.silence).performClick(); |
| 1528 | assertEquals(mContext.getString(R.string.inline_done_button), |
| 1529 | ((TextView) mNotificationInfo.findViewById(R.id.done)).getText()); |
| 1530 | } |
| 1531 | |
| 1532 | @Test |
| 1533 | public void testUnSilenceCallsUpdateNotificationChannel_channelImportanceUnspecified() |
| 1534 | throws Exception { |
| 1535 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1536 | mNotificationInfo.bindNotification( |
| 1537 | mMockPackageManager, |
| 1538 | mMockINotificationManager, |
| 1539 | mVisualStabilityManager, |
| 1540 | TEST_PACKAGE_NAME, |
| 1541 | mNotificationChannel, |
| 1542 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1543 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1544 | null, |
| 1545 | null, |
| 1546 | null, |
| 1547 | true, |
| 1548 | false, |
| 1549 | IMPORTANCE_LOW, |
| 1550 | false); |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1551 | |
| 1552 | mNotificationInfo.findViewById(R.id.alert).performClick(); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 1553 | mNotificationInfo.findViewById(R.id.done).performClick(); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 1554 | mNotificationInfo.handleCloseControls(true, false); |
| 1555 | |
| 1556 | mTestableLooper.processAllMessages(); |
| 1557 | ArgumentCaptor<NotificationChannel> updated = |
| 1558 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 1559 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 1560 | anyString(), eq(TEST_UID), updated.capture()); |
| 1561 | assertTrue((updated.getValue().getUserLockedFields() |
| 1562 | & USER_LOCKED_IMPORTANCE) != 0); |
Julia Reynolds | 9ae5e64 | 2019-02-06 10:19:22 -0500 | [diff] [blame] | 1563 | assertEquals(IMPORTANCE_DEFAULT, updated.getValue().getImportance()); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 1567 | public void testCloseControlsDoesNotUpdateIfSaveIsFalse() throws Exception { |
| 1568 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1569 | mNotificationInfo.bindNotification( |
| 1570 | mMockPackageManager, |
| 1571 | mMockINotificationManager, |
| 1572 | mVisualStabilityManager, |
| 1573 | TEST_PACKAGE_NAME, |
| 1574 | mNotificationChannel, |
| 1575 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1576 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1577 | null, |
| 1578 | null, |
| 1579 | null, |
| 1580 | true, |
| 1581 | false, |
| 1582 | IMPORTANCE_LOW, |
| 1583 | false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 1584 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1585 | mNotificationInfo.findViewById(R.id.alert).performClick(); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 1586 | mNotificationInfo.findViewById(R.id.done).performClick(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 1587 | mNotificationInfo.handleCloseControls(false, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 1588 | |
| 1589 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 1590 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 1591 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 1592 | } |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 1593 | |
| 1594 | @Test |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 1595 | public void testCloseControlsUpdatesWhenCheckSaveListenerUsesCallback() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 1596 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1597 | mNotificationInfo.bindNotification( |
| 1598 | mMockPackageManager, |
| 1599 | mMockINotificationManager, |
| 1600 | mVisualStabilityManager, |
| 1601 | TEST_PACKAGE_NAME, |
| 1602 | mNotificationChannel, |
| 1603 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1604 | mEntry, |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 1605 | (Runnable saveImportance, StatusBarNotification sbn) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 1606 | saveImportance.run(); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1607 | }, |
| 1608 | null, |
| 1609 | null, |
| 1610 | true, |
| 1611 | false, |
| 1612 | IMPORTANCE_LOW, |
| 1613 | false |
Gus Prevas | 5a70a4e | 2018-11-26 17:16:05 -0500 | [diff] [blame] | 1614 | ); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 1615 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1616 | mNotificationInfo.findViewById(R.id.alert).performClick(); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 1617 | mNotificationInfo.findViewById(R.id.done).performClick(); |
Gus Prevas | 533836a | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 1618 | mTestableLooper.processAllMessages(); |
| 1619 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 1620 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
| 1621 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 1622 | mNotificationInfo.handleCloseControls(true, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 1623 | |
| 1624 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 1625 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 1626 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 1627 | } |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 1628 | |
| 1629 | @Test |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 1630 | public void testCloseControls_withoutHittingApply() throws Exception { |
| 1631 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1632 | mNotificationInfo.bindNotification( |
| 1633 | mMockPackageManager, |
| 1634 | mMockINotificationManager, |
| 1635 | mVisualStabilityManager, |
| 1636 | TEST_PACKAGE_NAME, |
| 1637 | mNotificationChannel, |
| 1638 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1639 | mEntry, |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 1640 | (Runnable saveImportance, StatusBarNotification sbn) -> { |
| 1641 | saveImportance.run(); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1642 | }, |
| 1643 | null, |
| 1644 | null, |
| 1645 | true, |
| 1646 | false, |
| 1647 | IMPORTANCE_LOW, |
| 1648 | false |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 1649 | ); |
| 1650 | |
| 1651 | mNotificationInfo.findViewById(R.id.alert).performClick(); |
| 1652 | |
| 1653 | assertFalse(mNotificationInfo.shouldBeSaved()); |
| 1654 | } |
| 1655 | |
| 1656 | @Test |
| 1657 | public void testWillBeRemovedReturnsFalse() throws Exception { |
| 1658 | assertFalse(mNotificationInfo.willBeRemoved()); |
| 1659 | |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1660 | mNotificationInfo.bindNotification( |
| 1661 | mMockPackageManager, |
| 1662 | mMockINotificationManager, |
| 1663 | mVisualStabilityManager, |
| 1664 | TEST_PACKAGE_NAME, |
| 1665 | mNotificationChannel, |
| 1666 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1667 | mEntry, |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 1668 | (Runnable saveImportance, StatusBarNotification sbn) -> { |
| 1669 | saveImportance.run(); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1670 | }, |
| 1671 | null, |
| 1672 | null, |
| 1673 | true, |
| 1674 | false, |
| 1675 | IMPORTANCE_LOW, |
| 1676 | false |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 1677 | ); |
| 1678 | |
Geoffrey Pitsch | 8c8dbde | 2017-04-20 11:44:33 -0400 | [diff] [blame] | 1679 | assertFalse(mNotificationInfo.willBeRemoved()); |
| 1680 | } |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 1681 | |
| 1682 | private Set<NotificationChannel> createMultipleChannelSet(int howMany) { |
| 1683 | Set<NotificationChannel> multiChannelSet = new HashSet<>(); |
| 1684 | for (int i = 0; i < howMany; i++) { |
| 1685 | if (i == 0) { |
| 1686 | multiChannelSet.add(mNotificationChannel); |
| 1687 | continue; |
| 1688 | } |
| 1689 | |
| 1690 | NotificationChannel channel = new NotificationChannel( |
| 1691 | TEST_CHANNEL, TEST_CHANNEL_NAME + i, IMPORTANCE_LOW); |
| 1692 | |
| 1693 | multiChannelSet.add(channel); |
| 1694 | } |
| 1695 | |
| 1696 | return multiChannelSet; |
| 1697 | } |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 1698 | } |