Merge "Add sdk_genrule" into main
diff --git a/aconfig/aconfig_declarations.go b/aconfig/aconfig_declarations.go
index 697dc22..c4fc31a 100644
--- a/aconfig/aconfig_declarations.go
+++ b/aconfig/aconfig_declarations.go
@@ -230,3 +230,12 @@
 
 	return android.Paths{output}
 }
+
+func SetAconfigFileMkEntries(m *android.ModuleBase, entries *android.AndroidMkEntries, aconfigFiles map[string]android.Paths) {
+	if m.InstallInVendor() {
+		entries.SetPaths("LOCAL_ACONFIG_FILES", aconfigFiles["vendor"])
+	} else {
+		// TODO(b/311155208): The container here should be system.
+		entries.SetPaths("LOCAL_ACONFIG_FILES", aconfigFiles[""])
+	}
+}
diff --git a/aconfig/codegen/cc_aconfig_library_test.go b/aconfig/codegen/cc_aconfig_library_test.go
index 0c8a969..3de4626 100644
--- a/aconfig/codegen/cc_aconfig_library_test.go
+++ b/aconfig/codegen/cc_aconfig_library_test.go
@@ -104,3 +104,61 @@
 			}
 		`, bpMode))
 }
+
+func TestAndroidMkCcLibrary(t *testing.T) {
+	bp := `
+		aconfig_declarations {
+			name: "my_aconfig_declarations_foo",
+			package: "com.example.package",
+			srcs: ["foo.aconfig"],
+			container: "vendor",
+		}
+
+		cc_aconfig_library {
+			name: "my_cc_aconfig_library_foo",
+			aconfig_declarations: "my_aconfig_declarations_foo",
+			vendor_available: true,
+		}
+
+		aconfig_declarations {
+			name: "my_aconfig_declarations_bar",
+			package: "com.example.package",
+			srcs: ["bar.aconfig"],
+		}
+
+		cc_aconfig_library {
+			name: "my_cc_aconfig_library_bar",
+			aconfig_declarations: "my_aconfig_declarations_bar",
+			vendor_available: true,
+		}
+
+		cc_library {
+			name: "my_cc_library",
+			srcs: [
+				"src/foo.cc",
+			],
+			static_libs: [
+				"my_cc_aconfig_library_foo",
+				"my_cc_aconfig_library_bar",
+			],
+			vendor: true,
+		}
+
+		cc_library {
+			name: "server_configurable_flags",
+			srcs: ["server_configurable_flags.cc"],
+		}
+	`
+	result := android.GroupFixturePreparers(
+		PrepareForTestWithAconfigBuildComponents,
+		cc.PrepareForTestWithCcDefaultModules).
+		ExtendWithErrorHandler(android.FixtureExpectsNoErrors).RunTestWithBp(t, bp)
+
+	module := result.ModuleForTests("my_cc_library", "android_arm64_armv8-a_shared").Module()
+
+	entry := android.AndroidMkEntriesForTest(t, result.TestContext, module)[0]
+
+	makeVar := entry.EntryMap["LOCAL_ACONFIG_FILES"]
+	android.AssertIntEquals(t, "len(LOCAL_ACONFIG_FILES)", 1, len(makeVar))
+	android.EnsureListContainsSuffix(t, makeVar, "my_aconfig_declarations_foo/intermediate.pb")
+}
diff --git a/cc/androidmk.go b/cc/androidmk.go
index 8cae634..54c7f97 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -15,6 +15,7 @@
 package cc
 
 import (
+	"android/soong/aconfig"
 	"github.com/google/blueprint/proptools"
 
 	"fmt"
@@ -133,8 +134,7 @@
 					entries.SetString("SOONG_SDK_VARIANT_MODULES",
 						"$(SOONG_SDK_VARIANT_MODULES) $(patsubst %.sdk,%,$(LOCAL_MODULE))")
 				}
-				// TODO(b/311155208): The container here should be system.
-				entries.SetPaths("LOCAL_ACONFIG_FILES", c.mergedAconfigFiles[""])
+				aconfig.SetAconfigFileMkEntries(c.AndroidModuleBase(), entries, c.mergedAconfigFiles)
 			},
 		},
 		ExtraFooters: []android.AndroidMkExtraFootersFunc{
diff --git a/cc/compiler.go b/cc/compiler.go
index bb7885b..c9de1b0 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -479,7 +479,7 @@
 			target += strconv.Itoa(android.FutureApiLevelInt)
 		} else {
 			apiLevel := nativeApiLevelOrPanic(ctx, version)
-			target += apiLevel.String()
+			target += strconv.Itoa(apiLevel.FinalOrFutureInt())
 		}
 	}
 
diff --git a/cmd/sbox/sbox.go b/cmd/sbox/sbox.go
index e69a930..3364f50 100644
--- a/cmd/sbox/sbox.go
+++ b/cmd/sbox/sbox.go
@@ -22,7 +22,6 @@
 	"flag"
 	"fmt"
 	"io"
-	"io/fs"
 	"io/ioutil"
 	"os"
 	"os/exec"
@@ -479,8 +478,7 @@
 // copyOneFile copies a file and its permissions.  If forceExecutable is true it adds u+x to the
 // permissions.  If exists is allowFromNotExists it returns nil if the from path doesn't exist.
 // If write is onlyWriteIfChanged then the output file is compared to the input file and not written to
-// if it is the same, avoiding updating the timestamp. If from is a symlink, the symlink itself
-// will be copied, instead of what it points to.
+// if it is the same, avoiding updating the timestamp.
 func copyOneFile(from string, to string, forceExecutable bool, exists existsType,
 	write writeType) error {
 	err := os.MkdirAll(filepath.Dir(to), 0777)
@@ -488,7 +486,7 @@
 		return err
 	}
 
-	stat, err := os.Lstat(from)
+	stat, err := os.Stat(from)
 	if err != nil {
 		if os.IsNotExist(err) && exists == allowFromNotExists {
 			return nil
@@ -496,25 +494,6 @@
 		return err
 	}
 
-	if stat.Mode()&fs.ModeSymlink != 0 {
-		linkTarget, err := os.Readlink(from)
-		if err != nil {
-			return err
-		}
-		if write == onlyWriteIfChanged {
-			toLinkTarget, err := os.Readlink(to)
-			if err == nil && toLinkTarget == linkTarget {
-				return nil
-			}
-		}
-		err = os.Remove(to)
-		if err != nil && !os.IsNotExist(err) {
-			return err
-		}
-
-		return os.Symlink(linkTarget, to)
-	}
-
 	perm := stat.Mode()
 	if forceExecutable {
 		perm = perm | 0100 // u+x
diff --git a/java/androidmk.go b/java/androidmk.go
index a3f94cd..809f9b5 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -19,6 +19,7 @@
 	"io"
 	"strings"
 
+	"android/soong/aconfig"
 	"android/soong/android"
 
 	"github.com/google/blueprint/proptools"
@@ -128,9 +129,7 @@
 					if library.dexpreopter.configPath != nil {
 						entries.SetPath("LOCAL_SOONG_DEXPREOPT_CONFIG", library.dexpreopter.configPath)
 					}
-					// TODO(b/311155208): The container here should be system.
-
-					entries.SetPaths("LOCAL_ACONFIG_FILES", library.mergedAconfigFiles[""])
+					aconfig.SetAconfigFileMkEntries(&library.ModuleBase, entries, library.mergedAconfigFiles)
 				},
 			},
 		})
@@ -307,8 +306,7 @@
 					if len(binary.dexpreopter.builtInstalled) > 0 {
 						entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", binary.dexpreopter.builtInstalled)
 					}
-					// TODO(b/311155208): The container here should be system.
-					entries.SetPaths("LOCAL_ACONFIG_FILES", binary.mergedAconfigFiles[""])
+					aconfig.SetAconfigFileMkEntries(&binary.ModuleBase, entries, binary.mergedAconfigFiles)
 				},
 			},
 			ExtraFooters: []android.AndroidMkExtraFootersFunc{
@@ -461,8 +459,7 @@
 				entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", app.linter.reports)
 
 				if app.Name() != "framework-res" {
-					// TODO(b/311155208): The container here should be system.
-					entries.SetPaths("LOCAL_ACONFIG_FILES", app.mergedAconfigFiles[""])
+					aconfig.SetAconfigFileMkEntries(&app.ModuleBase, entries, app.mergedAconfigFiles)
 				}
 			},
 		},
@@ -540,8 +537,7 @@
 		entries.SetPath("LOCAL_FULL_MANIFEST_FILE", a.mergedManifestFile)
 		entries.SetPath("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", a.combinedExportedProguardFlagsFile)
 		entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", true)
-		// TODO(b/311155208): The container here should be system.
-		entries.SetPaths("LOCAL_ACONFIG_FILES", a.mergedAconfigFiles[""])
+		aconfig.SetAconfigFileMkEntries(&a.ModuleBase, entries, a.mergedAconfigFiles)
 	})
 
 	return entriesList
diff --git a/java/app.go b/java/app.go
index d5c4eba..ee82a32 100755
--- a/java/app.go
+++ b/java/app.go
@@ -139,12 +139,6 @@
 	// PRODUCT_CHARACTERISTICS.
 	Generate_product_characteristics_rro *bool
 
-	// A list of files or dependencies to make available to the build sandbox. This is
-	// useful if source files are symlinks, the targets of the symlinks must be listed here.
-	// Note that currently not all actions implemented by android_apps are sandboxed, so you
-	// may only see this being necessary in lint builds.
-	Compile_data []string
-
 	ProductCharacteristicsRROPackageName        *string `blueprint:"mutated"`
 	ProductCharacteristicsRROManifestModuleName *string `blueprint:"mutated"`
 }
@@ -824,7 +818,6 @@
 	a.linter.mergedManifest = a.aapt.mergedManifestFile
 	a.linter.manifest = a.aapt.manifestPath
 	a.linter.resources = a.aapt.resourceFiles
-	a.linter.compile_data = android.PathsForModuleSrc(ctx, a.appProperties.Compile_data)
 	a.linter.buildModuleReportZip = ctx.Config().UnbundledBuildApps()
 
 	dexJarFile, packageResources := a.dexBuildActions(ctx)
diff --git a/java/base.go b/java/base.go
index cdb58a2..7cd2820 100644
--- a/java/base.go
+++ b/java/base.go
@@ -195,6 +195,12 @@
 
 	// If true, then only the headers are built and not the implementation jar.
 	Headers_only *bool
+
+	// A list of files or dependencies to make available to the build sandbox. This is
+	// useful if source files are symlinks, the targets of the symlinks must be listed here.
+	// Note that currently not all actions implemented by android_apps are sandboxed, so you
+	// may only see this being necessary in lint builds.
+	Compile_data []string `android:"path"`
 }
 
 // Properties that are specific to device modules. Host module factories should not add these when
@@ -1677,6 +1683,7 @@
 		j.linter.compileSdkKind = j.SdkVersion(ctx).Kind
 		j.linter.javaLanguageLevel = flags.javaVersion.String()
 		j.linter.kotlinLanguageLevel = "1.3"
+		j.linter.compile_data = android.PathsForModuleSrc(ctx, j.properties.Compile_data)
 		if !apexInfo.IsForPlatform() && ctx.Config().UnbundledBuildApps() {
 			j.linter.buildModuleReportZip = true
 		}
diff --git a/rust/androidmk.go b/rust/androidmk.go
index 733ffc5..c355a56 100644
--- a/rust/androidmk.go
+++ b/rust/androidmk.go
@@ -17,6 +17,7 @@
 import (
 	"path/filepath"
 
+	"android/soong/aconfig"
 	"android/soong/android"
 )
 
@@ -66,8 +67,7 @@
 				if mod.UseVndk() {
 					entries.SetBool("LOCAL_USE_VNDK", true)
 				}
-				// TODO(b/311155208): The container here should be system.
-				entries.SetPaths("LOCAL_ACONFIG_FILES", mod.mergedAconfigFiles[""])
+				aconfig.SetAconfigFileMkEntries(mod.AndroidModuleBase(), entries, mod.mergedAconfigFiles)
 			},
 		},
 	}
diff --git a/tradefed/suite_harness/tradefed_binary.go b/tradefed/suite_harness/tradefed_binary.go
index 1ce94bc..96fb354 100644
--- a/tradefed/suite_harness/tradefed_binary.go
+++ b/tradefed/suite_harness/tradefed_binary.go
@@ -35,6 +35,7 @@
 	Short_name                    string
 	Full_name                     string
 	Version                       string
+	Suite_arch                    string
 	Prepend_platform_version_name bool
 }
 
@@ -67,6 +68,7 @@
 				Name:       &genName,
 				Short_name: tfb.Short_name,
 				Full_name:  tfb.Full_name,
+				Suite_arch: tfb.Suite_arch,
 				Version:    version,
 			})
 
@@ -95,6 +97,7 @@
 	Short_name string
 	Full_name  string
 	Version    string
+	Suite_arch string
 }
 
 type tradefedBinaryGen struct {
@@ -127,13 +130,19 @@
 func (tfg *tradefedBinaryGen) GenerateAndroidBuildActions(ctx android.ModuleContext) {
 	buildNumberFile := ctx.Config().BuildNumberFile(ctx)
 	outputFile := android.PathForModuleOut(ctx, "test-suite-info.properties")
+
+	arch := strings.ReplaceAll(tfg.properties.Suite_arch, " ", "")
+	if arch == "" {
+		arch = ctx.Config().DevicePrimaryArchType().String()
+	}
+
 	ctx.Build(pctx, android.BuildParams{
 		Rule:      tradefedBinaryGenRule,
 		Output:    outputFile,
 		OrderOnly: android.Paths{buildNumberFile},
 		Args: map[string]string{
 			"buildNumberFile": buildNumberFile.String(),
-			"arch":            ctx.Config().DevicePrimaryArchType().String(),
+			"arch":            arch,
 			"name":            tfg.properties.Short_name,
 			"fullname":        tfg.properties.Full_name,
 			"version":         tfg.properties.Version,