Loading services/core/java/com/android/server/connectivity/NetworkRanker.java +5 −4 Original line number Original line Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.Nullable; import android.net.NetworkRequest; import android.net.NetworkRequest; import java.util.ArrayList; import java.util.Collection; import java.util.Collection; /** /** Loading @@ -31,15 +32,15 @@ public class NetworkRanker { /** /** * Find the best network satisfying this request among the list of passed networks. * Find the best network satisfying this request among the list of passed networks. */ */ // Almost equivalent to Collections.max(nais), but allows returning null if no network // satisfies the request. @Nullable @Nullable public NetworkAgentInfo getBestNetwork(@NonNull final NetworkRequest request, public NetworkAgentInfo getBestNetwork(@NonNull final NetworkRequest request, @NonNull final Collection<NetworkAgentInfo> nais) { @NonNull final Collection<NetworkAgentInfo> nais) { final ArrayList<NetworkAgentInfo> candidates = new ArrayList<>(nais); candidates.removeIf(nai -> !nai.satisfies(request)); NetworkAgentInfo bestNetwork = null; NetworkAgentInfo bestNetwork = null; int bestScore = Integer.MIN_VALUE; int bestScore = Integer.MIN_VALUE; for (final NetworkAgentInfo nai : nais) { for (final NetworkAgentInfo nai : candidates) { if (!nai.satisfies(request)) continue; if (nai.getCurrentScore() > bestScore) { if (nai.getCurrentScore() > bestScore) { bestNetwork = nai; bestNetwork = nai; bestScore = nai.getCurrentScore(); bestScore = nai.getCurrentScore(); Loading Loading
services/core/java/com/android/server/connectivity/NetworkRanker.java +5 −4 Original line number Original line Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.Nullable; import android.net.NetworkRequest; import android.net.NetworkRequest; import java.util.ArrayList; import java.util.Collection; import java.util.Collection; /** /** Loading @@ -31,15 +32,15 @@ public class NetworkRanker { /** /** * Find the best network satisfying this request among the list of passed networks. * Find the best network satisfying this request among the list of passed networks. */ */ // Almost equivalent to Collections.max(nais), but allows returning null if no network // satisfies the request. @Nullable @Nullable public NetworkAgentInfo getBestNetwork(@NonNull final NetworkRequest request, public NetworkAgentInfo getBestNetwork(@NonNull final NetworkRequest request, @NonNull final Collection<NetworkAgentInfo> nais) { @NonNull final Collection<NetworkAgentInfo> nais) { final ArrayList<NetworkAgentInfo> candidates = new ArrayList<>(nais); candidates.removeIf(nai -> !nai.satisfies(request)); NetworkAgentInfo bestNetwork = null; NetworkAgentInfo bestNetwork = null; int bestScore = Integer.MIN_VALUE; int bestScore = Integer.MIN_VALUE; for (final NetworkAgentInfo nai : nais) { for (final NetworkAgentInfo nai : candidates) { if (!nai.satisfies(request)) continue; if (nai.getCurrentScore() > bestScore) { if (nai.getCurrentScore() > bestScore) { bestNetwork = nai; bestNetwork = nai; bestScore = nai.getCurrentScore(); bestScore = nai.getCurrentScore(); Loading