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

Commit 69a135b2 authored by Xin Guan's avatar Xin Guan Committed by Android (Google) Code Review
Browse files

Merge "JobScheduler: Ignore important while foreground flag" into main

parents 22061481 863a1a81
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -30,3 +30,10 @@ flag {
   description: "Enables automatic cancellation of jobs due to leaked JobParameters, reducing unnecessary battery drain and improving system efficiency. This includes logging and traces for better issue diagnosis."
   bug: "349688611"
}

flag {
    name: "ignore_important_while_foreground"
    namespace: "backstage_power"
    description: "Ignore the important_while_foreground flag and change the related APIs to be not effective"
    bug: "374175032"
}
+25 −0
Original line number Diff line number Diff line
@@ -809,9 +809,21 @@ public class JobInfo implements Parcelable {
    }

    /**
     * <p class="caution"><strong>Note:</strong> Beginning with
     * {@link android.os.Build.VERSION_CODES#B}, this flag will be ignored and no longer
     * function effectively, regardless of the calling app's target SDK version.
     * Calling this method will always return {@code false}.
     *
     * @see JobInfo.Builder#setImportantWhileForeground(boolean)
     *
     * @deprecated Use {@link #isExpedited()} instead.
     */
    @FlaggedApi(Flags.FLAG_IGNORE_IMPORTANT_WHILE_FOREGROUND)
    @Deprecated
    public boolean isImportantWhileForeground() {
        if (Flags.ignoreImportantWhileForeground()) {
            return false;
        }
        return (flags & FLAG_IMPORTANT_WHILE_FOREGROUND) != 0;
    }

@@ -2124,6 +2136,13 @@ public class JobInfo implements Parcelable {
         * <p>
         * Jobs marked as important-while-foreground are given {@link #PRIORITY_HIGH} by default.
         *
         * <p class="caution"><strong>Note:</strong> Beginning with
         * {@link android.os.Build.VERSION_CODES#B}, this flag will be ignored and no longer
         * function effectively, regardless of the calling app's target SDK version.
         * {link #isImportantWhileForeground()} will always return {@code false}.
         * Apps should use {link #setExpedited(boolean)} with {@code true} to indicate
         * that this job is important and needs to run as soon as possible.
         *
         * @param importantWhileForeground whether to relax doze restrictions for this job when the
         *                                 app is in the foreground. False by default.
         * @see JobInfo#isImportantWhileForeground()
@@ -2131,6 +2150,12 @@ public class JobInfo implements Parcelable {
         */
        @Deprecated
        public Builder setImportantWhileForeground(boolean importantWhileForeground) {
            if (Flags.ignoreImportantWhileForeground()) {
                Log.w(TAG, "Requested important-while-foreground flag for job" + mJobId
                        + " is ignored and takes no effect");
                return this;
            }

            if (importantWhileForeground) {
                mFlags |= FLAG_IMPORTANT_WHILE_FOREGROUND;
                if (mPriority == PRIORITY_DEFAULT) {
+3 −0
Original line number Diff line number Diff line
@@ -5864,6 +5864,9 @@ public class JobSchedulerService extends com.android.server.SystemService
            pw.print(android.app.job.Flags.FLAG_BACKUP_JOBS_EXEMPTION,
                    android.app.job.Flags.backupJobsExemption());
            pw.println();
            pw.print(android.app.job.Flags.FLAG_IGNORE_IMPORTANT_WHILE_FOREGROUND,
                    android.app.job.Flags.ignoreImportantWhileForeground());
            pw.println();
            pw.decreaseIndent();
            pw.println();

+3 −0
Original line number Diff line number Diff line
@@ -436,6 +436,9 @@ public final class JobSchedulerShellCommand extends BasicShellCommandHandler {
            case android.app.job.Flags.FLAG_BACKUP_JOBS_EXEMPTION:
                pw.println(android.app.job.Flags.backupJobsExemption());
                break;
            case android.app.job.Flags.FLAG_IGNORE_IMPORTANT_WHILE_FOREGROUND:
                pw.println(android.app.job.Flags.ignoreImportantWhileForeground());
                break;
            default:
                pw.println("Unknown flag: " + flagName);
                break;
+7 −3
Original line number Diff line number Diff line
@@ -210,7 +210,9 @@ public final class DeviceIdleJobsController extends StateController {
    }

    private boolean updateTaskStateLocked(JobStatus task, final long nowElapsed) {
        final boolean allowInIdle = ((task.getFlags()&JobInfo.FLAG_IMPORTANT_WHILE_FOREGROUND) != 0)
        final boolean allowInIdle =
                (!android.app.job.Flags.ignoreImportantWhileForeground()
                        && ((task.getFlags() & JobInfo.FLAG_IMPORTANT_WHILE_FOREGROUND) != 0))
                && (mForegroundUids.get(task.getSourceUid()) || isTempWhitelistedLocked(task));
        final boolean whitelisted = isWhitelistedLocked(task);
        final boolean enableTask = !mDeviceIdleMode || whitelisted || allowInIdle;
@@ -219,7 +221,8 @@ public final class DeviceIdleJobsController extends StateController {

    @Override
    public void maybeStartTrackingJobLocked(JobStatus jobStatus, JobStatus lastJob) {
        if ((jobStatus.getFlags()&JobInfo.FLAG_IMPORTANT_WHILE_FOREGROUND) != 0) {
        if (!android.app.job.Flags.ignoreImportantWhileForeground()
                && (jobStatus.getFlags() & JobInfo.FLAG_IMPORTANT_WHILE_FOREGROUND) != 0) {
            mAllowInIdleJobs.add(jobStatus);
        }
        updateTaskStateLocked(jobStatus, sElapsedRealtimeClock.millis());
@@ -227,7 +230,8 @@ public final class DeviceIdleJobsController extends StateController {

    @Override
    public void maybeStopTrackingJobLocked(JobStatus jobStatus, JobStatus incomingJob) {
        if ((jobStatus.getFlags()&JobInfo.FLAG_IMPORTANT_WHILE_FOREGROUND) != 0) {
        if (!android.app.job.Flags.ignoreImportantWhileForeground()
                && (jobStatus.getFlags() & JobInfo.FLAG_IMPORTANT_WHILE_FOREGROUND) != 0) {
            mAllowInIdleJobs.remove(jobStatus);
        }
    }
Loading