Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 85e7dbc9 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Send a11y updates for updated notifications" into oc-mr1-dev

parents 2d7a4a3f 9418756a
Loading
Loading
Loading
Loading
+23 −8
Original line number Diff line number Diff line
@@ -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;
@@ -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,
@@ -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;
@@ -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);
@@ -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;
@@ -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;
        }

@@ -4571,7 +4586,7 @@ public class NotificationManagerService extends SystemService {
            event.getText().add(tickerText);
        }

        manager.sendAccessibilityEvent(event);
        mAccessibilityManager.sendAccessibilityEvent(event);
    }

    /**
+51 −6
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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)
@@ -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";
@@ -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);
@@ -130,6 +149,7 @@ public class BuzzBeepBlinkTest extends NotificationTestCase {
        mService.setScreenOn(false);
        mService.setFallbackVibrationPattern(FALLBACK_VIBRATION_PATTERN);
        mService.setUsageStats(mUsageStats);
        mService.setAccessibilityManager(accessibilityManager);
    }

    //
@@ -381,6 +401,7 @@ public class BuzzBeepBlinkTest extends NotificationTestCase {

        verifyBeepLooped();
        verifyNeverVibrate();
        verify(mAccessibilityService, times(1)).sendAccessibilityEvent(any(), anyInt());
    }

    @Test
@@ -435,6 +456,7 @@ public class BuzzBeepBlinkTest extends NotificationTestCase {
        r.isUpdate = true;
        mService.buzzBeepBlinkLocked(r);
        verifyBeepLooped();
        verify(mAccessibilityService, times(2)).sendAccessibilityEvent(any(), anyInt());
    }

    @Test
@@ -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
@@ -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
    }

@@ -842,7 +865,6 @@ public class BuzzBeepBlinkTest extends NotificationTestCase {
        mService.addNotification(r);

        mService.buzzBeepBlinkLocked(r);

        verifyNeverBeep();
    }

@@ -870,7 +892,6 @@ public class BuzzBeepBlinkTest extends NotificationTestCase {
        summary.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY;

        mService.buzzBeepBlinkLocked(summary);

        verify(mUsageStats, never()).isAlertRateLimited(any());
    }

@@ -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;

+3 −0
Original line number Diff line number Diff line
@@ -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);
                }
@@ -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);
                }
@@ -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);
                }