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

Commit e9a988ca authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Work on issue #28942589: Tune job scheduler

We now have a new settings key that provides all of the existing
tuning parameters, plus some newly redone ones for dealing with
different memory levels.

Changed the minimum batching for overall jobs from 2 to 1, so
we will never get in the way of immediately scheduling jobs
when the developer asks for this.  We should now be able to rely
on the doze modes to do better batching of jobs for us when it
is really important.

Also work on issue #28981330: Excessive JobScheduler wakeup alarms.
Use a work source with scheduled alarms to blame them on the app
whose job they are being scheduled for, and add a check for whether
a job's timing constraint has been satisfied before considering it
a possible candidate for the next alarm.  (If it is satisified,
the time is in the past, so we should not schedule an alarm for it.)

Finally clean up a bunch of the dumpsys output to make it easier
to understand.

Change-Id: I06cf2c1310448f47cf386f393e9b267335fabaeb
parent ac2b44f5
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -596,6 +596,22 @@ public class AlarmManager {
                null, workSource, null);
    }

    /**
     * Direct callback version of {@link #set(int, long, long, long, PendingIntent, WorkSource)}.
     * Note that repeating alarms must use the PendingIntent variant, not an OnAlarmListener.
     * <p>
     * The OnAlarmListener's {@link OnAlarmListener#onAlarm() onAlarm()} method will be
     * invoked via the specified target Handler, or on the application's main looper
     * if {@code null} is passed as the {@code targetHandler} parameter.
     *
     * @hide
     */
    public void set(int type, long triggerAtMillis, long windowMillis, long intervalMillis,
            String tag, OnAlarmListener listener, Handler targetHandler, WorkSource workSource) {
        setImpl(type, triggerAtMillis, windowMillis, intervalMillis, 0, null, listener, tag,
                targetHandler, workSource, null);
    }

    /**
     * Direct callback version of {@link #set(int, long, long, long, PendingIntent, WorkSource)}.
     * Note that repeating alarms must use the PendingIntent variant, not an OnAlarmListener.
+11 −6
Original line number Diff line number Diff line
@@ -192,7 +192,8 @@ public class JobInfo implements Parcelable {
    private final int flags;

    /**
     * Unique job id associated with this class. This is assigned to your job by the scheduler.
     * Unique job id associated with this application (uid).  This is the same job ID
     * you supplied in the {@link Builder} constructor.
     */
    public int getId() {
        return jobId;
@@ -524,9 +525,9 @@ public class JobInfo implements Parcelable {

    /** Builder class for constructing {@link JobInfo} objects. */
    public static final class Builder {
        private int mJobId;
        private final int mJobId;
        private final ComponentName mJobService;
        private PersistableBundle mExtras = PersistableBundle.EMPTY;
        private ComponentName mJobService;
        private int mPriority = PRIORITY_DEFAULT;
        private int mFlags;
        // Requirements.
@@ -553,9 +554,13 @@ public class JobInfo implements Parcelable {
        private boolean mBackoffPolicySet = false;

        /**
         * Initialize a new Builder to construct a {@link JobInfo}.
         *
         * @param jobId Application-provided id for this job. Subsequent calls to cancel, or
         * jobs created with the same jobId, will update the pre-existing job with
         *               the same id.
         * the same id.  This ID must be unique across all clients of the same uid
         * (not just the same package).  You will want to make sure this is a stable
         * id across app updates, so probably not based on a resource ID.
         * @param jobService The endpoint that you implement that will receive the callback from the
         * JobScheduler.
         */
+30 −0
Original line number Diff line number Diff line
@@ -8017,6 +8017,36 @@ public final class Settings {
         */
        public static final String ALARM_MANAGER_CONSTANTS = "alarm_manager_constants";

        /**
         * Job scheduler specific settings.
         * This is encoded as a key=value list, separated by commas. Ex:
         *
         * "min_ready_jobs_count=2,moderate_use_factor=.5"
         *
         * The following keys are supported:
         *
         * <pre>
         * min_idle_count                       (int)
         * min_charging_count                   (int)
         * min_connectivity_count               (int)
         * min_content_count                    (int)
         * min_ready_jobs_count                 (int)
         * heavy_use_factor                     (float)
         * moderate_use_factor                  (float)
         * fg_job_count                         (int)
         * bg_normal_job_count                  (int)
         * bg_moderate_job_count                (int)
         * bg_low_job_count                     (int)
         * bg_critical_job_count                (int)
         * </pre>
         *
         * <p>
         * Type: string
         * @hide
         * @see com.android.server.job.JobSchedulerService.Constants
         */
        public static final String JOB_SCHEDULER_CONSTANTS = "job_scheduler_constants";

        /**
         * ShortcutManager specific settings.
         * This is encoded as a key=value list, separated by commas. Ex:
+18 −0
Original line number Diff line number Diff line
@@ -62,6 +62,24 @@ public class KeyValueListParser {
        }
    }

    /**
     * Get the value for key as an int.
     * @param key The key to lookup.
     * @param def The value to return if the key was not found, or the value was not a long.
     * @return the int value associated with the key.
     */
    public int getInt(String key, int def) {
        String value = mValues.get(key);
        if (value != null) {
            try {
                return Integer.parseInt(value);
            } catch (NumberFormatException e) {
                // fallthrough
            }
        }
        return def;
    }

    /**
     * Get the value for key as a long.
     * @param key The key to lookup.
+20 −0
Original line number Diff line number Diff line
@@ -105,6 +105,8 @@ public final class JobPackageTracker {
        final long mStartElapsedTime;
        final long mStartClockTime;
        long mSummedTime;
        int mMaxTotalActive;
        int mMaxFgActive;

        public DataSet(DataSet otherTimes) {
            mStartUptimeTime = otherTimes.mStartUptimeTime;
@@ -257,6 +259,12 @@ public final class JobPackageTracker {
                    }
                }
            }
            if (mMaxTotalActive > out.mMaxTotalActive) {
                out.mMaxTotalActive = mMaxTotalActive;
            }
            if (mMaxFgActive > out.mMaxFgActive) {
                out.mMaxFgActive = mMaxFgActive;
            }
        }

        void printDuration(PrintWriter pw, long period, long duration, int count, String suffix) {
@@ -317,6 +325,9 @@ public final class JobPackageTracker {
                    pw.println();
                }
            }
            pw.print(prefix); pw.print("  Max concurrency: ");
            pw.print(mMaxTotalActive); pw.print(" total, ");
            pw.print(mMaxFgActive); pw.println(" foreground");
        }
    }

@@ -366,6 +377,15 @@ public final class JobPackageTracker {
        addEvent(EVENT_STOP_JOB, job.getSourceUid(), job.getBatteryName());
    }

    public void noteConcurrency(int totalActive, int fgActive) {
        if (totalActive > mCurDataSet.mMaxTotalActive) {
            mCurDataSet.mMaxTotalActive = totalActive;
        }
        if (fgActive > mCurDataSet.mMaxFgActive) {
            mCurDataSet.mMaxFgActive = fgActive;
        }
    }

    public float getLoadFactor(JobStatus job) {
        final int uid = job.getSourceUid();
        final String pkg = job.getSourcePackageName();
Loading