Merge "Refactor header ABI checker code" into main
diff --git a/filesystem/fsverity_metadata.go b/filesystem/fsverity_metadata.go
index 70f94e0..3e50ff7 100644
--- a/filesystem/fsverity_metadata.go
+++ b/filesystem/fsverity_metadata.go
@@ -27,6 +27,9 @@
 	// etc/security/fsverity/BuildManifest.apk will also be generated which contains information
 	// about generated .fsv_meta files.
 	Inputs []string
+
+	// APK libraries to link against, for etc/security/fsverity/BuildManifest.apk
+	Libs []string `android:"path"`
 }
 
 func (f *filesystem) writeManifestGeneratorListFile(ctx android.ModuleContext, outputPath android.OutputPath, matchedSpecs []android.PackagingSpec, rebasedDir android.OutputPath) {
@@ -117,20 +120,20 @@
 	aapt2Path := ctx.Config().HostToolPath(ctx, "aapt2")
 	apkPath := rebasedDir.Join(ctx, "etc", "security", "fsverity", "BuildManifest.apk")
 	manifestTemplatePath := android.PathForSource(ctx, "system/security/fsverity/AndroidManifest.xml")
-	// package-export is currently generated by Makefile.
-	// TODO(b/330282551): fully migrate into Soong
-	frameworkResPath := android.PathForArbitraryOutput(ctx, "target/common/obj/APPS/framework-res_intermediates/package-export.apk")
+	libs := android.PathsForModuleSrc(ctx, f.properties.Fsverity.Libs)
 	cmd.Implicit(aapt2Path)
 	cmd.Implicit(manifestTemplatePath)
-	cmd.Implicit(frameworkResPath)
+	cmd.Implicits(libs)
 
 	sb.WriteString(aapt2Path.String())
 	sb.WriteString(" link -o ")
 	sb.WriteString(apkPath.String())
 	sb.WriteString(" -A ")
 	sb.WriteString(assetsPath.String())
-	sb.WriteString(" -I ")
-	sb.WriteString(frameworkResPath.String())
+	for _, lib := range libs {
+		sb.WriteString(" -I ")
+		sb.WriteString(lib.String())
+	}
 	minSdkVersion := ctx.Config().PlatformSdkCodename()
 	if minSdkVersion == "REL" {
 		minSdkVersion = ctx.Config().PlatformSdkVersion().String()
diff --git a/java/droidstubs.go b/java/droidstubs.go
index 9556e95..02b81a4 100644
--- a/java/droidstubs.go
+++ b/java/droidstubs.go
@@ -687,6 +687,23 @@
 	}
 }
 
+func (d *Droidstubs) apiCompatibilityFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsType StubsType) {
+	if len(d.Javadoc.properties.Out) > 0 {
+		ctx.PropertyErrorf("out", "out property may not be combined with check_api")
+	}
+
+	apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
+	removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
+
+	cmd.FlagWithInput("--check-compatibility:api:released ", apiFile)
+	cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile)
+
+	baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file)
+	if baselineFile.Valid() {
+		cmd.FlagWithInput("--baseline:compatibility:released ", baselineFile.Path())
+	}
+}
+
 func metalavaUseRbe(ctx android.ModuleContext) bool {
 	return ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_METALAVA")
 }
@@ -831,6 +848,10 @@
 	d.inclusionAnnotationsFlags(ctx, cmd)
 	d.apiLevelsAnnotationsFlags(ctx, cmd, params.stubConfig.stubsType, params.apiVersionsXml)
 
+	if params.stubConfig.doCheckReleased {
+		d.apiCompatibilityFlags(ctx, cmd, params.stubConfig.stubsType)
+	}
+
 	d.expandArgs(ctx, cmd)
 
 	for _, o := range d.Javadoc.properties.Out {
@@ -989,25 +1010,12 @@
 
 	// Add "check released" options. (Detect incompatible API changes from the last public release)
 	if doCheckReleased {
-		if len(d.Javadoc.properties.Out) > 0 {
-			ctx.PropertyErrorf("out", "out property may not be combined with check_api")
-		}
-
-		apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
-		removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
 		baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file)
-		updatedBaselineOutput := android.PathForModuleOut(ctx, Everything.String(), "last_released_baseline.txt")
-
 		d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, Everything.String(), "check_last_released_api.timestamp")
-
-		cmd.FlagWithInput("--check-compatibility:api:released ", apiFile)
-		cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile)
-
 		if baselineFile.Valid() {
-			cmd.FlagWithInput("--baseline:compatibility:released ", baselineFile.Path())
+			updatedBaselineOutput := android.PathForModuleOut(ctx, Everything.String(), "last_released_baseline.txt")
 			cmd.FlagWithOutput("--update-baseline:compatibility:released ", updatedBaselineOutput)
 		}
-
 		// Note this string includes quote ($' ... '), which decodes the "\n"s.
 		msg := `$'\n******************************\n` +
 			`You have tried to change the API from what has been previously released in\n` +
diff --git a/sdk/update.go b/sdk/update.go
index b8ae38a..afecf9f 100644
--- a/sdk/update.go
+++ b/sdk/update.go
@@ -163,6 +163,20 @@
 	})
 }
 
+// A denylist of modules whose host variants will be removed from the generated snapshots above the ApiLevel
+// even if they are listed in the corresponding `sdk`.
+// The key is the module name
+// The value is the _last_ dessert where the host variant of the module will be present
+// This is a workaround to ensure that these modules are generated in <=$ApiLevel, but not in in >=$ApiLevel
+var ignoreHostModuleVariantsAboveDessert = map[string]android.ApiLevel{
+	// ignore host variant of libdexfile and its transitive dependencies.
+	// The platform test that depends on them (`libunwindstack_unit_test` at the time of writing)
+	// no longer requires a prebuilt variant of libdexfile.
+	"libdexfile":    android.ApiLevelUpsideDownCake,
+	"libartpalette": android.ApiLevelUpsideDownCake,
+	"libartbase":    android.ApiLevelUpsideDownCake,
+}
+
 // groupMemberVariantsByMemberThenType groups the member variant dependencies so that all the
 // variants of each member are grouped together within an sdkMember instance.
 //
@@ -181,6 +195,14 @@
 		variant := memberVariantDep.variant
 
 		name := ctx.OtherModuleName(variant)
+		targetApiLevel, err := android.ApiLevelFromUser(ctx, targetBuildRelease.name)
+		if err != nil {
+			targetApiLevel = android.FutureApiLevel
+		}
+		if lastApiLevel, exists := ignoreHostModuleVariantsAboveDessert[name]; exists && targetApiLevel.GreaterThan(lastApiLevel) && memberVariantDep.Host() {
+			// ignore host variant of this module if the targetApiLevel is V and above.
+			continue
+		}
 		member := byName[name]
 		if member == nil {
 			member = &sdkMember{memberType: memberType, name: name}
diff --git a/ui/build/androidmk_denylist.go b/ui/build/androidmk_denylist.go
index e7896ab..a29f413 100644
--- a/ui/build/androidmk_denylist.go
+++ b/ui/build/androidmk_denylist.go
@@ -23,6 +23,7 @@
 	"cts/",
 	"dalvik/",
 	"developers/",
+	"frameworks/",
 	// Do not block other directories in kernel/, see b/319658303.
 	"kernel/configs/",
 	"kernel/prebuilts/",