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

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

Merge "Make NetworkScore public API"

parents 6df78253 e2214bf6
Loading
Loading
Loading
Loading
+10 −5
Original line number Original line Diff line number Diff line
@@ -34,6 +34,7 @@ import android.net.NetworkFactory;
import android.net.NetworkInfo;
import android.net.NetworkInfo;
import android.net.NetworkProvider;
import android.net.NetworkProvider;
import android.net.NetworkRequest;
import android.net.NetworkRequest;
import android.net.NetworkScore;
import android.net.ProxyInfo;
import android.net.ProxyInfo;
import android.net.RouteInfo;
import android.net.RouteInfo;
import android.net.SocketKeepalive;
import android.net.SocketKeepalive;
@@ -160,7 +161,7 @@ public class DataConnection extends StateMachine {
    private static final int OTHER_CONNECTION_SCORE = 45;
    private static final int OTHER_CONNECTION_SCORE = 45;


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


    // The subscription id associated with this data connection.
    // The subscription id associated with this data connection.
    private int mSubId;
    private int mSubId;
@@ -2949,21 +2950,23 @@ public class DataConnection extends StateMachine {
     *  Re-calculate score and update through network agent if it changes.
     *  Re-calculate score and update through network agent if it changes.
     */
     */
    private void updateScore() {
    private void updateScore() {
        int oldScore = mScore;
        final NetworkScore oldScore = mScore;
        mScore = calculateScore();
        mScore = calculateScore();
        if (oldScore != mScore && mNetworkAgent != null) {
        if (!oldScore.equals(mScore) && mNetworkAgent != null) {
            log("Updating score from " + oldScore + " to " + mScore);
            log("Updating score from " + oldScore + " to " + mScore);
            mNetworkAgent.sendNetworkScore(mScore, this);
            mNetworkAgent.sendNetworkScore(mScore, this);
        }
        }
    }
    }


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


        // If it's serving a network request that asks NET_CAPABILITY_INTERNET and doesn't have
        // 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
        // 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
        // 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.
        // 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 (ApnContext apnContext : mApnContexts.keySet()) {
            for (NetworkRequest networkRequest : apnContext.getNetworkRequests()) {
            for (NetworkRequest networkRequest : apnContext.getNetworkRequests()) {
                if (networkRequest.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
                if (networkRequest.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
@@ -2974,7 +2977,9 @@ public class DataConnection extends StateMachine {
            }
            }
        }
        }


        return score;
        // 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();
    }
    }


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


    private NetworkInfo mNetworkInfo;
    private NetworkInfo mNetworkInfo;


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


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


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