Jed and I got confused the other day when trying to add hidden prefs for a small Firefox OS application. We wanted to make a few advanced options configurable via preferences (like those found in about:config in Firefox) but couldn't figure out why it wasn't possible to access them from within our certified application.

The answer is that settings and prefs are entirely different things in FxOS land.


This is how you set prefs in Gaia:

pref("devtools.debugger.forbid-certified-apps", false);
pref("dom.inter-app-communication-api.enabled", true);

from build/config/custom-prefs.js.

These will be used by the Gecko layer like this:

if (!Preferences::GetBool("dom.inter-app-communication-api.enabled", false)) {
  return false;

from within C++ code, and like this:

let restrictPrivileges = Services.prefs.getBoolPref("devtools.debugger.forbid-certified-apps");

from JavaScript code.

Preferences can be strings, integers or booleans.


Settings on the other hand are JSON objects which can be set like this:

"alarm.enabled": false,

in build/config/common-settings.json and can then be read like this:

var req = navigator.mozSettings.createLock().get('alarm.enabled');
req.onsuccess = function() {

as long as you have the following in your application manifest:

"permissions": {
  "settings":{ "access": "readwrite" },

In other words, if you set something in build/config/custom-prefs.js, don't expect to be able to read it using navigator.mozSettings or the SettingsHelper!