Ensure that loading packages can be extended
Collections.emptySet() creates an immutable collection which will prevent us to add more packages to the loading packages set. Instead of using the emptySet, create a new set everytime, even if it's empty. Test: PackageDexUseTest Bug: 148774920 Change-Id: If274d0380d494d31768da24c10153810ef8bf513
This commit is contained in:
@@ -446,15 +446,12 @@ public class PackageDexUsage extends AbstractStatsBase<Void> {
|
||||
if (line == null) {
|
||||
throw new IllegalStateException("Could not find the loadingPackages line.");
|
||||
}
|
||||
// We expect that most of the times the list of loading packages will be empty.
|
||||
if (line.length() == LOADING_PACKAGE_CHAR.length()) {
|
||||
return Collections.emptySet();
|
||||
} else {
|
||||
Set<String> result = new HashSet<>();
|
||||
Set<String> result = new HashSet<>();
|
||||
if (line.length() != LOADING_PACKAGE_CHAR.length()) {
|
||||
Collections.addAll(result,
|
||||
line.substring(LOADING_PACKAGE_CHAR.length()).split(SPLIT_CHAR));
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -575,6 +575,22 @@ public class PackageDexUsageTests {
|
||||
assertPackageDexUsage(mBarBaseUser0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnsureLoadingPackagesCanBeExtended() {
|
||||
String isa = VMRuntime.getInstructionSet(Build.SUPPORTED_ABIS[0]);
|
||||
String content = "PACKAGE_MANAGER__PACKAGE_DEX_USAGE__2\n"
|
||||
+ "com.google.foo\n"
|
||||
+ "+/data/app/com.google.foo/split-2.apk\n"
|
||||
+ "@\n";
|
||||
PackageDexUsage packageDexUsage = new PackageDexUsage();
|
||||
try {
|
||||
packageDexUsage.read(new StringReader(content));
|
||||
} catch (IOException e) {
|
||||
fail();
|
||||
}
|
||||
record(packageDexUsage, mFooSplit2UsedByOtherApps0, mFooSplit2UsedByOtherApps0.getUsedBy());
|
||||
}
|
||||
|
||||
private void assertPackageDexUsage(TestData primary, TestData... secondaries) {
|
||||
assertPackageDexUsage(mPackageDexUsage, null, primary, secondaries);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user