fix(react-native-ble-plx) - Adjusted Android permissions #188
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.