diff --git a/dom/bluetooth/BluetoothService.cpp b/dom/bluetooth/BluetoothService.cpp index 8ca4f7fe4be..0013fbd8485 100644 --- a/dom/bluetooth/BluetoothService.cpp +++ b/dom/bluetooth/BluetoothService.cpp @@ -184,7 +184,7 @@ public: * When two values are the same, we don't switch on/off bluetooth, * but we still do ToggleBtAck task. */ - if (mEnabled == gBluetoothService->IsEnabled()) { + if (mEnabled == gBluetoothService->IsEnabledInternal()) { NS_WARNING("Bluetooth has already been enabled/disabled before."); } else { // Switch on/off bluetooth @@ -529,18 +529,7 @@ nsresult BluetoothService::HandleStartupSettingsCheck(bool aEnable) { MOZ_ASSERT(NS_IsMainThread()); - - if (aEnable) { - return StartStopBluetooth(true); - } - - /* - * Since BLUETOOTH_ENABLED_SETTING is false, we don't have to turn on - * bluetooth here, and set gToggleInProgress back to false. - */ - gToggleInProgress = false; - - return NS_OK; + return StartStopBluetooth(aEnable); } nsresult diff --git a/dom/bluetooth/BluetoothService.h b/dom/bluetooth/BluetoothService.h index 7754113e776..3a1694b9ebb 100644 --- a/dom/bluetooth/BluetoothService.h +++ b/dom/bluetooth/BluetoothService.h @@ -292,7 +292,7 @@ protected: virtual nsresult StartInternal() = 0; - /** + /** * Platform specific startup functions go here. Usually deals with member * variables, so not static. Guaranteed to be called outside of main thread. * @@ -301,6 +301,15 @@ protected: virtual nsresult StopInternal() = 0; + /** + * Platform specific startup functions go here. Usually deals with member + * variables, so not static. Guaranteed to be called outside of main thread. + * + * @return true if Bluetooth is enabled, false otherwise + */ + virtual bool + IsEnabledInternal() = 0; + /** * Called when XPCOM first creates this service. */ diff --git a/dom/bluetooth/gonk/BluetoothGonkService.cpp b/dom/bluetooth/gonk/BluetoothGonkService.cpp index 1519431b818..8e90c2f94db 100644 --- a/dom/bluetooth/gonk/BluetoothGonkService.cpp +++ b/dom/bluetooth/gonk/BluetoothGonkService.cpp @@ -120,7 +120,7 @@ StartStopGonkBluetooth(bool aShouldEnable) nsresult BluetoothGonkService::StartInternal() { - NS_ASSERTION(!NS_IsMainThread(), "This should not run on the main thread!"); + MOZ_ASSERT(!NS_IsMainThread()); nsresult ret; @@ -136,7 +136,7 @@ BluetoothGonkService::StartInternal() nsresult BluetoothGonkService::StopInternal() { - NS_ASSERTION(!NS_IsMainThread(), "This should not run on the main thread!"); + MOZ_ASSERT(!NS_IsMainThread()); nsresult ret; @@ -149,3 +149,16 @@ BluetoothGonkService::StopInternal() return StartStopGonkBluetooth(false); } +bool +BluetoothGonkService::IsEnabledInternal() +{ + MOZ_ASSERT(!NS_IsMainThread()); + + if (!EnsureBluetoothInit()) { + NS_ERROR("Failed to load bluedroid library.\n"); + return false; + } + + return (sBluedroidFunctions.bt_is_enabled() == 1); +} + diff --git a/dom/bluetooth/gonk/BluetoothGonkService.h b/dom/bluetooth/gonk/BluetoothGonkService.h index 997792c0266..b9fff9c9a48 100644 --- a/dom/bluetooth/gonk/BluetoothGonkService.h +++ b/dom/bluetooth/gonk/BluetoothGonkService.h @@ -35,23 +35,27 @@ BEGIN_BLUETOOTH_NAMESPACE class BluetoothGonkService : public BluetoothDBusService { public: - /** + /** * Set up variables and start the platform specific connection. Must - * be called from main thread. + * be called from non-main thread. * - * @return NS_OK if connection starts successfully, NS_ERROR_FAILURE - * otherwise + * @return NS_OK if connection starts successfully, NS_ERROR_FAILURE otherwise */ virtual nsresult StartInternal(); - /** - * Stop the platform specific connection. Must be called from main - * thread. + /** + * Stop the platform specific connection. Must be called from non-main thread. * - * @return NS_OK if connection starts successfully, NS_ERROR_FAILURE - * otherwise + * @return NS_OK if connection starts successfully, NS_ERROR_FAILURE otherwise */ virtual nsresult StopInternal(); + + /** + * Get status of Bluetooth. Must be called from non-main thread. + * + * @return true if Bluetooth is enabled, false otherwise + */ + virtual bool IsEnabledInternal(); }; END_BLUETOOTH_NAMESPACE diff --git a/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp b/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp index ea71d37fc33..0be3ca71b31 100644 --- a/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp +++ b/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp @@ -361,6 +361,13 @@ BluetoothServiceChildProcess::StopInternal() return NS_ERROR_FAILURE; } +bool +BluetoothServiceChildProcess::IsEnabledInternal() +{ + MOZ_NOT_REACHED("This should never be called!"); + return false; +} + bool BluetoothServiceChildProcess::IsConnected(uint16_t aProfileId) { diff --git a/dom/bluetooth/ipc/BluetoothServiceChildProcess.h b/dom/bluetooth/ipc/BluetoothServiceChildProcess.h index d2933610912..4ae83c53e3e 100644 --- a/dom/bluetooth/ipc/BluetoothServiceChildProcess.h +++ b/dom/bluetooth/ipc/BluetoothServiceChildProcess.h @@ -163,6 +163,10 @@ private: virtual nsresult StopInternal() MOZ_OVERRIDE; + // This method should never be called. + virtual bool + IsEnabledInternal() MOZ_OVERRIDE; + // Should never be called from the child virtual nsresult GetDevicePropertiesInternal(const BluetoothSignal& aSignal) MOZ_OVERRIDE; diff --git a/dom/bluetooth/linux/BluetoothDBusService.cpp b/dom/bluetooth/linux/BluetoothDBusService.cpp index 2bcb6f331c0..be4b362d5ec 100644 --- a/dom/bluetooth/linux/BluetoothDBusService.cpp +++ b/dom/bluetooth/linux/BluetoothDBusService.cpp @@ -1708,7 +1708,9 @@ BluetoothDBusService::StopInternal() // If Bluetooth is turned off while connections exist, in order not to only // disconnect with profile connections with low level ACL connections alive, // we disconnect ACLs directly instead of closing each socket. - DisconnectAllAcls(sAdapterPath); + if (!sAdapterPath.IsEmpty()) { + DisconnectAllAcls(sAdapterPath); + } if (!mConnection) { StopDBus(); @@ -1756,6 +1758,12 @@ BluetoothDBusService::StopInternal() return NS_OK; } +bool +BluetoothDBusService::IsEnabledInternal() +{ + return mEnabled; +} + class DefaultAdapterPropertiesRunnable : public nsRunnable { public: diff --git a/dom/bluetooth/linux/BluetoothDBusService.h b/dom/bluetooth/linux/BluetoothDBusService.h index e31f4105080..697991571f9 100644 --- a/dom/bluetooth/linux/BluetoothDBusService.h +++ b/dom/bluetooth/linux/BluetoothDBusService.h @@ -30,6 +30,8 @@ public: virtual nsresult StopInternal(); + virtual bool IsEnabledInternal(); + virtual nsresult GetDefaultAdapterPathInternal(BluetoothReplyRunnable* aRunnable); virtual nsresult GetPairedDevicePropertiesInternal(const nsTArray& aDeviceAddresses,