From e94c49cdb64f86e86c82cdce7b4b9c8c6505d4fd Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Mon, 1 Sep 2014 10:11:54 +0200 Subject: [PATCH] Bug 1057337: Integrate helper runnables into A2DP and AVRCP notifications, r=shuang The helper runnables where necessary to perform certain operations on the main thread after having received a callback from Bluedroid. The new notification methods already run on the main thread, so the helper runnables can be replaced by direct calls. --- .../bluedroid/BluetoothA2dpManager.cpp | 47 +++++++++++++++---- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp b/dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp index ad34ed68600..28c9ec6a1ec 100644 --- a/dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp +++ b/dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp @@ -1352,9 +1352,8 @@ BluetoothA2dpManager::ConnectionStateNotification(BluetoothA2dpConnectionState a InfallibleTArray props; BT_APPEND_NAMED_VALUE(props, "State", a2dpState); - BluetoothSignal signal(NS_LITERAL_STRING("AudioSink"), - nsString(aBdAddr), props); - NS_DispatchToMainThread(new SinkPropertyChangedHandler(signal)); + HandleSinkPropertyChanged(BluetoothSignal(NS_LITERAL_STRING("AudioSink"), + nsString(aBdAddr), props)); } void @@ -1378,9 +1377,8 @@ BluetoothA2dpManager::AudioStateNotification(BluetoothA2dpAudioState aState, InfallibleTArray props; BT_APPEND_NAMED_VALUE(props, "State", a2dpState); - BluetoothSignal signal(NS_LITERAL_STRING("AudioSink"), - nsString(aBdAddr), props); - NS_DispatchToMainThread(new SinkPropertyChangedHandler(signal)); + HandleSinkPropertyChanged(BluetoothSignal(NS_LITERAL_STRING("AudioSink"), + nsString(aBdAddr), props)); } /* @@ -1392,7 +1390,15 @@ BluetoothA2dpManager::GetPlayStatusNotification() { MOZ_ASSERT(NS_IsMainThread()); - NS_DispatchToMainThread(new RequestPlayStatusTask()); + BluetoothService* bs = BluetoothService::Get(); + if (!bs) { + return; + } + + bs->DistributeSignal( + BluetoothSignal(NS_LITERAL_STRING(REQUEST_MEDIA_PLAYSTATUS_ID), + NS_LITERAL_STRING(KEY_ADAPTER), + InfallibleTArray())); } /* Player application settings is optional for AVRCP 1.3. B2G @@ -1463,7 +1469,20 @@ BluetoothA2dpManager::GetElementAttrNotification( { MOZ_ASSERT(NS_IsMainThread()); - NS_DispatchToMainThread(new UpdateElementAttrsTask(aNumAttrs, aAttrs)); + nsAutoArrayPtr attrs( + new BluetoothAvrcpElementAttribute[aNumAttrs]); + + for (uint8_t i = 0; i < aNumAttrs; ++i) { + attrs[i].mId = aAttrs[i]; + ConvertAttributeString( + static_cast(attrs[i].mId), + attrs[i].mValue); + } + +#if ANDROID_VERSION >= 18 + MOZ_ASSERT(sBtAvrcpInterface); + sBtAvrcpInterface->GetElementAttrRsp(aNumAttrs, attrs, nullptr); +#endif // ANDROID_VERSION >= 18 } void @@ -1472,7 +1491,14 @@ BluetoothA2dpManager::RegisterNotificationNotification( { MOZ_ASSERT(NS_IsMainThread()); - NS_DispatchToMainThread(new UpdateRegisterNotificationTask(aEvent, aParam)); + BluetoothA2dpManager* a2dp = BluetoothA2dpManager::Get(); + if (!a2dp) { + return; + } + +#if ANDROID_VERSION >= 18 + a2dp->UpdateRegisterNotification(aEvent, aParam); +#endif // ANDROID_VERSION >= 18 } /* This method is used to get CT features from the Feature Bit Mask. If @@ -1531,7 +1557,8 @@ BluetoothA2dpManager::PassthroughCmdNotification(int aId, int aKeyState) return; } - NS_DispatchToMainThread(new UpdatePassthroughCmdTask(name)); + NS_NAMED_LITERAL_STRING(type, "media-button"); + BroadcastSystemMessage(type, BluetoothValue(name)); } NS_IMPL_ISUPPORTS(BluetoothA2dpManager, nsIObserver)