permissions-dispatcher / PermissionsDispatcher

A declarative API to handle Android runtime permissions.
https://github.com/permissions-dispatcher/PermissionsDispatcher
Apache License 2.0
11.22k stars 1.44k forks source link

lint CallNeedsPermission on same named function #602

Closed repitch closed 5 years ago

repitch commented 5 years ago

502 - is almost the same except now both classes are annotated with @RuntimePermissions

Overview

I have two classes (i.e. Activities), both annotated with @RuntimePermissions, both contains same named function, but the first one is annotated with @NeedsPermission, the second one - is not

// MainActivity.kt

@RuntimePermissions
class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        someFunWithPermissionCheck()
    }

    @NeedsPermission(Manifest.permission.CAMERA)
    fun someFun() {
        Toast.makeText(this, "someFun!", Toast.LENGTH_SHORT).show()
    }
}

// SecondActivity.kt

@RuntimePermissions
class SecondActivity: AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        otherFunWithPermissionCheck()
        someFun()
    }

    // no annotation here
    fun someFun() {
        Toast.makeText(this, "someFun without permission", Toast.LENGTH_SHORT).show()
    }

    @NeedsPermission(Manifest.permission.CAMERA)
    fun otherFun() {
        Toast.makeText(this, "reallyRequiresPermission", Toast.LENGTH_SHORT).show()
    }
}

Both classes has someFun(), but the second one is not annotated, so it shouldn't be treated as an error

Expected

Lint will not show any error

Actual

/SecondActivity.kt:21: Error: Trying to access permission-protected method directly [CallNeedsPermission] someFun()

Environment

Reproducible steps

hotchemi commented 5 years ago

Thank you for your report! Would you mind open a pull request? You can reproduce the bug in CallNeedsPermissionDetectorTest and fix the logic at CallNeedsPermissionDetector 😃

https://github.com/permissions-dispatcher/PermissionsDispatcher/blob/0c1a6b423a16b71f2a0a1de372103132d80502fc/lint/src/test/java/permissions/dispatcher/CallNeedsPermissionDetectorTest.kt#L11 https://github.com/permissions-dispatcher/PermissionsDispatcher/blob/0c1a6b423a16b71f2a0a1de372103132d80502fc/lint/src/main/java/permissions/dispatcher/CallNeedsPermissionDetector.java#L27

hotchemi commented 5 years ago

@repitch 👀

repitch commented 5 years ago

@hotchemi I'll try to fix it and open a PR as soon as find some free time, maybe on the upcoming weekends!

eschoenawa commented 5 years ago

I am getting a similar problem with two methods in the same class, one annotated, one is not. One of the methods has a boolean parameter. So this doesn't only affect methods in seperate classes, but also ones with different parameter counts.

hotchemi commented 5 years ago

The original issue was resolved with #627 but https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/602#issuecomment-496225878 is kind of difficult to address...🤔Anyway let me create another issue for tracking.