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

Commit a1e75deb authored by Sanath Kumar's avatar Sanath Kumar
Browse files

Use mVerb to track job execution state in system for consistency.

System currently uses `mRunningJob` to track job execution as a
simple binary (executing/not executing) state. However, `mRunningJob`
doesn't accurately reflect transient states, such as during initial
binding for `onStartJob` or when stopping due to `onStopJob`. These
granular state changes, from non-executing to executing, are tracked by
`mVerb`. While `mRunningJob` is functional, using `mVerb` for
consistency with other job related API implementation related to job
state checks would provide a more accurate and consistent reflection of
the job's lifecycle within the system.

Test: atest CtsJobSchedulerTestCases
Test: atest FrameworksMockingServicesTests
Bug: 372529068
Flag: android.app.job.handle_abandoned_jobs

Change-Id: Ib8077f601b9f476a71bbb1bd948aba4698d2fbc2
parent aaa454ed
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -809,7 +809,11 @@ public final class JobServiceContext implements ServiceConnection {
                if (!verifyCallerLocked(cb)) {
                    return;
                }

                if (mVerb != VERB_EXECUTING) {
                    // Any state other than executing means the
                    // job is in transient or stopped state
                    return;
                }
                executing = getRunningJobLocked();
            }
            if (executing != null && jobId == executing.getJobId()) {
+19 −0
Original line number Diff line number Diff line
@@ -276,6 +276,7 @@ public class JobServiceContextTest {
        final int jobId = 123;
        mJobServiceContext.setRunningJobLockedForTest(mMockJobStatus);
        mJobServiceContext.setRunningCallbackLockedForTest(mMockJobCallback);
        mJobServiceContext.mVerb = JobServiceContext.VERB_EXECUTING;
        doReturn(jobId).when(mMockJobStatus).getJobId();

        mJobServiceContext.doHandleAbandonedJob(mMockJobCallback, jobId);
@@ -296,7 +297,25 @@ public class JobServiceContextTest {
        mJobServiceContext.setRunningCallbackLockedForTest(mMockJobCallback);

        mJobServiceContext.doHandleAbandonedJob(mMockJobCallback, jobId);
        verify(mMockJobStatus, never()).setAbandoned(true);

        mJobServiceContext.setRunningJobLockedForTest(mMockJobStatus);
        doReturn(jobId).when(mMockJobStatus).getJobId();

        mJobServiceContext.mVerb = JobServiceContext.VERB_BINDING;
        mJobServiceContext.doHandleAbandonedJob(mMockJobCallback, jobId);
        verify(mMockJobStatus, never()).setAbandoned(true);

        mJobServiceContext.mVerb = JobServiceContext.VERB_STARTING;
        mJobServiceContext.doHandleAbandonedJob(mMockJobCallback, jobId);
        verify(mMockJobStatus, never()).setAbandoned(true);

        mJobServiceContext.mVerb = JobServiceContext.VERB_STOPPING;
        mJobServiceContext.doHandleAbandonedJob(mMockJobCallback, jobId);
        verify(mMockJobStatus, never()).setAbandoned(true);

        mJobServiceContext.mVerb = JobServiceContext.VERB_FINISHED;
        mJobServiceContext.doHandleAbandonedJob(mMockJobCallback, jobId);
        verify(mMockJobStatus, never()).setAbandoned(true);
    }