Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request location permissions for BLE scan on Android 12 and older #126

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ The full list can be found in `dev.icerock.moko.permissions.Permission` enum.
* Bluetooth Scan: **Permission.BLUETOOTH_SCAN**
* Bluetooth Connect: **Permission.BLUETOOTH_CONNECT**
* Bluetooth Advertise: **Permission.BLUETOOTH_ADVERTISE**
* Contacts: **Permission.CONTACTS**
* Motion: **Permission.MOTION**

## Usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,26 +281,19 @@ class PermissionsControllerImpl(
* @see https://developer.android.com/guide/topics/connectivity/bluetooth/permissions
*/

private fun allBluetoothPermissions() =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
listOf(
Manifest.permission.BLUETOOTH_CONNECT,
Manifest.permission.BLUETOOTH_SCAN,
Manifest.permission.BLUETOOTH_ADVERTISE,
Manifest.permission.ACCESS_COARSE_LOCATION
)
} else {
listOf(
Manifest.permission.BLUETOOTH,
Manifest.permission.ACCESS_COARSE_LOCATION
)
}
private fun allBluetoothPermissions() = buildSet {
addAll(bluetoothConnectCompat())
addAll(bluetoothScanCompat())
addAll(bluetoothAdvertiseCompat())
}.toList()
Comment on lines +284 to +288
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed more maintainable (don't need to keep "all" aligned with the other specific permission types, at the expense of allocating a Set), let me know if you'd prefer me to use the static lists (as it was before).


private fun bluetoothScanCompat() =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
listOf(Manifest.permission.BLUETOOTH_SCAN)
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
listOf(Manifest.permission.ACCESS_FINE_LOCATION)
} else {
listOf(Manifest.permission.BLUETOOTH)
listOf(Manifest.permission.ACCESS_COARSE_LOCATION)
}

private fun bluetoothAdvertiseCompat() =
Expand Down