Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 844e827f authored by Chalard Jean's avatar Chalard Jean Committed by Android (Google) Code Review
Browse files

Merge "Revert "Make NetworkScore public API"" into rvc-dev

parents 566065f7 07475509
Loading
Loading
Loading
Loading
+7 −18
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static android.net.NetworkPolicyManager.SUBSCRIPTION_OVERRIDE_CONGESTED;
import static android.net.NetworkPolicyManager.SUBSCRIPTION_OVERRIDE_UNMETERED;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.PendingIntent;
import android.content.Context;
@@ -35,7 +34,6 @@ import android.net.NetworkFactory;
import android.net.NetworkInfo;
import android.net.NetworkProvider;
import android.net.NetworkRequest;
import android.net.NetworkScore;
import android.net.ProxyInfo;
import android.net.RouteInfo;
import android.net.SocketKeepalive;
@@ -101,7 +99,6 @@ import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

@@ -162,7 +159,7 @@ public class DataConnection extends StateMachine {
    private static final int OTHER_CONNECTION_SCORE = 45;

    // The score we report to connectivity service
    private NetworkScore mScore;
    private int mScore;

    // The subscription id associated with this data connection.
    private int mSubId;
@@ -2951,27 +2948,21 @@ public class DataConnection extends StateMachine {
     *  Re-calculate score and update through network agent if it changes.
     */
    private void updateScore() {
        // No need to update the score if there is no network associated.
        if (mNetworkAgent == null) return;

        final NetworkScore score =  calculateScore();
        if (!Objects.equals(score, mScore)) {
            log("Updating score from " + mScore + " to " + score);
            mScore = score;
        int oldScore = mScore;
        mScore = calculateScore();
        if (oldScore != mScore && mNetworkAgent != null) {
            log("Updating score from " + oldScore + " to " + mScore);
            mNetworkAgent.sendNetworkScore(mScore, this);
        }
    }

    @NonNull
    private NetworkScore calculateScore() {
    private int calculateScore() {
        int score = OTHER_CONNECTION_SCORE;

        // If it's serving a network request that asks NET_CAPABILITY_INTERNET and doesn't have
        // specify a subId, this dataConnection is considered to be default Internet data
        // connection. In this case we assign a slightly higher score of 50. The intention is
        // it will not be replaced by other data connections accidentally in DSDS usecase.
        // TODO : this should be represented by the "default subscription" policy bit in
        // NetworkScore.
        for (ApnContext apnContext : mApnContexts.keySet()) {
            for (NetworkRequest networkRequest : apnContext.getNetworkRequests()) {
                if (networkRequest.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
@@ -2982,9 +2973,7 @@ public class DataConnection extends StateMachine {
            }
        }

        // STOPSHIP (b/148055573) : remove this copy of the constant (and the constant, this
        // code should just use the NetworkScore regular members)
        return new NetworkScore.Builder().setLegacyScore(score).build();
        return score;
    }

    private String handoverStateToString(@HandoverState int state) {
+2 −3
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.net.NetworkAgentConfig;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkProvider;
import android.net.NetworkScore;
import android.net.SocketKeepalive;
import android.os.Message;
import android.telephony.AccessNetworkConstants;
@@ -74,7 +73,7 @@ public class DcNetworkAgent extends NetworkAgent {

    private NetworkInfo mNetworkInfo;

    DcNetworkAgent(DataConnection dc, Phone phone, NetworkInfo ni, NetworkScore score,
    DcNetworkAgent(DataConnection dc, Phone phone, NetworkInfo ni, int score,
            NetworkAgentConfig config, NetworkProvider networkProvider, int transportType) {
        super(phone.getContext(), dc.getHandler().getLooper(), "DcNetworkAgent",
                dc.getNetworkCapabilities(), dc.getLinkProperties(), score, config,
@@ -241,7 +240,7 @@ public class DcNetworkAgent extends NetworkAgent {
     * @param score The network score.
     * @param dc The data connection that invokes this method.
     */
    public synchronized void sendNetworkScore(NetworkScore score, DataConnection dc) {
    public synchronized void sendNetworkScore(int score, DataConnection dc) {
        if (!isOwned(dc, "sendNetworkScore")) return;
        sendNetworkScore(score);
    }
+1 −1
Original line number Diff line number Diff line
@@ -677,7 +677,7 @@ public class ContextFixture implements TestFixture<Context> {
        doReturn(mBundle).when(mCarrierConfigManager).getConfig();

        doReturn(mock(Network.class)).when(mConnectivityManager).registerNetworkAgent(
                any(), any(), any(), any(), any(), any(), anyInt());
                any(), any(), any(), any(), anyInt(), any(), anyInt());

        doReturn(true).when(mEuiccManager).isEnabled();