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)
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 | ||
Updated•12 years ago
|
Assignee: nobody → echou
| Assignee | ||
Comment 1•12 years ago
|
||
I can reproduce. Patch is coming.
| Assignee | ||
Comment 2•12 years ago
|
||
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.
| Assignee | ||
Comment 3•12 years ago
|
||
* Set gToggleInProgress to false when bt toggling is really done.
Attachment #8338315 -
Flags: review?(gyeh)
| Assignee | ||
Comment 4•12 years ago
|
||
Attachment #8338323 -
Flags: review?(gyeh)
| Reporter | ||
Comment 5•12 years ago
|
||
Thanks for the quick fix!! :D
Comment 6•12 years ago
|
||
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+
| Assignee | ||
Comment 7•12 years ago
|
||
* 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)
| Assignee | ||
Comment 8•12 years ago
|
||
* 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 9•12 years ago
|
||
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|?
| Assignee | ||
Comment 10•12 years ago
|
||
>
> ::: 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.
| Assignee | ||
Comment 11•12 years ago
|
||
* Updated based on Gina's review comments.
Attachment #8339156 -
Attachment is obsolete: true
Attachment #8339156 -
Flags: review?(gyeh)
Attachment #8339789 -
Flags: review?(gyeh)
Comment 12•12 years ago
|
||
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+
| Assignee | ||
Comment 13•12 years ago
|
||
* nits picked.
Attachment #8339789 -
Attachment is obsolete: true
| Assignee | ||
Comment 14•12 years ago
|
||
Comment 15•12 years ago
|
||
hi Eric, i had to backout this 2 changesets in https://tbpl.mozilla.org/?tree=B2g-Inbound&rev=acb441feff28 since it was causing build bustages like https://tbpl.mozilla.org/php/getParsedLog.php?id=31213566&tree=B2g-Inbound and https://tbpl.mozilla.org/php/getParsedLog.php?id=31213625&tree=B2g-Inbound
| Assignee | ||
Comment 16•12 years ago
|
||
Sorry, my bad. Thank you, Carsten.
| Assignee | ||
Comment 17•12 years ago
|
||
| Assignee | ||
Comment 18•12 years ago
|
||
| Assignee | ||
Comment 19•12 years ago
|
||
oops, I have to update the try server link again.
https://tbpl.mozilla.org/?tree=Try&rev=0eeae75bf6ed
| Assignee | ||
Comment 20•12 years ago
|
||
| Assignee | ||
Comment 21•12 years ago
|
||
Comment 22•12 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/31306f1b7891
https://hg.mozilla.org/mozilla-central/rev/d27d0489b689
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•