Closed Bug 942712 Opened 12 years ago Closed 12 years ago

[bluetooth] first time searching devices won't work

Categories

(Firefox OS Graveyard :: Bluetooth, defect)

ARM
Gonk (Firefox OS)
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: wachen, Assigned: echou)

References

Details

Attachments

(2 files, 4 obsolete files)

device: nexus 4 master build steps: 1. flash the phone 2. launch settings app 3. go to bluetooth subsection 4. it started to search for devices expected result: there are some devices found actual result: no device found, you need to re-enable bluetooth to find devices.
Assignee: nobody → echou
I can reproduce. Patch is coming.
Let me explain the root cause briefly. When event adapterAdded is fired to Gaia, mozBluetooth.enabled is supposed to be true. If you trace related code in BluetoothService.cpp, you'll find out that mozBluetooth.enabled won't be set until event 'enabled'/'disabled' is fired. It seems to be reasonable so far, unfortunately another event 'adapteradded' may be fired before 'enabled' because the timing it comes up depends on our protocol stack. Apps will try to get mozBluetooth.enabled after it received adapteradded, however mozBluetooth.enabled may not be updated in time.
* Set gToggleInProgress to false when bt toggling is really done.
Attachment #8338315 - Flags: review?(gyeh)
Thanks for the quick fix!! :D
Comment on attachment 8338315 [details] [diff] [review] patch 1: v1: move gToggleInProgress to a more reasonable position Review of attachment 8338315 [details] [diff] [review]: ----------------------------------------------------------------- Seems reasonable.
Attachment #8338315 - Flags: review?(gyeh) → review+
* Patch modified after offline discussion with Gina. In this patch, I can guarantee that event AdapterAdded would be fired after event Enabled. Because SetEnabled() would be called before 'Enabled' is fired, the sequence of these 3 operations would become SetEnabled() -> 'Enabled' is fired -> 'AdapterAdded' is fired , and it is what we want.
Attachment #8338323 - Attachment is obsolete: true
Attachment #8338323 - Flags: review?(gyeh)
Attachment #8339131 - Flags: review?(gyeh)
* Patch updated since we need to ensure that low-level "AdapterAdded" event has been fired before notifying Gaia.
Attachment #8339131 - Attachment is obsolete: true
Attachment #8339131 - Flags: review?(gyeh)
Attachment #8339156 - Flags: review?(gyeh)
Comment on attachment 8339156 [details] [diff] [review] patch 2: v3: Ensure event 'AdapterAdded' will be fired after 'Enabled' being fired Review of attachment 8339156 [details] [diff] [review]: ----------------------------------------------------------------- Overall looks good, but still have some questions. Please correct me if I am wrong. Thanks. ::: dom/bluetooth/BluetoothService.cpp @@ +796,5 @@ > +BluetoothService::TryFiringAdapterAdded() > +{ > + MOZ_ASSERT(NS_IsMainThread()); > + > + if (IsToggling() || sIsAdapterAddedFired || !mAdapterIsReady) { Question: I was wondering if variable |sIsAdapterAddedFired| is needed? Am I missing something here? On the other hands, we might get multiple events of 'AdapterAdded' after enabling Bluetooth on BlueZ. If we check the value of |sIsAdpaterAddedFired| here, we will fire the event for the first time. Is it what we expected? @@ +805,5 @@ > + NS_LITERAL_STRING(KEY_MANAGER), true); > + DistributeSignal(signal); > + > + sIsAdapterAddedFired = true; > + mAdapterIsReady = false; Question: The name is a bit confusing to me. We reset |mAdapterIsReady| to its default value (false) here, however, the adapter is still ready to use. How about moving it to StopInternal? Does it make sense to you? ::: dom/bluetooth/BluetoothService.h @@ +321,5 @@ > + * Below 2 function/variable are used for ensuring event 'AdapterAdded' will > + * be fired after event 'Enabled'. > + */ > + void TryFiringAdapterAdded(); > + bool mAdapterIsReady; I'd like to make |mAdapterIsReady| as a private/protected member and create a setter function for accessing its value. ::: dom/bluetooth/bluedroid/gonk/BluetoothServiceBluedroid.cpp @@ +106,5 @@ > + } > + > + // Try to fire event 'AdapterAdded' to fit the original behaviour when > + // we used BlueZ as backend. > + BluetoothService* bs = BluetoothService::Get(); nit: Please make sure that |bs| is not a nullptr before using it. ::: dom/bluetooth/bluez/linux/BluetoothDBusService.cpp @@ +727,3 @@ > // Notify BluetoothManager whenever adapter name is ready. > if (!propertyValue.get_nsString().IsEmpty()) { > sAdapterNameIsReady = true; Question: Can we re-use/combine |sAdapterNameIsReady| and |mAdapterIsReady|?
> > ::: dom/bluetooth/BluetoothService.cpp > @@ +796,5 @@ > > +BluetoothService::TryFiringAdapterAdded() > > +{ > > + MOZ_ASSERT(NS_IsMainThread()); > > + > > + if (IsToggling() || sIsAdapterAddedFired || !mAdapterIsReady) { > > Question: I was wondering if variable |sIsAdapterAddedFired| is needed? Am I > missing something here? > sIsAdapterAddedFired is not necessary. My bad. > On the other hands, we might get multiple events of 'AdapterAdded' after > enabling Bluetooth on BlueZ. If we check the value of |sIsAdpaterAddedFired| > here, we will fire the event for the first time. Is it what we expected? > Good point. This problem won't exist since sIsAdapterAddedFired is gone. > @@ +805,5 @@ > > + NS_LITERAL_STRING(KEY_MANAGER), true); > > + DistributeSignal(signal); > > + > > + sIsAdapterAddedFired = true; > > + mAdapterIsReady = false; > > Question: The name is a bit confusing to me. We reset |mAdapterIsReady| to > its default value (false) here, however, the adapter is still ready to use. > How about moving it to StopInternal? Does it make sense to you? > I would like to keep the "setting mAdapterIsReady to false" happening in BluetoothService.cpp instead of in each derived class (BluetoothDBusService.cpp and BluetoothServiceBluedroid.cpp). I'll put it in function BluetoothService::StartStopBluetooth(). > ::: dom/bluetooth/BluetoothService.h > @@ +321,5 @@ > > + * Below 2 function/variable are used for ensuring event 'AdapterAdded' will > > + * be fired after event 'Enabled'. > > + */ > > + void TryFiringAdapterAdded(); > > + bool mAdapterIsReady; > > I'd like to make |mAdapterIsReady| as a private/protected member and create > a setter function for accessing its value. You caught me. > > ::: dom/bluetooth/bluedroid/gonk/BluetoothServiceBluedroid.cpp > @@ +106,5 @@ > > + } > > + > > + // Try to fire event 'AdapterAdded' to fit the original behaviour when > > + // we used BlueZ as backend. > > + BluetoothService* bs = BluetoothService::Get(); > > nit: Please make sure that |bs| is not a nullptr before using it. > > ::: dom/bluetooth/bluez/linux/BluetoothDBusService.cpp > @@ +727,3 @@ > > // Notify BluetoothManager whenever adapter name is ready. > > if (!propertyValue.get_nsString().IsEmpty()) { > > sAdapterNameIsReady = true; > > Question: Can we re-use/combine |sAdapterNameIsReady| and |mAdapterIsReady|? If we want to use mAdapterIsReady here, that means we have to write a getter of mAdapterIsReady, then we'll have both setter / getter of mAdapterIsReady (and then it would be no difference with using a public member variable). I'd prefer letting it stay as-is. Thanks for looking into the patch. This patch was awful and I shouldn't even send to review in a rush.
* Updated based on Gina's review comments.
Attachment #8339156 - Attachment is obsolete: true
Attachment #8339156 - Flags: review?(gyeh)
Attachment #8339789 - Flags: review?(gyeh)
Comment on attachment 8339789 [details] [diff] [review] patch 2: v4: Ensure event 'AdapterAdded' will be fired after 'Enabled' being fired Review of attachment 8339789 [details] [diff] [review]: ----------------------------------------------------------------- Thanks for your quick response. I think we're ready to land the patch. :) ::: dom/bluetooth/bluedroid/gonk/BluetoothServiceBluedroid.cpp @@ +106,5 @@ > + } > + > + // Try to fire event 'AdapterAdded' to fit the original behaviour when > + // we used BlueZ as backend. > + BluetoothService* bs = BluetoothService::Get(); NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
Attachment #8339789 - Flags: review?(gyeh) → review+
Blocks: 915533
See Also: → 940834
Sorry, my bad. Thank you, Carsten.
oops, I have to update the try server link again. https://tbpl.mozilla.org/?tree=Try&rev=0eeae75bf6ed
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: