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

Commit 120aa88d authored by Yurii Zubrytskyi's avatar Yurii Zubrytskyi Committed by Android (Google) Code Review
Browse files

Merge changes from topic "Tiramisu-SDK-Finalization-revert-hack" into tm-dev

* changes:
  Catch parsing errors for pre-release platforms
  Revert "HACK: allow apps with pre-release SDK RESTRICT AUTOMERGE"
parents 90cd705e bb146e1b
Loading
Loading
Loading
Loading
+0 −18
Original line number Diff line number Diff line
@@ -2618,15 +2618,6 @@ public class PackageParser {
            return Build.VERSION_CODES.CUR_DEVELOPMENT;
        }

        // STOPSHIP: hack for the pre-release SDK
        if (platformSdkCodenames.length == 0
                && Build.VERSION.KNOWN_CODENAMES.stream().max(String::compareTo).orElse("").equals(
                targetCode)) {
            Slog.w(TAG, "Package requires development platform " + targetCode
                    + ", returning current version " + Build.VERSION.SDK_INT);
            return Build.VERSION.SDK_INT;
        }

        // Otherwise, we're looking at an incompatible pre-release SDK.
        if (platformSdkCodenames.length > 0) {
            outError[0] = "Requires development platform " + targetCode
@@ -2698,15 +2689,6 @@ public class PackageParser {
            return Build.VERSION_CODES.CUR_DEVELOPMENT;
        }

        // STOPSHIP: hack for the pre-release SDK
        if (platformSdkCodenames.length == 0
                && Build.VERSION.KNOWN_CODENAMES.stream().max(String::compareTo).orElse("").equals(
                minCode)) {
            Slog.w(TAG, "Package requires min development platform " + minCode
                    + ", returning current version " + Build.VERSION.SDK_INT);
            return Build.VERSION.SDK_INT;
        }

        // Otherwise, we're looking at an incompatible pre-release SDK.
        if (platformSdkCodenames.length > 0) {
            outError[0] = "Requires development platform " + minCode
+8 −25
Original line number Diff line number Diff line
@@ -316,15 +316,6 @@ public class FrameworkParsingPackageUtils {
            return input.success(Build.VERSION_CODES.CUR_DEVELOPMENT);
        }

        // STOPSHIP: hack for the pre-release SDK
        if (platformSdkCodenames.length == 0
                && Build.VERSION.KNOWN_CODENAMES.stream().max(String::compareTo).orElse("").equals(
                        minCode)) {
            Slog.w(TAG, "Parsed package requires min development platform " + minCode
                    + ", returning current version " + Build.VERSION.SDK_INT);
            return input.success(Build.VERSION.SDK_INT);
        }

        // Otherwise, we're looking at an incompatible pre-release SDK.
        if (platformSdkCodenames.length > 0) {
            return input.error(PackageManager.INSTALL_FAILED_OLDER_SDK,
@@ -377,27 +368,19 @@ public class FrameworkParsingPackageUtils {
            return input.success(targetVers);
        }

        // If it's a pre-release SDK and the codename matches this platform, it
        // definitely targets this SDK.
        if (matchTargetCode(platformSdkCodenames, targetCode)) {
            return input.success(Build.VERSION_CODES.CUR_DEVELOPMENT);
        }

        // STOPSHIP: hack for the pre-release SDK
        if (platformSdkCodenames.length == 0
                && Build.VERSION.KNOWN_CODENAMES.stream().max(String::compareTo).orElse("").equals(
                        targetCode)) {
            Slog.w(TAG, "Parsed package requires development platform " + targetCode
                    + ", returning current version " + Build.VERSION.SDK_INT);
            return input.success(Build.VERSION.SDK_INT);
        }

        try {
            if (allowUnknownCodenames && UnboundedSdkLevel.isAtMost(targetCode)) {
                return input.success(Build.VERSION_CODES.CUR_DEVELOPMENT);
            }
        } catch (IllegalArgumentException e) {
            return input.error(PackageManager.INSTALL_FAILED_OLDER_SDK, "Bad package SDK");
            // isAtMost() throws it when encountering an older SDK codename
            return input.error(PackageManager.INSTALL_FAILED_OLDER_SDK, e.getMessage());
        }

        // If it's a pre-release SDK and the codename matches this platform, it
        // definitely targets this SDK.
        if (matchTargetCode(platformSdkCodenames, targetCode)) {
            return input.success(Build.VERSION_CODES.CUR_DEVELOPMENT);
        }

        // Otherwise, we're looking at an incompatible pre-release SDK.
+22 −6
Original line number Diff line number Diff line
@@ -113,6 +113,24 @@ public class SystemConfig {

    final ArrayList<SplitPermissionInfo> mSplitPermissions = new ArrayList<>();

    private static boolean isAtLeastSdkLevel(String version) {
        try {
            return UnboundedSdkLevel.isAtLeast(version);
        } catch (IllegalArgumentException e) {
            // UnboundedSdkLevel throws when it sees a known old codename
            return false;
        }
    }

    private static boolean isAtMostSdkLevel(String version) {
        try {
            return UnboundedSdkLevel.isAtMost(version);
        } catch (IllegalArgumentException e) {
            // UnboundedSdkLevel throws when it sees a known old codename
            return true;
        }
    }

    public static final class SharedLibraryEntry {
        public final String name;
        public final String filename;
@@ -180,9 +198,9 @@ public class SystemConfig {
            // - onBootclasspathBefore is set and we are before that SDK
            canBeSafelyIgnored =
                    (this.onBootclasspathSince != null
                            && UnboundedSdkLevel.isAtLeast(this.onBootclasspathSince))
                            && isAtLeastSdkLevel(this.onBootclasspathSince))
                            || (this.onBootclasspathBefore != null
                            && !UnboundedSdkLevel.isAtLeast(this.onBootclasspathBefore));
                            && !isAtLeastSdkLevel(this.onBootclasspathBefore));
        }
    }

@@ -885,11 +903,9 @@ public class SystemConfig {
                                        + parser.getPositionDescription());
                            } else {
                                boolean allowedMinSdk =
                                        minDeviceSdk == null || UnboundedSdkLevel.isAtLeast(
                                                minDeviceSdk);
                                        minDeviceSdk == null || isAtLeastSdkLevel(minDeviceSdk);
                                boolean allowedMaxSdk =
                                        maxDeviceSdk == null || UnboundedSdkLevel.isAtMost(
                                                maxDeviceSdk);
                                        maxDeviceSdk == null || isAtMostSdkLevel(maxDeviceSdk);
                                final boolean exists = new File(lfile).exists();
                                if (allowedMinSdk && allowedMaxSdk && exists) {
                                    String bcpSince = parser.getAttributeValue(null,
+2 −2
Original line number Diff line number Diff line
@@ -393,14 +393,14 @@ public class SystemConfigTest {
                        + "    <library \n"
                        + "        name=\"foo\"\n"
                        + "        file=\"" + mFooJar + "\"\n"
                        + "        on-bootclasspath-before=\"A\"\n"
                        + "        on-bootclasspath-before=\"Q\"\n"
                        + "        on-bootclasspath-since=\"W\"\n"
                        + "     />\n\n"
                        + " </permissions>";
        parseSharedLibraries(contents);
        assertFooIsOnlySharedLibrary();
        SystemConfig.SharedLibraryEntry entry = mSysConfig.getSharedLibraries().get("foo");
        assertThat(entry.onBootclasspathBefore).isEqualTo("A");
        assertThat(entry.onBootclasspathBefore).isEqualTo("Q");
        assertThat(entry.onBootclasspathSince).isEqualTo("W");
    }