Rework vndk detection

Instead of having a module define `use_vndk: true`, assume that we're
building with the VNDK if we're installed on the vendor partition, and
BOARD_VNDK_VERSION==current. This now matches our behavior in Make.

Once BOARD_VNDK_VERSION!=current, we'll need to disable modules that
need to otherwise compile against the VNDK, since we can only compile
against the current VNDK.

Test: build.ninja for aosp_arm is the same before/after
Test: Ensure there are no boards that set BOARD_VNDK_VERSION
Change-Id: If937fa7bdb119648137af52daebadf486163484b
diff --git a/android/config.go b/android/config.go
index 2361920..686eeb8 100644
--- a/android/config.go
+++ b/android/config.go
@@ -462,11 +462,11 @@
 	return "vendor"
 }
 
-func (c *deviceConfig) VndkVersion() string {
+func (c *deviceConfig) CompileVndk() bool {
 	if c.config.ProductVariables.DeviceVndkVersion == nil {
-		return ""
+		return false
 	}
-	return *c.config.ProductVariables.DeviceVndkVersion
+	return *c.config.ProductVariables.DeviceVndkVersion == "current"
 }
 
 func (c *deviceConfig) BtConfigIncludeDir() string {
diff --git a/android/module.go b/android/module.go
index cc420fb..8228a9c 100644
--- a/android/module.go
+++ b/android/module.go
@@ -59,6 +59,7 @@
 	Darwin() bool
 	Debug() bool
 	PrimaryArch() bool
+	Proprietary() bool
 	AConfig() Config
 	DeviceConfig() DeviceConfig
 }
@@ -87,7 +88,6 @@
 
 	AddMissingDependencies(deps []string)
 
-	Proprietary() bool
 	InstallInData() bool
 
 	RequiredModuleNames() []string
@@ -455,6 +455,7 @@
 	return androidBaseContextImpl{
 		target:        a.commonProperties.CompileTarget,
 		targetPrimary: a.commonProperties.CompilePrimary,
+		proprietary:   a.commonProperties.Proprietary,
 		config:        ctx.Config().(Config),
 	}
 }
@@ -491,6 +492,7 @@
 	target        Target
 	targetPrimary bool
 	debug         bool
+	proprietary   bool
 	config        Config
 }
 
@@ -619,8 +621,8 @@
 	return DeviceConfig{a.config.deviceConfig}
 }
 
-func (a *androidModuleContext) Proprietary() bool {
-	return a.module.base().commonProperties.Proprietary
+func (a *androidBaseContextImpl) Proprietary() bool {
+	return a.proprietary
 }
 
 func (a *androidModuleContext) InstallInData() bool {
diff --git a/androidmk/cmd/androidmk/android.go b/androidmk/cmd/androidmk/android.go
index 331bb4f..6d08ca8 100644
--- a/androidmk/cmd/androidmk/android.go
+++ b/androidmk/cmd/androidmk/android.go
@@ -118,7 +118,6 @@
 			"LOCAL_NO_STANDARD_LIBRARIES":   "no_standard_libraries",
 			"LOCAL_PACK_MODULE_RELOCATIONS": "pack_relocations",
 			"LOCAL_TIDY":                    "tidy",
-			"LOCAL_USE_VNDK":                "use_vndk",
 			"LOCAL_PROPRIETARY_MODULE":      "proprietary",
 
 			"LOCAL_EXPORT_PACKAGE_RESOURCES": "export_package_resources",
diff --git a/cc/androidmk.go b/cc/androidmk.go
index 7acc244..bf0ca6f 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -59,9 +59,6 @@
 		if c.Target().Os == android.Android && c.Properties.Sdk_version != "" {
 			fmt.Fprintln(w, "LOCAL_SDK_VERSION := "+c.Properties.Sdk_version)
 			fmt.Fprintln(w, "LOCAL_NDK_STL_VARIANT := none")
-		} else if c.Target().Os == android.Android && c.Properties.Use_vndk {
-			fmt.Fprintln(w, "LOCAL_USE_VNDK := true")
-			fmt.Fprintln(w, "LOCAL_NDK_STL_VARIANT := none")
 		} else {
 			// These are already included in LOCAL_SHARED_LIBRARIES
 			fmt.Fprintln(w, "LOCAL_CXX_STL := none")
diff --git a/cc/cc.go b/cc/cc.go
index b27e8ee..84afa73 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -135,9 +135,6 @@
 	// Minimum sdk version supported when compiling against the ndk
 	Sdk_version string
 
-	// Whether to compile against the VNDK
-	Use_vndk bool
-
 	// don't insert default compiler flags into asflags, cflags,
 	// cppflags, conlyflags, ldflags, or include_dirs
 	No_default_compiler_flags *bool
@@ -145,7 +142,6 @@
 	AndroidMkSharedLibs []string `blueprint:"mutated"`
 	HideFromMake        bool     `blueprint:"mutated"`
 	PreventInstall      bool     `blueprint:"mutated"`
-	Vndk_version        string   `blueprint:"mutated"`
 }
 
 type UnusedProperties struct {
@@ -378,8 +374,8 @@
 
 func (ctx *moduleContextImpl) sdkVersion() string {
 	if ctx.ctx.Device() {
-		if ctx.mod.Properties.Use_vndk {
-			return ctx.mod.Properties.Vndk_version
+		if ctx.vndk() {
+			return "current"
 		} else {
 			return ctx.mod.Properties.Sdk_version
 		}
@@ -388,10 +384,7 @@
 }
 
 func (ctx *moduleContextImpl) vndk() bool {
-	if ctx.ctx.Device() {
-		return ctx.mod.Properties.Use_vndk
-	}
-	return false
+	return ctx.ctx.Os() == android.Android && ctx.ctx.Proprietary() && ctx.ctx.DeviceConfig().CompileVndk()
 }
 
 func (ctx *moduleContextImpl) selectedStl() string {
@@ -544,22 +537,11 @@
 		feature.begin(ctx)
 	}
 	if ctx.sdk() {
-		if ctx.vndk() {
-			ctx.PropertyErrorf("use_vndk",
-				"sdk_version and use_vndk cannot be used at the same time")
-		}
-
 		version, err := normalizeNdkApiLevel(ctx.sdkVersion(), ctx.Arch())
 		if err != nil {
 			ctx.PropertyErrorf("sdk_version", err.Error())
 		}
 		c.Properties.Sdk_version = version
-	} else if ctx.vndk() {
-		version, err := normalizeNdkApiLevel(ctx.DeviceConfig().VndkVersion(), ctx.Arch())
-		if err != nil {
-			ctx.ModuleErrorf("Bad BOARD_VNDK_VERSION: %s", err.Error())
-		}
-		c.Properties.Vndk_version = version
 	}
 }