Bug 872907 - Patch 4: Implement NotifyStatusChagned() and NotifyAudioManager(), r=echou, r=mrbkap

This commit is contained in:
Gina Yeh 2013-06-08 23:26:01 +08:00
parent e7d0099af2
commit a6765ae76d
7 changed files with 110 additions and 14 deletions

View File

@ -24,7 +24,7 @@ using namespace mozilla;
USING_BLUETOOTH_NAMESPACE USING_BLUETOOTH_NAMESPACE
namespace { namespace {
StaticAutoPtr<BluetoothA2dpManager> gBluetoothA2dpManager; StaticRefPtr<BluetoothA2dpManager> gBluetoothA2dpManager;
StaticRefPtr<BluetoothA2dpManagerObserver> sA2dpObserver; StaticRefPtr<BluetoothA2dpManagerObserver> sA2dpObserver;
bool gInShutdown = false; bool gInShutdown = false;
} // anonymous namespace } // anonymous namespace
@ -231,6 +231,8 @@ BluetoothA2dpManager::HandleSinkPropertyChanged(const BluetoothSignal& aSignal)
// Indicates if a stream is setup to a A2DP sink on the remote device. // Indicates if a stream is setup to a A2DP sink on the remote device.
MOZ_ASSERT(value.type() == BluetoothValue::Tbool); MOZ_ASSERT(value.type() == BluetoothValue::Tbool);
mConnected = value.get_bool(); mConnected = value.get_bool();
NotifyStatusChanged();
NotifyAudioManager();
} else if (name.EqualsLiteral("Playing")) { } else if (name.EqualsLiteral("Playing")) {
// Indicates if a stream is active to a A2DP sink on the remote device. // Indicates if a stream is active to a A2DP sink on the remote device.
MOZ_ASSERT(value.type() == BluetoothValue::Tbool); MOZ_ASSERT(value.type() == BluetoothValue::Tbool);
@ -278,3 +280,65 @@ BluetoothA2dpManager::HandleSinkStateChanged(SinkState aState)
mSinkState = aState; mSinkState = aState;
} }
void
BluetoothA2dpManager::NotifyStatusChanged()
{
MOZ_ASSERT(NS_IsMainThread());
NS_NAMED_LITERAL_STRING(type, BLUETOOTH_A2DP_STATUS_CHANGED);
InfallibleTArray<BluetoothNamedValue> parameters;
BluetoothValue v = mConnected;
parameters.AppendElement(
BluetoothNamedValue(NS_LITERAL_STRING("connected"), v));
v = mDeviceAddress;
parameters.AppendElement(
BluetoothNamedValue(NS_LITERAL_STRING("address"), v));
if (!BroadcastSystemMessage(type, parameters)) {
NS_WARNING("Failed to broadcast system message to settings");
return;
}
}
void
BluetoothA2dpManager::NotifyAudioManager()
{
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIObserverService> obs =
do_GetService("@mozilla.org/observer-service;1");
NS_ENSURE_TRUE_VOID(obs);
nsAutoString data;
data.AppendInt(mConnected);
if (NS_FAILED(obs->NotifyObservers(this,
BLUETOOTH_A2DP_STATUS_CHANGED,
data.BeginReading()))) {
NS_WARNING("Failed to notify bluetooth-a2dp-status-changed observsers!");
}
}
void
BluetoothA2dpManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel)
{
}
void
BluetoothA2dpManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
{
}
void
BluetoothA2dpManager::GetAddress(nsAString& aDeviceAddress)
{
aDeviceAddress = mDeviceAddress;
}
NS_IMPL_ISUPPORTS0(BluetoothA2dpManager)

View File

@ -8,6 +8,7 @@
#define mozilla_dom_bluetooth_bluetootha2dpmanager_h__ #define mozilla_dom_bluetooth_bluetootha2dpmanager_h__
#include "BluetoothCommon.h" #include "BluetoothCommon.h"
#include "BluetoothProfileManagerBase.h"
BEGIN_BLUETOOTH_NAMESPACE BEGIN_BLUETOOTH_NAMESPACE
@ -23,9 +24,11 @@ class BluetoothA2dpManagerObserver;
class BluetoothValue; class BluetoothValue;
class BluetoothSocket; class BluetoothSocket;
class BluetoothA2dpManager class BluetoothA2dpManager : public BluetoothProfileManagerBase
{ {
public: public:
NS_DECL_ISUPPORTS
static BluetoothA2dpManager* Get(); static BluetoothA2dpManager* Get();
~BluetoothA2dpManager(); ~BluetoothA2dpManager();
@ -34,6 +37,11 @@ public:
void HandleSinkPropertyChanged(const BluetoothSignal& aSignal); void HandleSinkPropertyChanged(const BluetoothSignal& aSignal);
nsresult HandleShutdown(); nsresult HandleShutdown();
virtual void OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel) MOZ_OVERRIDE;
virtual void GetAddress(nsAString& aDeviceAddress) MOZ_OVERRIDE;
private: private:
BluetoothA2dpManager(); BluetoothA2dpManager();
bool Init(); bool Init();
@ -41,6 +49,9 @@ private:
void HandleSinkStateChanged(SinkState aState); void HandleSinkStateChanged(SinkState aState);
void NotifyStatusChanged();
void NotifyAudioManager();
bool mConnected; bool mConnected;
bool mPlaying; bool mPlaying;
nsString mDeviceAddress; nsString mDeviceAddress;

View File

@ -8,6 +8,7 @@
#include "BluetoothHfpManager.h" #include "BluetoothHfpManager.h"
#include "BluetoothA2dpManager.h"
#include "BluetoothReplyRunnable.h" #include "BluetoothReplyRunnable.h"
#include "BluetoothService.h" #include "BluetoothService.h"
#include "BluetoothSocket.h" #include "BluetoothSocket.h"
@ -62,7 +63,7 @@ using namespace mozilla::ipc;
USING_BLUETOOTH_NAMESPACE USING_BLUETOOTH_NAMESPACE
namespace { namespace {
StaticAutoPtr<BluetoothHfpManager> gBluetoothHfpManager; StaticRefPtr<BluetoothHfpManager> gBluetoothHfpManager;
StaticRefPtr<BluetoothHfpManagerObserver> sHfpObserver; StaticRefPtr<BluetoothHfpManagerObserver> sHfpObserver;
bool gInShutdown = false; bool gInShutdown = false;
static const char kHfpCrlf[] = "\xd\xa"; static const char kHfpCrlf[] = "\xd\xa";
@ -526,7 +527,7 @@ BluetoothHfpManager::NotifyDialer(const nsAString& aCommand)
} }
void void
BluetoothHfpManager::NotifyAudioManager(const nsAString& aAddress) BluetoothHfpManager::NotifyAudioManager(bool aStatus)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
@ -534,9 +535,12 @@ BluetoothHfpManager::NotifyAudioManager(const nsAString& aAddress)
do_GetService("@mozilla.org/observer-service;1"); do_GetService("@mozilla.org/observer-service;1");
NS_ENSURE_TRUE_VOID(obs); NS_ENSURE_TRUE_VOID(obs);
if (NS_FAILED(obs->NotifyObservers(nullptr, nsAutoString data;
data.AppendInt(aStatus);
if (NS_FAILED(obs->NotifyObservers(this,
BLUETOOTH_SCO_STATUS_CHANGED, BLUETOOTH_SCO_STATUS_CHANGED,
aAddress.BeginReading()))) { data.BeginReading()))) {
NS_WARNING("Failed to notify bluetooth-sco-status-changed observsers!"); NS_WARNING("Failed to notify bluetooth-sco-status-changed observsers!");
} }
} }
@ -1114,6 +1118,10 @@ BluetoothHfpManager::Disconnect()
mSocket->Disconnect(); mSocket->Disconnect();
mSocket = nullptr; mSocket = nullptr;
} }
BluetoothA2dpManager* a2dp = BluetoothA2dpManager::Get();
NS_ENSURE_TRUE_VOID(a2dp);
a2dp->Disconnect();
} }
bool bool
@ -1495,6 +1503,10 @@ BluetoothHfpManager::OnConnectSuccess(BluetoothSocket* aSocket)
NotifyStatusChanged(NS_LITERAL_STRING("bluetooth-hfp-status-changed")); NotifyStatusChanged(NS_LITERAL_STRING("bluetooth-hfp-status-changed"));
ListenSco(); ListenSco();
BluetoothA2dpManager* a2dp = BluetoothA2dpManager::Get();
NS_ENSURE_TRUE_VOID(a2dp);
a2dp->Connect(mDeviceAddress);
} }
void void
@ -1623,7 +1635,7 @@ BluetoothHfpManager::OnScoConnectSuccess()
mScoRunnable = nullptr; mScoRunnable = nullptr;
} }
NotifyAudioManager(mDeviceAddress); NotifyAudioManager(true);
NotifyStatusChanged(NS_LITERAL_STRING("bluetooth-sco-status-changed")); NotifyStatusChanged(NS_LITERAL_STRING("bluetooth-sco-status-changed"));
mScoSocketStatus = mScoSocket->GetConnectionStatus(); mScoSocketStatus = mScoSocket->GetConnectionStatus();
@ -1647,7 +1659,7 @@ BluetoothHfpManager::OnScoDisconnect()
{ {
if (mScoSocketStatus == SocketConnectionStatus::SOCKET_CONNECTED) { if (mScoSocketStatus == SocketConnectionStatus::SOCKET_CONNECTED) {
ListenSco(); ListenSco();
NotifyAudioManager(EmptyString()); NotifyAudioManager(false);
NotifyStatusChanged(NS_LITERAL_STRING("bluetooth-sco-status-changed")); NotifyStatusChanged(NS_LITERAL_STRING("bluetooth-sco-status-changed"));
} }
} }
@ -1752,3 +1764,6 @@ BluetoothHfpManager::IsScoConnected()
} }
return false; return false;
} }
NS_IMPL_ISUPPORTS0(BluetoothHfpManager)

View File

@ -55,6 +55,8 @@ class BluetoothHfpManager : public BluetoothSocketObserver
, public BluetoothProfileManagerBase , public BluetoothProfileManagerBase
{ {
public: public:
NS_DECL_ISUPPORTS
static BluetoothHfpManager* Get(); static BluetoothHfpManager* Get();
~BluetoothHfpManager(); ~BluetoothHfpManager();
@ -68,6 +70,7 @@ public:
const nsAString& aServiceUuid, const nsAString& aServiceUuid,
int aChannel) MOZ_OVERRIDE; int aChannel) MOZ_OVERRIDE;
virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) MOZ_OVERRIDE; virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) MOZ_OVERRIDE;
virtual void GetAddress(nsAString& aDeviceAddress) MOZ_OVERRIDE;
void Connect(const nsAString& aDeviceAddress, void Connect(const nsAString& aDeviceAddress,
const bool aIsHandsfree, const bool aIsHandsfree,
@ -87,7 +90,6 @@ public:
bool IsConnected(); bool IsConnected();
bool IsScoConnected(); bool IsScoConnected();
void GetAddress(nsAString& aDeviceAddress);
private: private:
class GetVolumeTask; class GetVolumeTask;
@ -114,7 +116,7 @@ private:
void NotifyDialer(const nsAString& aCommand); void NotifyDialer(const nsAString& aCommand);
void NotifyStatusChanged(const nsAString& aType); void NotifyStatusChanged(const nsAString& aType);
void NotifyAudioManager(const nsAString& aAddress); void NotifyAudioManager(bool aStatus);
bool SendCommand(const char* aCommand, uint32_t aValue = 0); bool SendCommand(const char* aCommand, uint32_t aValue = 0);
bool SendLine(const char* aMessage); bool SendLine(const char* aMessage);

View File

@ -86,7 +86,7 @@ static const uint32_t kUpdateProgressBase = 50 * 1024;
*/ */
static const uint32_t kPutRequestHeaderSize = 6; static const uint32_t kPutRequestHeaderSize = 6;
StaticAutoPtr<BluetoothOppManager> sInstance; StaticRefPtr<BluetoothOppManager> sInstance;
/* /*
* FIXME / Bug 806749 * FIXME / Bug 806749
@ -1508,6 +1508,8 @@ BluetoothOppManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
} }
} }
NS_IMPL_ISUPPORTS0(BluetoothOppManager)
bool bool
BluetoothOppManager::AcquireSdcardMountLock() BluetoothOppManager::AcquireSdcardMountLock()
{ {

View File

@ -29,6 +29,8 @@ class BluetoothOppManager : public BluetoothSocketObserver
, public BluetoothProfileManagerBase , public BluetoothProfileManagerBase
{ {
public: public:
NS_DECL_ISUPPORTS
/* /*
* Channel of reserved services are fixed values, please check * Channel of reserved services are fixed values, please check
* function add_reserved_service_records() in * function add_reserved_service_records() in
@ -76,7 +78,6 @@ public:
// Return true if there is an ongoing file-transfer session, please see // Return true if there is an ongoing file-transfer session, please see
// Bug 827267 for more information. // Bug 827267 for more information.
bool IsTransferring(); bool IsTransferring();
void GetAddress(nsAString& aDeviceAddress);
// Implement interface BluetoothSocketObserver // Implement interface BluetoothSocketObserver
void ReceiveSocketData( void ReceiveSocketData(
@ -90,6 +91,7 @@ public:
const nsAString& aServiceUuid, const nsAString& aServiceUuid,
int aChannel) MOZ_OVERRIDE; int aChannel) MOZ_OVERRIDE;
virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) MOZ_OVERRIDE; virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) MOZ_OVERRIDE;
virtual void GetAddress(nsAString& aDeviceAddress) MOZ_OVERRIDE;
private: private:
BluetoothOppManager(); BluetoothOppManager();

View File

@ -13,14 +13,14 @@
BEGIN_BLUETOOTH_NAMESPACE BEGIN_BLUETOOTH_NAMESPACE
class BluetoothProfileManagerBase class BluetoothProfileManagerBase : public nsISupports
{ {
public: public:
virtual void OnGetServiceChannel(const nsAString& aDeviceAddress, virtual void OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid, const nsAString& aServiceUuid,
int aChannel) = 0; int aChannel) = 0;
virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) = 0; virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) = 0;
virtual void GetAddress(nsAString& aDeviceAddress) = 0;
}; };
END_BLUETOOTH_NAMESPACE END_BLUETOOTH_NAMESPACE