Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly does Android's Bluetooth `autoConnect` parameter do?

See BluetoothDevice.connectGatt(). The description of autoConnect is

boolean: Whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device becomes available (true).

What exactly does this do? If it is false I suppose it must scan for the specific device for a short time, and give up if it is not found. But if it is true what does it do? Does it start scanning immediately? Does it scan forever? Does it scan periodically? If it disconnects does it automatically reconnect? When is Google going to start writing decent documentation?

Edit: I have traced the parameter to bt_gatt_client.h:

/** Create a connection to a remote LE or dual-mode device */
bt_status_t (*connect)(int server_if, const bt_bdaddr_t *bd_addr,
                       bool is_direct, int transport);

And a search for is_direct turns up some interesting results.

Here is a slightly longer explanation, but it still doesn't answer any questions.

The autoConnect parameter determines whether to actively connect to the remote device, or rather passively scan and finalize the connection when the remote device is in range/available. Generally, the first ever connection to a device should be direct (autoConnect set to false) and subsequent connections to known devices should be invoked with the autoConnect parameter set to true.

I also found this definition of the Android 5 Bluetooth HCI requirements which contains many useful details, but still no real answer about how autoconnect is supposed to work.

like image 873
Timmmm Avatar asked Jun 22 '16 10:06

Timmmm


People also ask

What is BLE autoConnect service?

The autoConnect parameter determines whether to actively connect to the remote device, or rather passively scan and finalize the connection when the remote device is in range/available.

How does Bluetooth Auto Connect work?

This means if you've already had your smartphone connected to the speaker, it will pair when you walk back into the room provided the speaker source is set to Bluetooth, and Bluetooth is enabled on your phone. Auto pairing will only remember the last device connected.

Does Android Auto automatically turn on Bluetooth?

This is also why turning off Bluetooth on either device will prevent the connection. You can't stop Android Auto from turning on Bluetooth because it's a necessary function of the system.

What is UUID in Android Bluetooth?

The UUID is used for uniquely identifying information. It identifies a particular service provided by a Bluetooth device. The standard defines a basic BASE_UUID: 00000000-0000-1000-8000-00805F9B34FB . Devices such as healthcare sensors can provide a service, substituting the first eight digits with a predefined code.


1 Answers

More details here on stack overflow: Which correct flag of autoConnect in connectGatt of BLE?

There are a few non-documented differences between direct and auto connect:

Direct connect is a connection attempt with a 30 seconds timeout. It will suspend all current auto connects while the direct connect is in progress. If there already is a direct connect pending, the last direct connect will not be executed immediately but rather be queued up and start when the previous has finished.

With auto connect you can have multiple pending connections at the same time and they will never time out (until explicitly aborted or until Bluetooth is turned off).

If the connection was established through an auto connect, Android will automatically try to reconnect to the remote device when it gets disconnected until you manually call disconnect() or close(). Once a connection established through direct connect disconnects, no attempt is made to reconnect to the remote device.

Direct connect has a different scan interval and scan window at a higher duty than auto connect, meaning it will dedicate more radio time to listen for connectable advertisements for the remote device, i.e. the connection will be established faster.

like image 166
Daniele Cux Avatar answered Nov 14 '22 09:11

Daniele Cux