Bug 815325 - Patch 1: Turning bluetooth on and off multiple times causes restart, r=echou
This commit is contained in:
@@ -1428,6 +1428,16 @@ GetDefaultAdapterPath(BluetoothValue& aValue, nsString& aError)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothDBusService::IsReady()
|
||||
{
|
||||
if (!IsEnabled() || !mConnection || !gThreadConnection || IsToggling()) {
|
||||
NS_WARNING("Bluetooth service is not ready yet!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothDBusService::StartInternal()
|
||||
{
|
||||
@@ -1607,14 +1617,17 @@ private:
|
||||
nsresult
|
||||
BluetoothDBusService::GetDefaultAdapterPathInternal(BluetoothReplyRunnable* aRunnable)
|
||||
{
|
||||
if (!mConnection || !gThreadConnection) {
|
||||
NS_ERROR("Bluetooth service not started yet!");
|
||||
return NS_ERROR_FAILURE;
|
||||
NS_ASSERTION(NS_IsMainThread(), "Must be called from main thread!");
|
||||
|
||||
if (!IsReady()) {
|
||||
BluetoothValue v;
|
||||
nsString errorStr;
|
||||
errorStr.AssignLiteral("Bluetooth service is not ready yet!");
|
||||
DispatchBluetoothReply(aRunnable, v, errorStr);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_ASSERTION(NS_IsMainThread(), "Must be called from main thread!");
|
||||
nsRefPtr<BluetoothReplyRunnable> runnable = aRunnable;
|
||||
|
||||
nsRefPtr<nsRunnable> func(new DefaultAdapterPropertiesRunnable(runnable));
|
||||
if (NS_FAILED(mBluetoothCommandThread->Dispatch(func, NS_DISPATCH_NORMAL))) {
|
||||
NS_WARNING("Cannot dispatch firmware loading task!");
|
||||
@@ -1655,8 +1668,11 @@ nsresult
|
||||
BluetoothDBusService::StopDiscoveryInternal(const nsAString& aAdapterPath,
|
||||
BluetoothReplyRunnable* aRunnable)
|
||||
{
|
||||
if (!mConnection) {
|
||||
NS_WARNING("Bluetooth service not started yet, no need to stop discovery.");
|
||||
if (!IsReady()) {
|
||||
BluetoothValue v;
|
||||
nsString errorStr;
|
||||
errorStr.AssignLiteral("Bluetooth service is not ready yet!");
|
||||
DispatchBluetoothReply(aRunnable, v, errorStr);
|
||||
return NS_OK;
|
||||
}
|
||||
return SendDiscoveryMessage(aAdapterPath, "StopDiscovery", aRunnable);
|
||||
@@ -1666,9 +1682,12 @@ nsresult
|
||||
BluetoothDBusService::StartDiscoveryInternal(const nsAString& aAdapterPath,
|
||||
BluetoothReplyRunnable* aRunnable)
|
||||
{
|
||||
if (!mConnection) {
|
||||
NS_WARNING("Bluetooth service not started yet, cannot start discovery!");
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!IsReady()) {
|
||||
BluetoothValue v;
|
||||
nsString errorStr;
|
||||
errorStr.AssignLiteral("Bluetooth service is not ready yet!");
|
||||
DispatchBluetoothReply(aRunnable, v, errorStr);
|
||||
return NS_OK;
|
||||
}
|
||||
return SendDiscoveryMessage(aAdapterPath, "StartDiscovery", aRunnable);
|
||||
}
|
||||
@@ -1877,12 +1896,15 @@ nsresult
|
||||
BluetoothDBusService::GetPairedDevicePropertiesInternal(const nsTArray<nsString>& aDeviceAddresses,
|
||||
BluetoothReplyRunnable* aRunnable)
|
||||
{
|
||||
if (!mConnection || !gThreadConnection) {
|
||||
NS_ERROR("Bluetooth service not started yet!");
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!IsReady()) {
|
||||
BluetoothValue v;
|
||||
nsString errorStr;
|
||||
errorStr.AssignLiteral("Bluetooth service is not ready yet!");
|
||||
DispatchBluetoothReply(aRunnable, v, errorStr);
|
||||
return NS_OK;
|
||||
}
|
||||
nsRefPtr<BluetoothReplyRunnable> runnable = aRunnable;
|
||||
|
||||
nsRefPtr<BluetoothReplyRunnable> runnable = aRunnable;
|
||||
nsRefPtr<nsRunnable> func(new BluetoothPairedDevicePropertiesRunnable(runnable, aDeviceAddresses));
|
||||
if (NS_FAILED(mBluetoothCommandThread->Dispatch(func, NS_DISPATCH_NORMAL))) {
|
||||
NS_WARNING("Cannot dispatch task!");
|
||||
@@ -2501,9 +2523,12 @@ BluetoothDBusService::GetSocketViaService(const nsAString& aObjectPath,
|
||||
BluetoothReplyRunnable* aRunnable)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Must be called from main thread!");
|
||||
if (!mConnection || !gThreadConnection) {
|
||||
NS_ERROR("Bluetooth service not started yet!");
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!IsReady()) {
|
||||
BluetoothValue v;
|
||||
nsString errorStr;
|
||||
errorStr.AssignLiteral("Bluetooth service is not ready yet!");
|
||||
DispatchBluetoothReply(aRunnable, v, errorStr);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsRefPtr<BluetoothReplyRunnable> runnable = aRunnable;
|
||||
@@ -2530,6 +2555,7 @@ BluetoothDBusService::GetScoSocket(const nsAString& aAddress,
|
||||
mozilla::ipc::UnixSocketConsumer* aConsumer)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Must be called from main thread!");
|
||||
|
||||
if (!mConnection || !gThreadConnection) {
|
||||
NS_ERROR("Bluetooth service not started yet!");
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
Reference in New Issue
Block a user