diff options
author | Adam Lesinski <adamlesinski@google.com> | 2015-06-10 15:33:45 -0700 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2015-06-11 22:01:45 +0000 |
commit | c8e8729244d75584ce71a74d29c452fe538a22c5 (patch) | |
tree | 11388496fdf1aef923b10b70f26c4e11f7a2def2 /services/usage/java | |
parent | 3d53a26d1a8471f4709b528686601381fd7e6da4 (diff) | |
download | frameworks_base-c8e8729244d75584ce71a74d29c452fe538a22c5.zip frameworks_base-c8e8729244d75584ce71a74d29c452fe538a22c5.tar.gz frameworks_base-c8e8729244d75584ce71a74d29c452fe538a22c5.tar.bz2 |
UsageStats: Change INTERACTION to SYSTEM_INTERACTION
SYSTEM_INTERACTION events are signals to the system for a package's
implicit actions (service bound, etc).
These should not affect the API visible stats like lastTimeUsed, etc.
USER_INTERACTION is for user initiated actions (notification interaction, etc).
Bug:21761781
Change-Id: I4585cf35fbb158612a3c737710108bec34e89183
Diffstat (limited to 'services/usage/java')
4 files changed, 40 insertions, 20 deletions
diff --git a/services/usage/java/com/android/server/usage/IntervalStats.java b/services/usage/java/com/android/server/usage/IntervalStats.java index a615675..1aa2978 100644 --- a/services/usage/java/com/android/server/usage/IntervalStats.java +++ b/services/usage/java/com/android/server/usage/IntervalStats.java @@ -110,7 +110,10 @@ class IntervalStats { usageStats.mLastEvent = eventType; } - usageStats.mLastTimeUsed = timeStamp; + if (eventType != UsageEvents.Event.SYSTEM_INTERACTION) { + usageStats.mLastTimeUsed = timeStamp; + } + usageStats.mLastTimeSystemUsed = timeStamp; usageStats.mEndTimeStamp = timeStamp; if (eventType == UsageEvents.Event.MOVE_TO_FOREGROUND) { @@ -131,9 +134,9 @@ class IntervalStats { usageStats.mBeginIdleTime = timeStamp; } - void updateLastUsedTime(String packageName, long lastUsedTime) { + void updateSystemLastUsedTime(String packageName, long lastUsedTime) { UsageStats usageStats = getOrCreateUsageStats(packageName); - usageStats.mLastTimeUsed = lastUsedTime; + usageStats.mLastTimeSystemUsed = lastUsedTime; } void updateConfigurationStats(Configuration config, long timeStamp) { diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java index 633aee8..7a34757 100644 --- a/services/usage/java/com/android/server/usage/UsageStatsService.java +++ b/services/usage/java/com/android/server/usage/UsageStatsService.java @@ -60,7 +60,6 @@ import android.provider.Settings; import android.telephony.TelephonyManager; import android.util.ArraySet; import android.util.AtomicFile; -import android.util.Log; import android.util.Slog; import android.util.SparseArray; import android.view.Display; @@ -543,14 +542,15 @@ public class UsageStatsService extends SystemService implements final UserUsageStatsService service = getUserDataAndInitializeIfNeededLocked(userId, timeNow); final long beginIdleTime = service.getBeginIdleTime(event.mPackage); - final long lastUsedTime = service.getLastUsedTime(event.mPackage); + final long lastUsedTime = service.getSystemLastUsedTime(event.mPackage); final boolean previouslyIdle = hasPassedIdleTimeoutLocked(beginIdleTime, lastUsedTime, screenOnTime, timeNow); service.reportEvent(event, getScreenOnTimeLocked(timeNow)); // Inform listeners if necessary if ((event.mEventType == Event.MOVE_TO_FOREGROUND || event.mEventType == Event.MOVE_TO_BACKGROUND - || event.mEventType == Event.INTERACTION)) { + || event.mEventType == Event.SYSTEM_INTERACTION + || event.mEventType == Event.USER_INTERACTION)) { if (previouslyIdle) { // Slog.d(TAG, "Informing listeners of out-of-idle " + event.mPackage); mHandler.sendMessage(mHandler.obtainMessage(MSG_INFORM_LISTENERS, userId, @@ -575,11 +575,11 @@ public class UsageStatsService extends SystemService implements final UserUsageStatsService service = getUserDataAndInitializeIfNeededLocked(userId, timeNow); final long beginIdleTime = service.getBeginIdleTime(packageName); - final long lastUsedTime = service.getLastUsedTime(packageName); + final long lastUsedTime = service.getSystemLastUsedTime(packageName); final boolean previouslyIdle = hasPassedIdleTimeoutLocked(beginIdleTime, lastUsedTime, screenOnTime, timeNow); service.setBeginIdleTime(packageName, deviceUsageTime); - service.setLastUsedTime(packageName, + service.setSystemLastUsedTime(packageName, timeNow - (idle ? DEFAULT_WALLCLOCK_APP_IDLE_THRESHOLD_MILLIS : 0) - 5000); // Inform listeners if necessary if (previouslyIdle != idle) { @@ -666,7 +666,7 @@ public class UsageStatsService extends SystemService implements final UserUsageStatsService service = getUserDataAndInitializeIfNeededLocked(userId, timeNow); long beginIdleTime = service.getBeginIdleTime(packageName); - long lastUsedTime = service.getLastUsedTime(packageName); + long lastUsedTime = service.getSystemLastUsedTime(packageName); return hasPassedIdleTimeoutLocked(beginIdleTime, lastUsedTime, screenOnTime, timeNow); } } diff --git a/services/usage/java/com/android/server/usage/UsageStatsXmlV1.java b/services/usage/java/com/android/server/usage/UsageStatsXmlV1.java index 0111201..f2ca3a4 100644 --- a/services/usage/java/com/android/server/usage/UsageStatsXmlV1.java +++ b/services/usage/java/com/android/server/usage/UsageStatsXmlV1.java @@ -55,6 +55,7 @@ final class UsageStatsXmlV1 { // Time attributes stored as an offset of the beginTime. private static final String LAST_TIME_ACTIVE_ATTR = "lastTimeActive"; + private static final String LAST_TIME_ACTIVE_SYSTEM_ATTR = "lastTimeActiveSystem"; private static final String BEGIN_IDLE_TIME_ATTR = "beginIdleTime"; private static final String END_TIME_ATTR = "endTime"; private static final String TIME_ATTR = "time"; @@ -71,6 +72,16 @@ final class UsageStatsXmlV1 { // Apply the offset to the beginTime to find the absolute time. stats.mLastTimeUsed = statsOut.beginTime + XmlUtils.readLongAttribute( parser, LAST_TIME_ACTIVE_ATTR); + + final String lastTimeUsedSystem = parser.getAttributeValue(null, + LAST_TIME_ACTIVE_SYSTEM_ATTR); + if (TextUtils.isEmpty(lastTimeUsedSystem)) { + // If the field isn't present, use the old one. + stats.mLastTimeSystemUsed = stats.mLastTimeUsed; + } else { + stats.mLastTimeSystemUsed = statsOut.beginTime + Long.parseLong(lastTimeUsedSystem); + } + final String beginIdleTime = parser.getAttributeValue(null, BEGIN_IDLE_TIME_ATTR); if (!TextUtils.isEmpty(beginIdleTime)) { stats.mBeginIdleTime = Long.parseLong(beginIdleTime); @@ -130,6 +141,8 @@ final class UsageStatsXmlV1 { // Write the time offset. XmlUtils.writeLongAttribute(xml, LAST_TIME_ACTIVE_ATTR, usageStats.mLastTimeUsed - stats.beginTime); + XmlUtils.writeLongAttribute(xml, LAST_TIME_ACTIVE_SYSTEM_ATTR, + usageStats.mLastTimeSystemUsed - stats.beginTime); XmlUtils.writeStringAttribute(xml, PACKAGE_ATTR, usageStats.mPackageName); XmlUtils.writeLongAttribute(xml, TOTAL_TIME_ACTIVE_ATTR, usageStats.mTotalTimeInForeground); diff --git a/services/usage/java/com/android/server/usage/UserUsageStatsService.java b/services/usage/java/com/android/server/usage/UserUsageStatsService.java index 7c00dae..b07b815 100644 --- a/services/usage/java/com/android/server/usage/UserUsageStatsService.java +++ b/services/usage/java/com/android/server/usage/UserUsageStatsService.java @@ -157,7 +157,7 @@ class UserUsageStatsService { if (pi.applicationInfo != null && (firstUpdate || pi.applicationInfo.isSystemApp()) && getBeginIdleTime(packageName) == -1) { for (IntervalStats stats : mCurrentStats) { - stats.update(packageName, currentTimeMillis, Event.INTERACTION); + stats.update(packageName, currentTimeMillis, Event.SYSTEM_INTERACTION); stats.updateBeginIdleTime(packageName, deviceUsageTime); mStatsChanged = true; } @@ -199,7 +199,7 @@ class UserUsageStatsService { if (currentDailyStats.events == null) { currentDailyStats.events = new TimeSparseArray<>(); } - if (event.mEventType != UsageEvents.Event.INTERACTION) { + if (event.mEventType != UsageEvents.Event.SYSTEM_INTERACTION) { currentDailyStats.events.put(event.mTimeStamp, event); } @@ -226,9 +226,9 @@ class UserUsageStatsService { notifyStatsChanged(); } - void setLastUsedTime(String packageName, long lastUsedTime) { + void setSystemLastUsedTime(String packageName, long lastUsedTime) { for (IntervalStats stats : mCurrentStats) { - stats.updateLastUsedTime(packageName, lastUsedTime); + stats.updateSystemLastUsedTime(packageName, lastUsedTime); } notifyStatsChanged(); } @@ -397,13 +397,13 @@ class UserUsageStatsService { } } - long getLastUsedTime(String packageName) { + long getSystemLastUsedTime(String packageName) { final IntervalStats yearly = mCurrentStats[UsageStatsManager.INTERVAL_YEARLY]; UsageStats packageUsage; if ((packageUsage = yearly.packageStats.get(packageName)) == null) { return -1; } else { - return packageUsage.getLastTimeUsed(); + return packageUsage.getLastTimeSystemUsed(); } } @@ -586,8 +586,11 @@ class UserUsageStatsService { for (int i = 0; i < pkgCount; i++) { final UsageStats usageStats = pkgStats.valueAt(i); pw.printPair("package", usageStats.mPackageName); - pw.printPair("totalTime", formatElapsedTime(usageStats.mTotalTimeInForeground, prettyDates)); + pw.printPair("totalTime", + formatElapsedTime(usageStats.mTotalTimeInForeground, prettyDates)); pw.printPair("lastTime", formatDateTime(usageStats.mLastTimeUsed, prettyDates)); + pw.printPair("lastTimeSystem", + formatDateTime(usageStats.mLastTimeSystemUsed, prettyDates)); pw.printPair("inactiveTime", formatElapsedTime(screenOnTime - usageStats.mBeginIdleTime, prettyDates)); pw.println(); @@ -596,8 +599,7 @@ class UserUsageStatsService { pw.println("configurations"); pw.increaseIndent(); - final ArrayMap<Configuration, ConfigurationStats> configStats = - stats.configurations; + final ArrayMap<Configuration, ConfigurationStats> configStats = stats.configurations; final int configCount = configStats.size(); for (int i = 0; i < configCount; i++) { final ConfigurationStats config = configStats.valueAt(i); @@ -659,8 +661,10 @@ class UserUsageStatsService { return "CONTINUE_PREVIOUS_DAY"; case UsageEvents.Event.CONFIGURATION_CHANGE: return "CONFIGURATION_CHANGE"; - case UsageEvents.Event.INTERACTION: - return "INTERACTION"; + case UsageEvents.Event.SYSTEM_INTERACTION: + return "SYSTEM_INTERACTION"; + case UsageEvents.Event.USER_INTERACTION: + return "USER_INTERACTION"; default: return "UNKNOWN"; } |