OSDN Git Service

DO NOT MERGE Add list of approved services in addApprovedList
authorArtem Iglikov <artikz@google.com>
Mon, 23 Apr 2018 14:55:04 +0000 (15:55 +0100)
committerArtem Iglikov <artikz@google.com>
Mon, 23 Apr 2018 17:12:00 +0000 (17:12 +0000)
... 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

services/core/java/com/android/server/notification/ManagedServices.java
services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java

index 477b062..269a0da 100644 (file)
@@ -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<String> approvedList = approvedByType.get(isPrimary);
+        if (approvedList == null) {
+            approvedList = new ArraySet<>();
+            approvedByType.put(isPrimary, approvedList);
+        }
+
         String[] approvedArray = approved.split(ENABLED_SERVICES_SEPARATOR);
-        final ArraySet<String> 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) {
index 9ef0ec7..4668ed4 100644 (file)
@@ -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<String> 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,