FileDocCategorySizeDatePackage
UsageStats.javaAPI DocAndroid 5.1 API5041Thu Mar 12 22:22:10 GMT 2015android.app.usage

UsageStats

public final class UsageStats extends Object implements android.os.Parcelable
Contains usage statistics for an app package for a specific time range.

Fields Summary
public String
mPackageName
{@hide}
public long
mBeginTimeStamp
{@hide}
public long
mEndTimeStamp
{@hide}
public long
mLastTimeUsed
{@hide}
public long
mTotalTimeInForeground
{@hide}
public int
mLaunchCount
{@hide}
public int
mLastEvent
{@hide}
public static final Creator
CREATOR
Constructors Summary
public UsageStats()
{@hide}

    
public UsageStats(UsageStats stats)

        mPackageName = stats.mPackageName;
        mBeginTimeStamp = stats.mBeginTimeStamp;
        mEndTimeStamp = stats.mEndTimeStamp;
        mLastTimeUsed = stats.mLastTimeUsed;
        mTotalTimeInForeground = stats.mTotalTimeInForeground;
        mLaunchCount = stats.mLaunchCount;
        mLastEvent = stats.mLastEvent;
    
Methods Summary
public voidadd(android.app.usage.UsageStats right)
Add the statistics from the right {@link UsageStats} to the left. The package name for both {@link UsageStats} objects must be the same.

param
right The {@link UsageStats} object to merge into this one.
throws
java.lang.IllegalArgumentException if the package names of the two {@link UsageStats} objects are different.

        if (!mPackageName.equals(right.mPackageName)) {
            throw new IllegalArgumentException("Can't merge UsageStats for package '" +
                    mPackageName + "' with UsageStats for package '" + right.mPackageName + "'.");
        }

        if (right.mEndTimeStamp > mEndTimeStamp) {
            mLastEvent = right.mLastEvent;
            mEndTimeStamp = right.mEndTimeStamp;
            mLastTimeUsed = right.mLastTimeUsed;
        }
        mBeginTimeStamp = Math.min(mBeginTimeStamp, right.mBeginTimeStamp);
        mTotalTimeInForeground += right.mTotalTimeInForeground;
        mLaunchCount += right.mLaunchCount;
    
public intdescribeContents()

        return 0;
    
public longgetFirstTimeStamp()
Get the beginning of the time range this {@link android.app.usage.UsageStats} represents, measured in milliseconds since the epoch.

See {@link System#currentTimeMillis()}.

        return mBeginTimeStamp;
    
public longgetLastTimeStamp()
Get the end of the time range this {@link android.app.usage.UsageStats} represents, measured in milliseconds since the epoch.

See {@link System#currentTimeMillis()}.

        return mEndTimeStamp;
    
public longgetLastTimeUsed()
Get the last time this package was used, measured in milliseconds since the epoch.

See {@link System#currentTimeMillis()}.

        return mLastTimeUsed;
    
public java.lang.StringgetPackageName()

        return mPackageName;
    
public longgetTotalTimeInForeground()
Get the total time this package spent in the foreground, measured in milliseconds.

        return mTotalTimeInForeground;
    
public voidwriteToParcel(android.os.Parcel dest, int flags)

        dest.writeString(mPackageName);
        dest.writeLong(mBeginTimeStamp);
        dest.writeLong(mEndTimeStamp);
        dest.writeLong(mLastTimeUsed);
        dest.writeLong(mTotalTimeInForeground);
        dest.writeInt(mLaunchCount);
        dest.writeInt(mLastEvent);