Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 70f8e99c authored by Kweku Adams's avatar Kweku Adams
Browse files

Reject invalid input.

Ensure that apps don't provide negative estimated byte usage.

Bug: 141645789
Test: atest android.jobscheduler.cts.JobInfoTest
Test: atest android.jobscheduler.cts.JobWorkItemTest
Change-Id: I66485040de0cc105056349e308561f9ddd6ab91a
parent 6fb5c88a
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -1250,6 +1250,11 @@ public class JobInfo implements Parcelable {
         */
        public Builder setEstimatedNetworkBytes(@BytesLong long downloadBytes,
                @BytesLong long uploadBytes) {
            if ((downloadBytes != NETWORK_BYTES_UNKNOWN && downloadBytes < 0)
                    || (uploadBytes != NETWORK_BYTES_UNKNOWN && uploadBytes < 0)) {
                throw new IllegalArgumentException(
                        "Can't provide negative estimated network usage");
            }
            mNetworkDownloadBytes = downloadBytes;
            mNetworkUploadBytes = uploadBytes;
            return this;
@@ -1647,12 +1652,16 @@ public class JobInfo implements Parcelable {
    /**
     * @hide
     */
    public void enforceValidity() {
    public final void enforceValidity() {
        // Check that network estimates require network type
        if ((networkDownloadBytes > 0 || networkUploadBytes > 0) && networkRequest == null) {
            throw new IllegalArgumentException(
                    "Can't provide estimated network usage without requiring a network");
        }
        if ((networkDownloadBytes != NETWORK_BYTES_UNKNOWN && networkDownloadBytes < 0)
                || (networkUploadBytes != NETWORK_BYTES_UNKNOWN && networkUploadBytes < 0)) {
            throw new IllegalArgumentException("Can't provide negative estimated network usage");
        }

        // Check that a deadline was not set on a periodic job.
        if (isPeriodic) {
+4 −0
Original line number Diff line number Diff line
@@ -68,6 +68,10 @@ final public class JobWorkItem implements Parcelable {
     *            uploaded by this job work item, in bytes.
     */
    public JobWorkItem(Intent intent, @BytesLong long downloadBytes, @BytesLong long uploadBytes) {
        if ((downloadBytes != NETWORK_BYTES_UNKNOWN && downloadBytes < 0)
                || (uploadBytes != NETWORK_BYTES_UNKNOWN && uploadBytes < 0)) {
            throw new IllegalArgumentException("Can't provide negative estimated network usage");
        }
        mIntent = intent;
        mNetworkDownloadBytes = downloadBytes;
        mNetworkUploadBytes = uploadBytes;