Use soong built autogenerated RROs
At ToT, soong emits metadata to make (LOCAL_SOONG_PRODUCT_RRO_DIRS and
LOCAL_SOONG_DEVICE_RRO_DIRS), and make uses this metadata to build and
install apks that are intalled in /vendor or /product. This CL ports
this logic to soong.
This CL autogenerates these modules in a load hook for android_app and
override_android_app, and adds them to the `LOCAL_REQUIRED_MODULES` of
the base app. The autogenerated modules will inherit the enabled
property of the apps. This required me to add `Target.Android.Enabled`
to commonProperties in ModuleBase.
Since autogeneration happens in soong now,
`LOCAL_SOONG_(DEVICE|PRODUCT)_RRO_DIRS` no longer needs to be exported.
Followup work
- Installing the overlay variants for soong built filesystems.
Test: lunch aosp_cf_x86_64_phone-trunk_staging-userdebug
Test: no diff in system, vendor, product file_list.txt
Test: m out/target/product/vsoc_x86_64/vendor/overlay/SystemUI__aosp_cf_x86_64_phone__auto_generated_rro_vendor.apk
the apk is not bit-identical, but this is likely due to different
aapt link flags between make and soong (e.g. `--enable-compact-entries`
is added as default in soong but not in make
Test: aapt2 diff
SystemUI__aosp_cf_x86_64_phone__auto_generated_rro_vendor.apk.before
SystemUI__aosp_cf_x86_64_phone__auto_generated_rro_vendor.apk.after
reports no diffs
Change-Id: I9b212a4ed443250a63dbe27cb955c6f133cff9af
diff --git a/java/app.go b/java/app.go
index 34a548e..34884d7 100644
--- a/java/app.go
+++ b/java/app.go
@@ -223,6 +223,8 @@
javaApiUsedByOutputFile android.ModuleOutPath
privAppAllowlist android.OptionalPath
+
+ requiredModuleNames []string
}
func (a *AndroidApp) IsInstallable() bool {
@@ -421,6 +423,24 @@
TestHelperApp: false,
EmbeddedJNILibs: embeddedJniLibs,
})
+
+ a.requiredModuleNames = a.getRequiredModuleNames(ctx)
+}
+
+func (a *AndroidApp) getRequiredModuleNames(ctx android.ModuleContext) []string {
+ var required []string
+ if proptools.Bool(a.appProperties.Generate_product_characteristics_rro) {
+ required = []string{a.productCharacteristicsRROPackageName()}
+ }
+ // Install the vendor overlay variant if this app is installed.
+ if len(filterRRO(a.rroDirsDepSet, device)) > 0 {
+ required = append(required, AutogeneratedRroModuleName(ctx, ctx.Module().Name(), "vendor"))
+ }
+ // Install the product overlay variant if this app is installed.
+ if len(filterRRO(a.rroDirsDepSet, product)) > 0 {
+ required = append(required, AutogeneratedRroModuleName(ctx, ctx.Module().Name(), "product"))
+ }
+ return required
}
func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) {
@@ -1377,6 +1397,11 @@
}
}
ctx.CreateModule(RuntimeResourceOverlayFactory, &rroProperties)
+
+ })
+
+ module.SetDefaultableHook(func(ctx android.DefaultableHookContext) {
+ createInternalRuntimeOverlays(ctx, module.ModuleBase)
})
return module
@@ -1386,6 +1411,68 @@
return fmt.Sprintf("%s__%s__auto_generated_rro_%s", moduleName, ctx.Config().DeviceProduct(), partition)
}
+type createModuleContext interface {
+ android.EarlyModuleContext
+ CreateModule(android.ModuleFactory, ...interface{}) android.Module
+}
+
+func createInternalRuntimeOverlays(ctx createModuleContext, a android.ModuleBase) {
+ if !ctx.Config().HasDeviceProduct() {
+ return
+ }
+ // vendor
+ vendorOverlayProps := struct {
+ Name *string
+ Base *string
+ Vendor *bool
+ Product_specific *bool
+ System_ext_specific *bool
+ Manifest *string
+ Sdk_version *string
+ Compile_multilib *string
+ Enabled proptools.Configurable[bool]
+ }{
+ Name: proptools.StringPtr(AutogeneratedRroModuleName(ctx, a.Name(), "vendor")),
+ Base: proptools.StringPtr(a.Name()),
+ Vendor: proptools.BoolPtr(true),
+ Product_specific: proptools.BoolPtr(false),
+ System_ext_specific: proptools.BoolPtr(false),
+ Manifest: proptools.StringPtr(":" + a.Name() + "{.manifest.xml}"),
+ Sdk_version: proptools.StringPtr("current"),
+ Compile_multilib: proptools.StringPtr("first"),
+ Enabled: a.EnabledProperty().Clone(),
+ }
+ ctx.CreateModule(AutogenRuntimeResourceOverlayFactory, &vendorOverlayProps)
+
+ // product
+ productOverlayProps := struct {
+ Name *string
+ Base *string
+ Vendor *bool
+ Proprietary *bool
+ Soc_specific *bool
+ Product_specific *bool
+ System_ext_specific *bool
+ Manifest *string
+ Sdk_version *string
+ Compile_multilib *string
+ Enabled proptools.Configurable[bool]
+ }{
+ Name: proptools.StringPtr(AutogeneratedRroModuleName(ctx, a.Name(), "product")),
+ Base: proptools.StringPtr(a.Name()),
+ Vendor: proptools.BoolPtr(false),
+ Proprietary: proptools.BoolPtr(false),
+ Soc_specific: proptools.BoolPtr(false),
+ Product_specific: proptools.BoolPtr(true),
+ System_ext_specific: proptools.BoolPtr(false),
+ Manifest: proptools.StringPtr(":" + a.Name() + "{.manifest.xml}"),
+ Sdk_version: proptools.StringPtr("current"),
+ Compile_multilib: proptools.StringPtr("first"),
+ Enabled: a.EnabledProperty().Clone(),
+ }
+ ctx.CreateModule(AutogenRuntimeResourceOverlayFactory, &productOverlayProps)
+}
+
// A dictionary of values to be overridden in the manifest.
type Manifest_values struct {
// Overrides the value of package_name in the manifest
@@ -1696,6 +1783,10 @@
android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
android.InitOverrideModule(m)
+ android.AddLoadHook(m, func(ctx android.LoadHookContext) {
+ createInternalRuntimeOverlays(ctx, m.ModuleBase)
+ })
+
return m
}