增加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";
下加上如下内容
/**
* 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 ETH_SERVICE = "ethernet";//add by hclydao
修改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());
}}); //add by hclydao
修改frameworks/base/services/java/com/android/server/ConnectivityService.java
增加
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();
增加如下代码
return new EthernetStateTracker(targetNetworkType, config.name);//add by hclydao
拷贝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下增加如下内容
修改values/strings.xml增加如下内容
Configure Ethernet device
Ethernet
Ethernet Devices:
Connection Type
DHCP
Static IP
DNS address
Gateway address
IP address
Ethernet
Turn on Ethernet
Ethernet configuration
Configure Ethernet devices
Netmask
Turn off Ethernet
Turn on Ethernet
Failed to set: Please enter the valid characters 0~255
拷贝Settings/src/ethernet到Settings/src文件夹下
修改Settings/AndroidManifest.xml
在
android:label="@string/wireless_networks_settings_title"
android:parentActivityName="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,
下加上
R.id.ethernet_settings,
在
WifiSettings.class.getName(),
下加上
EthernetSettings.class.getName(),
SystemUI修改
拷贝systemui下所有.png文件到frameworks/base/packages/SystemUI/res/drawable下
修改frameworks/base/packages/SystemUI/res/values/strings.xml
在
下增加如下
Ethernet connected.
Ethernet disconnected.
Ethernet connecting.
修改frameworks/base/packages/SystemUI/res/layout/signal_cluster_view.xml
在
android:layout_width="6dp"
android:visibility="gone"
android:id="@+id/spacer"
/>