android新增乙太網ethernet方法 android框架新增
下載原始碼地址:http://download.csdn.net/download/wocao1226/10134749
增加ethernet主要是三部分:1、ethernet service; 2、ethernet Settings 3、Systemui ethernet通知
以下提到的原始檔將會在文章最後提供下載地址
拷貝frameworks/base/ethernet到frameworks/base下
修改frameworks/base/Android.mk
在
wifi/Java/android/net/wifi/p2p/IWifiP2pManager.aidl
\
下加上如下程式碼
- ethernet/java/android/net/ethernet/IEthernetManager.aidl \
FRAMEWORKS_BASE_SUBDIRS中加上ethernet
拷貝EthernetService.java到frameworks/base/services/java/com/android/server/下
修改frameworks/base/core/java/android/content/Context.java
在
public static final String WIFI_P2P_SERVICE = "wifip2p";
下加上如下內容
- /**
- * 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
- */
-
publicstaticfinal String ETH_SERVICE = "ethernet"
在
import android.net.wifi.p2p.IWifiP2pManager;
import android.net.wifi.p2p.WifiP2pManager;
下增加如下內容
- import android.net.ethernet.IEthernetManager;
- import android.net.ethernet.EthernetManager;
在
registerService(WIFI_P2P_SERVICE, new ServiceFetcher() {
public Object createService(ContextImpl ctx) {
IBinder b = ServiceManager.getService(WIFI_P2P_SERVICE);
IWifiP2pManager service = IWifiP2pManager.Stub.asInterface(b);
return new WifiP2pManager(service);
}});
下增加如下內容
- registerService(ETH_SERVICE, new ServiceFetcher() {
- public Object createService(ContextImpl ctx) {
- IBinder b = ServiceManager.getService(ETH_SERVICE);
- IEthernetManager service = IEthernetManager.Stub.asInterface(b);
- returnnew EthernetManager(service, ctx.mMainThread.getHandler());
- }}); //add by hclydao
增加
- import android.net.ethernet.EthernetManager;//add by hclydao
- import android.net.ethernet.EthernetStateTracker;
//import android.net.EthernetDataTracker;
在
try {
tracker = netFactory.createTracker(targetNetworkType, config);
mNetTrackers[targetNetworkType] = tracker;
} catch (IllegalArgumentException e) {
Slog.e(TAG, "Problem creating " + getNetworkTypeName(targetNetworkType)
+ " tracker: " + e);
continue;
}
下加上如下程式碼
if(mNetConfigs[targetNetworkType].radio == ConnectivityManager.TYPE_ETHERNET) { //add by hclydao
EthernetService ethernet = new EthernetService(context, (EthernetStateTracker)mNetTrackers[targetNetworkType]);
ServiceManager.addService(Context.ETH_SERVICE, ethernet);
mNetTrackers[targetNetworkType].startMonitoring(context, mTrackerHandler);
}
註釋掉
//return EthernetDataTracker.getInstance();
增加如下程式碼
- returnnew EthernetStateTracker(targetNetworkType, config.name);//add by hclydao
修改frameworks/base/core/jni下的Android.mk
在
android_net_wifi_WifiNative.cpp \
下加上如下程式碼
- android_net_ethernet.cpp \
修改frameworks/base/core/jni/AndroidRuntime.cpp
在
extern int register_android_net_wifi_WifiNative(JNIEnv* env);下
加上
extern int register_android_net_ethernet_EthernetManager(JNIEnv* env);//add by hclydao
在
REG_JNI(register_android_net_wifi_WifiNative),
下加上如下程式碼
- REG_JNI(register_android_net_ethernet_EthernetManager),
public static final String WIFI_ON = "wifi_on";
下加上如下程式碼
- publicstaticfinal String ETH_ON = "eth_on";
- publicstaticfinal String ETH_MODE = "eth_mode";
- publicstaticfinal String ETH_IP = "eth_ip";
- publicstaticfinal String ETH_MASK = "eth_mask";
- publicstaticfinal String ETH_DNS = "eth_dns";
- publicstaticfinal String ETH_ROUTE = "eth_route";
- publicstaticfinal String ETH_CONF = "eth_conf";
- publicstaticfinal String ETH_IFNAME = "eth_ifname";
Settings部分修改
拷貝eth_configure.xml到Settings/res/layout/
拷貝ic_setttings_ethernet.png到Settings/res/drawable-hdpi與drawable-mdpi
拷貝ethernet_settings.xml到Settings/res/xml下
修改xml下settings_headers.xml在wifi下增加如下內容
- <!-- Ethernet -->
- lt;header
- android:id="@+id/ethernet_settings"
- android:title="@string/eth_setting"
- android:icon="@drawable/ic_settings_ethernet"
- android:fragment="com.android.settings.ethernet.EthernetSettings"/>
- <!-- Ethernet configuration dialog -->
- <string name="eth_config_title">Configure Ethernet device</string>
- <string name="eth_setting">Ethernet</string>
- <string name="eth_dev_list">Ethernet Devices:</string>
- <string name="eth_con_type">Connection Type</string>
- <string name="eth_con_type_dhcp">DHCP</string>
- <string name="eth_con_type_manual">Static IP</string>
- <string name="eth_dns">DNS address</string>
- <string name="eth_gw">Gateway address</string>
- <string name="eth_ipaddr">IP address</string>
- <string name="eth_quick_toggle_title">Ethernet</string>
- <string name="eth_quick_toggle_summary">Turn on Ethernet</string>
- <string name="eth_conf_perf_title">Ethernet configuration</string>
- <string name="eth_conf_summary">Configure Ethernet devices</string>
- <string name="eth_mask">Netmask</string>
- <string name="eth_toggle_summary_off">Turn off Ethernet</string>
- <string name="eth_toggle_summary_on">Turn on Ethernet</string>
- <string name="eth_settings_error">Failed to set: Please enter the valid characters 0~255</string>