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

Commit 2ffa7f0d authored by Suprabh Shukla's avatar Suprabh Shukla Committed by Android (Google) Code Review
Browse files

Merge "Delaying jobs while coming out of doze"

parents f08afcfc 106203bc
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6885,6 +6885,7 @@ package android.app.job {
    method public android.app.job.JobInfo.Builder setClipData(android.content.ClipData, int);
    method public android.app.job.JobInfo.Builder setEstimatedNetworkBytes(long);
    method public android.app.job.JobInfo.Builder setExtras(android.os.PersistableBundle);
    method public android.app.job.JobInfo.Builder setImportantWhileForeground(boolean);
    method public android.app.job.JobInfo.Builder setMinimumLatency(long);
    method public android.app.job.JobInfo.Builder setOverrideDeadline(long);
    method public android.app.job.JobInfo.Builder setPeriodic(long);
+1 −0
Original line number Diff line number Diff line
@@ -7328,6 +7328,7 @@ package android.app.job {
    method public android.app.job.JobInfo.Builder setClipData(android.content.ClipData, int);
    method public android.app.job.JobInfo.Builder setEstimatedNetworkBytes(long);
    method public android.app.job.JobInfo.Builder setExtras(android.os.PersistableBundle);
    method public android.app.job.JobInfo.Builder setImportantWhileForeground(boolean);
    method public android.app.job.JobInfo.Builder setMinimumLatency(long);
    method public android.app.job.JobInfo.Builder setOverrideDeadline(long);
    method public android.app.job.JobInfo.Builder setPeriodic(long);
+1 −0
Original line number Diff line number Diff line
@@ -6959,6 +6959,7 @@ package android.app.job {
    method public android.app.job.JobInfo.Builder setClipData(android.content.ClipData, int);
    method public android.app.job.JobInfo.Builder setEstimatedNetworkBytes(long);
    method public android.app.job.JobInfo.Builder setExtras(android.os.PersistableBundle);
    method public android.app.job.JobInfo.Builder setImportantWhileForeground(boolean);
    method public android.app.job.JobInfo.Builder setMinimumLatency(long);
    method public android.app.job.JobInfo.Builder setOverrideDeadline(long);
    method public android.app.job.JobInfo.Builder setPeriodic(long);
+35 −0
Original line number Diff line number Diff line
@@ -243,6 +243,13 @@ public class JobInfo implements Parcelable {
     */
    public static final int FLAG_WILL_BE_FOREGROUND = 1 << 0;

    /**
     * Allows this job to run despite doze restrictions as long as the app is in the foreground
     * or on the temporary whitelist
     * @hide
     */
    public static final int FLAG_IMPORTANT_WHILE_FOREGROUND = 1 << 1;

    /**
     * @hide
     */
@@ -1332,6 +1339,30 @@ public class JobInfo implements Parcelable {
            return this;
        }

        /**
         * Setting this to true indicates that this job is important while the scheduling app
         * is in the foreground or on the temporary whitelist for background restrictions.
         * This means that the system will relax doze restrictions on this job during this time.
         *
         * Apps should use this flag only for short jobs that are essential for the app to function
         * properly in the foreground.
         *
         * Note that once the scheduling app is no longer whitelisted from background restrictions
         * and in the background, or the job failed due to unsatisfied constraints,
         * this job should be expected to behave like other jobs without this flag.
         *
         * @param importantWhileForeground whether to relax doze restrictions for this job when the
         *                                 app is in the foreground. False by default.
         */
        public Builder setImportantWhileForeground(boolean importantWhileForeground) {
            if (importantWhileForeground) {
                mFlags |= FLAG_IMPORTANT_WHILE_FOREGROUND;
            } else {
                mFlags &= (~FLAG_IMPORTANT_WHILE_FOREGROUND);
            }
            return this;
        }

        /**
         * Set whether or not to persist this job across device reboots.
         *
@@ -1395,6 +1426,10 @@ public class JobInfo implements Parcelable {
                            "persisted job");
                }
            }
            if ((mFlags & FLAG_IMPORTANT_WHILE_FOREGROUND) != 0 && mHasEarlyConstraint) {
                throw new IllegalArgumentException("An important while foreground job cannot "
                        + "have a time delay");
            }
            if (mBackoffPolicySet && (mConstraintFlags & CONSTRAINT_FLAG_DEVICE_IDLE) != 0) {
                throw new IllegalArgumentException("An idle mode job will not respect any" +
                        " back-off policy, so calling setBackoffCriteria with" +
+13 −3
Original line number Diff line number Diff line
@@ -151,6 +151,7 @@ public final class JobSchedulerService extends com.android.server.SystemService
    StorageController mStorageController;
    /** Need directly for sending uid state changes */
    private BackgroundJobsController mBackgroundJobsController;
    private DeviceIdleJobsController mDeviceIdleJobsController;
    /**
     * Queue of pending jobs. The JobServiceContext class will receive jobs from this list
     * when ready to execute them.
@@ -622,15 +623,24 @@ public final class JobSchedulerService extends com.android.server.SystemService
            if (disabled) {
                cancelJobsForUid(uid, "uid gone");
            }
            synchronized (mLock) {
                mDeviceIdleJobsController.setUidActiveLocked(uid, false);
            }
        }

        @Override public void onUidActive(int uid) throws RemoteException {
            synchronized (mLock) {
                mDeviceIdleJobsController.setUidActiveLocked(uid, true);
            }
        }

        @Override public void onUidIdle(int uid, boolean disabled) {
            if (disabled) {
                cancelJobsForUid(uid, "app uid idle");
            }
            synchronized (mLock) {
                mDeviceIdleJobsController.setUidActiveLocked(uid, false);
            }
        }

        @Override public void onUidCachedChanged(int uid, boolean cached) {
@@ -939,11 +949,11 @@ public final class JobSchedulerService extends com.android.server.SystemService
        mControllers.add(mBatteryController);
        mStorageController = StorageController.get(this);
        mControllers.add(mStorageController);
        mBackgroundJobsController = BackgroundJobsController.get(this);
        mControllers.add(mBackgroundJobsController);
        mControllers.add(BackgroundJobsController.get(this));
        mControllers.add(AppIdleController.get(this));
        mControllers.add(ContentObserverController.get(this));
        mControllers.add(DeviceIdleJobsController.get(this));
        mDeviceIdleJobsController = DeviceIdleJobsController.get(this);
        mControllers.add(mDeviceIdleJobsController);

        // If the job store determined that it can't yet reschedule persisted jobs,
        // we need to start watching the clock.
Loading