|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components; |
|
5 const { Services } = Cu.import('resource://gre/modules/Services.jsm'); |
|
6 |
|
7 var browser = Services.wm.getMostRecentWindow('navigator:browser'); |
|
8 var connection = browser.navigator.mozMobileConnections[0]; |
|
9 |
|
10 // provide a fake APN and enable data connection. |
|
11 function enableDataConnection() { |
|
12 let setLock = browser.navigator.mozSettings.createLock(); |
|
13 setLock.set({ |
|
14 'ril.data.enabled': true, |
|
15 'ril.data.apnSettings': [ |
|
16 [ |
|
17 {'carrier':'T-Mobile US', |
|
18 'apn':'epc.tmobile.com', |
|
19 'mmsc':'http://mms.msg.eng.t-mobile.com/mms/wapenc', |
|
20 'types':['default','supl','mms']} |
|
21 ] |
|
22 ] |
|
23 }); |
|
24 } |
|
25 |
|
26 // enable 3G radio |
|
27 function enableRadio() { |
|
28 if (connection.radioState !== 'enabled') { |
|
29 connection.setRadioEnabled(true); |
|
30 } |
|
31 } |
|
32 |
|
33 // disable 3G radio |
|
34 function disableRadio() { |
|
35 if (connection.radioState === 'enabled') { |
|
36 connection.setRadioEnabled(false); |
|
37 } |
|
38 } |
|
39 |
|
40 addMessageListener('prepare-network', function(message) { |
|
41 //RIL DOM events will be pending until RIL receiveing system-message-listener-ready event. |
|
42 Services.obs.notifyObservers(null, 'system-message-listener-ready', null); |
|
43 |
|
44 connection.addEventListener('datachange', function onDataChange() { |
|
45 if (connection.data.connected) { |
|
46 connection.removeEventListener('datachange', onDataChange); |
|
47 Services.prefs.setIntPref('network.proxy.type', 2); |
|
48 sendAsyncMessage('network-ready', true); |
|
49 } |
|
50 }); |
|
51 |
|
52 enableRadio(); |
|
53 enableDataConnection(); |
|
54 }); |
|
55 |
|
56 addMessageListener('network-cleanup', function(message) { |
|
57 connection.addEventListener('datachange', function onDataChange() { |
|
58 if (!connection.data.connected) { |
|
59 connection.removeEventListener('datachange', onDataChange); |
|
60 Services.prefs.setIntPref('network.proxy.type', 2); |
|
61 sendAsyncMessage('network-disabled', true); |
|
62 } |
|
63 }); |
|
64 disableRadio(); |
|
65 }); |