Bug 935573 - [bluedroid] Add Connect/Disconnect api, r=echou

This commit is contained in:
Ben Tian 2013-11-11 14:16:28 +08:00
parent 7e8044d6bd
commit aa1eeeceab
6 changed files with 85 additions and 77 deletions

View File

@ -18,6 +18,11 @@ class BluetoothA2dpManager : public BluetoothProfileManagerBase
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
BT_DECL_PROFILE_MGR_BASE
virtual void GetName(nsACString& aName)
{
aName.AssignLiteral("A2DP");
}
enum SinkState {
SINK_UNKNOWN,
@ -32,24 +37,6 @@ public:
void ResetA2dp();
void ResetAvrcp();
// The following functions are inherited from BluetoothProfileManagerBase
virtual void OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel) MOZ_OVERRIDE;
virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) MOZ_OVERRIDE;
virtual void GetAddress(nsAString& aDeviceAddress) MOZ_OVERRIDE;
virtual bool IsConnected() MOZ_OVERRIDE;
virtual void Connect(const nsAString& aDeviceAddress,
BluetoothProfileController* aController) MOZ_OVERRIDE;
virtual void Disconnect(BluetoothProfileController* aController) MOZ_OVERRIDE;
virtual void OnConnect(const nsAString& aErrorStr) MOZ_OVERRIDE;
virtual void OnDisconnect(const nsAString& aErrorStr) MOZ_OVERRIDE;
virtual void GetName(nsACString& aName)
{
aName.AssignLiteral("A2DP");
}
// A2DP-specific functions
void HandleSinkPropertyChanged(const BluetoothSignal& aSignal);

View File

@ -80,6 +80,11 @@ class BluetoothHfpManager : public BluetoothSocketObserver
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
BT_DECL_PROFILE_MGR_BASE
virtual void GetName(nsACString& aName)
{
aName.AssignLiteral("HFP/HSP");
}
static BluetoothHfpManager* Get();
~BluetoothHfpManager();
@ -92,27 +97,11 @@ public:
virtual void OnSocketConnectError(BluetoothSocket* aSocket) MOZ_OVERRIDE;
virtual void OnSocketDisconnect(BluetoothSocket* aSocket) MOZ_OVERRIDE;
// The following functions are inherited from BluetoothProfileManagerBase
virtual void OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel) MOZ_OVERRIDE;
virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) MOZ_OVERRIDE;
virtual void GetAddress(nsAString& aDeviceAddress) MOZ_OVERRIDE;
virtual void Connect(const nsAString& aDeviceAddress,
BluetoothProfileController* aController) MOZ_OVERRIDE;
virtual void Disconnect(BluetoothProfileController* aController) MOZ_OVERRIDE;
virtual void OnConnect(const nsAString& aErrorStr) MOZ_OVERRIDE;
virtual void OnDisconnect(const nsAString& AErrorStr) MOZ_OVERRIDE;
virtual void GetName(nsACString& aName)
{
aName.AssignLiteral("HFP/HSP");
}
bool Listen();
bool ConnectSco(BluetoothReplyRunnable* aRunnable = nullptr);
bool DisconnectSco();
bool ListenSco();
bool IsScoConnected();
#ifdef MOZ_B2G_RIL
/**
@ -123,12 +112,7 @@ public:
const bool aIsOutgoing, bool aSend);
void HandleIccInfoChanged(uint32_t aClientId);
void HandleVoiceConnectionChanged(uint32_t aClientId);
#endif
bool IsConnected();
bool IsScoConnected();
#ifdef MOZ_B2G_RIL
// CDMA-specific functions
void UpdateSecondNumber(const nsAString& aNumber);
void AnswerWaitingCall();

View File

@ -18,29 +18,15 @@ class BluetoothHidManager : public BluetoothProfileManagerBase
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
static BluetoothHidManager* Get();
~BluetoothHidManager();
// The following functions are inherited from BluetoothProfileManagerBase
virtual void OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel) MOZ_OVERRIDE;
virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) MOZ_OVERRIDE;
virtual void GetAddress(nsAString& aDeviceAddress) MOZ_OVERRIDE;
virtual bool IsConnected() MOZ_OVERRIDE;
virtual void Connect(const nsAString& aDeviceAddress,
BluetoothProfileController* aController) MOZ_OVERRIDE;
virtual void Disconnect(BluetoothProfileController* aController)
MOZ_OVERRIDE;
virtual void OnConnect(const nsAString& aErrorStr) MOZ_OVERRIDE;
virtual void OnDisconnect(const nsAString& aErrorStr) MOZ_OVERRIDE;
BT_DECL_PROFILE_MGR_BASE
virtual void GetName(nsACString& aName)
{
aName.AssignLiteral("HID");
}
static BluetoothHidManager* Get();
~BluetoothHidManager();
// HID-specific functions
void HandleInputPropertyChanged(const BluetoothSignal& aSignal);

View File

@ -31,6 +31,11 @@ class BluetoothOppManager : public BluetoothSocketObserver
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
BT_DECL_PROFILE_MGR_BASE
virtual void GetName(nsACString& aName)
{
aName.AssignLiteral("OPP");
}
/*
* Channel of reserved services are fixed values, please check
@ -69,25 +74,6 @@ public:
virtual void OnSocketConnectError(BluetoothSocket* aSocket) MOZ_OVERRIDE;
virtual void OnSocketDisconnect(BluetoothSocket* aSocket) MOZ_OVERRIDE;
// The following functions are inherited from BluetoothProfileManagerBase
virtual void OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
int aChannel) MOZ_OVERRIDE;
virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) MOZ_OVERRIDE;
virtual void GetAddress(nsAString& aDeviceAddress) MOZ_OVERRIDE;
virtual bool IsConnected() MOZ_OVERRIDE;
virtual void GetName(nsACString& aName)
{
aName.AssignLiteral("OPP");
}
virtual void Connect(const nsAString& aDeviceAddress,
BluetoothProfileController* aController) MOZ_OVERRIDE;
virtual void Disconnect(BluetoothProfileController* aController) MOZ_OVERRIDE;
virtual void OnConnect(const nsAString& aErrorStr) MOZ_OVERRIDE;
virtual void OnDisconnect(const nsAString& aErrorStr) MOZ_OVERRIDE;
private:
BluetoothOppManager();
bool Init();

View File

@ -70,6 +70,20 @@ public:
virtual void GetName(nsACString& aName) = 0;
};
#define BT_DECL_PROFILE_MGR_BASE \
public: \
virtual void OnGetServiceChannel(const nsAString& aDeviceAddress, \
const nsAString& aServiceUuid, \
int aChannel) MOZ_OVERRIDE; \
virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) MOZ_OVERRIDE; \
virtual void GetAddress(nsAString& aDeviceAddress) MOZ_OVERRIDE; \
virtual bool IsConnected() MOZ_OVERRIDE; \
virtual void Connect(const nsAString& aDeviceAddress, \
BluetoothProfileController* aController) MOZ_OVERRIDE; \
virtual void Disconnect(BluetoothProfileController* aController) MOZ_OVERRIDE; \
virtual void OnConnect(const nsAString& aErrorStr) MOZ_OVERRIDE; \
virtual void OnDisconnect(const nsAString& AErrorStr) MOZ_OVERRIDE; \
END_BLUETOOTH_NAMESPACE
#endif //#ifndef mozilla_dom_bluetooth_bluetoothprofilemanagerbase_h__

View File

@ -21,6 +21,7 @@
#include <hardware/bluetooth.h>
#include <hardware/hardware.h>
#include "BluetoothProfileController.h"
#include "BluetoothReplyRunnable.h"
#include "BluetoothUtils.h"
#include "BluetoothUuid.h"
@ -70,6 +71,7 @@ static nsString sAdapterBdName;
static uint32_t sAdapterDiscoverableTimeout;
static InfallibleTArray<nsString> sAdapterBondedAddressArray;
static InfallibleTArray<BluetoothNamedValue> sRemoteDevicesPack;
static nsTArray<nsRefPtr<BluetoothProfileController> > sControllerArray;
static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sBondingRunnableArray;
static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sChangeDiscoveryRunnableArray;
static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sGetPairedDeviceRunnableArray;
@ -1079,13 +1081,55 @@ BluetoothServiceBluedroid::PrepareAdapterInternal()
return NS_OK;
}
static void
NextBluetoothProfileController()
{
sControllerArray[0] = nullptr;
sControllerArray.RemoveElementAt(0);
if (!sControllerArray.IsEmpty()) {
sControllerArray[0]->Start();
}
}
static void
ConnectDisconnect(bool aConnect, const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable,
uint16_t aServiceUuid, uint32_t aCod = 0)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aRunnable);
BluetoothProfileController* controller =
new BluetoothProfileController(aConnect, aDeviceAddress, aRunnable,
NextBluetoothProfileController,
aServiceUuid, aCod);
sControllerArray.AppendElement(controller);
/**
* If the request is the first element of the quene, start from here. Note
* that other request is pushed into the quene and is popped out after the
* first one is completed. See NextBluetoothProfileController() for details.
*/
if (sControllerArray.Length() == 1) {
sControllerArray[0]->Start();
}
}
void
BluetoothServiceBluedroid::Connect(const nsAString& aDeviceAddress,
uint32_t aCod,
uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable)
{
// TODO: Remove this error reply once Connect() is done in profile managers
if (aRunnable) {
DispatchBluetoothReply(aRunnable, BluetoothValue(),
NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
return;
}
ConnectDisconnect(true, aDeviceAddress, aRunnable, aServiceUuid, aCod);
}
bool
@ -1099,7 +1143,14 @@ BluetoothServiceBluedroid::Disconnect(
const nsAString& aDeviceAddress, uint16_t aServiceUuid,
BluetoothReplyRunnable* aRunnable)
{
// TODO: Remove this error reply once Disconnect() is done in profile managers
if (aRunnable) {
DispatchBluetoothReply(aRunnable, BluetoothValue(),
NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
return;
}
ConnectDisconnect(false, aDeviceAddress, aRunnable, aServiceUuid);
}
void