Bug 1020736 - Wrap adapter's new properties for BluetoothManager::GetAdapters call in BluetoothServiceBluedroid, r=echou

This commit is contained in:
Ben Tian 2014-06-16 16:47:11 +08:00
Родитель afe1746ad2
Коммит 89b88ca8f4
3 изменённых файлов: 28 добавлений и 58 удалений

Просмотреть файл

@ -167,7 +167,7 @@ BluetoothService::ToggleBtAck::Run()
return NS_OK;
}
class BluetoothService::StartupTask : public nsISettingsServiceCallback
class BluetoothService::StartupTask MOZ_FINAL : public nsISettingsServiceCallback
{
public:
NS_DECL_ISUPPORTS

Просмотреть файл

@ -67,6 +67,8 @@ static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sUnbondingRunnableArray;
// Atomic static variables
static Atomic<bool> sAdapterDiscoverable(false);
static Atomic<bool> sAdapterDiscovering(false);
static Atomic<bool> sAdapterEnabled(false);
static Atomic<uint32_t> sAdapterDiscoverableTimeout(0);
/**
@ -303,23 +305,22 @@ AdapterStateChangeCallback(bt_state_t aStatus)
MOZ_ASSERT(!NS_IsMainThread());
BT_LOGR("BT_STATE: %d", aStatus);
sAdapterEnabled = (aStatus == BT_STATE_ON);
bool isBtEnabled = (aStatus == BT_STATE_ON);
if (!isBtEnabled &&
if (!sAdapterEnabled &&
NS_FAILED(NS_DispatchToMainThread(new CleanupTask()))) {
BT_WARNING("Failed to dispatch to main thread!");
return;
}
nsRefPtr<nsRunnable> runnable =
new BluetoothService::ToggleBtAck(isBtEnabled);
new BluetoothService::ToggleBtAck(sAdapterEnabled);
if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
BT_WARNING("Failed to dispatch to main thread!");
return;
}
if (isBtEnabled &&
if (sAdapterEnabled &&
NS_FAILED(NS_DispatchToMainThread(new SetupAfterEnabledTask()))) {
BT_WARNING("Failed to dispatch to main thread!");
return;
@ -381,13 +382,8 @@ AdapterPropertiesCallback(bt_status_t aStatus, int aNumProperties,
BT_APPEND_NAMED_VALUE(props, "Name", propertyValue);
} else if (p.type == BT_PROPERTY_ADAPTER_SCAN_MODE) {
bt_scan_mode_t newMode = *(bt_scan_mode_t*)p.val;
if (newMode == BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
propertyValue = sAdapterDiscoverable = true;
} else {
propertyValue = sAdapterDiscoverable = false;
}
propertyValue = sAdapterDiscoverable =
(newMode == BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
BT_APPEND_NAMED_VALUE(props, "Discoverable", propertyValue);
} else if (p.type == BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT) {
propertyValue = sAdapterDiscoverableTimeout = *(uint32_t*)p.val;
@ -598,6 +594,8 @@ DiscoveryStateChangedCallback(bt_discovery_state_t aState)
{
MOZ_ASSERT(!NS_IsMainThread());
sAdapterDiscovering = (aState == BT_DISCOVERY_STARTED);
// Redirect to main thread to avoid racing problem
NS_DispatchToMainThread(new DiscoveryStateChangedCallbackTask());
}
@ -714,19 +712,15 @@ BondStateChangedCallback(bt_status_t aStatus, bt_bdaddr_t* aRemoteBdAddress,
nsAutoString remoteBdAddress;
BdAddressTypeToString(aRemoteBdAddress, remoteBdAddress);
if (aState == BT_BOND_STATE_BONDED &&
sAdapterBondedAddressArray.Contains(remoteBdAddress)) {
// See bug 940271 for more details about this case.
return;
}
bool bonded;
if (aState == BT_BOND_STATE_NONE) {
bonded = false;
sAdapterBondedAddressArray.RemoveElement(remoteBdAddress);
} else if (aState == BT_BOND_STATE_BONDED) {
bonded = true;
bool bonded = (aState == BT_BOND_STATE_BONDED);
if (bonded) {
if (sAdapterBondedAddressArray.Contains(remoteBdAddress)) {
// See bug 940271 for more details about this case.
return;
}
sAdapterBondedAddressArray.AppendElement(remoteBdAddress);
} else {
sAdapterBondedAddressArray.RemoveElement(remoteBdAddress);
}
// Update bonded address list to BluetoothAdapter
@ -952,24 +946,20 @@ BluetoothServiceBluedroid::GetAdaptersInternal(
uint32_t numAdapters = 1; // Bluedroid supports single adapter only
for (uint32_t i = 0; i < numAdapters; i++) {
// Since Atomic<*> is not acceptable for BT_APPEND_NAMED_VALUE(),
// create another variable to store data.
bool discoverable = sAdapterDiscoverable;
uint32_t discoverableTimeout = sAdapterDiscoverableTimeout;
BluetoothValue properties = InfallibleTArray<BluetoothNamedValue>();
// TODO: Revise here based on new BluetoothAdapter interface
BT_APPEND_NAMED_VALUE(properties.get_ArrayOfBluetoothNamedValue(),
"State", BluetoothValue(sAdapterEnabled));
BT_APPEND_NAMED_VALUE(properties.get_ArrayOfBluetoothNamedValue(),
"Address", sAdapterBdAddress);
BT_APPEND_NAMED_VALUE(properties.get_ArrayOfBluetoothNamedValue(),
"Name", sAdapterBdName);
BT_APPEND_NAMED_VALUE(properties.get_ArrayOfBluetoothNamedValue(),
"Discoverable", discoverable);
"Discoverable",
BluetoothValue(sAdapterDiscoverable));
BT_APPEND_NAMED_VALUE(properties.get_ArrayOfBluetoothNamedValue(),
"DiscoverableTimeout", discoverableTimeout);
BT_APPEND_NAMED_VALUE(properties.get_ArrayOfBluetoothNamedValue(),
"Devices", sAdapterBondedAddressArray);
"Discovering",
BluetoothValue(sAdapterDiscovering));
BT_APPEND_NAMED_VALUE(adaptersProperties.get_ArrayOfBluetoothNamedValue(),
"Adapter", properties);
@ -1274,29 +1264,16 @@ BluetoothServiceBluedroid::SetPairingConfirmationInternal(
return true;
}
bool
BluetoothServiceBluedroid::SetAuthorizationInternal(
const nsAString& aDeviceAddress, bool aAllow,
BluetoothReplyRunnable* aRunnable)
{
return true;
}
nsresult
BluetoothServiceBluedroid::PrepareAdapterInternal()
{
return NS_OK;
}
static void
NextBluetoothProfileController()
{
MOZ_ASSERT(NS_IsMainThread());
// First, remove the task at the front which has been already done.
// Remove the completed task at the head
NS_ENSURE_FALSE_VOID(sControllerArray.IsEmpty());
sControllerArray.RemoveElementAt(0);
// Re-check if the task array is empty, if it's not, the next task will begin.
// Start the next task if task array is not empty
if (!sControllerArray.IsEmpty()) {
sControllerArray[0]->StartSession();
}

Просмотреть файл

@ -74,13 +74,6 @@ public:
SetPairingConfirmationInternal(const nsAString& aDeviceAddress, bool aConfirm,
BluetoothReplyRunnable* aRunnable);
virtual bool
SetAuthorizationInternal(const nsAString& aDeviceAddress, bool aAllow,
BluetoothReplyRunnable* aRunnable);
virtual nsresult
PrepareAdapterInternal();
virtual void
Connect(const nsAString& aDeviceAddress,
uint32_t aCod,