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

BleError: Cannot start scanning operation on certain Android Phones #390

Closed
dested opened this issue Jan 9, 2019 · 10 comments
Closed

BleError: Cannot start scanning operation on certain Android Phones #390

dested opened this issue Jan 9, 2019 · 10 comments
Labels

Comments

@dested
Copy link

dested commented Jan 9, 2019

I am getting the above error on certain android phones when trying to initiate a scan. I am trying to track down exactly what version and model the phones are, but do you have any insight into what would cause this error to be thrown? The call I am making is manager.startDeviceScan([serviceId], {allowDuplicates: false}, async (error, device) => {});

Is it possible that this version of android doesn't support either allowDuplicates false or scanning by serviceId?

@Cierpliwy
Copy link
Contributor

One note: callback shouldn't be "async", startDeviceScan expects just normal function.

Can you specify which Android phones fail and what are their versions? Verbose logs from logcat would be helpful as well.

@hsmade
Copy link

hsmade commented Jan 29, 2019

I seem to have the same issue.
HW: Lenovo p2 (eu)
Android: 7.0

Logcat:

01-29 22:18:15.924 23913 23932 I ReactNativeJS: Running application "App" with appParams: {"rootTag":1}. __DEV__ === false, development-level warning are OFF, performance optimizations are ON
01-29 22:18:15.943 23913 23932 I ReactNativeJS: permission granted
01-29 22:18:15.944 23913 23932 I ReactNativeJS: BLE manager started
01-29 22:18:15.955  2626  2722 D BluetoothManagerService: Message: 20
01-29 22:18:15.955  2626  2722 D BluetoothManagerService: Added callback: android.bluetooth.IBluetoothManagerCallback$Stub$Proxy@2c663d6:true
01-29 22:18:16.010 23913 23960 D BluetoothAdapter: STATE_ON
01-29 22:18:16.015 12479 12491 D BtGatt.GattService: registerClient() - UUID=06c92c0b-e058-47dd-b0b7-3d1277960ccf
01-29 22:18:16.016 12479 12510 E bt_att  : GATT_Register: can't Register GATT client, MAX client reached!
01-29 22:18:16.016 12479 12510 E bt_btif : Register with GATT stack failed.
01-29 22:18:16.016 12479 12510 E bt_att  : GATT_Register: can't Register GATT client, MAX client reached!
01-29 22:18:16.016 12479 12510 E bt_btif : Register with GATT stack failed.
01-29 22:18:16.016 12479 12510 E bt_att  : GATT_Register: can't Register GATT client, MAX client reached!
01-29 22:18:16.016 12479 12510 E bt_btif : Register with GATT stack failed.
01-29 22:18:16.017 12479 12504 D BtGatt.GattService: onClientRegistered() - UUID=06c92c0b-e058-47dd-b0b7-3d1277960ccf, clientIf=0
01-29 22:18:16.018 23913 23925 D BluetoothLeScanner: onClientRegistered() - status=133 clientIf=0 mClientIf=0
01-29 22:18:16.022 23913 23960 D BluetoothAdapter: STATE_ON
01-29 22:18:16.022 23913 23960 D BluetoothLeScanner: could not find callback wrapper

Same apk/code does work on a Find 7 with android 8.1, but there I do have to open bluetooth settings and click 'pair new device' to manually start the scanner, or it won't find anything.
Logcat for that phone (working):

01-29 22:39:43.894 13064 13090 I ReactNativeJS: Running application "App" with appParams: {"rootTag":1}. __DEV__ === false, development-level warning are OFF, performance optimizations are ON
01-29 22:39:43.914 13064 13090 I ReactNativeJS: permission granted
01-29 22:39:43.915 13064 13090 I ReactNativeJS: BLE manager started
01-29 22:39:43.956 13064 13101 D BluetoothAdapter: isLeEnabled(): ON
01-29 22:39:43.962  5077  5792 I bt_stack: [INFO:gatt_api.cc(1004)] GATT_Register
01-29 22:39:43.962  5077  5792 I bt_stack: [INFO:gatt_api.cc(1027)] allocated gatt_if=9
01-29 22:39:43.962 13064 13078 D BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=9 mScannerId=0
01-29 22:39:44.435  3181  5859 I WifiService: getWifiEnabledState uid=10033
01-29 22:39:44.436  3181  5801 I WifiService: getConnectionInfo uid=10033
01-29 22:39:46.576  3181 12569 I WifiService: getWifiEnabledState uid=10033
01-29 22:39:46.576  3181  6176 I WifiService: getConnectionInfo uid=10033
01-29 22:39:46.578  3181  5289 I WifiService: getWifiEnabledState uid=10033
01-29 22:39:46.578  3181  5291 I WifiService: getConnectionInfo uid=10033
01-29 22:39:51.287  3181  3381 I WifiService: getWifiEnabledState uid=10033
01-29 22:39:51.288  3181 12571 I WifiService: getConnectionInfo uid=10033
01-29 22:39:51.290  3181 12568 I WifiService: getWifiEnabledState uid=10033
01-29 22:39:51.290  3181  6182 I WifiService: getConnectionInfo uid=10033
01-29 22:39:51.291  3181  5859 I WifiService: getWifiEnabledState uid=10033
01-29 22:39:51.291  3181  5801 I WifiService: getConnectionInfo uid=10033
01-29 22:39:51.294  3181  3346 I WifiService: getWifiEnabledState uid=10033
01-29 22:39:51.294  3181 12569 I WifiService: getConnectionInfo uid=10033
01-29 22:39:55.518  3181  6182 I ActivityManager: START u0 {act=android.settings.BLUETOOTH_SETTINGS flg=0x14000000 cmp=com.android.settings/.Settings$BluetoothSettingsActivity} from uid 10029
01-29 22:39:55.543  3181  6176 E ActivityManager: applyOptionsLocked: Unknown animationType=0
01-29 22:39:55.692 16823 16823 D BluetoothSettings: NO dashboard tiles for BluetoothSettings
01-29 22:39:55.696 16823 16823 D ProgressiveDisclosure: Cannot find preference with key pref_bt_pairing
01-29 22:39:55.697 16823 16823 D DashboardFragment: Cannot find preference with key pref_bt_pairing in Controller BluetoothPairingPreferenceController
01-29 22:39:55.722 16823 16823 D LocalBluetoothManager: setting foreground activity to non-null context
01-29 22:39:55.734  5077  5281 D BluetoothAdapterProperties: Discoverable Timeout:120
01-29 22:39:55.735  5077  5281 D BluetoothAdapterProperties: Scan Mode:23
01-29 22:39:57.211 16823 16823 D BluetoothPairingDetail: NO dashboard tiles for BluetoothPairingDetail
01-29 22:39:57.225 16823 16823 D LocalBluetoothManager: setting foreground activity to non-null context
01-29 22:39:57.226 16823 16823 D BluetoothAdapter: enable(): BT already enabled!
01-29 22:39:57.231  5077  5100 D BluetoothAdapterService: startDiscovery
01-29 22:39:57.232  5077  5792 E bt_btm  : BD Address not found!
01-29 22:39:57.232  5077  5792 E bt_btif : bte_scan_filt_param_cfg_evt, 1
01-29 22:39:57.232  5077  5792 W bt_btif : bta_dm_check_av:0
01-29 22:39:57.233  5077  5790 D bt_hci  : get_waiting_command VS event found treat it as valid 0xffff
01-29 22:39:57.234  5077  5792 E bt_btm  : btm_flt_update_cb: bad length: 1
01-29 22:39:57.258  5077  5281 D bt_btif_config: btif_get_device_type: Device [XX:XX:XX:XX:XX:XX] type 2
01-29 22:39:57.264 16823 12868 D Settings: No enabled state changed, skipping updateCategory call
01-29 22:39:57.309 16823 16823 D LocalBluetoothProfileManager: Handsfree Uuid not found.
01-29 22:39:57.309 16823 16823 D LocalBluetoothProfileManager: MAP Client Uuid not found.
01-29 22:39:57.314  3181  3640 I ActivityManager: Displayed com.android.settings/.SubSettings: +138ms
01-29 22:39:57.326 16823 16823 D BluetoothEventManager: DeviceFoundHandler created new CachedBluetoothDevice: XX:XX:XX:XX:XX:XX
01-29 22:39:57.469 13064 13101 D BluetoothAdapter: isLeEnabled(): ON
01-29 22:39:57.498 13064 13101 D BluetoothGatt: connect() - device: XX:XX:XX:XX:XX:XX, auto: false

@hsmade
Copy link

hsmade commented Jan 30, 2019

More info, when the scanning failed, the original error in java was:
{"errorCode":600,"attErrorCode":6,"iosErrorCode": null,"androidErrorCode":null,"reason":"Scan failed because application registration failed (code 6)","deviceID":null,"serviceUUID":null,"characteristicUUID":null,"descriptorUUID":null,"internalMessage":null}

@hsmade
Copy link

hsmade commented Jan 30, 2019

When I disable bluetooth, then start the app, wait for a bit and re-enable bluetooth, the scanning works. However, it disconnects after a few seconds. This smells of an Android bug

@Cierpliwy
Copy link
Contributor

01-29 22:18:16.016 12479 12510 E bt_att : GATT_Register: can't Register GATT client, MAX client reached!

This is generally bad. It means that all applications on Android used up all GATT clients and therefore your app won't be able to do anything.

Please make sure that your application has ACCESS_COARSE_LOCATION enabled (it is a dangerous permission) as well as location enabled (GPS symbol).

@hsmade
Copy link

hsmade commented Feb 1, 2019

Hey,

I have both enabled. It works on another phone. I can also get it to work after a reboot, if no other apps started running. I'm guessing this is either a bug in android, or some issue with one of the apps (nrf connect?) that I have installed. Not much to be fixed here in code, I'm afraid. Apart from maybe be a bit more verbose in the error message (why was scanning not started?), as we have that info in the java BleError class.

@stale
Copy link

stale bot commented Apr 2, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 2, 2019
@Cierpliwy
Copy link
Contributor

Closing, as this is probably not an issue in library itself.

@jbreuer95
Copy link

I ran into this problem and found some conditions when it occurs and how to prevent it;

  1. It mostly seems to happen on cheaper android phones.
  2. When you are developing and have fast refresh enabled make sure you properly destroy the old ble manager and start a new one. If you don't, you start multiple ble managers and multiple scans at the same time. This will cause this error for sure. Put a console.log in your scan function to monitor for this.
  3. Dont make your scans very short. I get this sometimes when my scans are 1 or 2 seconds. I now have them at 6 seconds and i dont see this error anymore

@Davidson-09
Copy link

how do I increase scan time ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants