From 4767922d0a677477cd618fb7a0cbcca14e5b34e0 Mon Sep 17 00:00:00 2001 From: Beverly Date: Thu, 16 May 2019 15:46:11 -0400 Subject: [PATCH] Allow updates to importance of default apps As long as it's not IMPORTANCE_NONE Test: manual 1. Messages app > Settings > Notifications 2. Change behavior from Prioritized to Gentle 3. Back 4. Click on Notifications again 5. Observe: setting was changed to Gentle Test: atest PreferencesHelperTest Fixes: 131893709 Change-Id: I1710435e9dfa741b14a8de3da07bff1d17e884b8 --- .../server/notification/PreferencesHelper.java | 3 ++- .../notification/PreferencesHelperTest.java | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/notification/PreferencesHelper.java b/services/core/java/com/android/server/notification/PreferencesHelper.java index 3f1a2487fe2f3..0804a738424a6 100644 --- a/services/core/java/com/android/server/notification/PreferencesHelper.java +++ b/services/core/java/com/android/server/notification/PreferencesHelper.java @@ -736,7 +736,8 @@ public class PreferencesHelper implements RankingConfig { } updatedChannel.setImportanceLockedByCriticalDeviceFunction( r.defaultAppLockedImportance); - if (updatedChannel.isImportanceLockedByCriticalDeviceFunction()) { + if (updatedChannel.isImportanceLockedByCriticalDeviceFunction() + && updatedChannel.getImportance() == IMPORTANCE_NONE) { updatedChannel.setImportance(channel.getImportance()); } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java index d1a3550ce2f2d..e22f8271cae74 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java @@ -66,6 +66,9 @@ import android.util.ArraySet; import android.util.Pair; import android.util.Xml; +import androidx.test.InstrumentationRegistry; +import androidx.test.runner.AndroidJUnit4; + import com.android.internal.util.FastXmlSerializer; import com.android.server.UiServiceTestCase; @@ -90,9 +93,6 @@ import java.util.Map; import java.util.Objects; import java.util.concurrent.ThreadLocalRandom; -import androidx.test.InstrumentationRegistry; -import androidx.test.runner.AndroidJUnit4; - @SmallTest @RunWith(AndroidJUnit4.class) public class PreferencesHelperTest extends UiServiceTestCase { @@ -2520,7 +2520,6 @@ public class PreferencesHelperTest extends UiServiceTestCase { toAdd.add(new Pair(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); - assertTrue(mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false) .isImportanceLockedByCriticalDeviceFunction()); assertFalse(mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, b.getId(), false) @@ -2623,16 +2622,20 @@ public class PreferencesHelperTest extends UiServiceTestCase { update.setAllowBubbles(false); mHelper.updateNotificationChannel(PKG_O, UID_O, update, true); - assertEquals(IMPORTANCE_HIGH, mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false).getImportance()); assertEquals(false, mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false).canBubble()); mHelper.updateNotificationChannel(PKG_O, UID_O, update, false); - assertEquals(IMPORTANCE_HIGH, mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false).getImportance()); + + NotificationChannel updateImportanceLow = new NotificationChannel("a", "a", + IMPORTANCE_LOW); + mHelper.updateNotificationChannel(PKG_O, UID_O, updateImportanceLow, true); + assertEquals(IMPORTANCE_LOW, + mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false).getImportance()); } @Test