Bug 1016186 - Do not fire AdapterAdded event when BT is turned on, r=echou

This commit is contained in:
Ben Tian 2014-06-04 16:11:59 +08:00
parent 86e3614aea
commit 1c89f9fe97
4 changed files with 8 additions and 56 deletions

View File

@ -25,7 +25,6 @@
#include "mozilla/unused.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
#include "mozilla/ipc/UnixSocket.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
#include "nsIObserverService.h"
@ -163,7 +162,6 @@ BluetoothService::ToggleBtAck::Run()
sBluetoothService->SetEnabled(mEnabled);
sToggleInProgress = false;
sBluetoothService->TryFiringAdapterAdded();
sBluetoothService->FireAdapterStateChanged(mEnabled);
return NS_OK;
@ -376,8 +374,6 @@ BluetoothService::StartBluetooth(bool aIsStartup,
return NS_ERROR_FAILURE;
}
mAdapterAddedReceived = false;
/* When IsEnabled() is true, we don't switch on Bluetooth but we still
* send ToggleBtAck task. One special case happens at startup stage. At
* startup, the initialization of BluetoothService still has to be done
@ -438,8 +434,6 @@ BluetoothService::StopBluetooth(bool aIsStartup,
profile->Reset();
}
mAdapterAddedReceived = false;
/* When IsEnabled() is false, we don't switch off Bluetooth but we still
* send ToggleBtAck task. One special case happens at startup stage. At
* startup, the initialization of BluetoothService still has to be done
@ -494,8 +488,8 @@ BluetoothService::SetEnabled(bool aEnabled)
* aEnabled: expected status of bluetooth
*/
if (mEnabled == aEnabled) {
BT_WARNING("Bluetooth has already been enabled/disabled before "
"or the toggling is failed.");
BT_WARNING("Bluetooth is already %s, or the toggling failed.",
mEnabled ? "enabled" : "disabled");
}
mEnabled = aEnabled;
@ -564,7 +558,7 @@ BluetoothService::HandleSettingsChanged(const nsAString& aData)
return NS_OK;
}
// First, check if the string equals to BLUETOOTH_DEBUGGING_SETTING
// Check whether the string is BLUETOOTH_DEBUGGING_SETTING
bool match;
if (!JS_StringEqualsAscii(cx, key.toString(), BLUETOOTH_DEBUGGING_SETTING, &match)) {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
@ -706,28 +700,6 @@ BluetoothService::Observe(nsISupports* aSubject, const char* aTopic,
return NS_ERROR_UNEXPECTED;
}
void
BluetoothService::TryFiringAdapterAdded()
{
MOZ_ASSERT(NS_IsMainThread());
if (IsToggling() || !mAdapterAddedReceived) {
return;
}
BluetoothSignal signal(NS_LITERAL_STRING("AdapterAdded"),
NS_LITERAL_STRING(KEY_MANAGER), true);
DistributeSignal(signal);
}
void
BluetoothService::AdapterAddedReceived()
{
MOZ_ASSERT(NS_IsMainThread());
mAdapterAddedReceived = true;
}
/**
* Enable/Disable the local adapter.
*
@ -795,10 +767,8 @@ BluetoothService::Notify(const BluetoothSignal& aData)
"pairedstatuschanged: Wrong length of parameters");
type.AssignLiteral("bluetooth-pairedstatuschanged");
} else {
nsCString warningMsg;
warningMsg.AssignLiteral("Not handling service signal: ");
warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name()));
BT_WARNING(warningMsg.get());
BT_WARNING("Not handling service signal: %s",
NS_ConvertUTF16toUTF8(aData.name()).get());
return;
}

View File

@ -308,13 +308,6 @@ public:
bool
IsToggling() const;
/**
* Below 2 function/variable are used for ensuring event 'AdapterAdded' will
* be fired after event 'Enabled'.
*/
void TryFiringAdapterAdded();
void AdapterAddedReceived();
void FireAdapterStateChanged(bool aEnable);
nsresult EnableDisable(bool aEnable,
BluetoothReplyRunnable* aRunnable);
@ -339,9 +332,7 @@ public:
protected:
BluetoothService() : mEnabled(false)
, mAdapterAddedReceived(false)
{
}
{ }
virtual ~BluetoothService();
@ -400,9 +391,6 @@ protected:
BluetoothSignalObserverTable mBluetoothSignalObserverTable;
bool mEnabled;
private:
bool mAdapterAddedReceived;
};
END_BLUETOOTH_NAMESPACE

View File

@ -127,14 +127,6 @@ public:
BT_LOGR("Fail to set: BT_SCAN_MODE_CONNECTABLE");
}
// Try to fire event 'AdapterAdded' to fit the original behaviour when
// we used BlueZ as backend.
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
bs->AdapterAddedReceived();
bs->TryFiringAdapterAdded();
// Trigger BluetoothOppManager to listen
BluetoothOppManager* opp = BluetoothOppManager::Get();
if (!opp || !opp->Listen()) {

View File

@ -538,8 +538,10 @@ public:
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE_VOID(bs);
#if 0 // for API_V2
bs->AdapterAddedReceived();
bs->TryFiringAdapterAdded();
#endif
}
};