OSDN Git Service

Add list of approved services in addApprovedList
authorArtem Iglikov <artikz@google.com>
Tue, 24 Apr 2018 11:46:44 +0000 (12:46 +0100)
committerArtem Iglikov <artikz@google.com>
Tue, 24 Apr 2018 11:46:44 +0000 (12:46 +0100)
... 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.

This is ag/3939056 in master.

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: Ie0eb6ef6629fb4c6d97f06b891282aa3e5563456

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

index b0ed85d..5eb7397 100644 (file)
@@ -71,10 +71,8 @@ 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.function.Predicate;
-import java.util.stream.Collectors;
 
 /**
  * Manages the lifecycle of application-provided services bound by system server.
@@ -406,15 +404,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 895bbb1..d0a656c 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,