From 6bd33c13bb552d3eee52bcc553b35d55dd91fe98 Mon Sep 17 00:00:00 2001 From: Jeongik Cha Date: Tue, 25 Jun 2019 16:26:18 +0900 Subject: [PATCH] Enforce hidden api usage in vendor (soong) From aosp/588578, if vendor app doesn't fill sdk_version, build scirpt overwrites system_current to sdk_version. But there is no similar enforcement in soong. So, as make does, sdkVersion() returns "system_current" if it is device-specific or soc-specific module. and sdk_version is not filled. Test: pass soong test Bug: 132780927 Change-Id: I69bb3d7bfcf7c27c2db4d0efbe046f9c7879b4bc --- java/aar.go | 2 +- java/droiddoc.go | 3 ++- java/java.go | 16 ++++++++++++++-- java/java_test.go | 26 ++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/java/aar.go b/java/aar.go index 47f6e5f6a..a2c203fcb 100644 --- a/java/aar.go +++ b/java/aar.go @@ -499,7 +499,7 @@ type AARImport struct { } func (a *AARImport) sdkVersion() string { - return String(a.properties.Sdk_version) + return proptools.StringDefault(a.properties.Sdk_version, defaultSdkVersion(a)) } func (a *AARImport) minSdkVersion() string { diff --git a/java/droiddoc.go b/java/droiddoc.go index be1b28153..18f337a26 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -23,6 +23,7 @@ import ( "strings" "github.com/google/blueprint" + "github.com/google/blueprint/proptools" ) var ( @@ -523,7 +524,7 @@ func JavadocHostFactory() android.Module { var _ android.OutputFileProducer = (*Javadoc)(nil) func (j *Javadoc) sdkVersion() string { - return String(j.properties.Sdk_version) + return proptools.StringDefault(j.properties.Sdk_version, defaultSdkVersion(j)) } func (j *Javadoc) minSdkVersion() string { diff --git a/java/java.go b/java/java.go index a2e9ab023..037843686 100644 --- a/java/java.go +++ b/java/java.go @@ -426,6 +426,18 @@ var ( usesLibTag = dependencyTag{name: "uses-library"} ) +func defaultSdkVersion(ctx checkVendorModuleContext) string { + if ctx.SocSpecific() || ctx.DeviceSpecific() { + return "system_current" + } + return "" +} + +type checkVendorModuleContext interface { + SocSpecific() bool + DeviceSpecific() bool +} + type sdkDep struct { useModule, useFiles, useDefaultLibs, invalidVersion bool @@ -465,7 +477,7 @@ func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool { } func (j *Module) sdkVersion() string { - return String(j.deviceProperties.Sdk_version) + return proptools.StringDefault(j.deviceProperties.Sdk_version, defaultSdkVersion(j)) } func (j *Module) minSdkVersion() string { @@ -1869,7 +1881,7 @@ type Import struct { } func (j *Import) sdkVersion() string { - return String(j.properties.Sdk_version) + return proptools.StringDefault(j.properties.Sdk_version, defaultSdkVersion(j)) } func (j *Import) minSdkVersion() string { diff --git a/java/java_test.go b/java/java_test.go index 22dec073f..628fec3f8 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -282,6 +282,32 @@ func TestSimple(t *testing.T) { } } +func TestSdkVersion(t *testing.T) { + ctx := testJava(t, ` + java_library { + name: "foo", + srcs: ["a.java"], + vendor: true, + } + + java_library { + name: "bar", + srcs: ["b.java"], + } + `) + + foo := ctx.ModuleForTests("foo", "android_common").Module().(*Library) + bar := ctx.ModuleForTests("bar", "android_common").Module().(*Library) + + if foo.sdkVersion() != "system_current" { + t.Errorf("If sdk version of vendor module is empty, it must change to system_current.") + } + + if bar.sdkVersion() != "" { + t.Errorf("If sdk version of non-vendor module is empty, it keeps empty.") + } +} + func TestArchSpecific(t *testing.T) { ctx := testJava(t, ` java_library {