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"
This commit is contained in:
Yurii Zubrytskyi
2022-06-11 05:42:37 +00:00
committed by Android (Google) Code Review
4 changed files with 32 additions and 51 deletions

View File

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

View File

@@ -316,15 +316,6 @@ public class FrameworkParsingPackageUtils {
return input.success(Build.VERSION_CODES.CUR_DEVELOPMENT); 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. // Otherwise, we're looking at an incompatible pre-release SDK.
if (platformSdkCodenames.length > 0) { if (platformSdkCodenames.length > 0) {
return input.error(PackageManager.INSTALL_FAILED_OLDER_SDK, return input.error(PackageManager.INSTALL_FAILED_OLDER_SDK,
@@ -377,27 +368,19 @@ public class FrameworkParsingPackageUtils {
return input.success(targetVers); 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 { try {
if (allowUnknownCodenames && UnboundedSdkLevel.isAtMost(targetCode)) { if (allowUnknownCodenames && UnboundedSdkLevel.isAtMost(targetCode)) {
return input.success(Build.VERSION_CODES.CUR_DEVELOPMENT); return input.success(Build.VERSION_CODES.CUR_DEVELOPMENT);
} }
} catch (IllegalArgumentException e) { } 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. // Otherwise, we're looking at an incompatible pre-release SDK.

View File

@@ -113,6 +113,24 @@ public class SystemConfig {
final ArrayList<SplitPermissionInfo> mSplitPermissions = new ArrayList<>(); 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 static final class SharedLibraryEntry {
public final String name; public final String name;
public final String filename; public final String filename;
@@ -180,9 +198,9 @@ public class SystemConfig {
// - onBootclasspathBefore is set and we are before that SDK // - onBootclasspathBefore is set and we are before that SDK
canBeSafelyIgnored = canBeSafelyIgnored =
(this.onBootclasspathSince != null (this.onBootclasspathSince != null
&& UnboundedSdkLevel.isAtLeast(this.onBootclasspathSince)) && isAtLeastSdkLevel(this.onBootclasspathSince))
|| (this.onBootclasspathBefore != null || (this.onBootclasspathBefore != null
&& !UnboundedSdkLevel.isAtLeast(this.onBootclasspathBefore)); && !isAtLeastSdkLevel(this.onBootclasspathBefore));
} }
} }
@@ -885,11 +903,9 @@ public class SystemConfig {
+ parser.getPositionDescription()); + parser.getPositionDescription());
} else { } else {
boolean allowedMinSdk = boolean allowedMinSdk =
minDeviceSdk == null || UnboundedSdkLevel.isAtLeast( minDeviceSdk == null || isAtLeastSdkLevel(minDeviceSdk);
minDeviceSdk);
boolean allowedMaxSdk = boolean allowedMaxSdk =
maxDeviceSdk == null || UnboundedSdkLevel.isAtMost( maxDeviceSdk == null || isAtMostSdkLevel(maxDeviceSdk);
maxDeviceSdk);
final boolean exists = new File(lfile).exists(); final boolean exists = new File(lfile).exists();
if (allowedMinSdk && allowedMaxSdk && exists) { if (allowedMinSdk && allowedMaxSdk && exists) {
String bcpSince = parser.getAttributeValue(null, String bcpSince = parser.getAttributeValue(null,

View File

@@ -393,14 +393,14 @@ public class SystemConfigTest {
+ " <library \n" + " <library \n"
+ " name=\"foo\"\n" + " name=\"foo\"\n"
+ " file=\"" + mFooJar + "\"\n" + " file=\"" + mFooJar + "\"\n"
+ " on-bootclasspath-before=\"A\"\n" + " on-bootclasspath-before=\"Q\"\n"
+ " on-bootclasspath-since=\"W\"\n" + " on-bootclasspath-since=\"W\"\n"
+ " />\n\n" + " />\n\n"
+ " </permissions>"; + " </permissions>";
parseSharedLibraries(contents); parseSharedLibraries(contents);
assertFooIsOnlySharedLibrary(); assertFooIsOnlySharedLibrary();
SystemConfig.SharedLibraryEntry entry = mSysConfig.getSharedLibraries().get("foo"); SystemConfig.SharedLibraryEntry entry = mSysConfig.getSharedLibraries().get("foo");
assertThat(entry.onBootclasspathBefore).isEqualTo("A"); assertThat(entry.onBootclasspathBefore).isEqualTo("Q");
assertThat(entry.onBootclasspathSince).isEqualTo("W"); assertThat(entry.onBootclasspathSince).isEqualTo("W");
} }