From a2d35c1933e58031ba62bfb7d0806a0b22cbd751 Mon Sep 17 00:00:00 2001 From: Jamin Liu Date: Fri, 16 May 2014 14:35:20 +0800 Subject: [PATCH] Bug 1003472 - If OPP manager can't get valid service channel, refresh SDP records until timeout is hit. r=shuang If user tries to send a file to a device which just completes the pairing process, the OPP manager may update SDP records when it's not ready. It's especially likely to occur in BT file transfer with inline pairing since OPP manager would request for a service channel to send the file when device is just paired. --- dom/bluetooth/bluez/BluetoothOppManager.cpp | 16 +++++++++++++++- dom/bluetooth/bluez/BluetoothOppManager.h | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/dom/bluetooth/bluez/BluetoothOppManager.cpp b/dom/bluetooth/bluez/BluetoothOppManager.cpp index b211c4603733..09b790875dc3 100644 --- a/dom/bluetooth/bluez/BluetoothOppManager.cpp +++ b/dom/bluetooth/bluez/BluetoothOppManager.cpp @@ -35,6 +35,8 @@ USING_BLUETOOTH_NAMESPACE using namespace mozilla; using namespace mozilla::ipc; +using mozilla::TimeDuration; +using mozilla::TimeStamp; namespace { // Sending system message "bluetooth-opp-update-progress" every 50kb @@ -53,6 +55,10 @@ static const uint32_t kPutRequestHeaderSize = 6; */ static const uint32_t kPutRequestAppendHeaderSize = 5; +// The default timeout we permit to wait for SDP updating if we can't get +// service channel. +static const double kSdpUpdatingTimeoutMs = 3000.0; + StaticRefPtr sBluetoothOppManager; static bool sInShutdown = false; } @@ -1546,9 +1552,17 @@ BluetoothOppManager::OnGetServiceChannel(const nsAString& aDeviceAddress, if (aChannel < 0) { if (mNeedsUpdatingSdpRecords) { mNeedsUpdatingSdpRecords = false; + mLastServiceChannelCheck = TimeStamp::Now(); bs->UpdateSdpRecords(aDeviceAddress, this); } else { - OnSocketConnectError(mSocket); + TimeDuration duration = TimeStamp::Now() - mLastServiceChannelCheck; + // Refresh SDP records until it gets valid service channel + // unless timeout is hit. + if (duration.ToMilliseconds() < kSdpUpdatingTimeoutMs) { + bs->UpdateSdpRecords(aDeviceAddress, this); + } else { + OnSocketConnectError(mSocket); + } } return; diff --git a/dom/bluetooth/bluez/BluetoothOppManager.h b/dom/bluetooth/bluez/BluetoothOppManager.h index 46c550646fc9..d7de3917883a 100644 --- a/dom/bluetooth/bluez/BluetoothOppManager.h +++ b/dom/bluetooth/bluez/BluetoothOppManager.h @@ -215,6 +215,10 @@ private: // is called. nsRefPtr mRfcommSocket; nsRefPtr mL2capSocket; + + // This holds the time when OPP manager fail to get service channel and + // prepare to refresh SDP records. + mozilla::TimeStamp mLastServiceChannelCheck; }; END_BLUETOOTH_NAMESPACE