Bug 1053804: Integrate runnables into Handsfree notifications, r=shuang

A number of notifications dispatch runnables to the main thread for
invoking actions. This is not requireed, as notifications already
run on the main thread. This patch merges the runnable's code into
the respective notifications.
This commit is contained in:
Thomas Zimmermann 2014-08-21 10:10:39 +02:00
parent 43e680c63c
commit 5e5bc1cd09

View File

@ -1732,12 +1732,13 @@ BluetoothHfpManager::ConnectionStateNotification(
if (aState == HFP_CONNECTION_STATE_SLC_CONNECTED) {
mDeviceAddress = aBdAddress;
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_CONN_STATE_CHANGED,
NS_LITERAL_STRING(BLUETOOTH_HFP_STATUS_CHANGED_ID));
NotifyConnectionStateChanged(
NS_LITERAL_STRING(BLUETOOTH_HFP_STATUS_CHANGED_ID));
} else if (aState == HFP_CONNECTION_STATE_DISCONNECTED) {
DisconnectSco();
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_CONN_STATE_CHANGED,
NS_LITERAL_STRING(BLUETOOTH_HFP_STATUS_CHANGED_ID));
NotifyConnectionStateChanged(
NS_LITERAL_STRING(BLUETOOTH_HFP_STATUS_CHANGED_ID));
}
}
@ -1753,8 +1754,8 @@ BluetoothHfpManager::AudioStateNotification(
if (aState == HFP_AUDIO_STATE_CONNECTED ||
aState == HFP_AUDIO_STATE_DISCONNECTED) {
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_CONN_STATE_CHANGED,
NS_LITERAL_STRING(BLUETOOTH_SCO_STATUS_CHANGED_ID));
NotifyConnectionStateChanged(
NS_LITERAL_STRING(BLUETOOTH_SCO_STATUS_CHANGED_ID));
}
}
@ -1763,8 +1764,7 @@ BluetoothHfpManager::AnswerCallNotification()
{
MOZ_ASSERT(NS_IsMainThread());
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
NS_LITERAL_STRING("ATA"));
NotifyDialer(NS_LITERAL_STRING("ATA"));
}
void
@ -1772,8 +1772,7 @@ BluetoothHfpManager::HangupCallNotification()
{
MOZ_ASSERT(NS_IsMainThread());
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
NS_LITERAL_STRING("CHUP"));
NotifyDialer(NS_LITERAL_STRING("CHUP"));
}
void
@ -1796,7 +1795,11 @@ BluetoothHfpManager::VolumeNotification(
nsString data;
data.AppendInt(aVolume);
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_SCO_VOLUME_CHANGED, data);
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
NS_ENSURE_TRUE_VOID(os);
os->NotifyObservers(nullptr, "bluetooth-volume-change", data.get());
}
}
@ -1809,8 +1812,7 @@ BluetoothHfpManager::DtmfNotification(char aDtmf)
nsAutoCString message("VTS=");
message += aDtmf;
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
NS_ConvertUTF8toUTF16(message));
NotifyDialer(NS_ConvertUTF8toUTF16(message));
}
void
@ -1818,12 +1820,11 @@ BluetoothHfpManager::CallHoldNotification(BluetoothHandsfreeCallHoldType aChld)
{
MOZ_ASSERT(NS_IsMainThread());
SendResponse(HFP_AT_RESPONSE_OK);
nsAutoCString message("CHLD=");
message.AppendInt((int)aChld);
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
NS_ConvertUTF8toUTF16(message));
SendResponse(HFP_AT_RESPONSE_OK);
NotifyDialer(NS_ConvertUTF8toUTF16(message));
}
void BluetoothHfpManager::DialCallNotification(const nsAString& aNumber)
@ -1842,22 +1843,27 @@ void BluetoothHfpManager::DialCallNotification(const nsAString& aNumber)
// 3): Respond here
if (message.IsEmpty()) {
mDialingRequestProcessed = false;
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
NS_LITERAL_STRING("BLDN"));
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::POST_TASK_RESPOND_TO_BLDN);
NotifyDialer(NS_LITERAL_STRING("BLDN"));
MessageLoop::current()->PostDelayedTask(FROM_HERE,
new RespondToBLDNTask(),
sWaitingForDialingInterval);
} else if (message[0] == '>') {
mDialingRequestProcessed = false;
nsAutoCString newMsg("ATD");
newMsg += StringHead(message, message.Length() - 1);
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
NS_ConvertUTF8toUTF16(newMsg));
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::POST_TASK_RESPOND_TO_BLDN);
NotifyDialer(NS_ConvertUTF8toUTF16(newMsg));
MessageLoop::current()->PostDelayedTask(FROM_HERE,
new RespondToBLDNTask(),
sWaitingForDialingInterval);
} else {
SendResponse(HFP_AT_RESPONSE_OK);
nsAutoCString newMsg("ATD");
newMsg += StringHead(message, message.Length() - 1);
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
NS_ConvertUTF8toUTF16(newMsg));
SendResponse(HFP_AT_RESPONSE_OK);
NotifyDialer(NS_ConvertUTF8toUTF16(newMsg));
}
}
@ -1961,7 +1967,7 @@ BluetoothHfpManager::KeyPressedNotification()
* and SCO will be established after we get the CallStateChanged event
* indicating the call is answered successfully.
*/
ProcessAnswerCall();
NotifyDialer(NS_LITERAL_STRING("ATA"));
} else if (hasActiveCall) {
if (!IsScoConnected()) {
/**
@ -1976,14 +1982,17 @@ BluetoothHfpManager::KeyPressedNotification()
* SCO socket directly. We notify dialer only if there is at least one
* active call.
*/
ProcessHangupCall();
NotifyDialer(NS_LITERAL_STRING("CHUP"));
}
} else {
// BLDN
mDialingRequestProcessed = false;
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
NS_LITERAL_STRING("BLDN"));
BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::POST_TASK_RESPOND_TO_BLDN);
NotifyDialer(NS_LITERAL_STRING("BLDN"));
MessageLoop::current()->PostDelayedTask(FROM_HERE,
new RespondToBLDNTask(),
sWaitingForDialingInterval);
}
}