Android permissions do not follow official Android Bluetooth Permissions docs and react-native-ble-plx. Also, it should allow more granular control over which permissions are added based on the BLE usage. Issue #149 goes over some of the permissions' challenges and inconsistencies.
How
On a very high level, the permissions now follow this sample manifest and closely follows settings based on the comments.
<manifest>
<!-- Request legacy Bluetooth permissions on older devices. -->
<uses-permission android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30" />
<!-- Needed only if your app looks for Bluetooth devices.
If your app doesn't use Bluetooth scan results to derive physical
location information, you can strongly assert that your app
doesn't derive physical location. -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<!-- Needed only if your app makes the device discoverable to Bluetooth
devices. -->
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<!-- Needed only if your app communicates with already-paired Bluetooth
devices. -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<!-- Needed only if your app uses Bluetooth scan results to derive physical location. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
...
</manifest>
Options have been renamed and changed, and I implemented some warnings about this, which I have updated on the readme.
Here are the following options and an overview of what they are doing.
Android options
canDiscover (boolean): default:true - Indicates whether your app should have the permission to discover other Bluetooth devices. If set to true, android.permission.BLUETOOTH_ADMIN and android:maxSdkVersion is added conditioanlly based on legacy Android support. conditionally based on your settings.
canConnect (boolean): default:true - Specifies if your app requires the permission to connect to already-paired Bluetooth devices. If set to true, android.permission.BLUETOOTH_CONNECT will be added to AndroidManifest.xml.
neverForLocation (boolean): default:false - A flag you can set to true to assert that your app doesn't use BLE scan results to derive physical location. If true, "android:usesPermissionFlags": "neverForLocation" will be added to your "android.permission.BLUETOOTH_SCAN" declaration. Android SDK 31+. Default false. WARNING: This parameter is experimental and BLE might not work. Make sure to test before releasing to production.
isDiscoverable (boolean): default:false - Dictates whether or not your app is discoverable to other Bluetooth devices. If set to true, android.permission.BLUETOOTH_ADVERTISE will be added to AndroidManifest.xml.
isRequired (boolean): default:false - Determines whether or not your app requires Bluetooth to function. If set to true, <uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/> will be added to the AndroidManifest.xml.
The user most likely will have to do a npx expo prebuild --clean
Test Plan
I have implemented test for all the changes. But it would not hurt to do a quick spot check.
Why
Android permissions do not follow official Android Bluetooth Permissions docs and react-native-ble-plx. Also, it should allow more granular control over which permissions are added based on the BLE usage. Issue #149 goes over some of the permissions' challenges and inconsistencies.
How
On a very high level, the permissions now follow this sample manifest and closely follows settings based on the comments.
Options have been renamed and changed, and I implemented some warnings about this, which I have updated on the readme.
Here are the following options and an overview of what they are doing.
Android options
canDiscover
(boolean): default:true
- Indicates whether your app should have the permission to discover other Bluetooth devices. If set totrue
,android.permission.BLUETOOTH_ADMIN
andandroid:maxSdkVersion
is added conditioanlly based on legacy Android support. conditionally based on your settings.canConnect
(boolean): default:true
- Specifies if your app requires the permission to connect to already-paired Bluetooth devices. If set totrue
,android.permission.BLUETOOTH_CONNECT
will be added toAndroidManifest.xml
.neverForLocation
(boolean): default:false
- A flag you can set totrue
to assert that your app doesn't use BLE scan results to derive physical location. Iftrue
,"android:usesPermissionFlags": "neverForLocation"
will be added to your"android.permission.BLUETOOTH_SCAN"
declaration. Android SDK 31+. Defaultfalse
. WARNING: This parameter is experimental and BLE might not work. Make sure to test before releasing to production.isDiscoverable
(boolean): default:false
- Dictates whether or not your app is discoverable to other Bluetooth devices. If set totrue
,android.permission.BLUETOOTH_ADVERTISE
will be added toAndroidManifest.xml
.isRequired
(boolean): default:false
- Determines whether or not your app requires Bluetooth to function. If set totrue
,<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
will be added to theAndroidManifest.xml
.The user most likely will have to do a
npx expo prebuild --clean
Test Plan
I have implemented test for all the changes. But it would not hurt to do a quick spot check.