OSDN Git Service

DO NOT MERGE ANYWHERE: Don't change screen on time on time changes
[android-x86/frameworks-base.git] / core / java / android / app / usage / UsageStats.java
index abfc435..a88aa31 100644 (file)
@@ -41,11 +41,26 @@ public final class UsageStats implements Parcelable {
     public long mEndTimeStamp;
 
     /**
+     * Last time used by the user with an explicit action (notification, activity launch).
      * {@hide}
      */
     public long mLastTimeUsed;
 
     /**
+     * The last time the package was used via implicit, non-user initiated actions (service
+     * was bound, etc).
+     * {@hide}
+     */
+    public long mLastTimeSystemUsed;
+
+    /**
+     * Last time the package was used and the beginning of the idle countdown.
+     * This uses a different timebase that is about how much the device has been in use in general.
+     * {@hide}
+     */
+    public long mBeginIdleTime;
+
+    /**
      * {@hide}
      */
     public long mTotalTimeInForeground;
@@ -74,6 +89,8 @@ public final class UsageStats implements Parcelable {
         mTotalTimeInForeground = stats.mTotalTimeInForeground;
         mLaunchCount = stats.mLaunchCount;
         mLastEvent = stats.mLastEvent;
+        mBeginIdleTime = stats.mBeginIdleTime;
+        mLastTimeSystemUsed = stats.mLastTimeSystemUsed;
     }
 
     public String getPackageName() {
@@ -110,6 +127,25 @@ public final class UsageStats implements Parcelable {
     }
 
     /**
+     * @hide
+     * Get the last time this package was used by the system (not the user). This can be different
+     * from {@link #getLastTimeUsed()} when the system binds to one of this package's services.
+     * See {@link System#currentTimeMillis()}.
+     */
+    public long getLastTimeSystemUsed() {
+        return mLastTimeSystemUsed;
+    }
+
+    /**
+     * @hide
+     * Get the last time this package was active, measured in milliseconds. This timestamp
+     * uses a timebase that represents how much the device was used and not wallclock time.
+     */
+    public long getBeginIdleTime() {
+        return mBeginIdleTime;
+    }
+
+    /**
      * Get the total time this package spent in the foreground, measured in milliseconds.
      */
     public long getTotalTimeInForeground() {
@@ -129,12 +165,18 @@ public final class UsageStats implements Parcelable {
                     mPackageName + "' with UsageStats for package '" + right.mPackageName + "'.");
         }
 
-        if (right.mEndTimeStamp > mEndTimeStamp) {
+        if (right.mBeginTimeStamp > mBeginTimeStamp) {
+            // The incoming UsageStat begins after this one, so use its last time used fields
+            // as the source of truth.
+            // We use the mBeginTimeStamp due to a bug where UsageStats files can overlap with
+            // regards to their mEndTimeStamp.
             mLastEvent = right.mLastEvent;
-            mEndTimeStamp = right.mEndTimeStamp;
             mLastTimeUsed = right.mLastTimeUsed;
+            mBeginIdleTime = right.mBeginIdleTime;
+            mLastTimeSystemUsed = right.mLastTimeSystemUsed;
         }
         mBeginTimeStamp = Math.min(mBeginTimeStamp, right.mBeginTimeStamp);
+        mEndTimeStamp = Math.max(mEndTimeStamp, right.mEndTimeStamp);
         mTotalTimeInForeground += right.mTotalTimeInForeground;
         mLaunchCount += right.mLaunchCount;
     }
@@ -153,6 +195,8 @@ public final class UsageStats implements Parcelable {
         dest.writeLong(mTotalTimeInForeground);
         dest.writeInt(mLaunchCount);
         dest.writeInt(mLastEvent);
+        dest.writeLong(mBeginIdleTime);
+        dest.writeLong(mLastTimeSystemUsed);
     }
 
     public static final Creator<UsageStats> CREATOR = new Creator<UsageStats>() {
@@ -166,6 +210,8 @@ public final class UsageStats implements Parcelable {
             stats.mTotalTimeInForeground = in.readLong();
             stats.mLaunchCount = in.readInt();
             stats.mLastEvent = in.readInt();
+            stats.mBeginIdleTime = in.readLong();
+            stats.mLastTimeSystemUsed = in.readLong();
             return stats;
         }