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

Commit bb4922a4 authored by Zhen Zhang's avatar Zhen Zhang Committed by Automerger Merge Worker
Browse files

Merge "Create component used metrics in UsageStats" into sc-dev am: abb8a88e

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13819021

Change-Id: I7534778ed762b81e80b7fd90dd50bf2c225258c9
parents 0c691fee abb8a88e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1793,6 +1793,7 @@ package android.app.usage {
  public final class UsageStats implements android.os.Parcelable {
    method public int getAppLaunchCount();
    method public long getLastTimeComponentUsed();
  }
  public final class UsageStatsManager {
+25 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.app.usage.UsageEvents.Event.ACTIVITY_DESTROYED;
import static android.app.usage.UsageEvents.Event.ACTIVITY_PAUSED;
import static android.app.usage.UsageEvents.Event.ACTIVITY_RESUMED;
import static android.app.usage.UsageEvents.Event.ACTIVITY_STOPPED;
import static android.app.usage.UsageEvents.Event.APP_COMPONENT_USED;
import static android.app.usage.UsageEvents.Event.CONTINUING_FOREGROUND_SERVICE;
import static android.app.usage.UsageEvents.Event.DEVICE_SHUTDOWN;
import static android.app.usage.UsageEvents.Event.END_OF_DAY;
@@ -108,6 +109,13 @@ public final class UsageStats implements Parcelable {
     */
    public long mTotalTimeForegroundServiceUsed;

    /**
     * Last time this package's component is used, measured in milliseconds since the epoch.
     * See {@link UsageEvents.Event#APP_COMPONENT_USED}
     * @hide
     */
    public long mLastTimeComponentUsed;

    /**
     * {@hide}
     */
@@ -166,6 +174,7 @@ public final class UsageStats implements Parcelable {
        mEndTimeStamp = stats.mEndTimeStamp;
        mLastTimeUsed = stats.mLastTimeUsed;
        mLastTimeVisible = stats.mLastTimeVisible;
        mLastTimeComponentUsed = stats.mLastTimeComponentUsed;
        mLastTimeForegroundServiceUsed = stats.mLastTimeForegroundServiceUsed;
        mTotalTimeInForeground = stats.mTotalTimeInForeground;
        mTotalTimeVisible = stats.mTotalTimeVisible;
@@ -264,6 +273,16 @@ public final class UsageStats implements Parcelable {
        return mTotalTimeForegroundServiceUsed;
    }

    /**
     * Get the last time this package's component was used, measured in milliseconds since the
     * epoch.
     * @hide
     */
    @SystemApi
    public long getLastTimeComponentUsed() {
        return mLastTimeComponentUsed;
    }

    /**
     * Returns the number of times the app was launched as an activity from outside of the app.
     * Excludes intra-app activity transitions.
@@ -323,6 +342,7 @@ public final class UsageStats implements Parcelable {
            mergeEventMap(mForegroundServices, right.mForegroundServices);
            mLastTimeUsed = Math.max(mLastTimeUsed, right.mLastTimeUsed);
            mLastTimeVisible = Math.max(mLastTimeVisible, right.mLastTimeVisible);
            mLastTimeComponentUsed = Math.max(mLastTimeComponentUsed, right.mLastTimeComponentUsed);
            mLastTimeForegroundServiceUsed = Math.max(mLastTimeForegroundServiceUsed,
                    right.mLastTimeForegroundServiceUsed);
        }
@@ -598,6 +618,9 @@ public final class UsageStats implements Parcelable {
                    mLastTimeVisible = timeStamp;
                }
                break;
            case APP_COMPONENT_USED:
                mLastTimeComponentUsed = timeStamp;
                break;
            default:
                break;
        }
@@ -620,6 +643,7 @@ public final class UsageStats implements Parcelable {
        dest.writeLong(mEndTimeStamp);
        dest.writeLong(mLastTimeUsed);
        dest.writeLong(mLastTimeVisible);
        dest.writeLong(mLastTimeComponentUsed);
        dest.writeLong(mLastTimeForegroundServiceUsed);
        dest.writeLong(mTotalTimeInForeground);
        dest.writeLong(mTotalTimeVisible);
@@ -674,6 +698,7 @@ public final class UsageStats implements Parcelable {
            stats.mEndTimeStamp = in.readLong();
            stats.mLastTimeUsed = in.readLong();
            stats.mLastTimeVisible = in.readLong();
            stats.mLastTimeComponentUsed = in.readLong();
            stats.mLastTimeForegroundServiceUsed = in.readLong();
            stats.mTotalTimeInForeground = in.readLong();
            stats.mTotalTimeVisible = in.readLong();
+2 −0
Original line number Diff line number Diff line
@@ -57,6 +57,8 @@ message IntervalStatsProto {
    // Time attributes stored as an offset of the IntervalStats's beginTime.
    optional int64 last_time_visible_ms = 10;
    optional int64 total_time_visible_ms = 11;
    // Time attributes stored as an offset of the IntervalStats's beginTime.
    optional int64 last_time_component_used_ms = 12;
  }

  // Stores the relevant information an IntervalStats will have about a Configuration
+1 −0
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ message UsageStatsObfuscatedProto {
  optional int64 total_time_service_used_ms = 9;
  optional int64 last_time_visible_ms = 10;
  optional int64 total_time_visible_ms = 11;
  optional int64 last_time_component_used_ms = 12;
}

/**
+2 −1
Original line number Diff line number Diff line
@@ -46,7 +46,8 @@ public class UsageStatsPersistenceTest {
    private static final String[] USAGESTATS_PERSISTED_FIELDS = {"mBeginTimeStamp", "mEndTimeStamp",
            "mPackageName", "mPackageToken", "mLastEvent", "mAppLaunchCount", "mChooserCounts",
            "mLastTimeUsed", "mTotalTimeInForeground", "mLastTimeForegroundServiceUsed",
            "mTotalTimeForegroundServiceUsed", "mLastTimeVisible", "mTotalTimeVisible"};
            "mTotalTimeForegroundServiceUsed", "mLastTimeVisible", "mTotalTimeVisible",
            "mLastTimeComponentUsed"};
    // All fields in this list are defined in UsageStats but not persisted
    private static final String[] USAGESTATS_IGNORED_FIELDS = {"CREATOR", "mActivities",
            "mForegroundServices", "mLaunchCount", "mChooserCountsObfuscated"};
Loading