diff --git a/apps/fm/index.html b/apps/fm/index.html index 1e0001de14ce..ef3e632009ea 100644 --- a/apps/fm/index.html +++ b/apps/fm/index.html @@ -8,6 +8,7 @@ + diff --git a/apps/fm/js/fm.js b/apps/fm/js/fm.js index 5f62f9b81a9c..e6f128763f51 100644 --- a/apps/fm/js/fm.js +++ b/apps/fm/js/fm.js @@ -130,29 +130,6 @@ var mozFMRadio = navigator.mozFM || navigator.mozFMRadio || { } }; -// XXX fake mozSetting object for UI testing on PC -var mozSettings = navigator.mozSettings || { - addObserver: function settings_addObserver(key, callback) {}, - createLock: function settings_createLock() { - return { - get: function() { - var request = { - result: {} - }; - - window.setTimeout(function() { - if (request.onsuccess) { - request.result['ril.radio.disabled'] = false; - request.onsuccess(); - } - }, 500); - - return request; - } - }; - } -}; - // XXX fake SpeakerManager object for UI testing on PC (function(aGlobal) { aGlobal.SpeakerManager = aGlobal.SpeakerManager || aGlobal.MozSpeakerManager; @@ -203,7 +180,7 @@ function updateAntennaUI() { } function updateAirplaneModeUI() { - $('airplane-mode-warning').hidden = !rilDisabled; + $('airplane-mode-warning').hidden = !airplaneModeEnabled; } var enabling = false; @@ -222,9 +199,9 @@ function updateEnablingState(enablingState) { updateFrequencyBarUI(); } -var rilDisabled = false; +var airplaneModeEnabled = false; function enableFMRadio(frequency) { - if (rilDisabled) + if (airplaneModeEnabled) return; var request = mozFMRadio.enable(frequency); @@ -822,8 +799,9 @@ function init() { // Disable the power button and the fav list when the airplane mode is on. updateAirplaneModeUI(); - mozSettings.addObserver('ril.radio.disabled', function(event) { - rilDisabled = event.settingValue; + + AirplaneModeHelper.addEventListener('statechange', function(status) { + airplaneModeEnabled = status === 'enabled'; updateAirplaneModeUI(); }); @@ -849,14 +827,10 @@ function init() { } window.addEventListener('load', function(e) { - var req = mozSettings.createLock().get('ril.radio.disabled'); - req.onsuccess = function() { - rilDisabled = req.result['ril.radio.disabled']; + AirplaneModeHelper.ready(function() { + airplaneModeEnabled = AirplaneModeHelper.getStatus() == 'enabled'; init(); - }; - req.onerror = function() { - init(); - }; + }); }, false); // Turn off radio immediately when window is unloaded. diff --git a/apps/fm/test/unit/fm_test.js b/apps/fm/test/unit/fm_test.js index bac72039aef6..3e2a76330465 100644 --- a/apps/fm/test/unit/fm_test.js +++ b/apps/fm/test/unit/fm_test.js @@ -1,20 +1,10 @@ +requireApp('shared/js/airplane_mode_helper.js'); requireApp('fm/js/fm.js'); var PerformanceTestingHelper = { dispatch: function() { } }; -// fake mozSettings at the global level because fm.js uses it before any `setup` -// function is called. -navigator.mozSettings = { - addObserver: function() {}, - createLock: function() { - return { - get: function() {} - }; - } -}; - suite('FM', function() { var tempNode; @@ -229,7 +219,7 @@ suite('FM', function() { suite('airplane mode on', function() { setup(function() { - rilDisabled = true; + airplaneModeEnabled = true; updateAirplaneModeUI(); }); @@ -240,7 +230,7 @@ suite('FM', function() { suite('airplane mode off', function() { setup(function() { - rilDisabled = false; + airplaneModeEnabled = false; updateAirplaneModeUI(); }); diff --git a/apps/system/js/airplane_mode.js b/apps/system/js/airplane_mode.js index 881221b344bb..2e8e368ecd74 100644 --- a/apps/system/js/airplane_mode.js +++ b/apps/system/js/airplane_mode.js @@ -90,9 +90,10 @@ ); }, updateStatus: function(value) { + // FM Radio will be turned off in Gecko, more detailed about why we do + // this in Gecko instead, please check bug 997064. var bluetooth = window.navigator.mozBluetooth; var wifiManager = window.navigator.mozWifiManager; - var fmRadio = window.navigator.mozFMRadio; var nfc = window.navigator.mozNfc; // Radio is a special service (might not exist e.g. tablet) @@ -130,11 +131,6 @@ if (nfc) { this._suspend('nfc'); } - - // Turn off FM Radio. - if (fmRadio && fmRadio.enabled) { - fmRadio.disable(); - } } else { // Note that we don't restore Wifi tethering when leaving airplane mode // because Wifi tethering can't be switched on before data connection is