Loading services/core/java/com/android/server/notification/NotificationManagerService.java +23 −8 Original line number Diff line number Diff line Loading @@ -281,6 +281,7 @@ public class NotificationManagerService extends SystemService { private WindowManagerInternal mWindowManagerInternal; private AlarmManager mAlarmManager; private ICompanionDeviceManager mCompanionManager; private AccessibilityManager mAccessibilityManager; final IBinder mForegroundToken = new Binder(); private WorkerHandler mHandler; Loading Loading @@ -1190,6 +1191,12 @@ public class NotificationManagerService extends SystemService { mUsageStats = us; } @VisibleForTesting void setAccessibilityManager(AccessibilityManager am) { mAccessibilityManager = am; } // TODO: All tests should use this init instead of the one-off setters above. @VisibleForTesting void init(Looper looper, IPackageManager packageManager, Loading @@ -1204,6 +1211,8 @@ public class NotificationManagerService extends SystemService { Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE, DEFAULT_MAX_NOTIFICATION_ENQUEUE_RATE); mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); mAm = ActivityManager.getService(); mPackageManager = packageManager; mPackageManagerClient = packageManagerClient; Loading Loading @@ -4015,13 +4024,16 @@ public class NotificationManagerService extends SystemService { // These are set inside the conditional if the notification is allowed to make noise. boolean hasValidVibrate = false; boolean hasValidSound = false; if (aboveThreshold && isNotificationForCurrentUser(record)) { boolean sentAccessibilityEvent = false; // If the notification will appear in the status bar, it should send an accessibility // event if (!record.isUpdate && record.getImportance() > IMPORTANCE_MIN) { sendAccessibilityEvent(notification, record.sbn.getPackageName()); sentAccessibilityEvent = true; } if (aboveThreshold && isNotificationForCurrentUser(record)) { if (mSystemReady && mAudioManager != null) { Uri soundUri = record.getSound(); hasValidSound = soundUri != null && !Uri.EMPTY.equals(soundUri); Loading @@ -4039,6 +4051,10 @@ public class NotificationManagerService extends SystemService { boolean hasAudibleAlert = hasValidSound || hasValidVibrate; if (hasAudibleAlert && !shouldMuteNotificationLocked(record)) { if (!sentAccessibilityEvent) { sendAccessibilityEvent(notification, record.sbn.getPackageName()); sentAccessibilityEvent = true; } if (DBG) Slog.v(TAG, "Interrupting!"); if (hasValidSound) { mSoundNotificationKey = key; Loading Loading @@ -4556,8 +4572,7 @@ public class NotificationManagerService extends SystemService { } void sendAccessibilityEvent(Notification notification, CharSequence packageName) { AccessibilityManager manager = AccessibilityManager.getInstance(getContext()); if (!manager.isEnabled()) { if (!mAccessibilityManager.isEnabled()) { return; } Loading @@ -4571,7 +4586,7 @@ public class NotificationManagerService extends SystemService { event.getText().add(tickerText); } manager.sendAccessibilityEvent(event); mAccessibilityManager.sendAccessibilityEvent(event); } /** Loading services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java +51 −6 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import static android.app.Notification.GROUP_ALERT_ALL; import static android.app.Notification.GROUP_ALERT_CHILDREN; import static android.app.Notification.GROUP_ALERT_SUMMARY; import static android.app.NotificationManager.IMPORTANCE_HIGH; import static android.app.NotificationManager.IMPORTANCE_MIN; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertTrue; Loading Loading @@ -57,7 +58,13 @@ import android.provider.Settings; import android.service.notification.StatusBarNotification; import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; import android.util.Slog; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; import android.view.accessibility.IAccessibilityManager; import android.view.accessibility.IAccessibilityManagerClient; import com.android.internal.util.IntPair; import com.android.server.lights.Light; import org.junit.Before; Loading @@ -67,6 +74,8 @@ import org.mockito.ArgumentMatcher; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @SmallTest @RunWith(AndroidJUnit4.class) Loading @@ -80,6 +89,8 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { NotificationManagerService.WorkerHandler mHandler; @Mock NotificationUsageStats mUsageStats; @Mock IAccessibilityManager mAccessibilityService; private NotificationManagerService mService; private String mPkg = "com.android.server.notification"; Loading Loading @@ -111,17 +122,25 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { private static final int MAX_VIBRATION_DELAY = 1000; @Before public void setUp() { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(mAudioManager.isAudioFocusExclusive()).thenReturn(false); when(mAudioManager.getRingtonePlayer()).thenReturn(mRingtonePlayer); when(mAudioManager.getStreamVolume(anyInt())).thenReturn(10); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL); when(mUsageStats.isAlertRateLimited(any())).thenReturn(false); mService = new NotificationManagerService(getContext()); long serviceReturnValue = IntPair.of( AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED, AccessibilityEvent.TYPES_ALL_MASK); when(mAccessibilityService.addClient(any(), anyInt())).thenReturn(serviceReturnValue); AccessibilityManager accessibilityManager = new AccessibilityManager(Handler.getMain(), mAccessibilityService, 0); verify(mAccessibilityService).addClient(any(IAccessibilityManagerClient.class), anyInt()); assertTrue(accessibilityManager.isEnabled()); mService = spy(new NotificationManagerService(getContext())); mService.setAudioManager(mAudioManager); mService.setVibrator(mVibrator); mService.setSystemReady(true); Loading @@ -130,6 +149,7 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { mService.setScreenOn(false); mService.setFallbackVibrationPattern(FALLBACK_VIBRATION_PATTERN); mService.setUsageStats(mUsageStats); mService.setAccessibilityManager(accessibilityManager); } // Loading Loading @@ -381,6 +401,7 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { verifyBeepLooped(); verifyNeverVibrate(); verify(mAccessibilityService, times(1)).sendAccessibilityEvent(any(), anyInt()); } @Test Loading Loading @@ -435,6 +456,7 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { r.isUpdate = true; mService.buzzBeepBlinkLocked(r); verifyBeepLooped(); verify(mAccessibilityService, times(2)).sendAccessibilityEvent(any(), anyInt()); } @Test Loading @@ -450,6 +472,7 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { // update should not beep mService.buzzBeepBlinkLocked(s); verifyNeverBeep(); verify(mAccessibilityService, times(1)).sendAccessibilityEvent(any(), anyInt()); } @Test Loading Loading @@ -547,7 +570,7 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { mService.mInCall = true; mService.buzzBeepBlinkLocked(r); //verify(mService, times(1)).playInCallNotification(); verify(mService, times(1)).playInCallNotification(); verifyNeverBeep(); // doesn't play normal beep } Loading Loading @@ -842,7 +865,6 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { mService.addNotification(r); mService.buzzBeepBlinkLocked(r); verifyNeverBeep(); } Loading Loading @@ -870,7 +892,6 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { summary.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY; mService.buzzBeepBlinkLocked(summary); verify(mUsageStats, never()).isAlertRateLimited(any()); } Loading @@ -889,6 +910,30 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { verifyNeverBeep(); } @Test public void testA11yMinInitialPost() throws Exception { NotificationRecord r = getQuietNotification(); r.setImportance(IMPORTANCE_MIN, ""); mService.buzzBeepBlinkLocked(r); verify(mAccessibilityService, never()).sendAccessibilityEvent(any(), anyInt()); } @Test public void testA11yQuietInitialPost() throws Exception { NotificationRecord r = getQuietNotification(); mService.buzzBeepBlinkLocked(r); verify(mAccessibilityService, times(1)).sendAccessibilityEvent(any(), anyInt()); } @Test public void testA11yQuietUpdate() throws Exception { NotificationRecord r = getQuietNotification(); mService.buzzBeepBlinkLocked(r); r.isUpdate = true; mService.buzzBeepBlinkLocked(r); verify(mAccessibilityService, times(1)).sendAccessibilityEvent(any(), anyInt()); } static class VibrateRepeatMatcher implements ArgumentMatcher<VibrationEffect> { private final int mRepeatIndex; Loading tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java +3 −0 Original line number Diff line number Diff line Loading @@ -296,6 +296,7 @@ public class NotificationTestList extends TestActivity Notification n = new Notification.Builder(NotificationTestList.this, "min") .setSmallIcon(R.drawable.icon2) .setContentTitle("Min priority") .setTicker("Min priority") .build(); mNM.notify("min", 7000, n); } Loading @@ -306,6 +307,7 @@ public class NotificationTestList extends TestActivity Notification n = new Notification.Builder(NotificationTestList.this, "low") .setSmallIcon(R.drawable.icon2) .setContentTitle("Low priority") .setTicker("Low priority") .build(); mNM.notify("low", 7002, n); } Loading @@ -326,6 +328,7 @@ public class NotificationTestList extends TestActivity Notification n = new Notification.Builder(NotificationTestList.this, "high") .setSmallIcon(R.drawable.icon2) .setContentTitle("High priority") .setTicker("High priority") .build(); mNM.notify("high", 7006, n); } Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +23 −8 Original line number Diff line number Diff line Loading @@ -281,6 +281,7 @@ public class NotificationManagerService extends SystemService { private WindowManagerInternal mWindowManagerInternal; private AlarmManager mAlarmManager; private ICompanionDeviceManager mCompanionManager; private AccessibilityManager mAccessibilityManager; final IBinder mForegroundToken = new Binder(); private WorkerHandler mHandler; Loading Loading @@ -1190,6 +1191,12 @@ public class NotificationManagerService extends SystemService { mUsageStats = us; } @VisibleForTesting void setAccessibilityManager(AccessibilityManager am) { mAccessibilityManager = am; } // TODO: All tests should use this init instead of the one-off setters above. @VisibleForTesting void init(Looper looper, IPackageManager packageManager, Loading @@ -1204,6 +1211,8 @@ public class NotificationManagerService extends SystemService { Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE, DEFAULT_MAX_NOTIFICATION_ENQUEUE_RATE); mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); mAm = ActivityManager.getService(); mPackageManager = packageManager; mPackageManagerClient = packageManagerClient; Loading Loading @@ -4015,13 +4024,16 @@ public class NotificationManagerService extends SystemService { // These are set inside the conditional if the notification is allowed to make noise. boolean hasValidVibrate = false; boolean hasValidSound = false; if (aboveThreshold && isNotificationForCurrentUser(record)) { boolean sentAccessibilityEvent = false; // If the notification will appear in the status bar, it should send an accessibility // event if (!record.isUpdate && record.getImportance() > IMPORTANCE_MIN) { sendAccessibilityEvent(notification, record.sbn.getPackageName()); sentAccessibilityEvent = true; } if (aboveThreshold && isNotificationForCurrentUser(record)) { if (mSystemReady && mAudioManager != null) { Uri soundUri = record.getSound(); hasValidSound = soundUri != null && !Uri.EMPTY.equals(soundUri); Loading @@ -4039,6 +4051,10 @@ public class NotificationManagerService extends SystemService { boolean hasAudibleAlert = hasValidSound || hasValidVibrate; if (hasAudibleAlert && !shouldMuteNotificationLocked(record)) { if (!sentAccessibilityEvent) { sendAccessibilityEvent(notification, record.sbn.getPackageName()); sentAccessibilityEvent = true; } if (DBG) Slog.v(TAG, "Interrupting!"); if (hasValidSound) { mSoundNotificationKey = key; Loading Loading @@ -4556,8 +4572,7 @@ public class NotificationManagerService extends SystemService { } void sendAccessibilityEvent(Notification notification, CharSequence packageName) { AccessibilityManager manager = AccessibilityManager.getInstance(getContext()); if (!manager.isEnabled()) { if (!mAccessibilityManager.isEnabled()) { return; } Loading @@ -4571,7 +4586,7 @@ public class NotificationManagerService extends SystemService { event.getText().add(tickerText); } manager.sendAccessibilityEvent(event); mAccessibilityManager.sendAccessibilityEvent(event); } /** Loading
services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java +51 −6 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import static android.app.Notification.GROUP_ALERT_ALL; import static android.app.Notification.GROUP_ALERT_CHILDREN; import static android.app.Notification.GROUP_ALERT_SUMMARY; import static android.app.NotificationManager.IMPORTANCE_HIGH; import static android.app.NotificationManager.IMPORTANCE_MIN; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertTrue; Loading Loading @@ -57,7 +58,13 @@ import android.provider.Settings; import android.service.notification.StatusBarNotification; import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; import android.util.Slog; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; import android.view.accessibility.IAccessibilityManager; import android.view.accessibility.IAccessibilityManagerClient; import com.android.internal.util.IntPair; import com.android.server.lights.Light; import org.junit.Before; Loading @@ -67,6 +74,8 @@ import org.mockito.ArgumentMatcher; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @SmallTest @RunWith(AndroidJUnit4.class) Loading @@ -80,6 +89,8 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { NotificationManagerService.WorkerHandler mHandler; @Mock NotificationUsageStats mUsageStats; @Mock IAccessibilityManager mAccessibilityService; private NotificationManagerService mService; private String mPkg = "com.android.server.notification"; Loading Loading @@ -111,17 +122,25 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { private static final int MAX_VIBRATION_DELAY = 1000; @Before public void setUp() { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(mAudioManager.isAudioFocusExclusive()).thenReturn(false); when(mAudioManager.getRingtonePlayer()).thenReturn(mRingtonePlayer); when(mAudioManager.getStreamVolume(anyInt())).thenReturn(10); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL); when(mUsageStats.isAlertRateLimited(any())).thenReturn(false); mService = new NotificationManagerService(getContext()); long serviceReturnValue = IntPair.of( AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED, AccessibilityEvent.TYPES_ALL_MASK); when(mAccessibilityService.addClient(any(), anyInt())).thenReturn(serviceReturnValue); AccessibilityManager accessibilityManager = new AccessibilityManager(Handler.getMain(), mAccessibilityService, 0); verify(mAccessibilityService).addClient(any(IAccessibilityManagerClient.class), anyInt()); assertTrue(accessibilityManager.isEnabled()); mService = spy(new NotificationManagerService(getContext())); mService.setAudioManager(mAudioManager); mService.setVibrator(mVibrator); mService.setSystemReady(true); Loading @@ -130,6 +149,7 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { mService.setScreenOn(false); mService.setFallbackVibrationPattern(FALLBACK_VIBRATION_PATTERN); mService.setUsageStats(mUsageStats); mService.setAccessibilityManager(accessibilityManager); } // Loading Loading @@ -381,6 +401,7 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { verifyBeepLooped(); verifyNeverVibrate(); verify(mAccessibilityService, times(1)).sendAccessibilityEvent(any(), anyInt()); } @Test Loading Loading @@ -435,6 +456,7 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { r.isUpdate = true; mService.buzzBeepBlinkLocked(r); verifyBeepLooped(); verify(mAccessibilityService, times(2)).sendAccessibilityEvent(any(), anyInt()); } @Test Loading @@ -450,6 +472,7 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { // update should not beep mService.buzzBeepBlinkLocked(s); verifyNeverBeep(); verify(mAccessibilityService, times(1)).sendAccessibilityEvent(any(), anyInt()); } @Test Loading Loading @@ -547,7 +570,7 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { mService.mInCall = true; mService.buzzBeepBlinkLocked(r); //verify(mService, times(1)).playInCallNotification(); verify(mService, times(1)).playInCallNotification(); verifyNeverBeep(); // doesn't play normal beep } Loading Loading @@ -842,7 +865,6 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { mService.addNotification(r); mService.buzzBeepBlinkLocked(r); verifyNeverBeep(); } Loading Loading @@ -870,7 +892,6 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { summary.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY; mService.buzzBeepBlinkLocked(summary); verify(mUsageStats, never()).isAlertRateLimited(any()); } Loading @@ -889,6 +910,30 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { verifyNeverBeep(); } @Test public void testA11yMinInitialPost() throws Exception { NotificationRecord r = getQuietNotification(); r.setImportance(IMPORTANCE_MIN, ""); mService.buzzBeepBlinkLocked(r); verify(mAccessibilityService, never()).sendAccessibilityEvent(any(), anyInt()); } @Test public void testA11yQuietInitialPost() throws Exception { NotificationRecord r = getQuietNotification(); mService.buzzBeepBlinkLocked(r); verify(mAccessibilityService, times(1)).sendAccessibilityEvent(any(), anyInt()); } @Test public void testA11yQuietUpdate() throws Exception { NotificationRecord r = getQuietNotification(); mService.buzzBeepBlinkLocked(r); r.isUpdate = true; mService.buzzBeepBlinkLocked(r); verify(mAccessibilityService, times(1)).sendAccessibilityEvent(any(), anyInt()); } static class VibrateRepeatMatcher implements ArgumentMatcher<VibrationEffect> { private final int mRepeatIndex; Loading
tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java +3 −0 Original line number Diff line number Diff line Loading @@ -296,6 +296,7 @@ public class NotificationTestList extends TestActivity Notification n = new Notification.Builder(NotificationTestList.this, "min") .setSmallIcon(R.drawable.icon2) .setContentTitle("Min priority") .setTicker("Min priority") .build(); mNM.notify("min", 7000, n); } Loading @@ -306,6 +307,7 @@ public class NotificationTestList extends TestActivity Notification n = new Notification.Builder(NotificationTestList.this, "low") .setSmallIcon(R.drawable.icon2) .setContentTitle("Low priority") .setTicker("Low priority") .build(); mNM.notify("low", 7002, n); } Loading @@ -326,6 +328,7 @@ public class NotificationTestList extends TestActivity Notification n = new Notification.Builder(NotificationTestList.this, "high") .setSmallIcon(R.drawable.icon2) .setContentTitle("High priority") .setTicker("High priority") .build(); mNM.notify("high", 7006, n); } Loading