Merge "NAS Allowed Adjustments Migration" into sc-dev am: 3c54db7b83

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13483558

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Iea484fc18f3a0d382045d5d125416cbef709b7d1
This commit is contained in:
Chloris Kuo
2021-02-09 17:17:40 +00:00
committed by Automerger Merge Worker
2 changed files with 39 additions and 3 deletions

View File

@@ -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,
@@ -9074,7 +9076,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();
@@ -9176,13 +9179,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));
}
}
}
}

View File

@@ -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 = "<q_allowed_adjustments types=\"adj_1\"/>";
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 = "<s_allowed_adjustments types=\"adj_2\"/>";
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");