New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 803105 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: Feb 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 3
Type: Bug



Sign in to add a comment

BluetoothAdapterAndroid should store pending SetPowered() callbacks and wait for ACTION_STATE_CHANGED

Project Member Reported by jdoerrie@chromium.org, Jan 17 2018

Issue description

On Android BluetoothAdapter::SetPowered() is implemented via android.bluetooth.BluetoothAdapter::enable() [1] which is an async operation. However, the current implementation does not wait for ACTION_STATE_CHANGED [2] and runs the callbacks immediately. This is a bug, as the callback is run before the state of the adapter actually changes. Also android.bluetooth.BluetoothAdapter::enable() can fail even if returning true, at which point the success callback mistakingly would have been run already.

Ideally SetPowered() stores the pending callbacks and runs them only after receiving the appropriate event. This is similar to how BluetoothRemoteGattCharacteristicAndroid::{Read,Write}RemoteCharacteristic are implemented [3].

[1] https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#enable()
[2] https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#ACTION_STATE_CHANGED
[3] https://cs.chromium.org/chromium/src/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc?l=125,149&rcl=868062045852303b6536137c48eb2ca1c55d4119
 

Comment 1 by cco3@chromium.org, Jan 17 2018

Owner: jdoerrie@chromium.org
Status: Started (was: Untriaged)
Project Member

Comment 2 by bugdroid1@chromium.org, Feb 14 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/8c849cb0acff947bc686b32740de58d2bc755b5b

commit 8c849cb0acff947bc686b32740de58d2bc755b5b
Author: Jan Wilken Dörrie <jdoerrie@chromium.org>
Date: Wed Feb 14 08:45:18 2018

[bluetooth] Enable Async BluetoothAdapterAndroid::SetPowered()

This change makes BluetoothAdapterAndroid::SetPowered() wait for
ACTION_STATE_CHANGED before running its success and error callbacks. The
same async behavior is introduced to the FakeAdapter for tests, allowing
more unit tests on Android to be enabled.

Bug:  803105 
Change-Id: I3e0f00e2b54583a0d715527939ceee4ad9dd5004
Reviewed-on: https://chromium-review.googlesource.com/875922
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: Conley Owens <cco3@chromium.org>
Cr-Commit-Position: refs/heads/master@{#536681}
[modify] https://crrev.com/8c849cb0acff947bc686b32740de58d2bc755b5b/device/bluetooth/bluetooth_adapter.cc
[modify] https://crrev.com/8c849cb0acff947bc686b32740de58d2bc755b5b/device/bluetooth/bluetooth_adapter.h
[modify] https://crrev.com/8c849cb0acff947bc686b32740de58d2bc755b5b/device/bluetooth/bluetooth_adapter_android.cc
[modify] https://crrev.com/8c849cb0acff947bc686b32740de58d2bc755b5b/device/bluetooth/bluetooth_adapter_android.h
[modify] https://crrev.com/8c849cb0acff947bc686b32740de58d2bc755b5b/device/bluetooth/bluetooth_adapter_mac.h
[modify] https://crrev.com/8c849cb0acff947bc686b32740de58d2bc755b5b/device/bluetooth/bluetooth_adapter_mac.mm
[modify] https://crrev.com/8c849cb0acff947bc686b32740de58d2bc755b5b/device/bluetooth/bluetooth_adapter_mac_unittest.mm
[modify] https://crrev.com/8c849cb0acff947bc686b32740de58d2bc755b5b/device/bluetooth/bluetooth_adapter_unittest.cc
[modify] https://crrev.com/8c849cb0acff947bc686b32740de58d2bc755b5b/device/bluetooth/bluetooth_adapter_win.cc
[modify] https://crrev.com/8c849cb0acff947bc686b32740de58d2bc755b5b/device/bluetooth/bluetooth_adapter_win.h
[modify] https://crrev.com/8c849cb0acff947bc686b32740de58d2bc755b5b/device/bluetooth/bluez/bluetooth_adapter_bluez.cc
[modify] https://crrev.com/8c849cb0acff947bc686b32740de58d2bc755b5b/device/bluetooth/bluez/bluetooth_adapter_bluez.h
[modify] https://crrev.com/8c849cb0acff947bc686b32740de58d2bc755b5b/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java
[modify] https://crrev.com/8c849cb0acff947bc686b32740de58d2bc755b5b/device/bluetooth/test/bluetooth_test_android.cc
[modify] https://crrev.com/8c849cb0acff947bc686b32740de58d2bc755b5b/device/bluetooth/test/bluetooth_test_mac.mm
[modify] https://crrev.com/8c849cb0acff947bc686b32740de58d2bc755b5b/device/bluetooth/test/fake_central.cc
[modify] https://crrev.com/8c849cb0acff947bc686b32740de58d2bc755b5b/device/bluetooth/test/fake_central.h
[modify] https://crrev.com/8c849cb0acff947bc686b32740de58d2bc755b5b/device/bluetooth/test/mock_bluetooth_adapter.cc
[modify] https://crrev.com/8c849cb0acff947bc686b32740de58d2bc755b5b/device/bluetooth/test/mock_bluetooth_adapter.h

Status: Fixed (was: Started)

Sign in to add a comment