From 47b553c59b1da664378f7753e806506b6a811780 Mon Sep 17 00:00:00 2001 From: "Qiao (Adora) Zhang" Date: Mon, 15 Apr 2019 20:42:57 +0000 Subject: [PATCH] Roll forward "Make notification effects for automotive configurable." This reverts commit a9d0bffa06bb094301dc8a1abfb20f2e58991fde. Reason for revert: Rolling forward after fixing test. The test was failing because NotificationManagerService.init() was not called in the test. Added another setter for testing purpose. Bug: 129677989 Test: runtest -x frameworks/base/services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java Change-Id: I2307052aeedb5a72d04930c7a5233c74390c1085 --- core/res/res/values/config.xml | 4 ++++ core/res/res/values/symbols.xml | 1 + .../NotificationManagerService.java | 11 ++++++++++ .../notification/BuzzBeepBlinkTest.java | 21 +++++++++++++++++-- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 526818949b3d5..edcc0572cb2e0 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -745,6 +745,10 @@ + + false + false diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 94b5da6baa071..da2f89083fefd 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -1910,6 +1910,7 @@ + diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 7f1b25ca3ca33..b6e09632717d3 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -455,6 +455,7 @@ public class NotificationManagerService extends SystemService { private int mAutoGroupAtCount; private boolean mIsTelevision; private boolean mIsAutomotive; + private boolean mNotificationEffectsEnabledForAutomotive; private MetricsLogger mMetricsLogger; private TriPredicate mAllowedManagedServicePackages; @@ -1525,6 +1526,11 @@ public class NotificationManagerService extends SystemService { mIsAutomotive = isAutomotive; } + @VisibleForTesting + void setNotificationEffectsEnabledForAutomotive(boolean isEnabled) { + mNotificationEffectsEnabledForAutomotive = isEnabled; + } + @VisibleForTesting void setIsTelevision(boolean isTelevision) { mIsTelevision = isTelevision; @@ -1686,6 +1692,8 @@ public class NotificationManagerService extends SystemService { mIsAutomotive = mPackageManagerClient.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE, 0); + mNotificationEffectsEnabledForAutomotive = + resources.getBoolean(R.bool.config_enableServerNotificationEffectsForAutomotive); mPreferencesHelper.lockChannelsForOEM(getContext().getResources().getStringArray( com.android.internal.R.array.config_nonBlockableNotificationPackages)); @@ -5560,6 +5568,9 @@ public class NotificationManagerService extends SystemService { @VisibleForTesting @GuardedBy("mNotificationLock") void buzzBeepBlinkLocked(NotificationRecord record) { + if (mIsAutomotive && !mNotificationEffectsEnabledForAutomotive) { + return; + } boolean buzz = false; boolean beep = false; boolean blink = false; diff --git a/services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java b/services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java index 6be2c2e8c59ef..6061d51f3d792 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java @@ -455,8 +455,23 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { } @Test - public void testNoBeepForImportanceDefaultInAutomotive() throws Exception { + public void testNoBeepForAutomotiveIfEffectsDisabled() throws Exception { mService.setIsAutomotive(true); + mService.setNotificationEffectsEnabledForAutomotive(false); + + NotificationRecord r = getBeepyNotification(); + r.setSystemImportance(NotificationManager.IMPORTANCE_HIGH); + + mService.buzzBeepBlinkLocked(r); + + verifyNeverBeep(); + assertFalse(r.isInterruptive()); + } + + @Test + public void testNoBeepForImportanceDefaultInAutomotiveIfEffectsEnabled() throws Exception { + mService.setIsAutomotive(true); + mService.setNotificationEffectsEnabledForAutomotive(true); NotificationRecord r = getBeepyNotification(); r.setSystemImportance(NotificationManager.IMPORTANCE_DEFAULT); @@ -468,10 +483,12 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { } @Test - public void testBeepForImportanceHighInAutomotive() throws Exception { + public void testBeepForImportanceHighInAutomotiveIfEffectsEnabled() throws Exception { mService.setIsAutomotive(true); + mService.setNotificationEffectsEnabledForAutomotive(true); NotificationRecord r = getBeepyNotification(); + r.setSystemImportance(NotificationManager.IMPORTANCE_HIGH); mService.buzzBeepBlinkLocked(r);