Android 2.2下实现Ethernet

Android源码本身是不支持Ethernet上网,主要因为它针对手机设计,而手机上一般不会带有RJ45模块,因此要想在Android上实现Ethernet功能就要增加Framework层和App层代码,工作量还是很大。还好网络上有基于上网本开发的开源项目android-x86,它已经实现了Ethernet功能,我们只要参考它的源码修改。下面将介绍下如何实现Ethernet功能:
 
1.linux驱动的修改
我所使用的RJ45芯片是MCS7830,linux kernel源码中已包含了它的驱动,只要在配置时选中它
make memuconfig:
[*] Network device support  --->
        USB Network Adapters  --->
            <*> Multi-purpose USB Networking Framework
                 <*>   MosChip MCS7830 based Ethernet adapters
 
2.Android源码的修改
下面只列出Android2.2需要修改的源码文件,包括所在的文件夹位置
  1. frameworks/base/Android.mk
  2. frameworks/base/core/java/android/app/ContextImpl.java
  3. frameworks/base/core/java/android/content/Context.java
  4. frameworks/base/core/java/android/net/ConnectivityManager.java
  5. frameworks/base/core/java/android/provider/Settings.java
  6. frameworks/base/core/jni/Android.mk
  7. frameworks/base/core/jni/AndroidRuntime.cpp
  8. frameworks/base/core/jni/android_net_ethernet.cpp (增加)
  9. frameworks/base/core/res/res/drawable/connect_creating.png (增加)
  10. frameworks/base/core/res/res/drawable/connect_established.png (增加)
  11. frameworks/base/core/res/res/drawable/connect_no.png (增加)
  12. frameworks/base/core/res/res/values/arrays.xml
  13. frameworks/base/core/res/res/values/config.xml
  14. frameworks/base/ethernet/java/android/net/ethernet/EthernetDevInfo.aidl (增加)
  15. frameworks/base/ethernet/java/android/net/ethernet/EthernetDevInfo.java (增加)
  16. frameworks/base/ethernet/java/android/net/ethernet/EthernetManager.java (增加)
  17. frameworks/base/ethernet/java/android/net/ethernet/EthernetMonitor.java (增加)
  18. frameworks/base/ethernet/java/android/net/ethernet/EthernetNative.java (增加)
  19. frameworks/base/ethernet/java/android/net/ethernet/EthernetStateTracker.java (增加)
  20. frameworks/base/ethernet/java/android/net/ethernet/IEthernetManager.aidl (增加)
  21. frameworks/base/services/java/com/android/server/status/StatusBarPolicy.java
  22. frameworks/base/services/java/com/android/server/ConnectivityService.java
  23. frameworks/base/services/java/com/android/server/EthernetService.java (增加)
  24. frameworks/base/wifi/java/android/net/wifi/WifiStateTracker.java
  25. packages/apps/Settings/res/drawable-hdpi/ic_settings_ethernet.png (增加)
  26. packages/apps/Settings/res/drawable-mdpi/ic_settings_ethernet.png (增加)
  27. packages/apps/Settings/res/layout/eth_configure.xml (增加)
  28. packages/apps/Settings/res/values/strings.xml
  29. packages/apps/Settings/res/xml/ethernet_settings.xml (增加)
  30. packages/apps/Settings/res/xml/settings.xml
  31. packages/apps/Settings/src/com/android/settings/ethernet/EthernetConfigDialog.java (增加)
  32. packages/apps/Settings/src/com/android/settings/ethernet/EthernetEnabler.java (增加)
  33. packages/apps/Settings/src/com/android/settings/ethernet/EthernetLayer.java (增加)
  34. packages/apps/Settings/src/com/android/settings/EthernetSettings.java (增加)
  35. packages/apps/Settings/AndroidManifest.xml
  36. build/core/pathmap.mk

3.init.rc的修改

增加以下代码:

+ mkdir /data/misc/dhcp 0777 dhcp dhcp
+ chown dhcp dhcp /data/misc/dhcp

+service dhcpcd /system/bin/dhcpcd -o domain_name_servers -ABKL
+      disabled
+      oneshot

以上全完成后,在Setting中就可以看到Ethernet Setting的选项,RJ45接上网线就可以上网了。

(android-x86下需要修改的文件源码包,基于Android 2.2版本)下载地址在安科网的1号FTP服务器里,下载地址:

密码:www.muu.cc

下载方法见这里 http://www.linuxidc.net/thread-1187-1-1.html

相关推荐