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

Commit 1505d0ab authored by Yintang Gu's avatar Yintang Gu Committed by JeiFeng Lee
Browse files

Fix null pointer exception of calling NetworkInfo.mState.name()

Remove setting nai.networkInfo as null temporarily to identify the new
created NetworkAgent, avoiding timing issue triggered by constructor
NetworkInfo(null).

Bug: 135569043
Test: Mannual test, network can work normally
Change-Id: I123ef9e97df2bccdd9528c0e894283c66d053890
parent 760e80c1
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -5519,7 +5519,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
        }
        nai.asyncChannel.connect(mContext, mTrackerHandler, nai.messenger);
        NetworkInfo networkInfo = nai.networkInfo;
        nai.networkInfo = null;
        updateNetworkInfo(nai, networkInfo);
        updateUids(nai, null, nai.networkCapabilities);
    }
@@ -6518,8 +6517,7 @@ public class ConnectivityService extends IConnectivityManager.Stub

        if (DBG) {
            log(networkAgent.name() + " EVENT_NETWORK_INFO_CHANGED, going from " +
                    (oldInfo == null ? "null" : oldInfo.getState()) +
                    " to " + state);
                    oldInfo.getState() + " to " + state);
        }

        if (!networkAgent.created
@@ -6592,8 +6590,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
                // TODO(b/122649188): send the broadcast only to VPN users.
                mProxyTracker.sendProxyBroadcast();
            }
        } else if ((oldInfo != null && oldInfo.getState() == NetworkInfo.State.SUSPENDED) ||
                state == NetworkInfo.State.SUSPENDED) {
        } else if (networkAgent.created && (oldInfo.getState() == NetworkInfo.State.SUSPENDED ||
                state == NetworkInfo.State.SUSPENDED)) {
            // going into or coming out of SUSPEND: re-score and notify
            if (networkAgent.getCurrentScore() != oldScore) {
                rematchAllNetworksAndRequests(networkAgent, oldScore);
+2 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.connectivity;

import android.annotation.NonNull;
import android.content.Context;
import android.net.IDnsResolver;
import android.net.INetd;
@@ -116,7 +117,7 @@ import java.util.TreeSet;
// not, ConnectivityService disconnects the NetworkAgent's AsyncChannel.
public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {

    public NetworkInfo networkInfo;
    @NonNull public NetworkInfo networkInfo;
    // This Network object should always be used if possible, so as to encourage reuse of the
    // enclosed socket factory and connection pool.  Avoid creating other Network objects.
    // This Network object is always valid.