android添加以太网ethernet方法 android框架添加

 

imx6 android4.4增加ethernet

下载源码地址: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 \
下加上如下代码

[java]  view plain  copy
 
 
  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";
下加上如下内容

[java]  view plain  copy
 
 
  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. public static final 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;
下增加如下内容
[java]  view plain  copy
 
 
  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);
                }});

下增加如下内容


[java]  view plain  copy
 
 
  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.             return new EthernetManager(service, ctx.mMainThread.getHandler());  
  6.         }}); //add by hclydao  
修改frameworks/base/services/java/com/android/server/ConnectivityService.java
增加
[java]  view plain  copy
 
 
  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();

增加如下代码

[java]  view plain  copy
 
 
  1. return new 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 \
下加上如下代码


[java]  view plain  copy
 
 
  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),
下加上如下代码

[java]  view plain  copy
 
 
  1. REG_JNI(register_android_net_ethernet_EthernetManager),  
在framework/base/core/java/android/provider/Settings.java中
       public static final String WIFI_ON = "wifi_on";
下加上如下代码
[java]  view plain  copy
 
 
  1. public static final String ETH_ON      = "eth_on";  
  2. public static final String ETH_MODE    = "eth_mode";  
  3. public static final String ETH_IP      = "eth_ip";  
  4. public static final String ETH_MASK    = "eth_mask";  
  5. public static final String ETH_DNS     = "eth_dns";  
  6. public static final String ETH_ROUTE   = "eth_route";  
  7. public static final String ETH_CONF    = "eth_conf";  
  8. public static final 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下增加如下内容

[java]  view plain  copy
 
 
  1.   
  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增加如下内容
[java]  view plain  copy
 
 
  1.   
  2. "eth_config_title">Configure Ethernet device  
  3. "eth_setting">Ethernet  
  4. "eth_dev_list">Ethernet Devices:  
  5. "eth_con_type">Connection Type  
  6. "eth_con_type_dhcp">DHCP  
  7. "eth_con_type_manual">Static IP  
  8. "eth_dns">DNS address  
  9. "eth_gw">Gateway address  
  10. "eth_ipaddr">IP address  
  11. "eth_quick_toggle_title">Ethernet  
  12. "eth_quick_toggle_summary">Turn on Ethernet  
  13. "eth_conf_perf_title">Ethernet configuration  
  14. "eth_conf_summary">Configure Ethernet devices  
  15. "eth_mask">Netmask  
  16. "eth_toggle_summary_off">Turn off Ethernet  
  17. "eth_toggle_summary_on">Turn on Ethernet  
  18. "eth_settings_error">Failed to set: Please enter the valid characters 0~255  
拷贝Settings/src/ethernet到Settings/src文件夹下

修改Settings/AndroidManifest.xml

       

                        android:taskAffinity="com.android.settings"
                android:label="@string/wireless_networks_settings_title"
                android:parentActivityName="Settings">
           
               
               
               
               
               
               
           

                            android:value="com.android.settings.WirelessSettings" />
                            android:resource="@id/wireless_settings" />
       

下增加如下代码


[java]  view plain  copy
 
 
  1.    
  2.   
  3. "Settings$EthernetSettingsActivity"  
  4.         android:label="@string/eth_setting">  
  5.       
  6.         "android.intent.action.MAIN" />  
  7.         "android.settings.ETHERNET_SETTINGS" />  
  8.         "android.intent.category.DEFAULT" />  
  9.         "android.intent.category.VOICE_LAUNCH" />  
  10.         "com.android.settings.SHORTCUT" />  
  11.       
  12.     "com.android.settings.FRAGMENT_CLASS"  
  13.         android:value="com.android.settings.ethernet.EthernetSettings" />  
  14.     "com.android.settings.TOP_LEVEL_HEADER_ID"  
  15.         android:resource="@id/ethernet_settings" />  
  16.   
修改Settings/src/Utils.java

    public static String getWifiIpAddresses(Context context) {
        ConnectivityManager cm = (ConnectivityManager)
                context.getSystemService(Context.CONNECTIVITY_SERVICE);
        LinkProperties prop = cm.getLinkProperties(ConnectivityManager.TYPE_WIFI);
        return formatIpAddresses(prop);
    }
下增加如下代码

[java]  view plain  copy
 
 
  1. public static String getEtherProperties(Context context) {  
  2.     ConnectivityManager cm = (ConnectivityManager)  
  3.             context.getSystemService(Context.CONNECTIVITY_SERVICE);  
  4.     LinkProperties prop = cm.getLinkProperties(ConnectivityManager.TYPE_ETHERNET);  
  5.     return prop.toString();  
  6. }  
修改Settings/src/Settings.java
加上
[java]  view plain  copy
 
 
  1. import com.android.settings.ethernet.EthernetSettings;  

            R.id.wifi_settings,
下加上
[java]  view plain  copy
 
 
  1. R.id.ethernet_settings,  

        WifiSettings.class.getName(),
下加上
[java]  view plain  copy
 
 
  1. EthernetSettings.class.getName(),  

SystemUI修改

拷贝systemui下所有.png文件到frameworks/base/packages/SystemUI/res/drawable下
修改frameworks/base/packages/SystemUI/res/values/strings.xml

    No SIM.
下增加如下

[java]  view plain  copy
 
 
  1.   
  2. "accessibility_ethernet_connected">Ethernet connected.  
  3. "accessibility_ethernet_disconnected">Ethernet disconnected.  
  4. "accessibility_ethernet_connecting">Ethernet connecting.  
修改frameworks/base/packages/SystemUI/res/layout/signal_cluster_view.xml

   
        android:layout_height="6dp"
        android:layout_width="6dp"
        android:visibility="gone"
        android:id="@+id/spacer"
        />
   

你可能感兴趣的:(android)