From d25060aa2d6e4468f1b67a70d65623afcefff45a Mon Sep 17 00:00:00 2001 From: David Brazdil Date: Mon, 18 Feb 2019 18:24:16 +0000 Subject: [PATCH] Set usesNonSdkApi in manifest when Platform_apis=true The Platform_apis field in CompilerDeviceProperties currently has no effect. Unify the behaviour with make and run manifest_fixer.py to encode the information in the manifest. This is used to exempt bundled apps and platform tests from hidden API access checks without having a fixed whitelist of packages. Bug: 113315999 Bug: 124671117 Test: m UbSystemUiJankTests && \ aapt d xmltree \ target/product/taimen/data/app/UbSystemUiJankTests/UbSystemUiJankTests.apk \ AndroidManifest.xml | grep usesNonSdkApi Change-Id: I20c392d91ee6275ef8139fbeb5b9700385abbc80 --- java/aar.go | 3 ++- java/android_manifest.go | 6 +++++- java/app.go | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/java/aar.go b/java/aar.go index 583a6fcc2..b8a5e35cd 100644 --- a/java/aar.go +++ b/java/aar.go @@ -77,6 +77,7 @@ type aapt struct { isLibrary bool uncompressedJNI bool useEmbeddedDex bool + usesNonSdkApis bool aaptProperties aaptProperties } @@ -184,7 +185,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile) manifestPath := manifestMerger(ctx, manifestSrcPath, sdkContext, staticLibManifests, a.isLibrary, - a.uncompressedJNI, a.useEmbeddedDex) + a.uncompressedJNI, a.useEmbeddedDex, a.usesNonSdkApis) linkFlags, linkDeps, resDirs, overlayDirs, rroDirs := a.aapt2Flags(ctx, sdkContext, manifestPath) diff --git a/java/android_manifest.go b/java/android_manifest.go index e63fb8049..3cca4f718 100644 --- a/java/android_manifest.go +++ b/java/android_manifest.go @@ -44,7 +44,7 @@ var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger", "libs") func manifestMerger(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext, - staticLibManifests android.Paths, isLibrary bool, uncompressedJNI, useEmbeddedDex bool) android.Path { + staticLibManifests android.Paths, isLibrary, uncompressedJNI, useEmbeddedDex, usesNonSdkApis bool) android.Path { var args []string if isLibrary { @@ -62,6 +62,10 @@ func manifestMerger(ctx android.ModuleContext, manifest android.Path, sdkContext } } + if usesNonSdkApis { + args = append(args, "--uses-non-sdk-api") + } + if useEmbeddedDex { args = append(args, "--use-embedded-dex=true") } diff --git a/java/app.go b/java/app.go index 3cb7e8e2f..501546883 100644 --- a/java/app.go +++ b/java/app.go @@ -186,6 +186,8 @@ func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool { } func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { + a.aapt.usesNonSdkApis = Bool(a.Module.deviceProperties.Platform_apis) + aaptLinkFlags := []string{} // Add TARGET_AAPT_CHARACTERISTICS values to AAPT link flags if they exist and --product flags were not provided.