diff options
author | Adam Lesinski <adamlesinski@google.com> | 2015-03-02 11:37:24 -0800 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2015-03-02 12:54:14 -0800 |
commit | 978a1ed5aa2752cd36ff51df91d2d2d8be2171d9 (patch) | |
tree | 4c383bf6ee66fd90b721fc670bb24a2d94fd15bd /services | |
parent | 5414d155e5ce3147f9db1b2ec6fb2dcd6473e089 (diff) | |
download | frameworks_base-978a1ed5aa2752cd36ff51df91d2d2d8be2171d9.zip frameworks_base-978a1ed5aa2752cd36ff51df91d2d2d8be2171d9.tar.gz frameworks_base-978a1ed5aa2752cd36ff51df91d2d2d8be2171d9.tar.bz2 |
Add generic "INTERACTION" event type to UsageStatsManager
This will allow for updating a package's last time used
property for packages that are interacted in ways other than
launching their activities (interacting with notifications, etc.)
Change-Id: Ic6f9519f46fa04abd37ea6fc9475bcd9ea721003
Diffstat (limited to 'services')
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"; } |