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

Commit 06bf8246 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Idle timebase

Use screen on time as timebase for idling out apps
that have been inactive.

Store the time when an app was last active as an additional
package state in UsageStats. Compare it to screenOnTime to decide
if it's inactive.

Exclude device idle whitelist from apps that can go inactive.

Bug: 20066058

Change-Id: I709f9f31a9affa7ca6e1ae3e4c5729c5fb221669
parent a5b2684c
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -45,6 +45,13 @@ public final class UsageStats implements Parcelable {
     */
    public long mLastTimeUsed;

    /**
     * Last time the package was used and the beginning of the idle countdown.
     * This uses a different timebase that is about how much the device has been in use in general.
     * {@hide}
     */
    public long mBeginIdleTime;

    /**
     * {@hide}
     */
@@ -74,6 +81,7 @@ public final class UsageStats implements Parcelable {
        mTotalTimeInForeground = stats.mTotalTimeInForeground;
        mLaunchCount = stats.mLaunchCount;
        mLastEvent = stats.mLastEvent;
        mBeginIdleTime = stats.mBeginIdleTime;
    }

    public String getPackageName() {
@@ -109,6 +117,15 @@ public final class UsageStats implements Parcelable {
        return mLastTimeUsed;
    }

    /**
     * @hide
     * Get the last time this package was active, measured in milliseconds. This timestamp
     * uses a timebase that represents how much the device was used and not wallclock time.
     */
    public long getBeginIdleTime() {
        return mBeginIdleTime;
    }

    /**
     * Get the total time this package spent in the foreground, measured in milliseconds.
     */
@@ -133,6 +150,7 @@ public final class UsageStats implements Parcelable {
            mLastEvent = right.mLastEvent;
            mEndTimeStamp = right.mEndTimeStamp;
            mLastTimeUsed = right.mLastTimeUsed;
            mBeginIdleTime = right.mBeginIdleTime;
        }
        mBeginTimeStamp = Math.min(mBeginTimeStamp, right.mBeginTimeStamp);
        mTotalTimeInForeground += right.mTotalTimeInForeground;
@@ -153,6 +171,7 @@ public final class UsageStats implements Parcelable {
        dest.writeLong(mTotalTimeInForeground);
        dest.writeInt(mLaunchCount);
        dest.writeInt(mLastEvent);
        dest.writeLong(mBeginIdleTime);
    }

    public static final Creator<UsageStats> CREATOR = new Creator<UsageStats>() {
@@ -166,6 +185,7 @@ public final class UsageStats implements Parcelable {
            stats.mTotalTimeInForeground = in.readLong();
            stats.mLaunchCount = in.readInt();
            stats.mLastEvent = in.readInt();
            stats.mBeginIdleTime = in.readLong();
            return stats;
        }

+0 −8
Original line number Diff line number Diff line
@@ -68,14 +68,6 @@ public abstract class UsageStatsManagerInternal {
     */
    public abstract boolean isAppIdle(String packageName, int userId);

    /**
     * Returns the most recent time that the specified package was active for the given user.
     * @param packageName The package to search.
     * @param userId The user id of the user of interest.
     * @return The timestamp of when the package was last used, or -1 if it hasn't been used.
     */
    public abstract long getLastPackageAccessTime(String packageName, int userId);

    /**
     * Sets up a listener for changes to packages being accessed.
     * @param listener A listener within the system process.
+1 −0
Original line number Diff line number Diff line
@@ -23,4 +23,5 @@ interface IDeviceIdleController {
    String[] getSystemPowerWhitelist();
    String[] getFullPowerWhitelist();
    int[] getAppIdWhitelist();
    boolean isPowerSaveWhitelistApp(String name);
}
+11 −0
Original line number Diff line number Diff line
@@ -306,6 +306,10 @@ public class DeviceIdleController extends SystemService {
            return getAppIdWhitelistInternal();
        }

        @Override public boolean isPowerSaveWhitelistApp(String name) {
            return isPowerSaveWhitelistAppInternal(name);
        }

        @Override protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
            DeviceIdleController.this.dump(fd, pw, args);
        }
@@ -443,6 +447,13 @@ public class DeviceIdleController extends SystemService {
        }
    }

    public boolean isPowerSaveWhitelistAppInternal(String packageName) {
        synchronized (this) {
            return mPowerSaveWhitelistApps.containsKey(packageName)
                    || mPowerSaveWhitelistUserApps.containsKey(packageName);
        }
    }

    public int[] getAppIdWhitelistInternal() {
        synchronized (this) {
            int size = mPowerSaveWhitelistAppIds.size();
+1 −1
Original line number Diff line number Diff line
@@ -19490,7 +19490,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            mStackSupervisor.resumeTopActivitiesLocked();
        }
        EventLogTags.writeAmSwitchUser(newUserId);
        getUserManagerLocked().userForeground(newUserId);
        getUserManagerLocked().onUserForeground(newUserId);
        sendUserSwitchBroadcastsLocked(oldUserId, newUserId);
    }
Loading