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

Commit 7d089050 authored by Shreyas Basarge's avatar Shreyas Basarge Committed by Matthew Williams
Browse files

NPE fix for JobScheduler

Add a null check before setting stop
reason for job parameters.

Bug: 27166522
Change-Id: I8b829c0cf8df7da0b8118ab75779f209d0af1b22
parent 44da2940
Loading
Loading
Loading
Loading
+8 −7
Original line number Original line Diff line number Diff line
@@ -368,6 +368,13 @@ public class JobServiceContext extends IJobCallback.Stub implements ServiceConne
                    }
                    }
                    break;
                    break;
                case MSG_CANCEL:
                case MSG_CANCEL:
                    if (mVerb == VERB_FINISHED) {
                        if (DEBUG) {
                            Slog.d(TAG,
                                   "Trying to process cancel for torn-down context, ignoring.");
                        }
                        return;
                    }
                    mParams.setStopReason(message.arg1);
                    mParams.setStopReason(message.arg1);
                    if (message.arg1 == JobParameters.REASON_PREEMPT) {
                    if (message.arg1 == JobParameters.REASON_PREEMPT) {
                        mPreferredUid = mRunningJob != null ? mRunningJob.getUid() :
                        mPreferredUid = mRunningJob != null ? mRunningJob.getUid() :
@@ -477,12 +484,6 @@ public class JobServiceContext extends IJobCallback.Stub implements ServiceConne
         *     _ENDING     -> No point in doing anything here, so we ignore.
         *     _ENDING     -> No point in doing anything here, so we ignore.
         */
         */
        private void handleCancelH() {
        private void handleCancelH() {
            if (mRunningJob == null) {
                if (DEBUG) {
                    Slog.d(TAG, "Trying to process cancel for torn-down context, ignoring.");
                }
                return;
            }
            if (JobSchedulerService.DEBUG) {
            if (JobSchedulerService.DEBUG) {
                Slog.d(TAG, "Handling cancel for: " + mRunningJob.getJobId() + " "
                Slog.d(TAG, "Handling cancel for: " + mRunningJob.getJobId() + " "
                        + VERB_STRINGS[mVerb]);
                        + VERB_STRINGS[mVerb]);
@@ -510,7 +511,6 @@ public class JobServiceContext extends IJobCallback.Stub implements ServiceConne


        /** Process MSG_TIMEOUT here. */
        /** Process MSG_TIMEOUT here. */
        private void handleOpTimeoutH() {
        private void handleOpTimeoutH() {
            mParams.setStopReason(JobParameters.REASON_TIMEOUT);
            switch (mVerb) {
            switch (mVerb) {
                case VERB_BINDING:
                case VERB_BINDING:
                    Slog.e(TAG, "Time-out while trying to bind " + mRunningJob.toShortString() +
                    Slog.e(TAG, "Time-out while trying to bind " + mRunningJob.toShortString() +
@@ -535,6 +535,7 @@ public class JobServiceContext extends IJobCallback.Stub implements ServiceConne
                    // Not an error - client ran out of time.
                    // Not an error - client ran out of time.
                    Slog.i(TAG, "Client timed out while executing (no jobFinished received)." +
                    Slog.i(TAG, "Client timed out while executing (no jobFinished received)." +
                            " sending onStop. "  + mRunningJob.toShortString());
                            " sending onStop. "  + mRunningJob.toShortString());
                    mParams.setStopReason(JobParameters.REASON_TIMEOUT);
                    sendStopMessageH();
                    sendStopMessageH();
                    break;
                    break;
                default:
                default: