2012-06-06 16:19:33 +04:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
"use strict;"
|
|
|
|
|
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');
|
|
|
|
|
2012-06-06 16:19:33 +04:00
|
|
|
// Once Bug 731746 - Allow chrome JS object to implement nsIDOMEventTarget
|
|
|
|
// is resolved this helper could be removed.
|
|
|
|
var SettingsListener = {
|
|
|
|
_callbacks: {},
|
|
|
|
|
|
|
|
init: function sl_init() {
|
|
|
|
if ('mozSettings' in navigator && navigator.mozSettings) {
|
|
|
|
navigator.mozSettings.onsettingchange = this.onchange.bind(this);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onchange: function sl_onchange(evt) {
|
|
|
|
var callback = this._callbacks[evt.settingName];
|
|
|
|
if (callback) {
|
|
|
|
callback(evt.settingValue);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
observe: function sl_observe(name, defaultValue, callback) {
|
|
|
|
var settings = window.navigator.mozSettings;
|
|
|
|
if (!settings) {
|
|
|
|
window.setTimeout(function() { callback(defaultValue); });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!callback || typeof callback !== 'function') {
|
|
|
|
throw new Error('Callback is not a function');
|
|
|
|
}
|
|
|
|
|
2012-09-06 04:33:03 +04:00
|
|
|
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);
|
|
|
|
}));
|
|
|
|
|
|
|
|
this._callbacks[name] = callback;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SettingsListener.init();
|
|
|
|
|
2012-07-13 14:17:37 +04:00
|
|
|
// =================== Audio ====================
|
|
|
|
SettingsListener.observe('audio.volume.master', 0.5, function(value) {
|
|
|
|
let audioManager = Services.audioManager;
|
|
|
|
if (!audioManager)
|
|
|
|
return;
|
|
|
|
|
2012-07-15 14:38:24 +04:00
|
|
|
audioManager.masterVolume = Math.max(0.0, Math.min(value, 1.0));
|
2012-07-13 14:17:37 +04:00
|
|
|
});
|
|
|
|
|
2012-12-04 14:21:43 +04:00
|
|
|
let audioChannelSettings = [];
|
2012-11-09 03:15:38 +04:00
|
|
|
|
|
|
|
if ("nsIAudioManager" in Ci) {
|
|
|
|
const nsIAudioManager = Ci.nsIAudioManager;
|
2012-12-04 14:21:43 +04:00
|
|
|
audioChannelSettings = [
|
|
|
|
// settings name, max value, apply to stream types
|
2012-12-11 14:26:01 +04:00
|
|
|
['audio.volume.content', 15, [nsIAudioManager.STREAM_TYPE_SYSTEM, nsIAudioManager.STREAM_TYPE_MUSIC]],
|
2012-12-04 14:21:43 +04:00
|
|
|
['audio.volume.notification', 15, [nsIAudioManager.STREAM_TYPE_RING, nsIAudioManager.STREAM_TYPE_NOTIFICATION]],
|
|
|
|
['audio.volume.alarm', 15, [nsIAudioManager.STREAM_TYPE_ALARM]],
|
|
|
|
['audio.volume.telephony', 5, [nsIAudioManager.STREAM_TYPE_VOICE_CALL]],
|
|
|
|
['audio.volume.bt_sco', 15, [nsIAudioManager.STREAM_TYPE_BLUETOOTH_SCO]],
|
2012-11-09 03:15:38 +04:00
|
|
|
];
|
|
|
|
}
|
2012-11-02 13:36:46 +04:00
|
|
|
|
2012-12-04 14:21:43 +04:00
|
|
|
for each (let [setting, maxValue, streamTypes] in audioChannelSettings) {
|
|
|
|
(function AudioStreamSettings(setting, maxValue, streamTypes) {
|
|
|
|
SettingsListener.observe(setting, maxValue, function(value) {
|
2012-11-02 13:36:46 +04:00
|
|
|
let audioManager = Services.audioManager;
|
|
|
|
if (!audioManager)
|
|
|
|
return;
|
|
|
|
|
2012-12-04 14:21:43 +04:00
|
|
|
for each(let streamType in streamTypes) {
|
|
|
|
audioManager.setStreamVolumeIndex(streamType, Math.min(value, maxValue));
|
|
|
|
}
|
2012-11-02 13:36:46 +04:00
|
|
|
});
|
2012-12-04 14:21:43 +04:00
|
|
|
})(setting, maxValue, streamTypes);
|
2012-11-02 13:36:46 +04:00
|
|
|
}
|
2012-06-06 16:19:33 +04:00
|
|
|
|
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';
|
|
|
|
if (Services.prefs.prefHasUserValue(prefName)) {
|
|
|
|
Services.prefs.clearUserPref(prefName);
|
|
|
|
}
|
|
|
|
|
|
|
|
let intl = '';
|
|
|
|
try {
|
|
|
|
intl = Services.prefs.getComplexValue(prefName,
|
|
|
|
Ci.nsIPrefLocalizedString).data;
|
|
|
|
} catch(e) {}
|
|
|
|
|
|
|
|
if (!((new RegExp('^' + value + '[^a-z-_] *[,;]?', 'i')).test(intl))) {
|
|
|
|
Services.prefs.setCharPref(prefName, value + ', ' + intl);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
SettingsListener.observe('ril.sms.strict7BitEncoding.enabled', false,
|
|
|
|
function(value) {
|
|
|
|
Services.prefs.setBoolPref('dom.sms.strict7BitEncoding', 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() {
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, 'gSettingsService',
|
|
|
|
'@mozilla.org/settingsService;1',
|
|
|
|
'nsISettingsService');
|
|
|
|
let lock = gSettingsService.createLock();
|
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
|
|
|
|
lock.set('deviceinfo.os', os_version, null, null);
|
2012-12-04 06:30:26 +04:00
|
|
|
lock.set('deviceinfo.software', os_name + ' ' + os_version, null, null);
|
2012-09-19 14:06:40 +04:00
|
|
|
|
2012-10-25 17:02:15 +04:00
|
|
|
let appInfo = Cc["@mozilla.org/xre/app-info;1"]
|
|
|
|
.getService(Ci.nsIXULAppInfo);
|
|
|
|
lock.set('deviceinfo.platform_version', appInfo.platformVersion, null, null);
|
|
|
|
lock.set('deviceinfo.platform_build_id', appInfo.platformBuildID, null, null);
|
|
|
|
|
|
|
|
let update_channel = Services.prefs.getCharPref('app.update.channel');
|
|
|
|
lock.set('deviceinfo.update_channel', update_channel, null, null);
|
|
|
|
|
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;
|
2012-09-19 14:06:40 +04:00
|
|
|
try {
|
|
|
|
let cutils = ctypes.open('libcutils.so');
|
|
|
|
let cbuf = ctypes.char.array(128)();
|
|
|
|
let c_property_get = cutils.declare('property_get', ctypes.default_abi,
|
|
|
|
ctypes.int, // return value: length
|
|
|
|
ctypes.char.ptr, // key
|
|
|
|
ctypes.char.ptr, // value
|
|
|
|
ctypes.char.ptr); // default
|
|
|
|
let property_get = function (key, defaultValue) {
|
|
|
|
if (defaultValue === undefined) {
|
|
|
|
defaultValue = null;
|
|
|
|
}
|
|
|
|
c_property_get(key, cbuf, defaultValue);
|
|
|
|
return cbuf.readString();
|
|
|
|
}
|
2012-12-04 06:30:26 +04:00
|
|
|
hardware_info = property_get('ro.hardware');
|
|
|
|
firmware_revision = property_get('ro.firmware_revision');
|
2012-09-19 14:06:40 +04:00
|
|
|
cutils.close();
|
|
|
|
} catch(e) {
|
2012-12-04 06:30:26 +04:00
|
|
|
// Error.
|
2012-09-19 14:06:40 +04:00
|
|
|
}
|
2012-12-04 06:30:26 +04:00
|
|
|
lock.set('deviceinfo.hardware', hardware_info, null, null);
|
|
|
|
lock.set('deviceinfo.firmware_revision', firmware_revision, null, null);
|
2012-09-19 14:06:40 +04:00
|
|
|
})();
|
2012-06-06 16:19:33 +04:00
|
|
|
|
|
|
|
// =================== Debugger ====================
|
2012-10-31 20:21:54 +04:00
|
|
|
SettingsListener.observe('devtools.debugger.remote-enabled', false, function(value) {
|
2012-07-03 13:32:36 +04:00
|
|
|
Services.prefs.setBoolPref('devtools.debugger.remote-enabled', value);
|
2012-10-31 20:21:54 +04:00
|
|
|
// This preference is consulted during startup
|
|
|
|
Services.prefs.savePrefFile(null);
|
2013-01-08 11:08:00 +04:00
|
|
|
value ? RemoteDebugger.start() : RemoteDebugger.stop();
|
2012-07-03 13:32:36 +04:00
|
|
|
});
|
2012-08-22 05:48:47 +04:00
|
|
|
|
|
|
|
SettingsListener.observe('debug.log-animations.enabled', false, function(value) {
|
|
|
|
Services.prefs.setBoolPref('layers.offmainthreadcomposition.log-animations', value);
|
|
|
|
});
|
|
|
|
|
2012-09-13 08:32:17 +04:00
|
|
|
// =================== Privacy ====================
|
|
|
|
SettingsListener.observe('privacy.donottrackheader.enabled', false, function(value) {
|
|
|
|
Services.prefs.setBoolPref('privacy.donottrackheader.enabled', value);
|
2012-09-19 14:06:40 +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');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-11-08 04:05:55 +04:00
|
|
|
// ================ Updates ================
|
|
|
|
SettingsListener.observe('app.update.interval', 86400, function(value) {
|
|
|
|
Services.prefs.setIntPref('app.update.interval', value);
|
|
|
|
});
|