Merge "Enable exportable stubs to include READ_WRITE aconfig flagged apis" into main

This commit is contained in:
Jihoon Kang
2024-02-08 23:52:47 +00:00
committed by Gerrit Code Review
3 changed files with 59 additions and 2 deletions

View File

@@ -210,6 +210,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")

View File

@@ -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{

View File

@@ -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"])
}