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

Commit 6c5dc642 authored by Kweku Adams's avatar Kweku Adams
Browse files

Removing JobScheduler heartbeat code.

Data shows that the quota based system has a small impact on battery life
while still addressing the core issues we had with the heartbeat system.
We can continue to tweak numbers and make some policy adjustments to the
quota system, but at this point, it appears safe to remove the
heartbeat code.

Bug: 138324538
Test: atest com.android.server.cts.JobSchedulerIncidentTest
Test: atest com.android.server.job.JobSchedulerServiceTest
Test: atest com.android.server.job.JobStoreTest
Test: atest com.android.server.job.controllers.ConnectivityControllerTest
Test: atest com.android.server.job.controllers.JobStatusTest
Test: atest com.android.server.job.controllers.QuotaControllerTest
Test: atest CtsJobSchedulerTestCases
Change-Id: I2b025ca426387ece123c0b8ed8bcc143f6c6d6db
parent 59cd53b1
Loading
Loading
Loading
Loading
+13 −380

File changed.

Preview size limit exceeded, changes collapsed.

+3 −11
Original line number Diff line number Diff line
@@ -340,15 +340,8 @@ public final class JobSchedulerShellCommand extends ShellCommand {
    private int doHeartbeat(PrintWriter pw) throws Exception {
        checkPermission("manipulate scheduler heartbeat");

        final String arg = getNextArg();
        final int numBeats = (arg != null) ? Integer.parseInt(arg) : 0;

        final long ident = Binder.clearCallingIdentity();
        try {
            return mInternal.executeHeartbeatCommand(pw, numBeats);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
        pw.println("Heartbeat command is no longer supported");
        return -1;
    }

    private int triggerDockState(PrintWriter pw) throws Exception {
@@ -401,8 +394,7 @@ public final class JobSchedulerShellCommand extends ShellCommand {
        pw.println("      -u or --user: specify which user's job is to be run; the default is");
        pw.println("         the primary or system user");
        pw.println("  heartbeat [num]");
        pw.println("    With no argument, prints the current standby heartbeat.  With a positive");
        pw.println("    argument, advances the standby heartbeat by that number.");
        pw.println("    No longer used.");
        pw.println("  monitor-battery [on|off]");
        pw.println("    Control monitoring of all battery changes.  Off by default.  Turning");
        pw.println("    on makes get-battery-seq useful.");
+0 −3
Original line number Diff line number Diff line
@@ -285,9 +285,6 @@ public final class JobServiceContext implements ServiceConnection {
            UsageStatsManagerInternal usageStats =
                    LocalServices.getService(UsageStatsManagerInternal.class);
            usageStats.setLastJobRunTime(jobPackage, jobUserId, mExecutionStartTimeElapsed);
            JobSchedulerInternal jobScheduler =
                    LocalServices.getService(JobSchedulerInternal.class);
            jobScheduler.noteJobStart(jobPackage, jobUserId);
            mAvailable = false;
            mStoppedReason = null;
            mStoppedTime = 0;
+2 −3
Original line number Diff line number Diff line
@@ -189,7 +189,7 @@ public final class JobStore {
            if (utcTimes != null) {
                Pair<Long, Long> elapsedRuntimes =
                        convertRtcBoundsToElapsed(utcTimes, elapsedNow);
                JobStatus newJob = new JobStatus(job, job.getBaseHeartbeat(),
                JobStatus newJob = new JobStatus(job,
                        elapsedRuntimes.first, elapsedRuntimes.second,
                        0, job.getLastSuccessfulRunTime(), job.getLastFailedRunTime());
                newJob.prepareLocked(am);
@@ -944,10 +944,9 @@ public final class JobStore {
            JobSchedulerInternal service = LocalServices.getService(JobSchedulerInternal.class);
            final int appBucket = JobSchedulerService.standbyBucketForPackage(sourcePackageName,
                    sourceUserId, elapsedNow);
            long currentHeartbeat = service != null ? service.currentHeartbeat() : 0;
            JobStatus js = new JobStatus(
                    jobBuilder.build(), uid, sourcePackageName, sourceUserId,
                    appBucket, currentHeartbeat, sourceTag,
                    appBucket, sourceTag,
                    elapsedRuntimes.first, elapsedRuntimes.second,
                    lastSuccessfulRunTime, lastFailedRunTime,
                    (rtcIsGood) ? null : rtcRuntimes, internalFlags);
+1 −35
Original line number Diff line number Diff line
@@ -47,7 +47,6 @@ import com.android.internal.util.IndentingPrintWriter;
import com.android.server.LocalServices;
import com.android.server.job.JobSchedulerService;
import com.android.server.job.JobSchedulerService.Constants;
import com.android.server.job.JobServiceContext;
import com.android.server.job.StateControllerProto;
import com.android.server.net.NetworkPolicyManagerInternal;

@@ -88,8 +87,6 @@ public final class ConnectivityController extends StateController implements
    @GuardedBy("mLock")
    private final ArraySet<Network> mAvailableNetworks = new ArraySet<>();

    private boolean mUseQuotaLimit;

    private static final int MSG_DATA_SAVER_TOGGLED = 0;
    private static final int MSG_UID_RULES_CHANGES = 1;
    private static final int MSG_REEVALUATE_JOBS = 2;
@@ -110,8 +107,6 @@ public final class ConnectivityController extends StateController implements
        mConnManager.registerNetworkCallback(request, mNetworkCallback);

        mNetPolicyManager.registerListener(mNetPolicyListener);

        mUseQuotaLimit = !mConstants.USE_HEARTBEATS;
    }

    @GuardedBy("mLock")
@@ -142,24 +137,6 @@ public final class ConnectivityController extends StateController implements
        }
    }

    @GuardedBy("mLock")
    @Override
    public void onConstantsUpdatedLocked() {
        if (mConstants.USE_HEARTBEATS) {
            // App idle exceptions are only requested for the rolling quota system.
            if (DEBUG) Slog.i(TAG, "Revoking all standby exceptions");
            for (int i = 0; i < mRequestedWhitelistJobs.size(); ++i) {
                int uid = mRequestedWhitelistJobs.keyAt(i);
                mNetPolicyManagerInternal.setAppIdleWhitelist(uid, false);
            }
            mRequestedWhitelistJobs.clear();
        }
        if (mUseQuotaLimit == mConstants.USE_HEARTBEATS) {
            mUseQuotaLimit = !mConstants.USE_HEARTBEATS;
            mHandler.obtainMessage(MSG_REEVALUATE_JOBS).sendToTarget();
        }
    }

    /**
     * Returns true if the job's requested network is available. This DOES NOT necesarilly mean
     * that the UID has been granted access to the network.
@@ -237,11 +214,6 @@ public final class ConnectivityController extends StateController implements
    @GuardedBy("mLock")
    @Override
    public void evaluateStateLocked(JobStatus jobStatus) {
        if (mConstants.USE_HEARTBEATS) {
            // This should only be used for the rolling quota system.
            return;
        }

        if (!jobStatus.hasConnectivityConstraint()) {
            return;
        }
@@ -263,9 +235,6 @@ public final class ConnectivityController extends StateController implements
    @GuardedBy("mLock")
    @Override
    public void reevaluateStateLocked(final int uid) {
        if (mConstants.USE_HEARTBEATS) {
            return;
        }
        // Check if we still need a connectivity exception in case the JobService was disabled.
        ArraySet<JobStatus> jobs = mTrackedJobs.get(uid);
        if (jobs == null) {
@@ -329,9 +298,7 @@ public final class ConnectivityController extends StateController implements
     */
    private boolean isInsane(JobStatus jobStatus, Network network,
            NetworkCapabilities capabilities, Constants constants) {
        final long maxJobExecutionTimeMs = mUseQuotaLimit
                ? mService.getMaxJobExecutionTimeMs(jobStatus)
                : JobServiceContext.EXECUTING_TIMESLICE_MILLIS;
        final long maxJobExecutionTimeMs = mService.getMaxJobExecutionTimeMs(jobStatus);

        final long downloadBytes = jobStatus.getEstimatedNetworkDownloadBytes();
        if (downloadBytes != JobInfo.NETWORK_BYTES_UNKNOWN) {
@@ -617,7 +584,6 @@ public final class ConnectivityController extends StateController implements
    @Override
    public void dumpControllerStateLocked(IndentingPrintWriter pw,
            Predicate<JobStatus> predicate) {
        pw.print("mUseQuotaLimit="); pw.println(mUseQuotaLimit);

        if (mRequestedWhitelistJobs.size() > 0) {
            pw.print("Requested standby exceptions:");
Loading