diff --git a/dom/bluetooth2/bluedroid/BluetoothServiceBluedroid.cpp b/dom/bluetooth2/bluedroid/BluetoothServiceBluedroid.cpp index 1e90cb734ffe..e5e20ef2124d 100644 --- a/dom/bluetooth2/bluedroid/BluetoothServiceBluedroid.cpp +++ b/dom/bluetooth2/bluedroid/BluetoothServiceBluedroid.cpp @@ -831,7 +831,7 @@ EnableInternal() } static nsresult -StartStopGonkBluetooth(bool aShouldEnable) +StartGonkBluetooth() { MOZ_ASSERT(NS_IsMainThread()); @@ -840,17 +840,43 @@ StartStopGonkBluetooth(bool aShouldEnable) BluetoothService* bs = BluetoothService::Get(); NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE); - if (bs->IsEnabled() == aShouldEnable) { + if (bs->IsEnabled()) { // Keep current enable status nsRefPtr runnable = - new BluetoothService::ToggleBtAck(aShouldEnable); + new BluetoothService::ToggleBtAck(true); if (NS_FAILED(NS_DispatchToMainThread(runnable))) { BT_WARNING("Failed to dispatch to main thread!"); } return NS_OK; } - int ret = aShouldEnable ? EnableInternal() : sBtInterface->Disable(); + int ret = EnableInternal(); + NS_ENSURE_TRUE(ret == BT_STATUS_SUCCESS, NS_ERROR_FAILURE); + + return NS_OK; +} + +static nsresult +StopGonkBluetooth() +{ + MOZ_ASSERT(NS_IsMainThread()); + + NS_ENSURE_TRUE(sBtInterface, NS_ERROR_FAILURE); + + BluetoothService* bs = BluetoothService::Get(); + NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE); + + if (!bs->IsEnabled()) { + // Keep current enable status + nsRefPtr runnable = + new BluetoothService::ToggleBtAck(false); + if (NS_FAILED(NS_DispatchToMainThread(runnable))) { + BT_WARNING("Failed to dispatch to main thread!"); + } + return NS_OK; + } + + int ret = sBtInterface->Disable(); NS_ENSURE_TRUE(ret == BT_STATUS_SUCCESS, NS_ERROR_FAILURE); return NS_OK; @@ -910,7 +936,7 @@ BluetoothServiceBluedroid::StartInternal(BluetoothReplyRunnable* aRunnable) sChangeAdapterStateRunnableArray.AppendElement(aRunnable); } - nsresult ret = StartStopGonkBluetooth(true); + nsresult ret = StartGonkBluetooth(); if (NS_FAILED(ret)) { nsRefPtr runnable = new BluetoothService::ToggleBtAck(false); @@ -942,7 +968,7 @@ BluetoothServiceBluedroid::StopInternal(BluetoothReplyRunnable* aRunnable) sChangeAdapterStateRunnableArray.AppendElement(aRunnable); } - nsresult ret = StartStopGonkBluetooth(false); + nsresult ret = StopGonkBluetooth(); if (NS_FAILED(ret)) { nsRefPtr runnable = new BluetoothService::ToggleBtAck(true);