Reland "Skip packaging cross container cc deps of apk-in-apex"

This relands https://r.android.com/3375509, but uses `NotInPlatform` of
the top-level app in `collectAppDeps`.

The original implementation was reverted because it skipped packaging
jni lib deps that crossed an api domain boundary. This is the intended
behavior for apk-in-apex, but runs into issues for android_test. The
linkerconfig for these has been setup to allow access to LLNDK (in
system) and LLNDK_MOVED_TO_APEX_LIBRARIES. Other libraries like
`libnativebridge` cannot be accessed by tests on device, so the tests
need their own copy.

Test: m ArtServiceTests
Test: verified that the contents of the apk are same before and after

Bug: 375473764
Change-Id: I3a3985e576959c3113fc1e11f43dbe669603ec22
diff --git a/cc/cc.go b/cc/cc.go
index 65ab686..03f738f 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -3345,17 +3345,17 @@
 	return depPaths
 }
 
-func ShouldUseStubForApex(ctx android.ModuleContext, dep android.Module) bool {
+func ShouldUseStubForApex(ctx android.ModuleContext, parent, dep android.Module) bool {
 	inVendorOrProduct := false
 	bootstrap := false
-	if linkable, ok := ctx.Module().(LinkableInterface); !ok {
-		panic(fmt.Errorf("Not a Linkable module: %q", ctx.ModuleName()))
+	if linkable, ok := parent.(LinkableInterface); !ok {
+		ctx.ModuleErrorf("Not a Linkable module: %q", ctx.ModuleName())
 	} else {
 		inVendorOrProduct = linkable.InVendorOrProduct()
 		bootstrap = linkable.Bootstrap()
 	}
 
-	apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
+	apexInfo, _ := android.OtherModuleProvider(ctx, parent, android.ApexInfoProvider)
 
 	useStubs := false
 
@@ -3402,7 +3402,7 @@
 
 	if !libDepTag.explicitlyVersioned && len(sharedLibraryStubsInfo.SharedStubLibraries) > 0 {
 		// when to use (unspecified) stubs, use the latest one.
-		if ShouldUseStubForApex(ctx, dep) {
+		if ShouldUseStubForApex(ctx, ctx.Module(), dep) {
 			stubs := sharedLibraryStubsInfo.SharedStubLibraries
 			toUse := stubs[len(stubs)-1]
 			sharedLibraryInfo = toUse.SharedLibraryInfo