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

Commit 7ab40254 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fix issue #29371078: Foreground jobs should not count...

...as active for idle maintenance

Nor jobs of whitelisted apps.

Now they don't.

Also remove the no longer used "active download" tracking code.

Change-Id: I553197801f6eabaf15716f3201dd65257a0d4e94
parent d5f7bf80
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -38,8 +38,6 @@ interface IDeviceIdleController {
    long addPowerSaveTempWhitelistAppForMms(String name, int userId, String reason);
    long addPowerSaveTempWhitelistAppForSms(String name, int userId, String reason);
    void exitIdle(String reason);
    void downloadServiceActive(IBinder token);
    void downloadServiceInactive();
    boolean registerMaintenanceActivityListener(IMaintenanceActivityListener listener);
    void unregisterMaintenanceActivityListener(IMaintenanceActivityListener listener);
}
+4 −55
Original line number Diff line number Diff line
@@ -212,7 +212,6 @@ public class DeviceIdleController extends SystemService

    private int mActiveIdleOpCount;
    private PowerManager.WakeLock mActiveIdleWakeLock;
    private IBinder mDownloadServiceActive;
    private boolean mJobsActive;
    private boolean mAlarmsActive;
    private boolean mReportedMaintenanceActivity;
@@ -607,7 +606,7 @@ public class DeviceIdleController extends SystemService
         * This is the minimum amount of time that we will stay in maintenance mode after
         * a light doze.  We have this minimum to allow various things to respond to switching
         * in to maintenance mode and scheduling their work -- otherwise we may
         * see there is nothing to do (no jobs or downloads pending) and go out of maintenance
         * see there is nothing to do (no jobs pending) and go out of maintenance
         * mode immediately.
         * @see Settings.Global#DEVICE_IDLE_CONSTANTS
         * @see #KEY_MIN_LIGHT_MAINTENANCE_TIME
@@ -618,7 +617,7 @@ public class DeviceIdleController extends SystemService
         * This is the minimum amount of time that we will stay in maintenance mode after
         * a full doze.  We have this minimum to allow various things to respond to switching
         * in to maintenance mode and scheduling their work -- otherwise we may
         * see there is nothing to do (no jobs or downloads pending) and go out of maintenance
         * see there is nothing to do (no jobs pending) and go out of maintenance
         * mode immediately.
         * @see Settings.Global#DEVICE_IDLE_CONSTANTS
         * @see #KEY_MIN_DEEP_MAINTENANCE_TIME
@@ -1220,28 +1219,6 @@ public class DeviceIdleController extends SystemService
            }
        }

        @Override public void downloadServiceActive(IBinder token) {
            getContext().enforceCallingOrSelfPermission(
                    "android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS", null);
            long ident = Binder.clearCallingIdentity();
            try {
                DeviceIdleController.this.downloadServiceActive(token);
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }

        @Override public void downloadServiceInactive() {
            getContext().enforceCallingOrSelfPermission(
                    "android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS", null);
            long ident = Binder.clearCallingIdentity();
            try {
                DeviceIdleController.this.downloadServiceInactive();
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }

        @Override public boolean registerMaintenanceActivityListener(
                IMaintenanceActivityListener listener) {
            return DeviceIdleController.this.registerMaintenanceActivityListener(listener);
@@ -2086,30 +2063,6 @@ public class DeviceIdleController extends SystemService
        }
    }

    void downloadServiceActive(IBinder token) {
        synchronized (this) {
            mDownloadServiceActive = token;
            reportMaintenanceActivityIfNeededLocked();
            try {
                token.linkToDeath(new IBinder.DeathRecipient() {
                    @Override public void binderDied() {
                        downloadServiceInactive();
                    }
                }, 0);
            } catch (RemoteException e) {
                mDownloadServiceActive = null;
            }
        }
    }

    void downloadServiceInactive() {
        synchronized (this) {
            mDownloadServiceActive = null;
            reportMaintenanceActivityIfNeededLocked();
            exitMaintenanceEarlyIfNeededLocked();
        }
    }

    void setJobsActive(boolean active) {
        synchronized (this) {
            mJobsActive = active;
@@ -2143,7 +2096,7 @@ public class DeviceIdleController extends SystemService
    }

    void reportMaintenanceActivityIfNeededLocked() {
        boolean active = mJobsActive | (mDownloadServiceActive != null);
        boolean active = mJobsActive;
        if (active == mReportedMaintenanceActivity) {
            return;
        }
@@ -2154,8 +2107,7 @@ public class DeviceIdleController extends SystemService
    }

    boolean isOpsInactiveLocked() {
        return mActiveIdleOpCount <= 0 && mDownloadServiceActive == null
                && !mJobsActive && !mAlarmsActive;
        return mActiveIdleOpCount <= 0 && !mJobsActive && !mAlarmsActive;
    }

    void exitMaintenanceEarlyIfNeededLocked() {
@@ -3053,9 +3005,6 @@ public class DeviceIdleController extends SystemService
            if (mAlarmsActive) {
                pw.print("  mAlarmsActive="); pw.println(mAlarmsActive);
            }
            if (mDownloadServiceActive != null) {
                pw.print("  mDownloadServiceActive="); pw.println(mDownloadServiceActive);
            }
        }
    }

+7 −2
Original line number Diff line number Diff line
@@ -692,8 +692,13 @@ public final class JobSchedulerService extends com.android.server.SystemService
        boolean active = mPendingJobs.size() > 0;
        if (mPendingJobs.size() <= 0) {
            for (int i=0; i<mActiveServices.size(); i++) {
                JobServiceContext jsc = mActiveServices.get(i);
                if (jsc.getRunningJob() != null) {
                final JobServiceContext jsc = mActiveServices.get(i);
                final JobStatus job = jsc.getRunningJob();
                if (job != null
                        && (job.getJob().getFlags() & JobInfo.FLAG_WILL_BE_FOREGROUND) == 0
                        && !job.dozeWhitelisted) {
                    // We will report active if we have a job running and it is not an exception
                    // due to being in the foreground or whitelisted.
                    active = true;
                    break;
                }
+5 −2
Original line number Diff line number Diff line
@@ -142,8 +142,11 @@ public class AppIdleController extends StateController {
                UserHandle.formatUid(pw, jobStatus.getSourceUid());
                pw.print(": ");
                pw.print(jobStatus.getSourcePackageName());
                pw.print(", runnable=");
                pw.println((jobStatus.satisfiedConstraints&JobStatus.CONSTRAINT_APP_NOT_IDLE) != 0);
                if ((jobStatus.satisfiedConstraints&JobStatus.CONSTRAINT_APP_NOT_IDLE) != 0) {
                    pw.println(" RUNNABLE");
                } else {
                    pw.println(" WAITING");
                }
            }
        });
    }
+10 −5
Original line number Diff line number Diff line
@@ -157,8 +157,9 @@ public class DeviceIdleJobsController extends StateController {
    }

    private void updateTaskStateLocked(JobStatus task) {
        boolean enableTask = !mDeviceIdleMode || isWhitelistedLocked(task);
        task.setDeviceNotDozingConstraintSatisfied(enableTask);
        final boolean whitelisted = isWhitelistedLocked(task);
        final boolean enableTask = !mDeviceIdleMode || whitelisted;
        task.setDeviceNotDozingConstraintSatisfied(enableTask, whitelisted);
    }

    @Override
@@ -186,9 +187,13 @@ public class DeviceIdleJobsController extends StateController {
                UserHandle.formatUid(pw, jobStatus.getSourceUid());
                pw.print(": ");
                pw.print(jobStatus.getSourcePackageName());
                pw.print(", runnable=");
                pw.println((jobStatus.satisfiedConstraints
                        & JobStatus.CONSTRAINT_DEVICE_NOT_DOZING) != 0);
                pw.print((jobStatus.satisfiedConstraints
                        & JobStatus.CONSTRAINT_DEVICE_NOT_DOZING) != 0
                                ? " RUNNABLE" : " WAITING");
                if (jobStatus.dozeWhitelisted) {
                    pw.print(" WHITELISTED");
                }
                pw.println();
            }
        });
    }
Loading