Loading services/core/java/com/android/server/notification/NotificationAttentionHelper.java +12 −4 Original line number Diff line number Diff line Loading @@ -135,7 +135,7 @@ public final class NotificationAttentionHelper { private LogicalLight mAttentionLight; private final boolean mUseAttentionLight; boolean mHasLight = true; boolean mHasLight; private final SettingsObserver mSettingsObserver; Loading @@ -149,7 +149,7 @@ public final class NotificationAttentionHelper { private boolean mInCallStateOffHook = false; private boolean mScreenOn = true; private boolean mUserPresent = false; boolean mNotificationPulseEnabled; private boolean mNotificationPulseEnabled; private final Uri mInCallNotificationUri; private final AudioAttributes mInCallNotificationAudioAttributes; private final float mInCallNotificationVolume; Loading Loading @@ -305,6 +305,13 @@ public final class NotificationAttentionHelper { } private void loadUserSettings() { boolean pulseEnabled = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.NOTIFICATION_LIGHT_PULSE, 0, UserHandle.USER_CURRENT) != 0; if (mNotificationPulseEnabled != pulseEnabled) { mNotificationPulseEnabled = pulseEnabled; updateLightsLocked(); } if (Flags.politeNotifications()) { try { mCurrentWorkProfileId = getManagedProfileId(ActivityManager.getCurrentUser()); Loading Loading @@ -874,6 +881,9 @@ public final class NotificationAttentionHelper { boolean canShowLightsLocked(final NotificationRecord record, final Signals signals, boolean aboveThreshold) { if (!mSystemReady) { return false; } // device lacks light if (!mHasLight) { return false; Loading Loading @@ -1721,8 +1731,6 @@ public final class NotificationAttentionHelper { void setLights(LogicalLight light) { mNotificationLight = light; mAttentionLight = light; mNotificationPulseEnabled = true; mHasLight = true; } @VisibleForTesting Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationAttentionHelperTest.java +62 −2 Original line number Diff line number Diff line Loading @@ -67,6 +67,7 @@ import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.pm.ShortcutInfo; import android.content.pm.UserInfo; import android.content.res.Resources; import android.graphics.Color; import android.graphics.drawable.Icon; import android.media.AudioAttributes; Loading @@ -93,6 +94,7 @@ import android.view.accessibility.IAccessibilityManagerClient; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; import com.android.internal.R; import com.android.internal.config.sysui.SystemUiSystemPropertiesFlags.NotificationFlags; import com.android.internal.config.sysui.TestableFlagResolver; import com.android.internal.logging.InstanceIdSequence; Loading Loading @@ -210,6 +212,16 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { verify(mAccessibilityService).addClient(any(IAccessibilityManagerClient.class), anyInt()); assertTrue(mAccessibilityManager.isEnabled()); // Enable LED pulse setting by default Settings.System.putInt(getContext().getContentResolver(), Settings.System.NOTIFICATION_LIGHT_PULSE, 1); Resources resources = spy(getContext().getResources()); when(resources.getBoolean(R.bool.config_useAttentionLight)).thenReturn(true); when(resources.getBoolean( com.android.internal.R.bool.config_intrusiveNotificationLed)).thenReturn(true); when(getContext().getResources()).thenReturn(resources); // TODO (b/291907312): remove feature flag // Disable feature flags by default. Tests should enable as needed. mSetFlagsRule.disableFlags(Flags.FLAG_POLITE_NOTIFICATIONS, Loading Loading @@ -239,7 +251,6 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { mAttentionHelper.setKeyguardManager(mKeyguardManager); mAttentionHelper.setScreenOn(false); mAttentionHelper.setInCallStateOffHook(false); mAttentionHelper.mNotificationPulseEnabled = true; if (Flags.crossAppPoliteNotifications()) { // Capture BroadcastReceiver for avalanche triggers Loading Loading @@ -611,6 +622,14 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { verify(mLight, times(1)).setFlashing(anyInt(), anyInt(), anyInt(), anyInt()); } private void verifyAttentionLights() { verify(mLight, times(1)).pulse(); } private void verifyNeverAttentionLights() { verify(mLight, never()).pulse(); } // // Tests // Loading Loading @@ -1524,7 +1543,25 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { @Test public void testLightsLightsOffGlobally() { mAttentionHelper.mNotificationPulseEnabled = false; Settings.System.putInt(getContext().getContentResolver(), Settings.System.NOTIFICATION_LIGHT_PULSE, 0); initAttentionHelper(mTestFlagResolver); NotificationRecord r = getLightsNotification(); mAttentionHelper.buzzBeepBlinkLocked(r, DEFAULT_SIGNALS); verifyNeverLights(); assertFalse(r.isInterruptive()); assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test public void testLightsLightsResConfigDisabled() { Resources resources = spy(getContext().getResources()); when(resources.getBoolean( com.android.internal.R.bool.config_intrusiveNotificationLed)).thenReturn(false); when(getContext().getResources()).thenReturn(resources); initAttentionHelper(mTestFlagResolver); NotificationRecord r = getLightsNotification(); mAttentionHelper.buzzBeepBlinkLocked(r, DEFAULT_SIGNALS); verifyNeverLights(); Loading @@ -1532,6 +1569,29 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test public void testLightsUseAttentionLight() { NotificationRecord r = getLightsNotification(); mAttentionHelper.buzzBeepBlinkLocked(r, DEFAULT_SIGNALS); verifyAttentionLights(); assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test public void testLightsUseAttentionLightDisabled() { Resources resources = spy(getContext().getResources()); when(resources.getBoolean(R.bool.config_useAttentionLight)).thenReturn(false); when(resources.getBoolean( com.android.internal.R.bool.config_intrusiveNotificationLed)).thenReturn(true); when(getContext().getResources()).thenReturn(resources); initAttentionHelper(mTestFlagResolver); NotificationRecord r = getLightsNotification(); mAttentionHelper.buzzBeepBlinkLocked(r, DEFAULT_SIGNALS); verifyNeverAttentionLights(); assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test public void testLightsDndIntercepted() { NotificationRecord r = getLightsNotification(); Loading Loading
services/core/java/com/android/server/notification/NotificationAttentionHelper.java +12 −4 Original line number Diff line number Diff line Loading @@ -135,7 +135,7 @@ public final class NotificationAttentionHelper { private LogicalLight mAttentionLight; private final boolean mUseAttentionLight; boolean mHasLight = true; boolean mHasLight; private final SettingsObserver mSettingsObserver; Loading @@ -149,7 +149,7 @@ public final class NotificationAttentionHelper { private boolean mInCallStateOffHook = false; private boolean mScreenOn = true; private boolean mUserPresent = false; boolean mNotificationPulseEnabled; private boolean mNotificationPulseEnabled; private final Uri mInCallNotificationUri; private final AudioAttributes mInCallNotificationAudioAttributes; private final float mInCallNotificationVolume; Loading Loading @@ -305,6 +305,13 @@ public final class NotificationAttentionHelper { } private void loadUserSettings() { boolean pulseEnabled = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.NOTIFICATION_LIGHT_PULSE, 0, UserHandle.USER_CURRENT) != 0; if (mNotificationPulseEnabled != pulseEnabled) { mNotificationPulseEnabled = pulseEnabled; updateLightsLocked(); } if (Flags.politeNotifications()) { try { mCurrentWorkProfileId = getManagedProfileId(ActivityManager.getCurrentUser()); Loading Loading @@ -874,6 +881,9 @@ public final class NotificationAttentionHelper { boolean canShowLightsLocked(final NotificationRecord record, final Signals signals, boolean aboveThreshold) { if (!mSystemReady) { return false; } // device lacks light if (!mHasLight) { return false; Loading Loading @@ -1721,8 +1731,6 @@ public final class NotificationAttentionHelper { void setLights(LogicalLight light) { mNotificationLight = light; mAttentionLight = light; mNotificationPulseEnabled = true; mHasLight = true; } @VisibleForTesting Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationAttentionHelperTest.java +62 −2 Original line number Diff line number Diff line Loading @@ -67,6 +67,7 @@ import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.pm.ShortcutInfo; import android.content.pm.UserInfo; import android.content.res.Resources; import android.graphics.Color; import android.graphics.drawable.Icon; import android.media.AudioAttributes; Loading @@ -93,6 +94,7 @@ import android.view.accessibility.IAccessibilityManagerClient; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; import com.android.internal.R; import com.android.internal.config.sysui.SystemUiSystemPropertiesFlags.NotificationFlags; import com.android.internal.config.sysui.TestableFlagResolver; import com.android.internal.logging.InstanceIdSequence; Loading Loading @@ -210,6 +212,16 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { verify(mAccessibilityService).addClient(any(IAccessibilityManagerClient.class), anyInt()); assertTrue(mAccessibilityManager.isEnabled()); // Enable LED pulse setting by default Settings.System.putInt(getContext().getContentResolver(), Settings.System.NOTIFICATION_LIGHT_PULSE, 1); Resources resources = spy(getContext().getResources()); when(resources.getBoolean(R.bool.config_useAttentionLight)).thenReturn(true); when(resources.getBoolean( com.android.internal.R.bool.config_intrusiveNotificationLed)).thenReturn(true); when(getContext().getResources()).thenReturn(resources); // TODO (b/291907312): remove feature flag // Disable feature flags by default. Tests should enable as needed. mSetFlagsRule.disableFlags(Flags.FLAG_POLITE_NOTIFICATIONS, Loading Loading @@ -239,7 +251,6 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { mAttentionHelper.setKeyguardManager(mKeyguardManager); mAttentionHelper.setScreenOn(false); mAttentionHelper.setInCallStateOffHook(false); mAttentionHelper.mNotificationPulseEnabled = true; if (Flags.crossAppPoliteNotifications()) { // Capture BroadcastReceiver for avalanche triggers Loading Loading @@ -611,6 +622,14 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { verify(mLight, times(1)).setFlashing(anyInt(), anyInt(), anyInt(), anyInt()); } private void verifyAttentionLights() { verify(mLight, times(1)).pulse(); } private void verifyNeverAttentionLights() { verify(mLight, never()).pulse(); } // // Tests // Loading Loading @@ -1524,7 +1543,25 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { @Test public void testLightsLightsOffGlobally() { mAttentionHelper.mNotificationPulseEnabled = false; Settings.System.putInt(getContext().getContentResolver(), Settings.System.NOTIFICATION_LIGHT_PULSE, 0); initAttentionHelper(mTestFlagResolver); NotificationRecord r = getLightsNotification(); mAttentionHelper.buzzBeepBlinkLocked(r, DEFAULT_SIGNALS); verifyNeverLights(); assertFalse(r.isInterruptive()); assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test public void testLightsLightsResConfigDisabled() { Resources resources = spy(getContext().getResources()); when(resources.getBoolean( com.android.internal.R.bool.config_intrusiveNotificationLed)).thenReturn(false); when(getContext().getResources()).thenReturn(resources); initAttentionHelper(mTestFlagResolver); NotificationRecord r = getLightsNotification(); mAttentionHelper.buzzBeepBlinkLocked(r, DEFAULT_SIGNALS); verifyNeverLights(); Loading @@ -1532,6 +1569,29 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase { assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test public void testLightsUseAttentionLight() { NotificationRecord r = getLightsNotification(); mAttentionHelper.buzzBeepBlinkLocked(r, DEFAULT_SIGNALS); verifyAttentionLights(); assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test public void testLightsUseAttentionLightDisabled() { Resources resources = spy(getContext().getResources()); when(resources.getBoolean(R.bool.config_useAttentionLight)).thenReturn(false); when(resources.getBoolean( com.android.internal.R.bool.config_intrusiveNotificationLed)).thenReturn(true); when(getContext().getResources()).thenReturn(resources); initAttentionHelper(mTestFlagResolver); NotificationRecord r = getLightsNotification(); mAttentionHelper.buzzBeepBlinkLocked(r, DEFAULT_SIGNALS); verifyNeverAttentionLights(); assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test public void testLightsDndIntercepted() { NotificationRecord r = getLightsNotification(); Loading