Remove InApexModules

The only use of InApexModules was a container check that verified that
apexes didn't depend on non-stubs modules from outside the apex.  Switch
it to InApexVariants for now, although that will also need to be removed.

Bug: 372543712
Test: builds
Change-Id: I822e982e3e8767dc251c8341de9f40373982c6ed
diff --git a/android/apex.go b/android/apex.go
index 414d4e1..fb2ad6c 100644
--- a/android/apex.go
+++ b/android/apex.go
@@ -16,7 +16,6 @@
 
 import (
 	"fmt"
-	"reflect"
 	"slices"
 	"sort"
 	"strconv"
@@ -62,14 +61,6 @@
 	// that are merged together.
 	InApexVariants []string
 
-	// List of APEX Soong module names that this module is part of. Note that the list includes
-	// different variations of the same APEX. For example, if module `foo` is included in the
-	// apex `com.android.foo`, and also if there is an override_apex module
-	// `com.mycompany.android.foo` overriding `com.android.foo`, then this list contains both
-	// `com.android.foo` and `com.mycompany.android.foo`.  If the APEX Soong module is a
-	// prebuilt, the name here doesn't have the `prebuilt_` prefix.
-	InApexModules []string
-
 	// True if this is for a prebuilt_apex.
 	//
 	// If true then this will customize the apex processing to make it suitable for handling
@@ -100,7 +91,6 @@
 	(*d)["Apex"] = map[string]interface{}{
 		"ApexVariationName": i.ApexVariationName,
 		"MinSdkVersion":     i.MinSdkVersion,
-		"InApexModules":     i.InApexModules,
 		"InApexVariants":    i.InApexVariants,
 		"ForPrebuiltApex":   i.ForPrebuiltApex,
 	}
@@ -135,15 +125,6 @@
 	return false
 }
 
-func (i ApexInfo) InApexModule(apexModuleName string) bool {
-	for _, a := range i.InApexModules {
-		if a == apexModuleName {
-			return true
-		}
-	}
-	return false
-}
-
 // To satisfy the comparable interface
 func (i ApexInfo) Equal(other any) bool {
 	otherApexInfo, ok := other.(ApexInfo)
@@ -151,8 +132,7 @@
 		i.MinSdkVersion == otherApexInfo.MinSdkVersion &&
 		i.Updatable == otherApexInfo.Updatable &&
 		i.UsePlatformApis == otherApexInfo.UsePlatformApis &&
-		reflect.DeepEqual(i.InApexVariants, otherApexInfo.InApexVariants) &&
-		reflect.DeepEqual(i.InApexModules, otherApexInfo.InApexModules)
+		slices.Equal(i.InApexVariants, otherApexInfo.InApexVariants)
 }
 
 // ApexBundleInfo contains information about the dependencies of an apex
@@ -361,23 +341,10 @@
 func (m *ApexModuleBase) BuildForApex(apex ApexInfo) {
 	m.apexInfosLock.Lock()
 	defer m.apexInfosLock.Unlock()
-	for i, v := range m.apexInfos {
-		if v.ApexVariationName == apex.ApexVariationName {
-			if len(apex.InApexModules) != 1 {
-				panic(fmt.Errorf("Newly created apexInfo must be for a single APEX"))
-			}
-			// Even when the ApexVariantNames are the same, the given ApexInfo might
-			// actually be for different APEX. This can happen when an APEX is
-			// overridden via override_apex. For example, there can be two apexes
-			// `com.android.foo` (from the `apex` module type) and
-			// `com.mycompany.android.foo` (from the `override_apex` module type), both
-			// of which has the same ApexVariantName `com.android.foo`. Add the apex
-			// name to the list so that it's not lost.
-			if !InList(apex.InApexModules[0], v.InApexModules) {
-				m.apexInfos[i].InApexModules = append(m.apexInfos[i].InApexModules, apex.InApexModules[0])
-			}
-			return
-		}
+	if slices.ContainsFunc(m.apexInfos, func(existing ApexInfo) bool {
+		return existing.ApexVariationName == apex.ApexVariationName
+	}) {
+		return
 	}
 	m.apexInfos = append(m.apexInfos, apex)
 }
@@ -546,7 +513,6 @@
 		if index, exists := seen[mergedName]; exists {
 			// Variants having the same mergedName are deduped
 			merged[index].InApexVariants = append(merged[index].InApexVariants, variantName)
-			merged[index].InApexModules = append(merged[index].InApexModules, apexInfo.InApexModules...)
 			merged[index].Updatable = merged[index].Updatable || apexInfo.Updatable
 			// Platform APIs is allowed for this module only when all APEXes containing
 			// the module are with `use_platform_apis: true`.
@@ -556,7 +522,6 @@
 			seen[mergedName] = len(merged)
 			apexInfo.ApexVariationName = mergedName
 			apexInfo.InApexVariants = CopyOf(apexInfo.InApexVariants)
-			apexInfo.InApexModules = CopyOf(apexInfo.InApexModules)
 			apexInfo.TestApexes = CopyOf(apexInfo.TestApexes)
 			merged = append(merged, apexInfo)
 		}
diff --git a/android/apex_test.go b/android/apex_test.go
index 347bf7d..78597b2 100644
--- a/android/apex_test.go
+++ b/android/apex_test.go
@@ -37,7 +37,6 @@
 					ApexVariationName: "foo",
 					MinSdkVersion:     FutureApiLevel,
 					InApexVariants:    []string{"foo"},
-					InApexModules:     []string{"foo"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 			},
@@ -46,7 +45,6 @@
 					ApexVariationName: "apex10000",
 					MinSdkVersion:     FutureApiLevel,
 					InApexVariants:    []string{"foo"},
-					InApexModules:     []string{"foo"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 			},
@@ -61,14 +59,12 @@
 					ApexVariationName: "foo",
 					MinSdkVersion:     FutureApiLevel,
 					InApexVariants:    []string{"foo"},
-					InApexModules:     []string{"foo"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 				{
 					ApexVariationName: "bar",
 					MinSdkVersion:     FutureApiLevel,
 					InApexVariants:    []string{"bar"},
-					InApexModules:     []string{"bar"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 			},
@@ -77,7 +73,6 @@
 					ApexVariationName: "apex10000",
 					MinSdkVersion:     FutureApiLevel,
 					InApexVariants:    []string{"foo", "bar"},
-					InApexModules:     []string{"foo", "bar"},
 				}},
 			wantAliases: [][2]string{
 				{"foo", "apex10000"},
@@ -91,14 +86,12 @@
 					ApexVariationName: "foo",
 					MinSdkVersion:     FutureApiLevel,
 					InApexVariants:    []string{"foo"},
-					InApexModules:     []string{"foo"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 				{
 					ApexVariationName: "bar",
 					MinSdkVersion:     uncheckedFinalApiLevel(30),
 					InApexVariants:    []string{"bar"},
-					InApexModules:     []string{"bar"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 			},
@@ -107,14 +100,12 @@
 					ApexVariationName: "apex10000",
 					MinSdkVersion:     FutureApiLevel,
 					InApexVariants:    []string{"foo"},
-					InApexModules:     []string{"foo"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 				{
 					ApexVariationName: "apex30",
 					MinSdkVersion:     uncheckedFinalApiLevel(30),
 					InApexVariants:    []string{"bar"},
-					InApexModules:     []string{"bar"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 			},
@@ -130,7 +121,6 @@
 					ApexVariationName: "foo",
 					MinSdkVersion:     FutureApiLevel,
 					InApexVariants:    []string{"foo"},
-					InApexModules:     []string{"foo"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 				{
@@ -138,7 +128,6 @@
 					MinSdkVersion:     FutureApiLevel,
 					Updatable:         true,
 					InApexVariants:    []string{"bar"},
-					InApexModules:     []string{"bar"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 			},
@@ -148,7 +137,6 @@
 					MinSdkVersion:     FutureApiLevel,
 					Updatable:         true,
 					InApexVariants:    []string{"foo", "bar"},
-					InApexModules:     []string{"foo", "bar"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 			},
@@ -164,7 +152,6 @@
 					ApexVariationName: "foo",
 					MinSdkVersion:     FutureApiLevel,
 					InApexVariants:    []string{"foo"},
-					InApexModules:     []string{"foo"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 				{
@@ -172,7 +159,6 @@
 					MinSdkVersion:     FutureApiLevel,
 					Updatable:         true,
 					InApexVariants:    []string{"bar"},
-					InApexModules:     []string{"bar"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 				// This one should not be merged in with the others because it is for
@@ -182,7 +168,6 @@
 					MinSdkVersion:     FutureApiLevel,
 					Updatable:         true,
 					InApexVariants:    []string{"baz"},
-					InApexModules:     []string{"baz"},
 					ForPrebuiltApex:   ForPrebuiltApex,
 				},
 			},
@@ -192,7 +177,6 @@
 					MinSdkVersion:     FutureApiLevel,
 					Updatable:         true,
 					InApexVariants:    []string{"foo", "bar"},
-					InApexModules:     []string{"foo", "bar"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 				{
@@ -200,7 +184,6 @@
 					MinSdkVersion:     FutureApiLevel,
 					Updatable:         true,
 					InApexVariants:    []string{"baz"},
-					InApexModules:     []string{"baz"},
 					ForPrebuiltApex:   ForPrebuiltApex,
 				},
 			},
@@ -216,7 +199,6 @@
 					ApexVariationName: "foo",
 					MinSdkVersion:     FutureApiLevel,
 					InApexVariants:    []string{"foo"},
-					InApexModules:     []string{"foo"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 				{
@@ -224,7 +206,6 @@
 					MinSdkVersion:     FutureApiLevel,
 					UsePlatformApis:   true,
 					InApexVariants:    []string{"bar"},
-					InApexModules:     []string{"bar"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 			},
@@ -233,7 +214,6 @@
 					ApexVariationName: "apex10000",
 					MinSdkVersion:     FutureApiLevel,
 					InApexVariants:    []string{"foo", "bar"},
-					InApexModules:     []string{"foo", "bar"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 			},
@@ -250,7 +230,6 @@
 					MinSdkVersion:     FutureApiLevel,
 					UsePlatformApis:   true,
 					InApexVariants:    []string{"foo"},
-					InApexModules:     []string{"foo"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 				{
@@ -258,7 +237,6 @@
 					MinSdkVersion:     FutureApiLevel,
 					UsePlatformApis:   true,
 					InApexVariants:    []string{"bar"},
-					InApexModules:     []string{"bar"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 			},
@@ -268,7 +246,6 @@
 					MinSdkVersion:     FutureApiLevel,
 					UsePlatformApis:   true,
 					InApexVariants:    []string{"foo", "bar"},
-					InApexModules:     []string{"foo", "bar"},
 					ForPrebuiltApex:   NotForPrebuiltApex,
 				},
 			},
diff --git a/android/container.go b/android/container.go
index 2a3777b..775436a 100644
--- a/android/container.go
+++ b/android/container.go
@@ -382,7 +382,7 @@
 
 func (c *ContainersInfo) ApexNames() (ret []string) {
 	for _, apex := range c.belongingApexes {
-		ret = append(ret, apex.InApexModules...)
+		ret = append(ret, apex.InApexVariants...)
 	}
 	slices.Sort(ret)
 	return ret
diff --git a/apex/apex.go b/apex/apex.go
index 7f259a8..a58822e 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -1020,7 +1020,6 @@
 		Updatable:         a.Updatable(),
 		UsePlatformApis:   a.UsePlatformApis(),
 		InApexVariants:    []string{apexVariationName},
-		InApexModules:     []string{a.Name()}, // could be com.mycompany.android.foo
 		TestApexes:        testApexes,
 		BaseApexName:      mctx.ModuleName(),
 		ApexAvailableName: proptools.String(a.properties.Apex_available_name),
diff --git a/apex/prebuilt.go b/apex/prebuilt.go
index 2bef0cc..f93eada 100644
--- a/apex/prebuilt.go
+++ b/apex/prebuilt.go
@@ -356,7 +356,6 @@
 	apexInfo := android.ApexInfo{
 		ApexVariationName: apexVariationName,
 		InApexVariants:    []string{apexVariationName},
-		InApexModules:     []string{p.BaseModuleName()}, // BaseModuleName() to avoid the prebuilt_ prefix.
 		ForPrebuiltApex:   true,
 	}