Add compat symlinks for prebuilt_apex

When prebuilt_apex overrides/replaces other apex, the same symlinks need
to be created as well.

Bug: 143192278
Test: 1. add prebuilt_apex with vndk apex
         with overrides set as ["com.android.vndk.current"]
      2. m <prebuilt apex>
      3. check if vndk symlinks are created

Change-Id: I8ee9c981ea9c7202ccf5143b3f43e6848773cd63
diff --git a/apex/vndk.go b/apex/vndk.go
index 1f52d11..f2e913e 100644
--- a/apex/vndk.go
+++ b/apex/vndk.go
@@ -105,7 +105,8 @@
 	}
 }
 
-func makeCompatSymlinks(apexName string, ctx android.ModuleContext) (symlinks []string) {
+// name is module.BaseModuleName() which is used as LOCAL_MODULE_NAME and also LOCAL_OVERRIDES_*
+func makeCompatSymlinks(name string, ctx android.ModuleContext) (symlinks []string) {
 	// small helper to add symlink commands
 	addSymlink := func(target, dir, linkName string) {
 		link := filepath.Join(dir, linkName)
@@ -116,9 +117,13 @@
 	// When all hard-coded references are fixed, remove symbolic links
 	// Note that  we should keep following symlinks for older VNDKs (<=29)
 	// Since prebuilt vndk libs still depend on system/lib/vndk path
-	if strings.HasPrefix(apexName, vndkApexNamePrefix) {
+	if strings.HasPrefix(name, vndkApexName) {
+		vndkVersion := ctx.DeviceConfig().PlatformVndkVersion()
+		if strings.HasPrefix(name, vndkApexNamePrefix) {
+			vndkVersion = strings.TrimPrefix(name, vndkApexNamePrefix)
+		}
 		// the name of vndk apex is formatted "com.android.vndk.v" + version
-		vndkVersion := strings.TrimPrefix(apexName, vndkApexNamePrefix)
+		apexName := vndkApexNamePrefix + vndkVersion
 		if ctx.Config().Android64() {
 			addSymlink("/apex/"+apexName+"/lib64", "$(TARGET_OUT)/lib64", "vndk-sp-"+vndkVersion)
 			addSymlink("/apex/"+apexName+"/lib64", "$(TARGET_OUT)/lib64", "vndk-"+vndkVersion)
@@ -127,22 +132,25 @@
 			addSymlink("/apex/"+apexName+"/lib", "$(TARGET_OUT)/lib", "vndk-sp-"+vndkVersion)
 			addSymlink("/apex/"+apexName+"/lib", "$(TARGET_OUT)/lib", "vndk-"+vndkVersion)
 		}
+		return
 	}
 
 	// http://b/121248172 - create a link from /system/usr/icu to
 	// /apex/com.android.i18n/etc/icu so that apps can find the ICU .dat file.
 	// A symlink can't overwrite a directory and the /system/usr/icu directory once
 	// existed so the required structure must be created whatever we find.
-	if apexName == "com.android.i18n" {
-		addSymlink("/apex/"+apexName+"/etc/icu", "$(TARGET_OUT)/usr", "icu")
+	if name == "com.android.i18n" {
+		addSymlink("/apex/com.android.i18n/etc/icu", "$(TARGET_OUT)/usr", "icu")
+		return
 	}
 
 	// TODO(b/124106384): Clean up compat symlinks for ART binaries.
-	if strings.HasPrefix(apexName, "com.android.art.") {
+	if strings.HasPrefix(name, "com.android.art.") {
 		artBinaries := []string{"dalvikvm", "dex2oat"}
 		for _, b := range artBinaries {
 			addSymlink("/apex/com.android.art/bin/"+b, "$(TARGET_OUT)/bin", b)
 		}
+		return
 	}
 	return
 }