Bug 1239979: Init and uninit all Bluetooth profile managers, r=shuang

The use is init and deinit methods is currently inconsistent among
Bluetooth profile managers. This patch unifies all these methods and
integrates them into the Bluetooth service. Instances of the manager
classes are now unref'ed during Bluetooth shutdown.
This commit is contained in:
Thomas Zimmermann 2016-01-21 12:30:00 +01:00
parent 67a377cc9b
commit 599768e032
14 changed files with 126 additions and 1 deletions

View File

@ -296,6 +296,7 @@ public:
sBtA2dpInterface->SetNotificationHandler(nullptr);
sBtA2dpInterface = nullptr;
sBluetoothA2dpManager = nullptr;
if (mRes) {
mRes->OnError(NS_ERROR_FAILURE);
@ -308,6 +309,7 @@ public:
sBtA2dpInterface->SetNotificationHandler(nullptr);
sBtA2dpInterface = nullptr;
sBluetoothA2dpManager = nullptr;
if (mRes) {
mRes->Deinit();

View File

@ -317,6 +317,7 @@ public:
sBtAvrcpInterface->SetNotificationHandler(nullptr);
sBtAvrcpInterface = nullptr;
sBluetoothAvrcpManager = nullptr;
if (mRes) {
mRes->OnError(NS_ERROR_FAILURE);
@ -329,6 +330,7 @@ public:
sBtAvrcpInterface->SetNotificationHandler(nullptr);
sBtAvrcpInterface = nullptr;
sBluetoothAvrcpManager = nullptr;
if (mRes) {
mRes->Deinit();

View File

@ -583,6 +583,7 @@ public:
sBluetoothGattInterface = nullptr;
sClients = nullptr;
sServers = nullptr;
sBluetoothGattManager = nullptr;
if (mRes) {
mRes->Deinit();

View File

@ -133,6 +133,30 @@ BluetoothMapSmsManager::Init()
return true;
}
// static
void
BluetoothMapSmsManager::InitMapSmsInterface(BluetoothProfileResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
if (aRes) {
aRes->Init();
}
}
// static
void
BluetoothMapSmsManager::DeinitMapSmsInterface(BluetoothProfileResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
sMapSmsManager = nullptr;
if (aRes) {
aRes->Deinit();
}
}
//static
BluetoothMapSmsManager*
BluetoothMapSmsManager::Get()

View File

@ -86,7 +86,10 @@ public:
// By defualt SMS/MMS is default supported
static const int SDP_SMS_MMS_INSTANCE_ID = 0;
static void InitMapSmsInterface(BluetoothProfileResultHandler* aRes);
static void DeinitMapSmsInterface(BluetoothProfileResultHandler* aRes);
static BluetoothMapSmsManager* Get();
bool Listen();
/**

View File

@ -253,6 +253,30 @@ BluetoothOppManager::Init()
return true;
}
// static
void
BluetoothOppManager::InitOppInterface(BluetoothProfileResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
if (aRes) {
aRes->Init();
}
}
// static
void
BluetoothOppManager::DeinitOppInterface(BluetoothProfileResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
sBluetoothOppManager = nullptr;
if (aRes) {
aRes->Deinit();
}
}
//static
BluetoothOppManager*
BluetoothOppManager::Get()

View File

@ -40,6 +40,7 @@ class BluetoothOppManager : public BluetoothSocketObserver
class SendSocketDataTask;
public:
BT_DECL_PROFILE_MGR_BASE
BT_DECL_SOCKET_OBSERVER
virtual void GetName(nsACString& aName)
@ -49,7 +50,10 @@ public:
static const int MAX_PACKET_LENGTH = 0xFFFE;
static void InitOppInterface(BluetoothProfileResultHandler* aRes);
static void DeinitOppInterface(BluetoothProfileResultHandler* aRes);
static BluetoothOppManager* Get();
void ClientDataHandler(mozilla::ipc::UnixSocketBuffer* aMessage);
void ServerDataHandler(mozilla::ipc::UnixSocketBuffer* aMessage);

View File

@ -140,6 +140,30 @@ BluetoothPbapManager::Init()
return true;
}
// static
void
BluetoothPbapManager::InitPbapInterface(BluetoothProfileResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
if (aRes) {
aRes->Init();
}
}
// static
void
BluetoothPbapManager::DeinitPbapInterface(BluetoothProfileResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
sPbapManager = nullptr;
if (aRes) {
aRes->Deinit();
}
}
//static
BluetoothPbapManager*
BluetoothPbapManager::Get()

View File

@ -67,7 +67,10 @@ public:
static const int MAX_PACKET_LENGTH = 0xFFFE;
static const int DIGEST_LENGTH = 16;
static void InitPbapInterface(BluetoothProfileResultHandler* aRes);
static void DeinitPbapInterface(BluetoothProfileResultHandler* aRes);
static BluetoothPbapManager* Get();
bool Listen();
/**

View File

@ -138,6 +138,10 @@ public:
void Init() override
{
static void (* const sInitManager[])(BluetoothProfileResultHandler*) = {
BluetoothMapSmsManager::InitMapSmsInterface,
BluetoothOppManager::InitOppInterface,
BluetoothPbapManager::InitPbapInterface,
BluetoothHidManager::InitHidInterface,
BluetoothHfpManager::InitHfpInterface,
BluetoothA2dpManager::InitA2dpInterface,
BluetoothAvrcpManager::InitAvrcpInterface,
@ -2037,7 +2041,11 @@ BluetoothServiceBluedroid::AdapterStateChangedNotification(bool aState)
BluetoothGattManager::DeinitGattInterface,
BluetoothAvrcpManager::DeinitAvrcpInterface,
BluetoothA2dpManager::DeinitA2dpInterface,
BluetoothHfpManager::DeinitHfpInterface
BluetoothHfpManager::DeinitHfpInterface,
BluetoothHidManager::DeinitHidInterface,
BluetoothPbapManager::DeinitPbapInterface,
BluetoothOppManager::DeinitOppInterface,
BluetoothMapSmsManager::DeinitMapSmsInterface
};
// Return error if BluetoothService is unavailable

View File

@ -176,6 +176,8 @@ BluetoothHfpManager::DeinitHfpInterface(BluetoothProfileResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
sBluetoothHfpManager = nullptr;
/**
* TODO:
* Implement DeinitHfpInterface() for applications that want to create SCO

View File

@ -446,6 +446,7 @@ public:
sBluetoothHfpInterface->SetNotificationHandler(nullptr);
sBluetoothHfpInterface = nullptr;
sBluetoothHfpManager = nullptr;
if (mRes) {
mRes->OnError(NS_ERROR_FAILURE);
@ -458,6 +459,7 @@ public:
sBluetoothHfpInterface->SetNotificationHandler(nullptr);
sBluetoothHfpInterface = nullptr;
sBluetoothHfpManager = nullptr;
if (mRes) {
mRes->Deinit();

View File

@ -78,6 +78,30 @@ BluetoothHidManager::~BluetoothHidManager()
}
}
// static
void
BluetoothHidManager::InitHidInterface(BluetoothProfileResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
if (aRes) {
aRes->Init();
}
}
// static
void
BluetoothHidManager::DeinitHidInterface(BluetoothProfileResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
sBluetoothHidManager = nullptr;
if (aRes) {
aRes->Deinit();
}
}
//static
BluetoothHidManager*
BluetoothHidManager::Get()

View File

@ -22,6 +22,8 @@ public:
aName.AssignLiteral("HID");
}
static void InitHidInterface(BluetoothProfileResultHandler* aRes);
static void DeinitHidInterface(BluetoothProfileResultHandler* aRes);
static BluetoothHidManager* Get();
// HID-specific functions