https://kotlinlang.org logo
#compose
Title
# compose
l

Lilly

06/03/2022, 12:34 AM
What is the recommended way to handle these false positive warnings about
Add permission check
in composables?:
Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException
With Android 12 this shit becomes really confusing. Anything that is not like:
Copy code
if (ActivityCompat.checkSelfPermission(
            this,
            Manifest.permission.BLUETOOTH_CONNECT
        ) != PackageManager.PERMISSION_GRANTED
    ) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return
    }
    val deviceName: String? = sharedPresenter.connectedDevice?.name // no warning
will be reported as if the permission has never been granted, which is technically wrong. But the example above is no real world use case and also verbose and leads to duplicated code. That's why accompanist has its
rememberPermissionState
API. But using this API does not prevent the warning.
j

Joseph Hawkes-Cates

06/03/2022, 4:30 AM
I’m not familiar with this particular issue, but there’s a suppressWarning annotation you can add from the suggestion for handling the warning in AS. There’s an option to add it to the file, function, or field. If you know that the warning is safe to ignore, then that’ll get it out of your way.
c

Colton Idle

06/03/2022, 10:31 AM
I'd probably file a bug with lint (Tor is really fast at triaging these). Every time I complain about something I get a fix in like the next version of AGP/Lint. I will say that one of the mottos of lint (I think from a talk Tor gave at KotlinConf) was to favor false positives so that you dont have to run into issues at runtime and allow the user to opt out. I wonder if this would fall into this category. But on the other hand. I've definitely encountered this issue myself of lint not being smart enough about a permission check and it does get annoying. If you file a bug I will
🧠 1
l

Lilly

06/03/2022, 1:10 PM
@Colton Idle I already filed a bug a month ago, and there was also another bug reported regarding this issue, see https://issuetracker.google.com/issues/201454155 There is a link to mine issue. So for now I have to throw
@Supress("MissingPermission")
annotations everywhere...
c

Colton Idle

06/03/2022, 2:41 PM
Upvoted both!
❤️ 1
155 Views