Add AIDL enforce_permissions attribute

When set to true, this attribute will pass down the
-Wmissing-permission-annotation flag to the aidl compiler. It is
possible to declare a set of exceptions (for a graduable adoption). For
now, only Java is supported.

Test: build having the attribute enabled for frameworks/base
Bug: 220214993
Change-Id: I54350199b4d980aef0050519e3daf1fef616d08c
This commit is contained in:
Thiébaud Weksteen
2022-02-10 15:41:46 +11:00
parent 7309742728
commit de8417c707
4 changed files with 73 additions and 5 deletions

View File

@@ -1333,6 +1333,42 @@ func TestAidlFlagsWithMinSdkVersion(t *testing.T) {
}
}
func TestAidlEnforcePermissions(t *testing.T) {
ctx, _ := testJava(t, `
java_library {
name: "foo",
srcs: ["aidl/foo/IFoo.aidl"],
aidl: { enforce_permissions: true },
}
`)
aidlCommand := ctx.ModuleForTests("foo", "android_common").Rule("aidl").RuleParams.Command
expectedAidlFlag := "-Wmissing-permission-annotation -Werror"
if !strings.Contains(aidlCommand, expectedAidlFlag) {
t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
}
}
func TestAidlEnforcePermissionsException(t *testing.T) {
ctx, _ := testJava(t, `
java_library {
name: "foo",
srcs: ["aidl/foo/IFoo.aidl", "aidl/foo/IFoo2.aidl"],
aidl: { enforce_permissions: true, enforce_permissions_exceptions: ["aidl/foo/IFoo2.aidl"] },
}
`)
aidlCommand := ctx.ModuleForTests("foo", "android_common").Rule("aidl").RuleParams.Command
expectedAidlFlag := "$$FLAGS -Wmissing-permission-annotation -Werror aidl/foo/IFoo.aidl"
if !strings.Contains(aidlCommand, expectedAidlFlag) {
t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
}
expectedAidlFlag = "$$FLAGS aidl/foo/IFoo2.aidl"
if !strings.Contains(aidlCommand, expectedAidlFlag) {
t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
}
}
func TestDataNativeBinaries(t *testing.T) {
ctx, _ := testJava(t, `
java_test_host {