Bug 818696 - prevent "pairing failed" prompt from appearing after re-enabling Bluetooth, r=gyeh

This commit is contained in:
Eric Chou 2012-12-11 19:31:47 +08:00
parent a1035b515e
commit ff2cd83c25

View File

@ -151,6 +151,7 @@ static const char* sBluetoothDBusSignals[] =
static nsAutoPtr<RawDBusConnection> gThreadConnection; static nsAutoPtr<RawDBusConnection> gThreadConnection;
static nsDataHashtable<nsStringHashKey, DBusMessage* > sPairingReqTable; static nsDataHashtable<nsStringHashKey, DBusMessage* > sPairingReqTable;
static nsDataHashtable<nsStringHashKey, DBusMessage* > sAuthorizeReqTable; static nsDataHashtable<nsStringHashKey, DBusMessage* > sAuthorizeReqTable;
static bool sIsPairing = false;
typedef void (*UnpackFunc)(DBusMessage*, DBusError*, BluetoothValue&, nsAString&); typedef void (*UnpackFunc)(DBusMessage*, DBusError*, BluetoothValue&, nsAString&);
class DistributeBluetoothSignalTask : public nsRunnable { class DistributeBluetoothSignalTask : public nsRunnable {
@ -819,8 +820,12 @@ RunDBusCallback(DBusMessage* aMsg, void* aBluetoothReplyRunnable,
void void
GetObjectPathCallback(DBusMessage* aMsg, void* aBluetoothReplyRunnable) GetObjectPathCallback(DBusMessage* aMsg, void* aBluetoothReplyRunnable)
{ {
RunDBusCallback(aMsg, aBluetoothReplyRunnable, if (sIsPairing) {
UnpackObjectPathMessage); RunDBusCallback(aMsg, aBluetoothReplyRunnable,
UnpackObjectPathMessage);
sIsPairing = false;
}
} }
void void
@ -1566,6 +1571,8 @@ BluetoothDBusService::StopInternal()
sAuthorizeReqTable.EnumerateRead(UnrefDBusMessages, nullptr); sAuthorizeReqTable.EnumerateRead(UnrefDBusMessages, nullptr);
sAuthorizeReqTable.Clear(); sAuthorizeReqTable.Clear();
sIsPairing = false;
StopDBus(); StopDBus();
return NS_OK; return NS_OK;
} }
@ -2087,6 +2094,21 @@ BluetoothDBusService::CreatePairedDeviceInternal(const nsAString& aAdapterPath,
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
/**
* FIXME: Bug 820274
*
* If the user turns off Bluetooth in the middle of pairing process, the
* callback function GetObjectPathCallback (see the third argument of the
* function call above) may still be called while enabling next time by
* dbus daemon. To prevent this from happening, added a flag to distinguish
* if Bluetooth has been turned off. Nevertheless, we need a check if there
* is a better solution.
*
* Please see Bug 818696 for more information.
*/
sIsPairing = true;
runnable.forget(); runnable.forget();
return NS_OK; return NS_OK;
} }