Bug 812404 - Patch 1: Crash when connect with a bluetooth headset right after pairing completed, r=echou

This commit is contained in:
Gina Yeh 2012-11-16 18:46:08 +08:00
parent 1b167c9767
commit aa95503d71
8 changed files with 31 additions and 35 deletions

View File

@ -744,15 +744,11 @@ BluetoothAdapter::Connect(const nsAString& aDeviceAddress,
return NS_ERROR_FAILURE;
}
nsRefPtr<BluetoothVoidReplyRunnable> result = new BluetoothVoidReplyRunnable(req);
if (!bs->Connect(aDeviceAddress, mPath, aProfileId, result)) {
NS_WARNING("Creating RFCOMM socket failed or unknown profile.");
return NS_ERROR_FAILURE;
}
nsRefPtr<BluetoothVoidReplyRunnable> results =
new BluetoothVoidReplyRunnable(req);
bs->Connect(aDeviceAddress, mPath, aProfileId, results);
req.forget(aRequest);
return NS_OK;
}
@ -779,12 +775,11 @@ BluetoothAdapter::Disconnect(uint16_t aProfileId,
return NS_ERROR_FAILURE;
}
nsRefPtr<BluetoothVoidReplyRunnable> result = new BluetoothVoidReplyRunnable(req);
nsRefPtr<BluetoothVoidReplyRunnable> result =
new BluetoothVoidReplyRunnable(req);
bs->Disconnect(aProfileId, result);
req.forget(aRequest);
return NS_OK;
}

View File

@ -580,8 +580,9 @@ BluetoothHfpManager::Connect(const nsAString& aDevicePath,
return false;
}
if (GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTED) {
NS_WARNING("BluetoothHfpManager has connected to a headset/handsfree!");
if (GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTED ||
GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTING) {
NS_WARNING("BluetoothHfpManager has connected/is connecting to a headset!");
return false;
}

View File

@ -264,7 +264,7 @@ public:
virtual nsresult
PrepareAdapterInternal(const nsAString& aPath) = 0;
virtual bool
virtual void
Connect(const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
uint16_t aProfileId,

View File

@ -505,10 +505,12 @@ BluetoothRequestParent::DoRequest(const ConnectRequest& aRequest)
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TConnectRequest);
return mService->Connect(aRequest.address(),
aRequest.adapterPath(),
aRequest.profileId(),
mReplyRunnable.get());
mService->Connect(aRequest.address(),
aRequest.adapterPath(),
aRequest.profileId(),
mReplyRunnable.get());
return true;
}
bool

View File

@ -300,7 +300,7 @@ BluetoothServiceChildProcess::PrepareAdapterInternal(const nsAString& aPath)
return NS_ERROR_NOT_IMPLEMENTED;
}
bool
void
BluetoothServiceChildProcess::Connect(
const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
@ -308,11 +308,9 @@ BluetoothServiceChildProcess::Connect(
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable,
ConnectRequest(nsString(aDeviceAddress),
ConnectRequest(nsString(aDeviceAddress),
nsString(aAdapterPath),
aProfileId));
return true;
}
void

View File

@ -129,7 +129,7 @@ public:
bool aAllow,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual bool
virtual void
Connect(const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
const uint16_t aProfileId,

View File

@ -2325,7 +2325,7 @@ BluetoothDBusService::PrepareAdapterInternal(const nsAString& aPath)
return NS_OK;
}
bool
void
BluetoothDBusService::Connect(const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
const uint16_t aProfileId,
@ -2333,34 +2333,34 @@ BluetoothDBusService::Connect(const nsAString& aDeviceAddress,
{
NS_ASSERTION(NS_IsMainThread(), "Must be called from main thread!");
BluetoothValue v;
nsString errorStr;
BluetoothValue v = true;
if (aProfileId == (uint16_t)(BluetoothServiceUuid::Handsfree >> 32)) {
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
if (!hfp->Connect(GetObjectPathFromAddress(aAdapterPath, aDeviceAddress),
true, aRunnable)) {
errorStr.AssignLiteral("Failed to connect with device.");
errorStr.AssignLiteral("BluetoothHfpManager has connected/is connecting to a headset!");
DispatchBluetoothReply(aRunnable, v, errorStr);
return false;
}
return true;
} else if (aProfileId == (uint16_t)(BluetoothServiceUuid::Headset >> 32)) {
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
if (!hfp->Connect(GetObjectPathFromAddress(aAdapterPath, aDeviceAddress),
false, aRunnable)) {
errorStr.AssignLiteral("Failed to connect with device.");
errorStr.AssignLiteral("BluetoothHfpManager has connected/is connecting to a headset!");
DispatchBluetoothReply(aRunnable, v, errorStr);
return false;
}
return true;
} else if (aProfileId == (uint16_t)(BluetoothServiceUuid::ObjectPush >> 32)) {
BluetoothOppManager* opp = BluetoothOppManager::Get();
return opp->Connect(GetObjectPathFromAddress(aAdapterPath, aDeviceAddress),
aRunnable);
if (!opp->Connect(GetObjectPathFromAddress(aAdapterPath, aDeviceAddress),
aRunnable)) {
errorStr.AssignLiteral("BluetoothOppManager has connected/is connecting!");
DispatchBluetoothReply(aRunnable, v, errorStr);
}
}
NS_WARNING("Unknow Profile");
return false;
#ifdef DEBUG
NS_WARNING("Unknown Profile");
#endif
}
void

View File

@ -133,7 +133,7 @@ public:
virtual nsresult
PrepareAdapterInternal(const nsAString& aPath);
virtual bool
virtual void
Connect(const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
const uint16_t aProfileId,