Loading apex/jobscheduler/service/aconfig/job.aconfig +10 −0 Original line number Diff line number Diff line Loading @@ -38,3 +38,13 @@ flag { purpose: PURPOSE_BUGFIX } } flag { name: "thermal_restrictions_to_fgs_jobs" namespace: "backstage_power" description: "Apply thermal restrictions to FGS jobs." bug: "315157163" metadata { purpose: PURPOSE_BUGFIX } } apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java +4 −2 Original line number Diff line number Diff line Loading @@ -1375,8 +1375,10 @@ class JobConcurrencyManager { final JobServiceContext jsc = mActiveServices.get(i); final JobStatus jobStatus = jsc.getRunningJobLocked(); if (jobStatus != null && !jsc.isWithinExecutionGuaranteeTime() && restriction.isJobRestricted(jobStatus)) { if (jobStatus != null && !jsc.isWithinExecutionGuaranteeTime() && restriction.isJobRestricted( jobStatus, mService.evaluateJobBiasLocked(jobStatus))) { jsc.cancelExecutingJobLocked(restriction.getStopReason(), restriction.getInternalReason(), JobParameters.getInternalReasonCodeDescription( Loading apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java +6 −10 Original line number Diff line number Diff line Loading @@ -310,7 +310,8 @@ public class JobSchedulerService extends com.android.server.SystemService * Note: do not add to or remove from this list at runtime except in the constructor, because we * do not synchronize access to this list. */ private final List<JobRestriction> mJobRestrictions; @VisibleForTesting final List<JobRestriction> mJobRestrictions; @GuardedBy("mLock") @VisibleForTesting Loading Loading @@ -3498,8 +3499,6 @@ public class JobSchedulerService extends com.android.server.SystemService /** * Check if a job is restricted by any of the declared {@link JobRestriction JobRestrictions}. * Note, that the jobs with {@link JobInfo#BIAS_FOREGROUND_SERVICE} bias or higher may not * be restricted, thus we won't even perform the check, but simply return null early. * * @param job to be checked * @return the first {@link JobRestriction} restricting the given job that has been found; null Loading @@ -3508,13 +3507,9 @@ public class JobSchedulerService extends com.android.server.SystemService */ @GuardedBy("mLock") JobRestriction checkIfRestricted(JobStatus job) { if (evaluateJobBiasLocked(job) >= JobInfo.BIAS_FOREGROUND_SERVICE) { // Jobs with BIAS_FOREGROUND_SERVICE or higher should not be restricted return null; } for (int i = mJobRestrictions.size() - 1; i >= 0; i--) { final JobRestriction restriction = mJobRestrictions.get(i); if (restriction.isJobRestricted(job)) { if (restriction.isJobRestricted(job, evaluateJobBiasLocked(job))) { return restriction; } } Loading Loading @@ -4221,6 +4216,7 @@ public class JobSchedulerService extends com.android.server.SystemService return curBias; } /** Gets and returns the adjusted Job Bias **/ int evaluateJobBiasLocked(JobStatus job) { int bias = job.getBias(); if (bias >= JobInfo.BIAS_BOUND_FOREGROUND_SERVICE) { Loading Loading @@ -5907,7 +5903,7 @@ public class JobSchedulerService extends com.android.server.SystemService if (isRestricted) { for (int i = mJobRestrictions.size() - 1; i >= 0; i--) { final JobRestriction restriction = mJobRestrictions.get(i); if (restriction.isJobRestricted(job)) { if (restriction.isJobRestricted(job, evaluateJobBiasLocked(job))) { final int reason = restriction.getInternalReason(); pw.print(" "); pw.print(JobParameters.getInternalReasonCodeDescription(reason)); Loading Loading @@ -6240,7 +6236,7 @@ public class JobSchedulerService extends com.android.server.SystemService proto.write(JobSchedulerServiceDumpProto.JobRestriction.REASON, restriction.getInternalReason()); proto.write(JobSchedulerServiceDumpProto.JobRestriction.IS_RESTRICTING, restriction.isJobRestricted(job)); restriction.isJobRestricted(job, evaluateJobBiasLocked(job))); proto.end(restrictionsToken); } Loading apex/jobscheduler/service/java/com/android/server/job/restrictions/JobRestriction.java +2 −1 Original line number Diff line number Diff line Loading @@ -62,10 +62,11 @@ public abstract class JobRestriction { * fine with it). * * @param job to be checked * @param bias job bias to be checked * @return false if the {@link JobSchedulerService} should not schedule this job at the moment, * true - otherwise */ public abstract boolean isJobRestricted(JobStatus job); public abstract boolean isJobRestricted(JobStatus job, int bias); /** Dump any internal constants the Restriction may have. */ public abstract void dumpConstants(IndentingPrintWriter pw); Loading apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java +31 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.os.PowerManager.OnThermalStatusChangedListener; import android.util.IndentingPrintWriter; import com.android.internal.annotations.VisibleForTesting; import com.android.server.job.Flags; import com.android.server.job.JobSchedulerService; import com.android.server.job.controllers.JobStatus; Loading Loading @@ -85,7 +86,18 @@ public class ThermalStatusRestriction extends JobRestriction { } @Override public boolean isJobRestricted(JobStatus job) { public boolean isJobRestricted(JobStatus job, int bias) { if (Flags.thermalRestrictionsToFgsJobs()) { if (bias >= JobInfo.BIAS_TOP_APP) { // Jobs with BIAS_TOP_APP should not be restricted return false; } } else { if (bias >= JobInfo.BIAS_FOREGROUND_SERVICE) { // Jobs with BIAS_FOREGROUND_SERVICE or higher should not be restricted return false; } } if (mThermalStatus >= UPPER_THRESHOLD) { return true; } Loading @@ -107,6 +119,17 @@ public class ThermalStatusRestriction extends JobRestriction { || (mService.isCurrentlyRunningLocked(job) && mService.isJobInOvertimeLocked(job)); } if (Flags.thermalRestrictionsToFgsJobs()) { // Only let foreground jobs run if: // 1. They haven't previously run // 2. They're already running and aren't yet in overtime if (bias >= JobInfo.BIAS_FOREGROUND_SERVICE && job.getJob().isImportantWhileForeground()) { return job.getNumPreviousAttempts() > 0 || (mService.isCurrentlyRunningLocked(job) && mService.isJobInOvertimeLocked(job)); } } if (priority == JobInfo.PRIORITY_HIGH) { return !mService.isCurrentlyRunningLocked(job) || mService.isJobInOvertimeLocked(job); Loading @@ -114,6 +137,13 @@ public class ThermalStatusRestriction extends JobRestriction { return true; } if (mThermalStatus >= LOW_PRIORITY_THRESHOLD) { if (Flags.thermalRestrictionsToFgsJobs()) { if (bias >= JobInfo.BIAS_FOREGROUND_SERVICE) { // No restrictions on foreground jobs // on LOW_PRIORITY_THRESHOLD and below return false; } } // For light throttling, throttle all min priority jobs and all low priority jobs that // aren't already running or have been running for long enough. return priority == JobInfo.PRIORITY_MIN Loading Loading
apex/jobscheduler/service/aconfig/job.aconfig +10 −0 Original line number Diff line number Diff line Loading @@ -38,3 +38,13 @@ flag { purpose: PURPOSE_BUGFIX } } flag { name: "thermal_restrictions_to_fgs_jobs" namespace: "backstage_power" description: "Apply thermal restrictions to FGS jobs." bug: "315157163" metadata { purpose: PURPOSE_BUGFIX } }
apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java +4 −2 Original line number Diff line number Diff line Loading @@ -1375,8 +1375,10 @@ class JobConcurrencyManager { final JobServiceContext jsc = mActiveServices.get(i); final JobStatus jobStatus = jsc.getRunningJobLocked(); if (jobStatus != null && !jsc.isWithinExecutionGuaranteeTime() && restriction.isJobRestricted(jobStatus)) { if (jobStatus != null && !jsc.isWithinExecutionGuaranteeTime() && restriction.isJobRestricted( jobStatus, mService.evaluateJobBiasLocked(jobStatus))) { jsc.cancelExecutingJobLocked(restriction.getStopReason(), restriction.getInternalReason(), JobParameters.getInternalReasonCodeDescription( Loading
apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java +6 −10 Original line number Diff line number Diff line Loading @@ -310,7 +310,8 @@ public class JobSchedulerService extends com.android.server.SystemService * Note: do not add to or remove from this list at runtime except in the constructor, because we * do not synchronize access to this list. */ private final List<JobRestriction> mJobRestrictions; @VisibleForTesting final List<JobRestriction> mJobRestrictions; @GuardedBy("mLock") @VisibleForTesting Loading Loading @@ -3498,8 +3499,6 @@ public class JobSchedulerService extends com.android.server.SystemService /** * Check if a job is restricted by any of the declared {@link JobRestriction JobRestrictions}. * Note, that the jobs with {@link JobInfo#BIAS_FOREGROUND_SERVICE} bias or higher may not * be restricted, thus we won't even perform the check, but simply return null early. * * @param job to be checked * @return the first {@link JobRestriction} restricting the given job that has been found; null Loading @@ -3508,13 +3507,9 @@ public class JobSchedulerService extends com.android.server.SystemService */ @GuardedBy("mLock") JobRestriction checkIfRestricted(JobStatus job) { if (evaluateJobBiasLocked(job) >= JobInfo.BIAS_FOREGROUND_SERVICE) { // Jobs with BIAS_FOREGROUND_SERVICE or higher should not be restricted return null; } for (int i = mJobRestrictions.size() - 1; i >= 0; i--) { final JobRestriction restriction = mJobRestrictions.get(i); if (restriction.isJobRestricted(job)) { if (restriction.isJobRestricted(job, evaluateJobBiasLocked(job))) { return restriction; } } Loading Loading @@ -4221,6 +4216,7 @@ public class JobSchedulerService extends com.android.server.SystemService return curBias; } /** Gets and returns the adjusted Job Bias **/ int evaluateJobBiasLocked(JobStatus job) { int bias = job.getBias(); if (bias >= JobInfo.BIAS_BOUND_FOREGROUND_SERVICE) { Loading Loading @@ -5907,7 +5903,7 @@ public class JobSchedulerService extends com.android.server.SystemService if (isRestricted) { for (int i = mJobRestrictions.size() - 1; i >= 0; i--) { final JobRestriction restriction = mJobRestrictions.get(i); if (restriction.isJobRestricted(job)) { if (restriction.isJobRestricted(job, evaluateJobBiasLocked(job))) { final int reason = restriction.getInternalReason(); pw.print(" "); pw.print(JobParameters.getInternalReasonCodeDescription(reason)); Loading Loading @@ -6240,7 +6236,7 @@ public class JobSchedulerService extends com.android.server.SystemService proto.write(JobSchedulerServiceDumpProto.JobRestriction.REASON, restriction.getInternalReason()); proto.write(JobSchedulerServiceDumpProto.JobRestriction.IS_RESTRICTING, restriction.isJobRestricted(job)); restriction.isJobRestricted(job, evaluateJobBiasLocked(job))); proto.end(restrictionsToken); } Loading
apex/jobscheduler/service/java/com/android/server/job/restrictions/JobRestriction.java +2 −1 Original line number Diff line number Diff line Loading @@ -62,10 +62,11 @@ public abstract class JobRestriction { * fine with it). * * @param job to be checked * @param bias job bias to be checked * @return false if the {@link JobSchedulerService} should not schedule this job at the moment, * true - otherwise */ public abstract boolean isJobRestricted(JobStatus job); public abstract boolean isJobRestricted(JobStatus job, int bias); /** Dump any internal constants the Restriction may have. */ public abstract void dumpConstants(IndentingPrintWriter pw); Loading
apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java +31 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.os.PowerManager.OnThermalStatusChangedListener; import android.util.IndentingPrintWriter; import com.android.internal.annotations.VisibleForTesting; import com.android.server.job.Flags; import com.android.server.job.JobSchedulerService; import com.android.server.job.controllers.JobStatus; Loading Loading @@ -85,7 +86,18 @@ public class ThermalStatusRestriction extends JobRestriction { } @Override public boolean isJobRestricted(JobStatus job) { public boolean isJobRestricted(JobStatus job, int bias) { if (Flags.thermalRestrictionsToFgsJobs()) { if (bias >= JobInfo.BIAS_TOP_APP) { // Jobs with BIAS_TOP_APP should not be restricted return false; } } else { if (bias >= JobInfo.BIAS_FOREGROUND_SERVICE) { // Jobs with BIAS_FOREGROUND_SERVICE or higher should not be restricted return false; } } if (mThermalStatus >= UPPER_THRESHOLD) { return true; } Loading @@ -107,6 +119,17 @@ public class ThermalStatusRestriction extends JobRestriction { || (mService.isCurrentlyRunningLocked(job) && mService.isJobInOvertimeLocked(job)); } if (Flags.thermalRestrictionsToFgsJobs()) { // Only let foreground jobs run if: // 1. They haven't previously run // 2. They're already running and aren't yet in overtime if (bias >= JobInfo.BIAS_FOREGROUND_SERVICE && job.getJob().isImportantWhileForeground()) { return job.getNumPreviousAttempts() > 0 || (mService.isCurrentlyRunningLocked(job) && mService.isJobInOvertimeLocked(job)); } } if (priority == JobInfo.PRIORITY_HIGH) { return !mService.isCurrentlyRunningLocked(job) || mService.isJobInOvertimeLocked(job); Loading @@ -114,6 +137,13 @@ public class ThermalStatusRestriction extends JobRestriction { return true; } if (mThermalStatus >= LOW_PRIORITY_THRESHOLD) { if (Flags.thermalRestrictionsToFgsJobs()) { if (bias >= JobInfo.BIAS_FOREGROUND_SERVICE) { // No restrictions on foreground jobs // on LOW_PRIORITY_THRESHOLD and below return false; } } // For light throttling, throttle all min priority jobs and all low priority jobs that // aren't already running or have been running for long enough. return priority == JobInfo.PRIORITY_MIN Loading