本文主要是介绍如何移植android-x86现成的Ethernet框架到android2.3 中, 实现系统对Ethernet的支持。
前面大部分内容摘自于网络, 后面是个人补充, 力求让整个Ethernet框架更完善.
一、下载android-x86代码,
repo init -u git://android-x86.git.sf.net/gitroot/android-x86/x86/platform/manifest.git -b gingerbread-x86
;gingerbread-x86代表2.3版本, 全部源码太大, 可以用下面的命令只下载和Ethernet相关的代码
repo sync platform/frameworks/base
repo sync platform/packages/apps/Settings
二、移植framework部分(+号的行代表增加的内容,-号的行代表删除的内容)
源路径:你下载的gingerbread-x86
目标路径: 你的项目路径
2.1.将源路径framework/base/ethernet 复制到目标路径的framework/base/目录下
2.2.修改目标路径的framework/base目录下的Android.mk
/java/android/net//IVpnService.aidl \
+ ethernet/java/android/net/ethernet/IEthernetManager.aidl \
voip/java/android/net/sip/ISipSession.aidl \
2.3. 将源路径文件frameworks/base/services/java/com/android/server/EthernetService.java复制到目标路径frameworks/base/services/java/com/android/server/目录下
2.4. 修改目标路径framework/base/service/java/com/android/server目录下的ConnectivityService.java文件
import android.net.wifi.WifiStateTracker;
+import android.net.ethernet.EthernetStateTracker;
import android.net.wimax.WimaxManagerConstants;
//-----------------------------------------------------------------------------------------
if (mNetAttributes[n.mType] != null) {
Slog.e(TAG, "Error in networkAttributes - ignoring attempt to redefine type " +
n.mType);
continue;
}
-if (mRadioAttributes[n.mRadio] == null) {
+if ((n.mType != ConnectivityManager.TYPE_ETHERNET) && (mRadioAttributes[n.mRadio] == null)) {
Slog.e(TAG, "Error in networkAttributes - ignoring attempt to use undefined " +
"radio " + n.mRadio + " in network type " + n.mType);
continue;
}
mNetAttributes[n.mType] = n;
mNetworksDefined++;
} catch(Exception e) {
+Slog.e(TAG, "wrong dev exception " + e);
// ignore it - leave the entry null
}
//-----------------------------------------------------------------------------------------
wifiService.startWifi();
mNetTrackers[ConnectivityManager.TYPE_WIFI] = wst;
wst.startMonitoring();
break;
+case ConnectivityManager.TYPE_ETHERNET:
+if (DBG) Slog.v(TAG, "#########Starting Ethernet Service.");
+EthernetStateTracker est = new EthernetStateTracker(context, mHandler);
+EthernetService ethService = new EthernetService(context, est);
+ServiceManager.addService(Context.ETHERNET_SERVICE, ethService);
+mNetTrackers[ConnectivityManager.TYPE_ETHERNET] = est;
+est.startMonitoring();
+break;//by bjw
case ConnectivityManager.TYPE_MOBILE:
//-----------------------------------------------------------------------------------------
if (noMobileData) {
if (DBG) Slog.d(TAG, "tearing down WiMAX networks due to setting");
mNetTrackers[netType].teardown();
}
break;
default:
// Slog.e(TAG, "Trying to create a DataStateTracker for an unknown radio type " +
// mNetAttributes[netType].mRadio);
2.5. 将源路径framework/base/core/jni/android_net_ethernet.cpp复制到目标路径framework/base/core/jni/目录下
2.6. 修改目标路径framework/base/core/jni/AndroidRuntime.cpp文件
extern int register_android_net_wifi_WifiManager(JNIEnv* env);
+extern int register_android_net_ethernet_EthernetManager(JNIEnv* env);
extern int register_android_security_Md5MessageDigest(JNIEnv *env);
//-----------------------------------------------------------------------------------------
REG_JNI(register_android_net_wifi_WifiManager),
+REG_JNI(register_android_net_ethernet_EthernetManager),
REG_JNI(register_android_nfc_NdefMessage),
2.7. 修改目标路径framework/base/core/jni/Android.mk文件,添加ethernetJNI接口文件的编译项
android_net_wifi_Wifi.cpp \
+android_net_ethernet.cpp \
android_nio_utils.cpp \
2.8. 修改目标路径framework/base/java/android/content/Context.java
public static final String WIFI_SERVICE = "wifi";
+public static final String ETHERNET_SERVICE = "ethernet";
2.9. 修改目标路径frameworks/base/core/java/android/provider/Settings.java
public static final String WIFI_ON = "wifi_on";
+ /**
+ * Ethernet related configurations
+ */
+ public static final String ETHERNET_ON = "ethernet_on";
+ public static final String ETHERNET_MODE = "ethernet_mode";
+ public static final String ETHERNET_IP = "ethernet_ip";
+ public static final String ETHERNET_MASK = "ethernet_netmask";
+ public static final String ETHERNET_DNS = "ethernet_dns";
+ public static final String ETHERNET_ROUTE = "ethernet_iproute";
+ public static final String ETHERNET_CONF = "ethernet_conf";
+ public static final String ETHERNET_IFNAME = "ethernet_ifname";
2.10. 修改目标路径frameworks/base/core/java/android/app/ContextImpl.java
import android.net.wifi.WifiManager;
+import android.net.ethernet.IEthernetManager;
+import android.net.ethernet.EthernetManager;
import android.nfc.NfcManager;
//-----------------------------------------------------------------------------------------
private static WifiManager sWifiManager;
+private static EthernetManager sEthernetManager;
private static LocationManager sLocationManager;
//-----------------------------------------------------------------------------------------
} else if (WIFI_SERVICE.equals(name)) {
return getWifiManager();
+ } else if (ETHERNET_SERVICE.equals(name)) {
+ return getEthernetManager(); //by bjw
} else if (NOTIFICATION_SERVICE.equals(name)) {
return getNotificationManager();
//-----------------------------------------------------------------------------------------
return sWifiManager;
}
+ private EthernetManager getEthernetManager()
+ {
+ synchronized (sSync) {
+ if (sEthernetManager == null) {
+ IBinder b = ServiceManager.getService(ETHERNET_SERVICE);
+ if (b == null) {
+ Log.w(TAG, "Error getting service name:" + ETHERNET_SERVICE);
+ }
+ IEthernetManager service = IEthernetManager.Stub.asInterface(b);
+ sEthernetManager = new EthernetManager(service, mMainThread.getHandler());
+ }
+ }
+ return sEthernetManager;
+ }
private NotificationManager getNotificationManager() {
2.11. 修改目标路径frameworks/base/core/res/res/values/config.xml
+
//-----------------------------------------------------------------------------------------
+
2.12. 修改目标路径frameworks/base/core/java/android/net/ConnectivityManager.java
public static final int TYPE_WIMAX = 6;
+public static final int TYPE_ETHERNET = 9;
+public static final int MAX_RADIO_TYPE = TYPE_ETHERNET;
public static final int MAX_NETWORK_TYPE = TYPE_ETHERNET;//modify TYPE_MOBILE_HIPRI to TYPE_ETHERNET
--120917