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

fix(react-native-ble-plx) - Adjusted Android permissions #188

Closed
wants to merge 3 commits into from

Conversation

leoafarias
Copy link

@leoafarias leoafarias commented Sep 6, 2023

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.

<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.

@leoafarias leoafarias changed the title Updated android permissions fix(react-native-ble-plx) - Adjusted permissions based on the official Android bluetooth permissions and react-native-ble-plx Sep 6, 2023
@leoafarias leoafarias changed the title fix(react-native-ble-plx) - Adjusted permissions based on the official Android bluetooth permissions and react-native-ble-plx fix(react-native-ble-plx) - Adjusted Android permissions Sep 6, 2023
@leoafarias
Copy link
Author

I am closing as there is no review, and I believe there is now an expo plugin as part of the package itself.

@leoafarias leoafarias closed this Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant