[RK3399][Android7.1] Ethernet -- 在设置-Ethernet中切换静态/动态模式,然后连接网线,测试网络获取不到IP的问题

测试平台

Platform: RK3399
OS: Android 7.1

现象

断开网线后,在设置-Ethernet中切换静态/动态模式,然后连接网线,测试网络获取不到IP的问题。

分析

简单分析下代码,设置以太网ip static/dhcp的流程是:

 packages/apps/Settings/src/com/android/settings/ethernet/EthernetSettings.java
 -->
 mEthManager.setConfiguration(new IpConfiguration(IpAssignment.DHCP, ProxySettings.NONE,null,null));//设置静态Ip
 mEthManager.setConfiguration(new IpConfiguration(IpAssignment.STATIC,ProxySettings.NONE,mStaticIpConfiguration,null));//设置dhcp
 -->
 frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetServiceImpl.java
 public void setConfiguration(IpConfiguration config) {
 		...
     	mTracker.reconnect("eth0");
     	...
 }
 -->
 frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetNetworkFactory.java
 public void reconnect(String iface) {
		...
		updateInterfaceState(iface, false);
		...
        updateInterfaceState(iface, true);
 }
 private void updateInterfaceState(String iface, boolean up) {
        if (!mIface.equals(iface)) {
            return;
        }
        if (!mReconnecting)
            Log.d(TAG, "updateInterface: " + iface + " link " + (up ? "up" : "down"));

        if (up && mEthernetCurrentState != EthernetManager.ETHER_STATE_DISCONNECTED) {
            Log.d(TAG, "Already connected or connecting, skip connect");
            return;
        }
        ...
 }

查看流程可以知道切换static/dhcp时会调用reconnect()来重启接口,且重启后up的状态设置为true.但是此时并没有判断以太网的状态,若此时网线没有连接,将up更新为true,那么当插入网线调用updateInterfaceState(iface, true)来获取IP时,由于up已经为true,所以不会进行操作而是直接返回,所以导致获取不到ip的问题。

解决方案

diff --git a/frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetNetworkFactory.java b/frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetNetworkFactory.java

index 6d4c3e9..0ac7f17 100755 (executable)

--- a/frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetNetworkFactory.java
+++ b/frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetNetworkFactory.java
@@ -232,6 +232,15 @@ class EthernetNetworkFactory {
     /**
       * Updates interface state variables.
       * Called on link state changes or on startup.
       */
      private void updateInterfaceState(String iface, boolean up) {
          if (!mIface.equals(iface)) {
             return;
          }
          if (!mReconnecting)
              Log.d(TAG, "updateInterface: " + iface + " link " + (up ? "up" : "down"));
  
          if (up && mEthernetCurrentState != EthernetManager.ETHER_STATE_DISCONNECTED) {
              Log.d(TAG, "Already connected or connecting, skip connect");
              return;
          }
+
+        if(up){
+            int carrier = getEthernetCarrierState(iface);
+            Log.d(TAG, "carrier:"+carrier);
+            if (carrier != 1) {
+                return;
+            }
+        }
+
展开阅读全文

没有更多推荐了,返回首页