Publish Vulpes Preview 15 sources for desktop, Android and Tundra

Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
OverSu 2026-09-30 23:13:03 +02:00
commit b38dea0597
52 changed files with 9982925 additions and 369 deletions

View file

@ -0,0 +1,349 @@
'use strict';
/* jshint node: true */
var utils = require('utils');
// Resources helper constructor
var Resources = function(gaia, settings, appDomain) {
this.gaia = gaia;
this.settings = settings;
this.fileList = [];
this.json = {};
this.appPrefix = 'app://';
this.appURL = this.appPrefix + appDomain + '/resources/';
};
// Parse and get resources for a given JSON configuration of one operator.
// Also create an output JSON configuration for the processed resources.
Resources.prototype.getResources = function(conf) {
var operatorJSON = {};
operatorJSON.default_contacts = this.addFile(conf.default_contacts);
operatorJSON.support_contacts = this.addFile(conf.support_contacts);
operatorJSON.network_type = this.addFile(conf.network_type);
operatorJSON.known_networks = this.addFile(conf.known_networks);
operatorJSON.sms = this.addFile(conf.sms);
operatorJSON.wallpaper = this.getWallpaperResource(conf.wallpaper);
operatorJSON.ringtone = this.getRingtoneResource(conf.ringtone);
operatorJSON.power = this.getPowerResource(conf.power);
operatorJSON.search = this.getSearchResource(conf.search);
operatorJSON.keyboard_settings = this.getKeyboardResource(conf.keyboard);
operatorJSON.topsites = this.getResourceWithIcon(conf.topsites, 'topSites',
'tilePath', 'tile');
operatorJSON.browser = this.getResourceWithIcon(conf.bookmarks, 'bookmarks',
'iconPath', 'iconUri');
if ('nfc' in conf) {
operatorJSON.nfc = this.getNfcResource(conf.nfc);
}
if ('data_ftu' in conf) {
operatorJSON.data_ftu = conf.data_ftu;
}
if ('data_roaming' in conf) {
operatorJSON.data_roaming = conf.data_roaming;
}
conf['mcc-mnc'].forEach(function(mcc) {
if (Object.keys(operatorJSON).length !== 0) {
this.json[mcc] = operatorJSON;
}
}.bind(this));
};
// Get file object for a given path.
Resources.prototype.getFile = function(path) {
var distDir = this.gaia.distributionDir;
var file = utils.getFile(distDir, path);
if (!file.exists()) {
throw new Error('Invalid single variant configuration: ' +
file.path + ' not found');
}
return file;
};
// Add new resource entry in the output JSON configuration (key / value)
// and add the resource path to the resources list.
Resources.prototype.addEntry = function(resources, name) {
if (resources instanceof Array) {
this.fileList.push.apply(this.fileList, resources);
} else {
this.fileList.push(resources);
}
return '/resources/' + name;
};
// Add file to resources object
Resources.prototype.addFile = function(path, key) {
if (path) {
var file = this.getFile(path);
return this.addEntry(file, file.leafName);
}
};
// Create a new JSON file and add to resources.
Resources.prototype.createJSON = function(name, content) {
var obj = { filename: name,
content: content };
return this.addEntry(obj, obj.filename);
};
// Create new wallpaper JSON from a wallpaper file path.
Resources.prototype.getWallpaperResource = function(wallpaper) {
if (wallpaper) {
var uri;
if (wallpaper.startsWith(this.appPrefix)) {
uri = wallpaper;
} else {
var file = this.getFile(wallpaper);
if (!file) {
return;
}
uri = '/resources/' + file.leafName;
this.addEntry(file, file.leafName);
}
var content = { uri: uri,
default: this.settings['wallpaper.image'] };
var jsonName = 'wallpaper-' + utils.getHash(wallpaper) + '.json';
return this.createJSON(jsonName, content);
}
};
// Create ringtone JSON and add file.
Resources.prototype.getRingtoneResource = function(ringtone) {
if (ringtone) {
var jsonName = 'ringtone-' +
utils.getHash(JSON.stringify(ringtone)) + '.json';
var ringtoneName = ringtone.name;
if (!ringtoneName) {
throw new Error('Missing name for ringtone in single variant conf.');
}
var uri;
if (ringtone.path.startsWith(this.appPrefix)) {
uri = ringtone.path;
} else {
var file = this.getFile(ringtone.path);
if (!file) {
throw new Error('Missing path for ringtone in single variant conf.');
}
uri = '/resources/' + file.leafName;
this.addEntry(file, file.leafName);
}
var content = { uri: uri,
name: ringtoneName,
default: this.settings['dialer.ringtone.id'] };
return this.createJSON(jsonName, content);
}
};
// Create power JSON and add files.
Resources.prototype.getPowerResource = function (power) {
if (power) {
var jsonName = 'power-' + utils.getHash(JSON.stringify(power)) + '.json';
var powerJSON = power;
var poweron = power.poweron;
var poweronFile;
if (poweron) {
var poweronType = poweron.video ? 'video' : null ||
poweron.image ? 'image' : null;
if (!poweronType) {
throw new Error('Invalid poweron type, only video or image are ' +
'valid.');
}
if (poweron[poweronType].startsWith(this.appPrefix)) {
powerJSON.poweron[poweronType] = poweron[poweronType];
} else {
poweronFile = this.getFile(poweron[poweronType]);
this.addEntry(poweronFile, poweronFile.leafName);
powerJSON.poweron[poweronType] = this.appURL + poweronFile.leafName;
}
}
var poweroff = power.poweroff;
var poweroffFile;
if (poweroff) {
var poweroffType = poweroff.video ? 'video' : null ||
poweroff.image ? 'image' : null;
if (!poweroffType) {
throw new Error('Invalid poweroff type, only video or image are ' +
'valid.');
}
if (poweroff[poweroffType].startsWith(this.appPrefix)) {
powerJSON.poweroff[poweroffType] = poweroff[poweroffType];
} else {
poweroffFile = this.getFile(poweroff[poweroffType]);
this.addEntry(poweroffFile, poweroffFile.leafName);
powerJSON.poweroff[poweroffType] = this.appURL + poweroffFile.leafName;
}
}
return this.createJSON(jsonName, powerJSON);
}
};
// Create search JSON and add files.
Resources.prototype.getSearchResource = function (searchPath) {
if (searchPath) {
var file = this.getFile(searchPath);
var searchContent = utils.getJSON(file);
searchContent.forEach(function(engine) {
if (!engine.iconPath.startsWith(this.appPrefix)) {
var searchFile = this.getFile(engine.iconPath);
this.addEntry(searchFile, searchFile.leafName);
engine.iconUrl = this.appURL + searchFile.leafName;
delete engine.iconPath;
}
}.bind(this));
return this.createJSON(file.leafName, searchContent);
}
};
// Create keyboard JSON.
Resources.prototype.getKeyboardResource = function (keyboard) {
if (keyboard) {
var file = utils.getFile(this.gaia.distributionDir, keyboard);
if (!file.exists()) {
throw new Error('Invalid single variant configuration: ' +
file.path + ' not found');
}
var defaults = {
'keyboard.vibration': this.settings['keyboard.vibration'],
'keyboard.autocorrect': this.settings['keyboard.autocorrect'],
'keyboard.clicksound': this.settings['keyboard.clicksound'],
'keyboard.wordsuggestion': this.settings['keyboard.wordsuggestion']
};
var content = { values: utils.getJSON(file),
defaults: defaults };
for (var value in content.values) {
if (!value.startsWith('keyboard.')) {
throw new Error('Invalid keyboard property \'' + value + '\' in file ' +
file.path + ', keyboard properties must start ' +
'with \'keyboard.\'');
}
}
var jsonName = 'keyboard-' + utils.getHash(keyboard) + '.json';
return this.createJSON(jsonName, content);
}
};
Resources.prototype.getResourceWithIcon = function(aFilePath, aRootKey,
aIconPathKey, aIconOutKey) {
if (aFilePath) {
var file = this.getFile(aFilePath);
var json = utils.getJSON(file);
json[aRootKey].forEach(function(elem) {
if (elem[aIconPathKey]) {
var iconFile = this.getFile(elem[aIconPathKey]);
var icon = utils.getFileAsDataURI(iconFile);
elem[aIconOutKey] = icon;
delete elem[aIconPathKey];
}
}.bind(this));
return this.createJSON(file.leafName, json);
}
};
// Create nfc JSON.
Resources.prototype.getNfcResource = function(nfc) {
var content = { isEnabled: nfc,
default: this.settings['nfc.enabled'] };
var jsonName = 'nfc-' + utils.getHash(JSON.stringify(content)) + '.json';
return this.createJSON(jsonName, content);
};
// OperatorAppBuilder constructor object.
var OperatorAppBuilder = function() {
};
// set destination directory, application directory and get settings in order
// to set default values.
OperatorAppBuilder.prototype.setOptions = function(options) {
this.stageDir = utils.getFile(options.STAGE_APP_DIR);
this.gaia = utils.gaia.getInstance(options);
var settingsFile = utils.getFile(options.PROFILE_DIR, 'settings.json');
if (!settingsFile.exists()) {
throw new Error('file not found: ' + settingsFile.path);
}
this.settings = utils.getJSON(settingsFile);
this.appDir = utils.getFile(options.APP_DIR);
this.appDomain = this.appDir.leafName + '.' + options.GAIA_DOMAIN;
};
// Get resources and copy files and configuration JSON to build_stage folder.
OperatorAppBuilder.prototype.generateCustomizeResources = function() {
if (!this.gaia.distributionDir) {
return;
}
var variantFile = utils.getFile(this.gaia.distributionDir, 'variant.json');
if (variantFile.exists()) {
var resources = this.getSingleVariantResources(variantFile);
var resourceDirFile = utils.getFile(this.stageDir.path, 'resources');
utils.ensureFolderExists(resourceDirFile);
var customizationFile = utils.getFile(this.stageDir.path,
'resources', 'customization.json');
utils.writeContent(customizationFile, JSON.stringify(resources.json));
resources.fileList.forEach(function(file) {
if (!file.filename && !file.content) {
utils.copyFileTo(file.path, resourceDirFile.path, file.leafName);
} else {
var resourceFile = utils.getFile(resourceDirFile.path, file.filename);
utils.writeContent(resourceFile, JSON.stringify(file.content));
}
});
} else {
utils.log('operatorvariant',
'Single variant resources will not be added since ' +
variantFile.path + ' not found');
}
};
// Use Resources object to get the resources for each operator.
OperatorAppBuilder.prototype.getSingleVariantResources = function(svConfFile) {
var svConf = utils.getJSON(svConfFile);
var resources = new Resources(this.gaia, this.settings, this.appDomain);
svConf.operators.forEach(function(operator) {
resources.getResources(operator);
});
return resources;
};
OperatorAppBuilder.prototype.execute = function(options) {
utils.copyToStage(options);
this.setOptions(options);
this.generateCustomizeResources(options);
};
exports.execute = function(options) {
(new OperatorAppBuilder()).execute(options);
};

View file

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<script type="text/javascript" src="/shared/js/lazy_loader.js"></script>
<script type="text/javascript" src="/shared/js/bookmarks_database.js"></script>
<script type="text/javascript" src="js/resources.js"></script>
<script type="text/javascript" src="js/operator_variant.js"></script>
</head>
<body>
</body>
</html>

View file

@ -0,0 +1,32 @@
/* global Customizer */
/* global BookmarksDatabase */
'use strict';
var BrowserCustomizer = function() {
Customizer.call(this, 'browser', 'json');
this.set = function(aData) {
if (!aData || ! aData.bookmarks) {
return;
}
var self = this;
aData.bookmarks.forEach(function(bookmark) {
if (!bookmark.uri || !bookmark.title) {
return;
}
var data = {
type: 'url',
name: bookmark.title,
url: bookmark.uri,
icon: bookmark.iconUri
};
BookmarksDatabase.add(data);
}, self);
};
};
var browserCustomizer = new BrowserCustomizer();
browserCustomizer.init();

View file

@ -0,0 +1,34 @@
/* global Resources */
/* exported Customizer */
'use strict';
// Extend this class for creating a new customizer and provide
// a set() method. It is expected set() returns nothing and accept
// an unique parameter which is an object of the type specified
// in the constructor of the customizer.
var Customizer = (function(setting, resourceType, onerror) {
var self = this;
this.init = function() {
window.addEventListener('customization', function eventHandler(event) {
if (event.detail.setting === setting) {
window.removeEventListener('customization', eventHandler);
var value = event.detail.value;
self.simPresentOnFirstBoot = event.detail.simPresentOnFirstBoot;
// If resourceType === 'data' the value received contains directly the
// value that the customizer will proccess.
// In other case the value will have the resource to be loaded by the
// customizer.
if (resourceType === 'data') {
self.set(value);
} else {
Resources.load(value, resourceType, self.set.bind(self),
function onerrorRetrieving(status) {
console.error('Customizer.js: Error retrieving the resource.');
onerror && onerror(status);
});
}
}
});
};
});

View file

@ -0,0 +1,20 @@
/* global Customizer */
'use strict';
var DataFTUCustomizer = (function() {
Customizer.call(this, 'data_ftu', 'data');
this.set = function(aIsEnabled) {
try {
navigator.mozSettings.createLock().set({
'ftu.ril.data.enabled': aIsEnabled
});
} catch (e) {
console.log('DataFTUCustomizer. Error recovering datas. ' +
'We will use default values. ' + e);
}
};
});
var dataFTUCustomizer = new DataFTUCustomizer();
dataFTUCustomizer.init();

View file

@ -0,0 +1,31 @@
/* global Customizer */
'use strict';
var DataRoamingCustomizer = (function() {
Customizer.call(this, 'data_roaming', 'data');
this.set = function(isEnabled) {
if (typeof isEnabled !== 'boolean') {
console.error('DataRoamingCustomizer. Invalid type for input value.');
return;
}
if (!this.simPresentOnFirstBoot) {
console.log('DataRoamingCustomizer. No first RUN with configured SIM.');
return;
}
var settings = navigator.mozSettings;
if (!settings) {
console.error('DataRoamingCustomizer. Settings is not available');
return;
}
settings.createLock().set({
'ril.data.roaming_enabled': isEnabled
});
};
});
var dataRoamingCustomizer = new DataRoamingCustomizer();
dataRoamingCustomizer.init();

View file

@ -0,0 +1,22 @@
/* global Customizer, mozContact */
'use strict';
var DefaultContactsCustomizer = (function() {
Customizer.call(this, 'default_contacts', 'json');
this.set = function(contacts) {
function errorHandler(contact, evt) {
console.error('Saving default contact failed: ' + evt && evt.target &&
evt.target.error && evt.target.error.name);
console.error('Error while saving ' + JSON.stringify(contact));
}
for (var i = 0; i < contacts.length; ++i) {
var contact = new mozContact(contacts[i]);
var savingContact = navigator.mozContacts.save(contact);
savingContact.onerror = errorHandler.bind(null, contact);
}
};
});
var defaultContactsCustomizer = new DefaultContactsCustomizer();
defaultContactsCustomizer.init();

View file

@ -0,0 +1,56 @@
/* global Customizer */
'use strict';
var KeyboardSettingsCustomizer = (function() {
Customizer.call(this, 'keyboard_settings', 'json');
this.set = function(keybrdParams) {
if (!this.simPresentOnFirstBoot) {
console.log('KeyboardSettingsCustomizer. ' +
'Skipping configuration since there was no SIM at first run');
return;
}
var settings = navigator.mozSettings;
if (!settings) {
console.error('KeyboardSettingsCustomizer. Settings is not available');
return;
}
function setKeyboard() {
try {
var settingsValue = {};
for (var key in keybrdParams.values) {
// we don't want falsy/truely values. We only accept explicit values
// for keyboard settings. Any other value is considered a
// configuration error.
if (typeof keybrdParams.values[key] == 'boolean') {
settingsValue[key] = keybrdParams.values[key];
}
}
settings.createLock().set(settingsValue);
} catch (e) {
console.log('KeyboardSettingsCustomizer. Error recovering datas. ' + e);
}
}
// First of all, we should verify the parameters
if (!keybrdParams || !keybrdParams.values) {
console.error('KeyboardCustomizer -> Configuration error: ' +
'Defaults parameters or new values have not been received');
return;
}
// If we have not new values to set we have already done
var numNewValues = Object.keys(keybrdParams.values).length;
if (numNewValues === 0) {
console.log('KeyboardCustomizer -> New values has not received');
return;
}
setKeyboard();
};
});
var keyboardSettingsCustomizer = new KeyboardSettingsCustomizer();
keyboardSettingsCustomizer.init();

View file

@ -0,0 +1,124 @@
/* global Customizer */
'use strict';
var KnownNetworksCustomizer = (function() {
Customizer.call(this, 'known_networks', 'json');
function isValidWepKey(password) {
switch (password.length) {
case 5:
case 13:
case 16:
case 29:
return true;
case 10:
case 26:
case 32:
case 58:
return !/[^a-fA-F0-9]/.test(password);
default:
return false;
}
}
function getNetwork(aNetParams) {
if (!aNetParams || !aNetParams.ssid) {
return;
}
var net = {};
net.ssid = aNetParams.ssid;
if (!aNetParams.keyType) {
return net;
}
net.keyManagement = aNetParams.keyType;
net.security = [aNetParams.keyType];
net.capabilities = aNetParams.capabilities ? [aNetParams.capabilities] : [];
switch (aNetParams.keyType) {
case 'WPA-PSK':
if (aNetParams.password && aNetParams.password.length >= 8) {
net.psk = aNetParams.password;
}
break;
case 'WPA-EAP':
if (!aNetParams.eap) {
break;
}
net.eap = aNetParams.eap;
switch (aNetParams.eap) {
case 'SIM':
break;
case 'PEAP':
case 'TLS':
case 'TTLS':
var properties = ['password', 'identity', 'phase2', 'pin',
'serverCertificate'];
for (var i = 0, l = properties.length; i < l; i++) {
if (aNetParams[properties[i]]) {
net[properties[i]] = aNetParams[properties[i]];
}
}
break;
}
break;
case 'WEP':
if (aNetParams.password && isValidWepKey(aNetParams.password)) {
net.wep = aNetParams.password;
}
break;
}
return net;
}
this.set = function(aNetworksParams) {
try {
if (!aNetworksParams) {
return;
}
var wifiManager = navigator.mozWifiManager;
if (!wifiManager) {
return;
}
var req = wifiManager.getKnownNetworks();
req.onerror = function onError() {
console.log('Error configuring SV knownNetworks. ' + req.error.name);
wifiManager = null;
};
req.onsuccess = function onSuccess() {
var allKnownNetArr = req.result;
var numKnownNet = allKnownNetArr.length;
var allKnownNet = {};
for (var i = 0; i < numKnownNet; i++) {
allKnownNet[allKnownNetArr[i].ssid] = allKnownNetArr[i];
if (aNetworksParams[allKnownNetArr[i].ssid]) {
delete aNetworksParams[allKnownNetArr[i].ssid];
}
}
allKnownNetArr = null;
for (var key in aNetworksParams) {
var netParams = aNetworksParams[key];
if (!allKnownNet[netParams.ssid]) {
var network = getNetwork(netParams);
if (network) {
network.dontConnect = true;
network = new window.MozWifiNetwork(network);
wifiManager.associate(network);
allKnownNet[network.ssid] = network;
}
}
}
wifiManager = null;
};
} catch (e) {
console.log('KnownNetworksCustomizer. Error recovering wifis. ' + e);
}
};
});
var knownNetworksCustomizer = new KnownNetworksCustomizer();
knownNetworksCustomizer.init();

View file

@ -0,0 +1,38 @@
/* global Customizer */
'use strict';
var NetworkTypeCustomizer = (function() {
Customizer.call(this, 'network_type', 'json');
this.set = function(aDatas) {
try {
if (!aDatas) {
return;
}
var settings = navigator.mozSettings;
if (!settings) {
console.error('NetworkTypeCustomizer. Settings is not available');
return;
}
var settingsValue = {};
for (var key in aDatas) {
settingsValue[key] = aDatas[key];
}
if (Object.keys(settingsValue).length) {
settings.createLock().set({
'operatorResources.data.icon': settingsValue
});
}
} catch (e) {
console.error('NetworkTypeCustomizer. Error recovering datas. ' +
'We will use default values. ' + e);
}
};
});
var networkTypeCustomizer = new NetworkTypeCustomizer();
networkTypeCustomizer.init();

View file

@ -0,0 +1,43 @@
/* global Customizer */
'use strict';
var NfcCustomizer = (function() {
Customizer.call(this, 'nfc', 'json');
this.set = function(nfcParams) {
if (!this.simPresentOnFirstBoot) {
console.log('NfcCustomizer. No first RUN with configured SIM.');
return;
}
const NFC_SETTING = 'nfc.enabled';
var settings = navigator.mozSettings;
if (!settings) {
console.error('NfcCustomizer. Settings is not available');
return;
}
var nfcLock = settings.createLock();
var nfc = nfcLock.get(NFC_SETTING);
// We only change the nfc value if the user does not changed it previously
// The user has changed the value if the actual value of nfc is
// different from default value.
nfc.onsuccess = function nc_onsuccess() {
var value = nfc.result[NFC_SETTING];
if (value === undefined || value === nfcParams.default) {
nfcLock.set({ 'nfc.enabled': nfcParams.isEnabled });
}
};
nfc.onerror = function wc_onerror() {
console.error('Error retrieving ' + NFC_SETTING + '. ' +
nfc.error.name);
};
};
});
var nfcCustomizer = new NfcCustomizer();
nfcCustomizer.init();

View file

@ -0,0 +1,45 @@
/* global Customizer */
'use strict';
var PowerCustomizer = (function() {
Customizer.call(this, 'power', 'json');
this.set = function(aDatas) {
if (!aDatas) {
return;
}
var settings = navigator.mozSettings;
if (!settings) {
console.error('PowerCustomizer. Settings is not available');
return;
}
var settingsValue = {};
if (aDatas.poweron) {
if (aDatas.poweron.video) {
settingsValue['poweron.video'] = aDatas.poweron.video;
}
if (aDatas.poweron.image) {
settingsValue['poweron.image'] = aDatas.poweron.image;
}
}
if (aDatas.poweroff) {
if (aDatas.poweroff.video) {
settingsValue['poweroff.video'] = aDatas.poweroff.video;
}
if (aDatas.poweroff.image) {
settingsValue['poweroff.image'] = aDatas.poweroff.image;
}
}
if (Object.keys(settingsValue).length) {
settings.createLock().set({
'operatorResources.power': settingsValue
});
}
};
});
var powerCustomizer = new PowerCustomizer();
powerCustomizer.init();

View file

@ -0,0 +1,37 @@
/* global Customizer, Resources */
'use strict';
var RingtoneCustomizer = (function() {
Customizer.call(this, 'ringtone', 'json');
this.set = function(ringtoneParams) {
if (!this.simPresentOnFirstBoot) {
console.log('RingtoneCustomizer. No first RUN with configured SIM.');
return;
}
var settings = navigator.mozSettings;
if (!settings) {
console.error('RingtoneCustomizer. Settings is not available');
return;
}
function setRingtone() {
Resources.load(ringtoneParams.uri, 'blob', function onsuccess(blob) {
settings.createLock().set({
'dialer.ringtone': blob,
'dialer.ringtone.name': ringtoneParams.name
});
}, function onerror(status) {
console.error('RingtoneCustomizer.js: Error retrieving the resource.' +
ringtoneParams.uri);
});
}
setRingtone();
};
});
var ringtoneCustomizer = new RingtoneCustomizer();
ringtoneCustomizer.init();

View file

@ -0,0 +1,25 @@
/* global Customizer */
'use strict';
var SearchCustomizer = (function() {
Customizer.call(this, 'search', 'json');
this.set = function(aData) {
if (!aData) {
return;
}
var settings = navigator.mozSettings;
if (!settings) {
console.error('SearchCustomizer. Settings is not available');
return;
}
settings.createLock().set({
'search.providers': aData
});
};
});
var searchCustomizer = new SearchCustomizer();
searchCustomizer.init();

View file

@ -0,0 +1,45 @@
/* global Customizer */
'use strict';
var SmsCustomizer = (function() {
Customizer.call(this, 'sms', 'json');
function getPosInteger(num, txtError) {
if (!num) {
return null;
}
var intPos = Math.floor(num);
if (isNaN(intPos) || intPos < 0) {
intPos = null;
}
return intPos;
}
this.set = function(smsParams) {
if (!smsParams) {
console.error('SmsCustomizer. Configuration parameters not received');
return;
}
var settings = navigator.mozSettings;
if (!settings) {
console.error('SmsCustomizer. Settings is not available');
return;
}
var maxConcatFloor = getPosInteger(smsParams.smsMaxConcat);
// Zero is wrong value too.
if (!maxConcatFloor) {
console.error('Incorrect value for max concatenated message:' +
smsParams.smsMaxConcat);
return;
}
settings.createLock().set({
'operatorResource.sms.maxConcat': maxConcatFloor
});
};
});
var smsCustomizer = new SmsCustomizer();
smsCustomizer.init();

View file

@ -0,0 +1,27 @@
/* global Customizer */
'use strict';
var SupportContactsCustomizer = (function() {
Customizer.call(this, 'support_contacts', 'json');
this.set = function(contacts) {
if (contacts) {
var settings = navigator.mozSettings;
if (!settings) {
console.error('SupportContactsCustomizer. Settings is not available');
return;
}
settings.createLock().set({
'support.onlinesupport.title': contacts.onlinesupport.title,
'support.onlinesupport.href': contacts.onlinesupport.href,
'support.callsupport1.title': contacts.callsupport1.title,
'support.callsupport1.href': contacts.callsupport1.href,
'support.callsupport2.title': contacts.callsupport2.title,
'support.callsupport2.href': contacts.callsupport2.href
});
}
};
});
var supportContactsCustomizer = new SupportContactsCustomizer();
supportContactsCustomizer.init();

View file

@ -0,0 +1,39 @@
/* global Customizer */
'use strict';
var TopSitesCustomizer = (function() {
Customizer.call(this, 'topsites', 'json');
this.set = function(topSiteConfig) {
if (!topSiteConfig ||
!topSiteConfig.topSites ||
!topSiteConfig.topSites.length) {
return;
}
this.getStore('places').then(store => {
topSiteConfig.topSites.forEach(site => {
store.get(site.url).then(place => {
if (!place) {
site.frecency = -1;
store.put(site, site.url);
}
});
});
});
};
this.getStore = function(name) {
return new Promise(resolve => {
navigator.getDataStores(name).then(stores => {
resolve(stores[0]);
});
});
};
});
var topSitesCustomizer = new TopSitesCustomizer();
topSitesCustomizer.init();

View file

@ -0,0 +1,38 @@
/* global Customizer, Resources */
'use strict';
var WallpaperCustomizer = (function() {
Customizer.call(this, 'wallpaper', 'json');
this.set = function(wallpaperParams) {
if (!this.simPresentOnFirstBoot) {
console.log('WallpaperCustomizer. No first RUN with configured SIM.');
return;
}
var settings = navigator.mozSettings;
if (!settings) {
console.error('WallpaperCustomizer. Settings is not available');
return;
}
function setWallpaper() {
Resources.load(wallpaperParams.uri, 'blob', function onsuccess(blob) {
settings.createLock().set({
'wallpaper.image': blob
});
}, function onerror(status) {
console.error('WallpaperCustomizer.js: Error retrieving the resource.' +
wallpaperParams.uri);
});
}
setWallpaper();
};
});
var wallpaperCustomizer = new WallpaperCustomizer();
wallpaperCustomizer.init();

View file

@ -0,0 +1,136 @@
/* global LazyLoader, Resources */
'use strict';
var OperatorVariantManager = {
SETTING_FTU_SIM_PRESENT: 'ftu.simPresentOnFirstBoot',
// Settings 'ftu.simPresentOnFirstBoot' only had false value if the user
// powered the phone on without SIM
// In other case we would have true or undefined depending on what process was
// executed first, so our variable is true by default.
simPresentOnFirstBoot: true,
// This file is created during the BUILD process
CUSTOMIZATION_FILE: '/resources/customization.json',
// If you want to add another customizer, you only need to add the js file
// with the implementation here
CUSTOMIZERS: [
// Base class, dont remove!
'/js/customizers/customizer.js',
// Extended classes from 'Customizer'
'/js/customizers/keyboard_settings_customizer.js',
'/js/customizers/wallpaper_customizer.js',
'/js/customizers/network_type_customizer.js',
'/js/customizers/ringtone_customizer.js',
'/js/customizers/support_contacts_customizer.js',
'/js/customizers/sms_customizer.js',
'/js/customizers/default_contacts_customizer.js',
'/js/customizers/power_customizer.js',
'/js/customizers/known_networks_customizer.js',
'/js/customizers/data_ftu_customizer.js',
'/js/customizers/nfc_customizer.js',
'/js/customizers/search_customizer.js',
'/js/customizers/default_search_customizer.js',
'/js/customizers/topsites_customizer.js',
'/js/customizers/data_roaming_customizer.js',
'/js/customizers/browser_customizer.js'
],
init: function ovm_init() {
navigator.mozSetMessageHandler('first-run-with-sim', (msg) => {
var self = this;
self.mcc_mnc = self.getMccMnc(msg.mcc, msg.mnc);
if (self.mcc_mnc) {
var settings = navigator.mozSettings;
if (!settings) {
console.log(
'Settings is not available. Cannot make the configuration changes');
return;
}
var req = settings.createLock().get(self.SETTING_FTU_SIM_PRESENT);
req.onsuccess = function osv_success(e) {
var simOnFirstBoot = req.result[self.SETTING_FTU_SIM_PRESENT];
self.simPresentOnFirstBoot = !simOnFirstBoot ||
req.result[self.SETTING_FTU_SIM_PRESENT] === self.mcc_mnc;
LazyLoader.load(
self.CUSTOMIZERS,
self.loadVariantAndCustomize.bind(self)
);
};
req.onerror = function osv_error(e) {
console.error('Error retrieving ftu.simPresentOnFirstBoot. ', e);
};
}
});
},
getMccMnc: function ovm_getMccMnc(aMcc, aMnc) {
if ((aMcc !== undefined) && (aMcc !== null) &&
(aMnc !== undefined) && (aMnc !== null)) {
return this.normalizeCode(aMcc) + '-' + this.normalizeCode(aMnc);
}
return undefined;
},
// Given a number returns a three characters string padding with zeroes
// to the left until the desired length (3) is reached
normalizeCode: function ovm_normalizeCode(aCode) {
var ncode = '' + aCode;
while (ncode.length < 3) {
ncode = '0' + ncode;
}
return ncode;
},
// Loads the variant file and start customization event dispatching.
loadVariantAndCustomize: function ovm_loadVariantAndCustomize() {
this.getVariantSettings(this.dispatchCustomizationEvents.bind(this));
},
getVariantSettings: function ovm_getVariantSettings(onsuccess, onerror) {
var filePath = this.CUSTOMIZATION_FILE;
Resources.load(filePath, 'json', function(data) {
onsuccess && onsuccess(data);
}, onerror);
},
// For each variant setting dispatch a customization event
dispatchCustomizationEvents: function ovm_dispatchEvents(customizationList) {
if (!customizationList) {
console.log('No customizers were found. Please review the content of ' +
this.CUSTOMIZATION_FILE + '.');
return;
}
function scheduleEvent(event) {
setTimeout(function() {
window.dispatchEvent(event);
}, 0);
}
var customizationSettings = customizationList[this.mcc_mnc];
if (!customizationSettings) {
console.error('There is no variant customization available for ' +
this.mcc_mnc);
return;
}
for (var setting in customizationSettings) {
if (customizationSettings.hasOwnProperty(setting)) {
var customizationEvent = new CustomEvent('customization', {
detail: {
setting: setting,
value: customizationSettings[setting],
simPresentOnFirstBoot: this.simPresentOnFirstBoot
}
});
scheduleEvent(customizationEvent);
}
}
}
};
OperatorVariantManager.init();

View file

@ -0,0 +1,55 @@
/* exported Resources */
'use strict';
var Resources = {
load: function r_load(url, type, onsuccess, onerror) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = type;
var mimetype = this.getMimetype(url);
if (mimetype) {
xhr.overrideMimeType(mimetype);
}
xhr.onload = function() {
if (xhr.status === 200) {
onsuccess && onsuccess(xhr.response);
} else {
console.error('Resources.js: Failed to fetch file ' + url + '. ' +
xhr.statusText);
onerror && onerror(xhr.statusText);
}
};
// Workaround due to https://bugzilla.mozilla.org/show_bug.cgi?id=827243
try {
xhr.send();
} catch (e) {
// TODO Remove when 827243 will be fixed.
console.error('Resources.js: Failed to fetch file ' + url + '. ' +
xhr.statusText);
onerror && onerror('404: due to bug 827243');
}
},
getMimetype: function r_getMimetype(fileName) {
var fileExtension = fileName.split('.').pop();
var mimetype = false;
if (fileExtension) {
switch (fileExtension) {
case 'ogg':
mimetype = 'audio/ogg';
break;
case 'json':
mimetype = 'application/json';
break;
case 'mp3':
mimetype = 'audio/mpeg';
break;
case 'mp4':
mimetype = 'audio/mp4';
break;
}
}
return mimetype;
}
};

Some files were not shown because too many files have changed in this diff Show more