summaryrefslogtreecommitdiff
path: root/android/neverallow.go
diff options
context:
space:
mode:
Diffstat (limited to 'android/neverallow.go')
-rw-r--r--android/neverallow.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/android/neverallow.go b/android/neverallow.go
index 44ac2cd6c..6176a996a 100644
--- a/android/neverallow.go
+++ b/android/neverallow.go
@@ -63,6 +63,7 @@ func init() {
AddNeverAllowRules(createLimitDirgroupRule()...)
AddNeverAllowRules(createFilesystemIsAutoGeneratedRule())
AddNeverAllowRules(createKotlinPluginRule()...)
+ AddNeverAllowRules(createPrebuiltEtcBpDefineRule())
}
// Add a NeverAllow rule to the set of rules to apply.
@@ -321,6 +322,27 @@ func createKotlinPluginRule() []Rule {
}
}
+// These module types are introduced to convert PRODUCT_COPY_FILES to Soong,
+// and is only intended to be used by filesystem_creator.
+func createPrebuiltEtcBpDefineRule() Rule {
+ return NeverAllow().
+ ModuleType(
+ "prebuilt_usr_srec",
+ "prebuilt_priv_app",
+ "prebuilt_rfs",
+ "prebuilt_framework",
+ "prebuilt_res",
+ "prebuilt_wlc_upt",
+ "prebuilt_odm",
+ "prebuilt_vendor_dlkm",
+ "prebuilt_bt_firmware",
+ "prebuilt_tvservice",
+ "prebuilt_optee",
+ ).
+ DefinedInBpFile().
+ Because("module type not allowed to be defined in bp file")
+}
+
func neverallowMutator(ctx BottomUpMutatorContext) {
m, ok := ctx.Module().(Module)
if !ok {
@@ -354,6 +376,10 @@ func neverallowMutator(ctx BottomUpMutatorContext) {
continue
}
+ if !n.appliesToBpDefinedModule(ctx) {
+ continue
+ }
+
ctx.ModuleErrorf("violates " + n.String())
}
}
@@ -477,6 +503,8 @@ type Rule interface {
WithoutMatcher(properties string, matcher ValueMatcher) Rule
+ DefinedInBpFile() Rule
+
Because(reason string) Rule
}
@@ -498,6 +526,8 @@ type rule struct {
unlessProps ruleProperties
onlyBootclasspathJar bool
+
+ definedInBp bool
}
// Create a new NeverAllow rule.
@@ -571,6 +601,13 @@ func (r *rule) WithoutMatcher(properties string, matcher ValueMatcher) Rule {
return r
}
+// DefinedInBpFile specifies that this rule applies to modules that are defined
+// in bp files, and does not apply to modules that are auto generated by other modules.
+func (r *rule) DefinedInBpFile() Rule {
+ r.definedInBp = true
+ return r
+}
+
func selectMatcher(expected string) ValueMatcher {
if expected == "*" {
return anyMatcherInstance
@@ -665,6 +702,13 @@ func (r *rule) appliesToProperties(ctx BottomUpMutatorContext, properties []inte
return includeProps && !excludeProps
}
+func (r *rule) appliesToBpDefinedModule(ctx BottomUpMutatorContext) bool {
+ if !r.definedInBp {
+ return true
+ }
+ return !ctx.OtherModuleIsAutoGenerated(ctx.Module()) == r.definedInBp
+}
+
func StartsWith(prefix string) ValueMatcher {
return &startsWithMatcher{prefix}
}