Bug 1201556 - Send hashed device id for foxfooders. r=fabrice

--HG--
extra : rebase_source : beee55eb2c52519d1c19fb5ebc667ea8b6ec7b42
This commit is contained in:
Alexandre Lissy 2015-09-17 05:06:00 +02:00
parent 63aeeea1b1
commit ca41727a38
3 changed files with 48 additions and 3 deletions

View File

@ -537,6 +537,48 @@ SettingsListener.observe("theme.selected",
setPAC();
})();
#ifdef MOZ_B2G_RIL
XPCOMUtils.defineLazyModuleGetter(this, "AppsUtils",
"resource://gre/modules/AppsUtils.jsm");
// ======================= Dogfooders FOTA ==========================
SettingsListener.observe('debug.performance_data.dogfooding', false,
isDogfooder => {
if (!isDogfooder) {
dump('AUS:Settings: Not a dogfooder!\n');
return;
}
if (!('mozTelephony' in navigator)) {
dump('AUS:Settings: There is no mozTelephony!\n');
return;
}
if (!('mozMobileConnections' in navigator)) {
dump('AUS:Settings: There is no mozMobileConnections!\n');
return;
}
let conn = navigator.mozMobileConnections[0];
conn.addEventListener('radiostatechange', function onradiostatechange() {
if (conn.radioState !== 'enabled') {
return;
}
conn.removeEventListener('radiostatechange', onradiostatechange);
navigator.mozTelephony.dial('*#06#').then(call => {
return call.result.then(res => {
if (res.success && res.statusMessage
&& (res.serviceCode === 'scImei')) {
Services.prefs.setCharPref("app.update.imei_hash",
AppsUtils.computeHash(res.statusMessage, "SHA512"));
}
});
});
});
});
#endif
// =================== Various simple mapping ======================
var settingsToObserve = {
'accessibility.screenreader_quicknav_modes': {

View File

@ -757,8 +757,8 @@ this.AppsUtils = {
return deferred.promise;
},
// Returns the MD5 hash of a string.
computeHash: function(aString) {
// Returns the hash of a string, with MD5 as a default hashing function.
computeHash: function(aString, aAlgorithm = "MD5") {
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
.createInstance(Ci.nsIScriptableUnicodeConverter);
converter.charset = "UTF-8";
@ -768,7 +768,7 @@ this.AppsUtils = {
let hasher = Cc["@mozilla.org/security/hash;1"]
.createInstance(Ci.nsICryptoHash);
hasher.init(hasher.MD5);
hasher.initWithString(aAlgorithm);
hasher.update(data, data.length);
// We're passing false to get the binary hash and not base64.
let hash = hasher.finish(false);

View File

@ -31,6 +31,7 @@ const PREF_APP_UPDATE_CERT_ERRORS = "app.update.cert.errors";
const PREF_APP_UPDATE_CERT_MAXERRORS = "app.update.cert.maxErrors";
const PREF_APP_UPDATE_CERT_REQUIREBUILTIN = "app.update.cert.requireBuiltIn";
const PREF_APP_UPDATE_CUSTOM = "app.update.custom";
const PREF_APP_UPDATE_IMEI_HASH = "app.update.imei_hash";
const PREF_APP_UPDATE_ENABLED = "app.update.enabled";
const PREF_APP_UPDATE_IDLETIME = "app.update.idletime";
const PREF_APP_UPDATE_INCOMPATIBLE_MODE = "app.update.incompatible.mode";
@ -3546,6 +3547,8 @@ Checker.prototype = {
}
url = url.replace(/%B2G_VERSION%/g,
getPref("getCharPref", PREF_APP_B2G_VERSION, null));
url = url.replace(/%IMEI%/g,
getPref("getCharPref", PREF_APP_UPDATE_IMEI_HASH, "default"));
}
if (force) {