Merge "NAS Allowed Adjustments Migration" into sc-dev
This commit is contained in:
@@ -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,
|
||||
@@ -9048,7 +9050,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();
|
||||
@@ -9150,13 +9153,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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user