Bug 861085 - Enable/Disable Bluetooth based on mozSettings value at startup, r=gyeh, r=qdot

This commit is contained in:
Eric Chou 2013-04-16 11:02:23 +08:00
parent fd6cbbfcfa
commit e909254f82
8 changed files with 62 additions and 26 deletions

View File

@ -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

View File

@ -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.
*/

View File

@ -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);
}

View File

@ -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

View File

@ -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)
{

View File

@ -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;

View File

@ -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:

View File

@ -30,6 +30,8 @@ public:
virtual nsresult StopInternal();
virtual bool IsEnabledInternal();
virtual nsresult GetDefaultAdapterPathInternal(BluetoothReplyRunnable* aRunnable);
virtual nsresult GetPairedDevicePropertiesInternal(const nsTArray<nsString>& aDeviceAddresses,