Bug 892392 - Execute BluetoothService::StartInternal() at startup, r=gyeh

This commit is contained in:
Eric Chou 2013-08-02 11:58:01 +08:00
parent 6b51784fd9
commit 94d685e575
2 changed files with 17 additions and 11 deletions

View File

@ -168,8 +168,9 @@ private:
class BluetoothService::ToggleBtTask : public nsRunnable class BluetoothService::ToggleBtTask : public nsRunnable
{ {
public: public:
ToggleBtTask(bool aEnabled) ToggleBtTask(bool aEnabled, bool aIsStartup)
: mEnabled(aEnabled) : mEnabled(aEnabled)
, mIsStartup(aIsStartup)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
} }
@ -178,14 +179,18 @@ public:
{ {
MOZ_ASSERT(!NS_IsMainThread()); MOZ_ASSERT(!NS_IsMainThread());
/* /**
* mEnabled: expected status of bluetooth * mEnabled: expected status of bluetooth
* gBluetoothService->IsEnabled(): real status of bluetooth * gBluetoothService->IsEnabled(): real status of bluetooth
* *
* When two values are the same, we don't switch on/off bluetooth, * When two values are the same, we don't switch on/off bluetooth
* but we still do ToggleBtAck task. * but we still do ToggleBtAck task. One special case happens at startup
* stage. At startup, the initialization of BluetoothService still has to
* be done even if mEnabled is equal to the status of Bluetooth firmware.
*
* Please see bug 892392 for more information.
*/ */
if (mEnabled == gBluetoothService->IsEnabledInternal()) { if (!mIsStartup && mEnabled == gBluetoothService->IsEnabledInternal()) {
NS_WARNING("Bluetooth has already been enabled/disabled before."); NS_WARNING("Bluetooth has already been enabled/disabled before.");
} else { } else {
// Switch on/off bluetooth // Switch on/off bluetooth
@ -225,6 +230,7 @@ public:
private: private:
bool mEnabled; bool mEnabled;
bool mIsStartup;
}; };
class BluetoothService::StartupTask : public nsISettingsServiceCallback class BluetoothService::StartupTask : public nsISettingsServiceCallback
@ -442,7 +448,7 @@ BluetoothService::DistributeSignal(const BluetoothSignal& aSignal)
} }
nsresult nsresult
BluetoothService::StartStopBluetooth(bool aStart) BluetoothService::StartStopBluetooth(bool aStart, bool aIsStartup)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
@ -469,7 +475,7 @@ BluetoothService::StartStopBluetooth(bool aStart)
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
nsCOMPtr<nsIRunnable> runnable = new ToggleBtTask(aStart); nsCOMPtr<nsIRunnable> runnable = new ToggleBtTask(aStart, aIsStartup);
rv = mBluetoothCommandThread->Dispatch(runnable, NS_DISPATCH_NORMAL); rv = mBluetoothCommandThread->Dispatch(runnable, NS_DISPATCH_NORMAL);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -539,7 +545,7 @@ nsresult
BluetoothService::HandleStartupSettingsCheck(bool aEnable) BluetoothService::HandleStartupSettingsCheck(bool aEnable)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
return StartStopBluetooth(aEnable); return StartStopBluetooth(aEnable, true);
} }
nsresult nsresult
@ -625,7 +631,7 @@ BluetoothService::HandleSettingsChanged(const nsAString& aData)
gToggleInProgress = true; gToggleInProgress = true;
nsresult rv = StartStopBluetooth(value.toBoolean()); nsresult rv = StartStopBluetooth(value.toBoolean(), false);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
@ -690,7 +696,7 @@ BluetoothService::HandleShutdown()
} }
} }
if (IsEnabled() && NS_FAILED(StartStopBluetooth(false))) { if (IsEnabled() && NS_FAILED(StartStopBluetooth(false, false))) {
MOZ_ASSERT(false, "Failed to deliver stop message!"); MOZ_ASSERT(false, "Failed to deliver stop message!");
} }

View File

@ -325,7 +325,7 @@ protected:
Cleanup(); Cleanup();
nsresult nsresult
StartStopBluetooth(bool aStart); StartStopBluetooth(bool aStart, bool aIsStartup);
/** /**
* Platform specific startup functions go here. Usually deals with member * Platform specific startup functions go here. Usually deals with member