diff --git a/dom/bluetooth/BluetoothService.cpp b/dom/bluetooth/BluetoothService.cpp index ed832f904cd..df672f1972b 100644 --- a/dom/bluetooth/BluetoothService.cpp +++ b/dom/bluetooth/BluetoothService.cpp @@ -447,61 +447,82 @@ BluetoothService::DistributeSignal(const BluetoothSignal& aSignal) } nsresult -BluetoothService::StartStopBluetooth(bool aStart, bool aIsStartup) +BluetoothService::StartBluetooth(bool aIsStartup) { MOZ_ASSERT(NS_IsMainThread()); if (sInShutdown) { - if (aStart) { - // Don't try to start if we're already shutting down. - MOZ_ASSERT(false, "Start called while in shutdown!"); - return NS_ERROR_FAILURE; - } - } - - if (!aStart) { - BluetoothProfileManagerBase* profile; - profile = BluetoothHfpManager::Get(); - NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE); - if (profile->IsConnected()) { - profile->Disconnect(nullptr); - } else { - profile->Reset(); - } - - profile = BluetoothOppManager::Get(); - NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE); - if (profile->IsConnected()) { - profile->Disconnect(nullptr); - } - - profile = BluetoothA2dpManager::Get(); - NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE); - if (profile->IsConnected()) { - profile->Disconnect(nullptr); - } else { - profile->Reset(); - } - - profile = BluetoothHidManager::Get(); - NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE); - if (profile->IsConnected()) { - profile->Disconnect(nullptr); - } else { - profile->Reset(); - } - + // Don't try to start if we're already shutting down. + MOZ_ASSERT(false, "Start called while in shutdown!"); + return NS_ERROR_FAILURE; } mAdapterAddedReceived = false; - nsCOMPtr runnable = new ToggleBtTask(aStart, aIsStartup); + nsCOMPtr runnable = new ToggleBtTask(true, aIsStartup); nsresult rv = NS_DispatchToMainThread(runnable); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; } +nsresult +BluetoothService::StopBluetooth(bool aIsStartup) +{ + MOZ_ASSERT(NS_IsMainThread()); + + BluetoothProfileManagerBase* profile; + profile = BluetoothHfpManager::Get(); + NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE); + if (profile->IsConnected()) { + profile->Disconnect(nullptr); + } else { + profile->Reset(); + } + + profile = BluetoothOppManager::Get(); + NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE); + if (profile->IsConnected()) { + profile->Disconnect(nullptr); + } + + profile = BluetoothA2dpManager::Get(); + NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE); + if (profile->IsConnected()) { + profile->Disconnect(nullptr); + } else { + profile->Reset(); + } + + profile = BluetoothHidManager::Get(); + NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE); + if (profile->IsConnected()) { + profile->Disconnect(nullptr); + } else { + profile->Reset(); + } + + mAdapterAddedReceived = false; + + nsCOMPtr runnable = new ToggleBtTask(false, aIsStartup); + nsresult rv = NS_DispatchToMainThread(runnable); + NS_ENSURE_SUCCESS(rv, rv); + + return NS_OK; +} + +nsresult +BluetoothService::StartStopBluetooth(bool aStart, bool aIsStartup) +{ + nsresult rv; + if (aStart) { + rv = StartBluetooth(aIsStartup); + } else { + rv = StopBluetooth(aIsStartup); + } + return rv; +} + void BluetoothService::SetEnabled(bool aEnabled) { @@ -714,7 +735,7 @@ BluetoothService::HandleShutdown() } } - if (IsEnabled() && NS_FAILED(StartStopBluetooth(false, false))) { + if (IsEnabled() && NS_FAILED(StopBluetooth(false))) { MOZ_ASSERT(false, "Failed to deliver stop message!"); } diff --git a/dom/bluetooth/BluetoothService.h b/dom/bluetooth/BluetoothService.h index 927718f9d6b..7acb3dd32f6 100644 --- a/dom/bluetooth/BluetoothService.h +++ b/dom/bluetooth/BluetoothService.h @@ -332,6 +332,12 @@ protected: void Cleanup(); + nsresult + StartBluetooth(bool aIsStartup); + + nsresult + StopBluetooth(bool aIsStartup); + nsresult StartStopBluetooth(bool aStart, bool aIsStartup);