From ea7fea2296b59ad60a5b317d5a68b8eb647c17cf Mon Sep 17 00:00:00 2001 From: Kweku Adams Date: Mon, 7 Dec 2020 13:06:13 -0800 Subject: [PATCH] Reduce unnecessary Handler processing. MSG_CHECK_JOB, MSG_CHECK_JOB_GREEDY, and MSG_JOB_EXPIRED all force queuing ready jobs in at least one code path. There can be situations where all and/or multiple messages are in the handler queue, which become unnecessary and redundant when we enqueue ready jobs. Remove all extraneous messages so we don't do unnecessary repetitive processing. Bug: 166701460 Test: atest CtsJobSchedulerTestCases Test: atest FrameworksMockingServicesTests:ConnectivityControllerTest Test: atest FrameworksMockingServicesTests:JobSchedulerServiceTest Test: atest FrameworksMockingServicesTests:JobStatusTest Test: atest FrameworksMockingServicesTests:QuotaControllerTest Test: atest FrameworksServicesTests:JobStoreTest Change-Id: I49738e44899ed4ceb37398b8875b6dabe387b205 --- .../com/android/server/job/JobSchedulerService.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java index 9ea402c56088a..99a9b97907f41 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java +++ b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java @@ -2044,7 +2044,6 @@ public class JobSchedulerService extends com.android.server.SystemService } maybeRunPendingJobsLocked(); - // Don't remove JOB_EXPIRED in case one came along while processing the queue. } } } @@ -2110,6 +2109,15 @@ public class JobSchedulerService extends com.android.server.SystemService * as many as we can. */ private void queueReadyJobsForExecutionLocked() { + // This method will check and capture all ready jobs, so we don't need to keep any messages + // in the queue. + mHandler.removeMessages(MSG_CHECK_JOB_GREEDY); + // MSG_CHECK_JOB is a weaker form of _GREEDY. Since we're checking and queueing all ready + // jobs, we don't need to keep any MSG_CHECK_JOB messages in the queue. + mHandler.removeMessages(MSG_CHECK_JOB); + // This method will capture all expired jobs that are ready, so there's no need to keep + // the _EXPIRED messages in the queue. + mHandler.removeMessages(MSG_JOB_EXPIRED); if (DEBUG) { Slog.d(TAG, "queuing all ready jobs for execution:"); }