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