Can kotlin contracts be used for methods that do p...
# android
j
Can kotlin contracts be used for methods that do permission checks? Couldn't find any detailed doc regarding this.
g
I highly doubt it. How would such support could look like?
j
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
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
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
@igor.wojda coroutines -> contracts
i
hmm…What exactly do you have in mind?
g
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
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
Looks like some internal annotcation, but seems related to your case