CHROMIUM: bluetooth: fix a regression about power off delay

Conditional commands were introduced to fix run-time race conditions
for advertising and scanning. To use conditional commands, all
enabling and disabling commands for advertising and scanning are
added to the command queue at command build time. And then
the command worker thread will check if such a conditional command
should be executed or skipped at command run time.

This may result in a regression when powering off the bluetooth
adapter. When powering off the bluetooth adapter, kernel may
send a variety of commands to stop all bluetooth activities and
wait for 5 seconds before forcing to power off the adapter.

There are two shortcuts to avoid the 5-second long delay. The
first shortcut is taken when there are no HCI commands built
at all at command built time. The kernel would power off the
bluetooth adapter immediately. The second shortcut is taken
when the last command of the request is completed. In this case,
the clean_up_hci_complete() callback is invoked to power off
the bluetooth adapter immediately.

The power off regression occurs when the last command in the
request is a conditional command and is skipped. In this case,
no clean_up_hci_complete() callback would be invoked. The
bluetooth adapter cannot be powered off until the 5-second
timeout expires.

This patch temporarily fixed the regression by adding a dummy
command as the last command in the request. This ensures that
the clean_up_hci_complete() callback is invoked to power off
the bluetooth adapter.

As adding a dummy command is kind of hacky, it is desirable to
have a formal fix which is being tracked in chromium:808749
Bluez: clean up dummy commands used for conditional HCI command.

BUG=chromium:805329
TEST=Conduct the following two tests with bluetoothctl
$ bluetoothctl
[bluetooth]# power off

Test 1: set power off when magic tethering is not running and there are
no other bluetooth activities (advertising, scanning, and connections)
ongoing.

Test 2: set power off when magic tethering is running.

The power off should take effect immediately in both tests.

Change-Id: If014efe56200c2a9a81fa8711d53ef1bf37e857c
Signed-off-by: Joseph Hwang <josephsih@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/896670
Commit-Ready: Shyh-In Hwang <josephsih@chromium.org>
Tested-by: Sonny Sasaka <sonnysasaka@chromium.org>
Tested-by: Shyh-In Hwang <josephsih@chromium.org>
Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Reviewed-by: Dmitry Grinberg <dmitrygr@google.com>
(cherry picked from commit e03072ba645077f98249a2451519db61d9246706)
Reviewed-on: https://chromium-review.googlesource.com/936403
Reviewed-by: Sonny Sasaka <sonnysasaka@chromium.org>
1 file changed