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

Commit 2410821b authored by Steven Moreland's avatar Steven Moreland
Browse files

pm: AndroidHidlUpdater: system only

Backwards compatibility takes a slight performance hit. Only apply this
rule to outdated system apps as they are the only ones that use these
libraries.

Bug: 86259915
Test: boot Pixel 2
Test: boot Pixel 3 and systrace app startup
Test: atest android.content.pm.AndroidHidlUpdaterTest

Change-Id: I2d2e2ca79266a92ba0e4efcf25e31d15daee87a1
parent b28b7960
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -34,8 +34,14 @@ public class AndroidHidlUpdater extends PackageSharedLibraryUpdater {

    @Override
    public void updatePackage(Package pkg) {
        ApplicationInfo info = pkg.applicationInfo;

        // This was the default <= P and is maintained for backwards compatibility.
        if (pkg.applicationInfo.targetSdkVersion <= Build.VERSION_CODES.P) {
        boolean isLegacy = info.targetSdkVersion <= Build.VERSION_CODES.P;
        // Only system apps use these libraries
        boolean isSystem = info.isSystemApp() || info.isUpdatedSystemApp();

        if (isLegacy && isSystem) {
            prefixRequiredLibrary(pkg, ANDROID_HIDL_BASE);
            prefixRequiredLibrary(pkg, ANDROID_HIDL_MANAGER);
        } else {
+38 −8
Original line number Diff line number Diff line
@@ -40,8 +40,17 @@ public class AndroidHidlUpdaterTest extends PackageSharedLibraryUpdaterTest {
        PackageBuilder before = builder()
                .targetSdkVersion(Build.VERSION_CODES.P);

        // no change, not system
        checkBackwardsCompatibility(before, before);
    }

    @Test
    public void targeted_at_P_system() {
        PackageBuilder before = builder().asSystemApp()
                .targetSdkVersion(Build.VERSION_CODES.P);

        // Should add both HIDL libraries
        PackageBuilder after = builder()
        PackageBuilder after = builder().asSystemApp()
                .targetSdkVersion(Build.VERSION_CODES.P)
                .requiredLibraries(ANDROID_HIDL_MANAGER, ANDROID_HIDL_BASE);

@@ -54,9 +63,19 @@ public class AndroidHidlUpdaterTest extends PackageSharedLibraryUpdaterTest {
                .targetSdkVersion(Build.VERSION_CODES.P)
                .requiredLibraries(OTHER_LIBRARY);

        // no change, not system
        checkBackwardsCompatibility(before, before);
    }

    @Test
    public void targeted_at_P_not_empty_usesLibraries_system() {
        PackageBuilder before = builder().asSystemApp()
                .targetSdkVersion(Build.VERSION_CODES.P)
                .requiredLibraries(OTHER_LIBRARY);

        // The hidl jars should be added at the start of the list because it
        // is not on the bootclasspath and the package targets pre-P.
        PackageBuilder after = builder()
        PackageBuilder after = builder().asSystemApp()
                .targetSdkVersion(Build.VERSION_CODES.P)
                .requiredLibraries(ANDROID_HIDL_MANAGER, ANDROID_HIDL_BASE, OTHER_LIBRARY);

@@ -69,8 +88,21 @@ public class AndroidHidlUpdaterTest extends PackageSharedLibraryUpdaterTest {
                .targetSdkVersion(Build.VERSION_CODES.P)
                .requiredLibraries(ANDROID_HIDL_MANAGER, ANDROID_HIDL_BASE);

        // No change is required because although the HIDL libraries has been removed from
        // the bootclasspath the package explicitly requests it.
        PackageBuilder after = builder()
                .targetSdkVersion(Build.VERSION_CODES.P);

        // Libraries are removed because they are not available for non-system apps
        checkBackwardsCompatibility(before, after);
    }

    @Test
    public void targeted_at_P_in_usesLibraries_system() {
        PackageBuilder before = builder().asSystemApp()
                .targetSdkVersion(Build.VERSION_CODES.P)
                .requiredLibraries(ANDROID_HIDL_MANAGER, ANDROID_HIDL_BASE);

        // No change is required because the package explicitly requests the HIDL libraries
        // and is targeted at the current version so does not need backwards compatibility.
        checkBackwardsCompatibility(before, before);
    }

@@ -81,8 +113,7 @@ public class AndroidHidlUpdaterTest extends PackageSharedLibraryUpdaterTest {
        // Dependency is removed, it is not available.
        PackageBuilder after = builder();

        // No change is required because the package explicitly requests the HIDL libraries
        // and is targeted at the current version so does not need backwards compatibility.
        // Libraries are removed because they are not available for apps targetting Q+
        checkBackwardsCompatibility(before, after);
    }

@@ -93,8 +124,7 @@ public class AndroidHidlUpdaterTest extends PackageSharedLibraryUpdaterTest {
        // Dependency is removed, it is not available.
        PackageBuilder after = builder();

        // No change is required because the package explicitly requests the HIDL libraries
        // and is targeted at the current version so does not need backwards compatibility.
        // Libraries are removed because they are not available for apps targetting Q+
        checkBackwardsCompatibility(before, after);
    }

+8 −0
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ class PackageBuilder {

    private int mTargetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;

    private int mFlags = 0;

    private ArrayList<String> mRequiredLibraries;

    private ArrayList<String> mOptionalLibraries;
@@ -41,6 +43,7 @@ class PackageBuilder {
    public PackageParser.Package build() {
        PackageParser.Package pkg = new PackageParser.Package("org.package.name");
        pkg.applicationInfo.targetSdkVersion = mTargetSdkVersion;
        pkg.applicationInfo.flags = mFlags;
        pkg.usesLibraries = mRequiredLibraries;
        pkg.usesOptionalLibraries = mOptionalLibraries;
        return pkg;
@@ -51,6 +54,11 @@ class PackageBuilder {
        return this;
    }

    PackageBuilder asSystemApp() {
        this.mFlags |= ApplicationInfo.FLAG_SYSTEM;
        return this;
    }

    PackageBuilder requiredLibraries(String... names) {
        this.mRequiredLibraries = arrayListOrNull(names);
        return this;