1. 程式人生 > >RK3288 Android5.1 SDK配置WiFi和乙太網共存

RK3288 Android5.1 SDK配置WiFi和乙太網共存

RK3288 Android 5.1官方SDK(rk3288_android5.1_v1.00_20150515,已更新到20180412),在Rockchip官方提供的RK_EVB_RK3288核心板上驗證OK。

根據Rockchip官方提供的補丁和配置方法,WiFi和乙太網可以共存,而且WiFi配置連線因特網,乙太網連線內部區域網,互不干擾。以下是具體的修改方法和補丁:


1)實現乙太網wifi共存,補丁如下:
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) {



2)若需要wifi訪問外網,乙太網用於訪問區域網,則打如下補丁: 
[email protected]:~/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)如果用ping命令發現只能ping通乙太網wifi中的一個時,輸入如下命令:

ip rule add from all lookup main pref 9999



4)共存且wifi優先順序高時,若斷開wifi後,設定介面乙太網也顯示未連線,或者先連線wifi後,再連線乙太網時,乙太網連線失敗,則用下面補丁:
[email protected]:~/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_DISCONNECTED){   //注意Android6.0可能是EthernetManager.ETHERNET_CONNECT_STATE_DISCONNECT
+                        return ;
+                }
                 if (DBG) Log.i(TAG, "dhcpThread(+" + mIface + "): mNetworkInfo=" + mNetworkInfo);
                 LinkProperties linkProperties;
 
 
/rk3288_rel_5.1/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");