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

Commit fd05b019 authored by Kweku Adams's avatar Kweku Adams
Browse files

Add CountQuotaTracker.

This adds a utility class that can track instantaneous app behavior and
manages count quotas for the owning system. A system service just needs to
create a tracker, set the limits, and call the relevant APIs to determine
what to do for each behavior. JobScheduler will use it to prevent apps from
calling JobScheduler.schedule() too often.

Bug: 135764360
Test: atest CountQuotaTrackerTest
Change-Id: Iacd4286bd7f4ab3fc428d8e2ec573671b287f225
parent 2a4b15a3
Loading
Loading
Loading
Loading
+802 −0

File added.

Preview size limit exceeded, changes collapsed.

+3 −20
Original line number Diff line number Diff line
@@ -112,37 +112,20 @@ class UptcMap<T> {
        return data.get(tag);
    }

    /**
     * Returns the index for which {@link #getUserIdAtIndex(int)} would return the specified userId,
     * or a negative number if the specified userId is not mapped.
     */
    public int indexOfUserId(int userId) {
        return mData.indexOfKey(userId);
    }

    /**
     * Returns the index for which {@link #getPackageNameAtIndex(int, int)} would return the
     * specified userId, or a negative number if the specified userId and packageName are not mapped
     * together.
     */
    public int indexOfUserIdAndPackage(int userId, @NonNull String packageName) {
        return mData.indexOfKey(userId, packageName);
    }

    /** Returns the userId at the given index. */
    public int getUserIdAtIndex(int index) {
    private int getUserIdAtIndex(int index) {
        return mData.keyAt(index);
    }

    /** Returns the package name at the given index. */
    @NonNull
    public String getPackageNameAtIndex(int userIndex, int packageIndex) {
    private String getPackageNameAtIndex(int userIndex, int packageIndex) {
        return mData.keyAt(userIndex, packageIndex);
    }

    /** Returns the tag at the given index. */
    @NonNull
    public String getTagAtIndex(int userIndex, int packageIndex, int tagIndex) {
    private String getTagAtIndex(int userIndex, int packageIndex, int tagIndex) {
        // This structure never inserts a null ArrayMap, so if the indices are valid, valueAt()
        // won't return null.
        return mData.valueAt(userIndex, packageIndex).keyAt(tagIndex);
+848 −0

File added.

Preview size limit exceeded, changes collapsed.