summaryrefslogtreecommitdiff
path: root/java/hiddenapi.go
diff options
context:
space:
mode:
author Paul Duffin <paulduffin@google.com> 2022-04-28 17:45:11 +0100
committer Paul Duffin <paulduffin@google.com> 2022-04-28 18:34:48 +0100
commit09817d66dea3639528b35a5b61ddce78766d198c (patch)
treefcf6479a6e90192cb5c2e64a83245f534e9325d4 /java/hiddenapi.go
parentfcf0b686aa0e00a76232f801fbe01707fb7be78f (diff)
hiddenapi: Prevent libraries for Q/R from include S+ flags.
The Q and R runtimes can handle Q/R flags but not S flags. So, this change verifies that any library that can run on Q/R (min_sdk_version <= R) by adding --max-hiddenapi-level=max-target-r to the "hiddenapi encode" command. That will cause a failure if any S+ flags are found in the flags to encode. Bug: 172453495 Test: m droid && launch_cvd Cherry pick changes in https://r.android.com/q/topic:max-target-s Add @UnsupportedAppUsage maxTargetSdk=S in classes in framework-permission (for r/q) and framework-permission-s (nominally for S+). I had to incresed the min_sdk_version in the latter to 31 (S) as it was still set at 30 (R). Change-Id: Ie0f68482603adc7b4e3d7a5c81bf203d81a84a9e
Diffstat (limited to 'java/hiddenapi.go')
-rw-r--r--java/hiddenapi.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/java/hiddenapi.go b/java/hiddenapi.go
index 3af5f1c7b..cf9c7ad7a 100644
--- a/java/hiddenapi.go
+++ b/java/hiddenapi.go
@@ -65,6 +65,8 @@ func (h *hiddenAPI) uncompressDex() *bool {
type hiddenAPIModule interface {
android.Module
hiddenAPIIntf
+
+ MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec
}
type hiddenAPIIntf interface {
@@ -148,7 +150,7 @@ func (h *hiddenAPI) hiddenAPIEncodeDex(ctx android.ModuleContext, dexJar android
// Create a copy of the dex jar which has been encoded with hiddenapi flags.
flagsCSV := hiddenAPISingletonPaths(ctx).flags
outputDir := android.PathForModuleOut(ctx, "hiddenapi").OutputPath
- encodedDex := hiddenAPIEncodeDex(ctx, dexJar, flagsCSV, uncompressDex, outputDir)
+ encodedDex := hiddenAPIEncodeDex(ctx, dexJar, flagsCSV, uncompressDex, android.SdkSpecNone, outputDir)
// Use the encoded dex jar from here onwards.
return encodedDex
@@ -246,7 +248,7 @@ var hiddenAPIEncodeDexRule = pctx.AndroidStaticRule("hiddenAPIEncodeDex", bluepr
// The encode dex rule requires unzipping, encoding and rezipping the classes.dex files along with
// all the resources from the input jar. It also ensures that if it was uncompressed in the input
// it stays uncompressed in the output.
-func hiddenAPIEncodeDex(ctx android.ModuleContext, dexInput, flagsCSV android.Path, uncompressDex bool, outputDir android.OutputPath) android.OutputPath {
+func hiddenAPIEncodeDex(ctx android.ModuleContext, dexInput, flagsCSV android.Path, uncompressDex bool, minSdkVersion android.SdkSpec, outputDir android.OutputPath) android.OutputPath {
// The output file has the same name as the input file and is in the output directory.
output := outputDir.Join(ctx, dexInput.Base())
@@ -274,6 +276,15 @@ func hiddenAPIEncodeDex(ctx android.ModuleContext, dexInput, flagsCSV android.Pa
hiddenapiFlags = "--no-force-assign-all"
}
+ // If the library is targeted for Q and/or R then make sure that they do not
+ // have any S+ flags encoded as that will break the runtime.
+ minApiLevel := minSdkVersion.ApiLevel
+ if !minApiLevel.IsNone() {
+ if minApiLevel.LessThanOrEqualTo(android.ApiLevelOrPanic(ctx, "R")) {
+ hiddenapiFlags = hiddenapiFlags + " --max-hiddenapi-level=max-target-r"
+ }
+ }
+
ctx.Build(pctx, android.BuildParams{
Rule: hiddenAPIEncodeDexRule,
Description: "hiddenapi encode dex",