RK3399 实现内外网共存补丁,并且wifi先连接是以太网连接失败

RK3399 实现内外网共存补丁:

(注:基于rk3399已经测试通过)

1)实现网络共存,补丁如下
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 327fb8a..e5bcb04 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -166,9 +166,17 @@ public class ConnectivityService extends IConnectivityManager.Stub
     private static final String TAG = "ConnectivityService";

     private static final boolean DBG = true;
     private static final boolean VDBG = false;

     private static final boolean LOGD_RULES = false;
+    private static final boolean LOGD_BLOCKED_NETWORKINFO = true;
+    
+    // if true:
+    //    wifi and ethernet can coexist, if wifi and ethernet connect together, prefered to use ethernet
+    // if false:
+    //    wifi and ethernet can't coexist, if wifi and ethernet connect together, will tear down wifi
+    //    TODO: still have bug in this case to fix (like can't reconnect wifi when ethernet disconnect)
+    private static final boolean ENABLE_NETWORK_COEXIST = true;

     // TODO: create better separation between radio types and network types

@@ -4247,7 +4255,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
             loge("Dead network still had at least " + nr);
             break;
         }
-        nai.asyncChannel.disconnect();
+
+        if (ENABLE_NETWORK_COEXIST) {
+            log("Skip teardownUnneededNetwork: " + nai.name

());
+        } else {
+            nai.asyncChannel.disconnect();
+        }
     }

     private void handleLingerComplete(NetworkAgentInfo oldNetwork) {
     
===============================================================================================================================
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 020495f..3e4794b 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -4805,6 +4805,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
 
         if (ENABLE_NETWORK_COEXIST) {
             log("Skip teardownUnneededNetwork: " + nai.name());
+            if (nai.getCurrentScore() > 0) {
+                try {
+                    mNetd.removeInterfaceFromNetwork(nai.linkProperties.getInterfaceName(), nai.network.netId);
+                    mNetd.addInterfaceToLocalNetwork(nai.linkProperties.getInterfaceName(), nai.linkProperties.getRoutes());
+                    mLegacyTypeTracker.add(nai.networkInfo.getType(), nai);
+                } catch (RemoteException e) {
+                    Log.e(TAG, "Failed to add iface to local network " + e);
+                }
+            }
         } else {
             nai.asyncChannel.disconnect();
         }
@@ -4953,6 +4962,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
                     } else {
                         if (VDBG) log("   accepting network in place of null");
                     }
+                    if (ENABLE_NETWORK_COEXIST) {
+                        try {
+                            mNetd.removeInterfaceFromLocalNetwork(newNetwork.linkProperties.getInterfaceName());
+                        } catch(RemoteException e) {}
+                        updateLinkProperties(newNetwork,null);
+                    }
                     newNetwork.unlingerRequest(nri.request);
                     mNetworkForRequestId.put(nri.request.requestId, newNetwork);
                     if (!newNetwork.addRequest(nri.request)) {
@@ -5297,6 +5312,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
             // This has to happen after matching the requests, because callbacks are just requests.
             notifyNetworkCallbacks(networkAgent, ConnectivityManager.CALLBACK_PRECHECK);
         } else if (state == NetworkInfo.State.DISCONNECTED) {
+            if (ENABLE_NETWORK_COEXIST) {
+                try {
+                    mNetd.removeInterfaceFromLocalNetwork(networkAgent.linkProperties.getInterfaceName());
+                } catch(RemoteException e) {}
+            }
             networkAgent.asyncChannel.disconnect();
             if (networkAgent.isVPN()) {
                 synchronized (mProxyLock) {

 


2)若需要wifi访问外网,以太网用于访问局域网,则打如下补丁:

fzk@RD-DEP1-SERVER-163:~/rk3288_rel_5.1/frameworks/opt/net/ethernet$ git diff
diff --git a/java/com/android/server/ethernet/EthernetNetworkFactory.java b/java/com/android/server/ethernet/EthernetNetworkFactory.java
index e5cb6f9..8abc5ea 100644
--- a/java/com/android/server/ethernet/EthernetNetworkFactory.java
+++ b/java/com/android/server/ethernet/EthernetNetworkFactory.java
@@ -81,7 +81,7 @@ import java.lang.Exception;
 class EthernetNetworkFactory {
     private static final String NETWORK_TYPE = "Ethernet";
     private static final String TAG = "EthernetNetworkFactory";
-    private static final int NETWORK_SCORE = 150;
+    private static final int NETWORK_SCORE = 30;
     private static final boolean DBG = true;
     private static final boolean VDBG = false;

     
     
3)共存且wifi优先级高时,若断开wifi后,设置界面以太网也显示未连接,或者先连接wifi后,再连接以太网时,以太网连接失败,则用下面补丁

在wifi先连接时,以太网获取不到IP,需要检查 ./frameworks/base/core/java/android/net/NetworkFactory.java中carrier 的值;

另外,在adb shell中使用命令:cat /sys/class/net/eth0/carrier ,然后插拔多次看对应的值是多少,正常0是拔出,1是插入。若0,1插拔正常,则是最后一个补丁没有打上。

fzk@RD-DEP1-SERVER-163:~/rk3288_rel_5.1/frameworks/opt/net/ethernet$ git diff
diff --git a/java/com/android/server/ethernet/EthernetNetworkFactory.java b/java/com/android/server/ethernet/EthernetNetworkFactory.java
index e80b252..974fa0f 100755
--- a/java/com/android/server/ethernet/EthernetNetworkFactory.java
+++ b/java/com/android/server/ethernet/EthernetNetworkFactory.java
@@ -411,6 +411,9 @@ class EthernetNetworkFactory {
         // TODO: Handle DHCP renew.
         Thread dhcpThread = new Thread(new Runnable() {
             public void run() {
+                if (mEthernetCurrentState == EthernetManager.ETHER_STATE_CONNECTED){   //注意Android6.0可能是EthernetManager.ETHERNET_CONNECT_STATE_CONNECT
+                        return ;
+                }
                 if (DBG) Log.i(TAG, "dhcpThread(+" + mIface + "): mNetworkInfo=" + mNetworkInfo);
                 LinkProperties linkProperties;
                 
================================================================================================================

7.0 还需打上以下两个文件的补丁 {我就是因为没有打最后一个补丁,浪费了不少时间}):
diff --git a/java/com/android/server/ethernet/EthernetNetworkFactory.java b/java/com/android/server/ethernet/EthernetNetworkFactory.java
index 15fe2e2..729070a 100755
--- a/java/com/android/server/ethernet/EthernetNetworkFactory.java
+++ b/java/com/android/server/ethernet/EthernetNetworkFactory.java
@@ -408,6 +446,10 @@ class EthernetNetworkFactory {
         if (carrier != 1) {
             return;
         }
+        
+        if (mEthernetCurrentState == EthernetManager.ETHER_STATE_CONNECTED){
+            return ;
+        }
 
         synchronized(EthernetNetworkFactory.this) {
             if (mIpProvisioningThread != null) {


./frameworks/base$ git diff
diff --git a/core/java/android/net/NetworkFactory.java b/core/java/android/net/NetworkFactory.java
index 64d0fcf..c4ae1a3 100644
--- a/core/java/android/net/NetworkFactory.java
+++ b/core/java/android/net/NetworkFactory.java
@@ -220,7 +220,7 @@ public class NetworkFactory extends Handler {

     private void evalRequest(NetworkRequestInfo n) {
         if (VDBG) log("evalRequest");
-        if (n.requested == false && n.score < mScore &&
+        if (n.requested == false && 0 < mScore &&
                 n.request.networkCapabilities.satisfiedByNetworkCapabilities(
                 mCapabilityFilter) && acceptRequest(n.request, n.score)) {
             if (VDBG) log("  needNetworkFor");

你可能感兴趣的:(RK3399 实现内外网共存补丁,并且wifi先连接是以太网连接失败)