Merge "Introduce Soong API CreateModuleInDirectory(...)" into main
diff --git a/android/path_properties.go b/android/path_properties.go
index 8ada133..b4fabeb 100644
--- a/android/path_properties.go
+++ b/android/path_properties.go
@@ -51,11 +51,13 @@
 	// tagged with `android:"path"` or one of the variant-specifying tags.
 	var pathProperties []string
 	var pathDeviceFirstProperties []string
+	var pathDeviceFirstPrefer32Properties []string
 	var pathDeviceCommonProperties []string
 	var pathCommonOsProperties []string
 	for _, ps := range props {
 		pathProperties = append(pathProperties, taggedPropertiesForPropertyStruct(ctx, ps, "path")...)
 		pathDeviceFirstProperties = append(pathDeviceFirstProperties, taggedPropertiesForPropertyStruct(ctx, ps, "path_device_first")...)
+		pathDeviceFirstPrefer32Properties = append(pathDeviceFirstPrefer32Properties, taggedPropertiesForPropertyStruct(ctx, ps, "path_device_first_prefer32")...)
 		pathDeviceCommonProperties = append(pathDeviceCommonProperties, taggedPropertiesForPropertyStruct(ctx, ps, "path_device_common")...)
 		pathCommonOsProperties = append(pathCommonOsProperties, taggedPropertiesForPropertyStruct(ctx, ps, "path_common_os")...)
 	}
@@ -63,6 +65,7 @@
 	// Remove duplicates to avoid multiple dependencies.
 	pathProperties = FirstUniqueStrings(pathProperties)
 	pathDeviceFirstProperties = FirstUniqueStrings(pathDeviceFirstProperties)
+	pathDeviceFirstPrefer32Properties = FirstUniqueStrings(pathDeviceFirstPrefer32Properties)
 	pathDeviceCommonProperties = FirstUniqueStrings(pathDeviceCommonProperties)
 	pathCommonOsProperties = FirstUniqueStrings(pathCommonOsProperties)
 
@@ -80,13 +83,27 @@
 			ctx.AddVariationDependencies(ctx.Config().AndroidFirstDeviceTarget.Variations(), sourceOrOutputDepTag(m, t), m)
 		}
 	}
+	// properties tagged path_device_first_prefer32 get the first 32 bit target if one is available,
+	// otherwise they use the first 64 bit target
+	if len(pathDeviceFirstPrefer32Properties) > 0 {
+		firstPrefer32Target := FirstTarget(ctx.Config().Targets[Android], "lib32", "lib64")
+		if len(firstPrefer32Target) == 0 {
+			ctx.ModuleErrorf("Could not find a first_prefer32 target")
+		} else {
+			for _, s := range pathDeviceFirstPrefer32Properties {
+				if m, t := SrcIsModuleWithTag(s); m != "" {
+					ctx.AddVariationDependencies(firstPrefer32Target[0].Variations(), sourceOrOutputDepTag(m, t), m)
+				}
+			}
+		}
+	}
 	// properties tagged "path_device_common" get the device common variant
 	for _, s := range pathDeviceCommonProperties {
 		if m, t := SrcIsModuleWithTag(s); m != "" {
 			ctx.AddVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), sourceOrOutputDepTag(m, t), m)
 		}
 	}
-	// properties tagged "path_device_common" get the device common variant
+	// properties tagged "path_common_os" get the CommonOs variant
 	for _, s := range pathCommonOsProperties {
 		if m, t := SrcIsModuleWithTag(s); m != "" {
 			ctx.AddVariationDependencies([]blueprint.Variation{
diff --git a/android/variable.go b/android/variable.go
index 13d5f05..34a3d30 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -591,6 +591,8 @@
 
 	ProductPackages      []string `json:",omitempty"`
 	ProductPackagesDebug []string `json:",omitempty"`
+
+	ProductCopyFiles map[string]string `json:",omitempty"`
 }
 
 func boolPtr(v bool) *bool {
diff --git a/cc/fuzz.go b/cc/fuzz.go
index cbe139f..8a974c0 100644
--- a/cc/fuzz.go
+++ b/cc/fuzz.go
@@ -182,13 +182,9 @@
 }
 
 func (fuzz *fuzzBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags {
-	var subdir string
-	if ctx.isForPlatform() {
-		subdir = "lib"
-	} else if ctx.inVendor() {
+	subdir := "lib"
+	if ctx.inVendor() {
 		subdir = "lib/vendor"
-	} else {
-		ctx.ModuleErrorf("Fuzzer must be system or vendor variant")
 	}
 
 	flags = fuzz.binaryDecorator.linkerFlags(ctx, flags)
diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go
index 59712c0..f17a5de 100644
--- a/etc/prebuilt_etc.go
+++ b/etc/prebuilt_etc.go
@@ -65,6 +65,7 @@
 	ctx.RegisterModuleType("prebuilt_dsp", PrebuiltDSPFactory)
 	ctx.RegisterModuleType("prebuilt_rfsa", PrebuiltRFSAFactory)
 	ctx.RegisterModuleType("prebuilt_renderscript_bitcode", PrebuiltRenderScriptBitcodeFactory)
+	ctx.RegisterModuleType("prebuilt_media_audio", PrebuiltMediaAudioFactory)
 
 	ctx.RegisterModuleType("prebuilt_defaults", defaultsFactory)
 
@@ -788,3 +789,13 @@
 	android.InitDefaultableModule(module)
 	return module
 }
+
+// prebuilt_media_audio installs audio files in <partition>/media/audio directory.
+func PrebuiltMediaAudioFactory() android.Module {
+	module := &PrebuiltEtc{}
+	InitPrebuiltEtcModule(module, "media/audio")
+	// This module is device-only
+	android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
+	android.InitDefaultableModule(module)
+	return module
+}
diff --git a/etc/prebuilt_etc_test.go b/etc/prebuilt_etc_test.go
index 75c6d12..676a096 100644
--- a/etc/prebuilt_etc_test.go
+++ b/etc/prebuilt_etc_test.go
@@ -588,3 +588,18 @@
 		})
 	}
 }
+
+func TestPrebuiltMediaAutoDirPath(t *testing.T) {
+	result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
+		prebuilt_media_audio {
+			name: "foo",
+			src: "Alarm_Beep_01.ogg",
+			product_specific: true,
+			relative_install_path: "alarms"
+		}
+	`)
+
+	p := result.Module("foo", "android_common").(*PrebuiltEtc)
+	expected := "out/soong/target/product/test_device/product/media/audio/alarms"
+	android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPaths[0])
+}
diff --git a/fsgen/filesystem_creator.go b/fsgen/filesystem_creator.go
index 75d2caa..c903338 100644
--- a/fsgen/filesystem_creator.go
+++ b/fsgen/filesystem_creator.go
@@ -130,7 +130,10 @@
 					"public.libraries.android.txt": defaultDepCandidateProps(ctx.Config()),
 					"update_engine_sideload":       defaultDepCandidateProps(ctx.Config()),
 				},
-				"vendor":  newMultilibDeps(),
+				"vendor": &map[string]*depCandidateProps{
+					"fs_config_files_vendor": defaultDepCandidateProps(ctx.Config()),
+					"fs_config_dirs_vendor":  defaultDepCandidateProps(ctx.Config()),
+				},
 				"odm":     newMultilibDeps(),
 				"product": newMultilibDeps(),
 				"system_ext": &map[string]*depCandidateProps{
diff --git a/java/app.go b/java/app.go
index 56fcfbb..addbc28 100644
--- a/java/app.go
+++ b/java/app.go
@@ -1442,6 +1442,7 @@
 	a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data)
 	a.data = append(a.data, android.PathsForModuleSrc(ctx, a.testProperties.Device_common_data)...)
 	a.data = append(a.data, android.PathsForModuleSrc(ctx, a.testProperties.Device_first_data)...)
+	a.data = append(a.data, android.PathsForModuleSrc(ctx, a.testProperties.Device_first_prefer32_data)...)
 	android.SetProvider(ctx, testing.TestModuleProviderKey, testing.TestModuleProviderData{})
 	android.SetProvider(ctx, tradefed.BaseTestProviderKey, tradefed.BaseTestProviderData{
 		InstalledFiles:          a.data,
diff --git a/java/java.go b/java/java.go
index 5bb3636..6797148 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1301,6 +1301,12 @@
 	// host test.
 	Device_first_data []string `android:"path_device_first"`
 
+	// same as data, but adds dependencies using the device's os variation and the device's first
+	// 32-bit architecture's variation. If a 32-bit arch doesn't exist for this device, it will use
+	// a 64 bit arch instead. Can be used to add a module built for device to the data of a
+	// host test.
+	Device_first_prefer32_data []string `android:"path_device_first_prefer32"`
+
 	// Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
 	// doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
 	// explicitly.
@@ -1593,6 +1599,7 @@
 	j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data)
 	j.data = append(j.data, android.PathsForModuleSrc(ctx, j.testProperties.Device_common_data)...)
 	j.data = append(j.data, android.PathsForModuleSrc(ctx, j.testProperties.Device_first_data)...)
+	j.data = append(j.data, android.PathsForModuleSrc(ctx, j.testProperties.Device_first_prefer32_data)...)
 
 	j.extraTestConfigs = android.PathsForModuleSrc(ctx, j.testProperties.Test_options.Extra_test_configs)
 
diff --git a/java/robolectric.go b/java/robolectric.go
index fb820ef..e6f80ac 100644
--- a/java/robolectric.go
+++ b/java/robolectric.go
@@ -151,6 +151,7 @@
 	r.data = android.PathsForModuleSrc(ctx, r.testProperties.Data)
 	r.data = append(r.data, android.PathsForModuleSrc(ctx, r.testProperties.Device_common_data)...)
 	r.data = append(r.data, android.PathsForModuleSrc(ctx, r.testProperties.Device_first_data)...)
+	r.data = append(r.data, android.PathsForModuleSrc(ctx, r.testProperties.Device_first_prefer32_data)...)
 
 	var ok bool
 	var instrumentedApp *AndroidApp