diff options
Diffstat (limited to 'apex')
8 files changed, 84 insertions, 27 deletions
diff --git a/apex/jobscheduler/framework/java/android/app/job/JobScheduler.java b/apex/jobscheduler/framework/java/android/app/job/JobScheduler.java index d59d430e0b78..ad54cd397413 100644 --- a/apex/jobscheduler/framework/java/android/app/job/JobScheduler.java +++ b/apex/jobscheduler/framework/java/android/app/job/JobScheduler.java @@ -491,8 +491,10 @@ public abstract class JobScheduler { * Returns a list of all currently-executing jobs. * @hide */ - @SuppressWarnings("HiddenAbstractMethod") - public abstract List<JobInfo> getStartedJobs(); + @Nullable + public List<JobInfo> getStartedJobs() { + return null; + } /** * <b>For internal system callers only!</b> @@ -501,8 +503,10 @@ public abstract class JobScheduler { * <p class="note">This is a slow operation, so it should be called sparingly. * @hide */ - @SuppressWarnings("HiddenAbstractMethod") - public abstract List<JobSnapshot> getAllJobSnapshots(); + @Nullable + public List<JobSnapshot> getAllJobSnapshots() { + return null; + } /** * @hide @@ -510,8 +514,8 @@ public abstract class JobScheduler { @RequiresPermission(allOf = { android.Manifest.permission.MANAGE_ACTIVITY_TASKS, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}) - @SuppressWarnings("HiddenAbstractMethod") - public abstract void registerUserVisibleJobObserver(@NonNull IUserVisibleJobObserver observer); + public void registerUserVisibleJobObserver(@NonNull IUserVisibleJobObserver observer) { + } /** * @hide @@ -519,9 +523,10 @@ public abstract class JobScheduler { @RequiresPermission(allOf = { android.Manifest.permission.MANAGE_ACTIVITY_TASKS, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}) - @SuppressWarnings("HiddenAbstractMethod") - public abstract void unregisterUserVisibleJobObserver( - @NonNull IUserVisibleJobObserver observer); + public void unregisterUserVisibleJobObserver( + @NonNull IUserVisibleJobObserver observer) { + + } /** * @hide @@ -529,7 +534,7 @@ public abstract class JobScheduler { @RequiresPermission(allOf = { android.Manifest.permission.MANAGE_ACTIVITY_TASKS, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}) - @SuppressWarnings("HiddenAbstractMethod") - public abstract void notePendingUserRequestedAppStop(@NonNull String packageName, int userId, - @Nullable String debugReason); + public void notePendingUserRequestedAppStop(@NonNull String packageName, int userId, + @Nullable String debugReason) { + } } diff --git a/apex/jobscheduler/framework/java/android/os/PowerExemptionManager.java b/apex/jobscheduler/framework/java/android/os/PowerExemptionManager.java index 24d815f2964b..e73417460724 100644 --- a/apex/jobscheduler/framework/java/android/os/PowerExemptionManager.java +++ b/apex/jobscheduler/framework/java/android/os/PowerExemptionManager.java @@ -427,6 +427,12 @@ public class PowerExemptionManager { */ public static final int REASON_PACKAGE_UNARCHIVE = 328; + /** + * Tile onClick event + * @hide + */ + public static final int REASON_TILE_ONCLICK = 329; + /** @hide The app requests out-out. */ public static final int REASON_OPT_OUT_REQUESTED = 1000; @@ -504,13 +510,15 @@ public class PowerExemptionManager { REASON_ROLE_EMERGENCY, REASON_SYSTEM_MODULE, REASON_CARRIER_PRIVILEGED_APP, - REASON_OPT_OUT_REQUESTED, REASON_DPO_PROTECTED_APP, REASON_DISALLOW_APPS_CONTROL, REASON_ACTIVE_DEVICE_ADMIN, REASON_MEDIA_NOTIFICATION_TRANSFER, REASON_PACKAGE_INSTALLER, + REASON_SYSTEM_EXEMPT_APP_OP, REASON_PACKAGE_UNARCHIVE, + REASON_TILE_ONCLICK, + REASON_OPT_OUT_REQUESTED, }) @Retention(RetentionPolicy.SOURCE) public @interface ReasonCode {} diff --git a/apex/jobscheduler/framework/java/android/os/PowerWhitelistManager.java b/apex/jobscheduler/framework/java/android/os/PowerWhitelistManager.java index 20da1718abb0..18ffb7ae70b1 100644 --- a/apex/jobscheduler/framework/java/android/os/PowerWhitelistManager.java +++ b/apex/jobscheduler/framework/java/android/os/PowerWhitelistManager.java @@ -310,6 +310,11 @@ public class PowerWhitelistManager { * @hide */ public static final int REASON_SHELL = PowerExemptionManager.REASON_SHELL; + /** + * Tile onClick event + * @hide + */ + public static final int REASON_TILE_ONCLICK = PowerExemptionManager.REASON_TILE_ONCLICK; /** * The list of BG-FGS-Launch and temp-allowlist reason code. diff --git a/apex/jobscheduler/service/aconfig/job.aconfig b/apex/jobscheduler/service/aconfig/job.aconfig index e20f525fcdaf..e489c1ad891a 100644 --- a/apex/jobscheduler/service/aconfig/job.aconfig +++ b/apex/jobscheduler/service/aconfig/job.aconfig @@ -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 + } +} diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java b/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java index 3bb395f39123..ba8e3e8b48fc 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java +++ b/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java @@ -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( 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 5d1433c815d6..384d78618c8b 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java +++ b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java @@ -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 @@ -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 @@ -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; } } @@ -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) { @@ -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)); @@ -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); } diff --git a/apex/jobscheduler/service/java/com/android/server/job/restrictions/JobRestriction.java b/apex/jobscheduler/service/java/com/android/server/job/restrictions/JobRestriction.java index 7aab67a00b1d..555a1186e0c9 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/restrictions/JobRestriction.java +++ b/apex/jobscheduler/service/java/com/android/server/job/restrictions/JobRestriction.java @@ -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); diff --git a/apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java b/apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java index ef634b565b65..ba0111349bc9 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java +++ b/apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java @@ -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; @@ -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; } @@ -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); @@ -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 |