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

@@ -227,6 +227,12 @@ type DeviceProperties struct {
// whether to generate Binder#GetTransaction name method.
Generate_get_transaction_name *bool
// whether all interfaces should be annotated with required permissions.
Enforce_permissions *bool
// allowlist for interfaces that (temporarily) do not require annotation for permissions.
Enforce_permissions_exceptions []string `android:"path"`
// list of flags that will be passed to the AIDL compiler
Flags []string
}
@@ -418,7 +424,8 @@ type Module struct {
outputFile android.Path
extraOutputFiles android.Paths
exportAidlIncludeDirs android.Paths
exportAidlIncludeDirs android.Paths
ignoredAidlPermissionList android.Paths
logtagsSrcs android.Paths
@@ -772,6 +779,17 @@ func (j *Module) hasSrcExt(ext string) bool {
return hasSrcExt(j.properties.Srcs, ext)
}
func (j *Module) individualAidlFlags(ctx android.ModuleContext, aidlFile android.Path) string {
var flags string
if Bool(j.deviceProperties.Aidl.Enforce_permissions) {
if !android.InList(aidlFile.String(), j.ignoredAidlPermissionList.Strings()) {
flags = "-Wmissing-permission-annotation -Werror"
}
}
return flags
}
func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
aidlIncludeDirs android.Paths) (string, android.Paths) {
@@ -814,6 +832,11 @@ func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.Opt
flags = append(flags, "--transaction_names")
}
if Bool(j.deviceProperties.Aidl.Enforce_permissions) {
exceptions := j.deviceProperties.Aidl.Enforce_permissions_exceptions
j.ignoredAidlPermissionList = android.PathsForModuleSrcExcludes(ctx, exceptions, nil)
}
aidlMinSdkVersion := j.MinSdkVersion(ctx).ApiLevel.String()
flags = append(flags, "--min_sdk_version="+aidlMinSdkVersion)