summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jihoon Kang <jihoonkang@google.com> 2024-02-06 22:43:18 +0000
committer Jihoon Kang <jihoonkang@google.com> 2024-02-07 01:17:59 +0000
commit5919815f80cb8da3d28a7cb4692245ac82c114f4 (patch)
tree8f84317397504920ff67b991cc3303b3e319b258
parent7870d329a5c21132adc16a5974f66839c1422c16 (diff)
Enable exportable stubs to include READ_WRITE aconfig flagged apis
Currently in SDK build, "exportable" stubs are used to generate the android.jar and the corresponding build artifacts, as well as the hiddenapi flags. "exportable" stubs only include the flagged apis that are "enabled" and "read only", and exclude all other flagged apis. This will be replaced with "runtime" stubs in the long run, which include "read_write" flagged apis on top of the "enabled" and "read only" flags. Prior to Trunk Stable, the SDK build did not distinguish the target audience of the SDK. That is, the identical build target was used to generate the SDK targeted toward the Google3 developers (i.e. Google3 SDK drop) and the SDK targeted toward the public (i.e. Developer Preview). However, given that we now have "experimental" apis with Trunk Stable, there are demands to differentiate the SDK based on the target audience, so that the "experimental" APIs are included in the SDK targeted toward Google3 while they are excluded in the public facing SDK. The long term solution to achieve this is to generate the hiddenapi flags and (conditionally) the SDKs using the runtime stubs. However, as this is high priority, this change resolves the problem by modifying the filter condition of the "exportable" stubs to include the "read_write" flagged apis on top of the "enabled" and "read only" flagged apis when the value of the default-false build flag "RELEASE_EXPORT_RUNTIME_APIS" is set to true. Note that this is a temporary solution; However, we might need to keep the "RELEASE_EXPORT_RUNTIME_APIS" build flag even in the long run to determine what set of apis are included in the generated SDK, based on the target audience of the SDK. Test: m nothing --no-skip-soong-tests Bug: 323188988 Change-Id: If0d5fa74b3ba6f4a57c86aade8d340f149a657a2
-rw-r--r--android/config.go6
-rw-r--r--java/droidstubs.go10
-rw-r--r--java/droidstubs_test.go45
3 files changed, 59 insertions, 2 deletions
diff --git a/android/config.go b/android/config.go
index d94a86f71..929f3178b 100644
--- a/android/config.go
+++ b/android/config.go
@@ -209,6 +209,12 @@ func (c Config) ReleaseDefaultModuleBuildFromSource() bool {
Bool(c.config.productVariables.ReleaseDefaultModuleBuildFromSource)
}
+// Enables flagged apis annotated with READ_WRITE aconfig flags to be included in the stubs
+// and hiddenapi flags so that they are accessible at runtime
+func (c Config) ReleaseExportRuntimeApis() bool {
+ return c.config.productVariables.GetBuildFlagBool("RELEASE_EXPORT_RUNTIME_APIS")
+}
+
// Enables ABI monitoring of NDK libraries
func (c Config) ReleaseNdkAbiMonitored() bool {
return c.config.productVariables.GetBuildFlagBool("RELEASE_NDK_ABI_MONITORED")
diff --git a/java/droidstubs.go b/java/droidstubs.go
index 56ae427ac..51503f22a 100644
--- a/java/droidstubs.go
+++ b/java/droidstubs.go
@@ -744,8 +744,14 @@ func (d *Droidstubs) generateRevertAnnotationArgs(ctx android.ModuleContext, cmd
filterArgs = "--filter='state:ENABLED+permission:READ_ONLY' --filter='permission:READ_WRITE'"
case Exportable:
- filterArgs = "--filter='state:ENABLED+permission:READ_ONLY'"
-
+ // When the build flag RELEASE_EXPORT_RUNTIME_APIS is set to true, apis marked with
+ // the flagged apis that have read_write permissions are exposed on top of the enabled
+ // and read_only apis. This is to support local override of flag values at runtime.
+ if ctx.Config().ReleaseExportRuntimeApis() {
+ filterArgs = "--filter='state:ENABLED+permission:READ_ONLY' --filter='permission:READ_WRITE'"
+ } else {
+ filterArgs = "--filter='state:ENABLED+permission:READ_ONLY'"
+ }
}
ctx.Build(pctx, android.BuildParams{
diff --git a/java/droidstubs_test.go b/java/droidstubs_test.go
index 52cd1c513..caa834535 100644
--- a/java/droidstubs_test.go
+++ b/java/droidstubs_test.go
@@ -412,3 +412,48 @@ func TestAconfigDeclarations(t *testing.T) {
android.AssertStringDoesContain(t, "foo generates exportable stubs jar",
strings.Join(m.AllOutputs(), ""), "exportable/foo-stubs.srcjar")
}
+
+func TestReleaseExportRuntimeApis(t *testing.T) {
+ result := android.GroupFixturePreparers(
+ prepareForJavaTest,
+ android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ variables.BuildFlags = map[string]string{
+ "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
+ "RELEASE_EXPORT_RUNTIME_APIS": "true",
+ }
+ }),
+ android.FixtureMergeMockFs(map[string][]byte{
+ "a/A.java": nil,
+ "a/current.txt": nil,
+ "a/removed.txt": nil,
+ }),
+ ).RunTestWithBp(t, `
+ aconfig_declarations {
+ name: "bar",
+ package: "com.example.package",
+ srcs: [
+ "bar.aconfig",
+ ],
+ }
+ droidstubs {
+ name: "foo",
+ srcs: ["a/A.java"],
+ api_surface: "public",
+ check_api: {
+ current: {
+ api_file: "a/current.txt",
+ removed_api_file: "a/removed.txt",
+ }
+ },
+ aconfig_declarations: [
+ "bar",
+ ],
+ }
+ `)
+
+ m := result.ModuleForTests("foo", "android_common")
+
+ rule := m.Output("released-flagged-apis-exportable.txt")
+ exposeWritableApisFilter := "--filter='state:ENABLED+permission:READ_ONLY' --filter='permission:READ_WRITE'"
+ android.AssertStringEquals(t, "Filter argument expected to contain READ_WRITE permissions", exposeWritableApisFilter, rule.Args["filter_args"])
+}