Fix the ABI dump directory name for vendor libraries

The condition for vendor libraries is inconsistent between
getRefAbiDumpFile and linkSAbiDumpFiles. It causes the ABI check not to
be triggered for vendor libraries. This commit fixes linkSAbiDumpFiles.
The vendor libraries' ABI dumps are placed in the "platform" directory
for now. A follow-up commit will allow configuring the dump directory
paths.

Test: make
Bug: 227282691
Change-Id: Iad8f92145bce6264bf51efb4b8180bb917a1476d
diff --git a/cc/library.go b/cc/library.go
index 65c6b6d..e55b516 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -1875,25 +1875,21 @@
 	}
 }
 
+func currRefAbiDumpVersion(ctx ModuleContext, isVndk bool) string {
+	if isVndk {
+		// Each version of VNDK is independent, so follow the VNDK version which is the codename or PLATFORM_SDK_VERSION.
+		return ctx.Module().(*Module).VndkVersion()
+	} else if ctx.Config().PlatformSdkFinal() {
+		// After sdk finalization, the ABI of the latest API level must be consistent with the source code,
+		// so choose PLATFORM_SDK_VERSION as the current version.
+		return ctx.Config().PlatformSdkVersion().String()
+	} else {
+		return "current"
+	}
+}
+
 func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objects, fileName string, soFile android.Path) {
 	if library.sabi.shouldCreateSourceAbiDump() {
-		var version string
-		var prevVersion int
-
-		if ctx.useVndk() {
-			// For modules linking against vndk, follow its vndk version
-			version = ctx.Module().(*Module).VndkVersion()
-		} else {
-			// After sdk finalizatoin, the ABI of the latest API level must be consistent with the source code
-			// so the chosen reference dump is the PLATFORM_SDK_VERSION.
-			if ctx.Config().PlatformSdkFinal() {
-				version = ctx.Config().PlatformSdkVersion().String()
-			} else {
-				version = "current"
-			}
-			prevVersion = prevDumpRefVersion(ctx)
-		}
-
 		exportIncludeDirs := library.flagExporter.exportedIncludes(ctx)
 		var SourceAbiFlags []string
 		for _, dir := range exportIncludeDirs.Strings() {
@@ -1910,10 +1906,12 @@
 
 		addLsdumpPath(classifySourceAbiDump(ctx) + ":" + library.sAbiOutputFile.String())
 
+		isVndk := ctx.useVndk() && ctx.isVndk()
 		isNdk := ctx.isNdk(ctx.Config())
 		isLlndk := ctx.isImplementationForLLNDKPublic()
 		// If NDK or PLATFORM library, check against previous version ABI.
-		if !ctx.useVndk() {
+		if !isVndk {
+			prevVersion := prevDumpRefVersion(ctx)
 			prevRefAbiDumpFile := getRefAbiDumpFile(ctx, strconv.Itoa(prevVersion), fileName)
 			if prevRefAbiDumpFile != nil {
 				library.prevSAbiDiff = sourceAbiDiff(ctx, library.sAbiOutputFile.Path(),
@@ -1924,7 +1922,8 @@
 			}
 		}
 
-		refAbiDumpFile := getRefAbiDumpFile(ctx, version, fileName)
+		currVersion := currRefAbiDumpVersion(ctx, isVndk)
+		refAbiDumpFile := getRefAbiDumpFile(ctx, currVersion, fileName)
 		if refAbiDumpFile != nil {
 			library.sAbiDiff = sourceAbiDiff(ctx, library.sAbiOutputFile.Path(),
 				refAbiDumpFile, fileName,