Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 978a1ed5 authored by Adam Lesinski's avatar Adam Lesinski
Browse files

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
parent 5414d155
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5773,6 +5773,7 @@ package android.app.usage {
    method public java.lang.String getPackageName();
    method public long getTimeStamp();
    field public static final int CONFIGURATION_CHANGE = 5; // 0x5
    field public static final int INTERACTION = 6; // 0x6
    field public static final int MOVE_TO_BACKGROUND = 2; // 0x2
    field public static final int MOVE_TO_FOREGROUND = 1; // 0x1
    field public static final int NONE = 0; // 0x0
+1 −0
Original line number Diff line number Diff line
@@ -5952,6 +5952,7 @@ package android.app.usage {
    method public java.lang.String getPackageName();
    method public long getTimeStamp();
    field public static final int CONFIGURATION_CHANGE = 5; // 0x5
    field public static final int INTERACTION = 6; // 0x6
    field public static final int MOVE_TO_BACKGROUND = 2; // 0x2
    field public static final int MOVE_TO_FOREGROUND = 1; // 0x1
    field public static final int NONE = 0; // 0x0
+5 −0
Original line number Diff line number Diff line
@@ -67,6 +67,11 @@ public final class UsageEvents implements Parcelable {
         */
        public static final int CONFIGURATION_CHANGE = 5;

        /**
         * An event type denoting that a package was interacted with in some way.
         */
        public static final int INTERACTION = 6;

        /**
         * {@hide}
         */
+10 −0
Original line number Diff line number Diff line
@@ -36,6 +36,16 @@ public abstract class UsageStatsManagerInternal {
     */
    public abstract void reportEvent(ComponentName component, int userId, int eventType);

    /**
     * Reports an event to the UsageStatsManager.
     *
     * @param packageName The package for which this event occurred.
     * @param userId The user id to which the component belongs to.
     * @param eventType The event that occurred. Valid values can be found at
     * {@link UsageEvents}
     */
    public abstract void reportEvent(String packageName, int userId, int eventType);

    /**
     * Reports a configuration change to the UsageStatsManager.
     *
+16 −1
Original line number Diff line number Diff line
@@ -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;
            }
        }

        if (isStatefulEvent(eventType)) {
            usageStats.mLastEvent = eventType;
        }

        usageStats.mLastTimeUsed = timeStamp;
        usageStats.mEndTimeStamp = timeStamp;

Loading