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

Commit e2214bf6 authored by Chalard Jean's avatar Chalard Jean
Browse files

Make NetworkScore public API

Bug: 146583853
Test: FrameworksNetTests FrameworkTelephonyTests
Change-Id: Ic66654a1cba9dc588da379d492611062c8288a55
parent d1061cd3
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ 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;
@@ -160,7 +161,7 @@ public class DataConnection extends StateMachine {
    private static final int OTHER_CONNECTION_SCORE = 45;

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

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

    private int calculateScore() {
    private NetworkScore 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)
@@ -2973,7 +2976,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) {
+3 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ 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;
@@ -70,7 +71,7 @@ public class DcNetworkAgent extends NetworkAgent {

    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) {
        super(phone.getContext(), dc.getHandler().getLooper(), "DcNetworkAgent",
                dc.getNetworkCapabilities(), dc.getLinkProperties(), score, config,
@@ -234,7 +235,7 @@ public class DcNetworkAgent extends NetworkAgent {
     * @param score The network score.
     * @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;
        sendNetworkScore(score);
    }
+1 −1
Original line number Diff line number Diff line
@@ -675,7 +675,7 @@ public class ContextFixture implements TestFixture<Context> {
        doReturn(mBundle).when(mCarrierConfigManager).getConfig();

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