Skip to content
Snippets Groups Projects
Commit 45296720 authored by lifr's avatar lifr
Browse files

[CS04]Remove hidden API usage of NetworkCapabilities

The connection service will become the mainline module. The mutating
NetworkCapabilities is deprecated, and the NetworkCapabilities should
be built through their Builder instead.

Bug: 170598012
Test: atest FrameworksMockingServicesTests:ConnectivityControllerTest
Test: atest CtsJobSchedulerTestCases
Change-Id: I931f6f4cedd89a3ff7c811266c68c00f26e8ce43
parent be75db95
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,6 @@
package com.android.server.job.controllers;
import static android.net.NetworkCapabilities.LINK_BANDWIDTH_UNSPECIFIED;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_CONGESTED;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_METERED;
......@@ -325,7 +324,7 @@ public final class ConnectivityController extends RestrictingController implemen
if (downloadBytes != JobInfo.NETWORK_BYTES_UNKNOWN) {
final long bandwidth = capabilities.getLinkDownstreamBandwidthKbps();
// If we don't know the bandwidth, all we can do is hope the job finishes in time.
if (bandwidth != LINK_BANDWIDTH_UNSPECIFIED) {
if (bandwidth > 0) {
// Divide by 8 to convert bits to bytes.
final long estimatedMillis = ((downloadBytes * DateUtils.SECOND_IN_MILLIS)
/ (DataUnit.KIBIBYTES.toBytes(bandwidth) / 8));
......@@ -343,7 +342,7 @@ public final class ConnectivityController extends RestrictingController implemen
if (uploadBytes != JobInfo.NETWORK_BYTES_UNKNOWN) {
final long bandwidth = capabilities.getLinkUpstreamBandwidthKbps();
// If we don't know the bandwidth, all we can do is hope the job finishes in time.
if (bandwidth != LINK_BANDWIDTH_UNSPECIFIED) {
if (bandwidth > 0) {
// Divide by 8 to convert bits to bytes.
final long estimatedMillis = ((uploadBytes * DateUtils.SECOND_IN_MILLIS)
/ (DataUnit.KIBIBYTES.toBytes(bandwidth) / 8));
......@@ -373,18 +372,16 @@ public final class ConnectivityController extends RestrictingController implemen
private static boolean isStrictSatisfied(JobStatus jobStatus, Network network,
NetworkCapabilities capabilities, Constants constants) {
final NetworkCapabilities required;
// A restricted job that's out of quota MUST use an unmetered network.
if (jobStatus.getEffectiveStandbyBucket() == RESTRICTED_INDEX
&& !jobStatus.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA)) {
required = new NetworkCapabilities(
final NetworkCapabilities required = new NetworkCapabilities.Builder(
jobStatus.getJob().getRequiredNetwork().networkCapabilities)
.addCapability(NET_CAPABILITY_NOT_METERED);
.addCapability(NET_CAPABILITY_NOT_METERED).build();
return required.satisfiedByNetworkCapabilities(capabilities);
} else {
required = jobStatus.getJob().getRequiredNetwork().networkCapabilities;
return jobStatus.getJob().getRequiredNetwork().canBeSatisfiedBy(capabilities);
}
return required.satisfiedByNetworkCapabilities(capabilities);
}
private static boolean isRelaxedSatisfied(JobStatus jobStatus, Network network,
......@@ -395,9 +392,9 @@ public final class ConnectivityController extends RestrictingController implemen
}
// See if we match after relaxing any unmetered request
final NetworkCapabilities relaxed = new NetworkCapabilities(
final NetworkCapabilities relaxed = new NetworkCapabilities.Builder(
jobStatus.getJob().getRequiredNetwork().networkCapabilities)
.removeCapability(NET_CAPABILITY_NOT_METERED);
.removeCapability(NET_CAPABILITY_NOT_METERED).build();
if (relaxed.satisfiedByNetworkCapabilities(capabilities)) {
// TODO: treat this as "maybe" response; need to check quotas
return jobStatus.getFractionRunTime() > constants.CONN_PREFETCH_RELAX_FRAC;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment