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

Commit 1085ff6e authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Work towards issue #26390161: Throttle syncs/jobs when system is low on RAM

First, we need to make the job scheduler prioritize jobs for
foreground apps over background apps (so we will degrade well
when we are limiting the number of concurrent jobs).

So now the job scheduler keeps track of the process state of
each uid, and uses that to bump up the priority of jobs
associated with foreground uids.  Added constants for priorities
since we have different places specifying priorities.

Also cleaned up a bit of the reporting of "wrapped" jobs from
the sync manager -- there is a new tag argument that can be supplied,
to have the name and tag used in various places be based on that
instead of the useless internal class name.

Change-Id: I8781750ddfac1472a98e1873fc38c014425db3d6
parent f8df4d0d
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -46,9 +46,9 @@ public class JobSchedulerImpl extends JobScheduler {
    }
    }


    @Override
    @Override
    public int scheduleAsPackage(JobInfo job, String packageName, int userId) {
    public int scheduleAsPackage(JobInfo job, String packageName, int userId, String tag) {
        try {
        try {
            return mBinder.scheduleAsPackage(job, packageName, userId);
            return mBinder.scheduleAsPackage(job, packageName, userId, tag);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            return JobScheduler.RESULT_FAILURE;
            return JobScheduler.RESULT_FAILURE;
        }
        }
+1 −1
Original line number Original line Diff line number Diff line
@@ -24,7 +24,7 @@ import android.app.job.JobInfo;
  */
  */
interface IJobScheduler {
interface IJobScheduler {
    int schedule(in JobInfo job);
    int schedule(in JobInfo job);
    int scheduleAsPackage(in JobInfo job, String packageName, int userId);
    int scheduleAsPackage(in JobInfo job, String packageName, int userId, String tag);
    void cancel(int jobId);
    void cancel(int jobId);
    void cancelAll();
    void cancelAll();
    List<JobInfo> getAllPendingJobs();
    List<JobInfo> getAllPendingJobs();
+26 −1
Original line number Original line Diff line number Diff line
@@ -83,6 +83,31 @@ public class JobInfo implements Parcelable {
     */
     */
    public static final int DEFAULT_BACKOFF_POLICY = BACKOFF_POLICY_EXPONENTIAL;
    public static final int DEFAULT_BACKOFF_POLICY = BACKOFF_POLICY_EXPONENTIAL;


    /**
     * Default of {@link #getPriority}.
     * @hide
     */
    public static final int PRIORITY_DEFAULT = 0;

    /**
     * Value of {@link #getPriority} for expedited syncs.
     * @hide
     */
    public static final int PRIORITY_SYNC_EXPEDITED = 10;

    /**
     * Value of {@link #getPriority} for first time initialization syncs.
     * @hide
     */
    public static final int PRIORITY_SYNC_INITIALIZATION = 20;

    /**
     * Value of {@link #getPriority} for the current foreground app (overrides the supplied
     * JobInfo priority if it is smaller).
     * @hide
     */
    public static final int PRIORITY_FOREGROUND_APP = 30;

    private final int jobId;
    private final int jobId;
    private final PersistableBundle extras;
    private final PersistableBundle extras;
    private final ComponentName service;
    private final ComponentName service;
@@ -406,7 +431,7 @@ public class JobInfo implements Parcelable {
        private int mJobId;
        private int mJobId;
        private PersistableBundle mExtras = PersistableBundle.EMPTY;
        private PersistableBundle mExtras = PersistableBundle.EMPTY;
        private ComponentName mJobService;
        private ComponentName mJobService;
        private int mPriority;
        private int mPriority = PRIORITY_DEFAULT;
        // Requirements.
        // Requirements.
        private boolean mRequiresCharging;
        private boolean mRequiresCharging;
        private boolean mRequiresDeviceIdle;
        private boolean mRequiresDeviceIdle;
+2 −1
Original line number Original line Diff line number Diff line
@@ -68,10 +68,11 @@ public abstract class JobScheduler {
     * @param packageName The package on behalf of which the job is to be scheduled. This will be
     * @param packageName The package on behalf of which the job is to be scheduled. This will be
     *                    used to track battery usage and appIdleState.
     *                    used to track battery usage and appIdleState.
     * @param userId    User on behalf of whom this job is to be scheduled.
     * @param userId    User on behalf of whom this job is to be scheduled.
     * @param tag Debugging tag for dumps associated with this job (instead of the service class)
     * @return {@link #RESULT_SUCCESS} or {@link #RESULT_FAILURE}
     * @return {@link #RESULT_SUCCESS} or {@link #RESULT_FAILURE}
     * @hide
     * @hide
     */
     */
    public abstract int scheduleAsPackage(JobInfo job, String packageName, int userId);
    public abstract int scheduleAsPackage(JobInfo job, String packageName, int userId, String tag);


    /**
    /**
     * Cancel a job that is pending in the JobScheduler.
     * Cancel a job that is pending in the JobScheduler.
+1 −1
Original line number Original line Diff line number Diff line
@@ -1319,7 +1319,7 @@ public class SyncManager {
        }
        }


        getJobScheduler().scheduleAsPackage(b.build(), syncOperation.owningPackage,
        getJobScheduler().scheduleAsPackage(b.build(), syncOperation.owningPackage,
                syncOperation.target.userId);
                syncOperation.target.userId, "sync");
    }
    }


    /**
    /**
Loading