Bug 1159179 - Patch 2/3: [PBAP] Revise profile disconnection when BT stops, r=shuang

This commit is contained in:
Ben Tian 2015-05-13 16:29:50 +08:00
parent a482aeaa6d
commit d61dda2930
3 changed files with 61 additions and 55 deletions

View File

@ -31,6 +31,7 @@
// TODO: Support HID
#endif
#include "BluetoothOppManager.h"
#include "BluetoothPbapManager.h"
#include "BluetoothProfileController.h"
#include "BluetoothReplyRunnable.h"
#include "BluetoothUtils.h"
@ -333,35 +334,30 @@ BluetoothServiceBluedroid::StopInternal(BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
BluetoothProfileManagerBase* profile;
profile = BluetoothHfpManager::Get();
NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE);
if (profile->IsConnected()) {
profile->Disconnect(nullptr);
} else {
profile->Reset();
}
static BluetoothProfileManagerBase* sProfiles[] = {
BluetoothHfpManager::Get(),
BluetoothA2dpManager::Get(),
BluetoothOppManager::Get(),
BluetoothPbapManager::Get(),
BluetoothHidManager::Get()
};
profile = BluetoothOppManager::Get();
NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE);
if (profile->IsConnected()) {
profile->Disconnect(nullptr);
}
// Disconnect all connected profiles
for (uint8_t i = 0; i < MOZ_ARRAY_LENGTH(sProfiles); i++) {
nsCString profileName;
sProfiles[i]->GetName(profileName);
profile = BluetoothA2dpManager::Get();
NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE);
if (profile->IsConnected()) {
profile->Disconnect(nullptr);
} else {
profile->Reset();
}
if (NS_WARN_IF(!sProfiles[i])) {
BT_LOGR("Profile manager [%s] is null", profileName.get());
return NS_ERROR_FAILURE;
}
profile = BluetoothHidManager::Get();
NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE);
if (profile->IsConnected()) {
profile->Disconnect(nullptr);
} else {
profile->Reset();
if (sProfiles[i]->IsConnected()) {
sProfiles[i]->Disconnect(nullptr);
} else if (!profileName.EqualsLiteral("OPP") &&
!profileName.EqualsLiteral("PBAP")) {
sProfiles[i]->Reset();
}
}
// aRunnable will be a nullptr during starup and shutdown
@ -2253,11 +2249,16 @@ BluetoothServiceBluedroid::AdapterStateChangedNotification(bool aState)
BluetoothNamedValue(NS_ConvertUTF8toUTF16("Discoverable"), false),
new SetAdapterPropertyDiscoverableResultHandler());
// Trigger BluetoothOppManager to listen
// Trigger OPP & PBAP managers to listen
BluetoothOppManager* opp = BluetoothOppManager::Get();
if (!opp || !opp->Listen()) {
BT_LOGR("Fail to start BluetoothOppManager listening");
}
BluetoothPbapManager* pbap = BluetoothPbapManager::Get();
if (!pbap || !pbap->Listen()) {
BT_LOGR("Fail to start BluetoothPbapManager listening");
}
}
// Resolve promise if existed
@ -2318,12 +2319,18 @@ BluetoothServiceBluedroid::AdapterStateChangedNotification(bool aState)
bs->AdapterAddedReceived();
bs->TryFiringAdapterAdded();
// Trigger BluetoothOppManager to listen
// Trigger OPP & PBAP managers to listen
BluetoothOppManager* opp = BluetoothOppManager::Get();
if (!opp || !opp->Listen()) {
BT_LOGR("Fail to start BluetoothOppManager listening");
}
BluetoothPbapManager* pbap = BluetoothPbapManager::Get();
if (!pbap || !pbap->Listen()) {
BT_LOGR("Fail to start BluetoothPbapManager listening");
}
}
// After ProfileManagers deinit and cleanup, now restarts bluetooth daemon
if (sIsRestart && !aState) {
BT_LOGR("sIsRestart and off, now restart");

View File

@ -15,6 +15,9 @@
#include "BluetoothManager.h"
#include "BluetoothOppManager.h"
#include "BluetoothParent.h"
#if defined(MOZ_B2G_BT_BLUEDROID)
#include "BluetoothPbapManager.h"
#endif
#include "BluetoothReplyRunnable.h"
#include "BluetoothServiceChildProcess.h"
#include "BluetoothUtils.h"
@ -408,35 +411,32 @@ BluetoothService::StopBluetooth(bool aIsStartup)
{
MOZ_ASSERT(NS_IsMainThread());
BluetoothProfileManagerBase* profile;
profile = BluetoothHfpManager::Get();
NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE);
if (profile->IsConnected()) {
profile->Disconnect(nullptr);
} else {
profile->Reset();
}
static BluetoothProfileManagerBase* sProfiles[] = {
BluetoothHfpManager::Get(),
BluetoothA2dpManager::Get(),
BluetoothOppManager::Get(),
#if defined(MOZ_B2G_BT_BLUEDROID)
BluetoothPbapManager::Get(),
#endif
BluetoothHidManager::Get()
};
profile = BluetoothOppManager::Get();
NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE);
if (profile->IsConnected()) {
profile->Disconnect(nullptr);
}
// Disconnect all connected profiles
for (uint8_t i = 0; i < MOZ_ARRAY_LENGTH(sProfiles); i++) {
nsCString profileName;
sProfiles[i]->GetName(profileName);
profile = BluetoothA2dpManager::Get();
NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE);
if (profile->IsConnected()) {
profile->Disconnect(nullptr);
} else {
profile->Reset();
}
if (NS_WARN_IF(!sProfiles[i])) {
BT_LOGR("Profile manager [%s] is null", profileName.get());
return NS_ERROR_FAILURE;
}
profile = BluetoothHidManager::Get();
NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE);
if (profile->IsConnected()) {
profile->Disconnect(nullptr);
} else {
profile->Reset();
if (sProfiles[i]->IsConnected()) {
sProfiles[i]->Disconnect(nullptr);
} else if (!profileName.EqualsLiteral("OPP") &&
!profileName.EqualsLiteral("PBAP")) {
sProfiles[i]->Reset();
}
}
mAdapterAddedReceived = false;

View File

@ -394,7 +394,6 @@ protected:
static BluetoothService*
Create();
typedef nsClassHashtable<nsStringHashKey, BluetoothSignalObserverList >
BluetoothSignalObserverTable;