2014-06-25 09:12:07 +04:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- /
|
2012-06-06 16:19:33 +04:00
|
|
|
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2013-09-06 00:18:28 +04:00
|
|
|
"use strict;"
|
2012-06-06 16:19:33 +04:00
|
|
|
|
2012-10-25 17:02:15 +04:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
const Cr = Components.results;
|
|
|
|
|
|
|
|
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
|
|
|
Cu.import('resource://gre/modules/Services.jsm');
|
|
|
|
|
2013-01-30 11:29:08 +04:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "libcutils", function () {
|
|
|
|
Cu.import("resource://gre/modules/systemlibs.js");
|
|
|
|
return libcutils;
|
|
|
|
});
|
|
|
|
#endif
|
|
|
|
|
2014-01-10 14:02:58 +04:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "uuidgen",
|
|
|
|
"@mozilla.org/uuid-generator;1",
|
|
|
|
"nsIUUIDGenerator");
|
|
|
|
|
2013-09-06 00:18:28 +04:00
|
|
|
// Once Bug 731746 - Allow chrome JS object to implement nsIDOMEventTarget
|
|
|
|
// is resolved this helper could be removed.
|
2012-06-06 16:19:33 +04:00
|
|
|
var SettingsListener = {
|
2013-09-06 00:18:28 +04:00
|
|
|
_callbacks: {},
|
2012-06-06 16:19:33 +04:00
|
|
|
|
2013-09-06 00:18:28 +04:00
|
|
|
init: function sl_init() {
|
|
|
|
if ('mozSettings' in navigator && navigator.mozSettings) {
|
|
|
|
navigator.mozSettings.onsettingchange = this.onchange.bind(this);
|
|
|
|
}
|
|
|
|
},
|
2013-09-04 16:28:28 +04:00
|
|
|
|
2013-09-06 00:18:28 +04:00
|
|
|
onchange: function sl_onchange(evt) {
|
|
|
|
var callback = this._callbacks[evt.settingName];
|
|
|
|
if (callback) {
|
|
|
|
callback(evt.settingValue);
|
|
|
|
}
|
2012-06-06 16:19:33 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
observe: function sl_observe(name, defaultValue, callback) {
|
2013-09-06 00:18:28 +04:00
|
|
|
var settings = window.navigator.mozSettings;
|
|
|
|
if (!settings) {
|
|
|
|
window.setTimeout(function() { callback(defaultValue); });
|
|
|
|
return;
|
2012-06-06 16:19:33 +04:00
|
|
|
}
|
|
|
|
|
2013-09-06 00:18:28 +04:00
|
|
|
if (!callback || typeof callback !== 'function') {
|
|
|
|
throw new Error('Callback is not a function');
|
|
|
|
}
|
|
|
|
|
|
|
|
var req = settings.createLock().get(name);
|
2012-06-06 16:19:33 +04:00
|
|
|
req.addEventListener('success', (function onsuccess() {
|
|
|
|
callback(typeof(req.result[name]) != 'undefined' ?
|
|
|
|
req.result[name] : defaultValue);
|
|
|
|
}));
|
|
|
|
|
2013-09-06 00:18:28 +04:00
|
|
|
this._callbacks[name] = callback;
|
2012-06-06 16:19:33 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-06 00:18:28 +04:00
|
|
|
SettingsListener.init();
|
|
|
|
|
2012-11-07 10:34:33 +04:00
|
|
|
// =================== Console ======================
|
|
|
|
|
|
|
|
SettingsListener.observe('debug.console.enabled', true, function(value) {
|
|
|
|
Services.prefs.setBoolPref('consoleservice.enabled', value);
|
2013-01-18 06:08:26 +04:00
|
|
|
Services.prefs.setBoolPref('layout.css.report_errors', value);
|
2012-11-07 10:34:33 +04:00
|
|
|
});
|
|
|
|
|
2012-06-06 16:19:33 +04:00
|
|
|
// =================== Languages ====================
|
|
|
|
SettingsListener.observe('language.current', 'en-US', function(value) {
|
2012-10-25 17:02:15 +04:00
|
|
|
Services.prefs.setCharPref('general.useragent.locale', value);
|
|
|
|
|
|
|
|
let prefName = 'intl.accept_languages';
|
2014-05-26 19:26:00 +04:00
|
|
|
let defaultBranch = Services.prefs.getDefaultBranch(null);
|
2012-10-25 17:02:15 +04:00
|
|
|
|
|
|
|
let intl = '';
|
|
|
|
try {
|
2014-05-26 19:26:00 +04:00
|
|
|
intl = defaultBranch.getComplexValue(prefName,
|
|
|
|
Ci.nsIPrefLocalizedString).data;
|
2012-10-25 17:02:15 +04:00
|
|
|
} catch(e) {}
|
|
|
|
|
2013-01-31 18:58:11 +04:00
|
|
|
// Bug 830782 - Homescreen is in English instead of selected locale after
|
|
|
|
// the first run experience.
|
|
|
|
// In order to ensure the current intl value is reflected on the child
|
|
|
|
// process let's always write a user value, even if this one match the
|
|
|
|
// current localized pref value.
|
2012-10-25 17:02:15 +04:00
|
|
|
if (!((new RegExp('^' + value + '[^a-z-_] *[,;]?', 'i')).test(intl))) {
|
2013-01-31 18:58:11 +04:00
|
|
|
value = value + ', ' + intl;
|
|
|
|
} else {
|
|
|
|
value = intl;
|
2012-10-25 17:02:15 +04:00
|
|
|
}
|
2013-01-31 18:58:11 +04:00
|
|
|
Services.prefs.setCharPref(prefName, value);
|
2012-10-31 17:17:43 +04:00
|
|
|
|
2012-11-27 23:28:56 +04:00
|
|
|
if (shell.hasStarted() == false) {
|
|
|
|
shell.start();
|
|
|
|
}
|
2012-06-06 16:19:33 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
// =================== RIL ====================
|
|
|
|
(function RILSettingsToPrefs() {
|
2012-11-30 14:09:37 +04:00
|
|
|
let strPrefs = ['ril.mms.mmsc', 'ril.mms.mmsproxy'];
|
2012-06-06 16:19:33 +04:00
|
|
|
strPrefs.forEach(function(key) {
|
2012-07-20 21:27:12 +04:00
|
|
|
SettingsListener.observe(key, "", function(value) {
|
2012-06-06 16:19:33 +04:00
|
|
|
Services.prefs.setCharPref(key, value);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-11-30 14:09:37 +04:00
|
|
|
['ril.mms.mmsport'].forEach(function(key) {
|
2012-07-20 21:27:12 +04:00
|
|
|
SettingsListener.observe(key, null, function(value) {
|
|
|
|
if (value != null) {
|
|
|
|
Services.prefs.setIntPref(key, value);
|
|
|
|
}
|
2012-06-06 16:19:33 +04:00
|
|
|
});
|
|
|
|
});
|
2012-11-07 21:51:40 +04:00
|
|
|
|
2013-10-24 12:15:06 +04:00
|
|
|
// DSDS default service IDs
|
|
|
|
['mms', 'sms', 'telephony', 'voicemail'].forEach(function(key) {
|
|
|
|
SettingsListener.observe('ril.' + key + '.defaultServiceId', 0,
|
|
|
|
function(value) {
|
|
|
|
if (value != null) {
|
|
|
|
Services.prefs.setIntPref('dom.' + key + '.defaultServiceId', value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2012-06-06 16:19:33 +04:00
|
|
|
})();
|
|
|
|
|
2012-09-19 14:06:40 +04:00
|
|
|
//=================== DeviceInfo ====================
|
|
|
|
Components.utils.import('resource://gre/modules/XPCOMUtils.jsm');
|
|
|
|
Components.utils.import('resource://gre/modules/ctypes.jsm');
|
|
|
|
(function DeviceInfoToSettings() {
|
2012-12-04 06:30:26 +04:00
|
|
|
// MOZ_B2G_VERSION is set in b2g/confvars.sh, and is output as a #define value
|
|
|
|
// from configure.in, defaults to 1.0.0 if this value is not exist.
|
2012-09-19 14:06:40 +04:00
|
|
|
#filter attemptSubstitution
|
|
|
|
let os_version = '@MOZ_B2G_VERSION@';
|
2012-12-04 06:30:26 +04:00
|
|
|
let os_name = '@MOZ_B2G_OS_NAME@';
|
2012-09-19 14:06:40 +04:00
|
|
|
#unfilter attemptSubstitution
|
|
|
|
|
2012-10-25 17:02:15 +04:00
|
|
|
let appInfo = Cc["@mozilla.org/xre/app-info;1"]
|
|
|
|
.getService(Ci.nsIXULAppInfo);
|
|
|
|
|
2012-12-04 06:30:26 +04:00
|
|
|
// Get the hardware info and firmware revision from device properties.
|
|
|
|
let hardware_info = null;
|
|
|
|
let firmware_revision = null;
|
2013-05-27 18:26:52 +04:00
|
|
|
let product_model = null;
|
2013-01-30 11:29:08 +04:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
hardware_info = libcutils.property_get('ro.hardware');
|
|
|
|
firmware_revision = libcutils.property_get('ro.firmware_revision');
|
2013-05-27 18:26:52 +04:00
|
|
|
product_model = libcutils.property_get('ro.product.model');
|
2013-01-30 11:29:08 +04:00
|
|
|
#endif
|
2013-09-09 14:28:01 +04:00
|
|
|
|
2014-07-28 22:13:10 +04:00
|
|
|
// Populate deviceinfo settings,
|
|
|
|
// copying any existing deviceinfo.os into deviceinfo.previous_os
|
|
|
|
let lock = window.navigator.mozSettings.createLock();
|
|
|
|
let req = lock.get('deviceinfo.os');
|
|
|
|
req.onsuccess = req.onerror = () => {
|
|
|
|
let previous_os = req.result && req.result['deviceinfo.os'] || '';
|
|
|
|
let software = os_name + ' ' + os_version;
|
|
|
|
let setting = {
|
|
|
|
'deviceinfo.os': os_version,
|
|
|
|
'deviceinfo.previous_os': previous_os,
|
|
|
|
'deviceinfo.software': software,
|
|
|
|
'deviceinfo.platform_version': appInfo.platformVersion,
|
|
|
|
'deviceinfo.platform_build_id': appInfo.platformBuildID,
|
|
|
|
'deviceinfo.hardware': hardware_info,
|
|
|
|
'deviceinfo.firmware_revision': firmware_revision,
|
|
|
|
'deviceinfo.product_model': product_model
|
|
|
|
}
|
|
|
|
lock.set(setting);
|
2013-09-09 14:28:01 +04:00
|
|
|
}
|
2012-09-19 14:06:40 +04:00
|
|
|
})();
|
2012-06-06 16:19:33 +04:00
|
|
|
|
2014-01-31 22:01:58 +04:00
|
|
|
// =================== DevTools ====================
|
|
|
|
|
2014-02-27 01:58:37 +04:00
|
|
|
let developerHUD;
|
2014-01-31 22:01:58 +04:00
|
|
|
SettingsListener.observe('devtools.overlay', false, (value) => {
|
|
|
|
if (value) {
|
2014-02-27 01:58:37 +04:00
|
|
|
if (!developerHUD) {
|
2014-01-31 22:01:58 +04:00
|
|
|
let scope = {};
|
2014-02-11 18:24:20 +04:00
|
|
|
Services.scriptloader.loadSubScript('chrome://b2g/content/devtools.js', scope);
|
2014-02-27 01:58:37 +04:00
|
|
|
developerHUD = scope.developerHUD;
|
2014-01-31 22:01:58 +04:00
|
|
|
}
|
2014-02-27 01:58:37 +04:00
|
|
|
developerHUD.init();
|
2014-01-31 22:01:58 +04:00
|
|
|
} else {
|
2014-02-27 01:58:37 +04:00
|
|
|
if (developerHUD) {
|
|
|
|
developerHUD.uninit();
|
2014-01-31 22:01:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-08-16 23:06:49 +04:00
|
|
|
// =================== Debugger / ADB ====================
|
2013-01-30 11:29:08 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2013-08-16 23:06:49 +04:00
|
|
|
let AdbController = {
|
|
|
|
DEBUG: false,
|
|
|
|
locked: undefined,
|
|
|
|
remoteDebuggerEnabled: undefined,
|
|
|
|
lockEnabled: undefined,
|
2013-08-16 23:07:05 +04:00
|
|
|
disableAdbTimer: null,
|
|
|
|
disableAdbTimeoutHours: 12,
|
2013-12-14 23:44:57 +04:00
|
|
|
umsActive: false,
|
2013-08-16 23:06:49 +04:00
|
|
|
|
|
|
|
debug: function(str) {
|
|
|
|
dump("AdbController: " + str + "\n");
|
|
|
|
},
|
2013-02-01 14:04:04 +04:00
|
|
|
|
2013-08-16 23:06:49 +04:00
|
|
|
setLockscreenEnabled: function(value) {
|
|
|
|
this.lockEnabled = value;
|
|
|
|
if (this.DEBUG) {
|
|
|
|
this.debug("setLockscreenEnabled = " + this.lockEnabled);
|
|
|
|
}
|
|
|
|
this.updateState();
|
|
|
|
},
|
2013-02-01 14:04:04 +04:00
|
|
|
|
2013-08-16 23:06:49 +04:00
|
|
|
setLockscreenState: function(value) {
|
|
|
|
this.locked = value;
|
|
|
|
if (this.DEBUG) {
|
|
|
|
this.debug("setLockscreenState = " + this.locked);
|
2013-02-07 23:44:23 +04:00
|
|
|
}
|
2013-08-16 23:06:49 +04:00
|
|
|
this.updateState();
|
|
|
|
},
|
2013-02-01 14:04:04 +04:00
|
|
|
|
2013-08-16 23:06:49 +04:00
|
|
|
setRemoteDebuggerState: function(value) {
|
|
|
|
this.remoteDebuggerEnabled = value;
|
|
|
|
if (this.DEBUG) {
|
|
|
|
this.debug("setRemoteDebuggerState = " + this.remoteDebuggerEnabled);
|
|
|
|
}
|
|
|
|
this.updateState();
|
|
|
|
},
|
|
|
|
|
2013-08-16 23:07:05 +04:00
|
|
|
startDisableAdbTimer: function() {
|
|
|
|
if (this.disableAdbTimer) {
|
|
|
|
this.disableAdbTimer.cancel();
|
|
|
|
} else {
|
|
|
|
this.disableAdbTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
|
|
try {
|
|
|
|
this.disableAdbTimeoutHours =
|
|
|
|
Services.prefs.getIntPref("b2g.adb.timeout-hours");
|
|
|
|
} catch (e) {
|
|
|
|
// This happens if the pref doesn't exist, in which case
|
|
|
|
// disableAdbTimeoutHours will still be set to the default.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.disableAdbTimeoutHours <= 0) {
|
|
|
|
if (this.DEBUG) {
|
|
|
|
this.debug("Timer to disable ADB not started due to zero timeout");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.DEBUG) {
|
|
|
|
this.debug("Starting timer to disable ADB in " +
|
|
|
|
this.disableAdbTimeoutHours + " hours");
|
|
|
|
}
|
|
|
|
let timeoutMilliseconds = this.disableAdbTimeoutHours * 60 * 60 * 1000;
|
|
|
|
this.disableAdbTimer.initWithCallback(this, timeoutMilliseconds,
|
|
|
|
Ci.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
},
|
|
|
|
|
|
|
|
stopDisableAdbTimer: function() {
|
|
|
|
if (this.DEBUG) {
|
|
|
|
this.debug("Stopping timer to disable ADB");
|
|
|
|
}
|
|
|
|
if (this.disableAdbTimer) {
|
|
|
|
this.disableAdbTimer.cancel();
|
|
|
|
this.disableAdbTimer = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
notify: function(aTimer) {
|
|
|
|
if (aTimer == this.disableAdbTimer) {
|
|
|
|
this.disableAdbTimer = null;
|
|
|
|
// The following dump will be the last thing that shows up in logcat,
|
|
|
|
// and will at least give the user a clue about why logcat was
|
|
|
|
// disconnected, if the user happens to be using logcat.
|
|
|
|
dump("AdbController: ADB timer expired - disabling ADB\n");
|
|
|
|
navigator.mozSettings.createLock().set(
|
2014-07-24 10:48:53 +04:00
|
|
|
{'debugger.remote-mode': 'disabled'});
|
2013-08-16 23:07:05 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-08-16 23:06:49 +04:00
|
|
|
updateState: function() {
|
2013-12-14 23:44:57 +04:00
|
|
|
this.umsActive = false;
|
|
|
|
this.storages = navigator.getDeviceStorages('sdcard');
|
|
|
|
this.updateStorageState(0);
|
|
|
|
},
|
|
|
|
|
|
|
|
updateStorageState: function(storageIndex) {
|
|
|
|
if (storageIndex >= this.storages.length) {
|
|
|
|
// We've iterated through all of the storage objects, now we can
|
|
|
|
// really do updateStateInternal.
|
|
|
|
this.updateStateInternal();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let storage = this.storages[storageIndex];
|
|
|
|
if (this.DEBUG) {
|
|
|
|
this.debug("Checking availability of storage: '" +
|
|
|
|
storage.storageName);
|
|
|
|
}
|
|
|
|
|
|
|
|
let req = storage.available();
|
|
|
|
req.onsuccess = function(e) {
|
|
|
|
if (this.DEBUG) {
|
|
|
|
this.debug("Storage: '" + storage.storageName + "' is '" +
|
|
|
|
e.target.result);
|
|
|
|
}
|
|
|
|
if (e.target.result == 'shared') {
|
|
|
|
// We've found a storage area that's being shared with the PC.
|
|
|
|
// We can stop looking now.
|
|
|
|
this.umsActive = true;
|
|
|
|
this.updateStateInternal();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.updateStorageState(storageIndex + 1);
|
|
|
|
}.bind(this);
|
|
|
|
req.onerror = function(e) {
|
|
|
|
dump("AdbController: error querying storage availability for '" +
|
|
|
|
this.storages[storageIndex].storageName + "' (ignoring)\n");
|
|
|
|
this.updateStorageState(storageIndex + 1);
|
|
|
|
}.bind(this);
|
|
|
|
},
|
|
|
|
|
|
|
|
updateStateInternal: function() {
|
|
|
|
if (this.DEBUG) {
|
|
|
|
this.debug("updateStateInternal: called");
|
|
|
|
}
|
|
|
|
|
2013-08-16 23:06:49 +04:00
|
|
|
if (this.remoteDebuggerEnabled === undefined ||
|
|
|
|
this.lockEnabled === undefined ||
|
|
|
|
this.locked === undefined) {
|
|
|
|
// Part of initializing the settings database will cause the observers
|
|
|
|
// to trigger. We want to wait until both have been initialized before
|
|
|
|
// we start changing ther adb state. Without this then we can wind up
|
|
|
|
// toggling adb off and back on again (or on and back off again).
|
|
|
|
//
|
|
|
|
// For completeness, one scenario which toggles adb is using the unagi.
|
|
|
|
// The unagi has adb enabled by default (prior to b2g starting). If you
|
|
|
|
// have the phone lock disabled and remote debugging enabled, then we'll
|
|
|
|
// receive an unlock event and an rde event. However at the time we
|
|
|
|
// receive the unlock event we haven't yet received the rde event, so
|
|
|
|
// we turn adb off momentarily, which disconnects a logcat that might
|
|
|
|
// be running. Changing the defaults (in AdbController) just moves the
|
|
|
|
// problem to a different phone, which has adb disabled by default and
|
|
|
|
// we wind up turning on adb for a short period when we shouldn't.
|
|
|
|
//
|
|
|
|
// By waiting until both values are properly initialized, we avoid
|
|
|
|
// turning adb on or off accidentally.
|
|
|
|
if (this.DEBUG) {
|
|
|
|
this.debug("updateState: Waiting for all vars to be initialized");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2013-09-08 03:28:51 +04:00
|
|
|
|
|
|
|
// Check if we have a remote debugging session going on. If so, we won't
|
|
|
|
// disable adb even if the screen is locked.
|
2014-07-21 16:39:00 +04:00
|
|
|
let isDebugging = USBRemoteDebugger.isDebugging;
|
2013-09-12 12:57:15 +04:00
|
|
|
if (this.DEBUG) {
|
|
|
|
this.debug("isDebugging=" + isDebugging);
|
|
|
|
}
|
2013-09-08 03:28:51 +04:00
|
|
|
|
2013-12-14 23:44:57 +04:00
|
|
|
// If USB Mass Storage, USB tethering, or a debug session is active,
|
|
|
|
// then we don't want to disable adb in an automatic fashion (i.e.
|
|
|
|
// when the screen locks or due to timeout).
|
|
|
|
let sysUsbConfig = libcutils.property_get("sys.usb.config");
|
|
|
|
let rndisActive = (sysUsbConfig.split(",").indexOf("rndis") >= 0);
|
|
|
|
let usbFuncActive = rndisActive || this.umsActive || isDebugging;
|
|
|
|
|
2013-08-16 23:06:49 +04:00
|
|
|
let enableAdb = this.remoteDebuggerEnabled &&
|
2013-12-14 23:44:57 +04:00
|
|
|
(!(this.lockEnabled && this.locked) || usbFuncActive);
|
2013-09-08 03:28:51 +04:00
|
|
|
|
2013-08-16 23:07:05 +04:00
|
|
|
let useDisableAdbTimer = true;
|
2013-08-16 23:06:49 +04:00
|
|
|
try {
|
|
|
|
if (Services.prefs.getBoolPref("marionette.defaultPrefs.enabled")) {
|
|
|
|
// Marionette is enabled. Marionette requires that adb be on (and also
|
|
|
|
// requires that remote debugging be off). The fact that marionette
|
|
|
|
// is enabled also implies that we're doing a non-production build, so
|
|
|
|
// we want adb enabled all of the time.
|
|
|
|
enableAdb = true;
|
2013-08-16 23:07:05 +04:00
|
|
|
useDisableAdbTimer = false;
|
2013-08-16 23:06:49 +04:00
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
// This means that the pref doesn't exist. Which is fine. We just leave
|
|
|
|
// enableAdb alone.
|
|
|
|
}
|
|
|
|
if (this.DEBUG) {
|
|
|
|
this.debug("updateState: enableAdb = " + enableAdb +
|
|
|
|
" remoteDebuggerEnabled = " + this.remoteDebuggerEnabled +
|
|
|
|
" lockEnabled = " + this.lockEnabled +
|
2013-12-14 23:44:57 +04:00
|
|
|
" locked = " + this.locked +
|
|
|
|
" usbFuncActive = " + usbFuncActive);
|
2013-08-16 23:06:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Configure adb.
|
2013-02-01 02:41:13 +04:00
|
|
|
let currentConfig = libcutils.property_get("persist.sys.usb.config");
|
|
|
|
let configFuncs = currentConfig.split(",");
|
|
|
|
let adbIndex = configFuncs.indexOf("adb");
|
|
|
|
|
2013-02-01 14:04:04 +04:00
|
|
|
if (enableAdb) {
|
2013-02-01 02:41:13 +04:00
|
|
|
// Add adb to the list of functions, if not already present
|
|
|
|
if (adbIndex < 0) {
|
|
|
|
configFuncs.push("adb");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Remove adb from the list of functions, if present
|
|
|
|
if (adbIndex >= 0) {
|
2013-08-16 23:06:49 +04:00
|
|
|
configFuncs.splice(adbIndex, 1);
|
2013-02-01 02:41:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
let newConfig = configFuncs.join(",");
|
|
|
|
if (newConfig != currentConfig) {
|
2013-08-16 23:06:49 +04:00
|
|
|
if (this.DEBUG) {
|
|
|
|
this.debug("updateState: currentConfig = " + currentConfig);
|
|
|
|
this.debug("updateState: newConfig = " + newConfig);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
libcutils.property_set("persist.sys.usb.config", newConfig);
|
|
|
|
} catch(e) {
|
|
|
|
dump("Error configuring adb: " + e);
|
|
|
|
}
|
2013-02-01 02:41:13 +04:00
|
|
|
}
|
2013-08-16 23:07:05 +04:00
|
|
|
if (useDisableAdbTimer) {
|
2013-12-14 23:44:57 +04:00
|
|
|
if (enableAdb && !usbFuncActive) {
|
2013-08-16 23:07:05 +04:00
|
|
|
this.startDisableAdbTimer();
|
|
|
|
} else {
|
|
|
|
this.stopDisableAdbTimer();
|
|
|
|
}
|
|
|
|
}
|
2013-08-16 23:06:49 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SettingsListener.observe("lockscreen.locked", false,
|
|
|
|
AdbController.setLockscreenState.bind(AdbController));
|
|
|
|
SettingsListener.observe("lockscreen.enabled", false,
|
|
|
|
AdbController.setLockscreenEnabled.bind(AdbController));
|
|
|
|
#endif
|
|
|
|
|
2014-07-21 16:39:00 +04:00
|
|
|
(function() {
|
|
|
|
// Track these separately here so we can determine the correct value for the
|
|
|
|
// pref "devtools.debugger.remote-enabled", which is true when either mode of
|
|
|
|
// using DevTools is enabled.
|
|
|
|
let devtoolsUSB = false;
|
|
|
|
let devtoolsWiFi = false;
|
|
|
|
|
|
|
|
// Keep the old setting to not break people that won't have updated
|
|
|
|
// gaia and gecko.
|
|
|
|
SettingsListener.observe('devtools.debugger.remote-enabled', false,
|
|
|
|
function(value) {
|
|
|
|
devtoolsUSB = value;
|
|
|
|
Services.prefs.setBoolPref('devtools.debugger.remote-enabled',
|
|
|
|
devtoolsUSB || devtoolsWiFi);
|
|
|
|
// This preference is consulted during startup
|
|
|
|
Services.prefs.savePrefFile(null);
|
|
|
|
try {
|
|
|
|
value ? USBRemoteDebugger.start() : USBRemoteDebugger.stop();
|
|
|
|
} catch(e) {
|
|
|
|
dump("Error while initializing USB devtools: "
|
|
|
|
+ e + "\n" + e.stack + "\n");
|
|
|
|
}
|
2013-08-16 23:06:49 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2014-07-21 16:39:00 +04:00
|
|
|
AdbController.setRemoteDebuggerState(value);
|
2013-01-30 11:29:08 +04:00
|
|
|
#endif
|
2014-07-21 16:39:00 +04:00
|
|
|
});
|
2012-08-22 05:48:47 +04:00
|
|
|
|
2014-07-24 10:48:53 +04:00
|
|
|
SettingsListener.observe('debugger.remote-mode', 'disabled', function(value) {
|
2014-07-21 16:39:00 +04:00
|
|
|
if (['disabled', 'adb-only', 'adb-devtools'].indexOf(value) == -1) {
|
|
|
|
dump('Illegal value for debugger.remote-mode: ' + value + '\n');
|
|
|
|
return;
|
|
|
|
}
|
2014-01-09 05:18:03 +04:00
|
|
|
|
2014-07-21 16:39:00 +04:00
|
|
|
devtoolsUSB = value == 'adb-devtools';
|
|
|
|
Services.prefs.setBoolPref('devtools.debugger.remote-enabled',
|
|
|
|
devtoolsUSB || devtoolsWiFi);
|
|
|
|
// This preference is consulted during startup
|
|
|
|
Services.prefs.savePrefFile(null);
|
2014-01-09 05:18:03 +04:00
|
|
|
|
2014-07-21 16:39:00 +04:00
|
|
|
try {
|
|
|
|
(value == 'adb-devtools') ? USBRemoteDebugger.start()
|
|
|
|
: USBRemoteDebugger.stop();
|
|
|
|
} catch(e) {
|
|
|
|
dump("Error while initializing USB devtools: "
|
|
|
|
+ e + "\n" + e.stack + "\n");
|
|
|
|
}
|
2014-01-09 05:18:03 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2014-07-21 16:39:00 +04:00
|
|
|
AdbController.setRemoteDebuggerState(value != 'disabled');
|
2014-01-09 05:18:03 +04:00
|
|
|
#endif
|
2014-07-21 16:39:00 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
SettingsListener.observe('devtools.remote.wifi.enabled', false,
|
|
|
|
function(value) {
|
|
|
|
devtoolsWiFi = value;
|
|
|
|
Services.prefs.setBoolPref('devtools.debugger.remote-enabled',
|
|
|
|
devtoolsUSB || devtoolsWiFi);
|
|
|
|
// Allow remote debugging on non-local interfaces when WiFi debug is enabled
|
|
|
|
// TODO: Bug 1034411: Lock down to WiFi interface, instead of all interfaces
|
|
|
|
Services.prefs.setBoolPref('devtools.debugger.force-local', !value);
|
|
|
|
// This preference is consulted during startup
|
|
|
|
Services.prefs.savePrefFile(null);
|
|
|
|
|
|
|
|
try {
|
|
|
|
value ? WiFiRemoteDebugger.start() : WiFiRemoteDebugger.stop();
|
|
|
|
} catch(e) {
|
|
|
|
dump("Error while initializing WiFi devtools: "
|
|
|
|
+ e + "\n" + e.stack + "\n");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})();
|
2014-01-09 05:18:03 +04:00
|
|
|
|
2013-05-11 13:10:18 +04:00
|
|
|
// =================== Device Storage ====================
|
2013-05-25 04:40:03 +04:00
|
|
|
SettingsListener.observe('device.storage.writable.name', 'sdcard', function(value) {
|
|
|
|
if (Services.prefs.getPrefType('device.storage.writable.name') != Ci.nsIPrefBranch.PREF_STRING) {
|
|
|
|
// We clear the pref because it used to be erroneously written as a bool
|
|
|
|
// and we need to clear it before we can change it to have the correct type.
|
|
|
|
Services.prefs.clearUserPref('device.storage.writable.name');
|
|
|
|
}
|
|
|
|
Services.prefs.setCharPref('device.storage.writable.name', value);
|
2013-05-11 13:10:18 +04:00
|
|
|
});
|
|
|
|
|
2012-09-13 08:32:17 +04:00
|
|
|
// =================== Privacy ====================
|
2013-08-31 18:15:57 +04:00
|
|
|
SettingsListener.observe('privacy.donottrackheader.value', 1, function(value) {
|
|
|
|
Services.prefs.setIntPref('privacy.donottrackheader.value', value);
|
2014-01-10 14:02:58 +04:00
|
|
|
// If the user specifically disallows tracking, we set the value of
|
|
|
|
// app.update.custom (update tracking ID) to an empty string.
|
|
|
|
if (value == 1) {
|
|
|
|
Services.prefs.setCharPref('app.update.custom', '');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Otherwise, we assure that the update tracking ID exists.
|
|
|
|
setUpdateTrackingId();
|
2013-08-31 18:15:57 +04:00
|
|
|
});
|
|
|
|
|
2012-10-29 22:18:50 +04:00
|
|
|
// =================== Crash Reporting ====================
|
|
|
|
SettingsListener.observe('app.reportCrashes', 'ask', function(value) {
|
|
|
|
if (value == 'always') {
|
|
|
|
Services.prefs.setBoolPref('app.reportCrashes', true);
|
|
|
|
} else if (value == 'never') {
|
|
|
|
Services.prefs.setBoolPref('app.reportCrashes', false);
|
|
|
|
} else {
|
|
|
|
Services.prefs.clearUserPref('app.reportCrashes');
|
|
|
|
}
|
2013-09-06 05:41:31 +04:00
|
|
|
// This preference is consulted during startup.
|
|
|
|
Services.prefs.savePrefFile(null);
|
2012-10-29 22:18:50 +04:00
|
|
|
});
|
|
|
|
|
2012-11-08 04:05:55 +04:00
|
|
|
// ================ Updates ================
|
2014-01-10 14:02:58 +04:00
|
|
|
/**
|
|
|
|
* For tracking purposes some partners require us to add an UUID to the
|
|
|
|
* update URL. The update tracking ID will be an empty string if the
|
|
|
|
* do-not-track feature specifically disallows tracking and it is reseted
|
|
|
|
* to a different ID if the do-not-track value changes from disallow to allow.
|
|
|
|
*/
|
|
|
|
function setUpdateTrackingId() {
|
|
|
|
try {
|
|
|
|
let dntEnabled = Services.prefs.getBoolPref('privacy.donottrackheader.enabled');
|
|
|
|
let dntValue = Services.prefs.getIntPref('privacy.donottrackheader.value');
|
|
|
|
// If the user specifically decides to disallow tracking (1), we just bail out.
|
|
|
|
if (dntEnabled && (dntValue == 1)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let trackingId =
|
|
|
|
Services.prefs.getPrefType('app.update.custom') ==
|
|
|
|
Ci.nsIPrefBranch.PREF_STRING &&
|
|
|
|
Services.prefs.getCharPref('app.update.custom');
|
|
|
|
|
|
|
|
// If there is no previous registered tracking ID, we generate a new one.
|
|
|
|
// This should only happen on first usage or after changing the
|
|
|
|
// do-not-track value from disallow to allow.
|
|
|
|
if (!trackingId) {
|
|
|
|
trackingId = uuidgen.generateUUID().toString().replace(/[{}]/g, "");
|
|
|
|
Services.prefs.setCharPref('app.update.custom', trackingId);
|
|
|
|
}
|
|
|
|
} catch(e) {
|
|
|
|
dump('Error getting tracking ID ' + e + '\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setUpdateTrackingId();
|
|
|
|
|
2014-04-23 10:14:00 +04:00
|
|
|
|
2013-05-28 21:24:02 +04:00
|
|
|
// ================ Debug ================
|
2014-01-15 02:44:47 +04:00
|
|
|
(function Composer2DSettingToPref() {
|
|
|
|
//layers.composer.enabled can be enabled in three ways
|
|
|
|
//In order of precedence they are:
|
|
|
|
//
|
|
|
|
//1. mozSettings "layers.composer.enabled"
|
|
|
|
//2. a gecko pref "layers.composer.enabled"
|
|
|
|
//3. presence of ro.display.colorfill at the Gonk level
|
|
|
|
|
|
|
|
var req = navigator.mozSettings.createLock().get('layers.composer2d.enabled');
|
|
|
|
req.onsuccess = function() {
|
|
|
|
if (typeof(req.result['layers.composer2d.enabled']) === 'undefined') {
|
|
|
|
var enabled = false;
|
|
|
|
if (Services.prefs.getPrefType('layers.composer2d.enabled') == Ci.nsIPrefBranch.PREF_BOOL) {
|
|
|
|
enabled = Services.prefs.getBoolPref('layers.composer2d.enabled');
|
|
|
|
} else {
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2014-05-09 23:03:53 +04:00
|
|
|
let androidVersion = libcutils.property_get("ro.build.version.sdk");
|
|
|
|
if (androidVersion >= 17 ) {
|
|
|
|
enabled = true;
|
|
|
|
} else {
|
|
|
|
enabled = (libcutils.property_get('ro.display.colorfill') === '1');
|
|
|
|
}
|
2014-01-15 02:44:47 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
navigator.mozSettings.createLock().set({'layers.composer2d.enabled': enabled });
|
|
|
|
}
|
|
|
|
|
|
|
|
SettingsListener.observe("layers.composer2d.enabled", true, function(value) {
|
|
|
|
Services.prefs.setBoolPref("layers.composer2d.enabled", value);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
req.onerror = function() {
|
|
|
|
dump("Error configuring layers.composer2d.enabled setting");
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|
2013-12-10 23:49:10 +04:00
|
|
|
|
|
|
|
// ================ Accessibility ============
|
|
|
|
SettingsListener.observe("accessibility.screenreader", false, function(value) {
|
|
|
|
if (value && !("AccessFu" in this)) {
|
|
|
|
Cu.import('resource://gre/modules/accessibility/AccessFu.jsm');
|
|
|
|
AccessFu.attach(window);
|
|
|
|
}
|
|
|
|
});
|
2014-01-16 18:52:30 +04:00
|
|
|
|
|
|
|
// ================ Theming ============
|
|
|
|
(function themingSettingsListener() {
|
|
|
|
let themingPrefs = ['ui.menu', 'ui.menutext', 'ui.infobackground', 'ui.infotext',
|
|
|
|
'ui.window', 'ui.windowtext', 'ui.highlight'];
|
|
|
|
|
|
|
|
themingPrefs.forEach(function(pref) {
|
|
|
|
SettingsListener.observe('gaia.' + pref, null, function(value) {
|
|
|
|
if (value) {
|
|
|
|
Services.prefs.setCharPref(pref, value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})();
|
2014-01-23 21:45:00 +04:00
|
|
|
|
2014-05-08 01:14:45 +04:00
|
|
|
// =================== Telemetry ======================
|
|
|
|
(function setupTelemetrySettings() {
|
|
|
|
let gaiaSettingName = 'debug.performance_data.shared';
|
|
|
|
let geckoPrefName = 'toolkit.telemetry.enabled';
|
|
|
|
SettingsListener.observe(gaiaSettingName, null, function(value) {
|
|
|
|
if (value !== null) {
|
|
|
|
// Gaia setting has been set; update Gecko pref to that.
|
|
|
|
Services.prefs.setBoolPref(geckoPrefName, value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Gaia setting has not been set; set the gaia setting to default.
|
|
|
|
#ifdef MOZ_TELEMETRY_ON_BY_DEFAULT
|
|
|
|
let prefValue = true;
|
|
|
|
#else
|
|
|
|
let prefValue = false;
|
|
|
|
#endif
|
|
|
|
try {
|
|
|
|
prefValue = Services.prefs.getBoolPref(geckoPrefName);
|
|
|
|
} catch (e) {
|
|
|
|
// Pref not set; use default value.
|
|
|
|
}
|
|
|
|
let setting = {};
|
|
|
|
setting[gaiaSettingName] = prefValue;
|
|
|
|
window.navigator.mozSettings.createLock().set(setting);
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
|
2014-07-24 14:35:00 +04:00
|
|
|
// =================== Low-precision buffer ======================
|
|
|
|
(function setupLowPrecisionSettings() {
|
|
|
|
// The gaia setting layers.low-precision maps to two gecko prefs
|
|
|
|
SettingsListener.observe('layers.low-precision', null, function(value) {
|
|
|
|
if (value !== null) {
|
|
|
|
// Update gecko from the new Gaia setting
|
|
|
|
Services.prefs.setBoolPref('layers.low-precision-buffer', value);
|
|
|
|
Services.prefs.setBoolPref('layers.progressive-paint', value);
|
|
|
|
} else {
|
|
|
|
// Update gaia setting from gecko value
|
|
|
|
try {
|
|
|
|
let prefValue = Services.prefs.getBoolPref('layers.low-precision-buffer');
|
|
|
|
let setting = { 'layers.low-precision': prefValue };
|
|
|
|
window.navigator.mozSettings.createLock().set(setting);
|
|
|
|
} catch (e) {
|
|
|
|
console.log('Unable to read pref layers.low-precision-buffer: ' + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// The gaia setting layers.low-opacity maps to a string gecko pref (0.5/1.0)
|
|
|
|
SettingsListener.observe('layers.low-opacity', null, function(value) {
|
|
|
|
if (value !== null) {
|
|
|
|
// Update gecko from the new Gaia setting
|
|
|
|
Services.prefs.setCharPref('layers.low-precision-opacity', value ? '0.5' : '1.0');
|
|
|
|
} else {
|
|
|
|
// Update gaia setting from gecko value
|
|
|
|
try {
|
|
|
|
let prefValue = Services.prefs.getCharPref('layers.low-precision-opacity');
|
|
|
|
let setting = { 'layers.low-opacity': (prefValue == '0.5') };
|
|
|
|
window.navigator.mozSettings.createLock().set(setting);
|
|
|
|
} catch (e) {
|
|
|
|
console.log('Unable to read pref layers.low-precision-opacity: ' + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
|
2014-03-04 12:53:16 +04:00
|
|
|
// =================== Various simple mapping ======================
|
|
|
|
let settingsToObserve = {
|
2014-05-14 14:08:00 +04:00
|
|
|
'app.update.channel': {
|
|
|
|
resetToPref: true
|
2014-03-04 12:53:16 +04:00
|
|
|
},
|
2014-05-14 14:08:00 +04:00
|
|
|
'app.update.interval': 86400,
|
|
|
|
'app.update.url': {
|
|
|
|
resetToPref: true
|
2014-03-04 12:53:16 +04:00
|
|
|
},
|
|
|
|
'apz.force-enable': {
|
|
|
|
prefName: 'dom.browser_frames.useAsyncPanZoom',
|
|
|
|
defaultValue: false
|
|
|
|
},
|
2014-06-06 19:42:22 +04:00
|
|
|
'apz.overscroll.enabled': true,
|
2014-03-04 12:53:16 +04:00
|
|
|
'debug.fps.enabled': {
|
|
|
|
prefName: 'layers.acceleration.draw-fps',
|
|
|
|
defaultValue: false
|
|
|
|
},
|
2014-05-14 14:08:00 +04:00
|
|
|
'debug.log-animations.enabled': {
|
|
|
|
prefName: 'layers.offmainthreadcomposition.log-animations',
|
|
|
|
defaultValue: false
|
|
|
|
},
|
2014-03-04 12:53:16 +04:00
|
|
|
'debug.paint-flashing.enabled': {
|
|
|
|
prefName: 'nglayout.debug.paint_flashing',
|
|
|
|
defaultValue: false
|
|
|
|
},
|
2014-05-14 14:08:00 +04:00
|
|
|
'devtools.eventlooplag.threshold': 100,
|
2014-07-14 20:11:00 +04:00
|
|
|
'devtools.remote.wifi.visible': {
|
|
|
|
resetToPref: true
|
|
|
|
},
|
2014-06-19 01:16:00 +04:00
|
|
|
'dom.mozApps.use_reviewer_certs': false,
|
2014-03-04 12:53:16 +04:00
|
|
|
'layers.draw-borders': false,
|
2014-05-14 14:08:00 +04:00
|
|
|
'layers.draw-tile-borders': false,
|
|
|
|
'layers.dump': false,
|
|
|
|
'layers.enable-tiles': true,
|
|
|
|
'layers.simple-tiles': false,
|
|
|
|
'privacy.donottrackheader.enabled': false,
|
|
|
|
'ril.radio.disabled': false,
|
|
|
|
'ril.mms.requestReadReport.enabled': {
|
|
|
|
prefName: 'dom.mms.requestReadReport',
|
|
|
|
defaultValue: true
|
2014-04-23 10:14:00 +04:00
|
|
|
},
|
2014-05-14 14:08:00 +04:00
|
|
|
'ril.mms.requestStatusReport.enabled': {
|
|
|
|
prefName: 'dom.mms.requestStatusReport',
|
|
|
|
defaultValue: false
|
2014-04-23 10:14:00 +04:00
|
|
|
},
|
2014-05-14 14:08:00 +04:00
|
|
|
'ril.mms.retrieval_mode': {
|
|
|
|
prefName: 'dom.mms.retrieval_mode',
|
|
|
|
defaultValue: 'manual'
|
|
|
|
},
|
|
|
|
'ril.sms.requestStatusReport.enabled': {
|
|
|
|
prefName: 'dom.sms.requestStatusReport',
|
2014-03-04 12:53:16 +04:00
|
|
|
defaultValue: false
|
2014-05-14 14:08:00 +04:00
|
|
|
},
|
|
|
|
'ril.sms.strict7BitEncoding.enabled': {
|
|
|
|
prefName: 'dom.sms.strict7BitEncoding',
|
|
|
|
defaultValue: false
|
|
|
|
},
|
2014-05-14 14:09:00 +04:00
|
|
|
'ui.touch.radius.leftmm': {
|
|
|
|
resetToPref: true
|
|
|
|
},
|
|
|
|
'ui.touch.radius.topmm': {
|
|
|
|
resetToPref: true
|
|
|
|
},
|
|
|
|
'ui.touch.radius.rightmm': {
|
|
|
|
resetToPref: true
|
|
|
|
},
|
|
|
|
'ui.touch.radius.bottommm': {
|
|
|
|
resetToPref: true
|
|
|
|
},
|
2014-05-14 14:08:00 +04:00
|
|
|
'wap.UAProf.tagname': 'x-wap-profile',
|
|
|
|
'wap.UAProf.url': ''
|
2014-03-04 12:53:16 +04:00
|
|
|
};
|
2014-02-04 03:20:00 +04:00
|
|
|
|
2014-03-04 12:53:16 +04:00
|
|
|
for (let key in settingsToObserve) {
|
|
|
|
let setting = settingsToObserve[key];
|
2014-02-04 03:20:00 +04:00
|
|
|
|
2014-04-23 10:14:00 +04:00
|
|
|
// Allow setting to contain flags redefining prefName and defaultValue.
|
|
|
|
let prefName = setting.prefName || key;
|
|
|
|
let defaultValue = setting.defaultValue;
|
|
|
|
if (defaultValue === undefined) {
|
|
|
|
defaultValue = setting;
|
|
|
|
}
|
|
|
|
|
|
|
|
let prefs = Services.prefs;
|
|
|
|
|
|
|
|
// If requested, reset setting value and defaultValue to the pref value.
|
|
|
|
if (setting.resetToPref) {
|
|
|
|
switch (prefs.getPrefType(prefName)) {
|
|
|
|
case Ci.nsIPrefBranch.PREF_BOOL:
|
|
|
|
defaultValue = prefs.getBoolPref(prefName);
|
|
|
|
break;
|
2014-02-04 03:20:00 +04:00
|
|
|
|
2014-04-23 10:14:00 +04:00
|
|
|
case Ci.nsIPrefBranch.PREF_INT:
|
|
|
|
defaultValue = prefs.getIntPref(prefName);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Ci.nsIPrefBranch.PREF_STRING:
|
|
|
|
defaultValue = prefs.getCharPref(prefName);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
let setting = {};
|
|
|
|
setting[key] = defaultValue;
|
|
|
|
window.navigator.mozSettings.createLock().set(setting);
|
2014-03-04 12:53:16 +04:00
|
|
|
}
|
|
|
|
|
2014-04-23 10:14:00 +04:00
|
|
|
// Figure out the right setter function for this type of pref.
|
|
|
|
let setPref;
|
2014-04-23 04:59:21 +04:00
|
|
|
switch (typeof defaultValue) {
|
2014-03-04 12:53:16 +04:00
|
|
|
case 'boolean':
|
2014-04-23 10:14:00 +04:00
|
|
|
setPref = prefs.setBoolPref.bind(prefs);
|
2014-03-04 12:53:16 +04:00
|
|
|
break;
|
|
|
|
|
2014-04-23 10:14:00 +04:00
|
|
|
case 'number':
|
|
|
|
setPref = prefs.setIntPref.bind(prefs);
|
2014-03-04 12:53:16 +04:00
|
|
|
break;
|
|
|
|
|
2014-04-23 10:14:00 +04:00
|
|
|
case 'string':
|
|
|
|
setPref = prefs.setCharPref.bind(prefs);
|
2014-03-04 12:53:16 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-04-23 10:14:00 +04:00
|
|
|
|
|
|
|
SettingsListener.observe(key, defaultValue, function(value) {
|
|
|
|
setPref(prefName, value);
|
|
|
|
});
|
2014-03-04 12:53:16 +04:00
|
|
|
};
|
2014-02-27 02:12:34 +04:00
|
|
|
|