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

Commit 9b23e4f4 authored by Varun Shah's avatar Varun Shah Committed by Android (Google) Code Review
Browse files

Merge "Removed AppUsageLimit#isGroupLimit API."

parents 25526010 9c6f72ba
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -287,19 +287,14 @@ public abstract class UsageStatsManagerInternal {

    /** A class which is used to share the usage limit data for an app or a group of apps. */
    public static class AppUsageLimitData {
        private final boolean mGroupLimit;
        private final long mTotalUsageLimit;
        private final long mUsageRemaining;

        public AppUsageLimitData(boolean groupLimit, long totalUsageLimit, long usageRemaining) {
            this.mGroupLimit = groupLimit;
        public AppUsageLimitData(long totalUsageLimit, long usageRemaining) {
            this.mTotalUsageLimit = totalUsageLimit;
            this.mUsageRemaining = usageRemaining;
        }

        public boolean isGroupLimit() {
            return mGroupLimit;
        }
        public long getTotalUsageLimit() {
            return mTotalUsageLimit;
        }
+4 −18
Original line number Diff line number Diff line
@@ -1658,34 +1658,22 @@ public class LauncherApps {
     * A class that encapsulates information about the usage limit set for an app or
     * a group of apps.
     *
     * <p>The launcher can query specifics about the usage limit such as if it is a group limit,
     * how much usage time the limit has, and how much of the total usage time is remaining
     * via the APIs available in this class.
     * <p>The launcher can query specifics about the usage limit such as how much usage time
     * the limit has and how much of the total usage time is remaining via the APIs available
     * in this class.
     *
     * @see #getAppUsageLimit(String, UserHandle)
     */
    public static final class AppUsageLimit implements Parcelable {
        private final boolean mGroupLimit;
        private final long mTotalUsageLimit;
        private final long mUsageRemaining;

        /** @hide */
        public AppUsageLimit(boolean groupLimit, long totalUsageLimit, long usageRemaining) {
            this.mGroupLimit = groupLimit;
        public AppUsageLimit(long totalUsageLimit, long usageRemaining) {
            this.mTotalUsageLimit = totalUsageLimit;
            this.mUsageRemaining = usageRemaining;
        }

        /**
         * Returns whether this limit refers to a group of apps.
         *
         * @return {@code TRUE} if the limit refers to a group of apps, {@code FALSE} otherwise.
         * @hide
         */
        public boolean isGroupLimit() {
            return mGroupLimit;
        }

        /**
         * Returns the total usage limit in milliseconds set for an app or a group of apps.
         *
@@ -1706,7 +1694,6 @@ public class LauncherApps {
        }

        private AppUsageLimit(Parcel source) {
            mGroupLimit = source.readBoolean();
            mTotalUsageLimit = source.readLong();
            mUsageRemaining = source.readLong();
        }
@@ -1730,7 +1717,6 @@ public class LauncherApps {

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeBoolean(mGroupLimit);
            dest.writeLong(mTotalUsageLimit);
            dest.writeLong(mUsageRemaining);
        }
+1 −1
Original line number Diff line number Diff line
@@ -696,7 +696,7 @@ public class LauncherAppsService extends SystemService {
                return null;
            }
            return new LauncherApps.AppUsageLimit(
                    data.isGroupLimit(), data.getTotalUsageLimit(), data.getUsageRemaining());
                    data.getTotalUsageLimit(), data.getUsageRemaining());
        }

        private void ensureShortcutPermission(@NonNull String callingPackage) {
+0 −20
Original line number Diff line number Diff line
@@ -964,26 +964,6 @@ public class AppTimeLimitControllerTests {
        assertFalse(hasAppUsageObserver(UID, OBS_ID1));
    }

    /** Verify app usage limit observer added correctly reports it being a group limit */
    @Test
    public void testAppUsageLimitObserver_IsGroupLimit() {
        addAppUsageLimitObserver(OBS_ID1, GROUP1, TIME_30_MIN);
        AppTimeLimitController.AppUsageLimitGroup group = getAppUsageLimitObserver(UID, OBS_ID1);
        assertNotNull("Observer wasn't added", group);
        assertTrue("Observer didn't correctly report being a group limit",
                group.isGroupLimit());
    }

    /** Verify app usage limit observer added correctly reports it being not a group limit */
    @Test
    public void testAppUsageLimitObserver_IsNotGroupLimit() {
        addAppUsageLimitObserver(OBS_ID1, new String[]{PKG_PROD}, TIME_30_MIN);
        AppTimeLimitController.AppUsageLimitGroup group = getAppUsageLimitObserver(UID, OBS_ID1);
        assertNotNull("Observer wasn't added", group);
        assertFalse("Observer didn't correctly report not being a group limit",
                group.isGroupLimit());
    }

    /** Verify app usage limit observer added correctly reports its total usage limit */
    @Test
    public void testAppUsageLimitObserver_GetTotalUsageLimit() {
+1 −17
Original line number Diff line number Diff line
@@ -510,12 +510,9 @@ public class AppTimeLimitController {
    }

    class AppUsageLimitGroup extends UsageGroup {
        private boolean mGroupLimit;

        public AppUsageLimitGroup(UserData user, ObserverAppData observerApp, int observerId,
                String[] observed, long timeLimitMs, PendingIntent limitReachedCallback) {
            super(user, observerApp, observerId, observed, timeLimitMs, limitReachedCallback);
            mGroupLimit = observed.length > 1;
        }

        @Override
@@ -528,11 +525,6 @@ public class AppTimeLimitController {
            }
        }

        @GuardedBy("mLock")
        boolean isGroupLimit() {
            return mGroupLimit;
        }

        @GuardedBy("mLock")
        long getTotaUsageLimit() {
            return mTimeLimitMs;
@@ -547,14 +539,6 @@ public class AppTimeLimitController {
                return mTimeLimitMs - mUsageTimeMs;
            }
        }

        @Override
        @GuardedBy("mLock")
        void dump(PrintWriter pw) {
            super.dump(pw);
            pw.print(" groupLimit=");
            pw.print(mGroupLimit);
        }
    }


@@ -692,7 +676,7 @@ public class AppTimeLimitController {
                    smallestGroup = otherGroup;
                }
            }
            return new UsageStatsManagerInternal.AppUsageLimitData(smallestGroup.isGroupLimit(),
            return new UsageStatsManagerInternal.AppUsageLimitData(
                    smallestGroup.getTotaUsageLimit(), smallestGroup.getUsageRemaining());
        }
    }