Check if vintf_fragment modules' target partition

Current implementation allows vintf_fragment to be installed in the
different partition of a module referenced it via
vintf_fragment_modules, but this is unexpected behavior and should be
caught from the build system to avoid any unintended mistakes. This
change checks target parition of vintf_fragment module and any modules
referencing it, and fails if there is any mismatch found.

Bug: 322089980
Test: aosp_cf_x86_64_phone build succeeded
Change-Id: Ie8152d2f2616726e44a99fb1261be292f2b9ad54
diff --git a/android/module.go b/android/module.go
index 009b0df..b1ff56e 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1063,8 +1063,29 @@
 }{}
 
 func addVintfFragmentDeps(ctx BottomUpMutatorContext) {
+	// Vintf manifests in the recovery partition will be ignored.
+	if !ctx.Device() || ctx.Module().InstallInRecovery() {
+		return
+	}
+
+	deviceConfig := ctx.DeviceConfig()
+
 	mod := ctx.Module()
-	ctx.AddDependency(mod, vintfDepTag, mod.VintfFragmentModuleNames(ctx)...)
+	vintfModules := ctx.AddDependency(mod, vintfDepTag, mod.VintfFragmentModuleNames(ctx)...)
+
+	modPartition := mod.PartitionTag(deviceConfig)
+	for _, vintf := range vintfModules {
+		if vintfModule, ok := vintf.(*vintfFragmentModule); ok {
+			vintfPartition := vintfModule.PartitionTag(deviceConfig)
+			if modPartition != vintfPartition {
+				ctx.ModuleErrorf("Module %q(%q) and Vintf_fragment %q(%q) are installed to different partitions.",
+					mod.Name(), modPartition,
+					vintfModule.Name(), vintfPartition)
+			}
+		} else {
+			ctx.ModuleErrorf("Only vintf_fragment type module should be listed in vintf_fragment_modules : %q", vintf.Name())
+		}
+	}
 }
 
 // AddProperties "registers" the provided props