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

Commit 855c397f authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Backup and restore user disabling the NAS

Test: reboot with NAS off - NAS is off
Test: reboot with NAS on - NAS is on
Test: restore with NAS off - NAS is off
Test: restort with NAS on - NAS is on
Test: NotificationAssistantsTest
Fixes: 323717740
Flag: EXEMPT bug fix
Change-Id: Ib73b7f1ca835beebafbb8d7d9680deed986510c0
parent f613f7fe
Loading
Loading
Loading
Loading
+25 −6
Original line number Diff line number Diff line
@@ -712,14 +712,22 @@ abstract public class ManagedServices {
                        }
                    }
                    readExtraAttributes(tag, parser, resolvedUserId);
                    if (allowedManagedServicePackages == null || allowedManagedServicePackages.test(
                    if (isUserChanged != null && approved.isEmpty()) {
                        // NAS
                        denyPregrantedAppUserSet(resolvedUserId, isPrimary);
                        mUseXml = true;
                    } else {
                        if (allowedManagedServicePackages == null
                                || allowedManagedServicePackages.test(
                                getPackageName(approved), resolvedUserId, getRequiredPermission())
                                || approved.isEmpty()) {
                            if (mUm.getUserInfo(resolvedUserId) != null) {
                            addApprovedList(approved, resolvedUserId, isPrimary, userSetComponent);
                                addApprovedList(approved, resolvedUserId, isPrimary,
                                        userSetComponent);
                            }
                            mUseXml = true;
                        }
                    }
                } else {
                    readExtraTag(tag, parser);
                }
@@ -826,6 +834,17 @@ abstract public class ManagedServices {
        }
    }

    protected void denyPregrantedAppUserSet(int userId, boolean isPrimary) {
        synchronized (mApproved) {
            ArrayMap<Boolean, ArraySet<String>> approvedByType = mApproved.get(userId);
            if (approvedByType == null) {
                approvedByType = new ArrayMap<>();
                mApproved.put(userId, approvedByType);
            }
            approvedByType.put(isPrimary, new ArraySet<>());
        }
    }

    protected boolean isComponentEnabledForPackage(String pkg) {
        synchronized (mMutex) {
            return mEnabledServicesPackageNames.contains(pkg);
+33 −2
Original line number Diff line number Diff line
@@ -145,7 +145,8 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
        mContext.setMockPackageManager(mPm);
        mContext.addMockSystemService(Context.USER_SERVICE, mUm);
        mContext.getOrCreateTestableResources().addOverride(
                com.android.internal.R.string.config_defaultAssistantAccessComponent, "a/a");
                com.android.internal.R.string.config_defaultAssistantAccessComponent,
                mCn.flattenToString());
        mAssistants = spy(mNm.new NotificationAssistants(mContext, mLock, mUserProfiles, miPm));
        when(mNm.getBinderService()).thenReturn(mINm);
        mContext.ensureTestableResources();
@@ -207,7 +208,8 @@ public class NotificationAssistantsTest extends UiServiceTestCase {

        writeXmlAndReload(USER_ALL);

        ArrayMap<Boolean, ArraySet<String>> approved = mAssistants.mApproved.get(0);
        ArrayMap<Boolean, ArraySet<String>> approved =
                mAssistants.mApproved.get(ActivityManager.getCurrentUser());
        // approved should not be null
        assertNotNull(approved);
        assertEquals(new ArraySet<>(), approved.get(true));
@@ -216,6 +218,35 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
        assertTrue(mAssistants.mIsUserChanged.get(ActivityManager.getCurrentUser()));
    }

    @Test
    public void testWriteXml_userTurnedOffNAS_backup() throws Exception {
        int userId = 10;

        mAssistants.loadDefaultsFromConfig(true);

        mAssistants.setPackageOrComponentEnabled(mCn.flattenToString(), userId, true,
                true, true);

        ComponentName current = CollectionUtils.firstOrNull(
                mAssistants.getAllowedComponents(userId));
        mAssistants.setUserSet(userId, true);
        mAssistants.setPackageOrComponentEnabled(current.flattenToString(), userId, true, false,
                true);
        assertTrue(mAssistants.mIsUserChanged.get(userId));
        assertThat(mAssistants.getApproved(userId, true)).isEmpty();

        writeXmlAndReload(userId);

        ArrayMap<Boolean, ArraySet<String>> approved = mAssistants.mApproved.get(userId);
        // approved should not be null
        assertNotNull(approved);
        assertEquals(new ArraySet<>(), approved.get(true));

        // user set is maintained
        assertTrue(mAssistants.mIsUserChanged.get(userId));
        assertThat(mAssistants.getApproved(userId, true)).isEmpty();
    }

    @Test
    public void testReadXml_userDisabled() throws Exception {
        String xml = "<enabled_assistants version=\"4\" defaults=\"b/b\">"