Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2fe3273f authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Handle NLS metadata when provided as strings

Test: atest
Bug: 181175697
Change-Id: I40d935ffb7c1fb9f978160d28297da84412501fb
parent bf5dd80d
Loading
Loading
Loading
Loading
+21 −5
Original line number Diff line number Diff line
@@ -16,6 +16,11 @@

package com.android.settings.applications.specialaccess.notificationaccess;

import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_ALERTING;
import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_CONVERSATIONS;
import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_ONGOING;
import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_SILENT;

import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ServiceInfo;
@@ -129,15 +134,26 @@ public abstract class TypeFilterPreferenceController extends BasePreferenceContr
                    int types = 0;
                    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;
                        }
                        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(typeStrings[i]);
                                types |= Integer.parseInt(typeString);
                            } catch (NumberFormatException e) {
                                // skip
                            }
                        }
                    }
                    if (hasFlag(types, getType())) {
                        disableRequestedByApp = true;
                    }
+2 −2
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ public class TypeFilterPreferenceControllerTest {
    public void updateState_enabled_metaData_disableFilter_notThisField() {
        mSi.metaData = new Bundle();
        mSi.metaData.putCharSequence(NotificationListenerService.META_DATA_DISABLED_FILTER_TYPES, 
                "1,2");
                "1,alerting");
        when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true);
        when(mNm.getListenerFilter(mCn, 0)).thenReturn(new NotificationListenerFilter());
        CheckBoxPreference pref = new CheckBoxPreference(mContext);
@@ -165,7 +165,7 @@ public class TypeFilterPreferenceControllerTest {
    public void updateState_enabled_metaData_disableFilter_thisField_stateIsChecked() {
        mSi.metaData = new Bundle();
        mSi.metaData.putCharSequence(NotificationListenerService.META_DATA_DISABLED_FILTER_TYPES,
                "1,2,32");
                "conversations,2,32");
        when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true);
        when(mNm.getListenerFilter(mCn, 0)).thenReturn(
                new NotificationListenerFilter(32, new ArraySet<>()));