From 60efeb64cd713ae3b7b689084d4a7c6c0e3bff1e Mon Sep 17 00:00:00 2001 From: Artem Iglikov Date: Mon, 23 Apr 2018 15:55:04 +0100 Subject: [PATCH] DO NOT MERGE Add list of approved services in addApprovedList ... instead of replacing it. I.e., do what the method name claims to do in order to fix restoring. Otherwise during restore the list of components is getting set to the list of the components from backup set, i.e., list of pre-approved components is lost. Bug: 77630371 Test: with a backup set for package "android" created with LocalTransport run (also see the bug) adb root && adb shell bmgr enable true && adb shell bmgr transport android/com.android.internal.backup.LocalTransport && adb shell bmgr backupnow android && adb shell rm -rf /cache/backup/1/_delta/android/ && adb push android /cache/backup/1/_delta/ && adb shell cat /data/system/notification_policy.xml | grep enabled_listeners -C 5 && adb shell bmgr restore 1 android && adb shell cat /data/system/notification_policy.xml | grep enabled_listeners -C 5 Test: atest FrameworksUiServicesTests Change-Id: Ic201d868bdb003fcac12876ab55f4992edb866e3 --- .../server/notification/ManagedServices.java | 11 +++++---- .../server/notification/ManagedServicesTest.java | 26 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/notification/ManagedServices.java b/services/core/java/com/android/server/notification/ManagedServices.java index 477b062ac90f..269a0dac41ab 100644 --- a/services/core/java/com/android/server/notification/ManagedServices.java +++ b/services/core/java/com/android/server/notification/ManagedServices.java @@ -71,9 +71,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; -import java.util.Objects; import java.util.Set; -import java.util.stream.Collectors; /** * Manages the lifecycle of application-provided services bound by system server. @@ -401,15 +399,20 @@ abstract public class ManagedServices { approvedByType = new ArrayMap<>(); mApproved.put(userId, approvedByType); } + + ArraySet approvedList = approvedByType.get(isPrimary); + if (approvedList == null) { + approvedList = new ArraySet<>(); + approvedByType.put(isPrimary, approvedList); + } + String[] approvedArray = approved.split(ENABLED_SERVICES_SEPARATOR); - final ArraySet approvedList = new ArraySet<>(); for (String pkgOrComponent : approvedArray) { String approvedItem = getApprovedValue(pkgOrComponent); if (approvedItem != null) { approvedList.add(approvedItem); } } - approvedByType.put(isPrimary, approvedList); } protected boolean isComponentEnabledForPackage(String pkg) { diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java index 9ef0ec7ac99b..4668ed42b11e 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java @@ -267,6 +267,32 @@ public class ManagedServicesTest extends UiServiceTestCase { } @Test + public void testReadXml_appendsListOfApprovedComponents() throws Exception { + for (int approvalLevel : new int[] {APPROVAL_BY_COMPONENT, APPROVAL_BY_PACKAGE}) { + ManagedServices service = new TestManagedServices(getContext(), mLock, mUserProfiles, + mIpm, approvalLevel); + + String preApprovedPackage = "some.random.package"; + String preApprovedComponent = "some.random.package/C1"; + + List packages = new ArrayList<>(); + packages.add(preApprovedPackage); + addExpectedServices(service, packages, 0); + + service.setPackageOrComponentEnabled(preApprovedComponent, 0, true, true); + + loadXml(service); + + verifyExpectedApprovedEntries(service); + + String verifyValue = (approvalLevel == APPROVAL_BY_COMPONENT) + ? preApprovedComponent + : preApprovedPackage; + assertTrue(service.isPackageOrComponentAllowed(verifyValue, 0)); + } + } + + @Test public void testWriteXml_trimsMissingServices() throws Exception { for (int approvalLevel : new int[] {APPROVAL_BY_COMPONENT, APPROVAL_BY_PACKAGE}) { ManagedServices service = new TestManagedServices(getContext(), mLock, mUserProfiles, -- 2.11.0