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

Commit 911456c7 authored by Adam Lesinski's avatar Adam Lesinski Committed by Android Git Automerger
Browse files

am 38daa3c5: Merge "Second iteration of the UsageStats API" into lmp-dev

* commit '38daa3c57a87a42bfbdce3d85535ff106fe6a8b4':
  Second iteration of the UsageStats API
parents 49049f62 81f6d857
Loading
Loading
Loading
Loading
+26 −25
Original line number Diff line number Diff line
@@ -5691,46 +5691,47 @@ package android.app.job {
package android.app.usage {
  public final class PackageUsageStats implements android.os.Parcelable {
  public final class UsageEvents implements android.os.Parcelable {
    method public int describeContents();
    method public long getLastTimeUsed();
    method public java.lang.String getPackageName();
    method public long getTotalTimeSpent();
    method public boolean getNextEvent(android.app.usage.UsageEvents.Event);
    method public boolean hasNextEvent();
    method public void resetToStart();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
  }
  public static final class UsageEvents.Event {
    ctor public UsageEvents.Event();
    method public android.content.ComponentName getComponent();
    method public int getEventType();
    method public long getTimeStamp();
    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
  }
  public final class UsageStats implements android.os.Parcelable {
    ctor public UsageStats(android.app.usage.UsageStats);
    method public void add(android.app.usage.UsageStats);
    method public int describeContents();
    method public long getFirstTimeStamp();
    method public long getLastTimeStamp();
    method public android.app.usage.PackageUsageStats getPackage(int);
    method public android.app.usage.PackageUsageStats getPackage(java.lang.String);
    method public int getPackageCount();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
  }
  public static class UsageStats.Event implements android.os.Parcelable {
    ctor public UsageStats.Event();
    method public int describeContents();
    method public long getLastTimeUsed();
    method public java.lang.String getPackageName();
    method public long getTotalTimeInForeground();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
    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
    field public int eventType;
    field public java.lang.String packageName;
    field public long timeStamp;
  }
  public final class UsageStatsManager {
    method public android.app.usage.UsageStats[] getDailyStatsSince(long);
    method public android.app.usage.UsageStats[] getMonthlyStatsSince(long);
    method public android.app.usage.UsageStats getRecentStatsSince(long);
    method public android.app.usage.UsageStats[] getWeeklyStatsSince(long);
    method public android.app.usage.UsageStats[] getYearlyStatsSince(long);
    method public android.util.ArrayMap<java.lang.String, android.app.usage.UsageStats> queryAndAggregateUsageStats(long, long);
    method public android.app.usage.UsageEvents queryEvents(long, long);
    method public java.util.List<android.app.usage.UsageStats> queryUsageStats(int, long, long);
    field public static final int INTERVAL_BEST = 4; // 0x4
    field public static final int INTERVAL_DAILY = 0; // 0x0
    field public static final int INTERVAL_MONTHLY = 2; // 0x2
    field public static final int INTERVAL_WEEKLY = 1; // 0x1
    field public static final int INTERVAL_YEARLY = 3; // 0x3
  }
}
+5 −4
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@

package android.app.usage;

import android.app.usage.UsageStats;
import android.content.ComponentName;
import android.app.usage.UsageEvents;
import android.content.pm.ParceledListSlice;

/**
 * System private API for talking with the UsageStatsManagerService.
@@ -25,6 +25,7 @@ import android.content.ComponentName;
 * {@hide}
 */
interface IUsageStatsManager {
    UsageStats[] getStatsSince(int bucketType, long time, String callingPackage);
    UsageStats.Event[] getEventsSince(long time, String callingPackage);
    ParceledListSlice queryUsageStats(int bucketType, long beginTime, long endTime,
            String callingPackage);
    UsageEvents queryEvents(long beginTime, long endTime, String callingPackage);
}
+0 −95
Original line number Diff line number Diff line
/**
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy
 * of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package android.app.usage;

import android.os.Parcel;
import android.os.Parcelable;

public final class PackageUsageStats implements Parcelable {

    /**
     * {@hide}
     */
    public String mPackageName;

    /**
     * {@hide}
     */
    public long mTotalTimeSpent;

    /**
     * {@hide}
     */
    public long mLastTimeUsed;

    /**
     * {@hide}
     */
    public int mLastEvent;

    PackageUsageStats() {
    }

    PackageUsageStats(PackageUsageStats stats) {
        mPackageName = stats.mPackageName;
        mTotalTimeSpent = stats.mTotalTimeSpent;
        mLastTimeUsed = stats.mLastTimeUsed;
        mLastEvent = stats.mLastEvent;
    }

    public long getTotalTimeSpent() {
        return mTotalTimeSpent;
    }

    public long getLastTimeUsed() {
        return mLastTimeUsed;
    }

    public String getPackageName() {
        return mPackageName;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mPackageName);
        dest.writeLong(mTotalTimeSpent);
        dest.writeLong(mLastTimeUsed);
        dest.writeInt(mLastEvent);
    }

    public static final Creator<PackageUsageStats> CREATOR = new Creator<PackageUsageStats>() {
        @Override
        public PackageUsageStats createFromParcel(Parcel in) {
            PackageUsageStats stats = new PackageUsageStats();
            stats.mPackageName = in.readString();
            stats.mTotalTimeSpent = in.readLong();
            stats.mLastTimeUsed = in.readLong();
            stats.mLastEvent = in.readInt();
            return stats;
        }

        @Override
        public PackageUsageStats[] newArray(int size) {
            return new PackageUsageStats[size];
        }
    };
}
+23 −3
Original line number Diff line number Diff line
@@ -39,16 +39,16 @@ public class TimeSparseArray<E> extends LongSparseArray<E> {
     * @param time The timestamp for which to search the array.
     * @return The index of the matched element, or -1 if no such match exists.
     */
    public int closestIndexAfter(long time) {
    public int closestIndexOnOrAfter(long time) {
        // This is essentially a binary search, except that if no match is found
        // the closest index is returned.
        final int size = size();
        int lo = 0;
        int hi = size;
        int hi = size - 1;
        int mid = -1;
        long key = -1;
        while (lo <= hi) {
            mid = (lo + hi) >>> 1;
            mid = lo + ((hi - lo) / 2);
            key = keyAt(mid);

            if (time > key) {
@@ -68,4 +68,24 @@ public class TimeSparseArray<E> extends LongSparseArray<E> {
            return -1;
        }
    }

    /**
     * Finds the index of the first element whose timestamp is less than or equal to
     * the given time.
     *
     * @param time The timestamp for which to search the array.
     * @return The index of the matched element, or -1 if no such match exists.
     */
    public int closestIndexOnOrBefore(long time) {
        final int index = closestIndexOnOrAfter(time);
        if (index < 0) {
            // Everything is larger, so we use the last element, or -1 if the list is empty.
            return size() - 1;
        }

        if (keyAt(index) == time) {
            return index;
        }
        return index - 1;
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -16,5 +16,4 @@

package android.app.usage;

parcelable UsageStats;
parcelable UsageStats.Event;
parcelable UsageEvents;
Loading