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

Commit 50b3c930 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "pm-block-incompatible-min-sdk-version-full" into main

* changes:
  Block installs of incompatible minSdkVersion minor values
  Build: add hidden method to convert major.minor int to human readable string
  Build: add hidden method to parse a major.minor String to int
  Allow new minSdkVersionFull attribute in <uses-sdk>
  android.sdk aconfig flags: add android.sdk.flags-aconfig-java-host
  android.sdk aconfig flags: rename soong modules
parents 0d5dcdd5 5570d1e6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ aconfig_declarations_group {
        "aconfig_mediacodec_flags_java_lib",
        "aconfig_settingslib_flags_java_lib",
        "aconfig_trade_in_mode_flags_java_lib",
        "android-sdk-flags-java",
        "android.adaptiveauth.flags-aconfig-java",
        "android.app.appfunctions.flags-aconfig-java",
        "android.app.assist.flags-aconfig-java",
@@ -63,6 +62,7 @@ aconfig_declarations_group {
        "android.os.vibrator.flags-aconfig-java",
        "android.permission.flags-aconfig-java",
        "android.provider.flags-aconfig-java",
        "android.sdk.flags-aconfig-java",
        "android.security.flags-aconfig-java",
        "android.server.app.flags-aconfig-java",
        "android.service.autofill.flags-aconfig-java",
+10 −3
Original line number Diff line number Diff line
@@ -17,14 +17,21 @@ package {
}

aconfig_declarations {
    name: "android-sdk-flags",
    name: "android.sdk.flags-aconfig",
    package: "android.sdk",
    container: "system",
    srcs: ["flags.aconfig"],
}

java_aconfig_library {
    name: "android-sdk-flags-java",
    aconfig_declarations: "android-sdk-flags",
    name: "android.sdk.flags-aconfig-java",
    aconfig_declarations: "android.sdk.flags-aconfig",
    defaults: ["framework-minus-apex-aconfig-java-defaults"],
}

java_aconfig_library {
    name: "android.sdk.flags-aconfig-java-host",
    aconfig_declarations: "android.sdk.flags-aconfig",
    host_supported: true,
    defaults: ["framework-minus-apex-aconfig-java-defaults"],
}
+1 −0
Original line number Diff line number Diff line
@@ -1203,6 +1203,7 @@ package android {
    field public static final int minResizeHeight = 16843670; // 0x1010396
    field public static final int minResizeWidth = 16843669; // 0x1010395
    field public static final int minSdkVersion = 16843276; // 0x101020c
    field @FlaggedApi("android.content.pm.support_minor_versions_in_minsdkversion") public static final int minSdkVersionFull;
    field public static final int minWidth = 16843071; // 0x101013f
    field public static final int minimumHorizontalAngle = 16843901; // 0x101047d
    field public static final int minimumVerticalAngle = 16843902; // 0x101047e
+30 −0
Original line number Diff line number Diff line
@@ -329,6 +329,36 @@ public class FrameworkParsingPackageUtils {
        }
    }

    /**
     * Check if a package is compatible with this platform with regards to its
     * its minSdkVersionFull.
     *
     * @param minSdkVersionFullString    A string representation of a major.minor version,
     *                                   e.g. "12.34"
     * @param platformMinSdkVersionFull The major and minor version of the platform, i.e. the value
     *                                  of Build.VERSION.SDK_INT_FULL
     * @param input                     A ParseInput object to report success or failure
     */
    public static ParseResult<Void> verifyMinSdkVersionFull(@NonNull String minSdkVersionFullString,
            int platformMinSdkVersionFull, @NonNull ParseInput input) {
        int minSdkVersionFull;
        try {
            minSdkVersionFull = Build.parseFullVersion(minSdkVersionFullString);
        } catch (IllegalStateException e) {
            return input.error(PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED,
                    e.getMessage());
        }
        if (minSdkVersionFull <= platformMinSdkVersionFull) {
            return input.success(null);
        }
        return input.error(PackageManager.INSTALL_FAILED_OLDER_SDK,
                "Requires newer sdk version "
                + Build.fullVersionToString(minSdkVersionFull)
                + " (current version is "
                + Build.fullVersionToString(platformMinSdkVersionFull)
                + ")");
    }

    /**
     * Computes the targetSdkVersion to use at runtime. If the package is not compatible with this
     * platform, populates {@code outError[0]} with an error message.
+51 −0
Original line number Diff line number Diff line
@@ -1545,6 +1545,57 @@ public class Build {
        return sdkIntFull % VERSION_CODES_FULL.SDK_INT_MULTIPLIER;
    }

    /**
     * Convert a major.minor version String like "36.1" to an int that
     * represents both major and minor version.
     *
     * @param version the String to parse
     * @return an int encoding the major and minor version
     * @throws IllegalArgumentException if the string could not be converted into an int
     *
     * @hide
     */
    @SuppressWarnings("FlaggedApi") // SDK_INT_MULTIPLIER is defined in this file
    public static @SdkIntFull int parseFullVersion(@NonNull String version) {
        int index = version.indexOf('.');
        int major;
        int minor = 0;
        try {
            if (index == -1) {
                major = Integer.parseInt(version);
            } else {
                major = Integer.parseInt(version.substring(0, index));
                minor = Integer.parseInt(version.substring(index + 1));
            }
            if (major < 0 || minor < 0) {
                throw new NumberFormatException();
            }
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("failed to parse '" + version
                    + "' as a major.minor version code");
        }
        return major * VERSION_CODES_FULL.SDK_INT_MULTIPLIER + minor;
    }

    /**
     * Convert an int representing a major.minor version like SDK_INT_FULL to a
     * human readable string. The returned string is only intended for debug
     * and error messages.
     *
     * @param version the int to convert to a string
     * @return a String representing the same major.minor version as the int passed in
     * @throws IllegalArgumentException if {@code version} is negative
     *
     * @hide
     */
    public static String fullVersionToString(@SdkIntFull int version) {
        if (version < 0) {
            throw new IllegalArgumentException("failed to convert '" + version
                    + "' to string: not a valid major.minor version code");
        }
        return String.format("%d.%d", getMajorSdkVersion(version), getMinorSdkVersion(version));
    }

    /**
     * The vendor API for 2024 Q2
     *
Loading