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

Commit 280d6f4b authored by David Krska's avatar David Krska
Browse files

Add a config allowing to disable notification accessibility events

On some devices notification accessibility events are posted by other system applications which leads to duplicate events. We want to be able to disable it for specific form-factors.

Bug: 338935444
Flag: EXEMPT bugfix
Test: Tested in b/338935444#comment57
Test: Built and flashed a Wear device
Change-Id: Ib0f60ad59b01cea29434798215a15e15cbe266b0
parent fd36953e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -533,6 +533,9 @@
    <!-- If this is true, key chords can be used to take a screenshot on the device. -->
    <bool name="config_enableScreenshotChord">true</bool>

    <!-- If this is true, accessibility events on notifications are sent. -->
    <bool name="config_enableNotificationAccessibilityEvents">true</bool>

    <!-- If this is true, allow wake from theater mode when plugged in or unplugged. -->
    <bool name="config_allowTheaterModeWakeFromUnplug">false</bool>
    <!-- If this is true, allow wake from theater mode from gesture. -->
+1 −0
Original line number Diff line number Diff line
@@ -2006,6 +2006,7 @@
  <java-symbol type="array" name="config_notificationFallbackVibeWaveform" />
  <java-symbol type="bool" name="config_enableServerNotificationEffectsForAutomotive" />
  <java-symbol type="bool" name="config_useAttentionLight" />
  <java-symbol type="bool" name="config_enableNotificationAccessibilityEvents" />
  <java-symbol type="bool" name="config_adaptive_sleep_available" />
  <java-symbol type="bool" name="config_camera_autorotate"/>
  <java-symbol type="bool" name="config_animateScreenLights" />
+5 −1
Original line number Diff line number Diff line
@@ -138,6 +138,7 @@ public final class NotificationAttentionHelper {

    private final boolean mUseAttentionLight;
    boolean mHasLight;
    private final boolean mEnableNotificationAccessibilityEvents;

    private final SettingsObserver mSettingsObserver;

@@ -190,6 +191,9 @@ public final class NotificationAttentionHelper {
        mUseAttentionLight = resources.getBoolean(R.bool.config_useAttentionLight);
        mHasLight =
                resources.getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed);
        mEnableNotificationAccessibilityEvents =
                resources.getBoolean(
                        com.android.internal.R.bool.config_enableNotificationAccessibilityEvents);

        // Don't start allowing notifications until the setup wizard has run once.
        // After that, including subsequent boots, init with notifications turned on.
@@ -1030,7 +1034,7 @@ public final class NotificationAttentionHelper {
    }

    void sendAccessibilityEvent(NotificationRecord record) {
        if (!mAccessibilityManager.isEnabled()) {
        if (!mAccessibilityManager.isEnabled() || !mEnableNotificationAccessibilityEvents) {
            return;
        }

+30 −0
Original line number Diff line number Diff line
@@ -227,6 +227,8 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase {
        when(resources.getBoolean(R.bool.config_useAttentionLight)).thenReturn(true);
        when(resources.getBoolean(
                com.android.internal.R.bool.config_intrusiveNotificationLed)).thenReturn(true);
        when(resources.getBoolean(R.bool.config_enableNotificationAccessibilityEvents))
                .thenReturn(true);
        when(getContext().getResources()).thenReturn(resources);

        // TODO (b/291907312): remove feature flag
@@ -2830,6 +2832,34 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase {
        assertThat(r.getRankingTimeMs()).isEqualTo(r.getSbn().getPostTime());
    }

    @Test
    public void testAccessibilityEventsEnabledInConfig() throws Exception {
        Resources resources = spy(getContext().getResources());
        when(resources.getBoolean(R.bool.config_enableNotificationAccessibilityEvents))
                .thenReturn(true);
        when(getContext().getResources()).thenReturn(resources);
        initAttentionHelper(mTestFlagResolver);
        NotificationRecord r = getBeepyNotification();

        mAttentionHelper.buzzBeepBlinkLocked(r, DEFAULT_SIGNALS);

        verify(mAccessibilityService).sendAccessibilityEvent(any(), anyInt());
    }

    @Test
    public void testAccessibilityEventsDisabledInConfig() throws Exception {
        Resources resources = spy(getContext().getResources());
        when(resources.getBoolean(R.bool.config_enableNotificationAccessibilityEvents))
                .thenReturn(false);
        when(getContext().getResources()).thenReturn(resources);
        initAttentionHelper(mTestFlagResolver);
        NotificationRecord r = getBeepyNotification();

        mAttentionHelper.buzzBeepBlinkLocked(r, DEFAULT_SIGNALS);

        verify(mAccessibilityService, never()).sendAccessibilityEvent(any(), anyInt());
    }

    static class VibrateRepeatMatcher implements ArgumentMatcher<VibrationEffect> {
        private final int mRepeatIndex;