Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Bug 997064: Do not call navigator.mozFMRadio from system app. #18444

Merged
merged 1 commit into from
Apr 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/fm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<link rel="resource" type="application/l10n" href="locales/locales.ini" />
<script defer src="shared/js/l10n.js"></script>
<script defer src="shared/js/async_storage.js"></script>
<script defer src="shared/js/airplane_mode_helper.js"></script>

<!-- For perf-measurement related utilities -->
<script defer src="shared/js/performance_testing_helper.js"></script>
Expand Down
44 changes: 9 additions & 35 deletions apps/fm/js/fm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -203,7 +180,7 @@ function updateAntennaUI() {
}

function updateAirplaneModeUI() {
$('airplane-mode-warning').hidden = !rilDisabled;
$('airplane-mode-warning').hidden = !airplaneModeEnabled;
}

var enabling = false;
Expand All @@ -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);
Expand Down Expand Up @@ -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();
});

Expand All @@ -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.
Expand Down
16 changes: 3 additions & 13 deletions apps/fm/test/unit/fm_test.js
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -229,7 +219,7 @@ suite('FM', function() {

suite('airplane mode on', function() {
setup(function() {
rilDisabled = true;
airplaneModeEnabled = true;
updateAirplaneModeUI();
});

Expand All @@ -240,7 +230,7 @@ suite('FM', function() {

suite('airplane mode off', function() {
setup(function() {
rilDisabled = false;
airplaneModeEnabled = false;
updateAirplaneModeUI();
});

Expand Down
8 changes: 2 additions & 6 deletions apps/system/js/airplane_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down