Loading services/core/java/com/android/server/notification/NotificationManagerService.java +19 −0 Original line number Diff line number Diff line Loading @@ -1315,6 +1315,11 @@ public class NotificationManagerService extends SystemService { mAudioManager = audioMananger; } @VisibleForTesting void setHints(int hints) { mListenerHints = hints; } @VisibleForTesting void setVibrator(Vibrator vibrator) { mVibrator = vibrator; Loading Loading @@ -3992,6 +3997,20 @@ public class NotificationManagerService extends SystemService { if ((mListenerHints & HINT_HOST_DISABLE_EFFECTS) != 0) { return "listenerHints"; } if (record != null && record.getAudioAttributes() != null) { if ((mListenerHints & HINT_HOST_DISABLE_NOTIFICATION_EFFECTS) != 0) { if (record.getAudioAttributes().getUsage() != AudioAttributes.USAGE_VOICE_COMMUNICATION) { return "listenerNoti"; } } if ((mListenerHints & HINT_HOST_DISABLE_CALL_EFFECTS) != 0) { if (record.getAudioAttributes().getUsage() == AudioAttributes.USAGE_VOICE_COMMUNICATION) { return "listenerCall"; } } } if (mCallState != TelephonyManager.CALL_STATE_IDLE && !mZenModeHelper.isCall(record)) { return "callState"; } Loading services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java +65 −11 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ import android.os.UserHandle; import android.os.VibrationEffect; import android.os.Vibrator; import android.provider.Settings; import android.service.notification.NotificationListenerService; import android.service.notification.StatusBarNotification; import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; Loading Loading @@ -114,7 +115,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { private static final Uri CUSTOM_SOUND = Settings.System.DEFAULT_ALARM_ALERT_URI; private static final AudioAttributes CUSTOM_ATTRIBUTES = new AudioAttributes.Builder() .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN) .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE) .setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION) .build(); private static final int CUSTOM_LIGHT_COLOR = Color.BLACK; private static final int CUSTOM_LIGHT_ON = 10000; Loading Loading @@ -237,11 +238,11 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { false /* noisy */, false /* buzzy*/, true /* lights */); } private NotificationRecord getCustomLightsNotification() { return getNotificationRecord(mId, false /* insistent */, true /* once */, false /* noisy */, true /* buzzy*/, true /* lights */, true /* defaultVibration */, true /* defaultSound */, false /* defaultLights */, null, Notification.GROUP_ALERT_ALL, false); private NotificationRecord getCallRecord(int id, boolean insistent) { return getNotificationRecord(id, false, false /* once */, true /* noisy */, false /* buzzy */, false /* lights */, false /* default vib */, false /* default sound */, false /* default lights */, "", Notification.GROUP_ALERT_ALL, false); } private NotificationRecord getNotificationRecord(int id, boolean insistent, boolean once, Loading Loading @@ -351,11 +352,6 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { eq(false), (AudioAttributes) anyObject()); } private void verifyCustomBeep() throws RemoteException { verify(mRingtonePlayer, times(1)).playAsync(eq(CUSTOM_SOUND), (UserHandle) anyObject(), eq(false), (AudioAttributes) anyObject()); } private void verifyNeverStopAudio() throws RemoteException { verify(mRingtonePlayer, never()).stopAsync(); } Loading Loading @@ -1293,6 +1289,64 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { assertEquals(-1, group.getLastAudiblyAlertedMs()); } @Test public void testListenerHintCall() throws Exception { NotificationRecord r = getCallRecord(1, true); mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS); mService.buzzBeepBlinkLocked(r); verifyNeverBeep(); } @Test public void testListenerHintCall_notificationSound() throws Exception { NotificationRecord r = getBeepyNotification(); mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS); mService.buzzBeepBlinkLocked(r); verifyBeepLooped(); } @Test public void testListenerHintNotification() throws Exception { NotificationRecord r = getBeepyNotification(); mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS); mService.buzzBeepBlinkLocked(r); verifyNeverBeep(); } @Test public void testListenerHintBoth() throws Exception { NotificationRecord r = getCallRecord(1, true); NotificationRecord s = getBeepyNotification(); mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS | NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS); mService.buzzBeepBlinkLocked(r); mService.buzzBeepBlinkLocked(s); verifyNeverBeep(); } @Test public void testListenerHintNotification_callSound() throws Exception { NotificationRecord r = getCallRecord(1, true); mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS); mService.buzzBeepBlinkLocked(r); verifyBeepLooped(); } static class VibrateRepeatMatcher implements ArgumentMatcher<VibrationEffect> { private final int mRepeatIndex; Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +19 −0 Original line number Diff line number Diff line Loading @@ -1315,6 +1315,11 @@ public class NotificationManagerService extends SystemService { mAudioManager = audioMananger; } @VisibleForTesting void setHints(int hints) { mListenerHints = hints; } @VisibleForTesting void setVibrator(Vibrator vibrator) { mVibrator = vibrator; Loading Loading @@ -3992,6 +3997,20 @@ public class NotificationManagerService extends SystemService { if ((mListenerHints & HINT_HOST_DISABLE_EFFECTS) != 0) { return "listenerHints"; } if (record != null && record.getAudioAttributes() != null) { if ((mListenerHints & HINT_HOST_DISABLE_NOTIFICATION_EFFECTS) != 0) { if (record.getAudioAttributes().getUsage() != AudioAttributes.USAGE_VOICE_COMMUNICATION) { return "listenerNoti"; } } if ((mListenerHints & HINT_HOST_DISABLE_CALL_EFFECTS) != 0) { if (record.getAudioAttributes().getUsage() == AudioAttributes.USAGE_VOICE_COMMUNICATION) { return "listenerCall"; } } } if (mCallState != TelephonyManager.CALL_STATE_IDLE && !mZenModeHelper.isCall(record)) { return "callState"; } Loading
services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java +65 −11 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ import android.os.UserHandle; import android.os.VibrationEffect; import android.os.Vibrator; import android.provider.Settings; import android.service.notification.NotificationListenerService; import android.service.notification.StatusBarNotification; import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; Loading Loading @@ -114,7 +115,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { private static final Uri CUSTOM_SOUND = Settings.System.DEFAULT_ALARM_ALERT_URI; private static final AudioAttributes CUSTOM_ATTRIBUTES = new AudioAttributes.Builder() .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN) .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE) .setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION) .build(); private static final int CUSTOM_LIGHT_COLOR = Color.BLACK; private static final int CUSTOM_LIGHT_ON = 10000; Loading Loading @@ -237,11 +238,11 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { false /* noisy */, false /* buzzy*/, true /* lights */); } private NotificationRecord getCustomLightsNotification() { return getNotificationRecord(mId, false /* insistent */, true /* once */, false /* noisy */, true /* buzzy*/, true /* lights */, true /* defaultVibration */, true /* defaultSound */, false /* defaultLights */, null, Notification.GROUP_ALERT_ALL, false); private NotificationRecord getCallRecord(int id, boolean insistent) { return getNotificationRecord(id, false, false /* once */, true /* noisy */, false /* buzzy */, false /* lights */, false /* default vib */, false /* default sound */, false /* default lights */, "", Notification.GROUP_ALERT_ALL, false); } private NotificationRecord getNotificationRecord(int id, boolean insistent, boolean once, Loading Loading @@ -351,11 +352,6 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { eq(false), (AudioAttributes) anyObject()); } private void verifyCustomBeep() throws RemoteException { verify(mRingtonePlayer, times(1)).playAsync(eq(CUSTOM_SOUND), (UserHandle) anyObject(), eq(false), (AudioAttributes) anyObject()); } private void verifyNeverStopAudio() throws RemoteException { verify(mRingtonePlayer, never()).stopAsync(); } Loading Loading @@ -1293,6 +1289,64 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { assertEquals(-1, group.getLastAudiblyAlertedMs()); } @Test public void testListenerHintCall() throws Exception { NotificationRecord r = getCallRecord(1, true); mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS); mService.buzzBeepBlinkLocked(r); verifyNeverBeep(); } @Test public void testListenerHintCall_notificationSound() throws Exception { NotificationRecord r = getBeepyNotification(); mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS); mService.buzzBeepBlinkLocked(r); verifyBeepLooped(); } @Test public void testListenerHintNotification() throws Exception { NotificationRecord r = getBeepyNotification(); mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS); mService.buzzBeepBlinkLocked(r); verifyNeverBeep(); } @Test public void testListenerHintBoth() throws Exception { NotificationRecord r = getCallRecord(1, true); NotificationRecord s = getBeepyNotification(); mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS | NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS); mService.buzzBeepBlinkLocked(r); mService.buzzBeepBlinkLocked(s); verifyNeverBeep(); } @Test public void testListenerHintNotification_callSound() throws Exception { NotificationRecord r = getCallRecord(1, true); mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS); mService.buzzBeepBlinkLocked(r); verifyBeepLooped(); } static class VibrateRepeatMatcher implements ArgumentMatcher<VibrationEffect> { private final int mRepeatIndex; Loading