Generic configuration for generic system modules.

Config object includes a copy of itself for the generic configuration.
The generic configuration replaces any product-specific configurations
with the generic information.
When a module context gets Config() object, it returns the generic
configuration if the module sets use_generic_config to true. Otherwise,
Config() returns the original config object as before.

By adding `generic:"<value>"` annotation to the product variable, the
variables will be initialized with the <value> for the generic configs.
If the <value> is "unset", the variable will be unset.

The generic modules can be included in the shared system image to be
installed in multiple targets.

Bug: 361816274
Test: m nothing --no-skip-soong-tests
Change-Id: I15e4ade17ad1a8969f8e0e91d994b60545dc412f
diff --git a/android/early_module_context.go b/android/early_module_context.go
index 8d28285..300edf1 100644
--- a/android/early_module_context.go
+++ b/android/early_module_context.go
@@ -146,6 +146,13 @@
 }
 
 func (e *earlyModuleContext) Config() Config {
+	// Only the system image may use the generic config.
+	// If a module builds multiple image variations, provide the generic config only for the core
+	// variant which is installed in the system partition. Other image variant may still read the
+	// original configurations.
+	if e.Module().base().UseGenericConfig() && e.Module().base().commonProperties.ImageVariation == "" {
+		return e.EarlyModuleContext.Config().(Config).genericConfig()
+	}
 	return e.EarlyModuleContext.Config().(Config)
 }