Android7 增加双以太网eth1的支持

--- a/frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetNetworkFactory.java
+++ b/frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetNetworkFactory.java
@@ -146,7 +146,8 @@ class EthernetNetworkFactory {
      */
     private void updateInterfaceState(String iface, boolean up) {
         if (!mIface.equals(iface)) {
-            //return;
+            if(iface.equals("eth1")){ //增加一个判断优化影响wifi问题
+             mIface = iface; //更新mIface后面dhcp IP用
+             }else{
+             return;
+                }
         }
         Log.d(TAG, "updateInterface: " + iface + " link " + (up ? "up" : "down"));

Note1:

      Android 7 默认开机测试eth0是up的,eth1是down的,"cat: /sys/class/net/eth1/carrier: Invalid argument",网上说:有的网口为了省电驱动默认是down的,需要ifconfig eth1 up。QCOM平台双usb转网测试eth1开机需要手动"ifconfig eth1 up"才正常。这一行命令开机写到开机脚本也失败。暂时计划apk自启动后下发。测试可行。

//Android 7 framework层usb转网插拔、网线插拔检测类
private class InterfaceObserver extends BaseNetworkObserver {
        @Override
        public void interfaceLinkStateChanged(String iface, boolean up) {
            updateInterfaceState(iface, up); //网线插拔调用
        }

        @Override
        public void interfaceAdded(String iface) {
            maybeTrackInterface(iface); //usb转网连接调用
        }

        @Override
        public void interfaceRemoved(String iface) {
            stopTrackingInterface(iface); //usb转网移除调用
        }
    }

Note2:

        Android 7 以太网连接符号"<......>"只有eth1网口分配到IP地址后才会显示,手动ifconfig分配一个IP地址也可以显示。系统默认是只支持dhcp分配ip地址,在framework层onRequestNetwork函数中。

if (config.getIpAssignment() == IpAssignment.STATIC) {//静态
                    if (!setStaticIpAddress(config.getStaticIpConfiguration())) {
                        // We've already logged an error.
                        return;
                    }
                    linkProperties = config.getStaticIpConfiguration().toLinkProperties(mIface);
                } else {//动态
                    mNetworkInfo.setDetailedState(DetailedState.OBTAINING_IPADDR, null, mHwAddr);
                    WaitForProvisioningCallback ipmCallback = new WaitForProvisioningCallback() {
                        @Override
                        public void onLinkPropertiesChange(LinkProperties newLp) {
                            synchronized(EthernetNetworkFactory.this) {
                                if (mNetworkAgent != null && mNetworkInfo.isConnected()) {
                                    mLinkProperties = newLp;
                                    mNetworkAgent.sendLinkProperties(newLp);
                                }
                            }
                        }
                    };

 

你可能感兴趣的:(QCOM平台,Android)