Android 13 setting a static ip causes the wired network to keep disconnecting and reconnecting analysis and solution

Android 13 setting a static ip causes the wired network to keep disconnecting and reconnecting analysis and solution

This article shares a bug of Android13 wired network! Or rather a modification of the new wired network.

Android13 found a problem when setting a static ip address, the wired network would keep disconnecting and reconnecting.

A normal gateway does not have this problem, but a wrong gateway will have this problem.

1. Simple analysis and solution

1. Log clues:

Find the key log of the cyclic disconnection, and find out the log of disconnecting the network after the connection is made from the log.


05-13 15:28:38.768  1186  3064 W IpClient.eth0: [IpReachabilityMonitor] WARN ALERT neighbor went from: null to: NeighborEvent{@43196,RTM_NEWNEIGH,if=14,170.168.20.1,NUD_FAILED,[null]}
05-13 15:28:38.768   445  3068 W resolv  : Validation failed
05-13 15:28:38.769  1186  3064 W IpReachabilityMonitor: FAILURE: LOST_PROVISIONING, NeighborEvent{@43196,RTM_NEWNEIGH,if=14,170.168.20.1,NUD_FAILED,[null]}
05-13 15:28:38.770   802  1023 I EthernetNetworkFactory: updateNeighborLostEvent FAILURE: LOST_PROVISIONING, NeighborEvent{@43196,RTM_NEWNEIGH,if=14,170.168.20.1,NUD_FAILED,[null]}
05-13 15:28:38.771   802  1023 D EthernetNetworkFactory: reconnecting Ethernet
05-13 15:28:38.845   802  1023 D EthernetNetworkFactory: Starting Ethernet IpClient(eth0)
05-13 15:28:38.846   802  1024 D ConnectivityService: [105 ETHERNET] EVENT_NETWORK_INFO_CHANGED, going from CONNECTED to DISCONNECTED
05-13 15:28:38.846   802  1024 D ConnectivityService: [105 ETHERNET] disconnected, was satisfying 16
05-13 15:28:38.851   802  1024 W BestClock: java.time.DateTimeException: Missing NTP fix

From the log above, we can see that the IpReachabilityMonitor class prints the verification failure information,
and then notifies EthernetNetworkFactory and ConnectivityService.

And it is easy to see the related process class from the log:

2. Related code classes:

packages\modules\Connectivity\service\src\com\android\server\ConnectivityService.java

packages\modules\Connectivity\service-t\src\com\android\server\ethernet\EthernetNetworkFactory.java

packages\modules\NetworkStack\src\android\net\ip\IpReachabilityMonitor.java

3. Key code for reconnection

EthernetNetworkFactory.java


        void updateNeighborLostEvent(String logMsg) {
            Log.i(TAG, "updateNeighborLostEvent " + logMsg); //上面日志是有打印这个方法的!
            // Reachability lost will be seen only if the gateway is not reachable.(这里写了网关不可用会回调这里)
            // Since ethernet FW doesn't have the mechanism to scan for new networks
            // like WiFi, simply restart.
            // If there is a better network, that will become default and apps
            // will be able to use internet. If ethernet gets connected again,(这里写了有线网会重连!)
            // and has backhaul connectivity, it will become default.
            restart(); // 注释了这行代码,就不会一直断开重连了!
        }

        void restart() {
            restart(null);
        }


        //断开重连的重要流程
        void restart(@Nullable final INetworkInterfaceOutcomeReceiver listener) {
            if (DBG) Log.d(TAG, "reconnecting Ethernet");
            stop();//断开有线网
            start(listener);//启动有线网
        }

From the above code, it can be seen that restart is the key point for the system to keep disconnecting and reconnecting to the wired network.

As for where to check the gateway, there is a trace analysis of IpReachabilityMonitor.

In fact, you can probably guess that it should be somewhere in the cable network service. After setting up the gateway,
there is a Client object. Use the sub-thread to connect to the gateway address to determine whether the connection is normal. If the connection fails, a callback will be made, and the callback will be made all the way later. .

4. The solution is to keep reconnecting:

(1) Remove the inspection of the gateway by the wired network

This is to chase the code,
idea 1, to trace and analyze before IpReachabilityMonitor;
idea 2, set the configuration object of the wired network gateway from EthernetManager and analyze all the way down.

There is no need to analyze this temporarily, and those who are interested can analyze it automatically.

(2) Remove the reconnection operation

In EthernetNetworkFactory.java, just remove the call of the restart() method.

other:

Compared with Android11, Android13 wired network has more changes.

Android 13 wired network changes:
https://blog.csdn.net/wenzhi20102321/article/details/130607641

Android11 ​​wired network and wifi priority settings:
https://blog.csdn.net/wenzhi20102321/article/details/122243516

Other cable network introduction:
https://so.csdn.net/so/search?q=%E6%9C%89%E7%BA%BF%E7%BD%91&t=blog&u=wenzhi20102321

Guess you like

Origin blog.csdn.net/wenzhi20102321/article/details/131296086
Recommended