1. 程式人生 > >android新增乙太網ethernet方法 android框架新增

android新增乙太網ethernet方法 android框架新增

下載原始碼地址:http://download.csdn.net/download/wocao1226/10134749

增加ethernet主要是三部分:1、ethernet service; 2、ethernet Settings  3、Systemui ethernet通知

以下提到的原始檔將會在文章最後提供下載地址

拷貝frameworks/base/ethernet到frameworks/base下

修改frameworks/base/Android.mk


    wifi/Java/android/net/wifi/p2p/IWifiP2pManager.aidl \
下加上如下程式碼

  1. ethernet/java/android/net/ethernet/IEthernetManager.aidl \  
修改build/core/pathmap.mk在
FRAMEWORKS_BASE_SUBDIRS中加上ethernet

拷貝EthernetService.java到frameworks/base/services/java/com/android/server/下

修改frameworks/base/core/java/android/content/Context.java

    public static final String WIFI_P2P_SERVICE = "wifip2p";
下加上如下內容

  1. /** 
  2.  * Use with {@link #getSystemService} to retrieve a {@link 
  3.  * android.net.ethernet.EthernetManager} for handling management of 
  4.  * Ethernet access. 
  5.  * 
  6.  * @see #getSystemService 
  7.  * @see android.net.ethernet.EthernetManager 
  8.  */
  9. publicstaticfinal String ETH_SERVICE = "ethernet"
    ;//add by hclydao
修改frameworks/base/core/java/android/app/ContextImpl.java

import android.net.wifi.p2p.IWifiP2pManager;
import android.net.wifi.p2p.WifiP2pManager;
下增加如下內容
  1. import android.net.ethernet.IEthernetManager;  
  2. import android.net.ethernet.EthernetManager;  

在     

registerService(WIFI_P2P_SERVICE, new ServiceFetcher() {
                public Object createService(ContextImpl ctx) {
                    IBinder b = ServiceManager.getService(WIFI_P2P_SERVICE);
                    IWifiP2pManager service = IWifiP2pManager.Stub.asInterface(b);
                    return new WifiP2pManager(service);
                }});

下增加如下內容

  1. registerService(ETH_SERVICE, new ServiceFetcher() {  
  2.         public Object createService(ContextImpl ctx) {  
  3.             IBinder b = ServiceManager.getService(ETH_SERVICE);  
  4.             IEthernetManager service = IEthernetManager.Stub.asInterface(b);  
  5.             returnnew EthernetManager(service, ctx.mMainThread.getHandler());  
  6.         }}); //add by hclydao
修改frameworks/base/services/java/com/android/server/ConnectivityService.java
增加
  1. import android.net.ethernet.EthernetManager;//add by hclydao
  2. import android.net.ethernet.EthernetStateTracker;  
註釋掉
//import android.net.EthernetDataTracker;

            try {
                tracker = netFactory.createTracker(targetNetworkType, config);
                mNetTrackers[targetNetworkType] = tracker;
            } catch (IllegalArgumentException e) {
                Slog.e(TAG, "Problem creating " + getNetworkTypeName(targetNetworkType)
                        + " tracker: " + e);
                continue;
            }

下加上如下程式碼

            if(mNetConfigs[targetNetworkType].radio == ConnectivityManager.TYPE_ETHERNET) { //add by hclydao
                EthernetService ethernet = new EthernetService(context, (EthernetStateTracker)mNetTrackers[targetNetworkType]);
                ServiceManager.addService(Context.ETH_SERVICE, ethernet);
                mNetTrackers[targetNetworkType].startMonitoring(context, mTrackerHandler);
            }

註釋掉
                    //return EthernetDataTracker.getInstance();

增加如下程式碼

  1. returnnew EthernetStateTracker(targetNetworkType, config.name);//add by hclydao
拷貝android_net_ethernet.cpp到frameworks/base/core/jni目錄下
修改frameworks/base/core/jni下的Android.mk

    android_net_wifi_WifiNative.cpp \
下加上如下程式碼
  1. android_net_ethernet.cpp \  

修改frameworks/base/core/jni/AndroidRuntime.cpp

extern int register_android_net_wifi_WifiNative(JNIEnv* env);下
加上

extern int register_android_net_ethernet_EthernetManager(JNIEnv* env);//add by hclydao


REG_JNI(register_android_net_wifi_WifiNative),
下加上如下程式碼

  1. REG_JNI(register_android_net_ethernet_EthernetManager),  
在framework/base/core/java/android/provider/Settings.java中
       public static final String WIFI_ON = "wifi_on";
下加上如下程式碼
  1. publicstaticfinal String ETH_ON      = "eth_on";  
  2. publicstaticfinal String ETH_MODE    = "eth_mode";  
  3. publicstaticfinal String ETH_IP      = "eth_ip";  
  4. publicstaticfinal String ETH_MASK    = "eth_mask";  
  5. publicstaticfinal String ETH_DNS     = "eth_dns";  
  6. publicstaticfinal String ETH_ROUTE   = "eth_route";  
  7. publicstaticfinal String ETH_CONF    = "eth_conf";  
  8. publicstaticfinal String ETH_IFNAME  = "eth_ifname";  

Settings部分修改

拷貝eth_configure.xml到Settings/res/layout/
拷貝ic_setttings_ethernet.png到Settings/res/drawable-hdpi與drawable-mdpi
拷貝ethernet_settings.xml到Settings/res/xml下
修改xml下settings_headers.xml在wifi下增加如下內容

  1. <!-- Ethernet -->  
  2. lt;header  
  3.     android:id="@+id/ethernet_settings"
  4.     android:title="@string/eth_setting"
  5.     android:icon="@drawable/ic_settings_ethernet"
  6.     android:fragment="com.android.settings.ethernet.EthernetSettings"/>  
修改values/strings.xml增加如下內容
  1. <!-- Ethernet configuration dialog -->  
  2. <string name="eth_config_title">Configure Ethernet device</string>  
  3. <string name="eth_setting">Ethernet</string>  
  4. <string name="eth_dev_list">Ethernet Devices:</string>  
  5. <string name="eth_con_type">Connection Type</string>  
  6. <string name="eth_con_type_dhcp">DHCP</string>  
  7. <string name="eth_con_type_manual">Static IP</string>  
  8. <string name="eth_dns">DNS address</string>  
  9. <string name="eth_gw">Gateway address</string>  
  10. <string name="eth_ipaddr">IP address</string>  
  11. <string name="eth_quick_toggle_title">Ethernet</string>  
  12. <string name="eth_quick_toggle_summary">Turn on Ethernet</string>  
  13. <string name="eth_conf_perf_title">Ethernet configuration</string>  
  14. <string name="eth_conf_summary">Configure Ethernet devices</string>  
  15. <string name="eth_mask">Netmask</string>  
  16. <string name="eth_toggle_summary_off">Turn off Ethernet</string>  
  17. <string name="eth_toggle_summary_on">Turn on Ethernet</string>  
  18. <string name="eth_settings_error">Failed to set: Please enter the valid characters 0~255</string>