diff --git a/dom/bluetooth/BluetoothHfpManager.cpp b/dom/bluetooth/BluetoothHfpManager.cpp index 4a1061f1c06..2238caeeb06 100644 --- a/dom/bluetooth/BluetoothHfpManager.cpp +++ b/dom/bluetooth/BluetoothHfpManager.cpp @@ -1026,15 +1026,22 @@ BluetoothHfpManager::Connect(const nsAString& aDeviceAddress, { MOZ_ASSERT(NS_IsMainThread()); - NS_ENSURE_FALSE_VOID(gInShutdown); - NS_ENSURE_FALSE_VOID(mSocket); + BluetoothService* bs = BluetoothService::Get(); + if (!bs || gInShutdown) { + DispatchBluetoothReply(aRunnable, BluetoothValue(), + NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE)); + return; + } + + if (mSocket) { + DispatchBluetoothReply(aRunnable, BluetoothValue(), + NS_LITERAL_STRING(ERR_REACHED_CONNECTION_LIMIT)); + return; + } mNeedsUpdatingSdpRecords = true; mIsHandsfree = aIsHandsfree; - BluetoothService* bs = BluetoothService::Get(); - NS_ENSURE_TRUE_VOID(bs); - nsString uuid; if (aIsHandsfree) { BluetoothUuidHelper::GetString(BluetoothServiceClass::HANDSFREE, uuid); diff --git a/dom/bluetooth/BluetoothOppManager.cpp b/dom/bluetooth/BluetoothOppManager.cpp index a8ef8f4f6b4..6ec66e19a37 100644 --- a/dom/bluetooth/BluetoothOppManager.cpp +++ b/dom/bluetooth/BluetoothOppManager.cpp @@ -257,10 +257,18 @@ BluetoothOppManager::Connect(const nsAString& aDeviceAddress, { MOZ_ASSERT(NS_IsMainThread()); - NS_ENSURE_FALSE_VOID(mSocket); - BluetoothService* bs = BluetoothService::Get(); - NS_ENSURE_TRUE_VOID(bs); + if (!bs || sInShutdown) { + DispatchBluetoothReply(aRunnable, BluetoothValue(), + NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE)); + return; + } + + if (mSocket) { + DispatchBluetoothReply(aRunnable, BluetoothValue(), + NS_LITERAL_STRING(ERR_REACHED_CONNECTION_LIMIT)); + return; + } mNeedsUpdatingSdpRecords = true; diff --git a/dom/bluetooth/BluetoothProfileManagerBase.h b/dom/bluetooth/BluetoothProfileManagerBase.h index 0e3d5fd027c..ae79508cdd9 100644 --- a/dom/bluetooth/BluetoothProfileManagerBase.h +++ b/dom/bluetooth/BluetoothProfileManagerBase.h @@ -8,6 +8,8 @@ #define mozilla_dom_bluetooth_bluetoothprofilemanagerbase_h__ #define ERR_SERVICE_CHANNEL_NOT_FOUND "DeviceChannelRetrievalError" +#define ERR_REACHED_CONNECTION_LIMIT "ReachedConnectionLimitError" +#define ERR_NO_AVAILABLE_RESOURCE "NoAvailableResourceError" #include "BluetoothCommon.h"