| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app.job; |
| 18 |
|
| 19 |
import android.os.Parcel; |
| 20 |
import android.os.Parcelable; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public class JobSnapshot implements Parcelable { |
| 32 |
private final JobInfo mJob; |
| 33 |
private final int mSatisfiedConstraints; |
| 34 |
private final boolean mIsRunnable; |
| 35 |
|
| 36 |
public JobSnapshot(JobInfo info, int satisfiedMask, boolean runnable) { |
| 37 |
mJob = info; |
| 38 |
mSatisfiedConstraints = satisfiedMask; |
| 39 |
mIsRunnable = runnable; |
| 40 |
} |
| 41 |
|
| 42 |
public JobSnapshot(Parcel in) { |
| 43 |
mJob = JobInfo.CREATOR.createFromParcel(in); |
| 44 |
mSatisfiedConstraints = in.readInt(); |
| 45 |
mIsRunnable = in.readBoolean(); |
| 46 |
} |
| 47 |
|
| 48 |
private boolean satisfied(int flag) { |
| 49 |
return (mSatisfiedConstraints & flag) != 0; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public JobInfo getJobInfo() { |
| 57 |
return mJob; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public boolean isRunnable() { |
| 64 |
return mIsRunnable; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public boolean isChargingSatisfied() { |
| 71 |
return !mJob.isRequireCharging() |
| 72 |
|| satisfied(JobInfo.CONSTRAINT_FLAG_CHARGING); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public boolean isBatteryNotLowSatisfied() { |
| 79 |
return !mJob.isRequireBatteryNotLow() |
| 80 |
|| satisfied(JobInfo.CONSTRAINT_FLAG_BATTERY_NOT_LOW); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
public boolean isRequireDeviceIdleSatisfied() { |
| 87 |
return !mJob.isRequireDeviceIdle() |
| 88 |
|| satisfied(JobInfo.CONSTRAINT_FLAG_DEVICE_IDLE); |
| 89 |
} |
| 90 |
|
| 91 |
public boolean isRequireStorageNotLowSatisfied() { |
| 92 |
return !mJob.isRequireStorageNotLow() |
| 93 |
|| satisfied(JobInfo.CONSTRAINT_FLAG_STORAGE_NOT_LOW); |
| 94 |
} |
| 95 |
|
| 96 |
@Override |
| 97 |
public int describeContents() { |
| 98 |
return 0; |
| 99 |
} |
| 100 |
|
| 101 |
@Override |
| 102 |
public void writeToParcel(Parcel out, int flags) { |
| 103 |
mJob.writeToParcel(out, flags); |
| 104 |
out.writeInt(mSatisfiedConstraints); |
| 105 |
out.writeBoolean(mIsRunnable); |
| 106 |
} |
| 107 |
|
| 108 |
public static final @android.annotation.NonNull Creator<JobSnapshot> CREATOR = new Creator<JobSnapshot>() { |
| 109 |
@Override |
| 110 |
public JobSnapshot createFromParcel(Parcel in) { |
| 111 |
return new JobSnapshot(in); |
| 112 |
} |
| 113 |
|
| 114 |
@Override |
| 115 |
public JobSnapshot[] newArray(int size) { |
| 116 |
return new JobSnapshot[size]; |
| 117 |
} |
| 118 |
}; |
| 119 |
} |