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

Commit 5e272ac5 authored by Sanath Kumar's avatar Sanath Kumar
Browse files

Rename empty to abandoned Jobs

This is to better reflect the purpose of this feature.
Abandoned jobs cannot be accurately determined. Hence we
cannot force finish them. However we can report them to
the client and take less disruptive actions post detection.

Additionally, change the feature flag to roll out the
modified version of this feature

bug: 372529068
Test: Existing CTS and unit tests pass
Flag: android.app.job.handle_abandoned_jobs
Change-Id: Ic6dc8bbe66cd9011da098fe5d6c8255f82d4c5e2
parent a0406c63
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -25,10 +25,10 @@ flag {
}

flag {
   name: "cleanup_empty_jobs"
   name: "handle_abandoned_jobs"
   namespace: "backstage_power"
   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"
   description: "Detect, report and take action on jobs that maybe abandoned by the app without calling jobFinished."
   bug: "372529068"
}

flag {
+4 −3
Original line number Diff line number Diff line
@@ -87,11 +87,12 @@ interface IJobCallback {
    void jobFinished(int jobId, boolean reschedule);

    /*
     * Inform JobScheduler to force finish this job because the client has lost
     * the job handle. jobFinished can no longer be called from the client.
     * Inform JobScheduler that this job may have been abandoned because the client process
     * has lost strong references to the JobParameters object without calling jobFinished.
     *
     * @param jobId Unique integer used to identify this job
     */
    void forceJobFinished(int jobId);
    void handleAbandonedJob(int jobId);

    /*
     * Inform JobScheduler of a change in the estimated transfer payload.
+2 −2
Original line number Diff line number Diff line
@@ -33,8 +33,8 @@ import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.Process;
import android.os.RemoteException;
import android.system.SystemCleaner;
import android.util.Log;

@@ -770,7 +770,7 @@ public class JobParameters implements Parcelable {
                return;
            }
            try {
                mCallback.forceJobFinished(mJobId);
                mCallback.handleAbandonedJob(mJobId);
            } catch (Exception e) {
                Log.wtf(TAG, "Could not destroy running job", e);
            }
+3 −3
Original line number Diff line number Diff line
@@ -165,11 +165,11 @@ public abstract class JobServiceEngine {
                case MSG_EXECUTE_JOB: {
                    final JobParameters params = (JobParameters) msg.obj;
                    try {
                        if (Flags.cleanupEmptyJobs()) {
                        if (Flags.handleAbandonedJobs()) {
                            params.enableCleaner();
                        }
                        boolean workOngoing = JobServiceEngine.this.onStartJob(params);
                        if (Flags.cleanupEmptyJobs() && !workOngoing) {
                        if (Flags.handleAbandonedJobs() && !workOngoing) {
                            params.disableCleaner();
                        }
                        ackStartMessage(params, workOngoing);
@@ -196,7 +196,7 @@ public abstract class JobServiceEngine {
                    IJobCallback callback = params.getCallback();
                    if (callback != null) {
                        try {
                            if (Flags.cleanupEmptyJobs()) {
                            if (Flags.handleAbandonedJobs()) {
                                params.disableCleaner();
                            }
                            callback.jobFinished(params.getJobId(), needsReschedule);
+7 −7
Original line number Diff line number Diff line
@@ -129,8 +129,8 @@ public final class JobServiceContext implements ServiceConnection {
    private static final String[] VERB_STRINGS = {
            "VERB_BINDING", "VERB_STARTING", "VERB_EXECUTING", "VERB_STOPPING", "VERB_FINISHED"
    };
    private static final String TRACE_JOB_FORCE_FINISHED_PREFIX = "forceJobFinished:";
    private static final String TRACE_JOB_FORCE_FINISHED_DELIMITER = "#";
    private static final String TRACE_ABANDONED_JOB = "abandonedJob:";
    private static final String TRACE_ABANDONED_JOB_DELIMITER = "#";

    // States that a job occupies while interacting with the client.
    static final int VERB_BINDING = 0;
@@ -294,8 +294,8 @@ public final class JobServiceContext implements ServiceConnection {
        }

        @Override
        public void forceJobFinished(int jobId) {
            doForceJobFinished(this, jobId);
        public void handleAbandonedJob(int jobId) {
            doHandleAbandonedJob(this, jobId);
        }

        @Override
@@ -773,7 +773,7 @@ public final class JobServiceContext implements ServiceConnection {
     * This method just adds traces to evaluate jobs that leak jobparameters at the client.
     * It does not stop the job.
     */
    void doForceJobFinished(JobCallback cb, int jobId) {
    void doHandleAbandonedJob(JobCallback cb, int jobId) {
        final long ident = Binder.clearCallingIdentity();
        try {
            final JobStatus executing;
@@ -787,9 +787,9 @@ public final class JobServiceContext implements ServiceConnection {
            }
            if (executing != null && jobId == executing.getJobId()) {
                final StringBuilder stateSuffix = new StringBuilder();
                stateSuffix.append(TRACE_JOB_FORCE_FINISHED_PREFIX);
                stateSuffix.append(TRACE_ABANDONED_JOB);
                stateSuffix.append(executing.getBatteryName());
                stateSuffix.append(TRACE_JOB_FORCE_FINISHED_DELIMITER);
                stateSuffix.append(TRACE_ABANDONED_JOB_DELIMITER);
                stateSuffix.append(executing.getJobId());
                Trace.instant(Trace.TRACE_TAG_POWER, stateSuffix.toString());
            }
Loading