Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c2deeefe authored by Calin Juravle's avatar Calin Juravle
Browse files

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
parent 7c8fd297
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -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<>();
        if (line.length() != LOADING_PACKAGE_CHAR.length()) {
            Collections.addAll(result,
                    line.substring(LOADING_PACKAGE_CHAR.length()).split(SPLIT_CHAR));
            return result;
        }
        return result;
    }

    /**
+16 −0
Original line number Diff line number Diff line
@@ -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);
    }