Last Comment Bug 777145 - B2G Network Manager: support navigator.onLine / online / offline events
: B2G Network Manager: support navigator.onLine / online / offline events
Status: RESOLVED FIXED
[WebAPI:P0][LOE:S]
: feature
Product: Core
Classification: Components
Component: DOM: Device Interfaces (show other bugs)
: unspecified
: All Gonk (Firefox OS)
: -- normal (vote)
: mozilla18
Assigned To: Hubert Figuiere [:hub]
:
Mentors:
: 786764 (view as bug list)
Depends on: 787277 778360 787298 787435 826297
Blocks: 773892 777187 789466 793213
  Show dependency treegraph
 
Reported: 2012-07-24 16:08 PDT by Philipp von Weitershausen [:philikon]
Modified: 2013-01-04 14:16 PST (History)
19 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---
+
fixed


Attachments
Bug 777145 - Set offline flag depending on the actual state of the network. (658 bytes, patch)
2012-07-27 16:47 PDT, Hubert Figuiere [:hub]
philipp: review+
hub: checkin+
Details | Diff | Review
Bug 777145 - Part 2: Make sure we are online when runing marionette. (813 bytes, patch)
2012-09-19 15:53 PDT, Hubert Figuiere [:hub]
jgriffin: review+
hub: checkin+
Details | Diff | Review

Description Philipp von Weitershausen [:philikon] 2012-07-24 16:08:22 PDT
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.
Comment 1 Hubert Figuiere [:hub] 2012-07-24 17:04:35 PDT
ok, this one seems to really be blocking me for bug 773892. I'll take a crack at it.
Comment 2 Philipp von Weitershausen [:philikon] 2012-07-24 17:41:28 PDT
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
Comment 3 Hubert Figuiere [:hub] 2012-07-25 17:34:31 PDT
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)
Comment 4 Hubert Figuiere [:hub] 2012-07-25 17:54:21 PDT
Correction, I get that when I reboot the phone completely. Not when I restart b2g.
Comment 5 Philipp von Weitershausen [:philikon] 2012-07-25 20:06:51 PDT
(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?
Comment 6 Hubert Figuiere [:hub] 2012-07-26 12:07:13 PDT
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
Comment 7 Hubert Figuiere [:hub] 2012-07-26 15:25:45 PDT
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.
Comment 8 Hubert Figuiere [:hub] 2012-07-26 15:29:52 PDT
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.
Comment 9 Hubert Figuiere [:hub] 2012-07-27 16:47:02 PDT
Created attachment 646758 [details] [diff] [review]
Bug 777145 - Set offline flag depending on the actual state of the network.
Comment 10 Hubert Figuiere [:hub] 2012-07-27 16:52:49 PDT
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 11 Philipp von Weitershausen [:philikon] 2012-07-28 12:08:38 PDT
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!
Comment 12 Hubert Figuiere [:hub] 2012-07-29 08:04:55 PDT
I'll check it in when bug 778360 is fixed. if I don't a restart of b2g will cause it to be offline.
Comment 13 Philipp von Weitershausen [:philikon] 2012-08-29 12:27:50 PDT
Nom'ing because a dupe (bug 786764) was nom'ed.
Comment 14 Philipp von Weitershausen [:philikon] 2012-08-29 12:27:54 PDT
*** Bug 786764 has been marked as a duplicate of this bug. ***
Comment 15 Philipp von Weitershausen [:philikon] 2012-08-29 12:33:41 PDT
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.
Comment 16 Hubert Figuiere [:hub] 2012-08-29 12:44:35 PDT
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.
Comment 17 Philipp von Weitershausen [:philikon] 2012-08-29 13:42:30 PDT
(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.
Comment 18 Hubert Figuiere [:hub] 2012-08-29 13:44:29 PDT
so can I get an Otoro device now?
Comment 19 Hubert Figuiere [:hub] 2012-08-29 17:32:37 PDT
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.
Comment 20 Ed Morley [:emorley] 2012-08-30 03:54:47 PDT
https://hg.mozilla.org/mozilla-central/rev/982d02faef3f
Comment 21 Andrew Overholt [:overholt] 2012-08-30 06:45:36 PDT
Seems like a blocker and even though it's fixed we don't want it to regress.
Comment 22 Philipp von Weitershausen [:philikon] 2012-08-31 09:18:00 PDT
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.
Comment 23 David Bolter [:davidb] 2012-09-05 12:19:22 PDT
Philipp is someone active on the fix? Is the fix happening on this bug?
Comment 24 Philipp von Weitershausen [:philikon] 2012-09-05 12:26:24 PDT
(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.
Comment 25 Hubert Figuiere [:hub] 2012-09-05 12:28:37 PDT
The thing is I have no clue about Marionette nor how it works.
Comment 26 Philipp von Weitershausen [:philikon] 2012-09-05 12:31:41 PDT
(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.
Comment 27 David Bolter [:davidb] 2012-09-05 12:32:51 PDT
Adding Malini for Marionette expertise.
Comment 28 Jonathan Griffin (:jgriffin) 2012-09-05 12:52:07 PDT
@hub, if you have any problems running Marionette, ping myself (jgriffin) or mdas on #b2g and we can help.
Comment 29 Dave Hylands [:dhylands] 2012-09-12 19:45:14 PDT
@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
Comment 30 Philipp von Weitershausen [:philikon] 2012-09-18 10:54:24 PDT
(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?
Comment 31 Hubert Figuiere [:hub] 2012-09-18 11:02:32 PDT
(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.
Comment 32 Hubert Figuiere [:hub] 2012-09-19 15:53:17 PDT
Created attachment 662727 [details] [diff] [review]
Bug 777145 - Part 2: Make sure we are online when runing marionette.

This patch to fix marionette. Needs the previous one to be relevant.
Comment 33 Jonathan Griffin (:jgriffin) 2012-09-19 19:23:05 PDT
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.
Comment 36 Jonas Sicking (:sicking) 2012-10-03 16:19:04 PDT
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?
Comment 37 David Bolter [:davidb] 2012-10-05 10:48:30 PDT
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.
Comment 38 Ran Ben Aharon [:ranbena] EverythingMe 2012-10-22 07:38:38 PDT
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?
Comment 39 Vivien Nicolas (:vingtetun) (:21) - (NOT reading bugmails, needinfo? please) 2012-10-22 08:38:34 PDT
(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? ?
Comment 40 Jose Manuel Cantera 2013-01-03 02:15:14 PST
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}]
Comment 41 Philipp von Weitershausen [:philikon] 2013-01-03 08:12:06 PST
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!

Note You need to log in before you can comment on or make changes to this bug.