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

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1221929 - [TV][System] Track the last app before turning the devi…
Browse files Browse the repository at this point in the history
…ce off.
rexboy7 committed Nov 25, 2015

Verified

This commit was signed with the committer’s verified signature.
hakimifr Hakimi
1 parent 2e5f63b commit a0de899
Showing 1 changed file with 54 additions and 13 deletions.
67 changes: 54 additions & 13 deletions tv_apps/smart-system/js/app_usage_metrics.js
Original file line number Diff line number Diff line change
@@ -78,6 +78,8 @@
const ENABLED = 'applicationenabled';
const DISABLED = 'applicationdisabled';
const UNDERLAYOPENED = 'homescreen-underlayopened';
const REQUESTSHUTDOWN = 'requestshutdown';
const BATTERYSHUTDOWN = 'batteryshutdown';

// This is the list of event types we register handlers for
const EVENT_TYPES = [
@@ -97,7 +99,9 @@
IACMETRICS,
ENABLED,
DISABLED,
UNDERLAYOPENED
UNDERLAYOPENED,
REQUESTSHUTDOWN,
BATTERYSHUTDOWN
];


@@ -386,6 +390,20 @@
// Register for idle events
navigator.addIdleObserver(self.idleObserver);

// Register for poweroff events
var mozPower;
if (mozPower && mozPower.addPowerStateListener) {
mozPower = navigator.mozPower;
} else {
// XXX: Mocked addPowerStateListener for testing.
mozPower = {
addPowerStateListener: function(cb) {
setTimeout(cb, 10000, 'on-powerstate');
setTimeout(cb, 30000, 'off-powerstate');
}
};
}
mozPower.addPowerStateListener(self.onPowerStateChange.bind(self));
if (done) {
done();
}
@@ -429,25 +447,31 @@
AUM.prototype.handleEvent = function handleEvent(e) {
var now = performance.now();
debug('got an event: ', e.type);
switch (e.type) {

case APPOPENED:
// The user has opened an app or switched apps.
// Record data about the app that was running and then
// update the currently running app.
if (this._appIsUnderlay) {
var self = this;
function recordUnderlayAndHome() {
if (self._appIsUnderlay) {
// In this case, user launched an app from Home app while Home is
// overlaying on an app. We increase invocation count of underlying app
// without recording any usage time (since the usage time before home
// covers on has already recorded in HOMESCREEN event).
this.metrics.recordInvocation(this.getCurrentApp(), 0);
this.metrics.recordUsageTime(homescreenWindowManager.getHomescreen(),
now - this.getCurrentStartTime());
this._appIsUnderlay = false;
self.metrics.recordInvocation(self.getCurrentApp(), 0);
self.metrics.recordUsageTime(homescreenWindowManager.getHomescreen(),
now - self.getCurrentStartTime());
self._appIsUnderlay = false;
} else {
this.metrics.recordInvocation(this.getCurrentApp(),
now - this.getCurrentStartTime());
self.metrics.recordInvocation(self.getCurrentApp(),
now - self.getCurrentStartTime());
}
}

switch (e.type) {

case APPOPENED:
// The user has opened an app or switched apps.
// Record data about the app that was running and then
// update the currently running app.
recordUnderlayAndHome();

this.attentionWindows = [];
this.currentApp = e.detail;
@@ -592,6 +616,14 @@
this.idle = true;
break;

case REQUESTSHUTDOWN:
case BATTERYSHUTDOWN:
recordUnderlayAndHome();

// Set idle to true to make sure calling metrics.save().
this.idle = true;
break;

case ACTIVE:
this.idle = false;
break;
@@ -760,6 +792,15 @@
}
};

AUM.prototype.onPowerStateChange = function onPowerStateChange(state) {
if (state === 'off-powerstate') {
this.handleEvent({
type: REQUESTSHUTDOWN,
detail: this
});
}
};

/*
* A helper class that holds (and persists) a batch of app usage data
*/

0 comments on commit a0de899

Please sign in to comment.