Allow NLS metadata fields to use name strings
Instead of just numbers Test: atest, CTS Verifier Fixes: 181175697 Change-Id: I677d1cfa47bb55a94b3c153453447477c66f99bd
This commit is contained in:
@@ -83,11 +83,11 @@ import java.util.Objects;
|
||||
* </intent-filter>
|
||||
* <meta-data
|
||||
* android:name="android.service.notification.default_filter_types"
|
||||
* android:value="1,2">
|
||||
* android:value="conversations,alerting">
|
||||
* </meta-data>
|
||||
* <meta-data
|
||||
* android:name="android.service.notification.disabled_filter_types"
|
||||
* android:value="2">
|
||||
* android:value="ongoing,silent">
|
||||
* </meta-data>
|
||||
* </service></pre>
|
||||
*
|
||||
|
||||
@@ -10259,13 +10259,24 @@ public class NotificationManagerService extends SystemService {
|
||||
if (typeList != null) {
|
||||
String[] typeStrings = typeList.split(XML_SEPARATOR);
|
||||
for (int i = 0; i < typeStrings.length; i++) {
|
||||
if (TextUtils.isEmpty(typeStrings[i])) {
|
||||
final String typeString = typeStrings[i];
|
||||
if (TextUtils.isEmpty(typeString)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
types |= Integer.parseInt(typeStrings[i]);
|
||||
} catch (NumberFormatException e) {
|
||||
// skip
|
||||
if (typeString.equalsIgnoreCase("ONGOING")) {
|
||||
types |= FLAG_FILTER_TYPE_ONGOING;
|
||||
} else if (typeString.equalsIgnoreCase("CONVERSATIONS")) {
|
||||
types |= FLAG_FILTER_TYPE_CONVERSATIONS;
|
||||
} else if (typeString.equalsIgnoreCase("SILENT")) {
|
||||
types |= FLAG_FILTER_TYPE_SILENT;
|
||||
} else if (typeString.equalsIgnoreCase("ALERTING")) {
|
||||
types |= FLAG_FILTER_TYPE_ALERTING;
|
||||
} else {
|
||||
try {
|
||||
types |= Integer.parseInt(typeString);
|
||||
} catch (NumberFormatException e) {
|
||||
// skip
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,6 +206,22 @@ public class NotificationListenersTest extends UiServiceTestCase {
|
||||
.isEqualTo(FLAG_FILTER_TYPE_CONVERSATIONS | FLAG_FILTER_TYPE_ALERTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnsureFilters_newServiceWithMetadata_namesNotNumbers() {
|
||||
ServiceInfo si = new ServiceInfo();
|
||||
si.packageName = "new";
|
||||
si.name = "comp";
|
||||
si.metaData = new Bundle();
|
||||
si.metaData.putString(NotificationListenerService.META_DATA_DEFAULT_FILTER_TYPES,
|
||||
"conversations,ALERTING");
|
||||
|
||||
mListeners.ensureFilters(si, 0);
|
||||
|
||||
assertThat(mListeners.getNotificationListenerFilter(
|
||||
Pair.create(si.getComponentName(), 0)).getTypes())
|
||||
.isEqualTo(FLAG_FILTER_TYPE_CONVERSATIONS | FLAG_FILTER_TYPE_ALERTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnsureFilters_newServiceWithMetadata_onlyOneListed() {
|
||||
ServiceInfo si = new ServiceInfo();
|
||||
@@ -236,6 +252,22 @@ public class NotificationListenersTest extends UiServiceTestCase {
|
||||
.isEqualTo(FLAG_FILTER_TYPE_SILENT | FLAG_FILTER_TYPE_ONGOING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnsureFilters_newServiceWithMetadata_disabledTypes_mixedText() {
|
||||
ServiceInfo si = new ServiceInfo();
|
||||
si.packageName = "new";
|
||||
si.name = "comp";
|
||||
si.metaData = new Bundle();
|
||||
si.metaData.putString(NotificationListenerService.META_DATA_DISABLED_FILTER_TYPES,
|
||||
"1,alerting");
|
||||
|
||||
mListeners.ensureFilters(si, 0);
|
||||
|
||||
assertThat(mListeners.getNotificationListenerFilter(
|
||||
Pair.create(si.getComponentName(), 0)).getTypes())
|
||||
.isEqualTo(FLAG_FILTER_TYPE_SILENT | FLAG_FILTER_TYPE_ONGOING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnsureFilters_newServiceWithMetadata_metaDataDisagrees() {
|
||||
ServiceInfo si = new ServiceInfo();
|
||||
|
||||
Reference in New Issue
Block a user