diff options
| author | 2022-10-26 21:22:14 +0000 | |
|---|---|---|
| committer | 2022-10-26 21:22:14 +0000 | |
| commit | d3e900e38c56d04aa024b1aa36e9d84fe04aba59 (patch) | |
| tree | 2928dbe0e16e12b5bd59b7409d2f2466c2de3911 | |
| parent | bd224c8afbf7cf56ab42958628cac35bd9de51b0 (diff) | |
Do best effort network estimate calculation.
Ignore invalid negative values in the network payload estimate
calculations and use known/available values to get a best effort
estimate of the total payload size.
Bug: 253665015
Bug: 255828754
Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/job
Test: atest frameworks/base/services/tests/mockingservicestests/src/com/android/server/job
Change-Id: Ie986ac8a4b46a920c6d57b6925e72f8d62e1ce68
| -rw-r--r-- | apex/jobscheduler/service/java/com/android/server/job/controllers/JobStatus.java | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/apex/jobscheduler/service/java/com/android/server/job/controllers/JobStatus.java b/apex/jobscheduler/service/java/com/android/server/job/controllers/JobStatus.java index de602a8f7f25..c5a56b86e7bd 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/controllers/JobStatus.java +++ b/apex/jobscheduler/service/java/com/android/server/job/controllers/JobStatus.java @@ -1061,27 +1061,41 @@ public final class JobStatus { private void updateNetworkBytesLocked() { mTotalNetworkDownloadBytes = job.getEstimatedNetworkDownloadBytes(); + if (mTotalNetworkDownloadBytes < 0) { + // Legacy apps may have provided invalid negative values. Ignore invalid values. + mTotalNetworkDownloadBytes = JobInfo.NETWORK_BYTES_UNKNOWN; + } mTotalNetworkUploadBytes = job.getEstimatedNetworkUploadBytes(); + if (mTotalNetworkUploadBytes < 0) { + // Legacy apps may have provided invalid negative values. Ignore invalid values. + mTotalNetworkUploadBytes = JobInfo.NETWORK_BYTES_UNKNOWN; + } + // Minimum network chunk bytes has had data validation since its introduction, so no + // need to do validation again. mMinimumNetworkChunkBytes = job.getMinimumNetworkChunkBytes(); if (pendingWork != null) { for (int i = 0; i < pendingWork.size(); i++) { - if (mTotalNetworkDownloadBytes != JobInfo.NETWORK_BYTES_UNKNOWN) { - // If any component of the job has unknown usage, we don't have a - // complete picture of what data will be used, and we have to treat the - // entire up/download as unknown. - long downloadBytes = pendingWork.get(i).getEstimatedNetworkDownloadBytes(); - if (downloadBytes != JobInfo.NETWORK_BYTES_UNKNOWN) { + long downloadBytes = pendingWork.get(i).getEstimatedNetworkDownloadBytes(); + if (downloadBytes != JobInfo.NETWORK_BYTES_UNKNOWN && downloadBytes > 0) { + // If any component of the job has unknown usage, we won't have a + // complete picture of what data will be used. However, we use what we are given + // to get us as close to the complete picture as possible. + if (mTotalNetworkDownloadBytes != JobInfo.NETWORK_BYTES_UNKNOWN) { mTotalNetworkDownloadBytes += downloadBytes; + } else { + mTotalNetworkDownloadBytes = downloadBytes; } } - if (mTotalNetworkUploadBytes != JobInfo.NETWORK_BYTES_UNKNOWN) { - // If any component of the job has unknown usage, we don't have a - // complete picture of what data will be used, and we have to treat the - // entire up/download as unknown. - long uploadBytes = pendingWork.get(i).getEstimatedNetworkUploadBytes(); - if (uploadBytes != JobInfo.NETWORK_BYTES_UNKNOWN) { + long uploadBytes = pendingWork.get(i).getEstimatedNetworkUploadBytes(); + if (uploadBytes != JobInfo.NETWORK_BYTES_UNKNOWN && uploadBytes > 0) { + // If any component of the job has unknown usage, we won't have a + // complete picture of what data will be used. However, we use what we are given + // to get us as close to the complete picture as possible. + if (mTotalNetworkUploadBytes != JobInfo.NETWORK_BYTES_UNKNOWN) { mTotalNetworkUploadBytes += uploadBytes; + } else { + mTotalNetworkUploadBytes = uploadBytes; } } final long chunkBytes = pendingWork.get(i).getMinimumNetworkChunkBytes(); |