Permalink
Browse files

Bug 827786 - We should not offer OTA updates to users when in 2G (GPR…

…S or EDGE). r=vingtetun
  • Loading branch information...
1 parent 51b3c17 commit 9f9ea501027848487587bbef5eda1c91f1ce642a @etiennesegonzac etiennesegonzac committed with vingtetun Jan 10, 2013
View
@@ -705,20 +705,26 @@ <h1 data-l10n-id="cancel-install">Cancel Install</h1>
</form>
<form id="updates-download-dialog" data-type="confirm" role="dialog"
- data-z-index-level="updates-download-dialog">
+ data-z-index-level="updates-download-dialog" data-nowifi="false" data-edge="false">
<section>
<h1>
Updates
</h1>
<ul>
</ul>
- <menu>
- <button id="updates-later-button" type="reset"
- data-l10n-id="later">Later</button>
- <button id="updates-download-button" type="submit"
- data-l10n-id="download">Download</button>
- </menu>
</section>
+ <p id="updates-no-wifi-warning"
+ data-l10n-id="downloadNoWifiWarning">
+ </p>
+ <p id="updates-edge-warning"
+ data-l10n-id="downloadEdgeWarning">
+ </p>
+ <menu>
+ <button id="updates-later-button" type="reset"
+ data-l10n-id="later">Later</button>
+ <button id="updates-download-button" type="submit"
+ data-l10n-id="download">Download</button>
+ </menu>
</form>
<div id="lockscreen-camera" data-z-index-level="lockscreen-camera"></div>
@@ -213,12 +213,9 @@ var StatusBar = {
this.update.data.call(this);
}
- var wifiManager = window.navigator.mozWifiManager;
- if (wifiManager) {
- wifiManager.onstatuschange =
- wifiManager.connectionInfoUpdate = (this.update.wifi).bind(this);
- this.update.wifi.call(this);
- }
+ window.addEventListener('wifi-statuschange',
+ this.update.wifi.bind(this));
+ this.update.wifi.call(this);
window.addEventListener('moznetworkupload', this);
window.addEventListener('moznetworkdownload', this);
@@ -19,6 +19,8 @@ var UpdateManager = {
_errorTimeout: null,
_wifiLock: null,
_systemUpdateDisplayed: false,
+ _conn: null,
+ _edgeTypes: ['edge', 'is95a', 'is95b', 'gprs'],
NOTIFICATION_BUFFERING_TIMEOUT: 30 * 1000,
TOASTER_TIMEOUT: 1200,
@@ -78,6 +80,17 @@ var UpdateManager = {
SettingsListener.observe('gaia.system.checkForUpdates', false,
this.checkForUpdates.bind(this));
+
+ // We maintain the the edge and nowifi data attributes to show
+ // a warning on the download dialog
+ window.addEventListener('wifi-statuschange', this);
+ this.updateWifiStatus();
+
+ this._conn = window.navigator.mozMobileConnection;
+ if (this._conn) {
+ this._conn.addEventListener('datachange', this);
+ this.updateEdgeStatus();
+ }
},
startDownloads: function um_startDownloads(evt) {
@@ -437,14 +450,19 @@ var UpdateManager = {
if (!evt.type)
return;
- if (evt.type === 'applicationinstall') {
- this.oninstall(evt.detail);
- return;
- }
-
- if (evt.type === 'applicationuninstall') {
- this.onuninstall(evt.detail);
- return;
+ switch (evt.type) {
+ case 'applicationinstall':
+ this.oninstall(evt.detail);
+ break;
+ case 'applicationuninstall':
+ this.onuninstall(evt.detail);
+ break;
+ case 'datachange':
+ this.updateEdgeStatus();
+ break;
+ case 'wifi-statuschange':
+ this.updateWifiStatus();
+ break;
}
if (evt.type !== 'mozChromeEvent')
@@ -458,6 +476,24 @@ var UpdateManager = {
}
},
+ updateEdgeStatus: function su_updateEdgeStatus() {
+ if (!this._conn)
+ return;
+
+ var data = this._conn.data;
+ this.downloadDialog.dataset.edge =
+ (this._edgeTypes.indexOf(data.type) !== -1);
+ },
+
+ updateWifiStatus: function su_updateWifiStatus() {
+ var wifiManager = window.navigator.mozWifiManager;
+ if (!wifiManager)
+ return;
+
+ this.downloadDialog.dataset.nowifi =
+ (wifiManager.connection.status != 'connected');
+ },
+
checkForUpdates: function su_checkForUpdates(shouldCheck) {
if (!shouldCheck) {
return;
View
@@ -64,6 +64,14 @@ var Wifi = {
window.dispatchEvent(evt);
};
+ // when wifi status change, emit event to notify StatusBar/UpdateManager
+ wifiManager.onstatuschange = function onWifiDisabled() {
+ var evt = document.createEvent('CustomEvent');
+ evt.initCustomEvent('wifi-statuschange',
+ /* canBubble */ true, /* cancelable */ false, null);
+ window.dispatchEvent(evt);
+ };
+
// Track the wifi.enabled mozSettings value
SettingsListener.observe('wifi.enabled', true, function(value) {
if (!wifiManager && value) {
@@ -113,6 +113,8 @@ numberOfUpdates[other]={{ n }} updates available
systemUpdate=System update
required=Required
uncompressingMessage=Uncompressing… <span>This can take a few minutes.</span>
+downloadNoWifiWarning=Wi-Fi unavailable. Updating over current connection may incur additional charges.
+downloadEdgeWarning=Wi-Fi unavailable. Updating over current connection will block incoming calls, and may incur additional charges.
# screenshots
screenshotSaved = Screenshot saved to Gallery
@@ -201,3 +201,35 @@ html, body {
height: 3rem;
line-height: 2.9rem;
}
+
+#updates-download-dialog p {
+ display: none;
+ position: absolute;
+ left: 0;
+ right: 0;
+ bottom: 6.8rem;
+ height: 6.6rem;
+ padding: 0.5rem 1.8rem;
+ margin: 0;
+
+ background-color: rgba(0, 0, 0, 0.4);
+ border-top: solid 1px rgba(255, 255, 255, 0.2);
+ overflow-y: scroll;
+
+ font-size: 1.6rem;
+ white-space: normal;
+}
+
+#updates-download-dialog[data-nowifi="true"] section {
+ /* Fixing at the top of the screen to properly make room for the warning */
+ position: absolute;
+ top: 20px;
+ max-height: calc(100% - 15rem - 20px);
+}
+#updates-download-dialog[data-nowifi="true"] #updates-no-wifi-warning,
+#updates-download-dialog[data-nowifi="true"][data-edge="true"] #updates-edge-warning {
+ display: block;
+}
+#updates-download-dialog[data-nowifi="true"][data-edge="true"] #updates-no-wifi-warning {
+ display: none;
+}
@@ -2,7 +2,7 @@
(function() {
- var props = ['voice', 'cardState', 'iccInfo'];
+ var props = ['voice', 'cardState', 'iccInfo', 'data'];
function mnmmc_init() {
props.forEach(function(prop) {
@@ -14,6 +14,7 @@ requireApp('system/test/unit/mock_statusbar.js');
requireApp('system/test/unit/mock_notification_screen.js');
requireApp('system/test/unit/mock_navigator_settings.js');
requireApp('system/test/unit/mock_navigator_wake_lock.js');
+requireApp('system/test/unit/mock_navigator_moz_mobile_connection.js');
requireApp('system/test/unit/mock_l10n.js');
requireApp('system/test/unit/mocks_helper.js');
@@ -37,6 +38,7 @@ mocksForUpdateManager.forEach(function(mockName) {
suite('system/UpdateManager', function() {
var realL10n;
+ var realWifiManager;
var realRequestWakeLock;
var realNavigatorSettings;
var realDispatchEvent;
@@ -61,6 +63,13 @@ suite('system/UpdateManager', function() {
realL10n = navigator.mozL10n;
navigator.mozL10n = MockL10n;
+ realWifiManager = navigator.mozWifiManager;
+ navigator.mozWifiManager = {
+ connection: {
+ status: 'connected'
+ }
+ };
+
realRequestWakeLock = navigator.requestWakeLock;
navigator.requestWakeLock = MockNavigatorWakeLock.requestWakeLock;
@@ -84,6 +93,7 @@ suite('system/UpdateManager', function() {
realNavigatorSettings = null;
navigator.mozL10n = realL10n;
+ navigator.mozWifiManager = realWifiManager;
navigator.requestWakeLock = realRequestWakeLock;
realRequestWakeLock = null;
@@ -700,6 +710,59 @@ suite('system/UpdateManager', function() {
evt.initEvent('click', true, true);
});
+ suite('data connection warning', function() {
+ var downloadDialog;
+ setup(function() {
+ downloadDialog = UpdateManager.downloadDialog;
+ });
+
+ test('should swith the nowifi data attribute when connected',
+ function() {
+ downloadDialog.dataset.nowifi = true;
+ window.dispatchEvent(new CustomEvent('wifi-statuschange'));
+ assert.equal(downloadDialog.dataset.nowifi, 'false');
+ });
+
+ test('should swith the nowifi data attribute when disconnected',
+ function() {
+ downloadDialog.dataset.nowifi = false;
+ navigator.mozWifiManager.connection.status = 'disconnected';
+ window.dispatchEvent(new CustomEvent('wifi-statuschange'));
+ assert.equal(downloadDialog.dataset.nowifi, 'true');
+ });
+
+ suite('edge detection', function() {
+ setup(function() {
+ UpdateManager._conn = MockNavigatorMozMobileConnection;
+ });
+
+ teardown(function() {
+ MockNavigatorMozMobileConnection.mTeardown();
+ });
+
+ test('should swith the edge data attribute when type is not edge',
+ function() {
+ downloadDialog.dataset.edge = true;
+ MockNavigatorMozMobileConnection.data = {
+ type: 'lte'
+ };
+ UpdateManager.updateEdgeStatus();
+ assert.equal(downloadDialog.dataset.edge, 'false');
+ });
+
+ test('should swith the edge data attribute when type is edge',
+ function() {
+ downloadDialog.dataset.edge = false;
+ MockNavigatorMozMobileConnection.data = {
+ type: 'gprs'
+ };
+ UpdateManager.updateEdgeStatus();
+ assert.equal(downloadDialog.dataset.edge, 'true');
+ });
+
+ });
+ });
+
test('should enable the download button', function() {
var downloadButton = UpdateManager.downloadButton;
assert.isFalse(downloadButton.disabled);

0 comments on commit 9f9ea50

Please sign in to comment.