From 5919815f80cb8da3d28a7cb4692245ac82c114f4 Mon Sep 17 00:00:00 2001 From: Jihoon Kang Date: Tue, 6 Feb 2024 22:43:18 +0000 Subject: 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 --- java/droidstubs_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'java/droidstubs_test.go') 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"]) +} -- cgit v1.2.3-59-g8ed1b