Merge changes I61392c55,I97e40d35 into sc-dev
* changes: Expand internal stop reasons. Rename "legacy" stop reasons.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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<JobStatus> 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<mActiveServices.size(); i++) {
|
||||
@JobParameters.StopReason int reason, int internalReasonCode, String debugReason) {
|
||||
for (int i = 0; i < mActiveServices.size(); i++) {
|
||||
JobServiceContext jsc = mActiveServices.get(i);
|
||||
final JobStatus executing = jsc.getRunningJobLocked();
|
||||
if (executing != null && executing.matches(job.getUid(), job.getJobId())) {
|
||||
jsc.cancelExecutingJobLocked(reason, legacyReason, debugReason);
|
||||
jsc.cancelExecutingJobLocked(reason, internalReasonCode, debugReason);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1819,8 +1820,8 @@ public class JobSchedulerService extends com.android.server.SystemService
|
||||
mLastCompletedJobTimeElapsed[mLastCompletedJobIndex] = sElapsedRealtimeClock.millis();
|
||||
mLastCompletedJobIndex = (mLastCompletedJobIndex + 1) % NUM_COMPLETED_JOB_HISTORY;
|
||||
|
||||
if (debugStopReason == JobParameters.DEBUG_REASON_UNINSTALL
|
||||
|| debugStopReason == JobParameters.DEBUG_REASON_DATA_CLEARED) {
|
||||
if (debugStopReason == JobParameters.INTERNAL_STOP_REASON_UNINSTALL
|
||||
|| debugStopReason == JobParameters.INTERNAL_STOP_REASON_DATA_CLEARED) {
|
||||
// The job should have already been cleared from the rest of the JS tracking. No need
|
||||
// to go through all that flow again.
|
||||
jobStatus.unprepareLocked();
|
||||
@@ -1838,8 +1839,8 @@ public class JobSchedulerService extends com.android.server.SystemService
|
||||
final JobStatus rescheduledJob = needsReschedule
|
||||
? getRescheduleJobForFailureLocked(jobStatus) : null;
|
||||
if (rescheduledJob != null
|
||||
&& (debugStopReason == JobParameters.REASON_TIMEOUT
|
||||
|| debugStopReason == JobParameters.REASON_PREEMPT)) {
|
||||
&& (debugStopReason == JobParameters.INTERNAL_STOP_REASON_TIMEOUT
|
||||
|| debugStopReason == JobParameters.INTERNAL_STOP_REASON_PREEMPT)) {
|
||||
rescheduledJob.disallowRunInBatterySaverAndDoze();
|
||||
}
|
||||
|
||||
@@ -1944,7 +1945,7 @@ public class JobSchedulerService extends com.android.server.SystemService
|
||||
break;
|
||||
case MSG_STOP_JOB:
|
||||
cancelJobImplLocked((JobStatus) message.obj, null, message.arg1,
|
||||
JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED,
|
||||
JobParameters.INTERNAL_STOP_REASON_CONSTRAINTS_NOT_SATISFIED,
|
||||
"app no longer allowed to run");
|
||||
break;
|
||||
|
||||
@@ -1961,7 +1962,8 @@ public class JobSchedulerService extends com.android.server.SystemService
|
||||
if (disabled) {
|
||||
cancelJobsForUid(uid,
|
||||
JobParameters.STOP_REASON_BACKGROUND_RESTRICTION,
|
||||
JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, "uid gone");
|
||||
JobParameters.INTERNAL_STOP_REASON_CONSTRAINTS_NOT_SATISFIED,
|
||||
"uid gone");
|
||||
}
|
||||
synchronized (mLock) {
|
||||
mDeviceIdleJobsController.setUidActiveLocked(uid, false);
|
||||
@@ -1981,7 +1983,8 @@ public class JobSchedulerService extends com.android.server.SystemService
|
||||
if (disabled) {
|
||||
cancelJobsForUid(uid,
|
||||
JobParameters.STOP_REASON_BACKGROUND_RESTRICTION,
|
||||
JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, "app uid idle");
|
||||
JobParameters.INTERNAL_STOP_REASON_CONSTRAINTS_NOT_SATISFIED,
|
||||
"app uid idle");
|
||||
}
|
||||
synchronized (mLock) {
|
||||
mDeviceIdleJobsController.setUidActiveLocked(uid, false);
|
||||
@@ -2034,22 +2037,23 @@ public class JobSchedulerService extends com.android.server.SystemService
|
||||
&& !running.areDynamicConstraintsSatisfied()) {
|
||||
serviceContext.cancelExecutingJobLocked(
|
||||
running.getStopReason(),
|
||||
JobParameters.REASON_RESTRICTED_BUCKET,
|
||||
JobParameters.INTERNAL_STOP_REASON_RESTRICTED_BUCKET,
|
||||
"cancelled due to restricted bucket");
|
||||
} else {
|
||||
serviceContext.cancelExecutingJobLocked(
|
||||
running.getStopReason(),
|
||||
JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED,
|
||||
JobParameters.INTERNAL_STOP_REASON_CONSTRAINTS_NOT_SATISFIED,
|
||||
"cancelled due to unsatisfied constraints");
|
||||
}
|
||||
} else {
|
||||
final JobRestriction restriction = checkIfRestricted(running);
|
||||
if (restriction != null) {
|
||||
final int reason = restriction.getReason();
|
||||
serviceContext.cancelExecutingJobLocked(reason,
|
||||
restriction.getLegacyReason(),
|
||||
"restricted due to " + JobParameters.getLegacyReasonCodeDescription(
|
||||
reason));
|
||||
final int internalReasonCode = restriction.getInternalReason();
|
||||
serviceContext.cancelExecutingJobLocked(restriction.getReason(),
|
||||
internalReasonCode,
|
||||
"restricted due to "
|
||||
+ JobParameters.getInternalReasonCodeDescription(
|
||||
internalReasonCode));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2354,7 +2358,7 @@ public class JobSchedulerService extends com.android.server.SystemService
|
||||
if (restriction != null) {
|
||||
if (DEBUG) {
|
||||
Slog.v(TAG, "areComponentsInPlaceLocked: " + job.toShortString()
|
||||
+ " restricted due to " + restriction.getLegacyReason());
|
||||
+ " restricted due to " + restriction.getInternalReason());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -2446,8 +2450,8 @@ public class JobSchedulerService extends com.android.server.SystemService
|
||||
|
||||
@Override
|
||||
public void cancelJobsForUid(int uid, @JobParameters.StopReason int reason,
|
||||
int debugReasonCode, String debugReason) {
|
||||
JobSchedulerService.this.cancelJobsForUid(uid, reason, debugReasonCode, debugReason);
|
||||
int internalReasonCode, String debugReason) {
|
||||
JobSchedulerService.this.cancelJobsForUid(uid, reason, internalReasonCode, debugReason);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2786,7 +2790,7 @@ public class JobSchedulerService extends com.android.server.SystemService
|
||||
try {
|
||||
JobSchedulerService.this.cancelJobsForUid(uid,
|
||||
JobParameters.STOP_REASON_CANCELLED_BY_APP,
|
||||
JobParameters.REASON_CANCELED,
|
||||
JobParameters.INTERNAL_STOP_REASON_CANCELED,
|
||||
"cancelAll() called by app, callingUid=" + uid);
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(ident);
|
||||
@@ -3007,7 +3011,8 @@ public class JobSchedulerService extends com.android.server.SystemService
|
||||
if (!hasJobId) {
|
||||
pw.println("Canceling all jobs for " + pkgName + " in user " + userId);
|
||||
if (!cancelJobsForUid(pkgUid, JobParameters.STOP_REASON_USER,
|
||||
JobParameters.REASON_CANCELED, "cancel shell command for package")) {
|
||||
JobParameters.INTERNAL_STOP_REASON_CANCELED,
|
||||
"cancel shell command for package")) {
|
||||
pw.println("No matching jobs found.");
|
||||
}
|
||||
} else {
|
||||
@@ -3247,9 +3252,9 @@ public class JobSchedulerService extends com.android.server.SystemService
|
||||
for (int i = mJobRestrictions.size() - 1; 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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -6076,7 +6076,7 @@ public abstract class BatteryStats implements Parcelable {
|
||||
pw.print(":");
|
||||
for (int it=0; it<types.size(); it++) {
|
||||
pw.print(" ");
|
||||
pw.print(JobParameters.getLegacyReasonCodeDescription(types.keyAt(it)));
|
||||
pw.print(JobParameters.getInternalReasonCodeDescription(types.keyAt(it)));
|
||||
pw.print("(");
|
||||
pw.print(types.valueAt(it));
|
||||
pw.print("x)");
|
||||
|
||||
@@ -3525,7 +3525,7 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
JobSchedulerInternal js = LocalServices.getService(JobSchedulerInternal.class);
|
||||
// Clearing data is a user-initiated action.
|
||||
js.cancelJobsForUid(appInfo.uid, JobParameters.STOP_REASON_USER,
|
||||
JobParameters.DEBUG_REASON_DATA_CLEARED, "clear data");
|
||||
JobParameters.INTERNAL_STOP_REASON_DATA_CLEARED, "clear data");
|
||||
|
||||
// Clear its pending alarms
|
||||
AlarmManagerInternal ami = LocalServices.getService(AlarmManagerInternal.class);
|
||||
|
||||
@@ -119,7 +119,7 @@ public class SyncJobService extends JobService {
|
||||
public boolean onStopJob(JobParameters params) {
|
||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
||||
Slog.v(TAG, "onStopJob called " + params.getJobId() + ", reason: "
|
||||
+ params.getLegacyStopReason());
|
||||
+ params.getInternalStopReasonCode());
|
||||
}
|
||||
final SyncOperation op = SyncOperation.maybeCreateFromJobExtras(params.getExtras());
|
||||
if (op == null) {
|
||||
@@ -161,9 +161,11 @@ public class SyncJobService extends JobService {
|
||||
m.obj = op;
|
||||
|
||||
// Reschedule if this job was NOT explicitly canceled.
|
||||
m.arg1 = params.getLegacyStopReason() != JobParameters.REASON_CANCELED ? 1 : 0;
|
||||
m.arg1 = params.getInternalStopReasonCode() != JobParameters.INTERNAL_STOP_REASON_CANCELED
|
||||
? 1 : 0;
|
||||
// Apply backoff only if stop is called due to timeout.
|
||||
m.arg2 = params.getLegacyStopReason() == JobParameters.REASON_TIMEOUT ? 1 : 0;
|
||||
m.arg2 = params.getInternalStopReasonCode() == JobParameters.INTERNAL_STOP_REASON_TIMEOUT
|
||||
? 1 : 0;
|
||||
|
||||
SyncManager.sendMessage(m);
|
||||
return false;
|
||||
@@ -204,7 +206,7 @@ public class SyncJobService extends JobService {
|
||||
return "job:null";
|
||||
} else {
|
||||
return "job:#" + params.getJobId() + ":"
|
||||
+ "sr=[" + params.getLegacyStopReason()
|
||||
+ "sr=[" + params.getInternalStopReasonCode()
|
||||
+ "/" + params.getDebugStopReason() + "]:"
|
||||
+ SyncOperation.maybeCreateFromJobExtras(params.getExtras());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user