Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [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 |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package com.android.server.notification; |
| 17 | |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 18 | import static android.app.Notification.GROUP_ALERT_ALL; |
| 19 | import static android.app.Notification.GROUP_ALERT_CHILDREN; |
| 20 | import static android.app.Notification.GROUP_ALERT_SUMMARY; |
Julia Reynolds | ca80d16 | 2017-04-23 12:39:32 -0400 | [diff] [blame] | 21 | import static android.app.NotificationManager.IMPORTANCE_HIGH; |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 22 | import static android.app.NotificationManager.IMPORTANCE_LOW; |
Julia Reynolds | 9418756 | 2017-10-10 13:58:49 -0400 | [diff] [blame] | 23 | import static android.app.NotificationManager.IMPORTANCE_MIN; |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 24 | import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_LIGHTS; |
Julia Reynolds | 181ff7c | 2019-10-18 12:16:31 -0400 | [diff] [blame] | 25 | import static android.media.AudioAttributes.USAGE_NOTIFICATION; |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 26 | import static android.media.AudioAttributes.USAGE_NOTIFICATION_RINGTONE; |
Julia Reynolds | ca80d16 | 2017-04-23 12:39:32 -0400 | [diff] [blame] | 27 | |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 28 | import static junit.framework.Assert.assertFalse; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 29 | import static junit.framework.Assert.assertNull; |
| 30 | import static junit.framework.Assert.assertTrue; |
| 31 | |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 32 | import static org.junit.Assert.assertEquals; |
| 33 | import static org.junit.Assert.assertNotEquals; |
Julia Reynolds | 76c096d | 2017-06-19 08:16:04 -0400 | [diff] [blame] | 34 | import static org.mockito.Matchers.any; |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 35 | import static org.mockito.Matchers.anyBoolean; |
| 36 | import static org.mockito.Matchers.anyInt; |
| 37 | import static org.mockito.Matchers.anyObject; |
| 38 | import static org.mockito.Matchers.anyString; |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 39 | import static org.mockito.Matchers.argThat; |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 40 | import static org.mockito.Matchers.eq; |
| 41 | import static org.mockito.Mockito.never; |
Tony Mantler | ab55f0f | 2017-06-16 10:50:00 -0700 | [diff] [blame] | 42 | import static org.mockito.Mockito.spy; |
Jean-Michel Trivi | ea0eb5f | 2017-05-25 18:32:40 -0700 | [diff] [blame] | 43 | import static org.mockito.Mockito.timeout; |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 44 | import static org.mockito.Mockito.times; |
| 45 | import static org.mockito.Mockito.verify; |
| 46 | import static org.mockito.Mockito.when; |
| 47 | |
Tony Mantler | ab55f0f | 2017-06-16 10:50:00 -0700 | [diff] [blame] | 48 | import android.app.ActivityManager; |
| 49 | import android.app.Notification; |
| 50 | import android.app.Notification.Builder; |
| 51 | import android.app.NotificationChannel; |
| 52 | import android.app.NotificationManager; |
Qiao (Adora) Zhang | a9d0bff | 2019-04-15 17:45:43 +0000 | [diff] [blame] | 53 | import android.content.Context; |
Tony Mantler | ab55f0f | 2017-06-16 10:50:00 -0700 | [diff] [blame] | 54 | import android.content.pm.PackageManager; |
| 55 | import android.graphics.Color; |
| 56 | import android.media.AudioAttributes; |
| 57 | import android.media.AudioManager; |
| 58 | import android.net.Uri; |
| 59 | import android.os.Handler; |
| 60 | import android.os.RemoteException; |
| 61 | import android.os.UserHandle; |
| 62 | import android.os.VibrationEffect; |
| 63 | import android.os.Vibrator; |
| 64 | import android.provider.Settings; |
Julia Reynolds | db7081e | 2019-01-03 14:35:38 -0500 | [diff] [blame] | 65 | import android.service.notification.NotificationListenerService; |
Tony Mantler | ab55f0f | 2017-06-16 10:50:00 -0700 | [diff] [blame] | 66 | import android.service.notification.StatusBarNotification; |
Tony Mantler | ab55f0f | 2017-06-16 10:50:00 -0700 | [diff] [blame] | 67 | import android.test.suitebuilder.annotation.SmallTest; |
Julia Reynolds | 9418756 | 2017-10-10 13:58:49 -0400 | [diff] [blame] | 68 | import android.view.accessibility.AccessibilityEvent; |
| 69 | import android.view.accessibility.AccessibilityManager; |
| 70 | import android.view.accessibility.IAccessibilityManager; |
| 71 | import android.view.accessibility.IAccessibilityManagerClient; |
Tony Mantler | ab55f0f | 2017-06-16 10:50:00 -0700 | [diff] [blame] | 72 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 73 | import androidx.test.runner.AndroidJUnit4; |
| 74 | |
Julia Reynolds | 9418756 | 2017-10-10 13:58:49 -0400 | [diff] [blame] | 75 | import com.android.internal.util.IntPair; |
Jason Monk | 74f5e36 | 2017-12-06 08:56:33 -0500 | [diff] [blame] | 76 | import com.android.server.UiServiceTestCase; |
Tony Mantler | ab55f0f | 2017-06-16 10:50:00 -0700 | [diff] [blame] | 77 | import com.android.server.lights.Light; |
| 78 | |
| 79 | import org.junit.Before; |
| 80 | import org.junit.Test; |
| 81 | import org.junit.runner.RunWith; |
| 82 | import org.mockito.ArgumentMatcher; |
| 83 | import org.mockito.Mock; |
| 84 | import org.mockito.Mockito; |
| 85 | import org.mockito.MockitoAnnotations; |
| 86 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 87 | @SmallTest |
| 88 | @RunWith(AndroidJUnit4.class) |
Jason Monk | 74f5e36 | 2017-12-06 08:56:33 -0500 | [diff] [blame] | 89 | public class BuzzBeepBlinkTest extends UiServiceTestCase { |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 90 | |
| 91 | @Mock AudioManager mAudioManager; |
| 92 | @Mock Vibrator mVibrator; |
| 93 | @Mock android.media.IRingtonePlayer mRingtonePlayer; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 94 | @Mock Light mLight; |
Julia Reynolds | eb3dca7 | 2017-07-11 10:39:58 -0400 | [diff] [blame] | 95 | @Mock |
| 96 | NotificationManagerService.WorkerHandler mHandler; |
Julia Reynolds | 76c096d | 2017-06-19 08:16:04 -0400 | [diff] [blame] | 97 | @Mock |
| 98 | NotificationUsageStats mUsageStats; |
Julia Reynolds | 9418756 | 2017-10-10 13:58:49 -0400 | [diff] [blame] | 99 | @Mock |
| 100 | IAccessibilityManager mAccessibilityService; |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 101 | |
| 102 | private NotificationManagerService mService; |
| 103 | private String mPkg = "com.android.server.notification"; |
| 104 | private int mId = 1001; |
| 105 | private int mOtherId = 1002; |
| 106 | private String mTag = null; |
| 107 | private int mUid = 1000; |
| 108 | private int mPid = 2000; |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 109 | private android.os.UserHandle mUser = UserHandle.of(ActivityManager.getCurrentUser()); |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 110 | private NotificationChannel mChannel; |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 111 | |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 112 | private VibrateRepeatMatcher mVibrateOnceMatcher = new VibrateRepeatMatcher(-1); |
| 113 | private VibrateRepeatMatcher mVibrateLoopMatcher = new VibrateRepeatMatcher(0); |
| 114 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 115 | private static final long[] CUSTOM_VIBRATION = new long[] { |
| 116 | 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, |
| 117 | 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, |
| 118 | 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400 }; |
| 119 | private static final Uri CUSTOM_SOUND = Settings.System.DEFAULT_ALARM_ALERT_URI; |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 120 | private static final AudioAttributes CUSTOM_ATTRIBUTES = new AudioAttributes.Builder() |
| 121 | .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN) |
Julia Reynolds | db7081e | 2019-01-03 14:35:38 -0500 | [diff] [blame] | 122 | .setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION) |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 123 | .build(); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 124 | private static final int CUSTOM_LIGHT_COLOR = Color.BLACK; |
| 125 | private static final int CUSTOM_LIGHT_ON = 10000; |
| 126 | private static final int CUSTOM_LIGHT_OFF = 10000; |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 127 | private static final long[] FALLBACK_VIBRATION_PATTERN = new long[] {100, 100, 100}; |
| 128 | private static final VibrationEffect FALLBACK_VIBRATION = |
| 129 | VibrationEffect.createWaveform(FALLBACK_VIBRATION_PATTERN, -1); |
Jean-Michel Trivi | ea0eb5f | 2017-05-25 18:32:40 -0700 | [diff] [blame] | 130 | private static final int MAX_VIBRATION_DELAY = 1000; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 131 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 132 | @Before |
Julia Reynolds | 9418756 | 2017-10-10 13:58:49 -0400 | [diff] [blame] | 133 | public void setUp() throws Exception { |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 134 | MockitoAnnotations.initMocks(this); |
| 135 | |
| 136 | when(mAudioManager.isAudioFocusExclusive()).thenReturn(false); |
| 137 | when(mAudioManager.getRingtonePlayer()).thenReturn(mRingtonePlayer); |
| 138 | when(mAudioManager.getStreamVolume(anyInt())).thenReturn(10); |
| 139 | when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL); |
Julia Reynolds | 76c096d | 2017-06-19 08:16:04 -0400 | [diff] [blame] | 140 | when(mUsageStats.isAlertRateLimited(any())).thenReturn(false); |
| 141 | |
Julia Reynolds | 9418756 | 2017-10-10 13:58:49 -0400 | [diff] [blame] | 142 | long serviceReturnValue = IntPair.of( |
| 143 | AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED, |
| 144 | AccessibilityEvent.TYPES_ALL_MASK); |
| 145 | when(mAccessibilityService.addClient(any(), anyInt())).thenReturn(serviceReturnValue); |
| 146 | AccessibilityManager accessibilityManager = |
| 147 | new AccessibilityManager(Handler.getMain(), mAccessibilityService, 0); |
| 148 | verify(mAccessibilityService).addClient(any(IAccessibilityManagerClient.class), anyInt()); |
| 149 | assertTrue(accessibilityManager.isEnabled()); |
| 150 | |
Qiao (Adora) Zhang | a9d0bff | 2019-04-15 17:45:43 +0000 | [diff] [blame] | 151 | mService = spy(new NotificationManagerService(getContext())); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 152 | mService.setAudioManager(mAudioManager); |
| 153 | mService.setVibrator(mVibrator); |
| 154 | mService.setSystemReady(true); |
| 155 | mService.setHandler(mHandler); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 156 | mService.setLights(mLight); |
| 157 | mService.setScreenOn(false); |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 158 | mService.setFallbackVibrationPattern(FALLBACK_VIBRATION_PATTERN); |
Julia Reynolds | 76c096d | 2017-06-19 08:16:04 -0400 | [diff] [blame] | 159 | mService.setUsageStats(mUsageStats); |
Julia Reynolds | 9418756 | 2017-10-10 13:58:49 -0400 | [diff] [blame] | 160 | mService.setAccessibilityManager(accessibilityManager); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 161 | mService.mScreenOn = false; |
Eric Laurent | 7412abc | 2019-07-12 18:26:29 -0700 | [diff] [blame] | 162 | mService.mInCallStateOffHook = false; |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 163 | mService.mNotificationPulseEnabled = true; |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 164 | |
| 165 | mChannel = new NotificationChannel("test", "test", IMPORTANCE_HIGH); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | // |
| 169 | // Convenience functions for creating notification records |
| 170 | // |
| 171 | |
| 172 | private NotificationRecord getNoisyOtherNotification() { |
| 173 | return getNotificationRecord(mOtherId, false /* insistent */, false /* once */, |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 174 | true /* noisy */, true /* buzzy*/, false /* lights */); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | private NotificationRecord getBeepyNotification() { |
| 178 | return getNotificationRecord(mId, false /* insistent */, false /* once */, |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 179 | true /* noisy */, false /* buzzy*/, false /* lights */); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 180 | } |
| 181 | |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 182 | private NotificationRecord getBeepyOtherNotification() { |
| 183 | return getNotificationRecord(mOtherId, false /* insistent */, false /* once */, |
| 184 | true /* noisy */, false /* buzzy*/, false /* lights */); |
| 185 | } |
| 186 | |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 187 | private NotificationRecord getBeepyOnceNotification() { |
| 188 | return getNotificationRecord(mId, false /* insistent */, true /* once */, |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 189 | true /* noisy */, false /* buzzy*/, false /* lights */); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | private NotificationRecord getQuietNotification() { |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 193 | return getNotificationRecord(mId, false /* insistent */, true /* once */, |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 194 | false /* noisy */, false /* buzzy*/, false /* lights */); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | private NotificationRecord getQuietOtherNotification() { |
| 198 | return getNotificationRecord(mOtherId, false /* insistent */, false /* once */, |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 199 | false /* noisy */, false /* buzzy*/, false /* lights */); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | private NotificationRecord getQuietOnceNotification() { |
| 203 | return getNotificationRecord(mId, false /* insistent */, true /* once */, |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 204 | false /* noisy */, false /* buzzy*/, false /* lights */); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | private NotificationRecord getInsistentBeepyNotification() { |
| 208 | return getNotificationRecord(mId, true /* insistent */, false /* once */, |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 209 | true /* noisy */, false /* buzzy*/, false /* lights */); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 210 | } |
| 211 | |
Tyler Gunn | 48f8627 | 2018-07-03 12:38:49 -0700 | [diff] [blame] | 212 | private NotificationRecord getInsistentBeepyOnceNotification() { |
| 213 | return getNotificationRecord(mId, true /* insistent */, true /* once */, |
| 214 | true /* noisy */, false /* buzzy*/, false /* lights */); |
| 215 | } |
| 216 | |
Tony Mantler | ab55f0f | 2017-06-16 10:50:00 -0700 | [diff] [blame] | 217 | private NotificationRecord getInsistentBeepyLeanbackNotification() { |
| 218 | return getLeanbackNotificationRecord(mId, true /* insistent */, false /* once */, |
| 219 | true /* noisy */, false /* buzzy*/, false /* lights */); |
| 220 | } |
| 221 | |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 222 | private NotificationRecord getBuzzyNotification() { |
| 223 | return getNotificationRecord(mId, false /* insistent */, false /* once */, |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 224 | false /* noisy */, true /* buzzy*/, false /* lights */); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 225 | } |
| 226 | |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 227 | private NotificationRecord getBuzzyOtherNotification() { |
| 228 | return getNotificationRecord(mOtherId, false /* insistent */, false /* once */, |
| 229 | false /* noisy */, true /* buzzy*/, false /* lights */); |
| 230 | } |
| 231 | |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 232 | private NotificationRecord getBuzzyOnceNotification() { |
| 233 | return getNotificationRecord(mId, false /* insistent */, true /* once */, |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 234 | false /* noisy */, true /* buzzy*/, false /* lights */); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | private NotificationRecord getInsistentBuzzyNotification() { |
| 238 | return getNotificationRecord(mId, true /* insistent */, false /* once */, |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 239 | false /* noisy */, true /* buzzy*/, false /* lights */); |
| 240 | } |
| 241 | |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 242 | private NotificationRecord getBuzzyBeepyNotification() { |
| 243 | return getNotificationRecord(mId, false /* insistent */, false /* once */, |
| 244 | true /* noisy */, true /* buzzy*/, false /* lights */); |
| 245 | } |
| 246 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 247 | private NotificationRecord getLightsNotification() { |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 248 | return getNotificationRecord(mId, false /* insistent */, false /* once */, |
| 249 | false /* noisy */, false /* buzzy*/, true /* lights */); |
| 250 | } |
| 251 | |
| 252 | private NotificationRecord getLightsOnceNotification() { |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 253 | return getNotificationRecord(mId, false /* insistent */, true /* once */, |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 254 | false /* noisy */, false /* buzzy*/, true /* lights */); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 255 | } |
| 256 | |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 257 | private NotificationRecord getCallRecord(int id, NotificationChannel channel, boolean looping) { |
| 258 | final Builder builder = new Builder(getContext()) |
| 259 | .setContentTitle("foo") |
| 260 | .setSmallIcon(android.R.drawable.sym_def_app_icon) |
| 261 | .setPriority(Notification.PRIORITY_HIGH); |
| 262 | Notification n = builder.build(); |
| 263 | if (looping) { |
| 264 | n.flags |= Notification.FLAG_INSISTENT; |
| 265 | } |
| 266 | StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, id, mTag, mUid, |
| 267 | mPid, n, mUser, null, System.currentTimeMillis()); |
| 268 | NotificationRecord r = new NotificationRecord(getContext(), sbn, channel); |
| 269 | mService.addNotification(r); |
| 270 | |
| 271 | return r; |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | private NotificationRecord getNotificationRecord(int id, boolean insistent, boolean once, |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 275 | boolean noisy, boolean buzzy, boolean lights) { |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 276 | return getNotificationRecord(id, insistent, once, noisy, buzzy, lights, buzzy, noisy, |
| 277 | lights, null, Notification.GROUP_ALERT_ALL, false); |
Tony Mantler | ab55f0f | 2017-06-16 10:50:00 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 280 | private NotificationRecord getLeanbackNotificationRecord(int id, boolean insistent, |
| 281 | boolean once, |
Tony Mantler | ab55f0f | 2017-06-16 10:50:00 -0700 | [diff] [blame] | 282 | boolean noisy, boolean buzzy, boolean lights) { |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 283 | return getNotificationRecord(id, insistent, once, noisy, buzzy, lights, true, true, |
| 284 | true, |
Tony Mantler | ab55f0f | 2017-06-16 10:50:00 -0700 | [diff] [blame] | 285 | null, Notification.GROUP_ALERT_ALL, true); |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | private NotificationRecord getBeepyNotificationRecord(String groupKey, int groupAlertBehavior) { |
| 289 | return getNotificationRecord(mId, false, false, true, false, false, true, true, true, |
Tony Mantler | ab55f0f | 2017-06-16 10:50:00 -0700 | [diff] [blame] | 290 | groupKey, groupAlertBehavior, false); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 291 | } |
| 292 | |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 293 | private NotificationRecord getLightsNotificationRecord(String groupKey, |
| 294 | int groupAlertBehavior) { |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 295 | return getNotificationRecord(mId, false, false, false, false, true /*lights*/, true, |
| 296 | true, true, groupKey, groupAlertBehavior, false); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 297 | } |
| 298 | |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 299 | private NotificationRecord getNotificationRecord(int id, |
| 300 | boolean insistent, boolean once, |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 301 | boolean noisy, boolean buzzy, boolean lights, boolean defaultVibration, |
Tony Mantler | ab55f0f | 2017-06-16 10:50:00 -0700 | [diff] [blame] | 302 | boolean defaultSound, boolean defaultLights, String groupKey, int groupAlertBehavior, |
| 303 | boolean isLeanback) { |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 304 | |
Qiao (Adora) Zhang | a9d0bff | 2019-04-15 17:45:43 +0000 | [diff] [blame] | 305 | final Builder builder = new Builder(getContext()) |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 306 | .setContentTitle("foo") |
| 307 | .setSmallIcon(android.R.drawable.sym_def_app_icon) |
| 308 | .setPriority(Notification.PRIORITY_HIGH) |
| 309 | .setOnlyAlertOnce(once); |
| 310 | |
| 311 | int defaults = 0; |
| 312 | if (noisy) { |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 313 | if (defaultSound) { |
| 314 | defaults |= Notification.DEFAULT_SOUND; |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 315 | mChannel.setSound(Settings.System.DEFAULT_NOTIFICATION_URI, |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 316 | Notification.AUDIO_ATTRIBUTES_DEFAULT); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 317 | } else { |
| 318 | builder.setSound(CUSTOM_SOUND); |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 319 | mChannel.setSound(CUSTOM_SOUND, CUSTOM_ATTRIBUTES); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 320 | } |
Julia Reynolds | 184b86d | 2017-04-12 13:27:58 -0400 | [diff] [blame] | 321 | } else { |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 322 | mChannel.setSound(null, null); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 323 | } |
| 324 | if (buzzy) { |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 325 | if (defaultVibration) { |
| 326 | defaults |= Notification.DEFAULT_VIBRATE; |
| 327 | } else { |
| 328 | builder.setVibrate(CUSTOM_VIBRATION); |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 329 | mChannel.setVibrationPattern(CUSTOM_VIBRATION); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 330 | } |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 331 | mChannel.enableVibration(true); |
| 332 | } else { |
| 333 | mChannel.setVibrationPattern(null); |
| 334 | mChannel.enableVibration(false); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 335 | } |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 336 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 337 | if (lights) { |
| 338 | if (defaultLights) { |
| 339 | defaults |= Notification.DEFAULT_LIGHTS; |
| 340 | } else { |
| 341 | builder.setLights(CUSTOM_LIGHT_COLOR, CUSTOM_LIGHT_ON, CUSTOM_LIGHT_OFF); |
| 342 | } |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 343 | mChannel.enableLights(true); |
| 344 | } else { |
| 345 | mChannel.enableLights(false); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 346 | } |
| 347 | builder.setDefaults(defaults); |
| 348 | |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 349 | builder.setGroup(groupKey); |
| 350 | builder.setGroupAlertBehavior(groupAlertBehavior); |
| 351 | |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 352 | Notification n = builder.build(); |
| 353 | if (insistent) { |
| 354 | n.flags |= Notification.FLAG_INSISTENT; |
| 355 | } |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 356 | |
Qiao (Adora) Zhang | a9d0bff | 2019-04-15 17:45:43 +0000 | [diff] [blame] | 357 | Context context = spy(getContext()); |
| 358 | PackageManager packageManager = spy(context.getPackageManager()); |
| 359 | when(context.getPackageManager()).thenReturn(packageManager); |
Tony Mantler | ab55f0f | 2017-06-16 10:50:00 -0700 | [diff] [blame] | 360 | when(packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)) |
| 361 | .thenReturn(isLeanback); |
| 362 | |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 363 | StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, id, mTag, mUid, |
Julia Reynolds | 423b9fc | 2016-11-09 09:51:08 -0500 | [diff] [blame] | 364 | mPid, n, mUser, null, System.currentTimeMillis()); |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 365 | NotificationRecord r = new NotificationRecord(context, sbn, mChannel); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 366 | mService.addNotification(r); |
| 367 | return r; |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | // |
| 371 | // Convenience functions for interacting with mocks |
| 372 | // |
| 373 | |
| 374 | private void verifyNeverBeep() throws RemoteException { |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 375 | verify(mRingtonePlayer, never()).playAsync(any(), any(), anyBoolean(), any()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 376 | } |
| 377 | |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 378 | private void verifyBeepUnlooped() throws RemoteException { |
| 379 | verify(mRingtonePlayer, times(1)).playAsync(any(), any(), eq(false), any()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 380 | } |
| 381 | |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 382 | private void verifyBeepLooped() throws RemoteException { |
| 383 | verify(mRingtonePlayer, times(1)).playAsync(any(), any(), eq(true), any()); |
| 384 | } |
| 385 | |
| 386 | private void verifyBeep(int times) throws RemoteException { |
| 387 | verify(mRingtonePlayer, times(times)).playAsync(any(), any(), anyBoolean(), any()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | private void verifyNeverStopAudio() throws RemoteException { |
| 391 | verify(mRingtonePlayer, never()).stopAsync(); |
| 392 | } |
| 393 | |
| 394 | private void verifyStopAudio() throws RemoteException { |
| 395 | verify(mRingtonePlayer, times(1)).stopAsync(); |
| 396 | } |
| 397 | |
| 398 | private void verifyNeverVibrate() { |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 399 | verify(mVibrator, never()).vibrate(anyInt(), anyString(), any(), anyString(), any()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | private void verifyVibrate() { |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 403 | verify(mVibrator, times(1)).vibrate(anyInt(), anyString(), argThat(mVibrateOnceMatcher), |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 404 | anyString(), any()); |
| 405 | } |
| 406 | |
| 407 | private void verifyVibrate(int times) { |
| 408 | verify(mVibrator, times(times)).vibrate(anyInt(), anyString(), any(), anyString(), any()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | private void verifyVibrateLooped() { |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 412 | verify(mVibrator, times(1)).vibrate(anyInt(), anyString(), argThat(mVibrateLoopMatcher), |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 413 | anyString(), any()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 414 | } |
| 415 | |
Jean-Michel Trivi | ea0eb5f | 2017-05-25 18:32:40 -0700 | [diff] [blame] | 416 | private void verifyDelayedVibrateLooped() { |
| 417 | verify(mVibrator, timeout(MAX_VIBRATION_DELAY).times(1)).vibrate(anyInt(), anyString(), |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 418 | argThat(mVibrateLoopMatcher), anyString(), any()); |
| 419 | } |
| 420 | |
| 421 | private void verifyDelayedVibrate() { |
| 422 | verify(mVibrator, timeout(MAX_VIBRATION_DELAY).times(1)).vibrate(anyInt(), anyString(), |
| 423 | argThat(mVibrateOnceMatcher), anyString(), any()); |
Jean-Michel Trivi | ea0eb5f | 2017-05-25 18:32:40 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 426 | private void verifyStopVibrate() { |
| 427 | verify(mVibrator, times(1)).cancel(); |
| 428 | } |
| 429 | |
| 430 | private void verifyNeverStopVibrate() throws RemoteException { |
| 431 | verify(mVibrator, never()).cancel(); |
| 432 | } |
| 433 | |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 434 | private void verifyNeverLights() { |
| 435 | verify(mLight, never()).setFlashing(anyInt(), anyInt(), anyInt(), anyInt()); |
| 436 | } |
| 437 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 438 | private void verifyLights() { |
Julia Reynolds | 033a412 | 2017-01-31 16:50:38 -0500 | [diff] [blame] | 439 | verify(mLight, times(1)).setFlashing(anyInt(), anyInt(), anyInt(), anyInt()); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 440 | } |
| 441 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 442 | // |
| 443 | // Tests |
| 444 | // |
| 445 | |
| 446 | @Test |
| 447 | public void testLights() throws Exception { |
| 448 | NotificationRecord r = getLightsNotification(); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 449 | r.setSystemImportance(NotificationManager.IMPORTANCE_DEFAULT); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 450 | |
| 451 | mService.buzzBeepBlinkLocked(r); |
| 452 | |
| 453 | verifyLights(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 454 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 455 | assertEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 456 | } |
| 457 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 458 | @Test |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 459 | public void testBeep() throws Exception { |
| 460 | NotificationRecord r = getBeepyNotification(); |
| 461 | |
| 462 | mService.buzzBeepBlinkLocked(r); |
| 463 | |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 464 | verifyBeepUnlooped(); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 465 | verifyNeverVibrate(); |
Julia Reynolds | 9418756 | 2017-10-10 13:58:49 -0400 | [diff] [blame] | 466 | verify(mAccessibilityService, times(1)).sendAccessibilityEvent(any(), anyInt()); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 467 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 468 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 469 | } |
| 470 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 471 | @Test |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 472 | public void testBeepInsistently() throws Exception { |
| 473 | NotificationRecord r = getInsistentBeepyNotification(); |
| 474 | |
| 475 | mService.buzzBeepBlinkLocked(r); |
| 476 | |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 477 | verifyBeepLooped(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 478 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 479 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 480 | } |
| 481 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 482 | @Test |
Tony Mantler | ab55f0f | 2017-06-16 10:50:00 -0700 | [diff] [blame] | 483 | public void testNoLeanbackBeep() throws Exception { |
| 484 | NotificationRecord r = getInsistentBeepyLeanbackNotification(); |
| 485 | |
| 486 | mService.buzzBeepBlinkLocked(r); |
| 487 | |
| 488 | verifyNeverBeep(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 489 | assertFalse(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 490 | assertEquals(-1, r.getLastAudiblyAlertedMs()); |
Tony Mantler | ab55f0f | 2017-06-16 10:50:00 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | @Test |
Qiao (Adora) Zhang | 47b553c | 2019-04-15 20:42:57 +0000 | [diff] [blame] | 494 | public void testNoBeepForAutomotiveIfEffectsDisabled() throws Exception { |
Adora Zhang | 963328f | 2018-11-15 18:17:19 -0800 | [diff] [blame] | 495 | mService.setIsAutomotive(true); |
Qiao (Adora) Zhang | 47b553c | 2019-04-15 20:42:57 +0000 | [diff] [blame] | 496 | mService.setNotificationEffectsEnabledForAutomotive(false); |
| 497 | |
| 498 | NotificationRecord r = getBeepyNotification(); |
| 499 | r.setSystemImportance(NotificationManager.IMPORTANCE_HIGH); |
| 500 | |
| 501 | mService.buzzBeepBlinkLocked(r); |
| 502 | |
| 503 | verifyNeverBeep(); |
| 504 | assertFalse(r.isInterruptive()); |
| 505 | } |
| 506 | |
| 507 | @Test |
| 508 | public void testNoBeepForImportanceDefaultInAutomotiveIfEffectsEnabled() throws Exception { |
| 509 | mService.setIsAutomotive(true); |
| 510 | mService.setNotificationEffectsEnabledForAutomotive(true); |
Adora Zhang | 963328f | 2018-11-15 18:17:19 -0800 | [diff] [blame] | 511 | |
| 512 | NotificationRecord r = getBeepyNotification(); |
| 513 | r.setSystemImportance(NotificationManager.IMPORTANCE_DEFAULT); |
| 514 | |
| 515 | mService.buzzBeepBlinkLocked(r); |
| 516 | |
| 517 | verifyNeverBeep(); |
| 518 | assertFalse(r.isInterruptive()); |
| 519 | } |
| 520 | |
| 521 | @Test |
Qiao (Adora) Zhang | 47b553c | 2019-04-15 20:42:57 +0000 | [diff] [blame] | 522 | public void testBeepForImportanceHighInAutomotiveIfEffectsEnabled() throws Exception { |
Adora Zhang | 963328f | 2018-11-15 18:17:19 -0800 | [diff] [blame] | 523 | mService.setIsAutomotive(true); |
Qiao (Adora) Zhang | 47b553c | 2019-04-15 20:42:57 +0000 | [diff] [blame] | 524 | mService.setNotificationEffectsEnabledForAutomotive(true); |
Adora Zhang | 963328f | 2018-11-15 18:17:19 -0800 | [diff] [blame] | 525 | |
| 526 | NotificationRecord r = getBeepyNotification(); |
Qiao (Adora) Zhang | 47b553c | 2019-04-15 20:42:57 +0000 | [diff] [blame] | 527 | r.setSystemImportance(NotificationManager.IMPORTANCE_HIGH); |
Adora Zhang | 963328f | 2018-11-15 18:17:19 -0800 | [diff] [blame] | 528 | |
| 529 | mService.buzzBeepBlinkLocked(r); |
| 530 | |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 531 | verifyBeepUnlooped(); |
Adora Zhang | 963328f | 2018-11-15 18:17:19 -0800 | [diff] [blame] | 532 | assertTrue(r.isInterruptive()); |
| 533 | } |
| 534 | |
| 535 | @Test |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 536 | public void testNoInterruptionForMin() throws Exception { |
| 537 | NotificationRecord r = getBeepyNotification(); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 538 | r.setSystemImportance(NotificationManager.IMPORTANCE_MIN); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 539 | |
| 540 | mService.buzzBeepBlinkLocked(r); |
| 541 | |
| 542 | verifyNeverBeep(); |
| 543 | verifyNeverVibrate(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 544 | assertFalse(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 545 | assertEquals(-1, r.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 546 | } |
| 547 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 548 | @Test |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 549 | public void testNoInterruptionForIntercepted() throws Exception { |
| 550 | NotificationRecord r = getBeepyNotification(); |
| 551 | r.setIntercepted(true); |
| 552 | |
| 553 | mService.buzzBeepBlinkLocked(r); |
| 554 | |
| 555 | verifyNeverBeep(); |
| 556 | verifyNeverVibrate(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 557 | assertFalse(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 558 | assertEquals(-1, r.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 559 | } |
| 560 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 561 | @Test |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 562 | public void testBeepTwice() throws Exception { |
| 563 | NotificationRecord r = getBeepyNotification(); |
| 564 | |
| 565 | // set up internal state |
| 566 | mService.buzzBeepBlinkLocked(r); |
| 567 | Mockito.reset(mRingtonePlayer); |
| 568 | |
| 569 | // update should beep |
| 570 | r.isUpdate = true; |
| 571 | mService.buzzBeepBlinkLocked(r); |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 572 | verifyBeepUnlooped(); |
Julia Reynolds | 9418756 | 2017-10-10 13:58:49 -0400 | [diff] [blame] | 573 | verify(mAccessibilityService, times(2)).sendAccessibilityEvent(any(), anyInt()); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 574 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 575 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 576 | } |
| 577 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 578 | @Test |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 579 | public void testHonorAlertOnlyOnceForBeep() throws Exception { |
| 580 | NotificationRecord r = getBeepyNotification(); |
| 581 | NotificationRecord s = getBeepyOnceNotification(); |
| 582 | s.isUpdate = true; |
| 583 | |
| 584 | // set up internal state |
| 585 | mService.buzzBeepBlinkLocked(r); |
| 586 | Mockito.reset(mRingtonePlayer); |
| 587 | |
| 588 | // update should not beep |
| 589 | mService.buzzBeepBlinkLocked(s); |
| 590 | verifyNeverBeep(); |
Julia Reynolds | 9418756 | 2017-10-10 13:58:49 -0400 | [diff] [blame] | 591 | verify(mAccessibilityService, times(1)).sendAccessibilityEvent(any(), anyInt()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 592 | } |
| 593 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 594 | @Test |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 595 | public void testNoisyUpdateDoesNotCancelAudio() throws Exception { |
| 596 | NotificationRecord r = getBeepyNotification(); |
| 597 | |
| 598 | mService.buzzBeepBlinkLocked(r); |
| 599 | r.isUpdate = true; |
| 600 | mService.buzzBeepBlinkLocked(r); |
| 601 | |
| 602 | verifyNeverStopAudio(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 603 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 604 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 605 | } |
| 606 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 607 | @Test |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 608 | public void testNoisyOnceUpdateDoesNotCancelAudio() throws Exception { |
| 609 | NotificationRecord r = getBeepyNotification(); |
| 610 | NotificationRecord s = getBeepyOnceNotification(); |
| 611 | s.isUpdate = true; |
| 612 | |
| 613 | mService.buzzBeepBlinkLocked(r); |
| 614 | mService.buzzBeepBlinkLocked(s); |
| 615 | |
| 616 | verifyNeverStopAudio(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 617 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 618 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 619 | assertFalse(s.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 620 | assertEquals(-1, s.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 621 | } |
| 622 | |
Tyler Gunn | 48f8627 | 2018-07-03 12:38:49 -0700 | [diff] [blame] | 623 | /** |
| 624 | * Tests the case where the user re-posts a {@link Notification} with looping sound where |
| 625 | * {@link Notification.Builder#setOnlyAlertOnce(true)} has been called. This should silence |
| 626 | * the sound associated with the notification. |
| 627 | * @throws Exception |
| 628 | */ |
| 629 | @Test |
| 630 | public void testNoisyOnceUpdateDoesCancelAudio() throws Exception { |
| 631 | NotificationRecord r = getInsistentBeepyNotification(); |
| 632 | NotificationRecord s = getInsistentBeepyOnceNotification(); |
| 633 | s.isUpdate = true; |
| 634 | |
| 635 | mService.buzzBeepBlinkLocked(r); |
| 636 | mService.buzzBeepBlinkLocked(s); |
| 637 | |
| 638 | verifyStopAudio(); |
| 639 | } |
| 640 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 641 | @Test |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 642 | public void testQuietUpdateDoesNotCancelAudioFromOther() throws Exception { |
| 643 | NotificationRecord r = getBeepyNotification(); |
| 644 | NotificationRecord s = getQuietNotification(); |
| 645 | s.isUpdate = true; |
| 646 | NotificationRecord other = getNoisyOtherNotification(); |
| 647 | |
| 648 | // set up internal state |
| 649 | mService.buzzBeepBlinkLocked(r); |
| 650 | mService.buzzBeepBlinkLocked(other); // this takes the audio stream |
| 651 | Mockito.reset(mRingtonePlayer); |
| 652 | |
| 653 | // should not stop noise, since we no longer own it |
| 654 | mService.buzzBeepBlinkLocked(s); // this no longer owns the stream |
| 655 | verifyNeverStopAudio(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 656 | assertTrue(other.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 657 | assertNotEquals(-1, other.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 658 | } |
| 659 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 660 | @Test |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 661 | public void testQuietInterloperDoesNotCancelAudio() throws Exception { |
| 662 | NotificationRecord r = getBeepyNotification(); |
| 663 | NotificationRecord other = getQuietOtherNotification(); |
| 664 | |
| 665 | // set up internal state |
| 666 | mService.buzzBeepBlinkLocked(r); |
| 667 | Mockito.reset(mRingtonePlayer); |
| 668 | |
| 669 | // should not stop noise, since it does not own it |
| 670 | mService.buzzBeepBlinkLocked(other); |
| 671 | verifyNeverStopAudio(); |
| 672 | } |
| 673 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 674 | @Test |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 675 | public void testQuietUpdateCancelsAudio() throws Exception { |
| 676 | NotificationRecord r = getBeepyNotification(); |
| 677 | NotificationRecord s = getQuietNotification(); |
| 678 | s.isUpdate = true; |
| 679 | |
| 680 | // set up internal state |
| 681 | mService.buzzBeepBlinkLocked(r); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 682 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 683 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 684 | Mockito.reset(mRingtonePlayer); |
| 685 | |
| 686 | // quiet update should stop making noise |
| 687 | mService.buzzBeepBlinkLocked(s); |
| 688 | verifyStopAudio(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 689 | assertFalse(s.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 690 | assertEquals(-1, s.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 691 | } |
| 692 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 693 | @Test |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 694 | public void testQuietOnceUpdateCancelsAudio() throws Exception { |
| 695 | NotificationRecord r = getBeepyNotification(); |
| 696 | NotificationRecord s = getQuietOnceNotification(); |
| 697 | s.isUpdate = true; |
| 698 | |
| 699 | // set up internal state |
| 700 | mService.buzzBeepBlinkLocked(r); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 701 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 702 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 703 | Mockito.reset(mRingtonePlayer); |
| 704 | |
| 705 | // stop making noise - this is a weird corner case, but quiet should override once |
| 706 | mService.buzzBeepBlinkLocked(s); |
| 707 | verifyStopAudio(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 708 | assertFalse(s.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 709 | assertEquals(-1, s.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 710 | } |
| 711 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 712 | @Test |
Beverly | 5d463b6 | 2017-07-26 14:13:40 -0400 | [diff] [blame] | 713 | public void testInCallNotification() throws Exception { |
| 714 | NotificationRecord r = getBeepyNotification(); |
| 715 | |
| 716 | // set up internal state |
| 717 | mService.buzzBeepBlinkLocked(r); |
| 718 | Mockito.reset(mRingtonePlayer); |
| 719 | |
Eric Laurent | 7412abc | 2019-07-12 18:26:29 -0700 | [diff] [blame] | 720 | mService.mInCallStateOffHook = true; |
Beverly | 5d463b6 | 2017-07-26 14:13:40 -0400 | [diff] [blame] | 721 | mService.buzzBeepBlinkLocked(r); |
| 722 | |
Julia Reynolds | 9418756 | 2017-10-10 13:58:49 -0400 | [diff] [blame] | 723 | verify(mService, times(1)).playInCallNotification(); |
Beverly | 5d463b6 | 2017-07-26 14:13:40 -0400 | [diff] [blame] | 724 | verifyNeverBeep(); // doesn't play normal beep |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 725 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 726 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Beverly | 5d463b6 | 2017-07-26 14:13:40 -0400 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | @Test |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 730 | public void testNoDemoteSoundToVibrateIfVibrateGiven() throws Exception { |
| 731 | NotificationRecord r = getBuzzyBeepyNotification(); |
| 732 | assertTrue(r.getSound() != null); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 733 | |
| 734 | // the phone is quiet |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 735 | when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); |
Julia Reynolds | 8589657 | 2017-09-20 12:54:52 -0400 | [diff] [blame] | 736 | when(mAudioManager.getStreamVolume(anyInt())).thenReturn(0); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 737 | |
| 738 | mService.buzzBeepBlinkLocked(r); |
| 739 | |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 740 | VibrationEffect effect = VibrationEffect.createWaveform(r.getVibration(), -1); |
| 741 | |
Jean-Michel Trivi | ea0eb5f | 2017-05-25 18:32:40 -0700 | [diff] [blame] | 742 | verify(mVibrator, timeout(MAX_VIBRATION_DELAY).times(1)).vibrate(anyInt(), anyString(), |
Alexey Kuzmin | e1f06b8 | 2018-06-20 17:48:43 +0100 | [diff] [blame] | 743 | eq(effect), anyString(), |
| 744 | (AudioAttributes) anyObject()); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 745 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 746 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 747 | } |
| 748 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 749 | @Test |
Julia Reynolds | 8589657 | 2017-09-20 12:54:52 -0400 | [diff] [blame] | 750 | public void testNoDemoteSoundToVibrateIfNonNotificationStream() throws Exception { |
| 751 | NotificationRecord r = getBeepyNotification(); |
| 752 | assertTrue(r.getSound() != null); |
| 753 | assertNull(r.getVibration()); |
| 754 | |
| 755 | // the phone is quiet |
| 756 | when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); |
| 757 | when(mAudioManager.getStreamVolume(anyInt())).thenReturn(1); |
| 758 | |
| 759 | mService.buzzBeepBlinkLocked(r); |
| 760 | |
| 761 | verifyNeverVibrate(); |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 762 | verifyBeepUnlooped(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 763 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 764 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | 8589657 | 2017-09-20 12:54:52 -0400 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | @Test |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 768 | public void testDemoteSoundToVibrate() throws Exception { |
| 769 | NotificationRecord r = getBeepyNotification(); |
| 770 | assertTrue(r.getSound() != null); |
| 771 | assertNull(r.getVibration()); |
| 772 | |
| 773 | // the phone is quiet |
| 774 | when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); |
Julia Reynolds | 8589657 | 2017-09-20 12:54:52 -0400 | [diff] [blame] | 775 | when(mAudioManager.getStreamVolume(anyInt())).thenReturn(0); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 776 | |
| 777 | mService.buzzBeepBlinkLocked(r); |
| 778 | |
Jean-Michel Trivi | ea0eb5f | 2017-05-25 18:32:40 -0700 | [diff] [blame] | 779 | verify(mVibrator, timeout(MAX_VIBRATION_DELAY).times(1)).vibrate(anyInt(), anyString(), |
Alexey Kuzmin | e1f06b8 | 2018-06-20 17:48:43 +0100 | [diff] [blame] | 780 | eq(FALLBACK_VIBRATION), anyString(), (AudioAttributes) anyObject()); |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 781 | verify(mRingtonePlayer, never()).playAsync |
| 782 | (anyObject(), anyObject(), anyBoolean(), anyObject()); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 783 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 784 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | @Test |
| 788 | public void testDemoteInsistentSoundToVibrate() throws Exception { |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 789 | NotificationRecord r = getInsistentBeepyNotification(); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 790 | assertTrue(r.getSound() != null); |
| 791 | assertNull(r.getVibration()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 792 | |
| 793 | // the phone is quiet |
| 794 | when(mAudioManager.getStreamVolume(anyInt())).thenReturn(0); |
| 795 | when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); |
| 796 | |
| 797 | mService.buzzBeepBlinkLocked(r); |
| 798 | |
Jean-Michel Trivi | ea0eb5f | 2017-05-25 18:32:40 -0700 | [diff] [blame] | 799 | verifyDelayedVibrateLooped(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 800 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 801 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 802 | } |
| 803 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 804 | @Test |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 805 | public void testVibrate() throws Exception { |
| 806 | NotificationRecord r = getBuzzyNotification(); |
| 807 | |
| 808 | mService.buzzBeepBlinkLocked(r); |
| 809 | |
| 810 | verifyNeverBeep(); |
| 811 | verifyVibrate(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 812 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 813 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 814 | } |
| 815 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 816 | @Test |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 817 | public void testInsistentVibrate() { |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 818 | NotificationRecord r = getInsistentBuzzyNotification(); |
| 819 | |
| 820 | mService.buzzBeepBlinkLocked(r); |
| 821 | verifyVibrateLooped(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 822 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 823 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 824 | } |
| 825 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 826 | @Test |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 827 | public void testVibrateTwice() { |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 828 | NotificationRecord r = getBuzzyNotification(); |
| 829 | |
| 830 | // set up internal state |
| 831 | mService.buzzBeepBlinkLocked(r); |
| 832 | Mockito.reset(mVibrator); |
| 833 | |
| 834 | // update should vibrate |
| 835 | r.isUpdate = true; |
| 836 | mService.buzzBeepBlinkLocked(r); |
| 837 | verifyVibrate(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 838 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 839 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 840 | } |
| 841 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 842 | @Test |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 843 | public void testGroupAlertSummarySilenceChild() throws Exception { |
| 844 | NotificationRecord child = getBeepyNotificationRecord("a", GROUP_ALERT_SUMMARY); |
| 845 | |
| 846 | mService.buzzBeepBlinkLocked(child); |
| 847 | |
| 848 | verifyNeverBeep(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 849 | assertFalse(child.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 850 | assertEquals(-1, child.getLastAudiblyAlertedMs()); |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | @Test |
| 854 | public void testGroupAlertSummaryNoSilenceSummary() throws Exception { |
| 855 | NotificationRecord summary = getBeepyNotificationRecord("a", GROUP_ALERT_SUMMARY); |
| 856 | summary.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY; |
| 857 | |
| 858 | mService.buzzBeepBlinkLocked(summary); |
| 859 | |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 860 | verifyBeepUnlooped(); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 861 | // summaries are never interruptive for notification counts |
| 862 | assertFalse(summary.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 863 | assertNotEquals(-1, summary.getLastAudiblyAlertedMs()); |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | @Test |
| 867 | public void testGroupAlertSummaryNoSilenceNonGroupChild() throws Exception { |
| 868 | NotificationRecord nonGroup = getBeepyNotificationRecord(null, GROUP_ALERT_SUMMARY); |
| 869 | |
| 870 | mService.buzzBeepBlinkLocked(nonGroup); |
| 871 | |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 872 | verifyBeepUnlooped(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 873 | assertTrue(nonGroup.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 874 | assertNotEquals(-1, nonGroup.getLastAudiblyAlertedMs()); |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | @Test |
| 878 | public void testGroupAlertChildSilenceSummary() throws Exception { |
| 879 | NotificationRecord summary = getBeepyNotificationRecord("a", GROUP_ALERT_CHILDREN); |
| 880 | summary.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY; |
| 881 | |
| 882 | mService.buzzBeepBlinkLocked(summary); |
| 883 | |
| 884 | verifyNeverBeep(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 885 | assertFalse(summary.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 886 | assertEquals(-1, summary.getLastAudiblyAlertedMs()); |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | @Test |
| 890 | public void testGroupAlertChildNoSilenceChild() throws Exception { |
| 891 | NotificationRecord child = getBeepyNotificationRecord("a", GROUP_ALERT_CHILDREN); |
| 892 | |
| 893 | mService.buzzBeepBlinkLocked(child); |
| 894 | |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 895 | verifyBeepUnlooped(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 896 | assertTrue(child.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 897 | assertNotEquals(-1, child.getLastAudiblyAlertedMs()); |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | @Test |
| 901 | public void testGroupAlertChildNoSilenceNonGroupSummary() throws Exception { |
| 902 | NotificationRecord nonGroup = getBeepyNotificationRecord(null, GROUP_ALERT_CHILDREN); |
| 903 | |
| 904 | mService.buzzBeepBlinkLocked(nonGroup); |
| 905 | |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 906 | verifyBeepUnlooped(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 907 | assertTrue(nonGroup.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 908 | assertNotEquals(-1, nonGroup.getLastAudiblyAlertedMs()); |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | @Test |
| 912 | public void testGroupAlertAllNoSilenceGroup() throws Exception { |
| 913 | NotificationRecord group = getBeepyNotificationRecord("a", GROUP_ALERT_ALL); |
| 914 | |
| 915 | mService.buzzBeepBlinkLocked(group); |
| 916 | |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 917 | verifyBeepUnlooped(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 918 | assertTrue(group.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 919 | assertNotEquals(-1, group.getLastAudiblyAlertedMs()); |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | @Test |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 923 | public void testHonorAlertOnlyOnceForBuzz() throws Exception { |
| 924 | NotificationRecord r = getBuzzyNotification(); |
| 925 | NotificationRecord s = getBuzzyOnceNotification(); |
| 926 | s.isUpdate = true; |
| 927 | |
| 928 | // set up internal state |
| 929 | mService.buzzBeepBlinkLocked(r); |
| 930 | Mockito.reset(mVibrator); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 931 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 932 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 933 | |
| 934 | // update should not beep |
| 935 | mService.buzzBeepBlinkLocked(s); |
| 936 | verifyNeverVibrate(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 937 | assertFalse(s.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 938 | assertEquals(-1, s.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 939 | } |
| 940 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 941 | @Test |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 942 | public void testNoisyUpdateDoesNotCancelVibrate() throws Exception { |
| 943 | NotificationRecord r = getBuzzyNotification(); |
| 944 | |
| 945 | mService.buzzBeepBlinkLocked(r); |
| 946 | r.isUpdate = true; |
| 947 | mService.buzzBeepBlinkLocked(r); |
| 948 | |
| 949 | verifyNeverStopVibrate(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 950 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 951 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 952 | } |
| 953 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 954 | @Test |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 955 | public void testNoisyOnceUpdateDoesNotCancelVibrate() throws Exception { |
| 956 | NotificationRecord r = getBuzzyNotification(); |
| 957 | NotificationRecord s = getBuzzyOnceNotification(); |
| 958 | s.isUpdate = true; |
| 959 | |
| 960 | mService.buzzBeepBlinkLocked(r); |
| 961 | mService.buzzBeepBlinkLocked(s); |
| 962 | |
| 963 | verifyNeverStopVibrate(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 964 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 965 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 966 | assertFalse(s.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 967 | assertEquals(-1, s.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 968 | } |
| 969 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 970 | @Test |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 971 | public void testQuietUpdateDoesNotCancelVibrateFromOther() throws Exception { |
| 972 | NotificationRecord r = getBuzzyNotification(); |
| 973 | NotificationRecord s = getQuietNotification(); |
| 974 | s.isUpdate = true; |
| 975 | NotificationRecord other = getNoisyOtherNotification(); |
| 976 | |
| 977 | // set up internal state |
| 978 | mService.buzzBeepBlinkLocked(r); |
| 979 | mService.buzzBeepBlinkLocked(other); // this takes the vibrate stream |
| 980 | Mockito.reset(mVibrator); |
| 981 | |
| 982 | // should not stop vibrate, since we no longer own it |
| 983 | mService.buzzBeepBlinkLocked(s); // this no longer owns the stream |
| 984 | verifyNeverStopVibrate(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 985 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 986 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 987 | assertTrue(other.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 988 | assertNotEquals(-1, other.getLastAudiblyAlertedMs()); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 989 | assertFalse(s.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 990 | assertEquals(-1, s.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 991 | } |
| 992 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 993 | @Test |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 994 | public void testQuietInterloperDoesNotCancelVibrate() throws Exception { |
| 995 | NotificationRecord r = getBuzzyNotification(); |
| 996 | NotificationRecord other = getQuietOtherNotification(); |
| 997 | |
| 998 | // set up internal state |
| 999 | mService.buzzBeepBlinkLocked(r); |
| 1000 | Mockito.reset(mVibrator); |
| 1001 | |
| 1002 | // should not stop noise, since it does not own it |
| 1003 | mService.buzzBeepBlinkLocked(other); |
| 1004 | verifyNeverStopVibrate(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 1005 | assertFalse(other.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1006 | assertEquals(-1, other.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 1007 | } |
| 1008 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 1009 | @Test |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 1010 | public void testQuietUpdateCancelsVibrate() { |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 1011 | NotificationRecord r = getBuzzyNotification(); |
| 1012 | NotificationRecord s = getQuietNotification(); |
| 1013 | s.isUpdate = true; |
| 1014 | |
| 1015 | // set up internal state |
| 1016 | mService.buzzBeepBlinkLocked(r); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 1017 | verifyVibrate(); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 1018 | |
| 1019 | // quiet update should stop making noise |
| 1020 | mService.buzzBeepBlinkLocked(s); |
| 1021 | verifyStopVibrate(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 1022 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1023 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 1024 | assertFalse(s.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1025 | assertEquals(-1, s.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 1026 | } |
| 1027 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 1028 | @Test |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 1029 | public void testQuietOnceUpdateCancelVibrate() throws Exception { |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 1030 | NotificationRecord r = getBuzzyNotification(); |
| 1031 | NotificationRecord s = getQuietOnceNotification(); |
| 1032 | s.isUpdate = true; |
| 1033 | |
| 1034 | // set up internal state |
| 1035 | mService.buzzBeepBlinkLocked(r); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 1036 | verifyVibrate(); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 1037 | |
| 1038 | // stop making noise - this is a weird corner case, but quiet should override once |
| 1039 | mService.buzzBeepBlinkLocked(s); |
| 1040 | verifyStopVibrate(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 1041 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1042 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 1043 | assertFalse(s.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1044 | assertEquals(-1, s.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 1045 | } |
| 1046 | |
Geoffrey Pitsch | 0ffe755 | 2016-08-29 10:07:40 -0400 | [diff] [blame] | 1047 | @Test |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 1048 | public void testQuietUpdateCancelsDemotedVibrate() throws Exception { |
| 1049 | NotificationRecord r = getBeepyNotification(); |
| 1050 | NotificationRecord s = getQuietNotification(); |
| 1051 | |
| 1052 | // the phone is quiet |
| 1053 | when(mAudioManager.getStreamVolume(anyInt())).thenReturn(0); |
| 1054 | when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); |
| 1055 | |
| 1056 | mService.buzzBeepBlinkLocked(r); |
| 1057 | |
| 1058 | // quiet update should stop making noise |
| 1059 | mService.buzzBeepBlinkLocked(s); |
| 1060 | verifyStopVibrate(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 1061 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1062 | assertNotEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 1063 | assertFalse(s.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1064 | assertEquals(-1, s.getLastAudiblyAlertedMs()); |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 1065 | } |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 1066 | |
Julia Reynolds | ca80d16 | 2017-04-23 12:39:32 -0400 | [diff] [blame] | 1067 | @Test |
| 1068 | public void testEmptyUriSoundTreatedAsNoSound() throws Exception { |
| 1069 | NotificationChannel channel = new NotificationChannel("test", "test", IMPORTANCE_HIGH); |
| 1070 | channel.setSound(Uri.EMPTY, null); |
Qiao (Adora) Zhang | a9d0bff | 2019-04-15 17:45:43 +0000 | [diff] [blame] | 1071 | final Notification n = new Builder(getContext(), "test") |
Julia Reynolds | ca80d16 | 2017-04-23 12:39:32 -0400 | [diff] [blame] | 1072 | .setSmallIcon(android.R.drawable.sym_def_app_icon).build(); |
| 1073 | |
| 1074 | StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 0, mTag, mUid, |
| 1075 | mPid, n, mUser, null, System.currentTimeMillis()); |
Qiao (Adora) Zhang | a9d0bff | 2019-04-15 17:45:43 +0000 | [diff] [blame] | 1076 | NotificationRecord r = new NotificationRecord(getContext(), sbn, channel); |
Julia Reynolds | ca80d16 | 2017-04-23 12:39:32 -0400 | [diff] [blame] | 1077 | mService.addNotification(r); |
| 1078 | |
| 1079 | mService.buzzBeepBlinkLocked(r); |
Julia Reynolds | ca80d16 | 2017-04-23 12:39:32 -0400 | [diff] [blame] | 1080 | verifyNeverBeep(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 1081 | assertFalse(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1082 | assertEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | ca80d16 | 2017-04-23 12:39:32 -0400 | [diff] [blame] | 1083 | } |
| 1084 | |
Julia Reynolds | 76c096d | 2017-06-19 08:16:04 -0400 | [diff] [blame] | 1085 | @Test |
| 1086 | public void testRepeatedSoundOverLimitMuted() throws Exception { |
| 1087 | when(mUsageStats.isAlertRateLimited(any())).thenReturn(true); |
| 1088 | |
| 1089 | NotificationRecord r = getBeepyNotification(); |
| 1090 | |
| 1091 | mService.buzzBeepBlinkLocked(r); |
| 1092 | verifyNeverBeep(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 1093 | assertFalse(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1094 | assertEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | 76c096d | 2017-06-19 08:16:04 -0400 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | @Test |
| 1098 | public void testPostingSilentNotificationDoesNotAffectRateLimiting() throws Exception { |
| 1099 | NotificationRecord r = getQuietNotification(); |
| 1100 | mService.buzzBeepBlinkLocked(r); |
| 1101 | |
| 1102 | verify(mUsageStats, never()).isAlertRateLimited(any()); |
| 1103 | } |
| 1104 | |
| 1105 | @Test |
Julia Reynolds | 65b85cf | 2017-07-20 09:19:20 -0400 | [diff] [blame] | 1106 | public void testPostingGroupSuppressedDoesNotAffectRateLimiting() throws Exception { |
| 1107 | NotificationRecord summary = getBeepyNotificationRecord("a", GROUP_ALERT_CHILDREN); |
| 1108 | summary.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY; |
| 1109 | |
| 1110 | mService.buzzBeepBlinkLocked(summary); |
Julia Reynolds | 65b85cf | 2017-07-20 09:19:20 -0400 | [diff] [blame] | 1111 | verify(mUsageStats, never()).isAlertRateLimited(any()); |
| 1112 | } |
| 1113 | |
| 1114 | @Test |
Julia Reynolds | 79dfdd6 | 2018-04-17 15:36:33 -0400 | [diff] [blame] | 1115 | public void testGroupSuppressionFailureDoesNotAffectRateLimiting() { |
| 1116 | NotificationRecord summary = getBeepyNotificationRecord("a", GROUP_ALERT_SUMMARY); |
| 1117 | summary.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY; |
| 1118 | |
| 1119 | mService.buzzBeepBlinkLocked(summary); |
| 1120 | verify(mUsageStats, times(1)).isAlertRateLimited(any()); |
| 1121 | } |
| 1122 | |
| 1123 | @Test |
Julia Reynolds | 76c096d | 2017-06-19 08:16:04 -0400 | [diff] [blame] | 1124 | public void testCrossUserSoundMuted() throws Exception { |
Qiao (Adora) Zhang | a9d0bff | 2019-04-15 17:45:43 +0000 | [diff] [blame] | 1125 | final Notification n = new Builder(getContext(), "test") |
Julia Reynolds | 76c096d | 2017-06-19 08:16:04 -0400 | [diff] [blame] | 1126 | .setSmallIcon(android.R.drawable.sym_def_app_icon).build(); |
| 1127 | |
| 1128 | int userId = mUser.getIdentifier() + 1; |
| 1129 | StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 0, mTag, mUid, |
| 1130 | mPid, n, UserHandle.of(userId), null, System.currentTimeMillis()); |
Qiao (Adora) Zhang | a9d0bff | 2019-04-15 17:45:43 +0000 | [diff] [blame] | 1131 | NotificationRecord r = new NotificationRecord(getContext(), sbn, |
Julia Reynolds | 76c096d | 2017-06-19 08:16:04 -0400 | [diff] [blame] | 1132 | new NotificationChannel("test", "test", IMPORTANCE_HIGH)); |
| 1133 | |
| 1134 | mService.buzzBeepBlinkLocked(r); |
| 1135 | verifyNeverBeep(); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 1136 | assertFalse(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1137 | assertEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | 76c096d | 2017-06-19 08:16:04 -0400 | [diff] [blame] | 1138 | } |
| 1139 | |
Julia Reynolds | 9418756 | 2017-10-10 13:58:49 -0400 | [diff] [blame] | 1140 | @Test |
| 1141 | public void testA11yMinInitialPost() throws Exception { |
| 1142 | NotificationRecord r = getQuietNotification(); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 1143 | r.setSystemImportance(IMPORTANCE_MIN); |
Julia Reynolds | 9418756 | 2017-10-10 13:58:49 -0400 | [diff] [blame] | 1144 | mService.buzzBeepBlinkLocked(r); |
| 1145 | verify(mAccessibilityService, never()).sendAccessibilityEvent(any(), anyInt()); |
| 1146 | } |
| 1147 | |
| 1148 | @Test |
| 1149 | public void testA11yQuietInitialPost() throws Exception { |
| 1150 | NotificationRecord r = getQuietNotification(); |
| 1151 | mService.buzzBeepBlinkLocked(r); |
| 1152 | verify(mAccessibilityService, times(1)).sendAccessibilityEvent(any(), anyInt()); |
| 1153 | } |
| 1154 | |
| 1155 | @Test |
| 1156 | public void testA11yQuietUpdate() throws Exception { |
| 1157 | NotificationRecord r = getQuietNotification(); |
| 1158 | mService.buzzBeepBlinkLocked(r); |
| 1159 | r.isUpdate = true; |
| 1160 | mService.buzzBeepBlinkLocked(r); |
| 1161 | verify(mAccessibilityService, times(1)).sendAccessibilityEvent(any(), anyInt()); |
| 1162 | } |
| 1163 | |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 1164 | @Test |
| 1165 | public void testLightsScreenOn() { |
| 1166 | mService.mScreenOn = true; |
| 1167 | NotificationRecord r = getLightsNotification(); |
| 1168 | mService.buzzBeepBlinkLocked(r); |
| 1169 | verifyNeverLights(); |
| 1170 | assertFalse(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1171 | assertEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | @Test |
| 1175 | public void testLightsInCall() { |
Eric Laurent | 7412abc | 2019-07-12 18:26:29 -0700 | [diff] [blame] | 1176 | mService.mInCallStateOffHook = true; |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 1177 | NotificationRecord r = getLightsNotification(); |
| 1178 | mService.buzzBeepBlinkLocked(r); |
| 1179 | verifyNeverLights(); |
| 1180 | assertFalse(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1181 | assertEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | @Test |
| 1185 | public void testLightsSilentUpdate() { |
| 1186 | NotificationRecord r = getLightsOnceNotification(); |
| 1187 | mService.buzzBeepBlinkLocked(r); |
| 1188 | verifyLights(); |
| 1189 | assertTrue(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1190 | assertEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 1191 | |
| 1192 | r = getLightsOnceNotification(); |
| 1193 | r.isUpdate = true; |
| 1194 | mService.buzzBeepBlinkLocked(r); |
| 1195 | // checks that lights happened once, i.e. this new call didn't trigger them again |
| 1196 | verifyLights(); |
| 1197 | assertFalse(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1198 | assertEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | @Test |
| 1202 | public void testLightsUnimportant() { |
| 1203 | NotificationRecord r = getLightsNotification(); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 1204 | r.setSystemImportance(IMPORTANCE_LOW); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 1205 | mService.buzzBeepBlinkLocked(r); |
| 1206 | verifyNeverLights(); |
| 1207 | assertFalse(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1208 | assertEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | @Test |
| 1212 | public void testLightsNoLights() { |
| 1213 | NotificationRecord r = getQuietNotification(); |
| 1214 | mService.buzzBeepBlinkLocked(r); |
| 1215 | verifyNeverLights(); |
| 1216 | assertFalse(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1217 | assertEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | @Test |
| 1221 | public void testLightsNoLightOnDevice() { |
| 1222 | mService.mHasLight = false; |
| 1223 | NotificationRecord r = getLightsNotification(); |
| 1224 | mService.buzzBeepBlinkLocked(r); |
| 1225 | verifyNeverLights(); |
| 1226 | assertFalse(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1227 | assertEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | @Test |
| 1231 | public void testLightsLightsOffGlobally() { |
| 1232 | mService.mNotificationPulseEnabled = false; |
| 1233 | NotificationRecord r = getLightsNotification(); |
| 1234 | mService.buzzBeepBlinkLocked(r); |
| 1235 | verifyNeverLights(); |
| 1236 | assertFalse(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1237 | assertEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | @Test |
| 1241 | public void testLightsDndIntercepted() { |
| 1242 | NotificationRecord r = getLightsNotification(); |
| 1243 | r.setSuppressedVisualEffects(SUPPRESSED_EFFECT_LIGHTS); |
| 1244 | mService.buzzBeepBlinkLocked(r); |
| 1245 | verifyNeverLights(); |
| 1246 | assertFalse(r.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1247 | assertEquals(-1, r.getLastAudiblyAlertedMs()); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | @Test |
| 1251 | public void testGroupAlertSummaryNoLightsChild() { |
| 1252 | NotificationRecord child = getLightsNotificationRecord("a", GROUP_ALERT_SUMMARY); |
| 1253 | |
| 1254 | mService.buzzBeepBlinkLocked(child); |
| 1255 | |
| 1256 | verifyNeverLights(); |
| 1257 | assertFalse(child.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1258 | assertEquals(-1, child.getLastAudiblyAlertedMs()); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | @Test |
| 1262 | public void testGroupAlertSummaryLightsSummary() { |
| 1263 | NotificationRecord summary = getLightsNotificationRecord("a", GROUP_ALERT_SUMMARY); |
| 1264 | summary.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY; |
| 1265 | |
| 1266 | mService.buzzBeepBlinkLocked(summary); |
| 1267 | |
| 1268 | verifyLights(); |
| 1269 | // summaries should never count for interruptiveness counts |
| 1270 | assertFalse(summary.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1271 | assertEquals(-1, summary.getLastAudiblyAlertedMs()); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | @Test |
| 1275 | public void testGroupAlertSummaryLightsNonGroupChild() { |
| 1276 | NotificationRecord nonGroup = getLightsNotificationRecord(null, GROUP_ALERT_SUMMARY); |
| 1277 | |
| 1278 | mService.buzzBeepBlinkLocked(nonGroup); |
| 1279 | |
| 1280 | verifyLights(); |
| 1281 | assertTrue(nonGroup.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1282 | assertEquals(-1, nonGroup.getLastAudiblyAlertedMs()); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | @Test |
| 1286 | public void testGroupAlertChildNoLightsSummary() { |
| 1287 | NotificationRecord summary = getLightsNotificationRecord("a", GROUP_ALERT_CHILDREN); |
| 1288 | summary.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY; |
| 1289 | |
| 1290 | mService.buzzBeepBlinkLocked(summary); |
| 1291 | |
| 1292 | verifyNeverLights(); |
| 1293 | assertFalse(summary.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1294 | assertEquals(-1, summary.getLastAudiblyAlertedMs()); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | @Test |
| 1298 | public void testGroupAlertChildLightsChild() { |
| 1299 | NotificationRecord child = getLightsNotificationRecord("a", GROUP_ALERT_CHILDREN); |
| 1300 | |
| 1301 | mService.buzzBeepBlinkLocked(child); |
| 1302 | |
| 1303 | verifyLights(); |
| 1304 | assertTrue(child.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1305 | assertEquals(-1, child.getLastAudiblyAlertedMs()); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | @Test |
| 1309 | public void testGroupAlertChildLightsNonGroupSummary() { |
| 1310 | NotificationRecord nonGroup = getLightsNotificationRecord(null, GROUP_ALERT_CHILDREN); |
| 1311 | |
| 1312 | mService.buzzBeepBlinkLocked(nonGroup); |
| 1313 | |
| 1314 | verifyLights(); |
| 1315 | assertTrue(nonGroup.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1316 | assertEquals(-1, nonGroup.getLastAudiblyAlertedMs()); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | @Test |
| 1320 | public void testGroupAlertAllLightsGroup() { |
| 1321 | NotificationRecord group = getLightsNotificationRecord("a", GROUP_ALERT_ALL); |
| 1322 | |
| 1323 | mService.buzzBeepBlinkLocked(group); |
| 1324 | |
| 1325 | verifyLights(); |
| 1326 | assertTrue(group.isInterruptive()); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1327 | assertEquals(-1, group.getLastAudiblyAlertedMs()); |
Julia Reynolds | 28149f6 | 2018-07-03 10:43:35 -0400 | [diff] [blame] | 1328 | } |
| 1329 | |
Julia Reynolds | db7081e | 2019-01-03 14:35:38 -0500 | [diff] [blame] | 1330 | @Test |
| 1331 | public void testListenerHintCall() throws Exception { |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 1332 | NotificationChannel ringtoneChannel = |
| 1333 | new NotificationChannel("ringtone", "", IMPORTANCE_HIGH); |
| 1334 | ringtoneChannel.setSound(Settings.System.DEFAULT_RINGTONE_URI, |
| 1335 | new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE).build()); |
| 1336 | NotificationRecord r = getCallRecord(1, ringtoneChannel, true); |
Julia Reynolds | db7081e | 2019-01-03 14:35:38 -0500 | [diff] [blame] | 1337 | |
| 1338 | mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS); |
| 1339 | |
| 1340 | mService.buzzBeepBlinkLocked(r); |
| 1341 | |
| 1342 | verifyNeverBeep(); |
| 1343 | } |
| 1344 | |
| 1345 | @Test |
| 1346 | public void testListenerHintCall_notificationSound() throws Exception { |
| 1347 | NotificationRecord r = getBeepyNotification(); |
| 1348 | |
| 1349 | mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS); |
| 1350 | |
| 1351 | mService.buzzBeepBlinkLocked(r); |
| 1352 | |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 1353 | verifyBeepUnlooped(); |
Julia Reynolds | db7081e | 2019-01-03 14:35:38 -0500 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | @Test |
| 1357 | public void testListenerHintNotification() throws Exception { |
| 1358 | NotificationRecord r = getBeepyNotification(); |
| 1359 | |
| 1360 | mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS); |
| 1361 | |
| 1362 | mService.buzzBeepBlinkLocked(r); |
| 1363 | |
| 1364 | verifyNeverBeep(); |
| 1365 | } |
| 1366 | |
| 1367 | @Test |
| 1368 | public void testListenerHintBoth() throws Exception { |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 1369 | NotificationChannel ringtoneChannel = |
| 1370 | new NotificationChannel("ringtone", "", IMPORTANCE_HIGH); |
| 1371 | ringtoneChannel.setSound(Settings.System.DEFAULT_RINGTONE_URI, |
| 1372 | new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE).build()); |
| 1373 | NotificationRecord r = getCallRecord(1, ringtoneChannel, true); |
Julia Reynolds | db7081e | 2019-01-03 14:35:38 -0500 | [diff] [blame] | 1374 | NotificationRecord s = getBeepyNotification(); |
| 1375 | |
| 1376 | mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS |
| 1377 | | NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS); |
| 1378 | |
| 1379 | mService.buzzBeepBlinkLocked(r); |
| 1380 | mService.buzzBeepBlinkLocked(s); |
| 1381 | |
| 1382 | verifyNeverBeep(); |
| 1383 | } |
| 1384 | |
| 1385 | @Test |
| 1386 | public void testListenerHintNotification_callSound() throws Exception { |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 1387 | NotificationChannel ringtoneChannel = |
| 1388 | new NotificationChannel("ringtone", "", IMPORTANCE_HIGH); |
| 1389 | ringtoneChannel.setSound(Settings.System.DEFAULT_RINGTONE_URI, |
| 1390 | new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE).build()); |
| 1391 | NotificationRecord r = getCallRecord(1, ringtoneChannel, true); |
Julia Reynolds | db7081e | 2019-01-03 14:35:38 -0500 | [diff] [blame] | 1392 | |
| 1393 | mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS); |
| 1394 | |
| 1395 | mService.buzzBeepBlinkLocked(r); |
| 1396 | |
| 1397 | verifyBeepLooped(); |
| 1398 | } |
| 1399 | |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 1400 | @Test |
| 1401 | public void testCannotInterruptRingtoneInsistentBeep() throws Exception { |
| 1402 | NotificationChannel ringtoneChannel = |
| 1403 | new NotificationChannel("ringtone", "", IMPORTANCE_HIGH); |
| 1404 | ringtoneChannel.setSound(Settings.System.DEFAULT_RINGTONE_URI, |
| 1405 | new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE).build()); |
| 1406 | NotificationRecord ringtoneNotification = getCallRecord(1, ringtoneChannel, true); |
| 1407 | mService.addNotification(ringtoneNotification); |
| 1408 | |
| 1409 | mService.buzzBeepBlinkLocked(ringtoneNotification); |
| 1410 | verifyBeepLooped(); |
| 1411 | |
| 1412 | NotificationRecord interrupter = getBeepyOtherNotification(); |
| 1413 | assertTrue(mService.shouldMuteNotificationLocked(interrupter)); |
| 1414 | mService.buzzBeepBlinkLocked(interrupter); |
| 1415 | |
| 1416 | verifyBeep(1); |
| 1417 | |
| 1418 | assertFalse(interrupter.isInterruptive()); |
| 1419 | assertEquals(-1, interrupter.getLastAudiblyAlertedMs()); |
| 1420 | } |
| 1421 | |
| 1422 | @Test |
| 1423 | public void testCannotInterruptRingtoneInsistentBuzz() { |
| 1424 | NotificationChannel ringtoneChannel = |
| 1425 | new NotificationChannel("ringtone", "", IMPORTANCE_HIGH); |
| 1426 | ringtoneChannel.setSound(Uri.EMPTY, |
| 1427 | new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE).build()); |
| 1428 | ringtoneChannel.enableVibration(true); |
| 1429 | NotificationRecord ringtoneNotification = getCallRecord(1, ringtoneChannel, true); |
| 1430 | assertFalse(mService.shouldMuteNotificationLocked(ringtoneNotification)); |
| 1431 | |
| 1432 | mService.buzzBeepBlinkLocked(ringtoneNotification); |
| 1433 | verifyVibrateLooped(); |
| 1434 | |
| 1435 | NotificationRecord interrupter = getBuzzyOtherNotification(); |
| 1436 | assertTrue(mService.shouldMuteNotificationLocked(interrupter)); |
| 1437 | mService.buzzBeepBlinkLocked(interrupter); |
| 1438 | |
| 1439 | verifyVibrate(1); |
| 1440 | |
| 1441 | assertFalse(interrupter.isInterruptive()); |
| 1442 | assertEquals(-1, interrupter.getLastAudiblyAlertedMs()); |
| 1443 | } |
| 1444 | |
| 1445 | @Test |
| 1446 | public void testCanInterruptRingtoneNonInsistentBeep() throws Exception { |
| 1447 | NotificationChannel ringtoneChannel = |
| 1448 | new NotificationChannel("ringtone", "", IMPORTANCE_HIGH); |
| 1449 | ringtoneChannel.setSound(Settings.System.DEFAULT_RINGTONE_URI, |
| 1450 | new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE).build()); |
| 1451 | NotificationRecord ringtoneNotification = getCallRecord(1, ringtoneChannel, false); |
| 1452 | |
| 1453 | mService.buzzBeepBlinkLocked(ringtoneNotification); |
| 1454 | verifyBeepUnlooped(); |
| 1455 | |
| 1456 | NotificationRecord interrupter = getBeepyOtherNotification(); |
| 1457 | mService.buzzBeepBlinkLocked(interrupter); |
| 1458 | |
| 1459 | verifyBeep(2); |
| 1460 | |
| 1461 | assertTrue(interrupter.isInterruptive()); |
| 1462 | } |
| 1463 | |
| 1464 | @Test |
| 1465 | public void testCanInterruptRingtoneNonInsistentBuzz() { |
| 1466 | NotificationChannel ringtoneChannel = |
| 1467 | new NotificationChannel("ringtone", "", IMPORTANCE_HIGH); |
| 1468 | ringtoneChannel.setSound(null, |
| 1469 | new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE).build()); |
| 1470 | ringtoneChannel.enableVibration(true); |
| 1471 | NotificationRecord ringtoneNotification = getCallRecord(1, ringtoneChannel, false); |
| 1472 | |
| 1473 | mService.buzzBeepBlinkLocked(ringtoneNotification); |
| 1474 | verifyVibrate(); |
| 1475 | |
| 1476 | NotificationRecord interrupter = getBuzzyOtherNotification(); |
| 1477 | mService.buzzBeepBlinkLocked(interrupter); |
| 1478 | |
| 1479 | verifyVibrate(2); |
| 1480 | |
| 1481 | assertTrue(interrupter.isInterruptive()); |
| 1482 | } |
| 1483 | |
| 1484 | @Test |
| 1485 | public void testRingtoneInsistentBeep_doesNotBlockFutureSoundsOnceStopped() throws Exception { |
| 1486 | NotificationChannel ringtoneChannel = |
| 1487 | new NotificationChannel("ringtone", "", IMPORTANCE_HIGH); |
| 1488 | ringtoneChannel.setSound(Settings.System.DEFAULT_RINGTONE_URI, |
| 1489 | new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE).build()); |
| 1490 | NotificationRecord ringtoneNotification = getCallRecord(1, ringtoneChannel, true); |
| 1491 | |
| 1492 | mService.buzzBeepBlinkLocked(ringtoneNotification); |
| 1493 | verifyBeepLooped(); |
| 1494 | |
| 1495 | mService.clearSoundLocked(); |
| 1496 | |
| 1497 | NotificationRecord interrupter = getBeepyOtherNotification(); |
| 1498 | mService.buzzBeepBlinkLocked(interrupter); |
| 1499 | |
| 1500 | verifyBeep(2); |
| 1501 | |
| 1502 | assertTrue(interrupter.isInterruptive()); |
| 1503 | } |
| 1504 | |
| 1505 | @Test |
| 1506 | public void testRingtoneInsistentBuzz_doesNotBlockFutureSoundsOnceStopped() { |
| 1507 | NotificationChannel ringtoneChannel = |
| 1508 | new NotificationChannel("ringtone", "", IMPORTANCE_HIGH); |
| 1509 | ringtoneChannel.setSound(null, |
| 1510 | new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE).build()); |
| 1511 | ringtoneChannel.enableVibration(true); |
| 1512 | NotificationRecord ringtoneNotification = getCallRecord(1, ringtoneChannel, true); |
| 1513 | |
| 1514 | mService.buzzBeepBlinkLocked(ringtoneNotification); |
| 1515 | verifyVibrateLooped(); |
| 1516 | |
| 1517 | mService.clearVibrateLocked(); |
| 1518 | |
| 1519 | NotificationRecord interrupter = getBuzzyOtherNotification(); |
| 1520 | mService.buzzBeepBlinkLocked(interrupter); |
| 1521 | |
| 1522 | verifyVibrate(2); |
| 1523 | |
| 1524 | assertTrue(interrupter.isInterruptive()); |
| 1525 | } |
| 1526 | |
| 1527 | @Test |
| 1528 | public void testCanInterruptNonRingtoneInsistentBeep() throws Exception { |
| 1529 | NotificationChannel fakeRingtoneChannel = |
| 1530 | new NotificationChannel("ringtone", "", IMPORTANCE_HIGH); |
| 1531 | NotificationRecord ringtoneNotification = getCallRecord(1, fakeRingtoneChannel, true); |
| 1532 | |
| 1533 | mService.buzzBeepBlinkLocked(ringtoneNotification); |
| 1534 | verifyBeepLooped(); |
| 1535 | |
| 1536 | NotificationRecord interrupter = getBeepyOtherNotification(); |
| 1537 | mService.buzzBeepBlinkLocked(interrupter); |
| 1538 | |
| 1539 | verifyBeep(2); |
| 1540 | |
| 1541 | assertTrue(interrupter.isInterruptive()); |
| 1542 | } |
| 1543 | |
| 1544 | @Test |
Julia Reynolds | 181ff7c | 2019-10-18 12:16:31 -0400 | [diff] [blame] | 1545 | public void testCanInterruptNonRingtoneInsistentBuzz() { |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 1546 | NotificationChannel fakeRingtoneChannel = |
| 1547 | new NotificationChannel("ringtone", "", IMPORTANCE_HIGH); |
| 1548 | fakeRingtoneChannel.enableVibration(true); |
Julia Reynolds | 181ff7c | 2019-10-18 12:16:31 -0400 | [diff] [blame] | 1549 | fakeRingtoneChannel.setSound(null, |
| 1550 | new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION).build()); |
Julia Reynolds | 714ff5f | 2019-10-14 11:19:53 -0400 | [diff] [blame] | 1551 | NotificationRecord ringtoneNotification = getCallRecord(1, fakeRingtoneChannel, true); |
| 1552 | |
| 1553 | mService.buzzBeepBlinkLocked(ringtoneNotification); |
| 1554 | |
| 1555 | NotificationRecord interrupter = getBuzzyOtherNotification(); |
| 1556 | mService.buzzBeepBlinkLocked(interrupter); |
| 1557 | |
| 1558 | verifyVibrate(2); |
| 1559 | |
| 1560 | assertTrue(interrupter.isInterruptive()); |
| 1561 | } |
| 1562 | |
Michael Wright | 7121697 | 2017-01-31 18:33:54 +0000 | [diff] [blame] | 1563 | static class VibrateRepeatMatcher implements ArgumentMatcher<VibrationEffect> { |
| 1564 | private final int mRepeatIndex; |
| 1565 | |
| 1566 | VibrateRepeatMatcher(int repeatIndex) { |
| 1567 | mRepeatIndex = repeatIndex; |
| 1568 | } |
| 1569 | |
| 1570 | @Override |
| 1571 | public boolean matches(VibrationEffect actual) { |
| 1572 | if (actual instanceof VibrationEffect.Waveform && |
| 1573 | ((VibrationEffect.Waveform) actual).getRepeatIndex() == mRepeatIndex) { |
| 1574 | return true; |
| 1575 | } |
| 1576 | // All non-waveform effects are essentially one shots. |
| 1577 | return mRepeatIndex == -1; |
| 1578 | } |
| 1579 | |
| 1580 | @Override |
| 1581 | public String toString() { |
| 1582 | return "repeatIndex=" + mRepeatIndex; |
| 1583 | } |
| 1584 | } |
Chris Wren | 93bb8b8 | 2016-03-29 14:35:05 -0400 | [diff] [blame] | 1585 | } |