diff --git a/dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp b/dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp index c9dac94c4c17..090333a8c38e 100644 --- a/dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp +++ b/dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp @@ -764,7 +764,7 @@ BluetoothA2dpManager::HandleSinkPropertyChanged(const BluetoothSignal& aSignal) case SinkState::SINK_DISCONNECTED: // case 2: Connection attempt failed if (prevState == SinkState::SINK_CONNECTING) { - OnConnect(NS_LITERAL_STRING("A2dpConnectionError")); + OnConnect(NS_LITERAL_STRING(ERR_CONNECTION_FAILED)); break; } diff --git a/dom/bluetooth/bluedroid/BluetoothA2dpManager.h b/dom/bluetooth/bluedroid/BluetoothA2dpManager.h index 821b393a3ef9..1a78f2fd73f5 100644 --- a/dom/bluetooth/bluedroid/BluetoothA2dpManager.h +++ b/dom/bluetooth/bluedroid/BluetoothA2dpManager.h @@ -31,8 +31,6 @@ public: static BluetoothA2dpManager* Get(); virtual ~BluetoothA2dpManager(); - void ResetA2dp(); - void ResetAvrcp(); // A2DP-specific functions void HandleSinkPropertyChanged(const BluetoothSignal& aSignal); @@ -63,6 +61,9 @@ private: class SinkPropertyChangedHandler; BluetoothA2dpManager(); bool Init(); + void ResetA2dp(); + void ResetAvrcp(); + void HandleShutdown(); void NotifyConnectionStatusChanged(); diff --git a/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp b/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp index 0ba1a4f7b70c..fa7203412b3b 100644 --- a/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp +++ b/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp @@ -760,7 +760,7 @@ BluetoothHfpManager::NotifyConnectionStateChanged(const nsAString& aType) // When the outgoing hfp connection fails, state changes to disconnected // state. Since bluedroid would not report connecting state, but only // report connected/disconnected. - OnConnect(NS_LITERAL_STRING("SocketConnectionError")); + OnConnect(NS_LITERAL_STRING(ERR_CONNECTION_FAILED)); } else { OnDisconnect(EmptyString()); } diff --git a/dom/bluetooth/bluez/BluetoothA2dpManager.cpp b/dom/bluetooth/bluez/BluetoothA2dpManager.cpp index d4f35c7c99a1..e77d72797a78 100644 --- a/dom/bluetooth/bluez/BluetoothA2dpManager.cpp +++ b/dom/bluetooth/bluez/BluetoothA2dpManager.cpp @@ -295,6 +295,15 @@ BluetoothA2dpManager::HandleSinkPropertyChanged(const BluetoothSignal& aSignal) NS_ENSURE_TRUE_VOID((newState != SinkState::SINK_UNKNOWN) && (newState != mSinkState)); + /** + * Reject 'connected' state change if bluetooth is already disabled. + * Sink state would be reset to 'disconnected' when bluetooth is disabled. + * + * See bug 984284 for more information about the edge case. + */ + NS_ENSURE_FALSE_VOID(newState == SinkState::SINK_CONNECTED && + mSinkState == SinkState::SINK_DISCONNECTED); + SinkState prevState = mSinkState; mSinkState = newState; @@ -325,13 +334,13 @@ BluetoothA2dpManager::HandleSinkPropertyChanged(const BluetoothSignal& aSignal) case SinkState::SINK_DISCONNECTED: // case 2: Connection attempt failed if (prevState == SinkState::SINK_CONNECTING) { - OnConnect(NS_LITERAL_STRING("A2dpConnectionError")); + OnConnect(NS_LITERAL_STRING(ERR_CONNECTION_FAILED)); break; } // case 6: Disconnected from the remote device MOZ_ASSERT(prevState == SinkState::SINK_CONNECTED || - prevState == SinkState::SINK_PLAYING) ; + prevState == SinkState::SINK_PLAYING); mA2dpConnected = false; NotifyConnectionStatusChanged(); diff --git a/dom/bluetooth/bluez/BluetoothA2dpManager.h b/dom/bluetooth/bluez/BluetoothA2dpManager.h index 402466201e43..4b27290ef95d 100644 --- a/dom/bluetooth/bluez/BluetoothA2dpManager.h +++ b/dom/bluetooth/bluez/BluetoothA2dpManager.h @@ -32,8 +32,6 @@ public: static BluetoothA2dpManager* Get(); virtual ~BluetoothA2dpManager(); - void ResetA2dp(); - void ResetAvrcp(); // A2DP-specific functions void HandleSinkPropertyChanged(const BluetoothSignal& aSignal); @@ -60,6 +58,8 @@ public: private: BluetoothA2dpManager(); bool Init(); + void ResetA2dp(); + void ResetAvrcp(); void HandleShutdown(); void NotifyConnectionStatusChanged(); diff --git a/dom/bluetooth/bluez/BluetoothDBusService.cpp b/dom/bluetooth/bluez/BluetoothDBusService.cpp index 472a8ab45c35..d4665a65b9fb 100644 --- a/dom/bluetooth/bluez/BluetoothDBusService.cpp +++ b/dom/bluetooth/bluez/BluetoothDBusService.cpp @@ -636,8 +636,7 @@ public: BluetoothA2dpManager* a2dp = BluetoothA2dpManager::Get(); NS_ENSURE_TRUE(a2dp, NS_ERROR_FAILURE); - a2dp->ResetA2dp(); - a2dp->ResetAvrcp(); + a2dp->Reset(); return NS_OK; } diff --git a/dom/bluetooth/bluez/BluetoothHfpManager.cpp b/dom/bluetooth/bluez/BluetoothHfpManager.cpp index 0d88f404a31e..8e9524232c8c 100644 --- a/dom/bluetooth/bluez/BluetoothHfpManager.cpp +++ b/dom/bluetooth/bluez/BluetoothHfpManager.cpp @@ -1690,7 +1690,7 @@ BluetoothHfpManager::OnSocketConnectError(BluetoothSocket* aSocket) mHandsfreeSocket = nullptr; mHeadsetSocket = nullptr; - OnConnect(NS_LITERAL_STRING("SocketConnectionError")); + OnConnect(NS_LITERAL_STRING(ERR_CONNECTION_FAILED)); } void @@ -1758,7 +1758,7 @@ BluetoothHfpManager::OnGetServiceChannel(const nsAString& aDeviceAddress, MOZ_ASSERT(mSocket); if (!mSocket->Connect(NS_ConvertUTF16toUTF8(aDeviceAddress), aChannel)) { - OnConnect(NS_LITERAL_STRING("SocketConnectionError")); + OnConnect(NS_LITERAL_STRING(ERR_CONNECTION_FAILED)); } }