下载源码地址: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 \
修改build/core/pathmap.mk在
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";
下加上如下内容
-
-
-
-
-
-
-
-
- public static final String ETH_SERVICE = "ethernet";
修改frameworks/base/core/java/android/app/ContextImpl.java
在
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);
- return new EthernetManager(service, ctx.mMainThread.getHandler());
- }});
修改frameworks/base/services/java/com/android/server/ConnectivityService.java
增加
- import android.net.ethernet.EthernetManager;
- 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();
增加如下代码
- return new EthernetStateTracker(targetNetworkType, config.name);
拷贝android_net_ethernet.cpp到frameworks/base/core/jni目录下
修改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),
在framework/base/core/java/android/provider/Settings.java中
public static final String WIFI_ON = "wifi_on";
下加上如下代码
- public static final String ETH_ON = "eth_on";
- public static final String ETH_MODE = "eth_mode";
- public static final String ETH_IP = "eth_ip";
- public static final String ETH_MASK = "eth_mask";
- public static final String ETH_DNS = "eth_dns";
- public static final String ETH_ROUTE = "eth_route";
- public static final String ETH_CONF = "eth_conf";
- public static final 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下增加如下内容
-
- 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"/>
修改values/strings.xml增加如下内容
-
- "eth_config_title">Configure Ethernet device
- "eth_setting">Ethernet
- "eth_dev_list">Ethernet Devices:
- "eth_con_type">Connection Type
- "eth_con_type_dhcp">DHCP
- "eth_con_type_manual">Static IP
- "eth_dns">DNS address
- "eth_gw">Gateway address
- "eth_ipaddr">IP address
- "eth_quick_toggle_title">Ethernet
- "eth_quick_toggle_summary">Turn on Ethernet
- "eth_conf_perf_title">Ethernet configuration
- "eth_conf_summary">Configure Ethernet devices
- "eth_mask">Netmask
- "eth_toggle_summary_off">Turn off Ethernet
- "eth_toggle_summary_on">Turn on Ethernet
- "eth_settings_error">Failed to set: Please enter the valid characters 0~255
拷贝Settings/src/ethernet到Settings/src文件夹下
修改Settings/AndroidManifest.xml
在
android:taskAffinity="com.android.settings"
android:label="@string/wireless_networks_settings_title"
android:parentActivityName="Settings">
android:value="com.android.settings.WirelessSettings" />
android:resource="@id/wireless_settings" />
下增加如下代码
-
-
- "Settings$EthernetSettingsActivity"
- android:label="@string/eth_setting">
-
- "android.intent.action.MAIN" />
- "android.settings.ETHERNET_SETTINGS" />
- "android.intent.category.DEFAULT" />
- "android.intent.category.VOICE_LAUNCH" />
- "com.android.settings.SHORTCUT" />
-
- "com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.ethernet.EthernetSettings" />
- "com.android.settings.TOP_LEVEL_HEADER_ID"
- android:resource="@id/ethernet_settings" />
-
修改Settings/src/Utils.java
在
public static String getWifiIpAddresses(Context context) {
ConnectivityManager cm = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
LinkProperties prop = cm.getLinkProperties(ConnectivityManager.TYPE_WIFI);
return formatIpAddresses(prop);
}
下增加如下代码
- public static String getEtherProperties(Context context) {
- ConnectivityManager cm = (ConnectivityManager)
- context.getSystemService(Context.CONNECTIVITY_SERVICE);
- LinkProperties prop = cm.getLinkProperties(ConnectivityManager.TYPE_ETHERNET);
- return prop.toString();
- }
修改Settings/src/Settings.java
加上
- import com.android.settings.ethernet.EthernetSettings;
在
R.id.wifi_settings,
下加上
在
WifiSettings.class.getName(),
下加上
- EthernetSettings.class.getName(),
SystemUI修改
拷贝systemui下所有.png文件到frameworks/base/packages/SystemUI/res/drawable下
修改frameworks/base/packages/SystemUI/res/values/strings.xml
在
No SIM.
下增加如下
-
- "accessibility_ethernet_connected">Ethernet connected.
- "accessibility_ethernet_disconnected">Ethernet disconnected.
- "accessibility_ethernet_connecting">Ethernet connecting.
修改frameworks/base/packages/SystemUI/res/layout/signal_cluster_view.xml
在
android:layout_height="6dp"
android:layout_width="6dp"
android:visibility="gone"
android:id="@+id/spacer"
/>