diff --git a/core/java/android/app/job/JobParameters.java b/core/java/android/app/job/JobParameters.java index 5053dc6fdf052..c71bf2e65731f 100644 --- a/core/java/android/app/job/JobParameters.java +++ b/core/java/android/app/job/JobParameters.java @@ -70,6 +70,7 @@ public class JobParameters implements Parcelable { private final Network network; private int stopReason; // Default value of stopReason is REASON_CANCELED + private String debugStopReason; // Human readable stop reason for debugging. /** @hide */ public JobParameters(IBinder callback, int jobId, PersistableBundle extras, @@ -103,6 +104,14 @@ public class JobParameters implements Parcelable { return stopReason; } + /** + * Reason onStopJob() was called on this job. + * @hide + */ + public String getDebugStopReason() { + return debugStopReason; + } + /** * @return The extras you passed in when constructing this job with * {@link android.app.job.JobInfo.Builder#setExtras(android.os.PersistableBundle)}. This will @@ -288,11 +297,13 @@ public class JobParameters implements Parcelable { network = null; } stopReason = in.readInt(); + debugStopReason = in.readString(); } /** @hide */ - public void setStopReason(int reason) { + public void setStopReason(int reason, String debugStopReason) { stopReason = reason; + this.debugStopReason = debugStopReason; } @Override @@ -323,6 +334,7 @@ public class JobParameters implements Parcelable { dest.writeInt(0); } dest.writeInt(stopReason); + dest.writeString(debugStopReason); } public static final Creator CREATOR = new Creator() { diff --git a/services/core/java/com/android/server/content/SyncJobService.java b/services/core/java/com/android/server/content/SyncJobService.java index 40a93c1c2808c..51499f735bcf7 100644 --- a/services/core/java/com/android/server/content/SyncJobService.java +++ b/services/core/java/com/android/server/content/SyncJobService.java @@ -122,10 +122,12 @@ public class SyncJobService extends JobService { final long startUptime = mJobStartUptimes.get(jobId); final long nowUptime = SystemClock.uptimeMillis(); + final long runtime = nowUptime - startUptime; + if (startUptime == 0) { wtf("Job " + jobId + " start uptime not found: " + " params=" + jobParametersToString(params)); - } else if ((nowUptime - startUptime) > 60 * 1000) { + } else if (runtime > 60 * 1000) { // WTF if startSyncH() hasn't happened, *unless* onStopJob() was called too soon. // (1 minute threshold.) if (!mStartedSyncs.get(jobId)) { @@ -134,6 +136,12 @@ public class SyncJobService extends JobService { + " nowUptime=" + nowUptime + " params=" + jobParametersToString(params)); } + } else if (runtime < 10 * 1000) { + // Job stopped too soon. WTF. + wtf("Job " + jobId + " stopped in " + runtime + " ms: " + + " startUptime=" + startUptime + + " nowUptime=" + nowUptime + + " params=" + jobParametersToString(params)); } mStartedSyncs.delete(jobId); @@ -183,6 +191,7 @@ public class SyncJobService extends JobService { return "job:null"; } else { return "job:#" + params.getJobId() + ":" + + "sr=[" + params.getStopReason() + "/" + params.getDebugStopReason() + "]:" + SyncOperation.maybeCreateFromJobExtras(params.getExtras()); } } diff --git a/services/core/java/com/android/server/job/JobSchedulerService.java b/services/core/java/com/android/server/job/JobSchedulerService.java index 733ed3d815559..bd1dbf9c46e84 100644 --- a/services/core/java/com/android/server/job/JobSchedulerService.java +++ b/services/core/java/com/android/server/job/JobSchedulerService.java @@ -934,12 +934,14 @@ public final class JobSchedulerService extends com.android.server.SystemService * @param uid Uid of the calling client. * @param jobId Id of the job, provided at schedule-time. */ - public boolean cancelJob(int uid, int jobId) { + public boolean cancelJob(int uid, int jobId, int callingUid) { JobStatus toCancel; synchronized (mLock) { toCancel = mJobs.getJobByUidAndJobId(uid, jobId); if (toCancel != null) { - cancelJobImplLocked(toCancel, null, "cancel() called by app"); + cancelJobImplLocked(toCancel, null, + "cancel() called by app, callingUid=" + callingUid + + " uid=" + uid + " jobId=" + jobId); } return (toCancel != null); } @@ -2341,7 +2343,8 @@ public final class JobSchedulerService extends com.android.server.SystemService final int uid = Binder.getCallingUid(); long ident = Binder.clearCallingIdentity(); try { - JobSchedulerService.this.cancelJobsForUid(uid, "cancelAll() called by app"); + JobSchedulerService.this.cancelJobsForUid(uid, + "cancelAll() called by app, callingUid=" + uid); } finally { Binder.restoreCallingIdentity(ident); } @@ -2353,7 +2356,7 @@ public final class JobSchedulerService extends com.android.server.SystemService long ident = Binder.clearCallingIdentity(); try { - JobSchedulerService.this.cancelJob(uid, jobId); + JobSchedulerService.this.cancelJob(uid, jobId, uid); } finally { Binder.restoreCallingIdentity(ident); } @@ -2466,7 +2469,7 @@ public final class JobSchedulerService extends com.android.server.SystemService for (int i=0; i