Loading services/core/java/com/android/server/notification/ManagedServices.java +25 −6 Original line number Diff line number Diff line Loading @@ -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); } Loading Loading @@ -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); Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java +33 −2 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -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)); Loading @@ -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\">" Loading Loading
services/core/java/com/android/server/notification/ManagedServices.java +25 −6 Original line number Diff line number Diff line Loading @@ -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); } Loading Loading @@ -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); Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java +33 −2 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -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)); Loading @@ -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\">" Loading