Android2.2添加Ethernet 框架支持(一)

时间:2021-01-12 09:25:28

  转自:

http://blog.csdn.net/sustzombie/article/details/6764131

下载android-x86的Framework 和package 两个文件夹;

网址:http://www.android-x86.org/getsourcecode

我们要移植的是android-2.2的版本,所以我们必须得到android-x86在2.2版本上的源码。

        mkdir android-x86

        cd android-x86

        repo init -u git://git.android-x86.org/manifest.git -b froyo-x86

前面初始化了android-x86,接下来你可以repo sync,只需要check out我们需要的几个文件夹,如下:

        repo sync platform/build

        repo sync platform/frameworks/base

        repo sync platform/packages/apps/Settings

下面我们将ethernet部分内容移植到自己的android源码中:

1.       将framework/base/ethernet 复制到源码的framework/base/目录下:

2.       修改源码framework/base目录下的Android.mk

LOCAL_SRC_FILES += \

         … \

         vpn/java/android/net/vpn/IVpnService.aidl \

185+:ethernet/java/android/net/ethernet/IEthernetManager.aidl

3.       将文件framework/base/service/java/com/android/server/EthernetService.java复制到 framework/base/service/java/com/android/server/目录下;

4.      修改framework/base/service/java/com/android/server目录下的ConnectivityService.java文件:


 

view plaincopy to clipboardprint?
  1. --- /home/thomas/android2.2/frameworks/base/services/java/com/android/server/ConnectivityService.java   2011-07-04 15:37:30.949468920 +0800  
  2. +++ ./frameworks/base/services/java/com/android/server/ConnectivityService.java 2011-09-08 11:02:01.927843001 +0800  
  3. @@ -28,6 +28,7 @@  
  4.  import android.net.NetworkInfo;  
  5.  import android.net.NetworkStateTracker;  
  6.  import android.net.wifi.WifiStateTracker;  
  7. +import android.net.ethernet.EthernetStateTracker;  
  8.  import android.os.Binder;  
  9.  import android.os.Handler;  
  10.  import android.os.IBinder;  
  11. @@ -235,7 +236,7 @@  
  12.                              n.mType);  
  13.                      continue;  
  14.                  }  
  15. -                if (mRadioAttributes[n.mRadio] == null) {  
  16. +                if ((n.mType != ConnectivityManager.TYPE_ETHERNET) && (mRadioAttributes[n.mRadio] == null)) {  
  17.                      Slog.e(TAG, "Error in networkAttributes - ignoring attempt to use undefined " +  
  18.                              "radio " + n.mRadio + " in network type " + n.mType);  
  19.                     continue;  
  20. @@ -243,6 +244,7 @@  
  21.                  mNetAttributes[n.mType] = n;  
  22.                  mNetworksDefined++;  
  23.              } catch(Exception e) {  
  24. +                Slog.e(TAG, "wrong dev exception " + e);  
  25.                  // ignore it - leave the entry null  
  26.              }  
  27.          }  
  28. @@ -299,8 +301,14 @@  
  29.                  wifiService.startWifi();  
  30.                  mNetTrackers[ConnectivityManager.TYPE_WIFI] = wst;  
  31.                  wst.startMonitoring();  
  32. -  
  33.                  break;  
  34. +           case ConnectivityManager.TYPE_ETHERNET:  
  35. +               if (DBG) Slog.v(TAG, "#########Starting Ethernet Service.");  
  36. +                EthernetStateTracker est = new EthernetStateTracker(context, mHandler);  
  37. +                EthernetService ethService = new EthernetService(context, est);  
  38. +                ServiceManager.addService(Context.ETHERNET_SERVICE, ethService);  
  39. +                mNetTrackers[ConnectivityManager.TYPE_ETHERNET] = est;  
  40. +                est.startMonitoring();  
  41.              case ConnectivityManager.TYPE_MOBILE:  
  42.                  mNetTrackers[netType] = new MobileDataStateTracker(context, mHandler,  
  43.                      netType, mNetAttributes[netType].mName);  
  44. @@ -310,9 +318,23 @@  
  45.                      mNetTrackers[netType].teardown();  
  46.                  }  
  47.                  break;  
  48. +                 
  49.              default:  
  50. -                Slog.e(TAG, "Trying to create a DataStateTracker for an unknown radio type " +  
  51. -                        mNetAttributes[netType].mRadio);  
  52. +                /* 
  53. +                 * The ethernet is not a radio device, but we will still need to init 
  54. +                 * it. check if this is the etherent device or not. 
  55. +                  
  56. +                if (netType == ConnectivityManager.TYPE_ETHERNET) { 
  57. +                    if (DBG) Slog.v(TAG, "Starting Ethernet Service."); 
  58. +                    EthernetStateTracker est = new EthernetStateTracker(context, mHandler); 
  59. +                    EthernetService ethService = new EthernetService(context, est); 
  60. +                    ServiceManager.addService(Context.ETHERNET_SERVICE, ethService); 
  61. +                    mNetTrackers[ConnectivityManager.TYPE_ETHERNET] = est; 
  62. +                    est.startMonitoring(); 
  63. +                } else { 
  64. +                    Slog.e(TAG, "Trying to create a DataStateTracker for an unknown radio type " + 
  65. +                    mNetAttributes[netType].mRadio); 
  66. +                }*/  
  67.                  continue;  
  68.              }  
  69.          }  

JNI接口文件添加:android_net_ethernet.cpp


5.    将framework/base/core/jni/android_net_ethernet.cpp复制到源码目录framework/base/core/jni/目录下;

6.    修改framework/base/core/jni/AndroidRuntime.cpp文件,注册JNI接口文件:

view plaincopy to clipboardprint?
  1. --- /home/thomas/android2.2/frameworks/base/core/jni/AndroidRuntime.cpp 2011-07-04 15:37:30.109468920 +0800  
  2. +++ ./frameworks/base/core/jni/AndroidRuntime.cpp   2011-09-08 15:35:47.047843001 +0800  
  3. @@ -141,6 +141,7 @@  
  4.  extern int register_android_net_NetworkUtils(JNIEnv* env);  
  5.  extern int register_android_net_TrafficStats(JNIEnv* env);  
  6.  extern int register_android_net_wifi_WifiManager(JNIEnv* env);  
  7. +extern int register_android_net_ethernet_EthernetManager(JNIEnv* env); //Added by TCL Thomas Yang Sep.08 2011  
  8.  extern int register_android_security_Md5MessageDigest(JNIEnv *env);  
  9.  extern int register_android_text_AndroidCharacter(JNIEnv *env);  
  10.  extern int register_android_text_AndroidBidi(JNIEnv *env);  
  11. @@ -1259,6 +1260,7 @@  
  12.      REG_JNI(register_android_net_NetworkUtils),  
  13.      REG_JNI(register_android_net_TrafficStats),  
  14.      REG_JNI(register_android_net_wifi_WifiManager),  
  15. +    REG_JNI(register_android_net_ethernet_EthernetManager),//Added by TCL Thomas Yang Sep.08 2011  
  16.      REG_JNI(register_android_os_MemoryFile),  
  17.      REG_JNI(register_com_android_internal_os_ZygoteInit),  
  18.      REG_JNI(register_android_hardware_Camera),  

7.      修改framework/base/core/jni/Android.mk文件,添加ethernetJNI接口文件的编译项:


view plaincopy to clipboardprint?
  1. --- /home/thomas/android2.2/frameworks/base/core/jni/Android.mk 2011-07-04 15:37:30.109468920 +0800  
  2. +++ ./frameworks/base/core/jni/Android.mk   2011-09-08 15:42:58.551843002 +0800  
  3. @@ -60,6 +60,7 @@  
  4.     android_net_NetUtils.cpp \  
  5.     android_net_TrafficStats.cpp \  
  6.     android_net_wifi_Wifi.cpp \  
  7. +   android_net_ethernet.cpp \  
  8.     android_nio_utils.cpp \  
  9.     android_pim_EventRecurrence.cpp \  
  10.     android_text_format_Time.cpp \  

8.      修改framework/base/core/java/android/net/ConnectivityManager.java文件:

view plaincopy to clipboardprint?
  1. --- /home/thomas/android2.2/frameworks/base/core/java/android/net/ConnectivityManager.java  2011-07-04 15:37:30.017468920 +0800  
  2. +++ ./frameworks/base/core/java/android/net/ConnectivityManager.java    2011-09-07 11:29:30.185267002 +0800  
  3. @@ -190,10 +190,19 @@  
  4.       * default connections.  
  5.       */  
  6.      public static final int TYPE_WIMAX       = 6;  
  7. +  
  8. +/** 
  9. +  * The Default Ethernet data connection.  When active, all data traffic 
  10. +  * will use this connection by default.  Should not coexist with other 
  11. +  * default connections. 
  12. +  */  
  13. +    public static final int TYPE_ETHERNET    = 7//Changed by TCL Thomas Yang Sep.07 2011  
  14. +  
  15. +  
  16.      /** {@hide} TODO: Need to adjust this for WiMAX. */  
  17.      public static final int MAX_RADIO_TYPE   = TYPE_WIFI;  
  18.      /** {@hide} TODO: Need to adjust this for WiMAX. */  
  19. -    public static final int MAX_NETWORK_TYPE = TYPE_MOBILE_HIPRI;  
  20. +    public static final int MAX_NETWORK_TYPE = TYPE_ETHERNET;   //Changed by TCL Thomas Yang Sep.07 2011  
  21.       public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI;  

9.     修改framework/base/java/android/content/Context.java:

view plaincopy to clipboardprint?
  1. <font xmlns="http://www.w3.org/1999/xhtml" size="4"><font xmlns="http://www.w3.org/1999/xhtml"><font xmlns="http://www.w3.org/1999/xhtml">--- /home/thomas/android2.2/frameworks/base/core/java/android/content/Context.java  2011-07-04 15:37:29.997468920 +0800  
  2. +++ ./frameworks/base/core/java/android/content/Context.java    2011-09-07 11:40:50.745267001 +0800  
  3. @@ -1450,6 +1450,16 @@  
  4.       * @see android.net.wifi.WifiManager  
  5.       */  
  6.      public static final String WIFI_SERVICE = "wifi";  
  7. +  
  8. +   /** 
  9. +     * Use with {@link #getSystemService} to retrieve a {@link 
  10. +     * android.net.ethernet.EthernetManager} for handling management of 
  11. +     * ethernet access. 
  12. +     * 
  13. +     * @see #getSystemService 
  14. +     * @see android.net.ethernet.EthernetManager 
  15. +     */  
  16.     public static final String ETHERNET_SERVICE = "ethernet";  //Added by TCL Thomas Yang Sep.07 2011  
  17.      /**  
  18. Use with {@link #getSystemService} to retrieve a</font></font></font>  

10.    修改文件frameworks/base/core/java/android/provider/Settings.java

view plaincopy to clipboardprint?
  1. <font xmlns="http://www.w3.org/1999/xhtml" size="4"><font xmlns="http://www.w3.org/1999/xhtml"><font xmlns="http://www.w3.org/1999/xhtml">--- /home/thomas/android2.2/frameworks/base/core/java/android/provider/Settings.java    2011-07-04 15:37:30.037468920 +0800  
  2. +++ ./frameworks/base/core/java/android/provider/Settings.java  2011-09-07 14:15:12.273267001 +0800  
  3. @@ -2628,6 +2628,20 @@  
  4.          public static final String WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS =  
  5.              "wifi_mobile_data_transition_wakelock_timeout_ms";  
  6.  +      /** 
  7. +       * Added by TCL Thomas Yang Sep.07 2011 
  8. +       * For Ethernet  
  9. +       */  
  10. +       public static final String ETHERNET_ON = "eth_on";  
  11. +       public static final String ETHERNET_MODE = "eth_mode";  
  12. +       public static final String ETHERNET_IFNAME = "eth_ifname";  
  13. +       public static final String ETHERNET_IP = "eth_ip";  
  14. +       public static final String ETHERNET_DNS = "eth_dns";  
  15. +       public static final String ETHERNET_MASK ="eth_mask";  
  16. +       public static final String ETHERNET_ROUTE = "eth_route";  
  17. +       public static final String ETHERNET_CONF = "eth_conf";  
  18. +         
  19. +  
  20.          /**  
  21.           * Whether background data usage is allowed by the user. See  
  22.           * ConnectivityManager for more info.</font></font></font>  

11.     修改文件:frameworks/base/core/java/android/app/ContextImpl.java

view plaincopy to clipboardprint?
  1. <font xmlns="http://www.w3.org/1999/xhtml" size="4"><font xmlns="http://www.w3.org/1999/xhtml"><font xmlns="http://www.w3.org/1999/xhtml">--- /home/thomas/android2.2/frameworks/base/core/java/android/app/ContextImpl.java  2011-07-04 15:37:29.973468920 +0800  
  2. +++ ./frameworks/base/core/java/android/app/ContextImpl.java    2011-09-08 13:33:12.531843001 +0800  
  3. @@ -72,6 +72,8 @@  
  4.  import android.net.Uri;  
  5.  import android.net.wifi.IWifiManager;  
  6.  import android.net.wifi.WifiManager;  
  7. +import android.net.ethernet.IEthernetManager;  
  8. +import android.net.ethernet.EthernetManager;  
  9.  import android.os.Binder;  
  10.  import android.os.Bundle;  
  11.  import android.os.DropBoxManager;  
  12. @@ -168,6 +170,7 @@  
  13.      private static ConnectivityManager sConnectivityManager;  
  14.      private static ThrottleManager sThrottleManager;  
  15.      private static WifiManager sWifiManager;  
  16. +    private static EthernetManager sEthernetManager;  
  17.      private static LocationManager sLocationManager;  
  18.      private static final HashMap<File, SharedPreferencesImpl> sSharedPrefs =  
  19.              new HashMap<File, SharedPreferencesImpl>();  
  20. @@ -936,6 +939,8 @@  
  21.              return getThrottleManager();  
  22.          } else if (WIFI_SERVICE.equals(name)) {  
  23.              return getWifiManager();  
  24. +        } else if (ETHERNET_SERVICE.equals(name)) {  
  25. +            return getEthernetManager();  
  26.          } else if (NOTIFICATION_SERVICE.equals(name)) {  
  27.              return getNotificationManager();  
  28.          } else if (KEYGUARD_SERVICE.equals(name)) {  
  29. @@ -1057,6 +1062,18 @@  
  30.          return sWifiManager;  
  31.      }  
  32. +    private EthernetManager getEthernetManager()  
  33. +    {  
  34. +        synchronized (sSync) {  
  35. +            if (sEthernetManager == null) {  
  36. +                IBinder b = ServiceManager.getService(ETHERNET_SERVICE);  
  37. +                IEthernetManager service = IEthernetManager.Stub.asInterface(b);  
  38. +                sEthernetManager = new EthernetManager(service, mMainThread.getHandler());  
  39. +            }  
  40. +        }  
  41. +        return sEthernetManager;  
  42. +    }  
  43. +  
  44.      private NotificationManager getNotificationManager() {  
  45.          synchronized (mSync) {  
  46.              if (mNotificationManager == null) {</font></font></font>  


12.     修改文件:frameworks/base/core/res/res/values/arrays.xml

view plaincopy to clipboardprint?
  1. <font xmlns="http://www.w3.org/1999/xhtml" size="4"><font xmlns="http://www.w3.org/1999/xhtml"><font xmlns="http://www.w3.org/1999/xhtml">--- /home/thomas/android2.2/frameworks/base/core/res/res/values/arrays.xml  2011-07-04 15:37:30.273468920 +0800  
  2. +++ ./frameworks/base/core/res/res/values/arrays.xml    2011-09-08 13:23:28.271843001 +0800  
  3. @@ -133,6 +133,7 @@  
  4.          <item><xliff:g id="id">mute</xliff:g></item>  
  5.          <item><xliff:g id="id">speakerphone</xliff:g></item>  
  6.          <item><xliff:g id="id">wifi</xliff:g></item>  
  7. +        <item><xliff:g id="id">ethernet</xliff:g></item>  
  8.          <item><xliff:g id="id">tty</xliff:g></item>  
  9.          <item><xliff:g id="id">bluetooth</xliff:g></item>  
  10.          <item><xliff:g id="id">gps</xliff:g></item></font></font></font>  


13.  修改文件:frameworks/base/core/res/res/values/config.xml

view plaincopy to clipboardprint?
  1. <font xmlns="http://www.w3.org/1999/xhtml" size="4"><font xmlns="http://www.w3.org/1999/xhtml"><font xmlns="http://www.w3.org/1999/xhtml">--- /home/thomas/android2.2/frameworks/base/core/res/res/values/config.xml  2011-07-04 15:37:30.277468920 +0800  
  2. +++ ./frameworks/base/core/res/res/values/config.xml    2011-09-08 13:25:17.127843001 +0800  
  3. @@ -58,6 +58,7 @@  
  4.          <item>"mobile_mms,2,0,2"</item>  
  5.          <item>"mobile_supl,3,0,2"</item>  
  6.          <item>"mobile_hipri,5,0,3"</item>  
  7. +        <item>"ethernet,7,7,1"</item>  
  8.      </string-array>  
  9.      <!-- This string array should be overridden by the device to present a list of radio</font></font></font>  

下文待续------


view plaincopy to clipboardprint?
  1. <span style="font-size:18px;"> </span>