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

Commit 4f203da1 authored by Songchun Fan's avatar Songchun Fan
Browse files

[pm] check versionMajor on sdk lib package update

When a package that defines an sdk lib is updated, if any change has
been made to the targetSdkVersion or minSdkVersion, make sure that the
sdk's versionMajor is also updated.

BUG: 354906634
FLAG: EXEMPT bug fix
Test: atest PackageManagerShellCommandInstallTest

Change-Id: I211d4fdec3d8e4a41d0821c0243561a07f4c9f0f
parent 00ab1ef9
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -1395,9 +1395,31 @@ final class InstallPackageHelper {
                                "Package " + pkgName + " is a persistent app. "
                                        + "Persistent apps are not updateable.");
                    }
                    // When updating an sdk library, make sure that the versionMajor is
                    // changed if the targetSdkVersion and minSdkVersion have changed
                    if (parsedPackage.isSdkLibrary() && ps.getPkg() != null
                            && ps.getPkg().isSdkLibrary()) {
                        final int oldMinSdk = ps.getPkg().getMinSdkVersion();
                        final int newMinSdk = parsedPackage.getMinSdkVersion();
                        if (oldTargetSdk != newTargetSdk || oldMinSdk != newMinSdk) {
                            final int oldVersionMajor = ps.getPkg().getSdkLibVersionMajor();
                            final int newVersionMajor = parsedPackage.getSdkLibVersionMajor();
                            if (oldVersionMajor == newVersionMajor) {
                                throw new PrepareFailure(
                                        PackageManager.INSTALL_FAILED_UPDATE_INCOMPATIBLE,
                                        "Failure updating " + pkgName + " as it updates"
                                                + " an sdk library <"
                                                + parsedPackage.getSdkLibraryName() + ">"
                                                + " without changing the versionMajor, but the"
                                                + " targetSdkVersion or minSdkVersion has changed."
                                );
                            }
                        }
                    }
                }

            }

            PackageSetting signatureCheckPs = ps;

            // SDK libs can have other major versions with different package names.