diff --git a/dom/bluetooth/BluetoothHfpManager.cpp b/dom/bluetooth/BluetoothHfpManager.cpp index fe387660f6f..0055091222e 100644 --- a/dom/bluetooth/BluetoothHfpManager.cpp +++ b/dom/bluetooth/BluetoothHfpManager.cpp @@ -462,15 +462,22 @@ BluetoothHfpManager::Get() } void -BluetoothHfpManager::NotifySettings() +BluetoothHfpManager::NotifyStatusChanged(const nsAString& aType) { nsString type, name; BluetoothValue v; InfallibleTArray parameters; - type.AssignLiteral("bluetooth-hfp-status-changed"); + type = aType; name.AssignLiteral("connected"); - v = IsConnected(); + if (type.EqualsLiteral("bluetooth-hfp-status-changed")) { + v = IsConnected(); + } else if (type.EqualsLiteral("bluetooth-sco-status-changed")) { + v = IsScoConnected(); + } else { + NS_WARNING("Wrong type for NotifyStatusChanged"); + return; + } parameters.AppendElement(BluetoothNamedValue(name, v)); name.AssignLiteral("address"); @@ -1410,7 +1417,7 @@ BluetoothHfpManager::OnConnectSuccess(BluetoothSocket* aSocket) // Cache device path for NotifySettings() since we can't get socket address // when a headset disconnect with us mSocket->GetAddress(mDeviceAddress); - NotifySettings(); + NotifyStatusChanged(NS_LITERAL_STRING("bluetooth-hfp-status-changed")); ListenSco(); } @@ -1461,7 +1468,7 @@ BluetoothHfpManager::OnDisconnect(BluetoothSocket* aSocket) DisconnectSco(); Listen(); - NotifySettings(); + NotifyStatusChanged(NS_LITERAL_STRING("bluetooth-hfp-status-changed")); Reset(); } @@ -1503,6 +1510,7 @@ BluetoothHfpManager::OnScoConnectSuccess() } NotifyAudioManager(mDeviceAddress); + NotifyStatusChanged(NS_LITERAL_STRING("bluetooth-sco-status-changed")); mScoSocketStatus = mScoSocket->GetConnectionStatus(); } @@ -1526,6 +1534,7 @@ BluetoothHfpManager::OnScoDisconnect() if (mScoSocketStatus == SocketConnectionStatus::SOCKET_CONNECTED) { ListenSco(); NotifyAudioManager(EmptyString()); + NotifyStatusChanged(NS_LITERAL_STRING("bluetooth-sco-status-changed")); } } @@ -1577,6 +1586,7 @@ BluetoothHfpManager::ConnectSco(BluetoothReplyRunnable* aRunnable) NS_ENSURE_TRUE(bs, false); nsresult rv = bs->GetScoSocket(mDeviceAddress, true, false, mScoSocket); + mScoSocketStatus = mSocket->GetConnectionStatus(); return NS_SUCCEEDED(rv); } diff --git a/dom/bluetooth/BluetoothHfpManager.h b/dom/bluetooth/BluetoothHfpManager.h index dd1b73d1ef0..34171d057be 100644 --- a/dom/bluetooth/BluetoothHfpManager.h +++ b/dom/bluetooth/BluetoothHfpManager.h @@ -110,7 +110,7 @@ private: void ResetCallArray(); void NotifyDialer(const nsAString& aCommand); - void NotifySettings(); + void NotifyStatusChanged(const nsAString& aType); void NotifyAudioManager(const nsAString& aAddress); bool SendCommand(const char* aCommand, uint8_t aValue = 0);