193bb8b800661653cc1c65b294eab621554af139aChris Wren/* 293bb8b800661653cc1c65b294eab621554af139aChris Wren * Copyright (C) 2016 The Android Open Source Project 393bb8b800661653cc1c65b294eab621554af139aChris Wren * 493bb8b800661653cc1c65b294eab621554af139aChris Wren * Licensed under the Apache License, Version 2.0 (the "License"); 593bb8b800661653cc1c65b294eab621554af139aChris Wren * you may not use this file except in compliance with the License. 693bb8b800661653cc1c65b294eab621554af139aChris Wren * You may obtain a copy of the License at 793bb8b800661653cc1c65b294eab621554af139aChris Wren * 893bb8b800661653cc1c65b294eab621554af139aChris Wren * http://www.apache.org/licenses/LICENSE-2.0 993bb8b800661653cc1c65b294eab621554af139aChris Wren * 1093bb8b800661653cc1c65b294eab621554af139aChris Wren * Unless required by applicable law or agreed to in writing, software 1193bb8b800661653cc1c65b294eab621554af139aChris Wren * distributed under the License is distributed on an "AS IS" BASIS, 1293bb8b800661653cc1c65b294eab621554af139aChris Wren * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1393bb8b800661653cc1c65b294eab621554af139aChris Wren * See the License for the specific language governing permissions and 1493bb8b800661653cc1c65b294eab621554af139aChris Wren * limitations under the License. 1593bb8b800661653cc1c65b294eab621554af139aChris Wren */ 1693bb8b800661653cc1c65b294eab621554af139aChris Wrenpackage com.android.server.notification; 1793bb8b800661653cc1c65b294eab621554af139aChris Wren 18a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynoldsimport static android.app.Notification.GROUP_ALERT_ALL; 19a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynoldsimport static android.app.Notification.GROUP_ALERT_CHILDREN; 20a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynoldsimport static android.app.Notification.GROUP_ALERT_SUMMARY; 21ca80d1632e205ac93e234203947efad4f8c7a164Julia Reynoldsimport static android.app.NotificationManager.IMPORTANCE_HIGH; 22ca80d1632e205ac93e234203947efad4f8c7a164Julia Reynolds 230c299d4d6316d14e43d386b4562782083fe3c886Julia Reynoldsimport static junit.framework.Assert.assertNull; 240c299d4d6316d14e43d386b4562782083fe3c886Julia Reynoldsimport static junit.framework.Assert.assertTrue; 250c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds 26ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport static org.mockito.Matchers.anyBoolean; 27ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport static org.mockito.Matchers.anyInt; 28ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport static org.mockito.Matchers.anyObject; 29ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport static org.mockito.Matchers.anyString; 30ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport static org.mockito.Matchers.argThat; 31ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport static org.mockito.Matchers.eq; 32ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport static org.mockito.Mockito.never; 33ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport static org.mockito.Mockito.spy; 34ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport static org.mockito.Mockito.timeout; 35ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport static org.mockito.Mockito.times; 36ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport static org.mockito.Mockito.verify; 37ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport static org.mockito.Mockito.when; 3893bb8b800661653cc1c65b294eab621554af139aChris Wren 3993bb8b800661653cc1c65b294eab621554af139aChris Wrenimport android.app.ActivityManager; 4093bb8b800661653cc1c65b294eab621554af139aChris Wrenimport android.app.Notification; 4193bb8b800661653cc1c65b294eab621554af139aChris Wrenimport android.app.Notification.Builder; 42b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynoldsimport android.app.NotificationChannel; 43ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport android.app.NotificationManager; 44ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport android.content.Context; 45ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport android.content.pm.PackageManager; 46b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynoldsimport android.graphics.Color; 4793bb8b800661653cc1c65b294eab621554af139aChris Wrenimport android.media.AudioAttributes; 4893bb8b800661653cc1c65b294eab621554af139aChris Wrenimport android.media.AudioManager; 4993bb8b800661653cc1c65b294eab621554af139aChris Wrenimport android.net.Uri; 5093bb8b800661653cc1c65b294eab621554af139aChris Wrenimport android.os.Handler; 5193bb8b800661653cc1c65b294eab621554af139aChris Wrenimport android.os.RemoteException; 5293bb8b800661653cc1c65b294eab621554af139aChris Wrenimport android.os.UserHandle; 537121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wrightimport android.os.VibrationEffect; 54ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport android.os.Vibrator; 55b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynoldsimport android.provider.Settings; 5693bb8b800661653cc1c65b294eab621554af139aChris Wrenimport android.service.notification.StatusBarNotification; 570ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitschimport android.support.test.runner.AndroidJUnit4; 5893bb8b800661653cc1c65b294eab621554af139aChris Wrenimport android.test.suitebuilder.annotation.SmallTest; 5993bb8b800661653cc1c65b294eab621554af139aChris Wren 60ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport com.android.server.lights.Light; 61ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler 62ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport org.junit.Before; 63ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport org.junit.Test; 64ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantlerimport org.junit.runner.RunWith; 657121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wrightimport org.mockito.ArgumentMatcher; 6693bb8b800661653cc1c65b294eab621554af139aChris Wrenimport org.mockito.Mock; 6793bb8b800661653cc1c65b294eab621554af139aChris Wrenimport org.mockito.Mockito; 6893bb8b800661653cc1c65b294eab621554af139aChris Wrenimport org.mockito.MockitoAnnotations; 6993bb8b800661653cc1c65b294eab621554af139aChris Wren 700ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch@SmallTest 710ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch@RunWith(AndroidJUnit4.class) 7289aa2261903fd09b08a2210a7a1b35d329f8330aChris Wrenpublic class BuzzBeepBlinkTest extends NotificationTestCase { 7393bb8b800661653cc1c65b294eab621554af139aChris Wren 7493bb8b800661653cc1c65b294eab621554af139aChris Wren @Mock AudioManager mAudioManager; 7593bb8b800661653cc1c65b294eab621554af139aChris Wren @Mock Vibrator mVibrator; 7693bb8b800661653cc1c65b294eab621554af139aChris Wren @Mock android.media.IRingtonePlayer mRingtonePlayer; 77b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds @Mock Light mLight; 7893bb8b800661653cc1c65b294eab621554af139aChris Wren @Mock Handler mHandler; 7993bb8b800661653cc1c65b294eab621554af139aChris Wren 8093bb8b800661653cc1c65b294eab621554af139aChris Wren private NotificationManagerService mService; 8193bb8b800661653cc1c65b294eab621554af139aChris Wren private String mPkg = "com.android.server.notification"; 8293bb8b800661653cc1c65b294eab621554af139aChris Wren private int mId = 1001; 8393bb8b800661653cc1c65b294eab621554af139aChris Wren private int mOtherId = 1002; 8493bb8b800661653cc1c65b294eab621554af139aChris Wren private String mTag = null; 8593bb8b800661653cc1c65b294eab621554af139aChris Wren private int mUid = 1000; 8693bb8b800661653cc1c65b294eab621554af139aChris Wren private int mPid = 2000; 8793bb8b800661653cc1c65b294eab621554af139aChris Wren private android.os.UserHandle mUser = UserHandle.of(ActivityManager.getCurrentUser()); 8893bb8b800661653cc1c65b294eab621554af139aChris Wren 897121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright private VibrateRepeatMatcher mVibrateOnceMatcher = new VibrateRepeatMatcher(-1); 907121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright private VibrateRepeatMatcher mVibrateLoopMatcher = new VibrateRepeatMatcher(0); 917121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright 92b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds private static final long[] CUSTOM_VIBRATION = new long[] { 93b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 94b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 95b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400 }; 96b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds private static final Uri CUSTOM_SOUND = Settings.System.DEFAULT_ALARM_ALERT_URI; 97619a69f722b75241b372cf7b01b45b2dd1c862faJulia Reynolds private static final AudioAttributes CUSTOM_ATTRIBUTES = new AudioAttributes.Builder() 98619a69f722b75241b372cf7b01b45b2dd1c862faJulia Reynolds .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN) 99619a69f722b75241b372cf7b01b45b2dd1c862faJulia Reynolds .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE) 100619a69f722b75241b372cf7b01b45b2dd1c862faJulia Reynolds .build(); 101b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds private static final int CUSTOM_LIGHT_COLOR = Color.BLACK; 102b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds private static final int CUSTOM_LIGHT_ON = 10000; 103b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds private static final int CUSTOM_LIGHT_OFF = 10000; 1047121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright private static final long[] FALLBACK_VIBRATION_PATTERN = new long[] {100, 100, 100}; 1057121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright private static final VibrationEffect FALLBACK_VIBRATION = 1067121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright VibrationEffect.createWaveform(FALLBACK_VIBRATION_PATTERN, -1); 107ea0eb5f5813d63283d9b069510418e495d4cc137Jean-Michel Trivi private static final int MAX_VIBRATION_DELAY = 1000; 108b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds 1090ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Before 11093bb8b800661653cc1c65b294eab621554af139aChris Wren public void setUp() { 11193bb8b800661653cc1c65b294eab621554af139aChris Wren MockitoAnnotations.initMocks(this); 11293bb8b800661653cc1c65b294eab621554af139aChris Wren 11393bb8b800661653cc1c65b294eab621554af139aChris Wren when(mAudioManager.isAudioFocusExclusive()).thenReturn(false); 11493bb8b800661653cc1c65b294eab621554af139aChris Wren when(mAudioManager.getRingtonePlayer()).thenReturn(mRingtonePlayer); 11593bb8b800661653cc1c65b294eab621554af139aChris Wren when(mAudioManager.getStreamVolume(anyInt())).thenReturn(10); 11693bb8b800661653cc1c65b294eab621554af139aChris Wren when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL); 11793bb8b800661653cc1c65b294eab621554af139aChris Wren 11893bb8b800661653cc1c65b294eab621554af139aChris Wren mService = new NotificationManagerService(getContext()); 11993bb8b800661653cc1c65b294eab621554af139aChris Wren mService.setAudioManager(mAudioManager); 12093bb8b800661653cc1c65b294eab621554af139aChris Wren mService.setVibrator(mVibrator); 12193bb8b800661653cc1c65b294eab621554af139aChris Wren mService.setSystemReady(true); 12293bb8b800661653cc1c65b294eab621554af139aChris Wren mService.setHandler(mHandler); 123b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds mService.setLights(mLight); 124b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds mService.setScreenOn(false); 1257121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright mService.setFallbackVibrationPattern(FALLBACK_VIBRATION_PATTERN); 12693bb8b800661653cc1c65b294eab621554af139aChris Wren } 12793bb8b800661653cc1c65b294eab621554af139aChris Wren 12893bb8b800661653cc1c65b294eab621554af139aChris Wren // 12993bb8b800661653cc1c65b294eab621554af139aChris Wren // Convenience functions for creating notification records 13093bb8b800661653cc1c65b294eab621554af139aChris Wren // 13193bb8b800661653cc1c65b294eab621554af139aChris Wren 13293bb8b800661653cc1c65b294eab621554af139aChris Wren private NotificationRecord getNoisyOtherNotification() { 13393bb8b800661653cc1c65b294eab621554af139aChris Wren return getNotificationRecord(mOtherId, false /* insistent */, false /* once */, 134b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds true /* noisy */, true /* buzzy*/, false /* lights */); 13593bb8b800661653cc1c65b294eab621554af139aChris Wren } 13693bb8b800661653cc1c65b294eab621554af139aChris Wren 13793bb8b800661653cc1c65b294eab621554af139aChris Wren private NotificationRecord getBeepyNotification() { 13893bb8b800661653cc1c65b294eab621554af139aChris Wren return getNotificationRecord(mId, false /* insistent */, false /* once */, 139b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds true /* noisy */, false /* buzzy*/, false /* lights */); 14093bb8b800661653cc1c65b294eab621554af139aChris Wren } 14193bb8b800661653cc1c65b294eab621554af139aChris Wren 14293bb8b800661653cc1c65b294eab621554af139aChris Wren private NotificationRecord getBeepyOnceNotification() { 14393bb8b800661653cc1c65b294eab621554af139aChris Wren return getNotificationRecord(mId, false /* insistent */, true /* once */, 144b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds true /* noisy */, false /* buzzy*/, false /* lights */); 14593bb8b800661653cc1c65b294eab621554af139aChris Wren } 14693bb8b800661653cc1c65b294eab621554af139aChris Wren 14793bb8b800661653cc1c65b294eab621554af139aChris Wren private NotificationRecord getQuietNotification() { 14893bb8b800661653cc1c65b294eab621554af139aChris Wren return getNotificationRecord(mId, false /* insistent */, false /* once */, 149b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds false /* noisy */, false /* buzzy*/, false /* lights */); 15093bb8b800661653cc1c65b294eab621554af139aChris Wren } 15193bb8b800661653cc1c65b294eab621554af139aChris Wren 15293bb8b800661653cc1c65b294eab621554af139aChris Wren private NotificationRecord getQuietOtherNotification() { 15393bb8b800661653cc1c65b294eab621554af139aChris Wren return getNotificationRecord(mOtherId, false /* insistent */, false /* once */, 154b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds false /* noisy */, false /* buzzy*/, false /* lights */); 15593bb8b800661653cc1c65b294eab621554af139aChris Wren } 15693bb8b800661653cc1c65b294eab621554af139aChris Wren 15793bb8b800661653cc1c65b294eab621554af139aChris Wren private NotificationRecord getQuietOnceNotification() { 15893bb8b800661653cc1c65b294eab621554af139aChris Wren return getNotificationRecord(mId, false /* insistent */, true /* once */, 159b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds false /* noisy */, false /* buzzy*/, false /* lights */); 16093bb8b800661653cc1c65b294eab621554af139aChris Wren } 16193bb8b800661653cc1c65b294eab621554af139aChris Wren 16293bb8b800661653cc1c65b294eab621554af139aChris Wren private NotificationRecord getInsistentBeepyNotification() { 16393bb8b800661653cc1c65b294eab621554af139aChris Wren return getNotificationRecord(mId, true /* insistent */, false /* once */, 164b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds true /* noisy */, false /* buzzy*/, false /* lights */); 16593bb8b800661653cc1c65b294eab621554af139aChris Wren } 16693bb8b800661653cc1c65b294eab621554af139aChris Wren 167ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler private NotificationRecord getInsistentBeepyLeanbackNotification() { 168ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler return getLeanbackNotificationRecord(mId, true /* insistent */, false /* once */, 169ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler true /* noisy */, false /* buzzy*/, false /* lights */); 170ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler } 171ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler 17293bb8b800661653cc1c65b294eab621554af139aChris Wren private NotificationRecord getBuzzyNotification() { 17393bb8b800661653cc1c65b294eab621554af139aChris Wren return getNotificationRecord(mId, false /* insistent */, false /* once */, 174b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds false /* noisy */, true /* buzzy*/, false /* lights */); 17593bb8b800661653cc1c65b294eab621554af139aChris Wren } 17693bb8b800661653cc1c65b294eab621554af139aChris Wren 17793bb8b800661653cc1c65b294eab621554af139aChris Wren private NotificationRecord getBuzzyOnceNotification() { 17893bb8b800661653cc1c65b294eab621554af139aChris Wren return getNotificationRecord(mId, false /* insistent */, true /* once */, 179b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds false /* noisy */, true /* buzzy*/, false /* lights */); 18093bb8b800661653cc1c65b294eab621554af139aChris Wren } 18193bb8b800661653cc1c65b294eab621554af139aChris Wren 18293bb8b800661653cc1c65b294eab621554af139aChris Wren private NotificationRecord getInsistentBuzzyNotification() { 18393bb8b800661653cc1c65b294eab621554af139aChris Wren return getNotificationRecord(mId, true /* insistent */, false /* once */, 184b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds false /* noisy */, true /* buzzy*/, false /* lights */); 185b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds } 186b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds 1870c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds private NotificationRecord getBuzzyBeepyNotification() { 1880c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds return getNotificationRecord(mId, false /* insistent */, false /* once */, 1890c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds true /* noisy */, true /* buzzy*/, false /* lights */); 190b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds } 191b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds 1920c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds private NotificationRecord getLightsNotification() { 193b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds return getNotificationRecord(mId, false /* insistent */, true /* once */, 1940c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds false /* noisy */, true /* buzzy*/, true /* lights */); 195b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds } 196b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds 197b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds private NotificationRecord getCustomLightsNotification() { 198b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds return getNotificationRecord(mId, false /* insistent */, true /* once */, 199b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds false /* noisy */, true /* buzzy*/, true /* lights */, 200a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds true /* defaultVibration */, true /* defaultSound */, false /* defaultLights */, 201ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler null, Notification.GROUP_ALERT_ALL, false); 202b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds } 203b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds 204b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds private NotificationRecord getNotificationRecord(int id, boolean insistent, boolean once, 205b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds boolean noisy, boolean buzzy, boolean lights) { 206a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds return getNotificationRecord(id, insistent, once, noisy, buzzy, lights, true, true, true, 207ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler null, Notification.GROUP_ALERT_ALL, false); 208ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler } 209ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler 210ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler private NotificationRecord getLeanbackNotificationRecord(int id, boolean insistent, boolean once, 211ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler boolean noisy, boolean buzzy, boolean lights) { 212ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler return getNotificationRecord(id, insistent, once, noisy, buzzy, lights, true, true, true, 213ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler null, Notification.GROUP_ALERT_ALL, true); 214a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds } 215a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 216a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds private NotificationRecord getBeepyNotificationRecord(String groupKey, int groupAlertBehavior) { 217a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds return getNotificationRecord(mId, false, false, true, false, false, true, true, true, 218ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler groupKey, groupAlertBehavior, false); 21993bb8b800661653cc1c65b294eab621554af139aChris Wren } 22093bb8b800661653cc1c65b294eab621554af139aChris Wren 22193bb8b800661653cc1c65b294eab621554af139aChris Wren private NotificationRecord getNotificationRecord(int id, boolean insistent, boolean once, 222b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds boolean noisy, boolean buzzy, boolean lights, boolean defaultVibration, 223ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler boolean defaultSound, boolean defaultLights, String groupKey, int groupAlertBehavior, 224ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler boolean isLeanback) { 2250c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds NotificationChannel channel = 226ca80d1632e205ac93e234203947efad4f8c7a164Julia Reynolds new NotificationChannel("test", "test", IMPORTANCE_HIGH); 22793bb8b800661653cc1c65b294eab621554af139aChris Wren final Builder builder = new Builder(getContext()) 22893bb8b800661653cc1c65b294eab621554af139aChris Wren .setContentTitle("foo") 22993bb8b800661653cc1c65b294eab621554af139aChris Wren .setSmallIcon(android.R.drawable.sym_def_app_icon) 23093bb8b800661653cc1c65b294eab621554af139aChris Wren .setPriority(Notification.PRIORITY_HIGH) 23193bb8b800661653cc1c65b294eab621554af139aChris Wren .setOnlyAlertOnce(once); 23293bb8b800661653cc1c65b294eab621554af139aChris Wren 23393bb8b800661653cc1c65b294eab621554af139aChris Wren int defaults = 0; 23493bb8b800661653cc1c65b294eab621554af139aChris Wren if (noisy) { 235b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds if (defaultSound) { 236b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds defaults |= Notification.DEFAULT_SOUND; 237619a69f722b75241b372cf7b01b45b2dd1c862faJulia Reynolds channel.setSound(Settings.System.DEFAULT_NOTIFICATION_URI, 238619a69f722b75241b372cf7b01b45b2dd1c862faJulia Reynolds Notification.AUDIO_ATTRIBUTES_DEFAULT); 239b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds } else { 240b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds builder.setSound(CUSTOM_SOUND); 241619a69f722b75241b372cf7b01b45b2dd1c862faJulia Reynolds channel.setSound(CUSTOM_SOUND, CUSTOM_ATTRIBUTES); 242b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds } 243184b86da382b8e24cdd0e5629e70d7057d418883Julia Reynolds } else { 244184b86da382b8e24cdd0e5629e70d7057d418883Julia Reynolds channel.setSound(null, null); 24593bb8b800661653cc1c65b294eab621554af139aChris Wren } 24693bb8b800661653cc1c65b294eab621554af139aChris Wren if (buzzy) { 247b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds if (defaultVibration) { 248b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds defaults |= Notification.DEFAULT_VIBRATE; 249b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds } else { 250b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds builder.setVibrate(CUSTOM_VIBRATION); 251f57de46d0b16fea790dc29062bf5e47cf63bae3eJulia Reynolds channel.setVibrationPattern(CUSTOM_VIBRATION); 252b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds } 253f57de46d0b16fea790dc29062bf5e47cf63bae3eJulia Reynolds channel.enableVibration(true); 254b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds } 255b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds if (lights) { 256b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds if (defaultLights) { 257b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds defaults |= Notification.DEFAULT_LIGHTS; 258b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds } else { 259b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds builder.setLights(CUSTOM_LIGHT_COLOR, CUSTOM_LIGHT_ON, CUSTOM_LIGHT_OFF); 260b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds } 261529e3329e68963eff0dd1cf40d938a9953cd5060Julia Reynolds channel.enableLights(true); 26293bb8b800661653cc1c65b294eab621554af139aChris Wren } 26393bb8b800661653cc1c65b294eab621554af139aChris Wren builder.setDefaults(defaults); 26493bb8b800661653cc1c65b294eab621554af139aChris Wren 265a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds builder.setGroup(groupKey); 266a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds builder.setGroupAlertBehavior(groupAlertBehavior); 267a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 26893bb8b800661653cc1c65b294eab621554af139aChris Wren Notification n = builder.build(); 26993bb8b800661653cc1c65b294eab621554af139aChris Wren if (insistent) { 27093bb8b800661653cc1c65b294eab621554af139aChris Wren n.flags |= Notification.FLAG_INSISTENT; 27193bb8b800661653cc1c65b294eab621554af139aChris Wren } 2720c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds 273ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler Context context = spy(getContext()); 274ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler PackageManager packageManager = spy(context.getPackageManager()); 275ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler when(context.getPackageManager()).thenReturn(packageManager); 276ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler when(packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)) 277ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler .thenReturn(isLeanback); 278ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler 279924eed1ca6d3fec5dae7eb0f9c11b8f23f628697Julia Reynolds StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, id, mTag, mUid, 280423b9fc83d736326b8ddadbfcd6fd5f181bf9fecJulia Reynolds mPid, n, mUser, null, System.currentTimeMillis()); 281ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler NotificationRecord r = new NotificationRecord(context, sbn, channel); 282b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds mService.addNotification(r); 283b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds return r; 28493bb8b800661653cc1c65b294eab621554af139aChris Wren } 28593bb8b800661653cc1c65b294eab621554af139aChris Wren 28693bb8b800661653cc1c65b294eab621554af139aChris Wren // 28793bb8b800661653cc1c65b294eab621554af139aChris Wren // Convenience functions for interacting with mocks 28893bb8b800661653cc1c65b294eab621554af139aChris Wren // 28993bb8b800661653cc1c65b294eab621554af139aChris Wren 29093bb8b800661653cc1c65b294eab621554af139aChris Wren private void verifyNeverBeep() throws RemoteException { 29193bb8b800661653cc1c65b294eab621554af139aChris Wren verify(mRingtonePlayer, never()).playAsync((Uri) anyObject(), (UserHandle) anyObject(), 29293bb8b800661653cc1c65b294eab621554af139aChris Wren anyBoolean(), (AudioAttributes) anyObject()); 29393bb8b800661653cc1c65b294eab621554af139aChris Wren } 29493bb8b800661653cc1c65b294eab621554af139aChris Wren 29593bb8b800661653cc1c65b294eab621554af139aChris Wren private void verifyBeep() throws RemoteException { 29693bb8b800661653cc1c65b294eab621554af139aChris Wren verify(mRingtonePlayer, times(1)).playAsync((Uri) anyObject(), (UserHandle) anyObject(), 29793bb8b800661653cc1c65b294eab621554af139aChris Wren eq(true), (AudioAttributes) anyObject()); 29893bb8b800661653cc1c65b294eab621554af139aChris Wren } 29993bb8b800661653cc1c65b294eab621554af139aChris Wren 30093bb8b800661653cc1c65b294eab621554af139aChris Wren private void verifyBeepLooped() throws RemoteException { 30193bb8b800661653cc1c65b294eab621554af139aChris Wren verify(mRingtonePlayer, times(1)).playAsync((Uri) anyObject(), (UserHandle) anyObject(), 30293bb8b800661653cc1c65b294eab621554af139aChris Wren eq(false), (AudioAttributes) anyObject()); 30393bb8b800661653cc1c65b294eab621554af139aChris Wren } 30493bb8b800661653cc1c65b294eab621554af139aChris Wren 305b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds private void verifyCustomBeep() throws RemoteException { 306b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds verify(mRingtonePlayer, times(1)).playAsync(eq(CUSTOM_SOUND), (UserHandle) anyObject(), 307b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds eq(false), (AudioAttributes) anyObject()); 308b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds } 309b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds 31093bb8b800661653cc1c65b294eab621554af139aChris Wren private void verifyNeverStopAudio() throws RemoteException { 31193bb8b800661653cc1c65b294eab621554af139aChris Wren verify(mRingtonePlayer, never()).stopAsync(); 31293bb8b800661653cc1c65b294eab621554af139aChris Wren } 31393bb8b800661653cc1c65b294eab621554af139aChris Wren 31493bb8b800661653cc1c65b294eab621554af139aChris Wren private void verifyStopAudio() throws RemoteException { 31593bb8b800661653cc1c65b294eab621554af139aChris Wren verify(mRingtonePlayer, times(1)).stopAsync(); 31693bb8b800661653cc1c65b294eab621554af139aChris Wren } 31793bb8b800661653cc1c65b294eab621554af139aChris Wren 31893bb8b800661653cc1c65b294eab621554af139aChris Wren private void verifyNeverVibrate() { 3197121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright verify(mVibrator, never()).vibrate(anyInt(), anyString(), (VibrationEffect) anyObject(), 3207121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright (AudioAttributes) anyObject()); 32193bb8b800661653cc1c65b294eab621554af139aChris Wren } 32293bb8b800661653cc1c65b294eab621554af139aChris Wren 32393bb8b800661653cc1c65b294eab621554af139aChris Wren private void verifyVibrate() { 3247121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright verify(mVibrator, times(1)).vibrate(anyInt(), anyString(), argThat(mVibrateOnceMatcher), 3257121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright (AudioAttributes) anyObject()); 32693bb8b800661653cc1c65b294eab621554af139aChris Wren } 32793bb8b800661653cc1c65b294eab621554af139aChris Wren 32893bb8b800661653cc1c65b294eab621554af139aChris Wren private void verifyVibrateLooped() { 3297121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright verify(mVibrator, times(1)).vibrate(anyInt(), anyString(), argThat(mVibrateLoopMatcher), 3307121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright (AudioAttributes) anyObject()); 33193bb8b800661653cc1c65b294eab621554af139aChris Wren } 33293bb8b800661653cc1c65b294eab621554af139aChris Wren 333ea0eb5f5813d63283d9b069510418e495d4cc137Jean-Michel Trivi private void verifyDelayedVibrateLooped() { 334ea0eb5f5813d63283d9b069510418e495d4cc137Jean-Michel Trivi verify(mVibrator, timeout(MAX_VIBRATION_DELAY).times(1)).vibrate(anyInt(), anyString(), 335ea0eb5f5813d63283d9b069510418e495d4cc137Jean-Michel Trivi argThat(mVibrateLoopMatcher), (AudioAttributes) anyObject()); 336ea0eb5f5813d63283d9b069510418e495d4cc137Jean-Michel Trivi } 337ea0eb5f5813d63283d9b069510418e495d4cc137Jean-Michel Trivi 33893bb8b800661653cc1c65b294eab621554af139aChris Wren private void verifyStopVibrate() { 33993bb8b800661653cc1c65b294eab621554af139aChris Wren verify(mVibrator, times(1)).cancel(); 34093bb8b800661653cc1c65b294eab621554af139aChris Wren } 34193bb8b800661653cc1c65b294eab621554af139aChris Wren 34293bb8b800661653cc1c65b294eab621554af139aChris Wren private void verifyNeverStopVibrate() throws RemoteException { 34393bb8b800661653cc1c65b294eab621554af139aChris Wren verify(mVibrator, never()).cancel(); 34493bb8b800661653cc1c65b294eab621554af139aChris Wren } 34593bb8b800661653cc1c65b294eab621554af139aChris Wren 346b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds private void verifyLights() { 347033a4120a8ed78c2b97a5ff9ce2f52de7a1a662dJulia Reynolds verify(mLight, times(1)).setFlashing(anyInt(), anyInt(), anyInt(), anyInt()); 348b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds } 349b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds 350b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds private void verifyCustomLights() { 351033a4120a8ed78c2b97a5ff9ce2f52de7a1a662dJulia Reynolds verify(mLight, times(1)).setFlashing( 352033a4120a8ed78c2b97a5ff9ce2f52de7a1a662dJulia Reynolds eq(CUSTOM_LIGHT_COLOR), anyInt(), eq(CUSTOM_LIGHT_ON), eq(CUSTOM_LIGHT_OFF)); 353b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds } 354b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds 355b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds // 356b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds // Tests 357b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds // 358b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds 359b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds @Test 360b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds public void testLights() throws Exception { 361b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds NotificationRecord r = getLightsNotification(); 362b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds r.setImportance(NotificationManager.IMPORTANCE_DEFAULT, "for testing"); 363b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds 364b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds mService.buzzBeepBlinkLocked(r); 365b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds 366b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds verifyLights(); 367b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds } 368b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds 3690ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 37093bb8b800661653cc1c65b294eab621554af139aChris Wren public void testBeep() throws Exception { 37193bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBeepyNotification(); 37293bb8b800661653cc1c65b294eab621554af139aChris Wren 37393bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 37493bb8b800661653cc1c65b294eab621554af139aChris Wren 37593bb8b800661653cc1c65b294eab621554af139aChris Wren verifyBeepLooped(); 37693bb8b800661653cc1c65b294eab621554af139aChris Wren verifyNeverVibrate(); 37793bb8b800661653cc1c65b294eab621554af139aChris Wren } 37893bb8b800661653cc1c65b294eab621554af139aChris Wren 379b5e44b796618c376cf535e43aaa86ea4522e7770Julia Reynolds @Test 38093bb8b800661653cc1c65b294eab621554af139aChris Wren public void testBeepInsistently() throws Exception { 38193bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getInsistentBeepyNotification(); 38293bb8b800661653cc1c65b294eab621554af139aChris Wren 38393bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 38493bb8b800661653cc1c65b294eab621554af139aChris Wren 38593bb8b800661653cc1c65b294eab621554af139aChris Wren verifyBeep(); 38693bb8b800661653cc1c65b294eab621554af139aChris Wren } 38793bb8b800661653cc1c65b294eab621554af139aChris Wren 3880ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 389ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler public void testNoLeanbackBeep() throws Exception { 390ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler NotificationRecord r = getInsistentBeepyLeanbackNotification(); 391ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler 392ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler mService.buzzBeepBlinkLocked(r); 393ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler 394ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler verifyNeverBeep(); 395ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler } 396ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler 397ab55f0f2b04c69d8a05f5685e2ed399fab33ab35Tony Mantler @Test 39893bb8b800661653cc1c65b294eab621554af139aChris Wren public void testNoInterruptionForMin() throws Exception { 39993bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBeepyNotification(); 40085769915e7ef10bef2b5338ed8f04d9b787924fbJulia Reynolds r.setImportance(NotificationManager.IMPORTANCE_MIN, "foo"); 40193bb8b800661653cc1c65b294eab621554af139aChris Wren 40293bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 40393bb8b800661653cc1c65b294eab621554af139aChris Wren 40493bb8b800661653cc1c65b294eab621554af139aChris Wren verifyNeverBeep(); 40593bb8b800661653cc1c65b294eab621554af139aChris Wren verifyNeverVibrate(); 40693bb8b800661653cc1c65b294eab621554af139aChris Wren } 40793bb8b800661653cc1c65b294eab621554af139aChris Wren 4080ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 40993bb8b800661653cc1c65b294eab621554af139aChris Wren public void testNoInterruptionForIntercepted() throws Exception { 41093bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBeepyNotification(); 41193bb8b800661653cc1c65b294eab621554af139aChris Wren r.setIntercepted(true); 41293bb8b800661653cc1c65b294eab621554af139aChris Wren 41393bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 41493bb8b800661653cc1c65b294eab621554af139aChris Wren 41593bb8b800661653cc1c65b294eab621554af139aChris Wren verifyNeverBeep(); 41693bb8b800661653cc1c65b294eab621554af139aChris Wren verifyNeverVibrate(); 41793bb8b800661653cc1c65b294eab621554af139aChris Wren } 41893bb8b800661653cc1c65b294eab621554af139aChris Wren 4190ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 42093bb8b800661653cc1c65b294eab621554af139aChris Wren public void testBeepTwice() throws Exception { 42193bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBeepyNotification(); 42293bb8b800661653cc1c65b294eab621554af139aChris Wren 42393bb8b800661653cc1c65b294eab621554af139aChris Wren // set up internal state 42493bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 42593bb8b800661653cc1c65b294eab621554af139aChris Wren Mockito.reset(mRingtonePlayer); 42693bb8b800661653cc1c65b294eab621554af139aChris Wren 42793bb8b800661653cc1c65b294eab621554af139aChris Wren // update should beep 42893bb8b800661653cc1c65b294eab621554af139aChris Wren r.isUpdate = true; 42993bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 43093bb8b800661653cc1c65b294eab621554af139aChris Wren verifyBeepLooped(); 43193bb8b800661653cc1c65b294eab621554af139aChris Wren } 43293bb8b800661653cc1c65b294eab621554af139aChris Wren 4330ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 43493bb8b800661653cc1c65b294eab621554af139aChris Wren public void testHonorAlertOnlyOnceForBeep() throws Exception { 43593bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBeepyNotification(); 43693bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord s = getBeepyOnceNotification(); 43793bb8b800661653cc1c65b294eab621554af139aChris Wren s.isUpdate = true; 43893bb8b800661653cc1c65b294eab621554af139aChris Wren 43993bb8b800661653cc1c65b294eab621554af139aChris Wren // set up internal state 44093bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 44193bb8b800661653cc1c65b294eab621554af139aChris Wren Mockito.reset(mRingtonePlayer); 44293bb8b800661653cc1c65b294eab621554af139aChris Wren 44393bb8b800661653cc1c65b294eab621554af139aChris Wren // update should not beep 44493bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(s); 44593bb8b800661653cc1c65b294eab621554af139aChris Wren verifyNeverBeep(); 44693bb8b800661653cc1c65b294eab621554af139aChris Wren } 44793bb8b800661653cc1c65b294eab621554af139aChris Wren 4480ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 44993bb8b800661653cc1c65b294eab621554af139aChris Wren public void testNoisyUpdateDoesNotCancelAudio() throws Exception { 45093bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBeepyNotification(); 45193bb8b800661653cc1c65b294eab621554af139aChris Wren 45293bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 45393bb8b800661653cc1c65b294eab621554af139aChris Wren r.isUpdate = true; 45493bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 45593bb8b800661653cc1c65b294eab621554af139aChris Wren 45693bb8b800661653cc1c65b294eab621554af139aChris Wren verifyNeverStopAudio(); 45793bb8b800661653cc1c65b294eab621554af139aChris Wren } 45893bb8b800661653cc1c65b294eab621554af139aChris Wren 4590ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 46093bb8b800661653cc1c65b294eab621554af139aChris Wren public void testNoisyOnceUpdateDoesNotCancelAudio() throws Exception { 46193bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBeepyNotification(); 46293bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord s = getBeepyOnceNotification(); 46393bb8b800661653cc1c65b294eab621554af139aChris Wren s.isUpdate = true; 46493bb8b800661653cc1c65b294eab621554af139aChris Wren 46593bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 46693bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(s); 46793bb8b800661653cc1c65b294eab621554af139aChris Wren 46893bb8b800661653cc1c65b294eab621554af139aChris Wren verifyNeverStopAudio(); 46993bb8b800661653cc1c65b294eab621554af139aChris Wren } 47093bb8b800661653cc1c65b294eab621554af139aChris Wren 4710ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 47293bb8b800661653cc1c65b294eab621554af139aChris Wren public void testQuietUpdateDoesNotCancelAudioFromOther() throws Exception { 47393bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBeepyNotification(); 47493bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord s = getQuietNotification(); 47593bb8b800661653cc1c65b294eab621554af139aChris Wren s.isUpdate = true; 47693bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord other = getNoisyOtherNotification(); 47793bb8b800661653cc1c65b294eab621554af139aChris Wren 47893bb8b800661653cc1c65b294eab621554af139aChris Wren // set up internal state 47993bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 48093bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(other); // this takes the audio stream 48193bb8b800661653cc1c65b294eab621554af139aChris Wren Mockito.reset(mRingtonePlayer); 48293bb8b800661653cc1c65b294eab621554af139aChris Wren 48393bb8b800661653cc1c65b294eab621554af139aChris Wren // should not stop noise, since we no longer own it 48493bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(s); // this no longer owns the stream 48593bb8b800661653cc1c65b294eab621554af139aChris Wren verifyNeverStopAudio(); 48693bb8b800661653cc1c65b294eab621554af139aChris Wren } 48793bb8b800661653cc1c65b294eab621554af139aChris Wren 4880ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 48993bb8b800661653cc1c65b294eab621554af139aChris Wren public void testQuietInterloperDoesNotCancelAudio() throws Exception { 49093bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBeepyNotification(); 49193bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord other = getQuietOtherNotification(); 49293bb8b800661653cc1c65b294eab621554af139aChris Wren 49393bb8b800661653cc1c65b294eab621554af139aChris Wren // set up internal state 49493bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 49593bb8b800661653cc1c65b294eab621554af139aChris Wren Mockito.reset(mRingtonePlayer); 49693bb8b800661653cc1c65b294eab621554af139aChris Wren 49793bb8b800661653cc1c65b294eab621554af139aChris Wren // should not stop noise, since it does not own it 49893bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(other); 49993bb8b800661653cc1c65b294eab621554af139aChris Wren verifyNeverStopAudio(); 50093bb8b800661653cc1c65b294eab621554af139aChris Wren } 50193bb8b800661653cc1c65b294eab621554af139aChris Wren 5020ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 50393bb8b800661653cc1c65b294eab621554af139aChris Wren public void testQuietUpdateCancelsAudio() throws Exception { 50493bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBeepyNotification(); 50593bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord s = getQuietNotification(); 50693bb8b800661653cc1c65b294eab621554af139aChris Wren s.isUpdate = true; 50793bb8b800661653cc1c65b294eab621554af139aChris Wren 50893bb8b800661653cc1c65b294eab621554af139aChris Wren // set up internal state 50993bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 51093bb8b800661653cc1c65b294eab621554af139aChris Wren Mockito.reset(mRingtonePlayer); 51193bb8b800661653cc1c65b294eab621554af139aChris Wren 51293bb8b800661653cc1c65b294eab621554af139aChris Wren // quiet update should stop making noise 51393bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(s); 51493bb8b800661653cc1c65b294eab621554af139aChris Wren verifyStopAudio(); 51593bb8b800661653cc1c65b294eab621554af139aChris Wren } 51693bb8b800661653cc1c65b294eab621554af139aChris Wren 5170ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 51893bb8b800661653cc1c65b294eab621554af139aChris Wren public void testQuietOnceUpdateCancelsAudio() throws Exception { 51993bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBeepyNotification(); 52093bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord s = getQuietOnceNotification(); 52193bb8b800661653cc1c65b294eab621554af139aChris Wren s.isUpdate = true; 52293bb8b800661653cc1c65b294eab621554af139aChris Wren 52393bb8b800661653cc1c65b294eab621554af139aChris Wren // set up internal state 52493bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 52593bb8b800661653cc1c65b294eab621554af139aChris Wren Mockito.reset(mRingtonePlayer); 52693bb8b800661653cc1c65b294eab621554af139aChris Wren 52793bb8b800661653cc1c65b294eab621554af139aChris Wren // stop making noise - this is a weird corner case, but quiet should override once 52893bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(s); 52993bb8b800661653cc1c65b294eab621554af139aChris Wren verifyStopAudio(); 53093bb8b800661653cc1c65b294eab621554af139aChris Wren } 53193bb8b800661653cc1c65b294eab621554af139aChris Wren 5320ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 5330c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds public void testNoDemoteSoundToVibrateIfVibrateGiven() throws Exception { 5340c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds NotificationRecord r = getBuzzyBeepyNotification(); 5350c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds assertTrue(r.getSound() != null); 5360c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds 5370c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds // the phone is quiet 5380c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); 5390c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds 5400c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds mService.buzzBeepBlinkLocked(r); 5410c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds 5427121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright VibrationEffect effect = VibrationEffect.createWaveform(r.getVibration(), -1); 5437121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright 544ea0eb5f5813d63283d9b069510418e495d4cc137Jean-Michel Trivi verify(mVibrator, timeout(MAX_VIBRATION_DELAY).times(1)).vibrate(anyInt(), anyString(), 545ea0eb5f5813d63283d9b069510418e495d4cc137Jean-Michel Trivi eq(effect), (AudioAttributes) anyObject()); 5460c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds } 5470c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds 5480c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds @Test 54993bb8b800661653cc1c65b294eab621554af139aChris Wren public void testDemoteSoundToVibrate() throws Exception { 55093bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBeepyNotification(); 5510c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds assertTrue(r.getSound() != null); 5520c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds assertNull(r.getVibration()); 55393bb8b800661653cc1c65b294eab621554af139aChris Wren 55493bb8b800661653cc1c65b294eab621554af139aChris Wren // the phone is quiet 55593bb8b800661653cc1c65b294eab621554af139aChris Wren when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); 55693bb8b800661653cc1c65b294eab621554af139aChris Wren 55793bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 55893bb8b800661653cc1c65b294eab621554af139aChris Wren 559ea0eb5f5813d63283d9b069510418e495d4cc137Jean-Michel Trivi verify(mVibrator, timeout(MAX_VIBRATION_DELAY).times(1)).vibrate(anyInt(), anyString(), 560ea0eb5f5813d63283d9b069510418e495d4cc137Jean-Michel Trivi eq(FALLBACK_VIBRATION), (AudioAttributes) anyObject()); 561619a69f722b75241b372cf7b01b45b2dd1c862faJulia Reynolds verify(mRingtonePlayer, never()).playAsync 562619a69f722b75241b372cf7b01b45b2dd1c862faJulia Reynolds (anyObject(), anyObject(), anyBoolean(), anyObject()); 56393bb8b800661653cc1c65b294eab621554af139aChris Wren } 56493bb8b800661653cc1c65b294eab621554af139aChris Wren 5650ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 5660c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds public void testDemoteInsistentSoundToVibrate() throws Exception { 56793bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getInsistentBeepyNotification(); 5680c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds assertTrue(r.getSound() != null); 5690c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds assertNull(r.getVibration()); 57093bb8b800661653cc1c65b294eab621554af139aChris Wren 57193bb8b800661653cc1c65b294eab621554af139aChris Wren // the phone is quiet 57293bb8b800661653cc1c65b294eab621554af139aChris Wren when(mAudioManager.getStreamVolume(anyInt())).thenReturn(0); 57393bb8b800661653cc1c65b294eab621554af139aChris Wren when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); 57493bb8b800661653cc1c65b294eab621554af139aChris Wren 57593bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 57693bb8b800661653cc1c65b294eab621554af139aChris Wren 577ea0eb5f5813d63283d9b069510418e495d4cc137Jean-Michel Trivi verifyDelayedVibrateLooped(); 57893bb8b800661653cc1c65b294eab621554af139aChris Wren } 57993bb8b800661653cc1c65b294eab621554af139aChris Wren 5800ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 58193bb8b800661653cc1c65b294eab621554af139aChris Wren public void testVibrate() throws Exception { 58293bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBuzzyNotification(); 58393bb8b800661653cc1c65b294eab621554af139aChris Wren 58493bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 58593bb8b800661653cc1c65b294eab621554af139aChris Wren 58693bb8b800661653cc1c65b294eab621554af139aChris Wren verifyNeverBeep(); 58793bb8b800661653cc1c65b294eab621554af139aChris Wren verifyVibrate(); 58893bb8b800661653cc1c65b294eab621554af139aChris Wren } 58993bb8b800661653cc1c65b294eab621554af139aChris Wren 5900ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 591a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds public void testInsistentVibrate() throws Exception { 59293bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getInsistentBuzzyNotification(); 59393bb8b800661653cc1c65b294eab621554af139aChris Wren 59493bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 59593bb8b800661653cc1c65b294eab621554af139aChris Wren verifyVibrateLooped(); 59693bb8b800661653cc1c65b294eab621554af139aChris Wren } 59793bb8b800661653cc1c65b294eab621554af139aChris Wren 5980ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 599a33f5c4312ce708933454dfd1b154ccc46be099cJulia Reynolds public void testVibrateTwice() throws Exception { 60093bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBuzzyNotification(); 60193bb8b800661653cc1c65b294eab621554af139aChris Wren 60293bb8b800661653cc1c65b294eab621554af139aChris Wren // set up internal state 60393bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 60493bb8b800661653cc1c65b294eab621554af139aChris Wren Mockito.reset(mVibrator); 60593bb8b800661653cc1c65b294eab621554af139aChris Wren 60693bb8b800661653cc1c65b294eab621554af139aChris Wren // update should vibrate 60793bb8b800661653cc1c65b294eab621554af139aChris Wren r.isUpdate = true; 60893bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 60993bb8b800661653cc1c65b294eab621554af139aChris Wren verifyVibrate(); 61093bb8b800661653cc1c65b294eab621554af139aChris Wren } 61193bb8b800661653cc1c65b294eab621554af139aChris Wren 6120ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 613a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds public void testGroupAlertSummarySilenceChild() throws Exception { 614a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds NotificationRecord child = getBeepyNotificationRecord("a", GROUP_ALERT_SUMMARY); 615a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 616a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds mService.buzzBeepBlinkLocked(child); 617a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 618a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds verifyNeverBeep(); 619a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds } 620a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 621a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds @Test 622a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds public void testGroupAlertSummaryNoSilenceSummary() throws Exception { 623a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds NotificationRecord summary = getBeepyNotificationRecord("a", GROUP_ALERT_SUMMARY); 624a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds summary.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY; 625a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 626a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds mService.buzzBeepBlinkLocked(summary); 627a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 628a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds verifyBeepLooped(); 629a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds } 630a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 631a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds @Test 632a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds public void testGroupAlertSummaryNoSilenceNonGroupChild() throws Exception { 633a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds NotificationRecord nonGroup = getBeepyNotificationRecord(null, GROUP_ALERT_SUMMARY); 634a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 635a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds mService.buzzBeepBlinkLocked(nonGroup); 636a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 637a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds verifyBeepLooped(); 638a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds } 639a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 640a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds @Test 641a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds public void testGroupAlertChildSilenceSummary() throws Exception { 642a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds NotificationRecord summary = getBeepyNotificationRecord("a", GROUP_ALERT_CHILDREN); 643a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds summary.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY; 644a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 645a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds mService.buzzBeepBlinkLocked(summary); 646a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 647a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds verifyNeverBeep(); 648a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds } 649a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 650a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds @Test 651a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds public void testGroupAlertChildNoSilenceChild() throws Exception { 652a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds NotificationRecord child = getBeepyNotificationRecord("a", GROUP_ALERT_CHILDREN); 653a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 654a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds mService.buzzBeepBlinkLocked(child); 655a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 656a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds verifyBeepLooped(); 657a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds } 658a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 659a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds @Test 660a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds public void testGroupAlertChildNoSilenceNonGroupSummary() throws Exception { 661a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds NotificationRecord nonGroup = getBeepyNotificationRecord(null, GROUP_ALERT_CHILDREN); 662a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 663a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds mService.buzzBeepBlinkLocked(nonGroup); 664a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 665a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds verifyBeepLooped(); 666a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds } 667a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 668a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds @Test 669a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds public void testGroupAlertAllNoSilenceGroup() throws Exception { 670a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds NotificationRecord group = getBeepyNotificationRecord("a", GROUP_ALERT_ALL); 671a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 672a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds mService.buzzBeepBlinkLocked(group); 673a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 674a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds verifyBeepLooped(); 675a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds } 676a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds 677a79c37170e818f57e1bac843998fd0ae30eba71aJulia Reynolds @Test 67893bb8b800661653cc1c65b294eab621554af139aChris Wren public void testHonorAlertOnlyOnceForBuzz() throws Exception { 67993bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBuzzyNotification(); 68093bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord s = getBuzzyOnceNotification(); 68193bb8b800661653cc1c65b294eab621554af139aChris Wren s.isUpdate = true; 68293bb8b800661653cc1c65b294eab621554af139aChris Wren 68393bb8b800661653cc1c65b294eab621554af139aChris Wren // set up internal state 68493bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 68593bb8b800661653cc1c65b294eab621554af139aChris Wren Mockito.reset(mVibrator); 68693bb8b800661653cc1c65b294eab621554af139aChris Wren 68793bb8b800661653cc1c65b294eab621554af139aChris Wren // update should not beep 68893bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(s); 68993bb8b800661653cc1c65b294eab621554af139aChris Wren verifyNeverVibrate(); 69093bb8b800661653cc1c65b294eab621554af139aChris Wren } 69193bb8b800661653cc1c65b294eab621554af139aChris Wren 6920ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 69393bb8b800661653cc1c65b294eab621554af139aChris Wren public void testNoisyUpdateDoesNotCancelVibrate() throws Exception { 69493bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBuzzyNotification(); 69593bb8b800661653cc1c65b294eab621554af139aChris Wren 69693bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 69793bb8b800661653cc1c65b294eab621554af139aChris Wren r.isUpdate = true; 69893bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 69993bb8b800661653cc1c65b294eab621554af139aChris Wren 70093bb8b800661653cc1c65b294eab621554af139aChris Wren verifyNeverStopVibrate(); 70193bb8b800661653cc1c65b294eab621554af139aChris Wren } 70293bb8b800661653cc1c65b294eab621554af139aChris Wren 7030ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 70493bb8b800661653cc1c65b294eab621554af139aChris Wren public void testNoisyOnceUpdateDoesNotCancelVibrate() throws Exception { 70593bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBuzzyNotification(); 70693bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord s = getBuzzyOnceNotification(); 70793bb8b800661653cc1c65b294eab621554af139aChris Wren s.isUpdate = true; 70893bb8b800661653cc1c65b294eab621554af139aChris Wren 70993bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 71093bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(s); 71193bb8b800661653cc1c65b294eab621554af139aChris Wren 71293bb8b800661653cc1c65b294eab621554af139aChris Wren verifyNeverStopVibrate(); 71393bb8b800661653cc1c65b294eab621554af139aChris Wren } 71493bb8b800661653cc1c65b294eab621554af139aChris Wren 7150ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 71693bb8b800661653cc1c65b294eab621554af139aChris Wren public void testQuietUpdateDoesNotCancelVibrateFromOther() throws Exception { 71793bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBuzzyNotification(); 71893bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord s = getQuietNotification(); 71993bb8b800661653cc1c65b294eab621554af139aChris Wren s.isUpdate = true; 72093bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord other = getNoisyOtherNotification(); 72193bb8b800661653cc1c65b294eab621554af139aChris Wren 72293bb8b800661653cc1c65b294eab621554af139aChris Wren // set up internal state 72393bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 72493bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(other); // this takes the vibrate stream 72593bb8b800661653cc1c65b294eab621554af139aChris Wren Mockito.reset(mVibrator); 72693bb8b800661653cc1c65b294eab621554af139aChris Wren 72793bb8b800661653cc1c65b294eab621554af139aChris Wren // should not stop vibrate, since we no longer own it 72893bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(s); // this no longer owns the stream 72993bb8b800661653cc1c65b294eab621554af139aChris Wren verifyNeverStopVibrate(); 73093bb8b800661653cc1c65b294eab621554af139aChris Wren } 73193bb8b800661653cc1c65b294eab621554af139aChris Wren 7320ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 73393bb8b800661653cc1c65b294eab621554af139aChris Wren public void testQuietInterloperDoesNotCancelVibrate() throws Exception { 73493bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBuzzyNotification(); 73593bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord other = getQuietOtherNotification(); 73693bb8b800661653cc1c65b294eab621554af139aChris Wren 73793bb8b800661653cc1c65b294eab621554af139aChris Wren // set up internal state 73893bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 73993bb8b800661653cc1c65b294eab621554af139aChris Wren Mockito.reset(mVibrator); 74093bb8b800661653cc1c65b294eab621554af139aChris Wren 74193bb8b800661653cc1c65b294eab621554af139aChris Wren // should not stop noise, since it does not own it 74293bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(other); 74393bb8b800661653cc1c65b294eab621554af139aChris Wren verifyNeverStopVibrate(); 74493bb8b800661653cc1c65b294eab621554af139aChris Wren } 74593bb8b800661653cc1c65b294eab621554af139aChris Wren 7460ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 74793bb8b800661653cc1c65b294eab621554af139aChris Wren public void testQuietUpdateCancelsVibrate() throws Exception { 74893bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBuzzyNotification(); 74993bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord s = getQuietNotification(); 75093bb8b800661653cc1c65b294eab621554af139aChris Wren s.isUpdate = true; 75193bb8b800661653cc1c65b294eab621554af139aChris Wren 75293bb8b800661653cc1c65b294eab621554af139aChris Wren // set up internal state 75393bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 7540c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds verifyVibrate(); 75593bb8b800661653cc1c65b294eab621554af139aChris Wren 75693bb8b800661653cc1c65b294eab621554af139aChris Wren // quiet update should stop making noise 75793bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(s); 75893bb8b800661653cc1c65b294eab621554af139aChris Wren verifyStopVibrate(); 75993bb8b800661653cc1c65b294eab621554af139aChris Wren } 76093bb8b800661653cc1c65b294eab621554af139aChris Wren 7610ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 7620c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds public void testQuietOnceUpdateCancelVibrate() throws Exception { 76393bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBuzzyNotification(); 76493bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord s = getQuietOnceNotification(); 76593bb8b800661653cc1c65b294eab621554af139aChris Wren s.isUpdate = true; 76693bb8b800661653cc1c65b294eab621554af139aChris Wren 76793bb8b800661653cc1c65b294eab621554af139aChris Wren // set up internal state 76893bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 7690c299d4d6316d14e43d386b4562782083fe3c886Julia Reynolds verifyVibrate(); 77093bb8b800661653cc1c65b294eab621554af139aChris Wren 77193bb8b800661653cc1c65b294eab621554af139aChris Wren // stop making noise - this is a weird corner case, but quiet should override once 77293bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(s); 77393bb8b800661653cc1c65b294eab621554af139aChris Wren verifyStopVibrate(); 77493bb8b800661653cc1c65b294eab621554af139aChris Wren } 77593bb8b800661653cc1c65b294eab621554af139aChris Wren 7760ffe755d9fbabaffc5975bff3e81c165ae5f4a81Geoffrey Pitsch @Test 77793bb8b800661653cc1c65b294eab621554af139aChris Wren public void testQuietUpdateCancelsDemotedVibrate() throws Exception { 77893bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord r = getBeepyNotification(); 77993bb8b800661653cc1c65b294eab621554af139aChris Wren NotificationRecord s = getQuietNotification(); 78093bb8b800661653cc1c65b294eab621554af139aChris Wren 78193bb8b800661653cc1c65b294eab621554af139aChris Wren // the phone is quiet 78293bb8b800661653cc1c65b294eab621554af139aChris Wren when(mAudioManager.getStreamVolume(anyInt())).thenReturn(0); 78393bb8b800661653cc1c65b294eab621554af139aChris Wren when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); 78493bb8b800661653cc1c65b294eab621554af139aChris Wren 78593bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(r); 78693bb8b800661653cc1c65b294eab621554af139aChris Wren 78793bb8b800661653cc1c65b294eab621554af139aChris Wren // quiet update should stop making noise 78893bb8b800661653cc1c65b294eab621554af139aChris Wren mService.buzzBeepBlinkLocked(s); 78993bb8b800661653cc1c65b294eab621554af139aChris Wren verifyStopVibrate(); 79093bb8b800661653cc1c65b294eab621554af139aChris Wren } 7917121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright 792ca80d1632e205ac93e234203947efad4f8c7a164Julia Reynolds @Test 793ca80d1632e205ac93e234203947efad4f8c7a164Julia Reynolds public void testEmptyUriSoundTreatedAsNoSound() throws Exception { 794ca80d1632e205ac93e234203947efad4f8c7a164Julia Reynolds NotificationChannel channel = new NotificationChannel("test", "test", IMPORTANCE_HIGH); 795ca80d1632e205ac93e234203947efad4f8c7a164Julia Reynolds channel.setSound(Uri.EMPTY, null); 796ca80d1632e205ac93e234203947efad4f8c7a164Julia Reynolds final Notification n = new Builder(getContext(), "test") 797ca80d1632e205ac93e234203947efad4f8c7a164Julia Reynolds .setSmallIcon(android.R.drawable.sym_def_app_icon).build(); 798ca80d1632e205ac93e234203947efad4f8c7a164Julia Reynolds 799ca80d1632e205ac93e234203947efad4f8c7a164Julia Reynolds StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 0, mTag, mUid, 800ca80d1632e205ac93e234203947efad4f8c7a164Julia Reynolds mPid, n, mUser, null, System.currentTimeMillis()); 801a22f644c79213138c232f3067b5f780a9c43b04cGeoffrey Pitsch NotificationRecord r = new NotificationRecord(getContext(), sbn, channel); 802ca80d1632e205ac93e234203947efad4f8c7a164Julia Reynolds mService.addNotification(r); 803ca80d1632e205ac93e234203947efad4f8c7a164Julia Reynolds 804ca80d1632e205ac93e234203947efad4f8c7a164Julia Reynolds mService.buzzBeepBlinkLocked(r); 805ca80d1632e205ac93e234203947efad4f8c7a164Julia Reynolds 806ca80d1632e205ac93e234203947efad4f8c7a164Julia Reynolds verifyNeverBeep(); 807ca80d1632e205ac93e234203947efad4f8c7a164Julia Reynolds } 808ca80d1632e205ac93e234203947efad4f8c7a164Julia Reynolds 8097121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright static class VibrateRepeatMatcher implements ArgumentMatcher<VibrationEffect> { 8107121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright private final int mRepeatIndex; 8117121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright 8127121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright VibrateRepeatMatcher(int repeatIndex) { 8137121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright mRepeatIndex = repeatIndex; 8147121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright } 8157121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright 8167121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright @Override 8177121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright public boolean matches(VibrationEffect actual) { 8187121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright if (actual instanceof VibrationEffect.Waveform && 8197121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright ((VibrationEffect.Waveform) actual).getRepeatIndex() == mRepeatIndex) { 8207121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright return true; 8217121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright } 8227121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright // All non-waveform effects are essentially one shots. 8237121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright return mRepeatIndex == -1; 8247121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright } 8257121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright 8267121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright @Override 8277121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright public String toString() { 8287121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright return "repeatIndex=" + mRepeatIndex; 8297121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright } 8307121697a5e2d4458f6f63e9eb3b5deec62ee6202Michael Wright } 83193bb8b800661653cc1c65b294eab621554af139aChris Wren} 832