mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1003663 - Handle the case that user turn off BT during the middle of BT reply. r=echou, f=shuang
- End the session if BT is turn off during the middle of BT profile connection. - Clear static queues(array) when BT is on.
This commit is contained in:
parent
c2d2051c84
commit
2742e6b9b5
@ -5,11 +5,12 @@
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "BluetoothProfileController.h"
|
||||
#include "BluetoothReplyRunnable.h"
|
||||
|
||||
#include "BluetoothA2dpManager.h"
|
||||
#include "BluetoothHfpManager.h"
|
||||
#include "BluetoothHidManager.h"
|
||||
#include "BluetoothReplyRunnable.h"
|
||||
#include "BluetoothService.h"
|
||||
#include "BluetoothUtils.h"
|
||||
|
||||
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
|
||||
@ -217,6 +218,11 @@ BluetoothProfileController::StartSession()
|
||||
MOZ_ASSERT(mProfilesIndex == -1);
|
||||
MOZ_ASSERT(mTimer);
|
||||
|
||||
if (!IsBtServiceAvailable()) {
|
||||
EndSession();
|
||||
return;
|
||||
}
|
||||
|
||||
if (mProfiles.Length() < 1) {
|
||||
BT_LOGR("No queued profile.");
|
||||
EndSession();
|
||||
@ -240,6 +246,12 @@ BluetoothProfileController::EndSession()
|
||||
|
||||
BT_LOGR("mSuccess %d", mSuccess);
|
||||
|
||||
// Don't have to check profile status and retrigger session after connection
|
||||
// timeout, since session is end.
|
||||
if (mTimer) {
|
||||
mTimer->Cancel();
|
||||
}
|
||||
|
||||
// The action has completed, so the DOM request should be replied then invoke
|
||||
// the callback.
|
||||
if (mSuccess) {
|
||||
@ -265,6 +277,11 @@ BluetoothProfileController::Next()
|
||||
|
||||
mCurrentProfileFinished = false;
|
||||
|
||||
if (!IsBtServiceAvailable()) {
|
||||
EndSession();
|
||||
return;
|
||||
}
|
||||
|
||||
if (++mProfilesIndex >= (int)mProfiles.Length()) {
|
||||
EndSession();
|
||||
return;
|
||||
@ -279,6 +296,13 @@ BluetoothProfileController::Next()
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothProfileController::IsBtServiceAvailable() const
|
||||
{
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
return (bs && bs->IsEnabled() && !bs->IsToggling());
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothProfileController::NotifyCompletion(const nsAString& aErrorStr)
|
||||
{
|
||||
@ -308,6 +332,11 @@ BluetoothProfileController::GiveupAndContinue()
|
||||
|
||||
BT_LOGR_PROFILE(mProfiles[mProfilesIndex], ERR_OPERATION_TIMEOUT);
|
||||
mProfiles[mProfilesIndex]->Reset();
|
||||
Next();
|
||||
|
||||
if (IsBtServiceAvailable()) {
|
||||
Next();
|
||||
} else {
|
||||
EndSession();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,6 +122,9 @@ private:
|
||||
// Connect/Disconnect next profile in the array
|
||||
void Next();
|
||||
|
||||
// Is Bluetooth service available for profile connection/disconnection ?
|
||||
bool IsBtServiceAvailable() const;
|
||||
|
||||
const bool mConnect;
|
||||
nsString mDeviceAddress;
|
||||
nsRefPtr<BluetoothReplyRunnable> mRunnable;
|
||||
|
@ -95,6 +95,14 @@ public:
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// Bluetooth just enabled, clear profile controllers and runnable arrays.
|
||||
sControllerArray.Clear();
|
||||
sBondingRunnableArray.Clear();
|
||||
sChangeDiscoveryRunnableArray.Clear();
|
||||
sGetDeviceRunnableArray.Clear();
|
||||
sSetPropertyRunnableArray.Clear();
|
||||
sUnbondingRunnableArray.Clear();
|
||||
|
||||
// Bluetooth scan mode is NONE by default
|
||||
bt_scan_mode_t mode = BT_SCAN_MODE_CONNECTABLE;
|
||||
bt_property_t prop;
|
||||
@ -1149,8 +1157,9 @@ NextBluetoothProfileController()
|
||||
NS_ENSURE_FALSE_VOID(sControllerArray.IsEmpty());
|
||||
sControllerArray.RemoveElementAt(0);
|
||||
// Re-check if the task array is empty, if it's not, the next task will begin.
|
||||
NS_ENSURE_FALSE_VOID(sControllerArray.IsEmpty());
|
||||
sControllerArray[0]->StartSession();
|
||||
if (!sControllerArray.IsEmpty()) {
|
||||
sControllerArray[0]->StartSession();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user