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

Commit 42afd3c1 authored by Matías Hernández's avatar Matías Hernández Committed by Automerger Merge Worker
Browse files

Settings: don't try to allow NLSes with too-long component names am: b88fbf93

parents 364eb998 b88fbf93
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -81,6 +81,8 @@ public class ApprovalPreferenceController extends BasePreferenceController {
        final RestrictedSwitchPreference preference =
        final RestrictedSwitchPreference preference =
                (RestrictedSwitchPreference) pref;
                (RestrictedSwitchPreference) pref;
        final CharSequence label = mPkgInfo.applicationInfo.loadLabel(mPm);
        final CharSequence label = mPkgInfo.applicationInfo.loadLabel(mPm);
        final boolean isAllowedCn = mCn.flattenToShortString().length()
                <= NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH;
        final boolean isEnabled = isServiceEnabled(mCn);
        final boolean isEnabled = isServiceEnabled(mCn);
        preference.setChecked(isEnabled);
        preference.setChecked(isEnabled);
        preference.setOnPreferenceChangeListener((p, newValue) -> {
        preference.setOnPreferenceChangeListener((p, newValue) -> {
@@ -105,7 +107,8 @@ public class ApprovalPreferenceController extends BasePreferenceController {
                return false;
                return false;
            }
            }
        });
        });
        preference.updateState(mCn.getPackageName(), mPkgInfo.applicationInfo.uid, isEnabled);
        preference.updateState(
                mCn.getPackageName(), mPkgInfo.applicationInfo.uid, isAllowedCn, isEnabled);
    }
    }


    public void disable(final ComponentName cn) {
    public void disable(final ComponentName cn) {
+3 −1
Original line number Original line Diff line number Diff line
@@ -67,7 +67,9 @@ public class NotificationAccessConfirmationActivity extends Activity
        mUserId = getIntent().getIntExtra(EXTRA_USER_ID, UserHandle.USER_NULL);
        mUserId = getIntent().getIntExtra(EXTRA_USER_ID, UserHandle.USER_NULL);
        CharSequence mAppLabel;
        CharSequence mAppLabel;


        if (mComponentName == null || mComponentName.getPackageName() == null) {
        if (mComponentName == null || mComponentName.getPackageName() == null
                || mComponentName.flattenToString().length()
                > NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) {
            finish();
            finish();
            return;
            return;
        }
        }
+2 −2
Original line number Original line Diff line number Diff line
@@ -66,7 +66,6 @@ public class NotificationAccessSettings extends EmptyTextSettings {
    private static final String TAG = "NotifAccessSettings";
    private static final String TAG = "NotifAccessSettings";
    static final String ALLOWED_KEY = "allowed";
    static final String ALLOWED_KEY = "allowed";
    static final String NOT_ALLOWED_KEY = "not_allowed";
    static final String NOT_ALLOWED_KEY = "not_allowed";
    private static final int MAX_CN_LENGTH = 500;


    private static final ManagedServiceSettings.Config CONFIG =
    private static final ManagedServiceSettings.Config CONFIG =
            new ManagedServiceSettings.Config.Builder()
            new ManagedServiceSettings.Config.Builder()
@@ -150,7 +149,8 @@ public class NotificationAccessSettings extends EmptyTextSettings {
        for (ServiceInfo service : services) {
        for (ServiceInfo service : services) {
            final ComponentName cn = new ComponentName(service.packageName, service.name);
            final ComponentName cn = new ComponentName(service.packageName, service.name);
            boolean isAllowed = mNm.isNotificationListenerAccessGranted(cn);
            boolean isAllowed = mNm.isNotificationListenerAccessGranted(cn);
            if (!isAllowed && cn.flattenToString().length() > MAX_CN_LENGTH) {
            if (!isAllowed && cn.flattenToString().length()
                    > NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) {
                continue;
                continue;
            }
            }


+30 −0
Original line number Original line Diff line number Diff line
@@ -83,6 +83,36 @@ public class ApprovalPreferenceControllerTest {


    }
    }


    @Test
    public void updateState_enabled() {
        when(mAppOpsManager.noteOpNoThrow(anyInt(), anyInt(), anyString())).thenReturn(
                AppOpsManager.MODE_ALLOWED);
        when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true);
        RestrictedSwitchPreference pref = new RestrictedSwitchPreference(
                mContext);
        pref.setAppOps(mAppOpsManager);

        mController.updateState(pref);

        assertThat(pref.isEnabled()).isTrue();
    }

    @Test
    public void updateState_invalidCn_disabled() {
        ComponentName longCn = new ComponentName("com.example.package",
                com.google.common.base.Strings.repeat("Blah", 150));
        mController.setCn(longCn);
        when(mAppOpsManager.noteOpNoThrow(anyInt(), anyInt(), anyString())).thenReturn(
                AppOpsManager.MODE_ALLOWED);
        RestrictedSwitchPreference pref = new RestrictedSwitchPreference(
                mContext);
        pref.setAppOps(mAppOpsManager);

        mController.updateState(pref);

        assertThat(pref.isEnabled()).isFalse();
    }

    @Test
    @Test
    public void updateState_checked() {
    public void updateState_checked() {
        when(mAppOpsManager.noteOpNoThrow(anyInt(), anyInt(), anyString())).thenReturn(
        when(mAppOpsManager.noteOpNoThrow(anyInt(), anyInt(), anyString())).thenReturn(