diff --git a/dom/bluetooth/bluedroid/BluetoothAvrcpManager.cpp b/dom/bluetooth/bluedroid/BluetoothAvrcpManager.cpp index 34e994f98fa..33ea6a248b6 100644 --- a/dom/bluetooth/bluedroid/BluetoothAvrcpManager.cpp +++ b/dom/bluetooth/bluedroid/BluetoothAvrcpManager.cpp @@ -339,6 +339,23 @@ BluetoothAvrcpManager::HandleShutdown() sBluetoothAvrcpManager = nullptr; } +class BluetoothAvrcpManager::ConnectRunnable final : public nsRunnable +{ +public: + ConnectRunnable(BluetoothAvrcpManager* aManager) + : mManager(aManager) + { + MOZ_ASSERT(mManager); + } + NS_METHOD Run() override + { + mManager->OnConnect(EmptyString()); + return NS_OK; + } +private: + BluetoothAvrcpManager* mManager; +}; + void BluetoothAvrcpManager::Connect(const nsAString& aDeviceAddress, BluetoothProfileController* aController) @@ -350,11 +367,28 @@ BluetoothAvrcpManager::Connect(const nsAString& aDeviceAddress, // AVRCP doesn't require connecting. We just set the remote address here. mDeviceAddress = aDeviceAddress; mController = aController; - SetConnected(true); - OnConnect(EmptyString()); + + NS_DispatchToMainThread(new ConnectRunnable(this)); } +class BluetoothAvrcpManager::DisconnectRunnable final : public nsRunnable +{ +public: + DisconnectRunnable(BluetoothAvrcpManager* aManager) + : mManager(aManager) + { + MOZ_ASSERT(mManager); + } + NS_METHOD Run() override + { + mManager->OnDisconnect(EmptyString()); + return NS_OK; + } +private: + BluetoothAvrcpManager* mManager; +}; + void BluetoothAvrcpManager::Disconnect(BluetoothProfileController* aController) { @@ -362,11 +396,10 @@ BluetoothAvrcpManager::Disconnect(BluetoothProfileController* aController) MOZ_ASSERT(!mController); mDeviceAddress.Truncate(); - mController = aController; - SetConnected(false); - OnDisconnect(EmptyString()); + + NS_DispatchToMainThread(new DisconnectRunnable(this)); } void diff --git a/dom/bluetooth/bluedroid/BluetoothAvrcpManager.h b/dom/bluetooth/bluedroid/BluetoothAvrcpManager.h index 59128d51f17..fe1f4efc478 100644 --- a/dom/bluetooth/bluedroid/BluetoothAvrcpManager.h +++ b/dom/bluetooth/bluedroid/BluetoothAvrcpManager.h @@ -62,8 +62,8 @@ protected: private: class CleanupAvrcpResultHandler; class CleanupAvrcpResultHandlerRunnable; - class ConnectResultHandler; - class DisconnectResultHandler; + class ConnectRunnable; + class DisconnectRunnable; class InitAvrcpResultHandler; class OnErrorProfileResultHandlerRunnable;