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
This commit is contained in:
Kweku Adams
2022-10-26 21:22:14 +00:00
parent bd224c8afb
commit d3e900e38c

View File

@@ -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();