Loading apex/jobscheduler/service/java/com/android/server/job/restrictions/JobRestriction.java +2 −1 Original line number Diff line number Diff line Loading @@ -66,7 +66,8 @@ public abstract class JobRestriction { public abstract void dumpConstants(IndentingPrintWriter pw); /** Dump any internal constants the Restriction may have. */ public abstract void dumpConstants(ProtoOutputStream proto); public void dumpConstants(ProtoOutputStream proto) { } /** @return reason code for the Restriction. */ @JobParameters.StopReason Loading apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java +38 −16 Original line number Diff line number Diff line Loading @@ -20,16 +20,21 @@ import android.app.job.JobParameters; import android.os.PowerManager; import android.os.PowerManager.OnThermalStatusChangedListener; import android.util.IndentingPrintWriter; import android.util.proto.ProtoOutputStream; import com.android.server.job.JobSchedulerService; import com.android.server.job.JobSchedulerServiceDumpProto; import com.android.server.job.controllers.JobStatus; public class ThermalStatusRestriction extends JobRestriction { private static final String TAG = "ThermalStatusRestriction"; private volatile boolean mIsThermalRestricted = false; /** The threshold at which we start restricting non-EJ jobs. */ private static final int REGULAR_JOB_THRESHOLD = PowerManager.THERMAL_STATUS_SEVERE; /** The lowest threshold at which we start restricting jobs. */ private static final int LOWER_THRESHOLD = REGULAR_JOB_THRESHOLD; /** The threshold at which we start restricting ALL jobs. */ private static final int UPPER_THRESHOLD = PowerManager.THERMAL_STATUS_CRITICAL; private volatile int mThermalStatus = PowerManager.THERMAL_STATUS_NONE; private PowerManager mPowerManager; Loading @@ -47,29 +52,46 @@ public class ThermalStatusRestriction extends JobRestriction { public void onThermalStatusChanged(int status) { // This is called on the main thread. Do not do any slow operations in it. // mService.onControllerStateChanged() will just post a message, which is okay. final boolean shouldBeActive = status >= PowerManager.THERMAL_STATUS_SEVERE; if (mIsThermalRestricted == shouldBeActive) { return; } mIsThermalRestricted = shouldBeActive; // There are three buckets: // 1. Below the lower threshold (we don't care about changes within this bucket) // 2. Between the lower and upper thresholds. // -> We care about transitions across buckets // -> We care about transitions within the middle bucket // 3. Upper the upper threshold (we don't care about changes within this bucket) final boolean significantChange = // Handle transitions within and into the bucket we care about (thus // causing us to change our restrictions). (status >= LOWER_THRESHOLD && status <= UPPER_THRESHOLD) // Take care of transitions from the 2nd or 3rd bucket to the 1st // bucket (thus exiting any restrictions we started enforcing). || (mThermalStatus >= LOWER_THRESHOLD && status < LOWER_THRESHOLD) // Take care of transitions from the 1st or 2nd bucket to the 3rd // bucket (thus resulting in us beginning to enforce the tightest // restrictions). || (mThermalStatus < UPPER_THRESHOLD && status > UPPER_THRESHOLD); mThermalStatus = status; if (significantChange) { mService.onControllerStateChanged(); } } }); } @Override public boolean isJobRestricted(JobStatus job) { return mIsThermalRestricted; if (mThermalStatus >= UPPER_THRESHOLD) { return true; } @Override public void dumpConstants(IndentingPrintWriter pw) { pw.print("In thermal throttling?: "); pw.println(mIsThermalRestricted); if (mThermalStatus >= REGULAR_JOB_THRESHOLD) { return !job.shouldTreatAsExpeditedJob(); } return false; } @Override public void dumpConstants(ProtoOutputStream proto) { proto.write(JobSchedulerServiceDumpProto.IN_THERMAL, mIsThermalRestricted); public void dumpConstants(IndentingPrintWriter pw) { pw.print("Thermal status: "); pw.println(mThermalStatus); } } Loading
apex/jobscheduler/service/java/com/android/server/job/restrictions/JobRestriction.java +2 −1 Original line number Diff line number Diff line Loading @@ -66,7 +66,8 @@ public abstract class JobRestriction { public abstract void dumpConstants(IndentingPrintWriter pw); /** Dump any internal constants the Restriction may have. */ public abstract void dumpConstants(ProtoOutputStream proto); public void dumpConstants(ProtoOutputStream proto) { } /** @return reason code for the Restriction. */ @JobParameters.StopReason Loading
apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java +38 −16 Original line number Diff line number Diff line Loading @@ -20,16 +20,21 @@ import android.app.job.JobParameters; import android.os.PowerManager; import android.os.PowerManager.OnThermalStatusChangedListener; import android.util.IndentingPrintWriter; import android.util.proto.ProtoOutputStream; import com.android.server.job.JobSchedulerService; import com.android.server.job.JobSchedulerServiceDumpProto; import com.android.server.job.controllers.JobStatus; public class ThermalStatusRestriction extends JobRestriction { private static final String TAG = "ThermalStatusRestriction"; private volatile boolean mIsThermalRestricted = false; /** The threshold at which we start restricting non-EJ jobs. */ private static final int REGULAR_JOB_THRESHOLD = PowerManager.THERMAL_STATUS_SEVERE; /** The lowest threshold at which we start restricting jobs. */ private static final int LOWER_THRESHOLD = REGULAR_JOB_THRESHOLD; /** The threshold at which we start restricting ALL jobs. */ private static final int UPPER_THRESHOLD = PowerManager.THERMAL_STATUS_CRITICAL; private volatile int mThermalStatus = PowerManager.THERMAL_STATUS_NONE; private PowerManager mPowerManager; Loading @@ -47,29 +52,46 @@ public class ThermalStatusRestriction extends JobRestriction { public void onThermalStatusChanged(int status) { // This is called on the main thread. Do not do any slow operations in it. // mService.onControllerStateChanged() will just post a message, which is okay. final boolean shouldBeActive = status >= PowerManager.THERMAL_STATUS_SEVERE; if (mIsThermalRestricted == shouldBeActive) { return; } mIsThermalRestricted = shouldBeActive; // There are three buckets: // 1. Below the lower threshold (we don't care about changes within this bucket) // 2. Between the lower and upper thresholds. // -> We care about transitions across buckets // -> We care about transitions within the middle bucket // 3. Upper the upper threshold (we don't care about changes within this bucket) final boolean significantChange = // Handle transitions within and into the bucket we care about (thus // causing us to change our restrictions). (status >= LOWER_THRESHOLD && status <= UPPER_THRESHOLD) // Take care of transitions from the 2nd or 3rd bucket to the 1st // bucket (thus exiting any restrictions we started enforcing). || (mThermalStatus >= LOWER_THRESHOLD && status < LOWER_THRESHOLD) // Take care of transitions from the 1st or 2nd bucket to the 3rd // bucket (thus resulting in us beginning to enforce the tightest // restrictions). || (mThermalStatus < UPPER_THRESHOLD && status > UPPER_THRESHOLD); mThermalStatus = status; if (significantChange) { mService.onControllerStateChanged(); } } }); } @Override public boolean isJobRestricted(JobStatus job) { return mIsThermalRestricted; if (mThermalStatus >= UPPER_THRESHOLD) { return true; } @Override public void dumpConstants(IndentingPrintWriter pw) { pw.print("In thermal throttling?: "); pw.println(mIsThermalRestricted); if (mThermalStatus >= REGULAR_JOB_THRESHOLD) { return !job.shouldTreatAsExpeditedJob(); } return false; } @Override public void dumpConstants(ProtoOutputStream proto) { proto.write(JobSchedulerServiceDumpProto.IN_THERMAL, mIsThermalRestricted); public void dumpConstants(IndentingPrintWriter pw) { pw.print("Thermal status: "); pw.println(mThermalStatus); } }