From d3e900e38c56d04aa024b1aa36e9d84fe04aba59 Mon Sep 17 00:00:00 2001 From: Kweku Adams Date: Wed, 26 Oct 2022 21:22:14 +0000 Subject: 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 --- .../android/server/job/controllers/JobStatus.java | 38 +++++++++++++++------- 1 file 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(); -- cgit v1.2.3-59-g8ed1b