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

Commit 963328f5 authored by Adora Zhang's avatar Adora Zhang
Browse files

Do not make sound for notifications <= IMPORTANCE_DEFAULT in Android Auto.

To reduce distraction, if there is no heads-up notification, there should be no sound.

Fix: 119640453
Test: runtest -x frameworks/base/services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java

Change-Id: Ie3280fb8239dd0779a3597aa75518f2ce9bdda58
parent 2c87f2ea
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -418,6 +418,7 @@ public class NotificationManagerService extends SystemService {
    private GroupHelper mGroupHelper;
    private int mAutoGroupAtCount;
    private boolean mIsTelevision;
    private boolean mIsAutomotive;

    private MetricsLogger mMetricsLogger;
    private Predicate<String> mAllowedManagedServicePackages;
@@ -1365,6 +1366,11 @@ public class NotificationManagerService extends SystemService {
        mRankingHandler = rankingHandler;
    }

    @VisibleForTesting
    void setIsAutomotive(boolean isAutomotive) {
        mIsAutomotive = isAutomotive;
    }

    @VisibleForTesting
    void setIsTelevision(boolean isTelevision) {
        mIsTelevision = isTelevision;
@@ -1521,6 +1527,9 @@ public class NotificationManagerService extends SystemService {

        mIsTelevision = mPackageManagerClient.hasSystemFeature(FEATURE_LEANBACK)
                || mPackageManagerClient.hasSystemFeature(FEATURE_TELEVISION);

        mIsAutomotive =
                mPackageManagerClient.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE, 0);
    }

    @Override
@@ -5044,7 +5053,9 @@ public class NotificationManagerService extends SystemService {

        // Should this notification make noise, vibe, or use the LED?
        final boolean aboveThreshold =
                record.getImportance() >= NotificationManager.IMPORTANCE_DEFAULT;
                mIsAutomotive
                        ? record.getImportance() > NotificationManager.IMPORTANCE_DEFAULT
                        : record.getImportance() >= NotificationManager.IMPORTANCE_DEFAULT;

        // Remember if this notification already owns the notification channels.
        boolean wasBeep = key != null && key.equals(mSoundNotificationKey);
+25 −0
Original line number Diff line number Diff line
@@ -451,6 +451,31 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase {
        assertFalse(r.isInterruptive());
    }

    @Test
    public void testNoBeepForImportanceDefaultInAutomotive() throws Exception {
        mService.setIsAutomotive(true);

        NotificationRecord r = getBeepyNotification();
        r.setSystemImportance(NotificationManager.IMPORTANCE_DEFAULT);

        mService.buzzBeepBlinkLocked(r);

        verifyNeverBeep();
        assertFalse(r.isInterruptive());
    }

    @Test
    public void testBeepForImportanceHighInAutomotive() throws Exception {
        mService.setIsAutomotive(true);

        NotificationRecord r = getBeepyNotification();

        mService.buzzBeepBlinkLocked(r);

        verifyBeepLooped();
        assertTrue(r.isInterruptive());
    }

    @Test
    public void testNoInterruptionForMin() throws Exception {
        NotificationRecord r = getBeepyNotification();