Closed Bug 777145 Opened 12 years ago Closed 12 years ago

B2G Network Manager: support navigator.onLine / online / offline events

Categories

(Core :: DOM: Device Interfaces, defect)

All
Gonk (Firefox OS)
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla18
blocking-basecamp +
Tracking Status
b2g18 --- fixed

People

(Reporter: philikon, Assigned: hub)

References

Details

(Keywords: feature, Whiteboard: [WebAPI:P0][LOE:S])

Attachments

(2 files)

This is useful if web apps want to be notified when the network comes back online. Also useful for Gecko (e.g. for submitting crash reports or metric or whatever). I think this is as simple as updating nsIIOService::offline.
Blocks: 773892
ok, this one seems to really be blocking me for bug 773892. I'll take a crack at it.
Assignee: nobody → hub
Cool, thanks! Basically, you want to hook into the end of NetworkManager::setAndConfigureActive [1], ideally when we successfully activate interfaces and set routes.

[1] https://mxr.mozilla.org/mozilla-central/source/dom/system/gonk/NetworkManager.js#179
when I set Service.io.offline, I currently get the following error on the console:

E/GeckoConsole( 3442): [JavaScript Error: "[Exception... "'JavaScript component does not have a method named: "onStopListening"' when calling method: [nsIServerSocketListener::onStopListening]"  nsresult: "0x80570030 (NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED)"  location: "<unknown>"  data: no]"]

Also it seems that I get, at https://mxr.mozilla.org/mozilla-central/source/dom/system/gonk/NetworkManager.js#179 this.active to be null as the state of wlan seems to always be disconnected, and when I try to force reconnection from the settings I don't get the event.

(I'm running on a SGS2)
Correction, I get that when I reboot the phone completely. Not when I restart b2g.
(In reply to Hub Figuiere [:hub] from comment #3)
> when I set Service.io.offline, I currently get the following error on the
> console:
> 
> E/GeckoConsole( 3442): [JavaScript Error: "[Exception... "'JavaScript
> component does not have a method named: "onStopListening"' when calling
> method: [nsIServerSocketListener::onStopListening]"  nsresult: "0x80570030
> (NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED)"  location: "<unknown>"  data:
> no]"]

That just means some nsIServerSocketListener implementation (in JS) out there hasn't implemented the full interface or has been cycle-collected. I suspect it's https://mxr.mozilla.org/mozilla-central/source/toolkit/devtools/debugger/server/dbg-server.js#194, even though that does implement an empty onStopListening().

> Also it seems that I get, at
> https://mxr.mozilla.org/mozilla-central/source/dom/system/gonk/
> NetworkManager.js#179 this.active to be null as the state of wlan seems to
> always be disconnected, and when I try to force reconnection from the
> settings I don't get the event.

That's definitely weird. I can take a look at that later/tomorrow. Have you enabled DEBUG = true in NetworkManager.js and looked at logcat at all?
I didn't have DEBUG, but I added some logging.

It shows that when it iterate through the network interfaces it finds one, wlan, and its state isn't "CONNECTED". ~line 175
If I restart b2g, here is what Networkmanager does:

I/Gecko   ( 3104): -*- NetworkManager: Starting worker.
I/Gecko   ( 3104): -*- NetworkManager: Evaluating whether active network needs to be changed.
I/Gecko   ( 3104): -*- NetworkManager: Network 'wlan0' registered.
I/Gecko   ( 3104): -*- NetworkManager: Network 'wlan0' changed state to 4
I/Gecko   ( 3104): -*- NetworkManager: Evaluating whether active network needs to be changed.
I/Gecko   ( 3104): -*- NetworkManager: Network 'wlan0' changed state to 4
I/Gecko   ( 3104): -*- NetworkManager: Evaluating whether active network needs to be changed.
I/Gecko   ( 3104): -*- NetworkManager: Network 'wlan0' changed state to 4
I/Gecko   ( 3104): -*- NetworkManager: Evaluating whether active network needs to be changed.
I/Gecko   ( 3104): -*- NetworkManager: Network 'wlan0' changed state to 4
I/Gecko   ( 3104): -*- NetworkManager: Evaluating whether active network needs to be changed.
I/Gecko   ( 3104): -*- NetworkManager: Network 'wlan0' changed state to 4
I/Gecko   ( 3104): -*- NetworkManager: Evaluating whether active network needs to be changed.
Just so that it is clear: by restart b2g I mean the b2g process (gecko) not the phone.

A reboot of the phone is a totally different story and seems to work as advertised.
Attachment #646758 - Flags: review?(philipp)
Depends on: 778360
This patch need bug 778360 to be properly fixed to work. Ie on restart of b2g, it will remain offline until wifi is restarted manually. (don't have cellular data ATM)
Comment on attachment 646758 [details] [diff] [review]
Bug 777145 - Set offline flag depending on the actual state of the network.

Review of attachment 646758 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/system/gonk/NetworkManager.js
@@ +178,4 @@
>      if (this.active) {
>        this.setDefaultRouteAndDNS(oldActive);
>      }
> +    Services.io.offline = !this.active;

Elegant!
Attachment #646758 - Flags: review?(philipp) → review+
I'll check it in when bug 778360 is fixed. if I don't a restart of b2g will cause it to be offline.
Nom'ing because a dupe (bug 786764) was nom'ed.
blocking-basecamp: --- → ?
Folks were running into this issue here at the work week. Since we had an r+'ed patch that works most of the time, I went ahead and landed this:

https://hg.mozilla.org/integration/mozilla-inbound/rev/982d02faef3f

No reason to wait for bug 778360.
oh yes BIG REASON.

Each time one restart b2g, one has to restart wifi by doing setings > wifi > off then on.

This is time that could be better use to do real stuff. That's the whole reason I marked this as being blocked by another bug and the whole reason I held up landing.

This is actually MY DISCLAIMER of responsibility, I didn't approve this landing. I DIDN'T BREAK THE SYSTEM.
(In reply to Hub Figuiere [:hub] from comment #16)
> Each time one restart b2g, one has to restart wifi by doing setings > wifi >
> off then on.

I cannot reproduce this on the Otoro. So I think we're ok.
so can I get an Otoro device now?
So it seems that the problem was specific SGS2 (the only device I have). Blake has a final solution for bug 778360 that will land soon. We should be all set in the end.
blocking-basecamp: ? → ---
https://hg.mozilla.org/mozilla-central/rev/982d02faef3f
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla18
Seems like a blocker and even though it's fixed we don't want it to regress.
blocking-basecamp: --- → +
Depends on: 787277
Depends on: 787435
Backed out in https://hg.mozilla.org/mozilla-central/rev/e56edfeb2bb4 due to B2G marionette breakage (see bug 787298). Will reland once we have a fix.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Depends on: 787298
Philipp is someone active on the fix? Is the fix happening on this bug?
(In reply to David Bolter [:davidb] from comment #23)
> Philipp is someone active on the fix?

I was for a bit, but I couldn't get it working. Pinging Hub about possibly taking over the fix was on my list... So thanks for the reminder. ;)

Hub, could you look at this?

> Is the fix happening on this bug?

Yes, it would have to. Breaking Marionette is like breaking any other test suite in the tree, so fixes need to land at the same time.
The thing is I have no clue about Marionette nor how it works.
(In reply to Hub Figuiere [:hub] from comment #25)
> The thing is I have no clue about Marionette nor how it works.

https://developer.mozilla.org/en-US/docs/Marionette has an overview. To run the Marionette test suite against B2G, configure your B2G for the emulator, build, and then run ./test.sh.
Adding Malini for Marionette expertise.
@hub, if you have any problems running Marionette, ping myself (jgriffin) or mdas on #b2g and we can help.
Whiteboard: [WebAPI:P0]
Keywords: feature
@hub: You could try to look in the /proc/cpuinfo file and scan for Hardware: For the emulator, this appears to be set to Goldfish (for ARM). For x86 based emulator, The model name field looks like a Pentium II.

if MOZ_WIDGET_GONK is defined then you should be able to use the above to tell if you're in an emulator.

You may also be able to try and retrieve the IMEI number, I've read that the emulator returns 0 for this, but philikon can probably confirm
Whiteboard: [WebAPI:P0] → [WebAPI:P0][LOE:S]
Blocks: 789466
Blocks: 777187
(In reply to Dave Hylands [:dhylands] from comment #29)
> @hub: You could try to look in the /proc/cpuinfo file and scan for Hardware:
> For the emulator, this appears to be set to Goldfish (for ARM). For x86
> based emulator, The model name field looks like a Pentium II.
> 
> if MOZ_WIDGET_GONK is defined then you should be able to use the above to
> tell if you're in an emulator.

I'm not sure what this is useful for. I don't think we want to special-case the emulator in Gecko, but rather make the test harness work with Gecko's behaviour. At least that would be my preference. Otherwise how are we going to write a test for it?


Hub, how are we doing here? This is a P0 basecamp blocker. Can we finish it up this week?
(In reply to Philipp von Weitershausen [:philikon] from comment #30)
> (In reply to Dave Hylands [:dhylands] from comment #29)
> > @hub: You could try to look in the /proc/cpuinfo file and scan for Hardware:
> > For the emulator, this appears to be set to Goldfish (for ARM). For x86
> > based emulator, The model name field looks like a Pentium II.
> > 
> > if MOZ_WIDGET_GONK is defined then you should be able to use the above to
> > tell if you're in an emulator.
> 
> I'm not sure what this is useful for. I don't think we want to special-case
> the emulator in Gecko, but rather make the test harness work with Gecko's
> behaviour. At least that would be my preference. Otherwise how are we going
> to write a test for it?

I was actually trying to special case it for the emulator, at least for now. I don't see how we can fix the emulator case without changing the actual emulator.

> Hub, how are we doing here? This is a P0 basecamp blocker. Can we finish it
> up this week?

That's my plan.
This patch to fix marionette. Needs the previous one to be relevant.
Attachment #662727 - Flags: review?(jgriffin)
Comment on attachment 662727 [details] [diff] [review]
Bug 777145 - Part 2: Make sure we are online when runing marionette.

Review of attachment 662727 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks!  I verified this works in both B2G and desktop Firefox.
Attachment #662727 - Flags: review?(jgriffin) → review+
Attachment #646758 - Flags: checkin+
Attachment #662727 - Flags: checkin+
Status: REOPENED → ASSIGNED
https://hg.mozilla.org/mozilla-central/rev/2e21fddbc007
https://hg.mozilla.org/mozilla-central/rev/2c8cb9b79705
Status: ASSIGNED → RESOLVED
Closed: 12 years ago12 years ago
Resolution: --- → FIXED
In light of bug 654579, I just wanted to verify that we set navigator.onLine to false and fire an "offline" event if the user doesn't currently have data connection through wifi or 2g/3g?
Noting here since people cc'ed are likely interested: I filed bug 798451 to see if we might want a non-wifi crash submission option.
Ryan, Jonas, I've noticed that after the device boots and is offline by default, navigator.onLine returns true instead of false. Only after connecting and disconnecting does the property return false as expected.

Can you take a look  at this?
(In reply to Ran Ben Aharon (everything.me) from comment #38)
> Ryan, Jonas, I've noticed that after the device boots and is offline by
> default, navigator.onLine returns true instead of false. Only after
> connecting and disconnecting does the property return false as expected.
> 
> Can you take a look  at this?

Hey Ran, do you mind filing a new bug and ask for blocking-basecamp? ?
It has stopped working. STR:

Gecko-257e1c1.Gaia Master

Go to Gaia and turn on / off airplane mode. The online / offline events are not raised over the window object. And the following JS error appears on the console

E/GeckoConsole(  717): [JavaScript Error: "NS_ERROR_NOT_AVAILABLE: Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIPrefBranch.setIntPref]" {file: "jar:file:///system/b2g/omni.ja!/components/RILContentHelper.js" line: 878}]
E/GeckoConsole(  768): [JavaScript Error: "NS_ERROR_NOT_AVAILABLE: Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIPrefBranch.setIntPref]" {file: "jar:file:///system/b2g/omni.ja!/components/RILContentHelper.js" line: 878}]
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Thanks for the bug report, Jose. But please don't reopen really old bugs. Please always file new ones blocking the bug that's regressing. Thanks!
Status: REOPENED → RESOLVED
Closed: 12 years ago12 years ago
Resolution: --- → FIXED
Depends on: 826297
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: