网上移植ethernet框架的文章很多,这里就不多说了,主要说下如何修改默认状态。如下就简单的说下,我也还没有研究的很清楚。
首先服务的建在:
frameworks/base/services/java/com/Android/server/ConnectivityService.java
有如下代码:
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();
这个应该是最开始执行的时候运行的。也就是说服务建后执行了这个est.startMonitoring();
这个函数在:
frameworks/base/ethernet/java/android/net/ethernet/EthernetStateTracker.java
代码如下:
@Override
public void startMonitoring() {
if (localLOGV) Slog.v(TAG,"start to monitor the ethernet devices");
if (mServiceStarted) {
mEM = (EthernetManager)mContext.getSystemService(Context.ETHERNET_SERVICE);
int state = mEM.getState();
if (state != mEM.ETHERNET_STATE_DISABLED) {
if (state == mEM.ETHERNET_STATE_UNKNOWN) {
// maybe this is the first time we run, so set it to enabled
mEm.setEnabled(true);
} else {
try {
resetInterface();
} catch (UnknownHostException e) {
Slog.e(TAG, "Wrong ethernet configuration");
}
}
}
}
}
@Override
public void startMonitoring() {
if (localLOGV) Slog.v(TAG,"start to monitor the ethernet devices");
if (mServiceStarted) {
mEM = (EthernetManager)mContext.getSystemService(Context.ETHERNET_SERVICE);
int state = mEM.getState();
if (state != mEM.ETHERNET_STATE_DISABLED) {
if (state == mEM.ETHERNET_STATE_UNKNOWN) {
// maybe this is the first time we run, so set it to enabled
mEm.setEnabled(true);
} else {
try {
resetInterface();
} catch (UnknownHostException e) {
Slog.e(TAG, "Wrong ethernet configuration");
}
}
}
}
}
其中state=mEm.getState();
调用的是EthernetManager里面的getState这个函数在:
frameworks/base/ethernet/java/android/net/ethernet/EthernetManager.java
代码如下:
/**
* Get ethernet service state
* @return the state of the ethernet service
*/
public int getState( ) {
try {
return mService.getState();
} catch (RemoteException e) {
return 0;
}
}
而这里又调用的Service里面的getState函数在:
frameworks/base/services/java/com/android/server/EthernetService.java
代码如下:
/**
* Get ethernet service state
* @return the state of the ethernet service
*/
public int getState( ) {
return mEthState;
}