Merge "Add CPU and RAM information to metrics" into main
diff --git a/Android.bp b/Android.bp
index d0f97db..cbe1c7b 100644
--- a/Android.bp
+++ b/Android.bp
@@ -164,6 +164,7 @@
     name: "product_config",
     visibility: [
         "//build/make/target/product/generic",
+        "//build/soong/fsgen",
     ],
 }
 
diff --git a/android/build_prop.go b/android/build_prop.go
index ede93ed..7c3c506 100644
--- a/android/build_prop.go
+++ b/android/build_prop.go
@@ -20,7 +20,7 @@
 
 func init() {
 	ctx := InitRegistrationContext
-	ctx.RegisterModuleType("build_prop", buildPropFactory)
+	ctx.RegisterModuleType("build_prop", BuildPropFactory)
 }
 
 type buildPropProperties struct {
@@ -65,6 +65,9 @@
 		return ctx.Config().ProductPropFiles(ctx)
 	} else if partition == "odm" {
 		return ctx.Config().OdmPropFiles(ctx)
+	} else if partition == "vendor" {
+		// TODO (b/375500423): Add android-info.txt to prop files
+		return ctx.Config().VendorPropFiles(ctx)
 	}
 	return nil
 }
@@ -104,6 +107,7 @@
 	"system_ext",
 	"product",
 	"odm",
+	"vendor",
 }
 
 func (p *buildPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
@@ -187,7 +191,7 @@
 // build_prop module generates {partition}/build.prop file. At first common build properties are
 // printed based on Soong config variables. And then prop_files are printed as-is. Finally,
 // post_process_props tool is run to check if the result build.prop is valid or not.
-func buildPropFactory() Module {
+func BuildPropFactory() Module {
 	module := &buildPropModule{}
 	module.AddProperties(&module.properties)
 	InitAndroidArchModule(module, DeviceSupported, MultilibCommon)
diff --git a/android/config.go b/android/config.go
index b3480d9..2fc6111 100644
--- a/android/config.go
+++ b/android/config.go
@@ -2206,6 +2206,10 @@
 	return PathsForSource(ctx, c.productVariables.OdmPropFiles)
 }
 
+func (c *config) VendorPropFiles(ctx PathContext) Paths {
+	return PathsForSource(ctx, c.productVariables.VendorPropFiles)
+}
+
 func (c *config) ExtraAllowedDepsTxt() string {
 	return String(c.productVariables.ExtraAllowedDepsTxt)
 }
diff --git a/android/image.go b/android/image.go
index 012267a..e8b6352 100644
--- a/android/image.go
+++ b/android/image.go
@@ -98,16 +98,47 @@
 	DebugRamdiskVariation string = "debug_ramdisk"
 )
 
+type imageInterfaceContextAdapter struct {
+	IncomingTransitionContext
+	kind moduleKind
+}
+
+var _ ImageInterfaceContext = (*imageInterfaceContextAdapter)(nil)
+
+func (e *imageInterfaceContextAdapter) Platform() bool {
+	return e.kind == platformModule
+}
+
+func (e *imageInterfaceContextAdapter) DeviceSpecific() bool {
+	return e.kind == deviceSpecificModule
+}
+
+func (e *imageInterfaceContextAdapter) SocSpecific() bool {
+	return e.kind == socSpecificModule
+}
+
+func (e *imageInterfaceContextAdapter) ProductSpecific() bool {
+	return e.kind == productSpecificModule
+}
+
+func (e *imageInterfaceContextAdapter) SystemExtSpecific() bool {
+	return e.kind == systemExtSpecificModule
+}
+
+func imageMutatorBeginMutator(ctx BottomUpMutatorContext) {
+	if m, ok := ctx.Module().(ImageInterface); ok && ctx.Os() == Android {
+		m.ImageMutatorBegin(ctx)
+	}
+}
+
 // imageTransitionMutator creates variants for modules that implement the ImageInterface that
 // allow them to build differently for each partition (recovery, core, vendor, etc.).
 type imageTransitionMutator struct{}
 
-func (imageTransitionMutator) Split(ctx BaseModuleContext) []string {
+func getImageVariations(ctx ImageInterfaceContext) []string {
 	var variations []string
 
 	if m, ok := ctx.Module().(ImageInterface); ctx.Os() == Android && ok {
-		m.ImageMutatorBegin(ctx)
-
 		if m.CoreVariantNeeded(ctx) {
 			variations = append(variations, CoreVariation)
 		}
@@ -141,6 +172,10 @@
 	return variations
 }
 
+func (imageTransitionMutator) Split(ctx BaseModuleContext) []string {
+	return getImageVariations(ctx)
+}
+
 func (imageTransitionMutator) OutgoingTransition(ctx OutgoingTransitionContext, sourceVariation string) string {
 	return sourceVariation
 }
@@ -149,6 +184,16 @@
 	if _, ok := ctx.Module().(ImageInterface); ctx.Os() != Android || !ok {
 		return CoreVariation
 	}
+	variations := getImageVariations(&imageInterfaceContextAdapter{
+		IncomingTransitionContext: ctx,
+		kind:                      determineModuleKind(ctx.Module().base(), ctx),
+	})
+	// If there's only 1 possible variation, use that. This is a holdover from when blueprint,
+	// when adding dependencies, would use the only variant of a module regardless of its variations
+	// if only 1 variant existed.
+	if len(variations) == 1 {
+		return variations[0]
+	}
 	return incomingVariation
 }
 
diff --git a/android/module.go b/android/module.go
index bc7f5e6..6ef5c6a 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1667,7 +1667,7 @@
 	}
 }
 
-func determineModuleKind(m *ModuleBase, ctx blueprint.EarlyModuleContext) moduleKind {
+func determineModuleKind(m *ModuleBase, ctx ModuleErrorContext) moduleKind {
 	var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
 	var deviceSpecific = Bool(m.commonProperties.Device_specific)
 	var productSpecific = Bool(m.commonProperties.Product_specific)
diff --git a/android/mutator.go b/android/mutator.go
index b736796..4ddc606 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -151,6 +151,7 @@
 
 func registerArchMutator(ctx RegisterMutatorsContext) {
 	ctx.Transition("os", &osTransitionMutator{})
+	ctx.BottomUp("image_begin", imageMutatorBeginMutator)
 	ctx.Transition("image", &imageTransitionMutator{})
 	ctx.Transition("arch", &archTransitionMutator{})
 }
diff --git a/android/variable.go b/android/variable.go
index c352942..6693d91 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -521,6 +521,7 @@
 	SystemExtPropFiles []string `json:",omitempty"`
 	ProductPropFiles   []string `json:",omitempty"`
 	OdmPropFiles       []string `json:",omitempty"`
+	VendorPropFiles    []string `json:",omitempty"`
 
 	EnableUffdGc *string `json:",omitempty"`
 
diff --git a/fsgen/filesystem_creator.go b/fsgen/filesystem_creator.go
index 39572d4..766176d 100644
--- a/fsgen/filesystem_creator.go
+++ b/fsgen/filesystem_creator.go
@@ -139,8 +139,9 @@
 					"update_engine_sideload":       defaultDepCandidateProps(ctx.Config()),
 				},
 				"vendor": &map[string]*depCandidateProps{
-					"fs_config_files_vendor": defaultDepCandidateProps(ctx.Config()),
-					"fs_config_dirs_vendor":  defaultDepCandidateProps(ctx.Config()),
+					"fs_config_files_vendor":                               defaultDepCandidateProps(ctx.Config()),
+					"fs_config_dirs_vendor":                                defaultDepCandidateProps(ctx.Config()),
+					generatedModuleName(ctx.Config(), "vendor-build.prop"): defaultDepCandidateProps(ctx.Config()),
 				},
 				"odm":     newMultilibDeps(),
 				"product": newMultilibDeps(),
@@ -481,6 +482,25 @@
 		module = ctx.CreateModule(filesystem.FilesystemFactory, baseProps, fsProps)
 	}
 	module.HideFromMake()
+	if partitionType == "vendor" {
+		// Create a build prop for vendor
+		vendorBuildProps := &struct {
+			Name           *string
+			Vendor         *bool
+			Stem           *string
+			Product_config *string
+		}{
+			Name:           proptools.StringPtr(generatedModuleName(ctx.Config(), "vendor-build.prop")),
+			Vendor:         proptools.BoolPtr(true),
+			Stem:           proptools.StringPtr("build.prop"),
+			Product_config: proptools.StringPtr(":product_config"),
+		}
+		vendorBuildProp := ctx.CreateModule(
+			android.BuildPropFactory,
+			vendorBuildProps,
+		)
+		vendorBuildProp.HideFromMake()
+	}
 	return true
 }
 
diff --git a/java/java.go b/java/java.go
index 4460053..85024e1 100644
--- a/java/java.go
+++ b/java/java.go
@@ -3277,6 +3277,7 @@
 		&JavaApiLibraryProperties{},
 		&bootclasspathFragmentProperties{},
 		&SourceOnlyBootclasspathProperties{},
+		&ravenwoodTestProperties{},
 	)
 
 	android.InitDefaultsModule(module)
diff --git a/java/ravenwood_test.go b/java/ravenwood_test.go
index 753a118..5d62ede 100644
--- a/java/ravenwood_test.go
+++ b/java/ravenwood_test.go
@@ -162,12 +162,16 @@
 			srcs: ["jni.cpp"],
 			stem: "libpink",
 		}
+		java_defaults {
+			name: "ravenwood-test-defaults",
+			jni_libs: ["jni-lib2"],
+		}
 		android_ravenwood_test {
 			name: "ravenwood-test",
 			srcs: ["Test.java"],
+			defaults: ["ravenwood-test-defaults"],
 			jni_libs: [
 				"jni-lib1",
-				"jni-lib2",
 				"ravenwood-runtime-jni2",
 			],
 			resource_apk: "app2",
diff --git a/scripts/gen_build_prop.py b/scripts/gen_build_prop.py
index df9e98d..e0686ed 100644
--- a/scripts/gen_build_prop.py
+++ b/scripts/gen_build_prop.py
@@ -524,7 +524,6 @@
 
   build_prop(args, gen_build_info=False, gen_common_build_props=True, variables=variables)
 
-'''
 def build_vendor_prop(args):
   config = args.config
 
@@ -541,7 +540,6 @@
     ]
 
   build_prop(args, gen_build_info=False, gen_common_build_props=True, variables=variables)
-'''
 
 def build_product_prop(args):
   config = args.config
@@ -608,8 +606,8 @@
         build_odm_prop(args)
       case "product":
         build_product_prop(args)
-      # case "vendor":  # NOT IMPLEMENTED
-      #  build_vendor_prop(args)
+      case "vendor":
+        build_vendor_prop(args)
       case _:
         sys.exit(f"not supported partition {args.partition}")