diff --git a/android/paths.go b/android/paths.go index b192a357a..128ec12d0 100644 --- a/android/paths.go +++ b/android/paths.go @@ -1591,6 +1591,18 @@ func (p InstallPath) ToMakePath() InstallPath { // PathForModuleInstall returns a Path representing the install path for the // module appended with paths... func PathForModuleInstall(ctx ModuleInstallPathContext, pathComponents ...string) InstallPath { + os, arch := osAndArch(ctx) + partition := modulePartition(ctx, os) + return makePathForInstall(ctx, os, arch, partition, ctx.Debug(), pathComponents...) +} + +// PathForModuleInPartitionInstall is similar to PathForModuleInstall but partition is provided by the caller +func PathForModuleInPartitionInstall(ctx ModuleInstallPathContext, partition string, pathComponents ...string) InstallPath { + os, arch := osAndArch(ctx) + return makePathForInstall(ctx, os, arch, partition, ctx.Debug(), pathComponents...) +} + +func osAndArch(ctx ModuleInstallPathContext) (OsType, ArchType) { os := ctx.Os() arch := ctx.Arch().ArchType forceOS, forceArch := ctx.InstallForceOS() @@ -1600,14 +1612,14 @@ func PathForModuleInstall(ctx ModuleInstallPathContext, pathComponents ...string if forceArch != nil { arch = *forceArch } - partition := modulePartition(ctx, os) - - ret := pathForInstall(ctx, os, arch, partition, ctx.Debug(), pathComponents...) + return os, arch +} +func makePathForInstall(ctx ModuleInstallPathContext, os OsType, arch ArchType, partition string, debug bool, pathComponents ...string) InstallPath { + ret := pathForInstall(ctx, os, arch, partition, debug, pathComponents...) if ctx.InstallBypassMake() && ctx.Config().KatiEnabled() { ret = ret.ToMakePath() } - return ret } diff --git a/java/rro.go b/java/rro.go index 2e58c042f..0b4d0916a 100644 --- a/java/rro.go +++ b/java/rro.go @@ -90,6 +90,22 @@ type RuntimeResourceOverlayModule interface { Theme() string } +// RRO's partition logic is different from the partition logic of other modules defined in soong/android/paths.go +// The default partition for RRO is "/product" and not "/system" +func rroPartition(ctx android.ModuleContext) string { + var partition string + if ctx.DeviceSpecific() { + partition = ctx.DeviceConfig().OdmPath() + } else if ctx.SocSpecific() { + partition = ctx.DeviceConfig().VendorPath() + } else if ctx.SystemExtSpecific() { + partition = ctx.DeviceConfig().SystemExtPath() + } else { + partition = ctx.DeviceConfig().ProductPath() + } + return partition +} + func (r *RuntimeResourceOverlay) DepsMutator(ctx android.BottomUpMutatorContext) { sdkDep := decodeSdkDep(ctx, android.SdkContext(r)) if sdkDep.hasFrameworkLibs() { @@ -137,7 +153,8 @@ func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleC r.certificate = certificates[0] r.outputFile = signed - r.installDir = android.PathForModuleInstall(ctx, "overlay", String(r.properties.Theme)) + partition := rroPartition(ctx) + r.installDir = android.PathForModuleInPartitionInstall(ctx, partition, "overlay", String(r.properties.Theme)) ctx.InstallFile(r.installDir, r.outputFile.Base(), r.outputFile) } diff --git a/java/rro_test.go b/java/rro_test.go index bad60bc16..27abbe4f3 100644 --- a/java/rro_test.go +++ b/java/rro_test.go @@ -177,7 +177,7 @@ func TestRuntimeResourceOverlay_JavaDefaults(t *testing.T) { // Check device location. path = android.AndroidMkEntriesForTest(t, ctx, m.Module())[0].EntryMap["LOCAL_MODULE_PATH"] - expectedPath = []string{shared.JoinPath("out/target/product/test_device/system/overlay")} + expectedPath = []string{shared.JoinPath("out/target/product/test_device/product/overlay")} android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_MODULE_PATH", config, expectedPath, path) } @@ -343,3 +343,57 @@ func TestEnforceRRO_propagatesToDependencies(t *testing.T) { }) } } + +func TestRuntimeResourceOverlayPartition(t *testing.T) { + bp := ` + runtime_resource_overlay { + name: "device_specific", + device_specific: true, + } + runtime_resource_overlay { + name: "soc_specific", + soc_specific: true, + } + runtime_resource_overlay { + name: "system_ext_specific", + system_ext_specific: true, + } + runtime_resource_overlay { + name: "product_specific", + product_specific: true, + } + runtime_resource_overlay { + name: "default" + } + ` + testCases := []struct { + name string + expectedPath string + }{ + { + name: "device_specific", + expectedPath: "out/soong/target/product/test_device/odm/overlay", + }, + { + name: "soc_specific", + expectedPath: "out/soong/target/product/test_device/vendor/overlay", + }, + { + name: "system_ext_specific", + expectedPath: "out/soong/target/product/test_device/system_ext/overlay", + }, + { + name: "product_specific", + expectedPath: "out/soong/target/product/test_device/product/overlay", + }, + { + name: "default", + expectedPath: "out/soong/target/product/test_device/product/overlay", + }, + } + for _, testCase := range testCases { + ctx, _ := testJava(t, bp) + mod := ctx.ModuleForTests(testCase.name, "android_common").Module().(*RuntimeResourceOverlay) + android.AssertPathRelativeToTopEquals(t, "Install dir is not correct for "+testCase.name, testCase.expectedPath, mod.installDir) + } +}