Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #27286 from marshall/bug1109422_mauChanges
Browse files Browse the repository at this point in the history
Bug 1109422 - [AUM] Updates to support monthly active users
  • Loading branch information
marshall authored and rvandermeulen committed Feb 19, 2015
1 parent d439c08 commit 9e3273d
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 44 deletions.
6 changes: 5 additions & 1 deletion Makefile
Expand Up @@ -119,6 +119,9 @@ REMOTE_DEBUGGER?=0
# Debug mode for build process
BUILD_DEBUG?=0

# Share performance and usage data
SHARE_PERF_USAGE?=1

ifeq ($(DEVICE_DEBUG),1)
REMOTE_DEBUGGER=1
NO_LOCK_SCREEN=1
Expand Down Expand Up @@ -537,7 +540,8 @@ define BUILD_CONFIG
"VARIANT_PATH" : "$(VARIANT_PATH)", \
"REBUILD": "$(REBUILD)", \
"P" : "$(P)", \
"VERBOSE" : "$(VERBOSE)"
"VERBOSE" : "$(VERBOSE)", \
"SHARE_PERF_USAGE": "$(SHARE_PERF_USAGE)" \
}
endef

Expand Down
12 changes: 12 additions & 0 deletions apps/ftu/js/navigation.js
Expand Up @@ -241,6 +241,18 @@ var Navigation = {
var improve = document.getElementById('browser_os_improve');
navigator.mozL10n.setAttributes(improve, 'helpImprove2',
getLocalizedLink('helpImprove'));

// Initialize the share checkbox according to the preset value
// of debug.performance_data.shared
var sharePerformance = document.getElementById('share-performance');
var settingName = sharePerformance.name;
var settings = navigator.mozSettings;
var req = settings && settings.createLock().get(settingName);
if (req) {
req.onsuccess = function() {
sharePerformance.checked = req.result[settingName] || false;
};
}
break;
case '#browser_privacy':
UIManager.mainTitle.setAttribute('data-l10n-id', 'aboutBrowser');
Expand Down
1 change: 1 addition & 0 deletions apps/ftu/test/unit/mock_navigation_index.html
Expand Up @@ -57,6 +57,7 @@ <h1 id="main-title"></h1>
<section role="region" id="welcome_browser">
<p id="browser_os_welcome"></p>
<p id="browser_os_improve"></p>
<input type="checkbox" id="share-performance"/>
</section>
</section>
<section id="finish-screen" role="region">
Expand Down
127 changes: 101 additions & 26 deletions apps/system/js/app_usage_metrics.js
Expand Up @@ -39,7 +39,8 @@
* normal app termination from abnormal and I can't figure out any way
* to tell when an app has crashed.
*/
/* global asyncStorage, SettingsListener, performance */
/* global asyncStorage, SettingsListener, performance, SIMSlotManager,
MobileOperator */
(function(exports) {
'use strict';

Expand All @@ -49,7 +50,7 @@

// This is the asyncStorage key we use to persist our app usage data so
// that it survives across device restarts.
const PERSISTENCE_KEY = 'metrics.app_usage.data';
const PERSISTENCE_KEY = 'metrics.app_usage.data.v2';

// This is the asyncStorage key we use to persist our device ID
const DEVICE_ID_KEY = 'metrics.app_usage.deviceID';
Expand Down Expand Up @@ -89,7 +90,6 @@
ATTENTIONCLOSED
];


// This AppUsageMetrics() constructor is the value we export from
// this module. This constructor does no initialization itself: that
// is all done in the start() instance method. See bootstrap.js for
Expand Down Expand Up @@ -135,7 +135,7 @@

// How often do we try to send the reports
// Can be overridden with metrics.appusage.reportInterval setting.
AUM.REPORT_INTERVAL = 24 * 60 * 60 * 1000; // 1 day
AUM.REPORT_INTERVAL = 14 * 24 * 60 * 60 * 1000; // 2 weeks

// If the telemetry server does not respond within this amount of time
// just give up and try again later.
Expand Down Expand Up @@ -613,19 +613,76 @@
};

var deviceInfoQuery = {
'deviceinfo.update_channel': 'unknown',
'deviceinfo.platform_version': 'unknown',
'developer.menu.enabled': false, // If true, data is probably an outlier
'deviceinfo.hardware': 'unknown',
'deviceinfo.os': 'unknown',
'deviceinfo.platform_build_id': 'unknown',
'developer.menu.enabled': false // If true, data is probably an outlier
'deviceinfo.platform_version': 'unknown',
'deviceinfo.product_model': 'unknown',
'deviceinfo.software': 'unknown',
'deviceinfo.update_channel': 'unknown'
};

// Query the settings db to get some more device-specific information
AUM.getSettings(deviceInfoQuery, function(deviceinfo) {
data.deviceinfo = deviceinfo;
AUM.getSettings(deviceInfoQuery, function(deviceInfo) {
data.deviceinfo = deviceInfo;
data.simInfo = getSIMInfo();

// Now transmit the data
send(data);
});

function getSIMInfo() {
var simInfo = {
network: null,
icc: null
};

if (SIMSlotManager.noSIMCardConnectedToNetwork()) {
// No connected SIMs
return simInfo;
}

var slots = SIMSlotManager.getSlots().filter(function(slot) {
return !slot.isAbsent() && !slot.isLocked();
});

if (slots.length === 0) {
// No unlocked or active SIM slots
return simInfo;
}

var conn = slots[0].conn;
if (!conn) {
// No connection
return simInfo;
}

var iccObj = navigator.mozIccManager.getIccById(conn.iccId);
var iccInfo = iccObj ? iccObj.iccInfo : null;
var voiceNetwork = conn.voice ? conn.voice.network : null;
if (!iccInfo && !voiceNetwork) {
// No voice network or ICC info
return simInfo;
}

simInfo.network = MobileOperator.userFacingInfo(conn);
if (voiceNetwork) {
simInfo.network.mnc = voiceNetwork.mnc;
simInfo.network.mcc = voiceNetwork.mcc;
}

if (iccInfo) {
simInfo.icc = {
mnc: iccInfo.mnc,
mcc: iccInfo.mcc,
spn: iccInfo.spn
};
}

return simInfo;
}

function send(data) {
var xhr = new XMLHttpRequest({ mozSystem: true, mozAnon: true });
xhr.open('POST', AUM.REPORT_URL);
Expand Down Expand Up @@ -671,20 +728,35 @@
this.relativeStartTime = performance.now();
}

UsageData.prototype.getAppUsage = function(app) {
/*
* Get app usage for the current date
*/
UsageData.prototype.getAppUsage = function(app, dayKey) {
var usage = this.data.apps[app];
dayKey = dayKey || this.getDayKey();

// We lazily initialize both the per-app and per-day usage maps
if (!usage) {
// If no usage exists for this app, create a new empty object for it.
usage = {
this.data.apps[app] = usage = {};
}

var dayUsage = usage[dayKey];
if (!dayUsage) {
dayUsage = usage[dayKey] = {
usageTime: 0,
invocations: 0,
installs: 0,
uninstalls: 0,
activities: {}
};
this.data.apps[app] = usage;
}
return usage;
return dayUsage;
};

UsageData.prototype.getDayKey = function(date) {
date = date || new Date();
var dayKey = date.toISOString().substring(0, 10);
return dayKey.replace(/-/g, '');
};

UsageData.prototype.startTime = function() {
Expand Down Expand Up @@ -761,18 +833,21 @@
// in the new batch and merge the new usage data with the old
// usage data.
for (var app in newbatch.data.apps) {
var newusage = newbatch.data.apps[app];
var oldusage = this.getAppUsage(app);

oldusage.usageTime += newusage.usageTime;
oldusage.invocations += newusage.invocations;
oldusage.installs += newusage.installs;
oldusage.uninstalls += newusage.uninstalls;

for (var url in newusage.activities) {
var newcount = newusage.activities[url];
var oldcount = oldusage.activities[url] || 0;
oldusage.activities[url] = oldcount + newcount;
var newdays = newbatch.data.apps[app];
for (var day in newdays) {
var newusage = newdays[day];
var oldusage = this.getAppUsage(app, day);

oldusage.usageTime += newusage.usageTime;
oldusage.invocations += newusage.invocations;
oldusage.installs += newusage.installs;
oldusage.uninstalls += newusage.uninstalls;

for (var url in newusage.activities) {
var newcount = newusage.activities[url];
var oldcount = oldusage.activities[url] || 0;
oldusage.activities[url] = oldcount + newcount;
}
}
}
};
Expand Down

0 comments on commit 9e3273d

Please sign in to comment.