Merge "enforce sdk_version for JNI libs for updatable APKs" am: 1852b586bf am: 548c377bee

Change-Id: Icb9cd88d908d28eebd89d25429b64fc30faf60bb
This commit is contained in:
Treehugger Robot
2020-05-13 01:22:49 +00:00
committed by Automerger Merge Worker
2 changed files with 150 additions and 1 deletions

View File

@@ -289,19 +289,47 @@ func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
}
func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) {
if Bool(a.appProperties.Updatable) {
if Bool(a.appProperties.Updatable) || a.ApexModuleBase.Updatable() {
if !a.sdkVersion().stable() {
ctx.PropertyErrorf("sdk_version", "Updatable apps must use stable SDKs, found %v", a.sdkVersion())
}
if String(a.deviceProperties.Min_sdk_version) == "" {
ctx.PropertyErrorf("updatable", "updatable apps must set min_sdk_version.")
}
if minSdkVersion, err := a.minSdkVersion().effectiveVersion(ctx); err == nil {
a.checkJniLibsSdkVersion(ctx, minSdkVersion)
} else {
ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
}
}
a.checkPlatformAPI(ctx)
a.checkSdkVersions(ctx)
}
// If an updatable APK sets min_sdk_version, min_sdk_vesion of JNI libs should match with it.
// This check is enforced for "updatable" APKs (including APK-in-APEX).
// b/155209650: until min_sdk_version is properly supported, use sdk_version instead.
// because, sdk_version is overridden by min_sdk_version (if set as smaller)
// and linkType is checked with dependencies so we can be sure that the whole dependency tree
// will meet the requirements.
func (a *AndroidApp) checkJniLibsSdkVersion(ctx android.ModuleContext, minSdkVersion sdkVersion) {
// It's enough to check direct JNI deps' sdk_version because all transitive deps from JNI deps are checked in cc.checkLinkType()
ctx.VisitDirectDeps(func(m android.Module) {
if !IsJniDepTag(ctx.OtherModuleDependencyTag(m)) {
return
}
dep, _ := m.(*cc.Module)
jniSdkVersion, err := android.ApiStrToNum(ctx, dep.SdkVersion())
if err != nil || int(minSdkVersion) < jniSdkVersion {
ctx.OtherModuleErrorf(dep, "sdk_version(%v) is higher than min_sdk_version(%v) of the containing android_app(%v)",
dep.SdkVersion(), a.MinSdkVersion(), ctx.ModuleName())
return
}
})
}
// Returns true if the native libraries should be stored in the APK uncompressed and the
// extractNativeLibs application flag should be set to false in the manifest.
func (a *AndroidApp) useEmbeddedNativeLibs(ctx android.ModuleContext) bool {