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 #33268 from rexboy7/1221924-metrics-smart-home-as-…
Browse files Browse the repository at this point in the history
…overlay

Bug 1221924 - [TV][usage] Log app usage time and smart-home covering time separately. r=lchang
  • Loading branch information
rexboy7 committed Nov 25, 2015
2 parents 38cab3b + 6b9d658 commit 2e5f63b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 7 deletions.
66 changes: 59 additions & 7 deletions tv_apps/smart-system/js/app_usage_metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/

/* global asyncStorage, SettingsListener, performance, uuid, TelemetryRequest,
applications, LazyLoader */
applications, LazyLoader, homescreenWindowManager */
(function(exports) {
'use strict';

Expand Down Expand Up @@ -77,6 +77,7 @@
const IACMETRICS = 'iac-app-metrics';
const ENABLED = 'applicationenabled';
const DISABLED = 'applicationdisabled';
const UNDERLAYOPENED = 'homescreen-underlayopened';

// This is the list of event types we register handlers for
const EVENT_TYPES = [
Expand All @@ -95,7 +96,8 @@
ATTENTIONCLOSED,
IACMETRICS,
ENABLED,
DISABLED
DISABLED,
UNDERLAYOPENED
];


Expand Down Expand Up @@ -430,17 +432,46 @@
switch (e.type) {

case APPOPENED:
case HOMESCREEN:
// The user has opened an app, switched apps, or switched to the
// homescreen. Record data about the app that was running and then
// The user has opened an app or switched apps.
// Record data about the app that was running and then
// update the currently running app.
this.metrics.recordInvocation(this.getCurrentApp(),
now - this.getCurrentStartTime());
if (this._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;
} else {
this.metrics.recordInvocation(this.getCurrentApp(),
now - this.getCurrentStartTime());
}

this.attentionWindows = [];
this.currentApp = e.detail;
this.currentAppStartTime = now;
break;
case HOMESCREEN:
// The user has switched to homescrseen.
// We record its usage time but postpone invocation count until other app
// replaces homescreen.
this.metrics.recordUsageTime(this.getCurrentApp(),
now - this.getCurrentStartTime());
this.attentionWindows = [];

this._appIsUnderlay = true;
this.currentAppStartTime = now;
break;
case UNDERLAYOPENED:
// The user has hidden the homescreen and use underlying app again.
this.metrics.recordUsageTime(homescreenWindowManager.getHomescreen(),
now - this.currentAppStartTime);

this._appIsUnderlay = false;
this.currentAppStartTime = now;
break;
case ATTENTIONOPENED:
// Push the current attention screen start time onto stack, and use
// currentApp / currentAppStartTime when the stack is empty
Expand Down Expand Up @@ -886,6 +917,27 @@
return time > 0;
};

// This function records usage time but doesn't increase invocation count.
// It's called for cases that user is switching between Home and underlying
// app back and forth.
UsageData.prototype.recordUsageTime = function(app, time) {
if (!this.shouldTrackApp(app)) {
return false;
}

// Convert time to seconds and round to the nearest second. If 0,
// don't record anything. (This can happen when we go to the
// lockscreen right before sleeping, for example.)
time = Math.round(time / 1000);
if (time > 0) {
var usage = this.getAppUsage(app);
usage.usageTime += time;
this.needsSave = true;
debug(app.manifestURL, 'run for', time);
}
return time > 0;
};

UsageData.prototype.recordSearch = function(provider) {
debug('recordSearch', provider);

Expand Down
2 changes: 2 additions & 0 deletions tv_apps/smart-system/js/homescreen_window_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@
// close the _underlayApp.
if (this._underlayApp.manifestURL ===
AppWindowManager.getActiveApp().manifestURL) {

this.publish('homescreen-underlayopened', this._underlayApp);
focusManager.focus();
} else {
this._underlayApp.close('immediate');
Expand Down

0 comments on commit 2e5f63b

Please sign in to comment.