[go: nahoru, domu]

blob: afd10ddb8ec26ca45b230a1b7ff7e105e0740420 [file] [log] [blame]
Chris Wren93bb8b82016-03-29 14:35:05 -04001/*
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 */
16package com.android.server.notification;
17
Julia Reynoldsa79c3712017-04-21 10:29:57 -040018import static android.app.Notification.GROUP_ALERT_ALL;
19import static android.app.Notification.GROUP_ALERT_CHILDREN;
20import static android.app.Notification.GROUP_ALERT_SUMMARY;
Julia Reynoldsca80d162017-04-23 12:39:32 -040021import static android.app.NotificationManager.IMPORTANCE_HIGH;
Julia Reynolds28149f62018-07-03 10:43:35 -040022import static android.app.NotificationManager.IMPORTANCE_LOW;
Julia Reynolds94187562017-10-10 13:58:49 -040023import static android.app.NotificationManager.IMPORTANCE_MIN;
Julia Reynolds28149f62018-07-03 10:43:35 -040024import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_LIGHTS;
Julia Reynolds181ff7c2019-10-18 12:16:31 -040025import static android.media.AudioAttributes.USAGE_NOTIFICATION;
Julia Reynolds714ff5f2019-10-14 11:19:53 -040026import static android.media.AudioAttributes.USAGE_NOTIFICATION_RINGTONE;
Julia Reynoldsca80d162017-04-23 12:39:32 -040027
Julia Reynolds1fac86e2018-03-07 08:30:37 -050028import static junit.framework.Assert.assertFalse;
Julia Reynolds0c299d42016-11-15 14:37:04 -050029import static junit.framework.Assert.assertNull;
30import static junit.framework.Assert.assertTrue;
31
Gus Prevas7306b902018-12-11 10:57:06 -050032import static org.junit.Assert.assertEquals;
33import static org.junit.Assert.assertNotEquals;
Julia Reynolds76c096d2017-06-19 08:16:04 -040034import static org.mockito.Matchers.any;
Chris Wren93bb8b82016-03-29 14:35:05 -040035import static org.mockito.Matchers.anyBoolean;
36import static org.mockito.Matchers.anyInt;
37import static org.mockito.Matchers.anyObject;
38import static org.mockito.Matchers.anyString;
Michael Wright71216972017-01-31 18:33:54 +000039import static org.mockito.Matchers.argThat;
Chris Wren93bb8b82016-03-29 14:35:05 -040040import static org.mockito.Matchers.eq;
41import static org.mockito.Mockito.never;
Tony Mantlerab55f0f2017-06-16 10:50:00 -070042import static org.mockito.Mockito.spy;
Jean-Michel Triviea0eb5f2017-05-25 18:32:40 -070043import static org.mockito.Mockito.timeout;
Chris Wren93bb8b82016-03-29 14:35:05 -040044import static org.mockito.Mockito.times;
45import static org.mockito.Mockito.verify;
46import static org.mockito.Mockito.when;
47
Tony Mantlerab55f0f2017-06-16 10:50:00 -070048import android.app.ActivityManager;
49import android.app.Notification;
50import android.app.Notification.Builder;
51import android.app.NotificationChannel;
52import android.app.NotificationManager;
Qiao (Adora) Zhanga9d0bff2019-04-15 17:45:43 +000053import android.content.Context;
Tony Mantlerab55f0f2017-06-16 10:50:00 -070054import android.content.pm.PackageManager;
55import android.graphics.Color;
56import android.media.AudioAttributes;
57import android.media.AudioManager;
58import android.net.Uri;
59import android.os.Handler;
60import android.os.RemoteException;
61import android.os.UserHandle;
62import android.os.VibrationEffect;
63import android.os.Vibrator;
64import android.provider.Settings;
Julia Reynoldsdb7081e2019-01-03 14:35:38 -050065import android.service.notification.NotificationListenerService;
Tony Mantlerab55f0f2017-06-16 10:50:00 -070066import android.service.notification.StatusBarNotification;
Tony Mantlerab55f0f2017-06-16 10:50:00 -070067import android.test.suitebuilder.annotation.SmallTest;
Julia Reynolds94187562017-10-10 13:58:49 -040068import android.view.accessibility.AccessibilityEvent;
69import android.view.accessibility.AccessibilityManager;
70import android.view.accessibility.IAccessibilityManager;
71import android.view.accessibility.IAccessibilityManagerClient;
Tony Mantlerab55f0f2017-06-16 10:50:00 -070072
Brett Chabot84151d92019-02-27 15:37:59 -080073import androidx.test.runner.AndroidJUnit4;
74
Will Brockmancfd98302020-01-29 15:57:30 -050075import com.android.internal.logging.InstanceIdSequence;
76import com.android.internal.logging.InstanceIdSequenceFake;
Julia Reynolds94187562017-10-10 13:58:49 -040077import com.android.internal.util.IntPair;
Jason Monk74f5e362017-12-06 08:56:33 -050078import com.android.server.UiServiceTestCase;
Ivailo Karamanolevf773e102020-01-16 16:10:42 +010079import com.android.server.lights.LogicalLight;
Tony Mantlerab55f0f2017-06-16 10:50:00 -070080
81import org.junit.Before;
82import org.junit.Test;
83import org.junit.runner.RunWith;
84import org.mockito.ArgumentMatcher;
85import org.mockito.Mock;
86import org.mockito.Mockito;
87import org.mockito.MockitoAnnotations;
88
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -040089@SmallTest
90@RunWith(AndroidJUnit4.class)
Jason Monk74f5e362017-12-06 08:56:33 -050091public class BuzzBeepBlinkTest extends UiServiceTestCase {
Chris Wren93bb8b82016-03-29 14:35:05 -040092
93 @Mock AudioManager mAudioManager;
94 @Mock Vibrator mVibrator;
95 @Mock android.media.IRingtonePlayer mRingtonePlayer;
Ivailo Karamanolevf773e102020-01-16 16:10:42 +010096 @Mock LogicalLight mLight;
Julia Reynoldseb3dca72017-07-11 10:39:58 -040097 @Mock
98 NotificationManagerService.WorkerHandler mHandler;
Julia Reynolds76c096d2017-06-19 08:16:04 -040099 @Mock
100 NotificationUsageStats mUsageStats;
Julia Reynolds94187562017-10-10 13:58:49 -0400101 @Mock
102 IAccessibilityManager mAccessibilityService;
Will Brockman2b6959e2020-01-22 09:59:50 -0500103 NotificationRecordLoggerFake mNotificationRecordLogger = new NotificationRecordLoggerFake();
Will Brockmancfd98302020-01-29 15:57:30 -0500104 private InstanceIdSequence mNotificationInstanceIdSequence = new InstanceIdSequenceFake(
105 1 << 30);
Chris Wren93bb8b82016-03-29 14:35:05 -0400106
107 private NotificationManagerService mService;
108 private String mPkg = "com.android.server.notification";
109 private int mId = 1001;
110 private int mOtherId = 1002;
111 private String mTag = null;
112 private int mUid = 1000;
113 private int mPid = 2000;
Chris Wren93bb8b82016-03-29 14:35:05 -0400114 private android.os.UserHandle mUser = UserHandle.of(ActivityManager.getCurrentUser());
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400115 private NotificationChannel mChannel;
Chris Wren93bb8b82016-03-29 14:35:05 -0400116
Michael Wright71216972017-01-31 18:33:54 +0000117 private VibrateRepeatMatcher mVibrateOnceMatcher = new VibrateRepeatMatcher(-1);
118 private VibrateRepeatMatcher mVibrateLoopMatcher = new VibrateRepeatMatcher(0);
119
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400120 private static final long[] CUSTOM_VIBRATION = new long[] {
121 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400,
122 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400,
123 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400 };
124 private static final Uri CUSTOM_SOUND = Settings.System.DEFAULT_ALARM_ALERT_URI;
Julia Reynolds619a69f2017-01-27 15:11:38 -0500125 private static final AudioAttributes CUSTOM_ATTRIBUTES = new AudioAttributes.Builder()
126 .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN)
Julia Reynoldsdb7081e2019-01-03 14:35:38 -0500127 .setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
Julia Reynolds619a69f2017-01-27 15:11:38 -0500128 .build();
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400129 private static final int CUSTOM_LIGHT_COLOR = Color.BLACK;
130 private static final int CUSTOM_LIGHT_ON = 10000;
131 private static final int CUSTOM_LIGHT_OFF = 10000;
Michael Wright71216972017-01-31 18:33:54 +0000132 private static final long[] FALLBACK_VIBRATION_PATTERN = new long[] {100, 100, 100};
133 private static final VibrationEffect FALLBACK_VIBRATION =
134 VibrationEffect.createWaveform(FALLBACK_VIBRATION_PATTERN, -1);
Jean-Michel Triviea0eb5f2017-05-25 18:32:40 -0700135 private static final int MAX_VIBRATION_DELAY = 1000;
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400136
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400137 @Before
Julia Reynolds94187562017-10-10 13:58:49 -0400138 public void setUp() throws Exception {
Chris Wren93bb8b82016-03-29 14:35:05 -0400139 MockitoAnnotations.initMocks(this);
140
141 when(mAudioManager.isAudioFocusExclusive()).thenReturn(false);
142 when(mAudioManager.getRingtonePlayer()).thenReturn(mRingtonePlayer);
143 when(mAudioManager.getStreamVolume(anyInt())).thenReturn(10);
144 when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL);
Julia Reynolds76c096d2017-06-19 08:16:04 -0400145 when(mUsageStats.isAlertRateLimited(any())).thenReturn(false);
146
Julia Reynolds94187562017-10-10 13:58:49 -0400147 long serviceReturnValue = IntPair.of(
148 AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED,
149 AccessibilityEvent.TYPES_ALL_MASK);
150 when(mAccessibilityService.addClient(any(), anyInt())).thenReturn(serviceReturnValue);
151 AccessibilityManager accessibilityManager =
152 new AccessibilityManager(Handler.getMain(), mAccessibilityService, 0);
153 verify(mAccessibilityService).addClient(any(IAccessibilityManagerClient.class), anyInt());
154 assertTrue(accessibilityManager.isEnabled());
155
Will Brockmancfd98302020-01-29 15:57:30 -0500156 mService = spy(new NotificationManagerService(getContext(), mNotificationRecordLogger,
157 mNotificationInstanceIdSequence));
Chris Wren93bb8b82016-03-29 14:35:05 -0400158 mService.setAudioManager(mAudioManager);
159 mService.setVibrator(mVibrator);
160 mService.setSystemReady(true);
161 mService.setHandler(mHandler);
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400162 mService.setLights(mLight);
163 mService.setScreenOn(false);
Michael Wright71216972017-01-31 18:33:54 +0000164 mService.setFallbackVibrationPattern(FALLBACK_VIBRATION_PATTERN);
Julia Reynolds76c096d2017-06-19 08:16:04 -0400165 mService.setUsageStats(mUsageStats);
Julia Reynolds94187562017-10-10 13:58:49 -0400166 mService.setAccessibilityManager(accessibilityManager);
Julia Reynolds28149f62018-07-03 10:43:35 -0400167 mService.mScreenOn = false;
Eric Laurent7412abc2019-07-12 18:26:29 -0700168 mService.mInCallStateOffHook = false;
Julia Reynolds28149f62018-07-03 10:43:35 -0400169 mService.mNotificationPulseEnabled = true;
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400170
171 mChannel = new NotificationChannel("test", "test", IMPORTANCE_HIGH);
Chris Wren93bb8b82016-03-29 14:35:05 -0400172 }
173
174 //
175 // Convenience functions for creating notification records
176 //
177
178 private NotificationRecord getNoisyOtherNotification() {
179 return getNotificationRecord(mOtherId, false /* insistent */, false /* once */,
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400180 true /* noisy */, true /* buzzy*/, false /* lights */);
Chris Wren93bb8b82016-03-29 14:35:05 -0400181 }
182
183 private NotificationRecord getBeepyNotification() {
184 return getNotificationRecord(mId, false /* insistent */, false /* once */,
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400185 true /* noisy */, false /* buzzy*/, false /* lights */);
Chris Wren93bb8b82016-03-29 14:35:05 -0400186 }
187
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400188 private NotificationRecord getBeepyOtherNotification() {
189 return getNotificationRecord(mOtherId, false /* insistent */, false /* once */,
190 true /* noisy */, false /* buzzy*/, false /* lights */);
191 }
192
Chris Wren93bb8b82016-03-29 14:35:05 -0400193 private NotificationRecord getBeepyOnceNotification() {
194 return getNotificationRecord(mId, false /* insistent */, true /* once */,
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400195 true /* noisy */, false /* buzzy*/, false /* lights */);
Chris Wren93bb8b82016-03-29 14:35:05 -0400196 }
197
198 private NotificationRecord getQuietNotification() {
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400199 return getNotificationRecord(mId, false /* insistent */, true /* once */,
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400200 false /* noisy */, false /* buzzy*/, false /* lights */);
Chris Wren93bb8b82016-03-29 14:35:05 -0400201 }
202
203 private NotificationRecord getQuietOtherNotification() {
204 return getNotificationRecord(mOtherId, false /* insistent */, false /* once */,
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400205 false /* noisy */, false /* buzzy*/, false /* lights */);
Chris Wren93bb8b82016-03-29 14:35:05 -0400206 }
207
208 private NotificationRecord getQuietOnceNotification() {
209 return getNotificationRecord(mId, false /* insistent */, true /* once */,
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400210 false /* noisy */, false /* buzzy*/, false /* lights */);
Chris Wren93bb8b82016-03-29 14:35:05 -0400211 }
212
213 private NotificationRecord getInsistentBeepyNotification() {
214 return getNotificationRecord(mId, true /* insistent */, false /* once */,
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400215 true /* noisy */, false /* buzzy*/, false /* lights */);
Chris Wren93bb8b82016-03-29 14:35:05 -0400216 }
217
Tyler Gunn48f86272018-07-03 12:38:49 -0700218 private NotificationRecord getInsistentBeepyOnceNotification() {
219 return getNotificationRecord(mId, true /* insistent */, true /* once */,
220 true /* noisy */, false /* buzzy*/, false /* lights */);
221 }
222
Tony Mantlerab55f0f2017-06-16 10:50:00 -0700223 private NotificationRecord getInsistentBeepyLeanbackNotification() {
224 return getLeanbackNotificationRecord(mId, true /* insistent */, false /* once */,
225 true /* noisy */, false /* buzzy*/, false /* lights */);
226 }
227
Chris Wren93bb8b82016-03-29 14:35:05 -0400228 private NotificationRecord getBuzzyNotification() {
229 return getNotificationRecord(mId, false /* insistent */, false /* once */,
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400230 false /* noisy */, true /* buzzy*/, false /* lights */);
Chris Wren93bb8b82016-03-29 14:35:05 -0400231 }
232
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400233 private NotificationRecord getBuzzyOtherNotification() {
234 return getNotificationRecord(mOtherId, false /* insistent */, false /* once */,
235 false /* noisy */, true /* buzzy*/, false /* lights */);
236 }
237
Chris Wren93bb8b82016-03-29 14:35:05 -0400238 private NotificationRecord getBuzzyOnceNotification() {
239 return getNotificationRecord(mId, false /* insistent */, true /* once */,
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400240 false /* noisy */, true /* buzzy*/, false /* lights */);
Chris Wren93bb8b82016-03-29 14:35:05 -0400241 }
242
243 private NotificationRecord getInsistentBuzzyNotification() {
244 return getNotificationRecord(mId, true /* insistent */, false /* once */,
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400245 false /* noisy */, true /* buzzy*/, false /* lights */);
246 }
247
Julia Reynolds0c299d42016-11-15 14:37:04 -0500248 private NotificationRecord getBuzzyBeepyNotification() {
249 return getNotificationRecord(mId, false /* insistent */, false /* once */,
250 true /* noisy */, true /* buzzy*/, false /* lights */);
251 }
252
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400253 private NotificationRecord getLightsNotification() {
Julia Reynolds28149f62018-07-03 10:43:35 -0400254 return getNotificationRecord(mId, false /* insistent */, false /* once */,
255 false /* noisy */, false /* buzzy*/, true /* lights */);
256 }
257
258 private NotificationRecord getLightsOnceNotification() {
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400259 return getNotificationRecord(mId, false /* insistent */, true /* once */,
Julia Reynolds28149f62018-07-03 10:43:35 -0400260 false /* noisy */, false /* buzzy*/, true /* lights */);
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400261 }
262
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400263 private NotificationRecord getCallRecord(int id, NotificationChannel channel, boolean looping) {
264 final Builder builder = new Builder(getContext())
265 .setContentTitle("foo")
266 .setSmallIcon(android.R.drawable.sym_def_app_icon)
267 .setPriority(Notification.PRIORITY_HIGH);
268 Notification n = builder.build();
269 if (looping) {
270 n.flags |= Notification.FLAG_INSISTENT;
271 }
272 StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, id, mTag, mUid,
273 mPid, n, mUser, null, System.currentTimeMillis());
274 NotificationRecord r = new NotificationRecord(getContext(), sbn, channel);
275 mService.addNotification(r);
276
277 return r;
Chris Wren93bb8b82016-03-29 14:35:05 -0400278 }
279
280 private NotificationRecord getNotificationRecord(int id, boolean insistent, boolean once,
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400281 boolean noisy, boolean buzzy, boolean lights) {
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400282 return getNotificationRecord(id, insistent, once, noisy, buzzy, lights, buzzy, noisy,
283 lights, null, Notification.GROUP_ALERT_ALL, false);
Tony Mantlerab55f0f2017-06-16 10:50:00 -0700284 }
285
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400286 private NotificationRecord getLeanbackNotificationRecord(int id, boolean insistent,
287 boolean once,
Tony Mantlerab55f0f2017-06-16 10:50:00 -0700288 boolean noisy, boolean buzzy, boolean lights) {
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400289 return getNotificationRecord(id, insistent, once, noisy, buzzy, lights, true, true,
290 true,
Tony Mantlerab55f0f2017-06-16 10:50:00 -0700291 null, Notification.GROUP_ALERT_ALL, true);
Julia Reynoldsa79c3712017-04-21 10:29:57 -0400292 }
293
294 private NotificationRecord getBeepyNotificationRecord(String groupKey, int groupAlertBehavior) {
295 return getNotificationRecord(mId, false, false, true, false, false, true, true, true,
Tony Mantlerab55f0f2017-06-16 10:50:00 -0700296 groupKey, groupAlertBehavior, false);
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400297 }
298
Julia Reynolds28149f62018-07-03 10:43:35 -0400299 private NotificationRecord getLightsNotificationRecord(String groupKey,
300 int groupAlertBehavior) {
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400301 return getNotificationRecord(mId, false, false, false, false, true /*lights*/, true,
302 true, true, groupKey, groupAlertBehavior, false);
Julia Reynolds28149f62018-07-03 10:43:35 -0400303 }
304
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400305 private NotificationRecord getNotificationRecord(int id,
306 boolean insistent, boolean once,
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400307 boolean noisy, boolean buzzy, boolean lights, boolean defaultVibration,
Tony Mantlerab55f0f2017-06-16 10:50:00 -0700308 boolean defaultSound, boolean defaultLights, String groupKey, int groupAlertBehavior,
309 boolean isLeanback) {
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400310
Qiao (Adora) Zhanga9d0bff2019-04-15 17:45:43 +0000311 final Builder builder = new Builder(getContext())
Chris Wren93bb8b82016-03-29 14:35:05 -0400312 .setContentTitle("foo")
313 .setSmallIcon(android.R.drawable.sym_def_app_icon)
314 .setPriority(Notification.PRIORITY_HIGH)
315 .setOnlyAlertOnce(once);
316
317 int defaults = 0;
318 if (noisy) {
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400319 if (defaultSound) {
320 defaults |= Notification.DEFAULT_SOUND;
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400321 mChannel.setSound(Settings.System.DEFAULT_NOTIFICATION_URI,
Julia Reynolds619a69f2017-01-27 15:11:38 -0500322 Notification.AUDIO_ATTRIBUTES_DEFAULT);
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400323 } else {
324 builder.setSound(CUSTOM_SOUND);
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400325 mChannel.setSound(CUSTOM_SOUND, CUSTOM_ATTRIBUTES);
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400326 }
Julia Reynolds184b86d2017-04-12 13:27:58 -0400327 } else {
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400328 mChannel.setSound(null, null);
Chris Wren93bb8b82016-03-29 14:35:05 -0400329 }
330 if (buzzy) {
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400331 if (defaultVibration) {
332 defaults |= Notification.DEFAULT_VIBRATE;
333 } else {
334 builder.setVibrate(CUSTOM_VIBRATION);
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400335 mChannel.setVibrationPattern(CUSTOM_VIBRATION);
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400336 }
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400337 mChannel.enableVibration(true);
338 } else {
339 mChannel.setVibrationPattern(null);
340 mChannel.enableVibration(false);
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400341 }
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400342
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400343 if (lights) {
344 if (defaultLights) {
345 defaults |= Notification.DEFAULT_LIGHTS;
346 } else {
347 builder.setLights(CUSTOM_LIGHT_COLOR, CUSTOM_LIGHT_ON, CUSTOM_LIGHT_OFF);
348 }
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400349 mChannel.enableLights(true);
350 } else {
351 mChannel.enableLights(false);
Chris Wren93bb8b82016-03-29 14:35:05 -0400352 }
353 builder.setDefaults(defaults);
354
Julia Reynoldsa79c3712017-04-21 10:29:57 -0400355 builder.setGroup(groupKey);
356 builder.setGroupAlertBehavior(groupAlertBehavior);
357
Chris Wren93bb8b82016-03-29 14:35:05 -0400358 Notification n = builder.build();
359 if (insistent) {
360 n.flags |= Notification.FLAG_INSISTENT;
361 }
Julia Reynolds0c299d42016-11-15 14:37:04 -0500362
Qiao (Adora) Zhanga9d0bff2019-04-15 17:45:43 +0000363 Context context = spy(getContext());
364 PackageManager packageManager = spy(context.getPackageManager());
365 when(context.getPackageManager()).thenReturn(packageManager);
Tony Mantlerab55f0f2017-06-16 10:50:00 -0700366 when(packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK))
367 .thenReturn(isLeanback);
368
Julia Reynolds924eed12017-01-19 09:52:07 -0500369 StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, id, mTag, mUid,
Julia Reynolds423b9fc2016-11-09 09:51:08 -0500370 mPid, n, mUser, null, System.currentTimeMillis());
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400371 NotificationRecord r = new NotificationRecord(context, sbn, mChannel);
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400372 mService.addNotification(r);
373 return r;
Chris Wren93bb8b82016-03-29 14:35:05 -0400374 }
375
376 //
377 // Convenience functions for interacting with mocks
378 //
379
380 private void verifyNeverBeep() throws RemoteException {
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400381 verify(mRingtonePlayer, never()).playAsync(any(), any(), anyBoolean(), any());
Chris Wren93bb8b82016-03-29 14:35:05 -0400382 }
383
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400384 private void verifyBeepUnlooped() throws RemoteException {
385 verify(mRingtonePlayer, times(1)).playAsync(any(), any(), eq(false), any());
Chris Wren93bb8b82016-03-29 14:35:05 -0400386 }
387
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400388 private void verifyBeepLooped() throws RemoteException {
389 verify(mRingtonePlayer, times(1)).playAsync(any(), any(), eq(true), any());
390 }
391
392 private void verifyBeep(int times) throws RemoteException {
393 verify(mRingtonePlayer, times(times)).playAsync(any(), any(), anyBoolean(), any());
Chris Wren93bb8b82016-03-29 14:35:05 -0400394 }
395
396 private void verifyNeverStopAudio() throws RemoteException {
397 verify(mRingtonePlayer, never()).stopAsync();
398 }
399
400 private void verifyStopAudio() throws RemoteException {
401 verify(mRingtonePlayer, times(1)).stopAsync();
402 }
403
404 private void verifyNeverVibrate() {
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400405 verify(mVibrator, never()).vibrate(anyInt(), anyString(), any(), anyString(), any());
Chris Wren93bb8b82016-03-29 14:35:05 -0400406 }
407
408 private void verifyVibrate() {
Michael Wright71216972017-01-31 18:33:54 +0000409 verify(mVibrator, times(1)).vibrate(anyInt(), anyString(), argThat(mVibrateOnceMatcher),
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400410 anyString(), any());
411 }
412
413 private void verifyVibrate(int times) {
414 verify(mVibrator, times(times)).vibrate(anyInt(), anyString(), any(), anyString(), any());
Chris Wren93bb8b82016-03-29 14:35:05 -0400415 }
416
417 private void verifyVibrateLooped() {
Michael Wright71216972017-01-31 18:33:54 +0000418 verify(mVibrator, times(1)).vibrate(anyInt(), anyString(), argThat(mVibrateLoopMatcher),
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400419 anyString(), any());
Chris Wren93bb8b82016-03-29 14:35:05 -0400420 }
421
Jean-Michel Triviea0eb5f2017-05-25 18:32:40 -0700422 private void verifyDelayedVibrateLooped() {
423 verify(mVibrator, timeout(MAX_VIBRATION_DELAY).times(1)).vibrate(anyInt(), anyString(),
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400424 argThat(mVibrateLoopMatcher), anyString(), any());
425 }
426
427 private void verifyDelayedVibrate() {
428 verify(mVibrator, timeout(MAX_VIBRATION_DELAY).times(1)).vibrate(anyInt(), anyString(),
429 argThat(mVibrateOnceMatcher), anyString(), any());
Jean-Michel Triviea0eb5f2017-05-25 18:32:40 -0700430 }
431
Chris Wren93bb8b82016-03-29 14:35:05 -0400432 private void verifyStopVibrate() {
433 verify(mVibrator, times(1)).cancel();
434 }
435
436 private void verifyNeverStopVibrate() throws RemoteException {
437 verify(mVibrator, never()).cancel();
438 }
439
Julia Reynolds28149f62018-07-03 10:43:35 -0400440 private void verifyNeverLights() {
441 verify(mLight, never()).setFlashing(anyInt(), anyInt(), anyInt(), anyInt());
442 }
443
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400444 private void verifyLights() {
Julia Reynolds033a4122017-01-31 16:50:38 -0500445 verify(mLight, times(1)).setFlashing(anyInt(), anyInt(), anyInt(), anyInt());
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400446 }
447
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400448 //
449 // Tests
450 //
451
452 @Test
453 public void testLights() throws Exception {
454 NotificationRecord r = getLightsNotification();
Julia Reynoldsefcdff42018-08-09 09:42:56 -0400455 r.setSystemImportance(NotificationManager.IMPORTANCE_DEFAULT);
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400456
457 mService.buzzBeepBlinkLocked(r);
458
459 verifyLights();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500460 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500461 assertEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400462 }
463
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400464 @Test
Chris Wren93bb8b82016-03-29 14:35:05 -0400465 public void testBeep() throws Exception {
466 NotificationRecord r = getBeepyNotification();
467
468 mService.buzzBeepBlinkLocked(r);
469
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400470 verifyBeepUnlooped();
Chris Wren93bb8b82016-03-29 14:35:05 -0400471 verifyNeverVibrate();
Julia Reynolds94187562017-10-10 13:58:49 -0400472 verify(mAccessibilityService, times(1)).sendAccessibilityEvent(any(), anyInt());
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500473 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500474 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400475 }
476
Julia Reynoldsb5e44b72016-08-16 15:00:25 -0400477 @Test
Chris Wren93bb8b82016-03-29 14:35:05 -0400478 public void testBeepInsistently() throws Exception {
479 NotificationRecord r = getInsistentBeepyNotification();
480
481 mService.buzzBeepBlinkLocked(r);
482
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400483 verifyBeepLooped();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500484 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500485 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400486 }
487
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400488 @Test
Tony Mantlerab55f0f2017-06-16 10:50:00 -0700489 public void testNoLeanbackBeep() throws Exception {
490 NotificationRecord r = getInsistentBeepyLeanbackNotification();
491
492 mService.buzzBeepBlinkLocked(r);
493
494 verifyNeverBeep();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500495 assertFalse(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500496 assertEquals(-1, r.getLastAudiblyAlertedMs());
Tony Mantlerab55f0f2017-06-16 10:50:00 -0700497 }
498
499 @Test
Qiao (Adora) Zhang47b553c2019-04-15 20:42:57 +0000500 public void testNoBeepForAutomotiveIfEffectsDisabled() throws Exception {
Adora Zhang963328f2018-11-15 18:17:19 -0800501 mService.setIsAutomotive(true);
Qiao (Adora) Zhang47b553c2019-04-15 20:42:57 +0000502 mService.setNotificationEffectsEnabledForAutomotive(false);
503
504 NotificationRecord r = getBeepyNotification();
505 r.setSystemImportance(NotificationManager.IMPORTANCE_HIGH);
506
507 mService.buzzBeepBlinkLocked(r);
508
509 verifyNeverBeep();
510 assertFalse(r.isInterruptive());
511 }
512
513 @Test
514 public void testNoBeepForImportanceDefaultInAutomotiveIfEffectsEnabled() throws Exception {
515 mService.setIsAutomotive(true);
516 mService.setNotificationEffectsEnabledForAutomotive(true);
Adora Zhang963328f2018-11-15 18:17:19 -0800517
518 NotificationRecord r = getBeepyNotification();
519 r.setSystemImportance(NotificationManager.IMPORTANCE_DEFAULT);
520
521 mService.buzzBeepBlinkLocked(r);
522
523 verifyNeverBeep();
524 assertFalse(r.isInterruptive());
525 }
526
527 @Test
Qiao (Adora) Zhang47b553c2019-04-15 20:42:57 +0000528 public void testBeepForImportanceHighInAutomotiveIfEffectsEnabled() throws Exception {
Adora Zhang963328f2018-11-15 18:17:19 -0800529 mService.setIsAutomotive(true);
Qiao (Adora) Zhang47b553c2019-04-15 20:42:57 +0000530 mService.setNotificationEffectsEnabledForAutomotive(true);
Adora Zhang963328f2018-11-15 18:17:19 -0800531
532 NotificationRecord r = getBeepyNotification();
Qiao (Adora) Zhang47b553c2019-04-15 20:42:57 +0000533 r.setSystemImportance(NotificationManager.IMPORTANCE_HIGH);
Adora Zhang963328f2018-11-15 18:17:19 -0800534
535 mService.buzzBeepBlinkLocked(r);
536
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400537 verifyBeepUnlooped();
Adora Zhang963328f2018-11-15 18:17:19 -0800538 assertTrue(r.isInterruptive());
539 }
540
541 @Test
Chris Wren93bb8b82016-03-29 14:35:05 -0400542 public void testNoInterruptionForMin() throws Exception {
543 NotificationRecord r = getBeepyNotification();
Julia Reynoldsefcdff42018-08-09 09:42:56 -0400544 r.setSystemImportance(NotificationManager.IMPORTANCE_MIN);
Chris Wren93bb8b82016-03-29 14:35:05 -0400545
546 mService.buzzBeepBlinkLocked(r);
547
548 verifyNeverBeep();
549 verifyNeverVibrate();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500550 assertFalse(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500551 assertEquals(-1, r.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400552 }
553
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400554 @Test
Chris Wren93bb8b82016-03-29 14:35:05 -0400555 public void testNoInterruptionForIntercepted() throws Exception {
556 NotificationRecord r = getBeepyNotification();
557 r.setIntercepted(true);
558
559 mService.buzzBeepBlinkLocked(r);
560
561 verifyNeverBeep();
562 verifyNeverVibrate();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500563 assertFalse(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500564 assertEquals(-1, r.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400565 }
566
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400567 @Test
Chris Wren93bb8b82016-03-29 14:35:05 -0400568 public void testBeepTwice() throws Exception {
569 NotificationRecord r = getBeepyNotification();
570
571 // set up internal state
572 mService.buzzBeepBlinkLocked(r);
573 Mockito.reset(mRingtonePlayer);
574
575 // update should beep
576 r.isUpdate = true;
577 mService.buzzBeepBlinkLocked(r);
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400578 verifyBeepUnlooped();
Julia Reynolds94187562017-10-10 13:58:49 -0400579 verify(mAccessibilityService, times(2)).sendAccessibilityEvent(any(), anyInt());
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500580 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500581 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400582 }
583
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400584 @Test
Chris Wren93bb8b82016-03-29 14:35:05 -0400585 public void testHonorAlertOnlyOnceForBeep() throws Exception {
586 NotificationRecord r = getBeepyNotification();
587 NotificationRecord s = getBeepyOnceNotification();
588 s.isUpdate = true;
589
590 // set up internal state
591 mService.buzzBeepBlinkLocked(r);
592 Mockito.reset(mRingtonePlayer);
593
594 // update should not beep
595 mService.buzzBeepBlinkLocked(s);
596 verifyNeverBeep();
Julia Reynolds94187562017-10-10 13:58:49 -0400597 verify(mAccessibilityService, times(1)).sendAccessibilityEvent(any(), anyInt());
Chris Wren93bb8b82016-03-29 14:35:05 -0400598 }
599
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400600 @Test
Chris Wren93bb8b82016-03-29 14:35:05 -0400601 public void testNoisyUpdateDoesNotCancelAudio() throws Exception {
602 NotificationRecord r = getBeepyNotification();
603
604 mService.buzzBeepBlinkLocked(r);
605 r.isUpdate = true;
606 mService.buzzBeepBlinkLocked(r);
607
608 verifyNeverStopAudio();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500609 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500610 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400611 }
612
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400613 @Test
Chris Wren93bb8b82016-03-29 14:35:05 -0400614 public void testNoisyOnceUpdateDoesNotCancelAudio() throws Exception {
615 NotificationRecord r = getBeepyNotification();
616 NotificationRecord s = getBeepyOnceNotification();
617 s.isUpdate = true;
618
619 mService.buzzBeepBlinkLocked(r);
620 mService.buzzBeepBlinkLocked(s);
621
622 verifyNeverStopAudio();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500623 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500624 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500625 assertFalse(s.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500626 assertEquals(-1, s.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400627 }
628
Tyler Gunn48f86272018-07-03 12:38:49 -0700629 /**
630 * Tests the case where the user re-posts a {@link Notification} with looping sound where
631 * {@link Notification.Builder#setOnlyAlertOnce(true)} has been called. This should silence
632 * the sound associated with the notification.
633 * @throws Exception
634 */
635 @Test
636 public void testNoisyOnceUpdateDoesCancelAudio() throws Exception {
637 NotificationRecord r = getInsistentBeepyNotification();
638 NotificationRecord s = getInsistentBeepyOnceNotification();
639 s.isUpdate = true;
640
641 mService.buzzBeepBlinkLocked(r);
642 mService.buzzBeepBlinkLocked(s);
643
644 verifyStopAudio();
645 }
646
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400647 @Test
Chris Wren93bb8b82016-03-29 14:35:05 -0400648 public void testQuietUpdateDoesNotCancelAudioFromOther() throws Exception {
649 NotificationRecord r = getBeepyNotification();
650 NotificationRecord s = getQuietNotification();
651 s.isUpdate = true;
652 NotificationRecord other = getNoisyOtherNotification();
653
654 // set up internal state
655 mService.buzzBeepBlinkLocked(r);
656 mService.buzzBeepBlinkLocked(other); // this takes the audio stream
657 Mockito.reset(mRingtonePlayer);
658
659 // should not stop noise, since we no longer own it
660 mService.buzzBeepBlinkLocked(s); // this no longer owns the stream
661 verifyNeverStopAudio();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500662 assertTrue(other.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500663 assertNotEquals(-1, other.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400664 }
665
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400666 @Test
Chris Wren93bb8b82016-03-29 14:35:05 -0400667 public void testQuietInterloperDoesNotCancelAudio() throws Exception {
668 NotificationRecord r = getBeepyNotification();
669 NotificationRecord other = getQuietOtherNotification();
670
671 // set up internal state
672 mService.buzzBeepBlinkLocked(r);
673 Mockito.reset(mRingtonePlayer);
674
675 // should not stop noise, since it does not own it
676 mService.buzzBeepBlinkLocked(other);
677 verifyNeverStopAudio();
678 }
679
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400680 @Test
Chris Wren93bb8b82016-03-29 14:35:05 -0400681 public void testQuietUpdateCancelsAudio() throws Exception {
682 NotificationRecord r = getBeepyNotification();
683 NotificationRecord s = getQuietNotification();
684 s.isUpdate = true;
685
686 // set up internal state
687 mService.buzzBeepBlinkLocked(r);
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500688 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500689 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400690 Mockito.reset(mRingtonePlayer);
691
692 // quiet update should stop making noise
693 mService.buzzBeepBlinkLocked(s);
694 verifyStopAudio();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500695 assertFalse(s.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500696 assertEquals(-1, s.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400697 }
698
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400699 @Test
Chris Wren93bb8b82016-03-29 14:35:05 -0400700 public void testQuietOnceUpdateCancelsAudio() throws Exception {
701 NotificationRecord r = getBeepyNotification();
702 NotificationRecord s = getQuietOnceNotification();
703 s.isUpdate = true;
704
705 // set up internal state
706 mService.buzzBeepBlinkLocked(r);
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500707 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500708 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400709 Mockito.reset(mRingtonePlayer);
710
711 // stop making noise - this is a weird corner case, but quiet should override once
712 mService.buzzBeepBlinkLocked(s);
713 verifyStopAudio();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500714 assertFalse(s.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500715 assertEquals(-1, s.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400716 }
717
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400718 @Test
Beverly5d463b62017-07-26 14:13:40 -0400719 public void testInCallNotification() throws Exception {
720 NotificationRecord r = getBeepyNotification();
721
722 // set up internal state
723 mService.buzzBeepBlinkLocked(r);
724 Mockito.reset(mRingtonePlayer);
725
Eric Laurent7412abc2019-07-12 18:26:29 -0700726 mService.mInCallStateOffHook = true;
Beverly5d463b62017-07-26 14:13:40 -0400727 mService.buzzBeepBlinkLocked(r);
728
Julia Reynolds94187562017-10-10 13:58:49 -0400729 verify(mService, times(1)).playInCallNotification();
Beverly5d463b62017-07-26 14:13:40 -0400730 verifyNeverBeep(); // doesn't play normal beep
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500731 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500732 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Beverly5d463b62017-07-26 14:13:40 -0400733 }
734
735 @Test
Julia Reynolds0c299d42016-11-15 14:37:04 -0500736 public void testNoDemoteSoundToVibrateIfVibrateGiven() throws Exception {
737 NotificationRecord r = getBuzzyBeepyNotification();
738 assertTrue(r.getSound() != null);
Chris Wren93bb8b82016-03-29 14:35:05 -0400739
740 // the phone is quiet
Chris Wren93bb8b82016-03-29 14:35:05 -0400741 when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
Julia Reynolds85896572017-09-20 12:54:52 -0400742 when(mAudioManager.getStreamVolume(anyInt())).thenReturn(0);
Chris Wren93bb8b82016-03-29 14:35:05 -0400743
744 mService.buzzBeepBlinkLocked(r);
745
Michael Wright71216972017-01-31 18:33:54 +0000746 VibrationEffect effect = VibrationEffect.createWaveform(r.getVibration(), -1);
747
Jean-Michel Triviea0eb5f2017-05-25 18:32:40 -0700748 verify(mVibrator, timeout(MAX_VIBRATION_DELAY).times(1)).vibrate(anyInt(), anyString(),
Alexey Kuzmine1f06b82018-06-20 17:48:43 +0100749 eq(effect), anyString(),
750 (AudioAttributes) anyObject());
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500751 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500752 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400753 }
754
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400755 @Test
Julia Reynolds85896572017-09-20 12:54:52 -0400756 public void testNoDemoteSoundToVibrateIfNonNotificationStream() throws Exception {
757 NotificationRecord r = getBeepyNotification();
758 assertTrue(r.getSound() != null);
759 assertNull(r.getVibration());
760
761 // the phone is quiet
762 when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
763 when(mAudioManager.getStreamVolume(anyInt())).thenReturn(1);
764
765 mService.buzzBeepBlinkLocked(r);
766
767 verifyNeverVibrate();
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400768 verifyBeepUnlooped();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500769 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500770 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynolds85896572017-09-20 12:54:52 -0400771 }
772
773 @Test
Julia Reynolds0c299d42016-11-15 14:37:04 -0500774 public void testDemoteSoundToVibrate() throws Exception {
775 NotificationRecord r = getBeepyNotification();
776 assertTrue(r.getSound() != null);
777 assertNull(r.getVibration());
778
779 // the phone is quiet
780 when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
Julia Reynolds85896572017-09-20 12:54:52 -0400781 when(mAudioManager.getStreamVolume(anyInt())).thenReturn(0);
Julia Reynolds0c299d42016-11-15 14:37:04 -0500782
783 mService.buzzBeepBlinkLocked(r);
784
Jean-Michel Triviea0eb5f2017-05-25 18:32:40 -0700785 verify(mVibrator, timeout(MAX_VIBRATION_DELAY).times(1)).vibrate(anyInt(), anyString(),
Alexey Kuzmine1f06b82018-06-20 17:48:43 +0100786 eq(FALLBACK_VIBRATION), anyString(), (AudioAttributes) anyObject());
Julia Reynolds619a69f2017-01-27 15:11:38 -0500787 verify(mRingtonePlayer, never()).playAsync
788 (anyObject(), anyObject(), anyBoolean(), anyObject());
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500789 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500790 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynolds0c299d42016-11-15 14:37:04 -0500791 }
792
793 @Test
794 public void testDemoteInsistentSoundToVibrate() throws Exception {
Chris Wren93bb8b82016-03-29 14:35:05 -0400795 NotificationRecord r = getInsistentBeepyNotification();
Julia Reynolds0c299d42016-11-15 14:37:04 -0500796 assertTrue(r.getSound() != null);
797 assertNull(r.getVibration());
Chris Wren93bb8b82016-03-29 14:35:05 -0400798
799 // the phone is quiet
800 when(mAudioManager.getStreamVolume(anyInt())).thenReturn(0);
801 when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
802
803 mService.buzzBeepBlinkLocked(r);
804
Jean-Michel Triviea0eb5f2017-05-25 18:32:40 -0700805 verifyDelayedVibrateLooped();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500806 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500807 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400808 }
809
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400810 @Test
Chris Wren93bb8b82016-03-29 14:35:05 -0400811 public void testVibrate() throws Exception {
812 NotificationRecord r = getBuzzyNotification();
813
814 mService.buzzBeepBlinkLocked(r);
815
816 verifyNeverBeep();
817 verifyVibrate();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500818 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500819 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400820 }
821
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400822 @Test
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500823 public void testInsistentVibrate() {
Chris Wren93bb8b82016-03-29 14:35:05 -0400824 NotificationRecord r = getInsistentBuzzyNotification();
825
826 mService.buzzBeepBlinkLocked(r);
827 verifyVibrateLooped();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500828 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500829 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400830 }
831
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400832 @Test
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500833 public void testVibrateTwice() {
Chris Wren93bb8b82016-03-29 14:35:05 -0400834 NotificationRecord r = getBuzzyNotification();
835
836 // set up internal state
837 mService.buzzBeepBlinkLocked(r);
838 Mockito.reset(mVibrator);
839
840 // update should vibrate
841 r.isUpdate = true;
842 mService.buzzBeepBlinkLocked(r);
843 verifyVibrate();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500844 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500845 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400846 }
847
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400848 @Test
Julia Reynolds65031622020-02-27 09:11:25 -0500849 public void testPostSilently() throws Exception {
850 NotificationRecord r = getBuzzyNotification();
851 r.setPostSilently(true);
852
853 mService.buzzBeepBlinkLocked(r);
854
855 verifyNeverBeep();
856 assertFalse(r.isInterruptive());
857 assertEquals(-1, r.getLastAudiblyAlertedMs());
858 }
859
860 @Test
Julia Reynoldsa79c3712017-04-21 10:29:57 -0400861 public void testGroupAlertSummarySilenceChild() throws Exception {
862 NotificationRecord child = getBeepyNotificationRecord("a", GROUP_ALERT_SUMMARY);
863
864 mService.buzzBeepBlinkLocked(child);
865
866 verifyNeverBeep();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500867 assertFalse(child.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500868 assertEquals(-1, child.getLastAudiblyAlertedMs());
Julia Reynoldsa79c3712017-04-21 10:29:57 -0400869 }
870
871 @Test
872 public void testGroupAlertSummaryNoSilenceSummary() throws Exception {
873 NotificationRecord summary = getBeepyNotificationRecord("a", GROUP_ALERT_SUMMARY);
874 summary.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY;
875
876 mService.buzzBeepBlinkLocked(summary);
877
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400878 verifyBeepUnlooped();
Julia Reynolds28149f62018-07-03 10:43:35 -0400879 // summaries are never interruptive for notification counts
880 assertFalse(summary.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500881 assertNotEquals(-1, summary.getLastAudiblyAlertedMs());
Julia Reynoldsa79c3712017-04-21 10:29:57 -0400882 }
883
884 @Test
885 public void testGroupAlertSummaryNoSilenceNonGroupChild() throws Exception {
886 NotificationRecord nonGroup = getBeepyNotificationRecord(null, GROUP_ALERT_SUMMARY);
887
888 mService.buzzBeepBlinkLocked(nonGroup);
889
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400890 verifyBeepUnlooped();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500891 assertTrue(nonGroup.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500892 assertNotEquals(-1, nonGroup.getLastAudiblyAlertedMs());
Julia Reynoldsa79c3712017-04-21 10:29:57 -0400893 }
894
895 @Test
896 public void testGroupAlertChildSilenceSummary() throws Exception {
897 NotificationRecord summary = getBeepyNotificationRecord("a", GROUP_ALERT_CHILDREN);
898 summary.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY;
899
900 mService.buzzBeepBlinkLocked(summary);
901
902 verifyNeverBeep();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500903 assertFalse(summary.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500904 assertEquals(-1, summary.getLastAudiblyAlertedMs());
Julia Reynoldsa79c3712017-04-21 10:29:57 -0400905 }
906
907 @Test
908 public void testGroupAlertChildNoSilenceChild() throws Exception {
909 NotificationRecord child = getBeepyNotificationRecord("a", GROUP_ALERT_CHILDREN);
910
911 mService.buzzBeepBlinkLocked(child);
912
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400913 verifyBeepUnlooped();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500914 assertTrue(child.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500915 assertNotEquals(-1, child.getLastAudiblyAlertedMs());
Julia Reynoldsa79c3712017-04-21 10:29:57 -0400916 }
917
918 @Test
919 public void testGroupAlertChildNoSilenceNonGroupSummary() throws Exception {
920 NotificationRecord nonGroup = getBeepyNotificationRecord(null, GROUP_ALERT_CHILDREN);
921
922 mService.buzzBeepBlinkLocked(nonGroup);
923
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400924 verifyBeepUnlooped();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500925 assertTrue(nonGroup.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500926 assertNotEquals(-1, nonGroup.getLastAudiblyAlertedMs());
Julia Reynoldsa79c3712017-04-21 10:29:57 -0400927 }
928
929 @Test
930 public void testGroupAlertAllNoSilenceGroup() throws Exception {
931 NotificationRecord group = getBeepyNotificationRecord("a", GROUP_ALERT_ALL);
932
933 mService.buzzBeepBlinkLocked(group);
934
Julia Reynolds714ff5f2019-10-14 11:19:53 -0400935 verifyBeepUnlooped();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500936 assertTrue(group.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500937 assertNotEquals(-1, group.getLastAudiblyAlertedMs());
Julia Reynoldsa79c3712017-04-21 10:29:57 -0400938 }
939
940 @Test
Chris Wren93bb8b82016-03-29 14:35:05 -0400941 public void testHonorAlertOnlyOnceForBuzz() throws Exception {
942 NotificationRecord r = getBuzzyNotification();
943 NotificationRecord s = getBuzzyOnceNotification();
944 s.isUpdate = true;
945
946 // set up internal state
947 mService.buzzBeepBlinkLocked(r);
948 Mockito.reset(mVibrator);
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500949 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500950 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400951
952 // update should not beep
953 mService.buzzBeepBlinkLocked(s);
954 verifyNeverVibrate();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500955 assertFalse(s.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500956 assertEquals(-1, s.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400957 }
958
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400959 @Test
Chris Wren93bb8b82016-03-29 14:35:05 -0400960 public void testNoisyUpdateDoesNotCancelVibrate() throws Exception {
961 NotificationRecord r = getBuzzyNotification();
962
963 mService.buzzBeepBlinkLocked(r);
964 r.isUpdate = true;
965 mService.buzzBeepBlinkLocked(r);
966
967 verifyNeverStopVibrate();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500968 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500969 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400970 }
971
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400972 @Test
Chris Wren93bb8b82016-03-29 14:35:05 -0400973 public void testNoisyOnceUpdateDoesNotCancelVibrate() throws Exception {
974 NotificationRecord r = getBuzzyNotification();
975 NotificationRecord s = getBuzzyOnceNotification();
976 s.isUpdate = true;
977
978 mService.buzzBeepBlinkLocked(r);
979 mService.buzzBeepBlinkLocked(s);
980
981 verifyNeverStopVibrate();
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500982 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500983 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynolds1fac86e2018-03-07 08:30:37 -0500984 assertFalse(s.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -0500985 assertEquals(-1, s.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -0400986 }
987
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -0400988 @Test
Chris Wren93bb8b82016-03-29 14:35:05 -0400989 public void testQuietUpdateDoesNotCancelVibrateFromOther() throws Exception {
990 NotificationRecord r = getBuzzyNotification();
991 NotificationRecord s = getQuietNotification();
992 s.isUpdate = true;
993 NotificationRecord other = getNoisyOtherNotification();
994
995 // set up internal state
996 mService.buzzBeepBlinkLocked(r);
997 mService.buzzBeepBlinkLocked(other); // this takes the vibrate stream
998 Mockito.reset(mVibrator);
999
1000 // should not stop vibrate, since we no longer own it
1001 mService.buzzBeepBlinkLocked(s); // this no longer owns the stream
1002 verifyNeverStopVibrate();
Julia Reynolds1fac86e2018-03-07 08:30:37 -05001003 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001004 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynolds1fac86e2018-03-07 08:30:37 -05001005 assertTrue(other.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001006 assertNotEquals(-1, other.getLastAudiblyAlertedMs());
Julia Reynolds1fac86e2018-03-07 08:30:37 -05001007 assertFalse(s.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001008 assertEquals(-1, s.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -04001009 }
1010
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -04001011 @Test
Chris Wren93bb8b82016-03-29 14:35:05 -04001012 public void testQuietInterloperDoesNotCancelVibrate() throws Exception {
1013 NotificationRecord r = getBuzzyNotification();
1014 NotificationRecord other = getQuietOtherNotification();
1015
1016 // set up internal state
1017 mService.buzzBeepBlinkLocked(r);
1018 Mockito.reset(mVibrator);
1019
1020 // should not stop noise, since it does not own it
1021 mService.buzzBeepBlinkLocked(other);
1022 verifyNeverStopVibrate();
Julia Reynolds1fac86e2018-03-07 08:30:37 -05001023 assertFalse(other.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001024 assertEquals(-1, other.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -04001025 }
1026
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -04001027 @Test
Julia Reynolds1fac86e2018-03-07 08:30:37 -05001028 public void testQuietUpdateCancelsVibrate() {
Chris Wren93bb8b82016-03-29 14:35:05 -04001029 NotificationRecord r = getBuzzyNotification();
1030 NotificationRecord s = getQuietNotification();
1031 s.isUpdate = true;
1032
1033 // set up internal state
1034 mService.buzzBeepBlinkLocked(r);
Julia Reynolds0c299d42016-11-15 14:37:04 -05001035 verifyVibrate();
Chris Wren93bb8b82016-03-29 14:35:05 -04001036
1037 // quiet update should stop making noise
1038 mService.buzzBeepBlinkLocked(s);
1039 verifyStopVibrate();
Julia Reynolds1fac86e2018-03-07 08:30:37 -05001040 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001041 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynolds1fac86e2018-03-07 08:30:37 -05001042 assertFalse(s.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001043 assertEquals(-1, s.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -04001044 }
1045
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -04001046 @Test
Julia Reynolds0c299d42016-11-15 14:37:04 -05001047 public void testQuietOnceUpdateCancelVibrate() throws Exception {
Chris Wren93bb8b82016-03-29 14:35:05 -04001048 NotificationRecord r = getBuzzyNotification();
1049 NotificationRecord s = getQuietOnceNotification();
1050 s.isUpdate = true;
1051
1052 // set up internal state
1053 mService.buzzBeepBlinkLocked(r);
Julia Reynolds0c299d42016-11-15 14:37:04 -05001054 verifyVibrate();
Chris Wren93bb8b82016-03-29 14:35:05 -04001055
1056 // stop making noise - this is a weird corner case, but quiet should override once
1057 mService.buzzBeepBlinkLocked(s);
1058 verifyStopVibrate();
Julia Reynolds1fac86e2018-03-07 08:30:37 -05001059 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001060 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynolds1fac86e2018-03-07 08:30:37 -05001061 assertFalse(s.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001062 assertEquals(-1, s.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -04001063 }
1064
Geoffrey Pitsch0ffe7552016-08-29 10:07:40 -04001065 @Test
Chris Wren93bb8b82016-03-29 14:35:05 -04001066 public void testQuietUpdateCancelsDemotedVibrate() throws Exception {
1067 NotificationRecord r = getBeepyNotification();
1068 NotificationRecord s = getQuietNotification();
1069
1070 // the phone is quiet
1071 when(mAudioManager.getStreamVolume(anyInt())).thenReturn(0);
1072 when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
1073
1074 mService.buzzBeepBlinkLocked(r);
1075
1076 // quiet update should stop making noise
1077 mService.buzzBeepBlinkLocked(s);
1078 verifyStopVibrate();
Julia Reynolds1fac86e2018-03-07 08:30:37 -05001079 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001080 assertNotEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynolds1fac86e2018-03-07 08:30:37 -05001081 assertFalse(s.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001082 assertEquals(-1, s.getLastAudiblyAlertedMs());
Chris Wren93bb8b82016-03-29 14:35:05 -04001083 }
Michael Wright71216972017-01-31 18:33:54 +00001084
Julia Reynoldsca80d162017-04-23 12:39:32 -04001085 @Test
1086 public void testEmptyUriSoundTreatedAsNoSound() throws Exception {
1087 NotificationChannel channel = new NotificationChannel("test", "test", IMPORTANCE_HIGH);
1088 channel.setSound(Uri.EMPTY, null);
Qiao (Adora) Zhanga9d0bff2019-04-15 17:45:43 +00001089 final Notification n = new Builder(getContext(), "test")
Julia Reynoldsca80d162017-04-23 12:39:32 -04001090 .setSmallIcon(android.R.drawable.sym_def_app_icon).build();
1091
1092 StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 0, mTag, mUid,
1093 mPid, n, mUser, null, System.currentTimeMillis());
Qiao (Adora) Zhanga9d0bff2019-04-15 17:45:43 +00001094 NotificationRecord r = new NotificationRecord(getContext(), sbn, channel);
Julia Reynoldsca80d162017-04-23 12:39:32 -04001095 mService.addNotification(r);
1096
1097 mService.buzzBeepBlinkLocked(r);
Julia Reynoldsca80d162017-04-23 12:39:32 -04001098 verifyNeverBeep();
Julia Reynolds1fac86e2018-03-07 08:30:37 -05001099 assertFalse(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001100 assertEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynoldsca80d162017-04-23 12:39:32 -04001101 }
1102
Julia Reynolds76c096d2017-06-19 08:16:04 -04001103 @Test
1104 public void testRepeatedSoundOverLimitMuted() throws Exception {
1105 when(mUsageStats.isAlertRateLimited(any())).thenReturn(true);
1106
1107 NotificationRecord r = getBeepyNotification();
1108
1109 mService.buzzBeepBlinkLocked(r);
1110 verifyNeverBeep();
Julia Reynolds1fac86e2018-03-07 08:30:37 -05001111 assertFalse(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001112 assertEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynolds76c096d2017-06-19 08:16:04 -04001113 }
1114
1115 @Test
1116 public void testPostingSilentNotificationDoesNotAffectRateLimiting() throws Exception {
1117 NotificationRecord r = getQuietNotification();
1118 mService.buzzBeepBlinkLocked(r);
1119
1120 verify(mUsageStats, never()).isAlertRateLimited(any());
1121 }
1122
1123 @Test
Julia Reynolds65b85cf2017-07-20 09:19:20 -04001124 public void testPostingGroupSuppressedDoesNotAffectRateLimiting() throws Exception {
1125 NotificationRecord summary = getBeepyNotificationRecord("a", GROUP_ALERT_CHILDREN);
1126 summary.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY;
1127
1128 mService.buzzBeepBlinkLocked(summary);
Julia Reynolds65b85cf2017-07-20 09:19:20 -04001129 verify(mUsageStats, never()).isAlertRateLimited(any());
1130 }
1131
1132 @Test
Julia Reynolds79dfdd62018-04-17 15:36:33 -04001133 public void testGroupSuppressionFailureDoesNotAffectRateLimiting() {
1134 NotificationRecord summary = getBeepyNotificationRecord("a", GROUP_ALERT_SUMMARY);
1135 summary.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY;
1136
1137 mService.buzzBeepBlinkLocked(summary);
1138 verify(mUsageStats, times(1)).isAlertRateLimited(any());
1139 }
1140
1141 @Test
Julia Reynolds76c096d2017-06-19 08:16:04 -04001142 public void testCrossUserSoundMuted() throws Exception {
Qiao (Adora) Zhanga9d0bff2019-04-15 17:45:43 +00001143 final Notification n = new Builder(getContext(), "test")
Julia Reynolds76c096d2017-06-19 08:16:04 -04001144 .setSmallIcon(android.R.drawable.sym_def_app_icon).build();
1145
1146 int userId = mUser.getIdentifier() + 1;
1147 StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 0, mTag, mUid,
1148 mPid, n, UserHandle.of(userId), null, System.currentTimeMillis());
Qiao (Adora) Zhanga9d0bff2019-04-15 17:45:43 +00001149 NotificationRecord r = new NotificationRecord(getContext(), sbn,
Julia Reynolds76c096d2017-06-19 08:16:04 -04001150 new NotificationChannel("test", "test", IMPORTANCE_HIGH));
1151
1152 mService.buzzBeepBlinkLocked(r);
1153 verifyNeverBeep();
Julia Reynolds1fac86e2018-03-07 08:30:37 -05001154 assertFalse(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001155 assertEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynolds76c096d2017-06-19 08:16:04 -04001156 }
1157
Julia Reynolds94187562017-10-10 13:58:49 -04001158 @Test
1159 public void testA11yMinInitialPost() throws Exception {
1160 NotificationRecord r = getQuietNotification();
Julia Reynoldsefcdff42018-08-09 09:42:56 -04001161 r.setSystemImportance(IMPORTANCE_MIN);
Julia Reynolds94187562017-10-10 13:58:49 -04001162 mService.buzzBeepBlinkLocked(r);
1163 verify(mAccessibilityService, never()).sendAccessibilityEvent(any(), anyInt());
1164 }
1165
1166 @Test
1167 public void testA11yQuietInitialPost() throws Exception {
1168 NotificationRecord r = getQuietNotification();
1169 mService.buzzBeepBlinkLocked(r);
1170 verify(mAccessibilityService, times(1)).sendAccessibilityEvent(any(), anyInt());
1171 }
1172
1173 @Test
1174 public void testA11yQuietUpdate() throws Exception {
1175 NotificationRecord r = getQuietNotification();
1176 mService.buzzBeepBlinkLocked(r);
1177 r.isUpdate = true;
1178 mService.buzzBeepBlinkLocked(r);
1179 verify(mAccessibilityService, times(1)).sendAccessibilityEvent(any(), anyInt());
1180 }
1181
Julia Reynolds28149f62018-07-03 10:43:35 -04001182 @Test
1183 public void testLightsScreenOn() {
1184 mService.mScreenOn = true;
1185 NotificationRecord r = getLightsNotification();
1186 mService.buzzBeepBlinkLocked(r);
1187 verifyNeverLights();
1188 assertFalse(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001189 assertEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynolds28149f62018-07-03 10:43:35 -04001190 }
1191
1192 @Test
1193 public void testLightsInCall() {
Eric Laurent7412abc2019-07-12 18:26:29 -07001194 mService.mInCallStateOffHook = true;
Julia Reynolds28149f62018-07-03 10:43:35 -04001195 NotificationRecord r = getLightsNotification();
1196 mService.buzzBeepBlinkLocked(r);
1197 verifyNeverLights();
1198 assertFalse(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001199 assertEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynolds28149f62018-07-03 10:43:35 -04001200 }
1201
1202 @Test
1203 public void testLightsSilentUpdate() {
1204 NotificationRecord r = getLightsOnceNotification();
1205 mService.buzzBeepBlinkLocked(r);
1206 verifyLights();
1207 assertTrue(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001208 assertEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynolds28149f62018-07-03 10:43:35 -04001209
1210 r = getLightsOnceNotification();
1211 r.isUpdate = true;
1212 mService.buzzBeepBlinkLocked(r);
1213 // checks that lights happened once, i.e. this new call didn't trigger them again
1214 verifyLights();
1215 assertFalse(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001216 assertEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynolds28149f62018-07-03 10:43:35 -04001217 }
1218
1219 @Test
1220 public void testLightsUnimportant() {
1221 NotificationRecord r = getLightsNotification();
Julia Reynoldsefcdff42018-08-09 09:42:56 -04001222 r.setSystemImportance(IMPORTANCE_LOW);
Julia Reynolds28149f62018-07-03 10:43:35 -04001223 mService.buzzBeepBlinkLocked(r);
1224 verifyNeverLights();
1225 assertFalse(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001226 assertEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynolds28149f62018-07-03 10:43:35 -04001227 }
1228
1229 @Test
1230 public void testLightsNoLights() {
1231 NotificationRecord r = getQuietNotification();
1232 mService.buzzBeepBlinkLocked(r);
1233 verifyNeverLights();
1234 assertFalse(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001235 assertEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynolds28149f62018-07-03 10:43:35 -04001236 }
1237
1238 @Test
1239 public void testLightsNoLightOnDevice() {
1240 mService.mHasLight = false;
1241 NotificationRecord r = getLightsNotification();
1242 mService.buzzBeepBlinkLocked(r);
1243 verifyNeverLights();
1244 assertFalse(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001245 assertEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynolds28149f62018-07-03 10:43:35 -04001246 }
1247
1248 @Test
1249 public void testLightsLightsOffGlobally() {
1250 mService.mNotificationPulseEnabled = false;
1251 NotificationRecord r = getLightsNotification();
1252 mService.buzzBeepBlinkLocked(r);
1253 verifyNeverLights();
1254 assertFalse(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001255 assertEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynolds28149f62018-07-03 10:43:35 -04001256 }
1257
1258 @Test
1259 public void testLightsDndIntercepted() {
1260 NotificationRecord r = getLightsNotification();
1261 r.setSuppressedVisualEffects(SUPPRESSED_EFFECT_LIGHTS);
1262 mService.buzzBeepBlinkLocked(r);
1263 verifyNeverLights();
1264 assertFalse(r.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001265 assertEquals(-1, r.getLastAudiblyAlertedMs());
Julia Reynolds28149f62018-07-03 10:43:35 -04001266 }
1267
1268 @Test
1269 public void testGroupAlertSummaryNoLightsChild() {
1270 NotificationRecord child = getLightsNotificationRecord("a", GROUP_ALERT_SUMMARY);
1271
1272 mService.buzzBeepBlinkLocked(child);
1273
1274 verifyNeverLights();
1275 assertFalse(child.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001276 assertEquals(-1, child.getLastAudiblyAlertedMs());
Julia Reynolds28149f62018-07-03 10:43:35 -04001277 }
1278
1279 @Test
1280 public void testGroupAlertSummaryLightsSummary() {
1281 NotificationRecord summary = getLightsNotificationRecord("a", GROUP_ALERT_SUMMARY);
1282 summary.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY;
1283
1284 mService.buzzBeepBlinkLocked(summary);
1285
1286 verifyLights();
1287 // summaries should never count for interruptiveness counts
1288 assertFalse(summary.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001289 assertEquals(-1, summary.getLastAudiblyAlertedMs());
Julia Reynolds28149f62018-07-03 10:43:35 -04001290 }
1291
1292 @Test
1293 public void testGroupAlertSummaryLightsNonGroupChild() {
1294 NotificationRecord nonGroup = getLightsNotificationRecord(null, GROUP_ALERT_SUMMARY);
1295
1296 mService.buzzBeepBlinkLocked(nonGroup);
1297
1298 verifyLights();
1299 assertTrue(nonGroup.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001300 assertEquals(-1, nonGroup.getLastAudiblyAlertedMs());
Julia Reynolds28149f62018-07-03 10:43:35 -04001301 }
1302
1303 @Test
1304 public void testGroupAlertChildNoLightsSummary() {
1305 NotificationRecord summary = getLightsNotificationRecord("a", GROUP_ALERT_CHILDREN);
1306 summary.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY;
1307
1308 mService.buzzBeepBlinkLocked(summary);
1309
1310 verifyNeverLights();
1311 assertFalse(summary.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001312 assertEquals(-1, summary.getLastAudiblyAlertedMs());
Julia Reynolds28149f62018-07-03 10:43:35 -04001313 }
1314
1315 @Test
1316 public void testGroupAlertChildLightsChild() {
1317 NotificationRecord child = getLightsNotificationRecord("a", GROUP_ALERT_CHILDREN);
1318
1319 mService.buzzBeepBlinkLocked(child);
1320
1321 verifyLights();
1322 assertTrue(child.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001323 assertEquals(-1, child.getLastAudiblyAlertedMs());
Julia Reynolds28149f62018-07-03 10:43:35 -04001324 }
1325
1326 @Test
1327 public void testGroupAlertChildLightsNonGroupSummary() {
1328 NotificationRecord nonGroup = getLightsNotificationRecord(null, GROUP_ALERT_CHILDREN);
1329
1330 mService.buzzBeepBlinkLocked(nonGroup);
1331
1332 verifyLights();
1333 assertTrue(nonGroup.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001334 assertEquals(-1, nonGroup.getLastAudiblyAlertedMs());
Julia Reynolds28149f62018-07-03 10:43:35 -04001335 }
1336
1337 @Test
1338 public void testGroupAlertAllLightsGroup() {
1339 NotificationRecord group = getLightsNotificationRecord("a", GROUP_ALERT_ALL);
1340
1341 mService.buzzBeepBlinkLocked(group);
1342
1343 verifyLights();
1344 assertTrue(group.isInterruptive());
Gus Prevas7306b902018-12-11 10:57:06 -05001345 assertEquals(-1, group.getLastAudiblyAlertedMs());
Julia Reynolds28149f62018-07-03 10:43:35 -04001346 }
1347
Julia Reynoldsdb7081e2019-01-03 14:35:38 -05001348 @Test
1349 public void testListenerHintCall() throws Exception {
Julia Reynolds714ff5f2019-10-14 11:19:53 -04001350 NotificationChannel ringtoneChannel =
1351 new NotificationChannel("ringtone", "", IMPORTANCE_HIGH);
1352 ringtoneChannel.setSound(Settings.System.DEFAULT_RINGTONE_URI,
1353 new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE).build());
1354 NotificationRecord r = getCallRecord(1, ringtoneChannel, true);
Julia Reynoldsdb7081e2019-01-03 14:35:38 -05001355
1356 mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS);
1357
1358 mService.buzzBeepBlinkLocked(r);
1359
1360 verifyNeverBeep();
1361 }
1362
1363 @Test
1364 public void testListenerHintCall_notificationSound() throws Exception {
1365 NotificationRecord r = getBeepyNotification();
1366
1367 mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS);
1368
1369 mService.buzzBeepBlinkLocked(r);
1370
Julia Reynolds714ff5f2019-10-14 11:19:53 -04001371 verifyBeepUnlooped();
Julia Reynoldsdb7081e2019-01-03 14:35:38 -05001372 }
1373
1374 @Test
1375 public void testListenerHintNotification() throws Exception {
1376 NotificationRecord r = getBeepyNotification();
1377
1378 mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS);
1379
1380 mService.buzzBeepBlinkLocked(r);
1381
1382 verifyNeverBeep();
1383 }
1384
1385 @Test
1386 public void testListenerHintBoth() throws Exception {
Julia Reynolds714ff5f2019-10-14 11:19:53 -04001387 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 Reynoldsdb7081e2019-01-03 14:35:38 -05001392 NotificationRecord s = getBeepyNotification();
1393
1394 mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS
1395 | NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS);
1396
1397 mService.buzzBeepBlinkLocked(r);
1398 mService.buzzBeepBlinkLocked(s);
1399
1400 verifyNeverBeep();
1401 }
1402
1403 @Test
1404 public void testListenerHintNotification_callSound() throws Exception {
Julia Reynolds714ff5f2019-10-14 11:19:53 -04001405 NotificationChannel ringtoneChannel =
1406 new NotificationChannel("ringtone", "", IMPORTANCE_HIGH);
1407 ringtoneChannel.setSound(Settings.System.DEFAULT_RINGTONE_URI,
1408 new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE).build());
1409 NotificationRecord r = getCallRecord(1, ringtoneChannel, true);
Julia Reynoldsdb7081e2019-01-03 14:35:38 -05001410
1411 mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS);
1412
1413 mService.buzzBeepBlinkLocked(r);
1414
1415 verifyBeepLooped();
1416 }
1417
Julia Reynolds714ff5f2019-10-14 11:19:53 -04001418 @Test
1419 public void testCannotInterruptRingtoneInsistentBeep() throws Exception {
1420 NotificationChannel ringtoneChannel =
1421 new NotificationChannel("ringtone", "", IMPORTANCE_HIGH);
1422 ringtoneChannel.setSound(Settings.System.DEFAULT_RINGTONE_URI,
1423 new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE).build());
1424 NotificationRecord ringtoneNotification = getCallRecord(1, ringtoneChannel, true);
1425 mService.addNotification(ringtoneNotification);
1426
1427 mService.buzzBeepBlinkLocked(ringtoneNotification);
1428 verifyBeepLooped();
1429
1430 NotificationRecord interrupter = getBeepyOtherNotification();
1431 assertTrue(mService.shouldMuteNotificationLocked(interrupter));
1432 mService.buzzBeepBlinkLocked(interrupter);
1433
1434 verifyBeep(1);
1435
1436 assertFalse(interrupter.isInterruptive());
1437 assertEquals(-1, interrupter.getLastAudiblyAlertedMs());
1438 }
1439
1440 @Test
1441 public void testCannotInterruptRingtoneInsistentBuzz() {
1442 NotificationChannel ringtoneChannel =
1443 new NotificationChannel("ringtone", "", IMPORTANCE_HIGH);
1444 ringtoneChannel.setSound(Uri.EMPTY,
1445 new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE).build());
1446 ringtoneChannel.enableVibration(true);
1447 NotificationRecord ringtoneNotification = getCallRecord(1, ringtoneChannel, true);
1448 assertFalse(mService.shouldMuteNotificationLocked(ringtoneNotification));
1449
1450 mService.buzzBeepBlinkLocked(ringtoneNotification);
1451 verifyVibrateLooped();
1452
1453 NotificationRecord interrupter = getBuzzyOtherNotification();
1454 assertTrue(mService.shouldMuteNotificationLocked(interrupter));
1455 mService.buzzBeepBlinkLocked(interrupter);
1456
1457 verifyVibrate(1);
1458
1459 assertFalse(interrupter.isInterruptive());
1460 assertEquals(-1, interrupter.getLastAudiblyAlertedMs());
1461 }
1462
1463 @Test
1464 public void testCanInterruptRingtoneNonInsistentBeep() throws Exception {
1465 NotificationChannel ringtoneChannel =
1466 new NotificationChannel("ringtone", "", IMPORTANCE_HIGH);
1467 ringtoneChannel.setSound(Settings.System.DEFAULT_RINGTONE_URI,
1468 new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE).build());
1469 NotificationRecord ringtoneNotification = getCallRecord(1, ringtoneChannel, false);
1470
1471 mService.buzzBeepBlinkLocked(ringtoneNotification);
1472 verifyBeepUnlooped();
1473
1474 NotificationRecord interrupter = getBeepyOtherNotification();
1475 mService.buzzBeepBlinkLocked(interrupter);
1476
1477 verifyBeep(2);
1478
1479 assertTrue(interrupter.isInterruptive());
1480 }
1481
1482 @Test
1483 public void testCanInterruptRingtoneNonInsistentBuzz() {
1484 NotificationChannel ringtoneChannel =
1485 new NotificationChannel("ringtone", "", IMPORTANCE_HIGH);
1486 ringtoneChannel.setSound(null,
1487 new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE).build());
1488 ringtoneChannel.enableVibration(true);
1489 NotificationRecord ringtoneNotification = getCallRecord(1, ringtoneChannel, false);
1490
1491 mService.buzzBeepBlinkLocked(ringtoneNotification);
1492 verifyVibrate();
1493
1494 NotificationRecord interrupter = getBuzzyOtherNotification();
1495 mService.buzzBeepBlinkLocked(interrupter);
1496
1497 verifyVibrate(2);
1498
1499 assertTrue(interrupter.isInterruptive());
1500 }
1501
1502 @Test
1503 public void testRingtoneInsistentBeep_doesNotBlockFutureSoundsOnceStopped() throws Exception {
1504 NotificationChannel ringtoneChannel =
1505 new NotificationChannel("ringtone", "", IMPORTANCE_HIGH);
1506 ringtoneChannel.setSound(Settings.System.DEFAULT_RINGTONE_URI,
1507 new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE).build());
1508 NotificationRecord ringtoneNotification = getCallRecord(1, ringtoneChannel, true);
1509
1510 mService.buzzBeepBlinkLocked(ringtoneNotification);
1511 verifyBeepLooped();
1512
1513 mService.clearSoundLocked();
1514
1515 NotificationRecord interrupter = getBeepyOtherNotification();
1516 mService.buzzBeepBlinkLocked(interrupter);
1517
1518 verifyBeep(2);
1519
1520 assertTrue(interrupter.isInterruptive());
1521 }
1522
1523 @Test
1524 public void testRingtoneInsistentBuzz_doesNotBlockFutureSoundsOnceStopped() {
1525 NotificationChannel ringtoneChannel =
1526 new NotificationChannel("ringtone", "", IMPORTANCE_HIGH);
1527 ringtoneChannel.setSound(null,
1528 new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE).build());
1529 ringtoneChannel.enableVibration(true);
1530 NotificationRecord ringtoneNotification = getCallRecord(1, ringtoneChannel, true);
1531
1532 mService.buzzBeepBlinkLocked(ringtoneNotification);
1533 verifyVibrateLooped();
1534
1535 mService.clearVibrateLocked();
1536
1537 NotificationRecord interrupter = getBuzzyOtherNotification();
1538 mService.buzzBeepBlinkLocked(interrupter);
1539
1540 verifyVibrate(2);
1541
1542 assertTrue(interrupter.isInterruptive());
1543 }
1544
1545 @Test
1546 public void testCanInterruptNonRingtoneInsistentBeep() throws Exception {
1547 NotificationChannel fakeRingtoneChannel =
1548 new NotificationChannel("ringtone", "", IMPORTANCE_HIGH);
1549 NotificationRecord ringtoneNotification = getCallRecord(1, fakeRingtoneChannel, true);
1550
1551 mService.buzzBeepBlinkLocked(ringtoneNotification);
1552 verifyBeepLooped();
1553
1554 NotificationRecord interrupter = getBeepyOtherNotification();
1555 mService.buzzBeepBlinkLocked(interrupter);
1556
1557 verifyBeep(2);
1558
1559 assertTrue(interrupter.isInterruptive());
1560 }
1561
1562 @Test
Julia Reynolds181ff7c2019-10-18 12:16:31 -04001563 public void testCanInterruptNonRingtoneInsistentBuzz() {
Julia Reynolds714ff5f2019-10-14 11:19:53 -04001564 NotificationChannel fakeRingtoneChannel =
1565 new NotificationChannel("ringtone", "", IMPORTANCE_HIGH);
1566 fakeRingtoneChannel.enableVibration(true);
Julia Reynolds181ff7c2019-10-18 12:16:31 -04001567 fakeRingtoneChannel.setSound(null,
1568 new AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION).build());
Julia Reynolds714ff5f2019-10-14 11:19:53 -04001569 NotificationRecord ringtoneNotification = getCallRecord(1, fakeRingtoneChannel, true);
1570
1571 mService.buzzBeepBlinkLocked(ringtoneNotification);
1572
1573 NotificationRecord interrupter = getBuzzyOtherNotification();
1574 mService.buzzBeepBlinkLocked(interrupter);
1575
1576 verifyVibrate(2);
1577
1578 assertTrue(interrupter.isInterruptive());
1579 }
1580
Michael Wright71216972017-01-31 18:33:54 +00001581 static class VibrateRepeatMatcher implements ArgumentMatcher<VibrationEffect> {
1582 private final int mRepeatIndex;
1583
1584 VibrateRepeatMatcher(int repeatIndex) {
1585 mRepeatIndex = repeatIndex;
1586 }
1587
1588 @Override
1589 public boolean matches(VibrationEffect actual) {
1590 if (actual instanceof VibrationEffect.Waveform &&
1591 ((VibrationEffect.Waveform) actual).getRepeatIndex() == mRepeatIndex) {
1592 return true;
1593 }
1594 // All non-waveform effects are essentially one shots.
1595 return mRepeatIndex == -1;
1596 }
1597
1598 @Override
1599 public String toString() {
1600 return "repeatIndex=" + mRepeatIndex;
1601 }
1602 }
Chris Wren93bb8b82016-03-29 14:35:05 -04001603}