转自:
http://blog.csdn.net/sustzombie/article/details/6764131
下载android-x86的Framework 和package 两个文件夹;
我们要移植的是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文件:
- --- /home/thomas/android2.2/frameworks/base/services/java/com/android/server/ConnectivityService.java 2011-07-04 15:37:30.949468920 +0800
- +++ ./frameworks/base/services/java/com/android/server/ConnectivityService.java 2011-09-08 11:02:01.927843001 +0800
- @@ -28,6 +28,7 @@
- import android.net.NetworkInfo;
- import android.net.NetworkStateTracker;
- import android.net.wifi.WifiStateTracker;
- +import android.net.ethernet.EthernetStateTracker;
- import android.os.Binder;
- import android.os.Handler;
- import android.os.IBinder;
- @@ -235,7 +236,7 @@
- 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;
- @@ -243,6 +244,7 @@
- mNetAttributes[n.mType] = n;
- mNetworksDefined++;
- } catch(Exception e) {
- + Slog.e(TAG, "wrong dev exception " + e);
- // ignore it - leave the entry null
- }
- }
- @@ -299,8 +301,14 @@
- 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();
- case ConnectivityManager.TYPE_MOBILE:
- mNetTrackers[netType] = new MobileDataStateTracker(context, mHandler,
- netType, mNetAttributes[netType].mName);
- @@ -310,9 +318,23 @@
- mNetTrackers[netType].teardown();
- }
- break;
- +
- default:
- - Slog.e(TAG, "Trying to create a DataStateTracker for an unknown radio type " +
- - mNetAttributes[netType].mRadio);
- + /*
- + * The ethernet is not a radio device, but we will still need to init
- + * it. check if this is the etherent device or not.
- +
- + if (netType == 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();
- + } else {
- + Slog.e(TAG, "Trying to create a DataStateTracker for an unknown radio type " +
- + mNetAttributes[netType].mRadio);
- + }*/
- continue;
- }
- }
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接口文件:
- --- /home/thomas/android2.2/frameworks/base/core/jni/AndroidRuntime.cpp 2011-07-04 15:37:30.109468920 +0800
- +++ ./frameworks/base/core/jni/AndroidRuntime.cpp 2011-09-08 15:35:47.047843001 +0800
- @@ -141,6 +141,7 @@
- extern int register_android_net_NetworkUtils(JNIEnv* env);
- extern int register_android_net_TrafficStats(JNIEnv* env);
- extern int register_android_net_wifi_WifiManager(JNIEnv* env);
- +extern int register_android_net_ethernet_EthernetManager(JNIEnv* env); //Added by TCL Thomas Yang Sep.08 2011
- extern int register_android_security_Md5MessageDigest(JNIEnv *env);
- extern int register_android_text_AndroidCharacter(JNIEnv *env);
- extern int register_android_text_AndroidBidi(JNIEnv *env);
- @@ -1259,6 +1260,7 @@
- REG_JNI(register_android_net_NetworkUtils),
- REG_JNI(register_android_net_TrafficStats),
- REG_JNI(register_android_net_wifi_WifiManager),
- + REG_JNI(register_android_net_ethernet_EthernetManager),//Added by TCL Thomas Yang Sep.08 2011
- REG_JNI(register_android_os_MemoryFile),
- REG_JNI(register_com_android_internal_os_ZygoteInit),
- REG_JNI(register_android_hardware_Camera),
7. 修改framework/base/core/jni/Android.mk文件,添加ethernetJNI接口文件的编译项:
- --- /home/thomas/android2.2/frameworks/base/core/jni/Android.mk 2011-07-04 15:37:30.109468920 +0800
- +++ ./frameworks/base/core/jni/Android.mk 2011-09-08 15:42:58.551843002 +0800
- @@ -60,6 +60,7 @@
- android_net_NetUtils.cpp \
- android_net_TrafficStats.cpp \
- android_net_wifi_Wifi.cpp \
- + android_net_ethernet.cpp \
- android_nio_utils.cpp \
- android_pim_EventRecurrence.cpp \
- android_text_format_Time.cpp \
8. 修改framework/base/core/java/android/net/ConnectivityManager.java文件:
- --- /home/thomas/android2.2/frameworks/base/core/java/android/net/ConnectivityManager.java 2011-07-04 15:37:30.017468920 +0800
- +++ ./frameworks/base/core/java/android/net/ConnectivityManager.java 2011-09-07 11:29:30.185267002 +0800
- @@ -190,10 +190,19 @@
- * default connections.
- */
- public static final int TYPE_WIMAX = 6;
- +
- +/**
- + * The Default Ethernet data connection. When active, all data traffic
- + * will use this connection by default. Should not coexist with other
- + * default connections.
- + */
- + public static final int TYPE_ETHERNET = 7; //Changed by TCL Thomas Yang Sep.07 2011
- +
- +
- /** {@hide} TODO: Need to adjust this for WiMAX. */
- public static final int MAX_RADIO_TYPE = TYPE_WIFI;
- /** {@hide} TODO: Need to adjust this for WiMAX. */
- - public static final int MAX_NETWORK_TYPE = TYPE_MOBILE_HIPRI;
- + public static final int MAX_NETWORK_TYPE = TYPE_ETHERNET; //Changed by TCL Thomas Yang Sep.07 2011
- public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI;
9. 修改framework/base/java/android/content/Context.java:
- <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
- +++ ./frameworks/base/core/java/android/content/Context.java 2011-09-07 11:40:50.745267001 +0800
- @@ -1450,6 +1450,16 @@
- * @see android.net.wifi.WifiManager
- */
- public static final String WIFI_SERVICE = "wifi";
- +
- + /**
- + * Use with {@link #getSystemService} to retrieve a {@link
- + * android.net.ethernet.EthernetManager} for handling management of
- + * ethernet access.
- + *
- + * @see #getSystemService
- + * @see android.net.ethernet.EthernetManager
- + */
- public static final String ETHERNET_SERVICE = "ethernet"; //Added by TCL Thomas Yang Sep.07 2011
- /**
- Use with {@link #getSystemService} to retrieve a</font></font></font>
10. 修改文件frameworks/base/core/java/android/provider/Settings.java
- <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
- +++ ./frameworks/base/core/java/android/provider/Settings.java 2011-09-07 14:15:12.273267001 +0800
- @@ -2628,6 +2628,20 @@
- public static final String WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS =
- "wifi_mobile_data_transition_wakelock_timeout_ms";
- + /**
- + * Added by TCL Thomas Yang Sep.07 2011
- + * For Ethernet
- + */
- + public static final String ETHERNET_ON = "eth_on";
- + public static final String ETHERNET_MODE = "eth_mode";
- + public static final String ETHERNET_IFNAME = "eth_ifname";
- + public static final String ETHERNET_IP = "eth_ip";
- + public static final String ETHERNET_DNS = "eth_dns";
- + public static final String ETHERNET_MASK ="eth_mask";
- + public static final String ETHERNET_ROUTE = "eth_route";
- + public static final String ETHERNET_CONF = "eth_conf";
- +
- +
- /**
- * Whether background data usage is allowed by the user. See
- * ConnectivityManager for more info.</font></font></font>
11. 修改文件:frameworks/base/core/java/android/app/ContextImpl.java
- <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
- +++ ./frameworks/base/core/java/android/app/ContextImpl.java 2011-09-08 13:33:12.531843001 +0800
- @@ -72,6 +72,8 @@
- import android.net.Uri;
- import android.net.wifi.IWifiManager;
- import android.net.wifi.WifiManager;
- +import android.net.ethernet.IEthernetManager;
- +import android.net.ethernet.EthernetManager;
- import android.os.Binder;
- import android.os.Bundle;
- import android.os.DropBoxManager;
- @@ -168,6 +170,7 @@
- private static ConnectivityManager sConnectivityManager;
- private static ThrottleManager sThrottleManager;
- private static WifiManager sWifiManager;
- + private static EthernetManager sEthernetManager;
- private static LocationManager sLocationManager;
- private static final HashMap<File, SharedPreferencesImpl> sSharedPrefs =
- new HashMap<File, SharedPreferencesImpl>();
- @@ -936,6 +939,8 @@
- return getThrottleManager();
- } else if (WIFI_SERVICE.equals(name)) {
- return getWifiManager();
- + } else if (ETHERNET_SERVICE.equals(name)) {
- + return getEthernetManager();
- } else if (NOTIFICATION_SERVICE.equals(name)) {
- return getNotificationManager();
- } else if (KEYGUARD_SERVICE.equals(name)) {
- @@ -1057,6 +1062,18 @@
- return sWifiManager;
- }
- + private EthernetManager getEthernetManager()
- + {
- + synchronized (sSync) {
- + if (sEthernetManager == null) {
- + IBinder b = ServiceManager.getService(ETHERNET_SERVICE);
- + IEthernetManager service = IEthernetManager.Stub.asInterface(b);
- + sEthernetManager = new EthernetManager(service, mMainThread.getHandler());
- + }
- + }
- + return sEthernetManager;
- + }
- +
- private NotificationManager getNotificationManager() {
- synchronized (mSync) {
- if (mNotificationManager == null) {</font></font></font>
12. 修改文件:frameworks/base/core/res/res/values/arrays.xml:
- <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
- +++ ./frameworks/base/core/res/res/values/arrays.xml 2011-09-08 13:23:28.271843001 +0800
- @@ -133,6 +133,7 @@
- <item><xliff:g id="id">mute</xliff:g></item>
- <item><xliff:g id="id">speakerphone</xliff:g></item>
- <item><xliff:g id="id">wifi</xliff:g></item>
- + <item><xliff:g id="id">ethernet</xliff:g></item>
- <item><xliff:g id="id">tty</xliff:g></item>
- <item><xliff:g id="id">bluetooth</xliff:g></item>
- <item><xliff:g id="id">gps</xliff:g></item></font></font></font>
13. 修改文件:frameworks/base/core/res/res/values/config.xml:
- <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
- +++ ./frameworks/base/core/res/res/values/config.xml 2011-09-08 13:25:17.127843001 +0800
- @@ -58,6 +58,7 @@
- <item>"mobile_mms,2,0,2"</item>
- <item>"mobile_supl,3,0,2"</item>
- <item>"mobile_hipri,5,0,3"</item>
- + <item>"ethernet,7,7,1"</item>
- </string-array>
- <!-- This string array should be overridden by the device to present a list of radio</font></font></font>
下文待续------
- <span style="font-size:18px;"> </span>