add bluetooth_connect permission checks

This commit is contained in:
andrekir 2022-01-31 21:19:54 -03:00
parent a2f5d74bfc
commit dc852b97ba
3 changed files with 44 additions and 28 deletions

View file

@ -29,6 +29,24 @@ fun Context.getMissingPermissions(perms: List<String>) = perms.filter {
) != PackageManager.PERMISSION_GRANTED
}
/**
* Bluetooth connect permissions (or empty if we already have what we need)
*/
fun Context.getConnectPermissions(): List<String> {
val perms = mutableListOf<String>()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
perms.add(Manifest.permission.BLUETOOTH_CONNECT)
} else {
perms.add(Manifest.permission.BLUETOOTH)
}
return getMissingPermissions(perms)
}
/** @return true if the user already has Bluetooth connect permission */
fun Context.hasConnectPermission() = getConnectPermissions().isEmpty()
/**
* Bluetooth scan/discovery permissions (or empty if we already have what we need)
*/