From 280d6f4bf2814daffc48ec769b1a097e6ec72ff4 Mon Sep 17 00:00:00 2001 From: David Krska Date: Fri, 21 Jun 2024 16:08:50 +0100 Subject: 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 --- core/res/res/values/config.xml | 3 +++ core/res/res/values/symbols.xml | 1 + .../notification/NotificationAttentionHelper.java | 6 ++++- .../NotificationAttentionHelperTest.java | 30 ++++++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 4f0a836224f9..dc3d9355f148 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -533,6 +533,9 @@ true + + true + false diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 419a615d92ff..d25f59d7c488 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -2006,6 +2006,7 @@ + diff --git a/services/core/java/com/android/server/notification/NotificationAttentionHelper.java b/services/core/java/com/android/server/notification/NotificationAttentionHelper.java index 614a0a59c691..5a9cf0326244 100644 --- a/services/core/java/com/android/server/notification/NotificationAttentionHelper.java +++ b/services/core/java/com/android/server/notification/NotificationAttentionHelper.java @@ -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; } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationAttentionHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationAttentionHelperTest.java index 2233aa2eed0f..28a5db904bd9 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationAttentionHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationAttentionHelperTest.java @@ -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 { private final int mRepeatIndex; -- cgit v1.2.3-59-g8ed1b