Set targetSdkVersion to 10000 for MTS tests targeting current

MTS tests built on unstable branches (e.g. git_master) should be testable on
old system images (e.g. S). However, they run into an error during installation
on older images:
`Requires development platform $<current_codename>, but this is a
release platform`

This CL fixes this issue by updating the target_sdk_version of MTS test apps
targeting current to the magical sdk_version 10000

Bug: 227473065
Test: go build ./java
Test: TH
Change-Id: Ic0358a48a19dc239defbb4ee8ec99225cce75584
Merged-In: Ic0358a48a19dc239defbb4ee8ec99225cce75584
This commit is contained in:
Spandan Das
2022-07-25 00:34:18 +00:00
parent c4d437c6bf
commit cf9b0070c0
3 changed files with 88 additions and 1 deletions

View File

@@ -45,7 +45,11 @@ var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger",
// This enables release builds (that run with TARGET_BUILD_APPS=[val...]) to target APIs that have not yet been finalized as part of an SDK
func targetSdkVersionForManifestFixer(ctx android.ModuleContext, sdkContext android.SdkContext) string {
targetSdkVersionSpec := sdkContext.TargetSdkVersion(ctx)
if ctx.Config().UnbundledBuildApps() && targetSdkVersionSpec.ApiLevel.IsPreview() {
// Return 10000 for modules targeting "current" if either
// 1. The module is built in unbundled mode (TARGET_BUILD_APPS not empty)
// 2. The module is run as part of MTS, and should be testable on stable branches
// TODO(b/240294501): Determine the rules for handling test apexes
if targetSdkVersionSpec.ApiLevel.IsPreview() && (ctx.Config().UnbundledBuildApps() || includedInMts(ctx.Module())) {
return strconv.Itoa(android.FutureApiLevel.FinalOrFutureInt())
}
targetSdkVersion, err := targetSdkVersionSpec.EffectiveVersionString(ctx)
@@ -55,6 +59,15 @@ func targetSdkVersionForManifestFixer(ctx android.ModuleContext, sdkContext andr
return targetSdkVersion
}
// Helper function that casts android.Module to java.androidTestApp
// If this type conversion is possible, it queries whether the test app is included in an MTS suite
func includedInMts(module android.Module) bool {
if test, ok := module.(androidTestApp); ok {
return test.includedInTestSuite("mts")
}
return false
}
type ManifestFixerParams struct {
SdkContext android.SdkContext
ClassLoaderContexts dexpreopt.ClassLoaderContextMap