diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 6843733eea9fe..c7f59e665ce49 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -378,7 +378,9 @@ public class NotificationManagerService extends SystemService { static final String[] DEFAULT_ALLOWED_ADJUSTMENTS = new String[] { Adjustment.KEY_CONTEXTUAL_ACTIONS, Adjustment.KEY_TEXT_REPLIES, - Adjustment.KEY_NOT_CONVERSATION}; + Adjustment.KEY_NOT_CONVERSATION, + Adjustment.KEY_IMPORTANCE, + Adjustment.KEY_RANKING_SCORE}; static final String[] NON_BLOCKABLE_DEFAULT_ROLES = new String[] { RoleManager.ROLE_DIALER, @@ -9047,7 +9049,8 @@ public class NotificationManagerService extends SystemService { public class NotificationAssistants extends ManagedServices { static final String TAG_ENABLED_NOTIFICATION_ASSISTANTS = "enabled_assistants"; - private static final String TAG_ALLOWED_ADJUSTMENT_TYPES = "q_allowed_adjustments"; + private static final String TAG_ALLOWED_ADJUSTMENT_TYPES_OLD = "q_allowed_adjustments"; + private static final String TAG_ALLOWED_ADJUSTMENT_TYPES = "s_allowed_adjustments"; private static final String ATT_TYPES = "types"; private final Object mLock = new Object(); @@ -9149,13 +9152,19 @@ public class NotificationManagerService extends SystemService { @Override protected void readExtraTag(String tag, TypedXmlPullParser parser) throws IOException { - if (TAG_ALLOWED_ADJUSTMENT_TYPES.equals(tag)) { + if (TAG_ALLOWED_ADJUSTMENT_TYPES_OLD.equals(tag) + || TAG_ALLOWED_ADJUSTMENT_TYPES.equals(tag)) { final String types = XmlUtils.readStringAttribute(parser, ATT_TYPES); synchronized (mLock) { mAllowedAdjustments.clear(); if (!TextUtils.isEmpty(types)) { mAllowedAdjustments.addAll(Arrays.asList(types.split(","))); } + if (TAG_ALLOWED_ADJUSTMENT_TYPES_OLD.equals(tag)) { + if (DEBUG) Slog.d(TAG, "Migrate allowed adjustments."); + mAllowedAdjustments.addAll( + Arrays.asList(DEFAULT_ALLOWED_ADJUSTMENTS)); + } } } } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java index b3116d9707252..17c9411798531 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java @@ -15,6 +15,9 @@ */ package com.android.server.notification; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; + import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Matchers.any; @@ -137,6 +140,30 @@ public class NotificationAssistantsTest extends UiServiceTestCase { new ComponentName("b", "b").flattenToString(), 10, true, null); } + @Test + public void testXmlMigratingAllowedAdjustments() throws Exception { + // Old tag, need migration + String xml = ""; + + TypedXmlPullParser parser = Xml.newFastPullParser(); + parser.setInput(new BufferedInputStream( + new ByteArrayInputStream(xml.toString().getBytes())), null); + parser.nextTag(); + mAssistants.readExtraTag("q_allowed_adjustments", parser); + assertTrue(mAssistants.isAdjustmentAllowed("adj_1")); + assertEquals(mNm.DEFAULT_ALLOWED_ADJUSTMENTS.length + 1, + mAssistants.getAllowedAssistantAdjustments().size()); + + // New TAG + xml = ""; + parser.setInput(new BufferedInputStream( + new ByteArrayInputStream(xml.toString().getBytes())), null); + parser.nextTag(); + mAssistants.readExtraTag("s_allowed_adjustments", parser); + assertTrue(mAssistants.isAdjustmentAllowed("adj_2")); + assertEquals(1, mAssistants.getAllowedAssistantAdjustments().size()); + } + @Test public void testSetPackageOrComponentEnabled_onlyOnePackage() throws Exception { ComponentName component1 = ComponentName.unflattenFromString("package/Component1");