Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9393190
  • 博文数量: 1747
  • 博客积分: 12961
  • 博客等级: 上将
  • 技术积分: 20060
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-09 11:25
个人简介

偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.

文章分类

全部博文(1747)

文章存档

2024年(23)

2023年(26)

2022年(112)

2021年(217)

2020年(157)

2019年(192)

2018年(81)

2017年(78)

2016年(70)

2015年(52)

2014年(40)

2013年(51)

2012年(85)

2011年(45)

2010年(231)

2009年(287)

分类: Android平台

2014-06-18 11:13:44

http://gw-1984.blog.163.com/blog/static/9529128920129300313642/

一、移植framework部分(+号的行代表增加的内容,-号的行代表删除的内容) 

从4.0.4 master分支移植到4.0.4_r1

1.1.将源路径framework/base/ethernet 复制到目标路径的framework/base/目录下 
1.2.修改目标路径的framework/base目录下的Android.mk 
    vpn/java/android/net/vpn/IVpnService.aidl \ 
+    ethernet/java/android/net/ethernet/IEthernetManager.aidl \ 
    voip/java/android/net/sip/ISipSession.aidl \ 
1.3. 将源路径文件frameworks/base/services/java/com/android/server /EthernetService.java复制到目标路径frameworks/base/services/java/com/android /server/目录下
1.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 ((n.type != ConnectivityManager.TYPE_ETHERNET) && (mRadioAttributes[n.radio] == null)) {
                    loge("Error in networkAttributes - ignoring attempt to use undefined " +
                            "radio " + n.radio + " in network type " + n.type);
                    continue;
//-----------------------------------------------------------------------------------------


+case ConnectivityManager.TYPE_ETHERNET:

 

+               mNetTrackers[netType] = new EthernetStateTracker(netType, mNetConfigs[netType].name);

 +              mNetTrackers[netType].startMonitoring(context, mHandler);
 +            break;
1.5. 将源路径framework/base/core/jni/android_net_ethernet.cpp复制到目标路径framework/base/core/jni/目录下
1.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), 
1.7. 修改目标路径framework/base/core/jni/Android.mk文件,添加ethernetJNI接口文件的编译项 
android_net_wifi_Wifi.cpp \ 
+android_net_ethernet.cpp \ 
android_nio_utils.cpp \ 
1.8. 修改目标路径framework/base/core/java/android/content/Context.java 
public static final String WIFI_SERVICE = "wifi"; 
+public static final String ETHERNET_SERVICE = "ethernet"; 
1.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";
1.10. 修改目标路径frameworks/base/core/java/android/app/ContextImpl.java 
iimport android.net.ethernet.IEthernetManager;
import android.net.ethernet.EthernetManager;
//-----------------------------------------------------------------------------------------
registerService(ETHERNET_SERVICE, new ServiceFetcher() {
                public Object createService(ContextImpl ctx) {
                    IBinder b = ServiceManager.getService(ETHERNET_SERVICE);
                    IEthernetManager service = IEthernetManager.Stub.asInterface(b);
                    return new EthernetManager(service, ctx.mMainThread.getHandler());
                }});
1.11. 修改目标路径frameworks/base/core/res/res/values/config.xml 
wifi 
+ethernet 
cdma_eri 
//-----------------------------------------------------------------------------------------
"mobile_hipri,5,0,3" 
+"ethernet,9,9,1" 

 

1.12.frameworks/base/services/java/com/android/server/SystemServer.java 

import android.net.ethernet.EthernetManager;
import android.net.ethernet.EthernetStateTracker;

EthernetService ethernet = null;

 try {
                Slog.i(TAG, "Ethernet Service");
                ethernet = new EthernetService(context);
                ServiceManager.addService(Context.ETHERNET_SERVICE, ethernet);
            } catch (Throwable e) {
                reportWtf("starting Ethernt Service", e);
            }
            try {
                Slog.i(TAG, "Connectivity Service");
                connectivity = new ConnectivityService(
                        context, networkManagement, networkStats, networkPolicy);
                ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
                networkStats.bindConnectivityManager(connectivity);
                networkPolicy.bindConnectivityManager(connectivity);
                wifi.checkAndStartWifi();
                wifiP2p.connectivityServiceReady();
                ethernet.checkAndStartEthernet();
            } catch (Throwable e) {
                reportWtf("starting Connectivity Service", e);

            }

1.13. 修改目标路径文件frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkController.java

import android.net.wifi.WifiManager; 
+import android.net.ethernet.EthernetManager; 
+import android.net.ethernet.EthernetStateTracker; 
import android.os.Binder; 
//-----------------------------------------------------------------------------------------
String mContentDescriptionEthernet;
 // Ethernet
    boolean mEthernetEnabled, mEthernetConnected;
    int mEthernetIconId = 0; // overlay arrows for wifi direction
    int mEthernetActivity = EthernetManager.DATA_ACTIVITY_NONE;
    private static final int[] sEthImages = {
            R.drawable.connect_established,
            R.drawable.connect_no,
            R.drawable.connect_creating

        };

filter.addAction(EthernetManager.ETHERNET_STATE_CHANGED_ACTION);


 public void onReceive(Context context, Intent intent) {
        final String action = intent.getAction();
        if (action.equals(WifiManager.RSSI_CHANGED_ACTION)
                || action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)
                || action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
            updateWifiState(intent);
            refreshViews();
        } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
            updateSimState(intent);
            updateDataIcon();
            refreshViews();
        } else if (action.equals(Telephony.Intents.SPN_STRINGS_UPDATED_ACTION)) {
            updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
                        intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
                        intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
                        intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
            refreshViews();
        } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION) ||
                 action.equals(ConnectivityManager.INET_CONDITION_ACTION)) {
            updateConnectivity(intent);
            refreshViews();
        } else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
            refreshViews();
        } else if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
            updateAirplaneMode();
            refreshViews();
        } else if (action.equals(WimaxManagerConstants.NET_4G_STATE_CHANGED_ACTION) ||
                action.equals(WimaxManagerConstants.SIGNAL_LEVEL_CHANGED_ACTION) ||
                action.equals(WimaxManagerConstants.WIMAX_NETWORK_STATE_CHANGED_ACTION)) {
            updateWimaxState(intent);
            refreshViews();
        } else if (action.equals(EthernetManager.ETHERNET_STATE_CHANGED_ACTION)) {
            updateEth(intent);
            refreshViews();
        }
    }



private void updateEthernetIcons() {
        if (mEthernetConnected) {
            mEthernetIconId = sEthImages[0];
        } else {
            mEthernetIconId = sEthImages[1];
            }
    }


if (mEthernetConnected) {
            switch (mEthernetActivity) {
                case EthernetStateTracker.EVENT_HW_CONNECTED:
                case EthernetStateTracker.EVENT_INTERFACE_CONFIGURATION_SUCCEEDED:
                    mEthernetIconId = sEthImages[0];
                    break;
                case EthernetStateTracker.EVENT_HW_DISCONNECTED:
                case EthernetStateTracker.EVENT_INTERFACE_CONFIGURATION_FAILED:
                    mEthernetIconId = sEthImages[1];
                    return;
                    default:
                mEthernetIconId = sEthImages[2];
            }
        }


private final void updateEth(Intent intent) {
        final int event = intent.getIntExtra(EthernetManager.EXTRA_ETHERNET_STATE, EthernetManager.ETHERNET_STATE_UNKNOWN);
        switch (event) {
            case EthernetStateTracker.EVENT_HW_CONNECTED:
            case EthernetStateTracker.EVENT_INTERFACE_CONFIGURATION_SUCCEEDED:
                mEthernetIconId = sEthImages[0];
                break;
            case EthernetStateTracker.EVENT_HW_DISCONNECTED:
            case EthernetStateTracker.EVENT_INTERFACE_CONFIGURATION_FAILED:
                mEthernetIconId = sEthImages[1];
                return;
            default:
                mEthernetIconId = sEthImages[2];
        }
    }


1.14. 修改目标路径文件frameworks/base/core/jni/android_net_NetUtils.cpp

int ifc_configure(const char *ifname, in_addr_t ipaddr, uint32_t prefixLength, in_addr_t gateway, in_addr_t dns1, in_addr_t dns2);

{ "configureNative", "(Ljava/lang/String;IIIII)Z",  (void *)android_net_utils_configureInterface },

static jboolean android_net_utils_configureInterface(JNIEnv* env,
        jobject clazz,
        jstring ifname,
        jint ipaddr,
        jint prefixLength,
        jint gateway,
        jint dns1,
        jint dns2)
{
    int result;
    uint32_t lease;
    const char *nameStr = env->GetStringUTFChars(ifname, NULL);
    result = ::ifc_configure(nameStr, ipaddr, prefixLength, gateway, dns1, dns2);
    env->ReleaseStringUTFChars(ifname, nameStr);
    return (jboolean)(result == 0);
}


1.15. 修改目标路径文件frameworks/base/core/java/android/net/NetworkUtils.java

public static boolean configureInterface(String interfaceName, DhcpInfo ipInfo) {
        return configureNative(interfaceName,
            ipInfo.ipAddress,
            netmaskIntToPrefixLength(ipInfo.netmask),
            ipInfo.gateway,
            ipInfo.dns1,
            ipInfo.dns2);
    }
    private native static boolean configureNative(
        String interfaceName, int ipAddress, int prefixLength, int gateway, int dns1, int dns2);



二、移植packages部分 
2.1.复制源路径packages/apps/Settings/src/com/android/settings/ethernet目录到目标路径packages/apps/Settings/src/com/android/settings/目录下;
2.3.复制源路径packages/apps/Settings/res/drawable-hdpi/ic_settings_ethernet.png到目标路径packages/apps/Settings/res/drawable-hdpi/目录下
2.4.复制源路径packages/apps/Settings/res/drawable-mdpi/ic_settings_ethernet.png到目标路径packages/apps/Settings/res/drawable-mdpi/目录下
2.5.复制源路径packages/apps/Settings/res/layout/eth_configure.xml到目标路径packages/apps/Settings/res/layout/目录下
2.6.复制源路径packages/apps/Settings/res/xml/ethernet_settings.xml到目标路径packages/apps/Settings/res/xml/目录下
2.7. 修改目标路径文件packages/apps/Settings/res/values/strings.xml 
Feedback 
+   
+Configure Ethernet device   
+Ethernet setting   
+Ethernet Devices:   
+Connection Type   
+DHCP   
+Static IP   
+DNS address   
+Default Gateway   
+IP address   
+Ethernet   
+Turn on Ethernet   
+Ethernet configuration   
+Ethernet configuration   
+Configure Ethernet devices   
+Netmask   
+Turn off Ethernet   
+Turn on Ethernet   
2.8. 修改目标路径文件packages/apps/Settings/res/xml/settings_headers.xml 

           android:id="@+id/ethernet_settings"
        android:title="@string/eth_radio_ctrl_title"
        android:icon="@drawable/ic_settings_ethernet"
        android:fragment="com.android.settings.ethernet.EthernetSettings"/>
2.9. 修改目标路径文件packages/apps/Settings/AndroidManifest.xml 
 
                        android:label="@string/eth_radio_ctrl_title">
           
               
               
               
               
           

       

                android:label="@string/eth_setting"
                android:clearTaskOnLaunch="true">
           
               
               
               
               
               
           

       

                android:label="@string/eth_conf_perf_title"
                android:clearTaskOnLaunch="true">
           
               
               
               
               
               
           

       

三、接下来要增加Ethernet的状态栏图标 
3.1.复制源路径frameworks/base/packages/SystemUI/res/drawable-hdpi/connect_creating.png到目标路径对应目录下
3.2.复制源路径frameworks/base/packages/SystemUI/res/drawable-hdpi/connect_established.png到目标路径对应目录下
3.3.复制源路径frameworks/base/packages/SystemUI/res/drawable-hdpi/connect_no.png到目标路径对应目录下
3.4.复制源路径frameworks/base/packages/SystemUI/res/drawable-mdpi/connect_creating.png到目标路径对应目录下
3.5.复制源路径frameworks/base/packages/SystemUI/res/drawable-mdpi/connect_established.png到目标路径对应目录下
3.6.复制源路径frameworks/base/packages/SystemUI/res/drawable-mdpi/connect_no.png到目标路径对应目录下

四、修改目标路径文件build/core/pathmap.mk

vpn \ 
+ethernet \ 
keystore \ 
最后记得修改init.rc,在最后增加DHCP服务 
service dhcpcd_eth0 /system/bin/dhcpcd -ABKL
          disabled
          oneshot
service iprenew_eth0 /system/bin/dhcpcd -n
          disabled
          oneshot
阅读(3572) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~