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

Commit c0857666 authored by Thiébaud Weksteen's avatar Thiébaud Weksteen Committed by Gerrit Code Review
Browse files

Merge changes I04c68e95,I9ab2b654,Ic0104961 into main

* changes:
  Add test for mis-annotated method
  Enable related issues in EnforcePermissionDetectorTest
  Allow short strings for manifest permissions in @EnforcePermission
parents 352e1eb9 9252e5ce
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ const val BINDER_CLASS = "android.os.Binder"
const val IINTERFACE_INTERFACE = "android.os.IInterface"

const val AIDL_PERMISSION_HELPER_SUFFIX = "_enforcePermission"
const val PERMISSION_PREFIX_LITERAL = "android.permission."

/**
 * If a non java (e.g. c++) backend is enabled, the @EnforcePermission
+17 −2
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ class EnforcePermissionDetector : Detector(), SourceCodeScanner {
            val v1 = ConstantEvaluator.evaluate(context, value1)
            val v2 = ConstantEvaluator.evaluate(context, value2)
            if (v1 != null && v2 != null) {
                if (v1 != v2) {
                if (v1 != v2 && !isOneShortPermissionOfOther(v1, v2)) {
                    return false
                }
            } else {
@@ -109,7 +109,7 @@ class EnforcePermissionDetector : Detector(), SourceCodeScanner {
                for (j in children1.indices) {
                    val c1 = ConstantEvaluator.evaluate(context, children1[j])
                    val c2 = ConstantEvaluator.evaluate(context, children2[j])
                    if (c1 != c2) {
                    if (c1 != c2 && !isOneShortPermissionOfOther(c1, c2)) {
                        return false
                    }
                }
@@ -118,6 +118,12 @@ class EnforcePermissionDetector : Detector(), SourceCodeScanner {
        return true
    }

    private fun isOneShortPermissionOfOther(
        permission1: Any?,
        permission2: Any?
    ): Boolean = permission1 == (permission2 as? String)?.removePrefix(PERMISSION_PREFIX_LITERAL) ||
            permission2 == (permission1 as? String)?.removePrefix(PERMISSION_PREFIX_LITERAL)

    private fun compareMethods(
        context: JavaContext,
        element: UElement,
@@ -191,6 +197,15 @@ class EnforcePermissionDetector : Detector(), SourceCodeScanner {
            /* Check that we are connected to the super class */
            val overridingMethod = node as PsiMethod
            val parents = overridingMethod.findSuperMethods()
            if (parents.isEmpty()) {
                context.report(
                    ISSUE_MISUSING_ENFORCE_PERMISSION,
                    node,
                    context.getLocation(node),
                    "The method ${node.name} does not override an AIDL generated method"
                )
                return
            }
            for (overriddenMethod in parents) {
                // The equivalence check can be skipped, if both methods are
                // annotated, it will be verified by visitAnnotationUsage.
+158 −62

File changed.

Preview size limit exceeded, changes collapsed.

+2 −1
Original line number Diff line number Diff line
@@ -28,7 +28,8 @@ class EnforcePermissionHelperDetectorCodegenTest : LintDetectorTest() {
    override fun getDetector(): Detector = EnforcePermissionDetector()

    override fun getIssues(): List<Issue> = listOf(
            EnforcePermissionDetector.ISSUE_ENFORCE_PERMISSION_HELPER
            EnforcePermissionDetector.ISSUE_ENFORCE_PERMISSION_HELPER,
            EnforcePermissionDetector.ISSUE_MISUSING_ENFORCE_PERMISSION
    )

    override fun lint(): TestLintTask = super.lint().allowMissingSdk(true)