Bug 842934 - Patch 1: Add topic for hfp status changed and notify observers with device address, r=echou

This commit is contained in:
Gina Yeh 2013-07-30 17:34:56 +08:00
parent cf63111369
commit e8935b0303
5 changed files with 26 additions and 50 deletions

View File

@ -205,7 +205,6 @@ BluetoothA2dpManager::HandleSinkPropertyChanged(const BluetoothSignal& aSignal)
MOZ_ASSERT(value.type() == BluetoothValue::Tbool);
mA2dpConnected = value.get_bool();
NotifyStatusChanged();
NotifyAudioManager();
} else if (name.EqualsLiteral("Playing")) {
// Indicates if a stream is active to a A2DP sink on the remote device.
MOZ_ASSERT(value.type() == BluetoothValue::Tbool);
@ -259,6 +258,7 @@ BluetoothA2dpManager::NotifyStatusChanged()
{
MOZ_ASSERT(NS_IsMainThread());
// Broadcast system message to Gaia
NS_NAMED_LITERAL_STRING(type, BLUETOOTH_A2DP_STATUS_CHANGED_ID);
InfallibleTArray<BluetoothNamedValue> parameters;
@ -272,25 +272,16 @@ BluetoothA2dpManager::NotifyStatusChanged()
if (!BroadcastSystemMessage(type, parameters)) {
NS_WARNING("Failed to broadcast system message to settings");
return;
}
}
void
BluetoothA2dpManager::NotifyAudioManager()
{
MOZ_ASSERT(NS_IsMainThread());
// Notify Gecko observers
nsCOMPtr<nsIObserverService> obs =
do_GetService("@mozilla.org/observer-service;1");
NS_ENSURE_TRUE_VOID(obs);
nsAutoString data;
data.AppendInt(mA2dpConnected);
if (NS_FAILED(obs->NotifyObservers(this,
BLUETOOTH_A2DP_STATUS_CHANGED_ID,
data.BeginReading()))) {
mDeviceAddress.get()))) {
NS_WARNING("Failed to notify bluetooth-a2dp-status-changed observsers!");
}
}

View File

@ -73,13 +73,11 @@ private:
void HandleShutdown();
void NotifyStatusChanged();
void NotifyAudioManager();
nsString mDeviceAddress;
// A2DP data member
bool mA2dpConnected;
bool mPlaying;
nsString mDeviceAddress;
SinkState mSinkState;
// AVRCP data member

View File

@ -55,6 +55,7 @@ extern bool gBluetoothDebugFlag;
* When connection status of Bluetooth profiles change, we'll notify observers
* of following topics.
*/
#define BLUETOOTH_HFP_STATUS_CHANGED_ID "bluetooth-hfp-status-changed"
#define BLUETOOTH_SCO_STATUS_CHANGED_ID "bluetooth-sco-status-changed"
#define BLUETOOTH_A2DP_STATUS_CHANGED_ID "bluetooth-a2dp-status-changed"

View File

@ -454,17 +454,18 @@ BluetoothHfpManager::Get()
}
void
BluetoothHfpManager::NotifyStatusChanged(const nsAString& aType)
BluetoothHfpManager::NotifyStatusChanged(const char* aType)
{
nsString type, name;
// Broadcast system message to Gaia
BluetoothValue v;
InfallibleTArray<BluetoothNamedValue> parameters;
type = aType;
nsAutoString type, name;
type = NS_ConvertUTF8toUTF16(aType);
name.AssignLiteral("connected");
if (type.EqualsLiteral("bluetooth-hfp-status-changed")) {
if (type.EqualsLiteral(BLUETOOTH_HFP_STATUS_CHANGED_ID)) {
v = IsConnected();
} else if (type.EqualsLiteral("bluetooth-sco-status-changed")) {
} else if (type.EqualsLiteral(BLUETOOTH_SCO_STATUS_CHANGED_ID)) {
v = IsScoConnected();
} else {
NS_WARNING("Wrong type for NotifyStatusChanged");
@ -478,7 +479,15 @@ BluetoothHfpManager::NotifyStatusChanged(const nsAString& aType)
if (!BroadcastSystemMessage(type, parameters)) {
NS_WARNING("Failed to broadcast system message to settings");
return;
}
// Notify Gecko observers
nsCOMPtr<nsIObserverService> obs =
do_GetService("@mozilla.org/observer-service;1");
NS_ENSURE_TRUE_VOID(obs);
if (NS_FAILED(obs->NotifyObservers(this, aType, mDeviceAddress.get()))) {
NS_WARNING("Failed to notify bluetooth-sco-status-changed observsers!");
}
}
@ -496,26 +505,6 @@ BluetoothHfpManager::NotifyDialer(const nsAString& aCommand)
if (!BroadcastSystemMessage(type, parameters)) {
NS_WARNING("Failed to broadcast system message to dialer");
return;
}
}
void
BluetoothHfpManager::NotifyAudioManager(bool aStatus)
{
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIObserverService> obs =
do_GetService("@mozilla.org/observer-service;1");
NS_ENSURE_TRUE_VOID(obs);
nsAutoString data;
data.AppendInt(aStatus);
if (NS_FAILED(obs->NotifyObservers(this,
BLUETOOTH_SCO_STATUS_CHANGED_ID,
data.BeginReading()))) {
NS_WARNING("Failed to notify bluetooth-sco-status-changed observsers!");
}
}
@ -1493,7 +1482,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);
NotifyStatusChanged(NS_LITERAL_STRING("bluetooth-hfp-status-changed"));
NotifyStatusChanged(BLUETOOTH_HFP_STATUS_CHANGED_ID);
ListenSco();
@ -1548,7 +1537,7 @@ BluetoothHfpManager::OnDisconnect(BluetoothSocket* aSocket)
DisconnectSco();
Listen();
NotifyStatusChanged(NS_LITERAL_STRING("bluetooth-hfp-status-changed"));
NotifyStatusChanged(BLUETOOTH_HFP_STATUS_CHANGED_ID);
Reset();
}
@ -1628,8 +1617,7 @@ BluetoothHfpManager::OnScoConnectSuccess()
mScoRunnable = nullptr;
}
NotifyAudioManager(true);
NotifyStatusChanged(NS_LITERAL_STRING("bluetooth-sco-status-changed"));
NotifyStatusChanged(BLUETOOTH_SCO_STATUS_CHANGED_ID);
mScoSocketStatus = mScoSocket->GetConnectionStatus();
}
@ -1652,8 +1640,7 @@ BluetoothHfpManager::OnScoDisconnect()
{
if (mScoSocketStatus == SocketConnectionStatus::SOCKET_CONNECTED) {
ListenSco();
NotifyAudioManager(false);
NotifyStatusChanged(NS_LITERAL_STRING("bluetooth-sco-status-changed"));
NotifyStatusChanged(BLUETOOTH_SCO_STATUS_CHANGED_ID);
}
}

View File

@ -118,8 +118,7 @@ private:
uint32_t GetNumberOfCalls(uint16_t aState);
void NotifyDialer(const nsAString& aCommand);
void NotifyStatusChanged(const nsAString& aType);
void NotifyAudioManager(bool aStatus);
void NotifyStatusChanged(const char* aType);
bool SendCommand(const char* aCommand, uint32_t aValue = 0);
bool SendLine(const char* aMessage);