diff options
author | Adam Lesinski <adamlesinski@google.com> | 2015-03-02 22:22:57 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-03-02 22:22:58 +0000 |
commit | a4005662c7a22b457a6db092426f16b240902732 (patch) | |
tree | fda1861c00e64ab4d7b0ce44a7c65961c8f4762d /services/usage/java | |
parent | 7b91c55b3ff4857e904a11a0a67fcc86a32868b4 (diff) | |
parent | 978a1ed5aa2752cd36ff51df91d2d2d8be2171d9 (diff) | |
download | frameworks_base-a4005662c7a22b457a6db092426f16b240902732.zip frameworks_base-a4005662c7a22b457a6db092426f16b240902732.tar.gz frameworks_base-a4005662c7a22b457a6db092426f16b240902732.tar.bz2 |
Merge "Add generic "INTERACTION" event type to UsageStatsManager"
Diffstat (limited to 'services/usage/java')
3 files changed, 35 insertions, 1 deletions
diff --git a/services/usage/java/com/android/server/usage/IntervalStats.java b/services/usage/java/com/android/server/usage/IntervalStats.java index 5f639ab..869d6e1 100644 --- a/services/usage/java/com/android/server/usage/IntervalStats.java +++ b/services/usage/java/com/android/server/usage/IntervalStats.java @@ -81,6 +81,17 @@ class IntervalStats { return event; } + private boolean isStatefulEvent(int eventType) { + switch (eventType) { + case UsageEvents.Event.MOVE_TO_FOREGROUND: + case UsageEvents.Event.MOVE_TO_BACKGROUND: + case UsageEvents.Event.END_OF_DAY: + case UsageEvents.Event.CONTINUE_PREVIOUS_DAY: + return true; + } + return false; + } + void update(String packageName, long timeStamp, int eventType) { UsageStats usageStats = getOrCreateUsageStats(packageName); @@ -93,7 +104,11 @@ class IntervalStats { usageStats.mTotalTimeInForeground += timeStamp - usageStats.mLastTimeUsed; } } - usageStats.mLastEvent = eventType; + + if (isStatefulEvent(eventType)) { + usageStats.mLastEvent = eventType; + } + usageStats.mLastTimeUsed = timeStamp; usageStats.mEndTimeStamp = timeStamp; diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java index 485b2a2..5eefe6a 100644 --- a/services/usage/java/com/android/server/usage/UsageStatsService.java +++ b/services/usage/java/com/android/server/usage/UsageStatsService.java @@ -488,6 +488,23 @@ public class UsageStatsService extends SystemService implements } @Override + public void reportEvent(String packageName, int userId, int eventType) { + if (packageName == null) { + Slog.w(TAG, "Event reported without a package name"); + return; + } + + UsageEvents.Event event = new UsageEvents.Event(); + event.mPackage = packageName; + + // This will later be converted to system time. + event.mTimeStamp = SystemClock.elapsedRealtime(); + + event.mEventType = eventType; + mHandler.obtainMessage(MSG_REPORT_EVENT, userId, 0, event).sendToTarget(); + } + + @Override public void reportConfigurationChange(Configuration config, int userId) { if (config == null) { Slog.w(TAG, "Configuration event reported with a null config"); diff --git a/services/usage/java/com/android/server/usage/UserUsageStatsService.java b/services/usage/java/com/android/server/usage/UserUsageStatsService.java index 6596781..75fa030 100644 --- a/services/usage/java/com/android/server/usage/UserUsageStatsService.java +++ b/services/usage/java/com/android/server/usage/UserUsageStatsService.java @@ -570,6 +570,8 @@ class UserUsageStatsService { return "CONTINUE_PREVIOUS_DAY"; case UsageEvents.Event.CONFIGURATION_CHANGE: return "CONFIGURATION_CHANGE"; + case UsageEvents.Event.INTERACTION: + return "INTERACTION"; default: return "UNKNOWN"; } |