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

Commit 5ef7d7b7 authored by Pedro Loureiro's avatar Pedro Loureiro
Browse files

Allow unknown codenames in target sdk version for APK-in-apexes

This is currently a recurring issue every new Android release as a few of
our apps will be targeting new platforms and they also get installed on
devices running older SDKs.

This change only changes behaviour for APK in apexes.

Test: atest com.android.server.pm.parsing.PackageParserLegacyCoreTest

Bug: 208239394

Merged-In: If1195c8ec39ac88a605e25dfb1c78d49a5aa3e7c
Change-Id: If1195c8ec39ac88a605e25dfb1c78d49a5aa3e7c
parent 5ff11183
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -326,6 +326,7 @@ java_defaults {
        "av-types-aidl-java",
        "tv_tuner_resource_manager_aidl_interface-java",
        "soundtrigger_middleware-aidl-java",
        "modules-utils-build",
        "modules-utils-preconditions",
        "modules-utils-synchronous-result-receiver",
        "modules-utils-os",
+2 −1
Original line number Diff line number Diff line
@@ -568,7 +568,8 @@ public class ApkLiteParseUtils {
                }

                ParseResult<Integer> targetResult = FrameworkParsingPackageUtils.computeTargetSdkVersion(
                        targetVer, targetCode, SDK_CODENAMES, input);
                        targetVer, targetCode, SDK_CODENAMES, input,
                        /* allowUnknownCodenames= */ false);
                if (targetResult.isError()) {
                    return input.error(targetResult);
                }
+20 −8
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.util.Slog;
import android.util.apk.ApkSignatureVerifier;

import com.android.internal.util.ArrayUtils;
import com.android.modules.utils.build.UnboundedSdkLevel;

import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
@@ -334,8 +335,9 @@ public class FrameworkParsingPackageUtils {
     * If {@code targetCode} is not specified, e.g. the value is {@code null}, then the {@code
     * targetVers} will be returned unmodified.
     * <p>
     * Otherwise, the behavior varies based on whether the current platform is a pre-release
     * version, e.g. the {@code platformSdkCodenames} array has length > 0:
     * When {@code allowUnknownCodenames} is false, the behavior varies based on whether the
     * current platform is a pre-release version, e.g. the {@code platformSdkCodenames} array has
     * length > 0:
     * <ul>
     * <li>If this is a pre-release platform and the value specified by
     * {@code targetCode} is contained within the array of allowed pre-release
@@ -343,22 +345,32 @@ public class FrameworkParsingPackageUtils {
     * <li>If this is a released platform, this method will return -1 to
     * indicate that the package is not compatible with this platform.
     * </ul>
     * <p>
     * When {@code allowUnknownCodenames} is true, any codename that is not known (presumed to be
     * a codename announced after the build of the current device) is allowed and this method will
     * return {@link Build.VERSION_CODES#CUR_DEVELOPMENT}.
     *
     * @param targetVers            targetSdkVersion number, if specified in the application
     *                              manifest, or 0 otherwise
     * @param targetCode            targetSdkVersion code, if specified in the application manifest,
     *                              or {@code null} otherwise
     * @param platformSdkCodenames  array of allowed pre-release SDK codenames for this platform
     * @param allowUnknownCodenames allow unknown codenames, if true this method will accept unknown
     *                              (presumed to be future) codenames
     * @return the targetSdkVersion to use at runtime if successful
     */
    public static ParseResult<Integer> computeTargetSdkVersion(@IntRange(from = 0) int targetVers,
            @Nullable String targetCode, @NonNull String[] platformSdkCodenames,
            @NonNull ParseInput input) {
            @NonNull ParseInput input, boolean allowUnknownCodenames) {
        // If it's a release SDK, return the version number unmodified.
        if (targetCode == null) {
            return input.success(targetVers);
        }

        if (allowUnknownCodenames && UnboundedSdkLevel.isAtMost(targetCode)) {
            return input.success(Build.VERSION_CODES.CUR_DEVELOPMENT);
        }

        // If it's a pre-release SDK and the codename matches this platform, it
        // definitely targets this SDK.
        if (matchTargetCode(platformSdkCodenames, targetCode)) {
+3 −0
Original line number Diff line number Diff line
@@ -5,3 +5,6 @@ rule android.hidl.** android.internal.hidl.@1
# Framework-specific renames.
rule android.net.wifi.WifiAnnotations* android.internal.wifi.WifiAnnotations@1
rule com.android.server.vcn.util.** com.android.server.vcn.repackaged.util.@1

# for modules-utils-build dependency
rule com.android.modules.utils.build.** android.internal.modules.utils.build.@1
+2 −2
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ import static com.android.server.pm.PackageManagerService.SCAN_NO_DEX;
import static com.android.server.pm.PackageManagerService.SCAN_REQUIRE_KNOWN;
import static com.android.server.pm.PackageManagerService.SYSTEM_PARTITIONS;
import static com.android.server.pm.PackageManagerService.TAG;
import static com.android.server.pm.pkg.parsing.ParsingPackageUtils.PARSE_CHECK_MAX_SDK_VERSION;
import static com.android.server.pm.pkg.parsing.ParsingPackageUtils.PARSE_APK_IN_APEX;

import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -359,7 +359,7 @@ final class InitAppsHelper {
        try {
            if ((scanFlags & SCAN_AS_APK_IN_APEX) != 0) {
                // when scanning apk in apexes, we want to check the maxSdkVersion
                parseFlags |= PARSE_CHECK_MAX_SDK_VERSION;
                parseFlags |= PARSE_APK_IN_APEX;
            }
            mInstallPackageHelper.installPackagesFromDir(scanDir, frameworkSplits, parseFlags,
                    scanFlags, packageParser, executorService);
Loading