From f3aa3225b6cd8e2d457ba19d8f28b3597e2d0f82 Mon Sep 17 00:00:00 2001 From: Jihoon Kang Date: Tue, 26 Sep 2023 22:32:08 +0000 Subject: [PATCH 1/2] Revert^2 "Add soong config variable Release_expose_flagged_api" This reverts commit 5548bf305368571c40461a818f24f26cbe2de533. Test: m nothing Bug: 299570421 Change-Id: I9f70648fb6657bbf4f5681cd6d40517d70a8fefb --- android/config.go | 4 ++++ android/variable.go | 2 ++ 2 files changed, 6 insertions(+) diff --git a/android/config.go b/android/config.go index b3ff86b49..8113ed73e 100644 --- a/android/config.go +++ b/android/config.go @@ -2084,3 +2084,7 @@ func (c *deviceConfig) CheckVendorSeappViolations() bool { func (c *deviceConfig) NextReleaseHideFlaggedApi() bool { return Bool(c.config.productVariables.NextReleaseHideFlaggedApi) } + +func (c *deviceConfig) ReleaseExposeFlaggedApi() bool { + return Bool(c.config.productVariables.Release_expose_flagged_api) +} diff --git a/android/variable.go b/android/variable.go index 44a8fd7f3..d4cd863d7 100644 --- a/android/variable.go +++ b/android/variable.go @@ -490,6 +490,8 @@ type ProductVariables struct { PartitionVarsForBazelMigrationOnlyDoNotUse PartitionVariables `json:",omitempty"` NextReleaseHideFlaggedApi *bool `json:",omitempty"` + + Release_expose_flagged_api *bool `json:",omitempty"` } type PartitionVariables struct { From c8313896258f5eba5bf08b197984f174c39871d9 Mon Sep 17 00:00:00 2001 From: Jihoon Kang Date: Wed, 20 Sep 2023 00:54:47 +0000 Subject: [PATCH 2/2] Revert^2 "Add flagged api hide conditional to droidstubs" This reverts commit 1180919ddab993c4b0d1da81cd8fa242afc7303a. Test: go test ./java && m TARGET_PRODUCT=sdk TESTING_TARGET_RELEASE_NEXT=true nothing and inspect ninja command for generating stubs and verify the flag is included && m TARGET_PRODUCT=sdk TARGET_RELEASE=trunk_food nothing and inspect ninja command for generating stubs and verify the flag is not included Bug: 299570421 Change-Id: I4967376c0236bad729398af80fa59b48dbab5f21 --- android/config.go | 4 ++++ java/droidstubs.go | 4 ++++ java/droidstubs_test.go | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/android/config.go b/android/config.go index 8113ed73e..ee61b0f25 100644 --- a/android/config.go +++ b/android/config.go @@ -2088,3 +2088,7 @@ func (c *deviceConfig) NextReleaseHideFlaggedApi() bool { func (c *deviceConfig) ReleaseExposeFlaggedApi() bool { return Bool(c.config.productVariables.Release_expose_flagged_api) } + +func (c *deviceConfig) HideFlaggedApis() bool { + return c.NextReleaseHideFlaggedApi() && !c.ReleaseExposeFlaggedApi() +} diff --git a/java/droidstubs.go b/java/droidstubs.go index 67a55bd49..b059c0abf 100644 --- a/java/droidstubs.go +++ b/java/droidstubs.go @@ -540,6 +540,10 @@ func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersi // See b/285312164 for more information. cmd.FlagWithArg("--format-defaults ", "overloaded-method-order=source") + if ctx.DeviceConfig().HideFlaggedApis() { + cmd.FlagWithArg("--hide-annotation ", "android.annotation.FlaggedApi") + } + return cmd } diff --git a/java/droidstubs_test.go b/java/droidstubs_test.go index 7a04d7326..e149b9893 100644 --- a/java/droidstubs_test.go +++ b/java/droidstubs_test.go @@ -22,6 +22,8 @@ import ( "testing" "android/soong/android" + + "github.com/google/blueprint/proptools" ) func TestDroidstubs(t *testing.T) { @@ -403,3 +405,35 @@ func TestGeneratedApiContributionVisibilityTest(t *testing.T) { ctx.ModuleForTests("bar", "android_common") } + +func TestDroidstubsHideFlaggedApi(t *testing.T) { + result := android.GroupFixturePreparers( + prepareForJavaTest, + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + variables.NextReleaseHideFlaggedApi = proptools.BoolPtr(true) + variables.Release_expose_flagged_api = proptools.BoolPtr(false) + }), + android.FixtureMergeMockFs(map[string][]byte{ + "a/A.java": nil, + "a/current.txt": nil, + "a/removed.txt": nil, + }), + ).RunTestWithBp(t, ` + droidstubs { + name: "foo", + srcs: ["a/A.java"], + api_surface: "public", + check_api: { + current: { + api_file: "a/current.txt", + removed_api_file: "a/removed.txt", + } + }, + } + `) + + m := result.ModuleForTests("foo", "android_common") + manifest := m.Output("metalava.sbox.textproto") + cmdline := String(android.RuleBuilderSboxProtoForTests(t, manifest).Commands[0].Command) + android.AssertStringDoesContain(t, "flagged api hide command not included", cmdline, "--hide-annotation android.annotation.FlaggedApi") +}