FileDocCategorySizeDatePackage
JobStatus.javaAPI DocAndroid 5.1 API9444Thu Mar 12 22:22:42 GMT 2015com.android.server.job.controllers

JobStatus

public class JobStatus extends Object
Uniquely identifies a job internally. Created from the public {@link android.app.job.JobInfo} object when it lands on the scheduler. Contains current state of the requirements of the job, as well as a function to evaluate whether it's ready to run. This object is shared among the various controllers - hence why the different fields are atomic. This isn't strictly necessary because each controller is only interested in a specific field, and the receivers that are listening for global state change will all run on the main looper, but we don't enforce that so this is safer.
hide

Fields Summary
public static final long
NO_LATEST_RUNTIME
public static final long
NO_EARLIEST_RUNTIME
final android.app.job.JobInfo
job
final int
uId
Uid of the package requesting this job.
final String
name
final String
tag
final AtomicBoolean
chargingConstraintSatisfied
final AtomicBoolean
timeDelayConstraintSatisfied
final AtomicBoolean
deadlineConstraintSatisfied
final AtomicBoolean
idleConstraintSatisfied
final AtomicBoolean
unmeteredConstraintSatisfied
final AtomicBoolean
connectivityConstraintSatisfied
private long
earliestRunTimeElapsedMillis
Earliest point in the future at which this job will be eligible to run. A value of 0 indicates there is no delay constraint. See {@link #hasTimingDelayConstraint()}.
private long
latestRunTimeElapsedMillis
Latest point in the future at which this job must be run. A value of {@link Long#MAX_VALUE} indicates there is no deadline constraint. See {@link #hasDeadlineConstraint()}.
private final int
numFailures
How many times this job has failed, used to compute back-off.
Constructors Summary
private JobStatus(android.app.job.JobInfo job, int uId, int numFailures)

        this.job = job;
        this.uId = uId;
        this.name = job.getService().flattenToShortString();
        this.tag = "*job*/" + this.name;
        this.numFailures = numFailures;
    
public JobStatus(android.app.job.JobInfo job, int uId)
Create a newly scheduled job.

        this(job, uId, 0);

        final long elapsedNow = SystemClock.elapsedRealtime();

        if (job.isPeriodic()) {
            earliestRunTimeElapsedMillis = elapsedNow;
            latestRunTimeElapsedMillis = elapsedNow + job.getIntervalMillis();
        } else {
            earliestRunTimeElapsedMillis = job.hasEarlyConstraint() ?
                    elapsedNow + job.getMinLatencyMillis() : NO_EARLIEST_RUNTIME;
            latestRunTimeElapsedMillis = job.hasLateConstraint() ?
                    elapsedNow + job.getMaxExecutionDelayMillis() : NO_LATEST_RUNTIME;
        }
    
public JobStatus(android.app.job.JobInfo job, int uId, long earliestRunTimeElapsedMillis, long latestRunTimeElapsedMillis)
Create a new JobStatus that was loaded from disk. We ignore the provided {@link android.app.job.JobInfo} time criteria because we can load a persisted periodic job from the {@link com.android.server.job.JobStore} and still want to respect its wallclock runtime rather than resetting it on every boot. We consider a freshly loaded job to no longer be in back-off.

        this(job, uId, 0);

        this.earliestRunTimeElapsedMillis = earliestRunTimeElapsedMillis;
        this.latestRunTimeElapsedMillis = latestRunTimeElapsedMillis;
    
public JobStatus(JobStatus rescheduling, long newEarliestRuntimeElapsedMillis, long newLatestRuntimeElapsedMillis, int backoffAttempt)
Create a new job to be rescheduled with the provided parameters.

        this(rescheduling.job, rescheduling.getUid(), backoffAttempt);

        earliestRunTimeElapsedMillis = newEarliestRuntimeElapsedMillis;
        latestRunTimeElapsedMillis = newLatestRuntimeElapsedMillis;
    
Methods Summary
public voiddump(java.io.PrintWriter pw, java.lang.String prefix)

        pw.print(prefix);
        pw.println(this.toString());
    
private java.lang.StringformatRunTime(long runtime, long defaultValue)

        if (runtime == defaultValue) {
            return "none";
        } else {
            long elapsedNow = SystemClock.elapsedRealtime();
            long nextRuntime = runtime - elapsedNow;
            if (nextRuntime > 0) {
                return DateUtils.formatElapsedTime(nextRuntime / 1000);
            } else {
                return "-" + DateUtils.formatElapsedTime(nextRuntime / -1000);
            }
        }
    
public longgetEarliestRunTime()

        return earliestRunTimeElapsedMillis;
    
public android.os.PersistableBundlegetExtras()

        return job.getExtras();
    
public android.app.job.JobInfogetJob()

        return job;
    
public intgetJobId()

        return job.getId();
    
public longgetLatestRunTimeElapsed()

        return latestRunTimeElapsedMillis;
    
public java.lang.StringgetName()

        return name;
    
public intgetNumFailures()

        return numFailures;
    
public android.content.ComponentNamegetServiceComponent()

        return job.getService();
    
public intgetServiceToken()
Provide a handle to the service that this job will be run on.


                  
       
        return uId;
    
public java.lang.StringgetTag()

        return tag;
    
public intgetUid()

        return uId;
    
public intgetUserId()

        return UserHandle.getUserId(uId);
    
public booleanhasChargingConstraint()

        return job.isRequireCharging();
    
public booleanhasConnectivityConstraint()

        return job.getNetworkType() == JobInfo.NETWORK_TYPE_ANY;
    
public booleanhasDeadlineConstraint()

        return latestRunTimeElapsedMillis != NO_LATEST_RUNTIME;
    
public booleanhasIdleConstraint()

        return job.isRequireDeviceIdle();
    
public booleanhasTimingDelayConstraint()

        return earliestRunTimeElapsedMillis != NO_EARLIEST_RUNTIME;
    
public booleanhasUnmeteredConstraint()

        return job.getNetworkType() == JobInfo.NETWORK_TYPE_UNMETERED;
    
public synchronized booleanisConstraintsSatisfied()

return
Whether the constraints set on this job are satisfied.

        return (!hasChargingConstraint() || chargingConstraintSatisfied.get())
                && (!hasTimingDelayConstraint() || timeDelayConstraintSatisfied.get())
                && (!hasConnectivityConstraint() || connectivityConstraintSatisfied.get())
                && (!hasUnmeteredConstraint() || unmeteredConstraintSatisfied.get())
                && (!hasIdleConstraint() || idleConstraintSatisfied.get());
    
public booleanisPersisted()

        return job.isPersisted();
    
public synchronized booleanisReady()

return
Whether or not this job is ready to run, based on its requirements. This is true if the constraints are satisfied or the deadline on the job has expired.

        return isConstraintsSatisfied()
                || (hasDeadlineConstraint() && deadlineConstraintSatisfied.get());
    
public booleanmatches(int uid, int jobId)

        return this.job.getId() == jobId && this.uId == uid;
    
public java.lang.StringtoShortString()
Convenience function to identify a job uniquely without pulling all the data that {@link #toString()} returns.

        return job.getService().flattenToShortString() + " jId=" + job.getId() +
                ", u" + getUserId();
    
public java.lang.StringtoString()

        return String.valueOf(hashCode()).substring(0, 3) + ".."
                + ":[" + job.getService()
                + ",jId=" + job.getId()
                + ",u" + getUserId()
                + ",R=(" + formatRunTime(earliestRunTimeElapsedMillis, NO_EARLIEST_RUNTIME)
                + "," + formatRunTime(latestRunTimeElapsedMillis, NO_LATEST_RUNTIME) + ")"
                + ",N=" + job.getNetworkType() + ",C=" + job.isRequireCharging()
                + ",I=" + job.isRequireDeviceIdle() + ",F=" + numFailures
                + ",P=" + job.isPersisted()
                + (isReady() ? "(READY)" : "")
                + "]";