https://kotlinlang.org logo
#android
Title
# android
j

jishindev

11/15/2018, 4:22 PM
Can kotlin contracts be used for methods that do permission checks? Couldn't find any detailed doc regarding this.
g

gildor

11/15/2018, 5:23 PM
I highly doubt it. How would such support could look like?
j

jishindev

11/15/2018, 6:06 PM
I don't know if I understand contracts correctly but can it be used to take care of permission errors like in this case ?
Copy code
ifLocationPermsGranted {

fusedLocationProviderClient.lastLocation. ....
}
Right now, it shows the MissingPermission lint error on
fusedLocationProviderClient.lastLocation
.
r

rkeazor

11/15/2018, 8:03 PM
I think your misunderstanding kotlin contracts. Kotlin Contracts are used to give the compiler more information of what your particular function is doing, that way it can do things like smart casting
i

igor.wojda

11/15/2018, 9:29 PM
Iam with @rkeazor on this. You can reed this Keep to have better understanding fo coroutines https://github.com/Kotlin/KEEP/blob/master/proposals/kotlin-contracts.md
g

gildor

11/16/2018, 10:20 AM
@igor.wojda coroutines -> contracts
i

igor.wojda

11/16/2018, 10:21 AM
hmm…What exactly do you have in mind?
g

gildor

11/16/2018, 10:22 AM
You message, you wrote coroutines instead of contracts, I was confused %)
👍 1
@jishindev Yes, this particular lint check has nothing to do with Kotlin contracts. Instead android.support.annotations should provide some annotation to mark lambda as “permission provided”. It’s little bit similar to contracts, but not related, better report this to Android issue tracker
j

jishindev

11/16/2018, 11:05 AM
I see. I do need to read more about contracts. Thanks for the guidance. And yes, I'll put it up on the issue tracker. I found
@PackageManager.PermissionResult
inside the
Context
class used on the
checkSelfPermission()
method. But not so sure I can use it. It's unresolved on the package manager. Is there any other way to achieve the same behavior ? Which doesn't pop up lint errors like this one does ?
g

gildor

11/16/2018, 11:06 AM
Looks like some internal annotcation, but seems related to your case
3 Views