1From b4ae5c71f327d00081bbb0b7b26d48eb88761fbc Mon Sep 17 00:00:00 2001
2From: Alex Buynytskyy <alexbuy@google.com>
3Date: Tue, 21 Feb 2023 01:43:14 +0000
4Subject: [PATCH] Revert "HACK: allow apps with pre-release SDK RESTRICT AUTOMERGE"
5
6This reverts commit 3c9a5321dc94124367f2f4363d85a8f488f5d4d1.
7
8Reason for revert: not needed anymore
9
10Change-Id: I5c5e3af78a41e7bd8cbc99464dccc57c345105f3
11---
12
13diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
14index 3f4df4d..c15b3e0 100644
15--- a/core/java/android/content/pm/PackageParser.java
16+++ b/core/java/android/content/pm/PackageParser.java
17@@ -2628,15 +2628,6 @@
18             return Build.VERSION_CODES.CUR_DEVELOPMENT;
19         }
20
21-        // STOPSHIP: hack for the pre-release SDK
22-        if (platformSdkCodenames.length == 0
23-                && Build.VERSION.KNOWN_CODENAMES.stream().max(String::compareTo).orElse("").equals(
24-                targetCode)) {
25-            Slog.w(TAG, "Package requires development platform " + targetCode
26-                    + ", returning current version " + Build.VERSION.SDK_INT);
27-            return Build.VERSION.SDK_INT;
28-        }
29-
30         // Otherwise, we're looking at an incompatible pre-release SDK.
31         if (platformSdkCodenames.length > 0) {
32             outError[0] = "Requires development platform " + targetCode
33@@ -2708,15 +2699,6 @@
34             return Build.VERSION_CODES.CUR_DEVELOPMENT;
35         }
36
37-        // STOPSHIP: hack for the pre-release SDK
38-        if (platformSdkCodenames.length == 0
39-                && Build.VERSION.KNOWN_CODENAMES.stream().max(String::compareTo).orElse("").equals(
40-                minCode)) {
41-            Slog.w(TAG, "Package requires min development platform " + minCode
42-                    + ", returning current version " + Build.VERSION.SDK_INT);
43-            return Build.VERSION.SDK_INT;
44-        }
45-
46         // Otherwise, we're looking at an incompatible pre-release SDK.
47         if (platformSdkCodenames.length > 0) {
48             outError[0] = "Requires development platform " + minCode
49diff --git a/core/java/android/content/pm/parsing/FrameworkParsingPackageUtils.java b/core/java/android/content/pm/parsing/FrameworkParsingPackageUtils.java
50index 8cc4cdb..3e1c5bb 100644
51--- a/core/java/android/content/pm/parsing/FrameworkParsingPackageUtils.java
52+++ b/core/java/android/content/pm/parsing/FrameworkParsingPackageUtils.java
53@@ -316,15 +316,6 @@
54             return input.success(Build.VERSION_CODES.CUR_DEVELOPMENT);
55         }
56
57-        // STOPSHIP: hack for the pre-release SDK
58-        if (platformSdkCodenames.length == 0
59-                && Build.VERSION.KNOWN_CODENAMES.stream().max(String::compareTo).orElse("").equals(
60-                        minCode)) {
61-            Slog.w(TAG, "Parsed package requires min development platform " + minCode
62-                    + ", returning current version " + Build.VERSION.SDK_INT);
63-            return input.success(Build.VERSION.SDK_INT);
64-        }
65-
66         // Otherwise, we're looking at an incompatible pre-release SDK.
67         if (platformSdkCodenames.length > 0) {
68             return input.error(PackageManager.INSTALL_FAILED_OLDER_SDK,
69@@ -377,27 +368,19 @@
70             return input.success(targetVers);
71         }
72
73-        // If it's a pre-release SDK and the codename matches this platform, it
74-        // definitely targets this SDK.
75-        if (matchTargetCode(platformSdkCodenames, targetCode)) {
76-            return input.success(Build.VERSION_CODES.CUR_DEVELOPMENT);
77-        }
78-
79-        // STOPSHIP: hack for the pre-release SDK
80-        if (platformSdkCodenames.length == 0
81-                && Build.VERSION.KNOWN_CODENAMES.stream().max(String::compareTo).orElse("").equals(
82-                        targetCode)) {
83-            Slog.w(TAG, "Parsed package requires development platform " + targetCode
84-                    + ", returning current version " + Build.VERSION.SDK_INT);
85-            return input.success(Build.VERSION.SDK_INT);
86-        }
87-
88         try {
89             if (allowUnknownCodenames && UnboundedSdkLevel.isAtMost(targetCode)) {
90                 return input.success(Build.VERSION_CODES.CUR_DEVELOPMENT);
91             }
92         } catch (IllegalArgumentException e) {
93-            return input.error(PackageManager.INSTALL_FAILED_OLDER_SDK, "Bad package SDK");
94+            // isAtMost() throws it when encountering an older SDK codename
95+            return input.error(PackageManager.INSTALL_FAILED_OLDER_SDK, e.getMessage());
96+        }
97+
98+        // If it's a pre-release SDK and the codename matches this platform, it
99+        // definitely targets this SDK.
100+        if (matchTargetCode(platformSdkCodenames, targetCode)) {
101+            return input.success(Build.VERSION_CODES.CUR_DEVELOPMENT);
102         }
103
104         // Otherwise, we're looking at an incompatible pre-release SDK.
105diff --git a/services/tests/servicestests/src/com/android/server/systemconfig/SystemConfigTest.java b/services/tests/servicestests/src/com/android/server/systemconfig/SystemConfigTest.java
106index 687e8f7..92c7871 100644
107--- a/services/tests/servicestests/src/com/android/server/systemconfig/SystemConfigTest.java
108+++ b/services/tests/servicestests/src/com/android/server/systemconfig/SystemConfigTest.java
109@@ -446,14 +446,14 @@
110                         + "    <library \n"
111                         + "        name=\"foo\"\n"
112                         + "        file=\"" + mFooJar + "\"\n"
113-                        + "        on-bootclasspath-before=\"A\"\n"
114+                        + "        on-bootclasspath-before=\"Q\"\n"
115                         + "        on-bootclasspath-since=\"W\"\n"
116                         + "     />\n\n"
117                         + " </permissions>";
118         parseSharedLibraries(contents);
119         assertFooIsOnlySharedLibrary();
120         SystemConfig.SharedLibraryEntry entry = mSysConfig.getSharedLibraries().get("foo");
121-        assertThat(entry.onBootclasspathBefore).isEqualTo("A");
122+        assertThat(entry.onBootclasspathBefore).isEqualTo("Q");
123         assertThat(entry.onBootclasspathSince).isEqualTo("W");
124     }
125
126