diff --git a/apex/blobstore/service/java/com/android/server/blob/BlobStoreIdleJobService.java b/apex/blobstore/service/java/com/android/server/blob/BlobStoreIdleJobService.java index e65abcfba3e45..7c67ce424a250 100644 --- a/apex/blobstore/service/java/com/android/server/blob/BlobStoreIdleJobService.java +++ b/apex/blobstore/service/java/com/android/server/blob/BlobStoreIdleJobService.java @@ -49,7 +49,8 @@ public class BlobStoreIdleJobService extends JobService { public boolean onStopJob(final JobParameters params) { Slog.d(TAG, "Idle maintenance job is stopped; id=" + params.getJobId() + ", reason=" - + JobParameters.getLegacyReasonCodeDescription(params.getLegacyStopReason())); + + JobParameters.getInternalReasonCodeDescription( + params.getInternalStopReasonCode())); return false; } diff --git a/apex/jobscheduler/framework/java/android/app/job/JobParameters.java b/apex/jobscheduler/framework/java/android/app/job/JobParameters.java index e1bfde15fa0a9..48b62a607a5e6 100644 --- a/apex/jobscheduler/framework/java/android/app/job/JobParameters.java +++ b/apex/jobscheduler/framework/java/android/app/job/JobParameters.java @@ -44,36 +44,53 @@ import java.lang.annotation.RetentionPolicy; public class JobParameters implements Parcelable { /** @hide */ - public static final int REASON_CANCELED = JobProtoEnums.STOP_REASON_CANCELLED; // 0. + public static final int INTERNAL_STOP_REASON_CANCELED = + JobProtoEnums.STOP_REASON_CANCELLED; // 0. /** @hide */ - public static final int REASON_CONSTRAINTS_NOT_SATISFIED = - JobProtoEnums.STOP_REASON_CONSTRAINTS_NOT_SATISFIED; //1. + public static final int INTERNAL_STOP_REASON_CONSTRAINTS_NOT_SATISFIED = + JobProtoEnums.STOP_REASON_CONSTRAINTS_NOT_SATISFIED; // 1. /** @hide */ - public static final int REASON_PREEMPT = JobProtoEnums.STOP_REASON_PREEMPT; // 2. + public static final int INTERNAL_STOP_REASON_PREEMPT = + JobProtoEnums.STOP_REASON_PREEMPT; // 2. + /** + * The job ran for at least its minimum execution limit. + * @hide + */ + public static final int INTERNAL_STOP_REASON_TIMEOUT = + JobProtoEnums.STOP_REASON_TIMEOUT; // 3. /** @hide */ - public static final int REASON_TIMEOUT = JobProtoEnums.STOP_REASON_TIMEOUT; // 3. + public static final int INTERNAL_STOP_REASON_DEVICE_IDLE = + JobProtoEnums.STOP_REASON_DEVICE_IDLE; // 4. /** @hide */ - public static final int REASON_DEVICE_IDLE = JobProtoEnums.STOP_REASON_DEVICE_IDLE; // 4. - /** @hide */ - public static final int REASON_DEVICE_THERMAL = JobProtoEnums.STOP_REASON_DEVICE_THERMAL; // 5. + public static final int INTERNAL_STOP_REASON_DEVICE_THERMAL = + JobProtoEnums.STOP_REASON_DEVICE_THERMAL; // 5. /** * The job is in the {@link android.app.usage.UsageStatsManager#STANDBY_BUCKET_RESTRICTED} * bucket. * * @hide */ - public static final int REASON_RESTRICTED_BUCKET = + public static final int INTERNAL_STOP_REASON_RESTRICTED_BUCKET = JobProtoEnums.STOP_REASON_RESTRICTED_BUCKET; // 6. /** * The app was uninstalled. * @hide */ - public static final int DEBUG_REASON_UNINSTALL = 7; + public static final int INTERNAL_STOP_REASON_UNINSTALL = 7; /** * The app's data was cleared. * @hide */ - public static final int DEBUG_REASON_DATA_CLEARED = 8; + public static final int INTERNAL_STOP_REASON_DATA_CLEARED = 8; + /** + * @hide + */ + public static final int INTERNAL_STOP_REASON_RTC_UPDATED = 9; + /** + * The app called jobFinished() on its own. + * @hide + */ + public static final int INTERNAL_STOP_REASON_SUCCESSFUL_FINISH = 10; /** * All the stop reason codes. This should be regarded as an immutable array at runtime. @@ -85,13 +102,13 @@ public class JobParameters implements Parcelable { * @hide */ public static final int[] JOB_STOP_REASON_CODES = { - REASON_CANCELED, - REASON_CONSTRAINTS_NOT_SATISFIED, - REASON_PREEMPT, - REASON_TIMEOUT, - REASON_DEVICE_IDLE, - REASON_DEVICE_THERMAL, - REASON_RESTRICTED_BUCKET, + INTERNAL_STOP_REASON_CANCELED, + INTERNAL_STOP_REASON_CONSTRAINTS_NOT_SATISFIED, + INTERNAL_STOP_REASON_PREEMPT, + INTERNAL_STOP_REASON_TIMEOUT, + INTERNAL_STOP_REASON_DEVICE_IDLE, + INTERNAL_STOP_REASON_DEVICE_THERMAL, + INTERNAL_STOP_REASON_RESTRICTED_BUCKET, }; /** @@ -99,21 +116,24 @@ public class JobParameters implements Parcelable { */ // TODO(142420609): make it @SystemApi for mainline @NonNull - public static String getLegacyReasonCodeDescription(int reasonCode) { + public static String getInternalReasonCodeDescription(int reasonCode) { switch (reasonCode) { - case REASON_CANCELED: return "canceled"; - case REASON_CONSTRAINTS_NOT_SATISFIED: return "constraints"; - case REASON_PREEMPT: return "preempt"; - case REASON_TIMEOUT: return "timeout"; - case REASON_DEVICE_IDLE: return "device_idle"; - case REASON_DEVICE_THERMAL: return "thermal"; - case REASON_RESTRICTED_BUCKET: return "restricted_bucket"; + case INTERNAL_STOP_REASON_CANCELED: return "canceled"; + case INTERNAL_STOP_REASON_CONSTRAINTS_NOT_SATISFIED: return "constraints"; + case INTERNAL_STOP_REASON_PREEMPT: return "preempt"; + case INTERNAL_STOP_REASON_TIMEOUT: return "timeout"; + case INTERNAL_STOP_REASON_DEVICE_IDLE: return "device_idle"; + case INTERNAL_STOP_REASON_DEVICE_THERMAL: return "thermal"; + case INTERNAL_STOP_REASON_RESTRICTED_BUCKET: return "restricted_bucket"; + case INTERNAL_STOP_REASON_UNINSTALL: return "uninstall"; + case INTERNAL_STOP_REASON_DATA_CLEARED: return "data_cleared"; + case INTERNAL_STOP_REASON_RTC_UPDATED: return "rtc_updated"; + case INTERNAL_STOP_REASON_SUCCESSFUL_FINISH: return "successful_finish"; default: return "unknown:" + reasonCode; } } /** @hide */ - // TODO: move current users of legacy reasons to new public reasons @NonNull public static int[] getJobStopReasonCodes() { return JOB_STOP_REASON_CODES; @@ -241,7 +261,7 @@ public class JobParameters implements Parcelable { private final Network network; private int mStopReason = STOP_REASON_UNDEFINED; - private int mLegacyStopReason; // Default value of stopReason is REASON_CANCELED + private int mInternalStopReason; // Default value is REASON_CANCELED private String debugStopReason; // Human readable stop reason for debugging. /** @hide */ @@ -280,8 +300,8 @@ public class JobParameters implements Parcelable { } /** @hide */ - public int getLegacyStopReason() { - return mLegacyStopReason; + public int getInternalStopReasonCode() { + return mInternalStopReason; } /** @@ -502,15 +522,15 @@ public class JobParameters implements Parcelable { network = null; } mStopReason = in.readInt(); - mLegacyStopReason = in.readInt(); + mInternalStopReason = in.readInt(); debugStopReason = in.readString(); } /** @hide */ - public void setStopReason(@StopReason int reason, int legacyStopReason, + public void setStopReason(@StopReason int reason, int internalStopReason, String debugStopReason) { mStopReason = reason; - mLegacyStopReason = legacyStopReason; + mInternalStopReason = internalStopReason; this.debugStopReason = debugStopReason; } @@ -543,7 +563,7 @@ public class JobParameters implements Parcelable { dest.writeInt(0); } dest.writeInt(mStopReason); - dest.writeInt(mLegacyStopReason); + dest.writeInt(mInternalStopReason); dest.writeString(debugStopReason); } diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java b/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java index e60a5d189ea65..5a13a849a352c 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java +++ b/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java @@ -695,7 +695,7 @@ class JobConcurrencyManager { // preferredUid will be set to uid of currently running job. activeServices.get(i).cancelExecutingJobLocked( preemptReasonCodeForContext[i], - JobParameters.REASON_PREEMPT, preemptReasonForContext[i]); + JobParameters.INTERNAL_STOP_REASON_PREEMPT, preemptReasonForContext[i]); // Only preserve the UID if we're preempting for the same UID. If we're stopping // the job because something is pending (eg. EJs), then we shouldn't preserve // the UID. @@ -727,7 +727,7 @@ class JobConcurrencyManager { if (jobStatus != null && !jsc.isWithinExecutionGuaranteeTime()) { jsc.cancelExecutingJobLocked(JobParameters.STOP_REASON_DEVICE_STATE, - JobParameters.REASON_TIMEOUT, debugReason); + JobParameters.INTERNAL_STOP_REASON_TIMEOUT, debugReason); } } } diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobPackageTracker.java b/apex/jobscheduler/service/java/com/android/server/job/JobPackageTracker.java index 02f9129198780..1f0900d53e7fe 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/JobPackageTracker.java +++ b/apex/jobscheduler/service/java/com/android/server/job/JobPackageTracker.java @@ -374,7 +374,7 @@ public final class JobPackageTracker { pw.print(pe.stopReasons.valueAt(k)); pw.print("x "); pw.print(JobParameters - .getLegacyReasonCodeDescription(pe.stopReasons.keyAt(k))); + .getInternalReasonCodeDescription(pe.stopReasons.keyAt(k))); } pw.println(); } @@ -621,7 +621,7 @@ public final class JobPackageTracker { if (reason != null) { pw.print(mEventReasons[index]); } else { - pw.print(JobParameters.getLegacyReasonCodeDescription( + pw.print(JobParameters.getInternalReasonCodeDescription( (mEventCmds[index] & EVENT_STOP_REASON_MASK) >> EVENT_STOP_REASON_SHIFT)); } diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java index 1eebae83bc13d..313cd208f7fba 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java +++ b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java @@ -758,7 +758,7 @@ public class JobSchedulerService extends com.android.server.SystemService // put USER instead of UNINSTALL or DISABLED. cancelJobsForPackageAndUidLocked(pkgName, pkgUid, JobParameters.STOP_REASON_USER, - JobParameters.DEBUG_REASON_UNINSTALL, + JobParameters.INTERNAL_STOP_REASON_UNINSTALL, "app disabled"); } } @@ -809,7 +809,7 @@ public class JobSchedulerService extends com.android.server.SystemService // be fine to just put USER instead of UNINSTALL or DISABLED. cancelJobsForPackageAndUidLocked(pkgName, uidRemoved, JobParameters.STOP_REASON_USER, - JobParameters.DEBUG_REASON_UNINSTALL, "app uninstalled"); + JobParameters.INTERNAL_STOP_REASON_UNINSTALL, "app uninstalled"); for (int c = 0; c < mControllers.size(); ++c) { mControllers.get(c).onAppRemovedLocked(pkgName, pkgUid); } @@ -863,7 +863,8 @@ public class JobSchedulerService extends com.android.server.SystemService } synchronized (mLock) { cancelJobsForPackageAndUidLocked(pkgName, pkgUid, - JobParameters.STOP_REASON_USER, JobParameters.REASON_CANCELED, + JobParameters.STOP_REASON_USER, + JobParameters.INTERNAL_STOP_REASON_CANCELED, "app force stopped"); } } @@ -1074,7 +1075,7 @@ public class JobSchedulerService extends com.android.server.SystemService if (toCancel != null) { // Implicitly replaces the existing job record with the new instance cancelJobImplLocked(toCancel, jobStatus, JobParameters.STOP_REASON_CANCELLED_BY_APP, - JobParameters.REASON_CANCELED, "job rescheduled by app"); + JobParameters.INTERNAL_STOP_REASON_CANCELED, "job rescheduled by app"); } else { startTrackingJobLocked(jobStatus, null); } @@ -1155,7 +1156,7 @@ public class JobSchedulerService extends com.android.server.SystemService // but since this is a user-initiated action, it should be fine to just put USER // instead of UNINSTALL or DISABLED. cancelJobImplLocked(toRemove, null, JobParameters.STOP_REASON_USER, - JobParameters.DEBUG_REASON_UNINSTALL, "user removed"); + JobParameters.INTERNAL_STOP_REASON_UNINSTALL, "user removed"); } } @@ -1167,7 +1168,7 @@ public class JobSchedulerService extends com.android.server.SystemService } private void cancelJobsForPackageAndUidLocked(String pkgName, int uid, - @JobParameters.StopReason int reason, int debugReasonCode, String debugReason) { + @JobParameters.StopReason int reason, int internalReasonCode, String debugReason) { if ("android".equals(pkgName)) { Slog.wtfStack(TAG, "Can't cancel all jobs for system package"); return; @@ -1176,7 +1177,7 @@ public class JobSchedulerService extends com.android.server.SystemService for (int i = jobsForUid.size() - 1; i >= 0; i--) { final JobStatus job = jobsForUid.get(i); if (job.getSourcePackageName().equals(pkgName)) { - cancelJobImplLocked(job, null, reason, debugReasonCode, debugReason); + cancelJobImplLocked(job, null, reason, internalReasonCode, debugReason); } } } @@ -1189,7 +1190,7 @@ public class JobSchedulerService extends com.android.server.SystemService * @param uid Uid to check against for removal of a job. */ public boolean cancelJobsForUid(int uid, @JobParameters.StopReason int reason, - int debugReasonCode, String debugReason) { + int internalReasonCode, String debugReason) { if (uid == Process.SYSTEM_UID) { Slog.wtfStack(TAG, "Can't cancel all jobs for system uid"); return false; @@ -1200,7 +1201,7 @@ public class JobSchedulerService extends com.android.server.SystemService final List jobsForUid = mJobs.getJobsByUid(uid); for (int i = 0; i < jobsForUid.size(); i++) { JobStatus toRemove = jobsForUid.get(i); - cancelJobImplLocked(toRemove, null, reason, debugReasonCode, debugReason); + cancelJobImplLocked(toRemove, null, reason, internalReasonCode, debugReason); jobsCanceled = true; } } @@ -1222,7 +1223,7 @@ public class JobSchedulerService extends com.android.server.SystemService toCancel = mJobs.getJobByUidAndJobId(uid, jobId); if (toCancel != null) { cancelJobImplLocked(toCancel, null, reason, - JobParameters.REASON_CANCELED, + JobParameters.INTERNAL_STOP_REASON_CANCELED, "cancel() called by app, callingUid=" + callingUid + " uid=" + uid + " jobId=" + jobId); } @@ -1237,7 +1238,7 @@ public class JobSchedulerService extends com.android.server.SystemService * currently scheduled jobs. */ private void cancelJobImplLocked(JobStatus cancelled, JobStatus incomingJob, - @JobParameters.StopReason int reason, int debugReasonCode, String debugReason) { + @JobParameters.StopReason int reason, int internalReasonCode, String debugReason) { if (DEBUG) Slog.d(TAG, "CANCEL: " + cancelled.toShortString()); cancelled.unprepareLocked(); stopTrackingJobLocked(cancelled, incomingJob, true /* writeBack */); @@ -1246,7 +1247,7 @@ public class JobSchedulerService extends com.android.server.SystemService mJobPackageTracker.noteNonpending(cancelled); } // Cancel if running. - stopJobOnServiceContextLocked(cancelled, reason, debugReasonCode, debugReason); + stopJobOnServiceContextLocked(cancelled, reason, internalReasonCode, debugReason); // If this is a replacement, bring in the new version of the job if (incomingJob != null) { if (DEBUG) Slog.i(TAG, "Tracking replacement job " + incomingJob.toShortString()); @@ -1297,7 +1298,7 @@ public class JobSchedulerService extends com.android.server.SystemService final JobStatus executing = jsc.getRunningJobLocked(); if (executing != null && !executing.canRunInDoze()) { jsc.cancelExecutingJobLocked(JobParameters.STOP_REASON_DEVICE_STATE, - JobParameters.REASON_DEVICE_IDLE, + JobParameters.INTERNAL_STOP_REASON_DEVICE_IDLE, "cancelled due to doze"); } } @@ -1496,7 +1497,7 @@ public class JobSchedulerService extends com.android.server.SystemService Slog.v(TAG, " replacing " + oldJob + " with " + newJob); } cancelJobImplLocked(oldJob, newJob, JobParameters.STOP_REASON_SYSTEM_PROCESSING, - JobParameters.REASON_CANCELED, "deferred rtc calculation"); + JobParameters.INTERNAL_STOP_REASON_RTC_UPDATED, "deferred rtc calculation"); } } }; @@ -1618,12 +1619,12 @@ public class JobSchedulerService extends com.android.server.SystemService } private boolean stopJobOnServiceContextLocked(JobStatus job, - @JobParameters.StopReason int reason, int legacyReason, String debugReason) { - for (int i=0; i= 0; i--) { final JobRestriction restriction = mJobRestrictions.get(i); if (restriction.isJobRestricted(job)) { - final int reason = restriction.getLegacyReason(); + final int reason = restriction.getInternalReason(); pw.print(" "); - pw.print(JobParameters.getLegacyReasonCodeDescription(reason)); + pw.print(JobParameters.getInternalReasonCodeDescription(reason)); } } } else { @@ -3534,7 +3539,7 @@ public class JobSchedulerService extends com.android.server.SystemService final long restrictionsToken = proto.start( JobSchedulerServiceDumpProto.RegisteredJob.RESTRICTIONS); proto.write(JobSchedulerServiceDumpProto.JobRestriction.REASON, - restriction.getLegacyReason()); + restriction.getInternalReason()); proto.write(JobSchedulerServiceDumpProto.JobRestriction.IS_RESTRICTING, restriction.isJobRestricted(job)); proto.end(restrictionsToken); diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobServiceContext.java b/apex/jobscheduler/service/java/com/android/server/job/JobServiceContext.java index 44b3e3e192321..6ab2be32f5c34 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/JobServiceContext.java +++ b/apex/jobscheduler/service/java/com/android/server/job/JobServiceContext.java @@ -156,7 +156,7 @@ public final class JobServiceContext implements ServiceConnection { * {@link JobParameters#STOP_REASON_UNDEFINED}. */ private int mPendingStopReason = JobParameters.STOP_REASON_UNDEFINED; - private int mPendingLegacyStopReason; + private int mPendingInternalStopReason; private String mPendingDebugStopReason; // Debugging: reason this job was last stopped. @@ -366,8 +366,8 @@ public final class JobServiceContext implements ServiceConnection { /** Called externally when a job that was scheduled for execution should be cancelled. */ @GuardedBy("mLock") void cancelExecutingJobLocked(@JobParameters.StopReason int reason, - int legacyStopReason, @NonNull String debugReason) { - doCancelLocked(reason, legacyStopReason, debugReason); + int internalStopReason, @NonNull String debugReason) { + doCancelLocked(reason, internalStopReason, debugReason); } int getPreferredUid() { @@ -400,7 +400,7 @@ public final class JobServiceContext implements ServiceConnection { && (!matchJobId || jobId == executing.getJobId())) { if (mVerb == VERB_EXECUTING) { mParams.setStopReason(JobParameters.STOP_REASON_TIMEOUT, - JobParameters.REASON_TIMEOUT, reason); + JobParameters.INTERNAL_STOP_REASON_TIMEOUT, reason); sendStopMessageLocked("force timeout from shell"); return true; } @@ -409,7 +409,20 @@ public final class JobServiceContext implements ServiceConnection { } void doJobFinished(JobCallback cb, int jobId, boolean reschedule) { - doCallback(cb, reschedule, "app called jobFinished"); + final long ident = Binder.clearCallingIdentity(); + try { + synchronized (mLock) { + if (!verifyCallerLocked(cb)) { + return; + } + mParams.setStopReason(JobParameters.STOP_REASON_UNDEFINED, + JobParameters.INTERNAL_STOP_REASON_SUCCESSFUL_FINISH, + "app called jobFinished"); + doCallbackLocked(reschedule, "app called jobFinished"); + } + } finally { + Binder.restoreCallingIdentity(ident); + } } void doAcknowledgeStopMessage(JobCallback cb, int jobId, boolean reschedule) { @@ -433,6 +446,9 @@ public final class JobServiceContext implements ServiceConnection { } final JobWorkItem work = mRunningJob.dequeueWorkLocked(); if (work == null && !mRunningJob.hasExecutingWorkLocked()) { + mParams.setStopReason(JobParameters.STOP_REASON_UNDEFINED, + JobParameters.INTERNAL_STOP_REASON_SUCCESSFUL_FINISH, + "last work dequeued"); // This will finish the job. doCallbackLocked(false, "last work dequeued"); } @@ -627,8 +643,8 @@ public final class JobServiceContext implements ServiceConnection { } @GuardedBy("mLock") - private void doCancelLocked(@JobParameters.StopReason int stopReasonCode, int legacyStopReason, - @Nullable String debugReason) { + private void doCancelLocked(@JobParameters.StopReason int stopReasonCode, + int internalStopReasonCode, @Nullable String debugReason) { if (mVerb == VERB_FINISHED) { if (DEBUG) { Slog.d(TAG, @@ -644,15 +660,14 @@ public final class JobServiceContext implements ServiceConnection { final long nowElapsed = sElapsedRealtimeClock.millis(); if (nowElapsed < earliestStopTimeElapsed) { mPendingStopReason = stopReasonCode; - mPendingLegacyStopReason = legacyStopReason; + mPendingInternalStopReason = internalStopReasonCode; mPendingDebugStopReason = debugReason; return; } } - mParams.setStopReason(stopReasonCode, legacyStopReason, debugReason); - if (legacyStopReason == JobParameters.REASON_PREEMPT) { - mPreferredUid = mRunningJob != null ? mRunningJob.getUid() : - NO_PREFERRED_UID; + mParams.setStopReason(stopReasonCode, internalStopReasonCode, debugReason); + if (internalStopReasonCode == JobParameters.INTERNAL_STOP_REASON_PREEMPT) { + mPreferredUid = mRunningJob != null ? mRunningJob.getUid() : NO_PREFERRED_UID; } handleCancelLocked(debugReason); } @@ -807,12 +822,12 @@ public final class JobServiceContext implements ServiceConnection { // the device was temporarily taken off the charger). Ignore the pending // stop and see what the manager says. mPendingStopReason = JobParameters.STOP_REASON_UNDEFINED; - mPendingLegacyStopReason = 0; + mPendingInternalStopReason = 0; mPendingDebugStopReason = null; } else { Slog.i(TAG, "JS was waiting to stop this job." + " Sending onStop: " + getRunningJobNameLocked()); - mParams.setStopReason(mPendingStopReason, mPendingLegacyStopReason, + mParams.setStopReason(mPendingStopReason, mPendingInternalStopReason, mPendingDebugStopReason); sendStopMessageLocked(mPendingDebugStopReason); break; @@ -826,7 +841,7 @@ public final class JobServiceContext implements ServiceConnection { Slog.i(TAG, "Client timed out while executing (no jobFinished received)." + " Sending onStop: " + getRunningJobNameLocked()); mParams.setStopReason(JobParameters.STOP_REASON_TIMEOUT, - JobParameters.REASON_TIMEOUT, "client timed out"); + JobParameters.INTERNAL_STOP_REASON_TIMEOUT, "client timed out"); sendStopMessageLocked("timeout while executing"); } else { // We've given the app the minimum execution time. See if we should stop it or @@ -839,7 +854,7 @@ public final class JobServiceContext implements ServiceConnection { // of timeout since all of the reasons could equate to "the system needs // the resources the app is currently using." mParams.setStopReason(JobParameters.STOP_REASON_DEVICE_STATE, - JobParameters.REASON_TIMEOUT, reason); + JobParameters.INTERNAL_STOP_REASON_TIMEOUT, reason); sendStopMessageLocked(reason); } else { Slog.i(TAG, "Letting " + getRunningJobNameLocked() @@ -893,12 +908,12 @@ public final class JobServiceContext implements ServiceConnection { } applyStoppedReasonLocked(reason); completedJob = mRunningJob; - final int legacyStopReason = mParams.getLegacyStopReason(); - mJobPackageTracker.noteInactive(completedJob, legacyStopReason, reason); + final int internalStopReason = mParams.getInternalStopReasonCode(); + mJobPackageTracker.noteInactive(completedJob, internalStopReason, reason); FrameworkStatsLog.write_non_chained(FrameworkStatsLog.SCHEDULED_JOB_STATE_CHANGED, completedJob.getSourceUid(), null, completedJob.getBatteryName(), FrameworkStatsLog.SCHEDULED_JOB_STATE_CHANGED__STATE__FINISHED, - legacyStopReason, completedJob.getStandbyBucket(), completedJob.getJobId(), + internalStopReason, completedJob.getStandbyBucket(), completedJob.getJobId(), completedJob.hasChargingConstraint(), completedJob.hasBatteryNotLowConstraint(), completedJob.hasStorageNotLowConstraint(), @@ -911,7 +926,7 @@ public final class JobServiceContext implements ServiceConnection { completedJob.startedAsExpeditedJob); try { mBatteryStats.noteJobFinish(mRunningJob.getBatteryName(), mRunningJob.getSourceUid(), - legacyStopReason); + internalStopReason); } catch (RemoteException e) { // Whatever. } @@ -930,10 +945,10 @@ public final class JobServiceContext implements ServiceConnection { service = null; mAvailable = true; mPendingStopReason = JobParameters.STOP_REASON_UNDEFINED; - mPendingLegacyStopReason = 0; + mPendingInternalStopReason = 0; mPendingDebugStopReason = null; removeOpTimeOutLocked(); - mCompletedListener.onJobCompletedLocked(completedJob, legacyStopReason, reschedule); + mCompletedListener.onJobCompletedLocked(completedJob, internalStopReason, reschedule); mJobConcurrencyManager.onJobCompletedLocked(this, completedJob, workType); } @@ -1023,7 +1038,7 @@ public final class JobServiceContext implements ServiceConnection { pw.print(" Pending stop because "); pw.print(mPendingStopReason); pw.print("/"); - pw.print(mPendingLegacyStopReason); + pw.print(mPendingInternalStopReason); pw.print("/"); pw.print(mPendingDebugStopReason); } diff --git a/apex/jobscheduler/service/java/com/android/server/job/restrictions/JobRestriction.java b/apex/jobscheduler/service/java/com/android/server/job/restrictions/JobRestriction.java index 2962b10173151..20df3ea2196b6 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/restrictions/JobRestriction.java +++ b/apex/jobscheduler/service/java/com/android/server/job/restrictions/JobRestriction.java @@ -28,7 +28,7 @@ import com.android.server.job.controllers.JobStatus; * Used by {@link JobSchedulerService} to impose additional restrictions regarding whether jobs * should be scheduled or not based on the state of the system/device. * Every restriction is associated with exactly one stop reason, which could be retrieved using - * {@link #getReason()} (and the legacy reason via {@link #getLegacyReason()}). + * {@link #getReason()} (and the internal reason via {@link #getInternalReason()}). * Note, that this is not taken into account for the jobs that have priority * {@link JobInfo#PRIORITY_FOREGROUND_APP} or higher. */ @@ -36,13 +36,13 @@ public abstract class JobRestriction { final JobSchedulerService mService; private final int mReason; - private final int mLegacyReason; + private final int mInternalReason; JobRestriction(JobSchedulerService service, @JobParameters.StopReason int reason, - int legacyReason) { + int internalReason) { mService = service; mReason = reason; - mLegacyReason = legacyReason; + mInternalReason = internalReason; } /** @@ -74,7 +74,7 @@ public abstract class JobRestriction { return mReason; } - public final int getLegacyReason() { - return mLegacyReason; + public final int getInternalReason() { + return mInternalReason; } } diff --git a/apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java b/apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java index 8b699e9b04c3a..3069db32c5480 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java +++ b/apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java @@ -34,7 +34,8 @@ public class ThermalStatusRestriction extends JobRestriction { private PowerManager mPowerManager; public ThermalStatusRestriction(JobSchedulerService service) { - super(service, JobParameters.STOP_REASON_DEVICE_STATE, JobParameters.REASON_DEVICE_THERMAL); + super(service, JobParameters.STOP_REASON_DEVICE_STATE, + JobParameters.INTERNAL_STOP_REASON_DEVICE_THERMAL); } @Override diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java index 043a22b6e311c..9ec6938de271f 100644 --- a/core/java/android/os/BatteryStats.java +++ b/core/java/android/os/BatteryStats.java @@ -6076,7 +6076,7 @@ public abstract class BatteryStats implements Parcelable { pw.print(":"); for (int it=0; it