Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5c45ce22 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Support Kotlin implementation for EnforcePermissionDetector" into main

parents c92498c7 583fe724
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -88,7 +88,9 @@ class EnforcePermissionDetector : Detector(), SourceCodeScanner {
            return false
        }
        for (i in overridingAttributes.indices) {
            if (overridingAttributes[i].name != overriddenAttributes[i].name) {
            val overridingAttrName = overridingAttributes[i].name ?: "value"
            val overriddenAttrName = overriddenAttributes[i].name ?: "value"
            if (overridingAttrName != overriddenAttrName) {
                return false
            }
            val value1 = overridingAttributes[i].value ?: return false
@@ -171,7 +173,7 @@ class EnforcePermissionDetector : Detector(), SourceCodeScanner {
            if (getContainingAidlInterface(context, uMethod) == null) {
                return
            }
            val overridingMethod = element.sourcePsi as PsiMethod
            val overridingMethod = element.javaPsi as PsiMethod
            val overriddenMethod = usageInfo.referenced as PsiMethod
            compareMethods(context, element, overridingMethod, overriddenMethod)
        }
+24 −1
Original line number Diff line number Diff line
@@ -54,6 +54,24 @@ class EnforcePermissionDetectorTest : LintDetectorTest() {
        .expectClean()
    }

    fun testDoesNotDetectIssuesCorrectAnnotationOnMethodKotlin() {
        lint().files(kotlin(
            """
            package test.pkg
            import android.annotation.EnforcePermission
            public class TestClass2 : IFooMethod.Stub {
                @EnforcePermission(android.Manifest.permission.READ_PHONE_STATE)
                override fun testMethod() {
                    testMethod_enforcePermission()
                }
            }
            """).indented(),
                *stubs
        )
        .run()
        .expectClean()
    }

    fun testDoesNotDetectIssuesCorrectAnnotationAllOnMethod() {
        lint().files(java(
            """
@@ -487,6 +505,7 @@ class EnforcePermissionDetectorTest : LintDetectorTest() {
        """
        public interface IFooMethod extends android.os.IInterface {
         public static abstract class Stub extends android.os.Binder implements IFooMethod {
             protected void testMethod_enforcePermission() {}
          }
          @android.annotation.EnforcePermission(android.Manifest.permission.READ_PHONE_STATE)
          public void testMethod();
@@ -532,7 +551,11 @@ class EnforcePermissionDetectorTest : LintDetectorTest() {
    private val enforcePermissionAnnotationStub: TestFile = java(
        """
        package android.annotation;
        public @interface EnforcePermission {}
        public @interface EnforcePermission {
            String value() default "";
            String[] allOf() default {};
            String[] anyOf() default {};
        }
        """
    ).indented()