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.
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) {
}
@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,