diff options
| author | 2021-05-04 16:49:12 -0700 | |
|---|---|---|
| committer | 2021-05-06 14:04:01 -0700 | |
| commit | 850f8aa4d96544d533c45f60bb8e91859f50baf3 (patch) | |
| tree | b3c240d93c9be38d2d59a6388c83b42f0759917a /errorprone/java | |
| parent | edbef14097ae17b7c448fbd957ac8c711de657b9 (diff) | |
Extend errorprone checks for unattributed calls
Support warnings for the following methods as well:
noteOpNoThrow
startOp
startOpNoThrow
noteProxyOp
noteProxyOpNoThrow
finishOp
Bug: 186785930
Test: atest error_prone_android_framework_test:com.google.errorprone.bugpatterns.android.UnattributedNoteOpCallCheckerTest
Change-Id: I3a30f32cfb48a20b90682b28b709b086b8bb6b35
Diffstat (limited to 'errorprone/java')
| -rw-r--r-- | errorprone/java/com/google/errorprone/bugpatterns/android/UnattributedNoteOpCallChecker.java | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/errorprone/java/com/google/errorprone/bugpatterns/android/UnattributedNoteOpCallChecker.java b/errorprone/java/com/google/errorprone/bugpatterns/android/UnattributedNoteOpCallChecker.java index d39978f54ebc..3d7b94f880ac 100644 --- a/errorprone/java/com/google/errorprone/bugpatterns/android/UnattributedNoteOpCallChecker.java +++ b/errorprone/java/com/google/errorprone/bugpatterns/android/UnattributedNoteOpCallChecker.java @@ -47,6 +47,54 @@ public final class UnattributedNoteOpCallChecker extends BugChecker private static final Matcher<ExpressionTree> UNATTRIBUTED_NOTEOP_CALL_3 = methodInvocation( instanceMethod().onExactClass("android.app.AppOpsManager") .withSignature("noteOp(int)")); + private static final Matcher<ExpressionTree> UNATTRIBUTED_NOTEOPNOTHROW_CALL_1 = methodInvocation( + instanceMethod().onExactClass("android.app.AppOpsManager") + .withSignature("noteOpNoThrow(int,int,java.lang.String)")); + private static final Matcher<ExpressionTree> UNATTRIBUTED_NOTEOPNOTHROW_CALL_2 = methodInvocation( + instanceMethod().onExactClass("android.app.AppOpsManager") + .withSignature("noteOpNoThrow(java.lang.String,int,java.lang.String)")); + private static final Matcher<ExpressionTree> UNATTRIBUTED_STARTOP_CALL_1 = methodInvocation( + instanceMethod().onExactClass("android.app.AppOpsManager") + .withSignature("startOp(java.lang.String,int,java.lang.String)")); + private static final Matcher<ExpressionTree> UNATTRIBUTED_STARTOP_CALL_2 = methodInvocation( + instanceMethod().onExactClass("android.app.AppOpsManager") + .withSignature("startOp(int,int,java.lang.String)")); + private static final Matcher<ExpressionTree> UNATTRIBUTED_STARTOP_CALL_3 = methodInvocation( + instanceMethod().onExactClass("android.app.AppOpsManager") + .withSignature("startOp(int)")); + private static final Matcher<ExpressionTree> UNATTRIBUTED_STARTOP_CALL_4 = methodInvocation( + instanceMethod().onExactClass("android.app.AppOpsManager") + .withSignature("startOp(int,int,java.lang.String,boolean)")); + private static final Matcher<ExpressionTree> UNATTRIBUTED_STARTOPNOTHROW_CALL_1 = methodInvocation( + instanceMethod().onExactClass("android.app.AppOpsManager") + .withSignature("startOpNoThrow(java.lang.String,int,java.lang.String)")); + private static final Matcher<ExpressionTree> UNATTRIBUTED_STARTOPNOTHROW_CALL_2 = methodInvocation( + instanceMethod().onExactClass("android.app.AppOpsManager") + .withSignature("startOpNoThrow(int,int,java.lang.String)")); + private static final Matcher<ExpressionTree> UNATTRIBUTED_STARTOPNOTHROW_CALL_3 = methodInvocation( + instanceMethod().onExactClass("android.app.AppOpsManager") + .withSignature("startOpNoThrow(int,int,java.lang.String,boolean)")); + private static final Matcher<ExpressionTree> UNATTRIBUTED_NOTEPROXYOP_CALL_1 = methodInvocation( + instanceMethod().onExactClass("android.app.AppOpsManager") + .withSignature("noteProxyOp(java.lang.String,java.lang.String)")); + private static final Matcher<ExpressionTree> UNATTRIBUTED_NOTEPROXYOP_CALL_2 = methodInvocation( + instanceMethod().onExactClass("android.app.AppOpsManager") + .withSignature("noteProxyOp(int,java.lang.String)")); + private static final Matcher<ExpressionTree> UNATTRIBUTED_NOTEPROXYOPNOTHROW_CALL_1 = methodInvocation( + instanceMethod().onExactClass("android.app.AppOpsManager") + .withSignature("noteProxyOpNoThrow(java.lang.String,java.lang.String)")); + private static final Matcher<ExpressionTree> UNATTRIBUTED_NOTEPROXYOPNOTHROW_CALL_2 = methodInvocation( + instanceMethod().onExactClass("android.app.AppOpsManager") + .withSignature("noteProxyOpNoThrow(java.lang.String,java.lang.String,int)")); + private static final Matcher<ExpressionTree> UNATTRIBUTED_FINISHOP_CALL_1 = methodInvocation( + instanceMethod().onExactClass("android.app.AppOpsManager") + .withSignature("finishOp(int)")); + private static final Matcher<ExpressionTree> UNATTRIBUTED_FINISHOP_CALL_2 = methodInvocation( + instanceMethod().onExactClass("android.app.AppOpsManager") + .withSignature("finishOp(java.lang.String,int,java.lang.String)")); + private static final Matcher<ExpressionTree> UNATTRIBUTED_FINISHOP_CALL_3 = methodInvocation( + instanceMethod().onExactClass("android.app.AppOpsManager") + .withSignature("finishOp(int,int,java.lang.String)")); @Override public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { @@ -57,6 +105,49 @@ public final class UnattributedNoteOpCallChecker extends BugChecker .setMessage("Unattributed noteOp call! Please use noteOp(int, String, String, String) or noteOp(int, CallerIdentity)") .build(); } + if (UNATTRIBUTED_NOTEOPNOTHROW_CALL_1.matches(tree, state) + || UNATTRIBUTED_NOTEOPNOTHROW_CALL_2.matches(tree, state)) { + return buildDescription(tree) + .setMessage("Unattributed noteOpNoThrow call! Please use noteOpNoThrow(String, int, String, String, String)") + .build(); + } + if (UNATTRIBUTED_STARTOP_CALL_1.matches(tree, state) + || UNATTRIBUTED_STARTOP_CALL_2.matches(tree, state) + || UNATTRIBUTED_STARTOP_CALL_3.matches(tree, state) + || UNATTRIBUTED_STARTOP_CALL_4.matches(tree, state)) { + return buildDescription(tree) + .setMessage("Unattributed startOp call! Please use startOp(int, int, String, boolean, String, String)") + .build(); + } + if (UNATTRIBUTED_STARTOPNOTHROW_CALL_1.matches(tree, state) + || UNATTRIBUTED_STARTOPNOTHROW_CALL_2.matches(tree, state) + || UNATTRIBUTED_STARTOPNOTHROW_CALL_3.matches(tree, state)) { + return buildDescription(tree) + .setMessage("Unattributed startOpNoThrow call!") + .build(); + } + if (UNATTRIBUTED_NOTEPROXYOP_CALL_1.matches(tree, state) + || UNATTRIBUTED_NOTEPROXYOP_CALL_2.matches(tree, state)) { + return buildDescription(tree) + .setMessage("Unattributed noteProxyOp call!") + .build(); + } + if (UNATTRIBUTED_NOTEPROXYOPNOTHROW_CALL_1.matches(tree, state) + || UNATTRIBUTED_NOTEPROXYOPNOTHROW_CALL_2.matches(tree, state)) { + return buildDescription(tree) + .setMessage("Unattributed noteProxyOpNoThrow call!") + .build(); + } + if (UNATTRIBUTED_FINISHOP_CALL_1.matches(tree, state) + || UNATTRIBUTED_FINISHOP_CALL_2.matches(tree, state) + || UNATTRIBUTED_FINISHOP_CALL_3.matches(tree, state)) { + return buildDescription(tree) + .setMessage("Unattributed finishOp call!") + .build(); + } + + + return Description.NO_MATCH; } } |