5.1以前请参考:
http://blog.csdn.net/u013686019/article/details/51447129
平台
RK3288 + android5.1
需求
修改网络连接优先级为
Ethernet > Mobile > Wifi
修改
diff --git a/frameworks/opt/telephony/src/java/com/android/internal/telephony/dataconnection/DataConnection.java b/frameworks/opt/telephony/src/java/com/android/internal/telephony/dataconnection/DataConnection.java old mode 100644 new mode 100755 index 09b3c9b..00fba2a --- a/frameworks/opt/telephony/src/java/com/android/internal/telephony/dataconnection/DataConnection.java +++ b/frameworks/opt/telephony/src/java/com/android/internal/telephony/dataconnection/DataConnection.java @@ -1734,7 +1734,7 @@ public final class DataConnection extends StateMachine { misc.subscriberId = mPhone.getSubscriberId(); mNetworkAgent = new DcNetworkAgent(getHandler().getLooper(), mPhone.getContext(), "DcNetworkAgent", mNetworkInfo, makeNetworkCapabilities(), mLinkProperties, - 50, misc); + 100, misc); } @Override diff --git a/frameworks/opt/telephony/src/java/com/android/internal/telephony/dataconnection/DctController.java b/frameworks/opt/telephony/src/java/com/android/internal/telephony/dataconnection/DctController.java old mode 100644 new mode 100755 index 4fce2ec..fdb59b1 --- a/frameworks/opt/telephony/src/java/com/android/internal/telephony/dataconnection/DctController.java +++ b/frameworks/opt/telephony/src/java/com/android/internal/telephony/dataconnection/DctController.java @@ -152,7 +152,7 @@ public class DctController extends Handler { mNetworkFactory[index] = new TelephonyNetworkFactory(this.getLooper(), mPhones[index].getContext(), "TelephonyNetworkFactory", phoneBase, mNetworkFilter[index]); - mNetworkFactory[index].setScoreFilter(50); + mNetworkFactory[index].setScoreFilter(100); mNetworkFactoryMessenger[index] = new Messenger(mNetworkFactory[index]); cm.registerNetworkFactory(mNetworkFactoryMessenger[index], "Telephony"); }
说明
网络优先级采用新的score机制.
以上改法, 将移动网络的score从50 加到 100.
从当前代码中看, Ethernet (150), Wifi(60)
frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiStateMachine.java(Wifi)
mNetworkAgent = new WifiNetworkAgent(getHandler().getLooper(), mContext, "WifiNetworkAgent", mNetworkInfo, mNetworkCapabilitiesFilter, mLinkProperties, 60); mNetworkFactory = new WifiNetworkFactory(getHandler().getLooper(), mContext, NETWORKTYPE, mNetworkCapabilitiesFilter); mNetworkFactory.setScoreFilter(60);
frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetNetworkFactory.java(Ethernet)
private static final int NETWORK_SCORE = 150; // Create our NetworkAgent. mNetworkAgent = new NetworkAgent(mFactory.getLooper(), mContext, NETWORK_TYPE, mNetworkInfo, mNetworkCapabilities, mLinkProperties, NETWORK_SCORE) { // Create and register our NetworkFactory. mFactory = new LocalNetworkFactory(NETWORK_TYPE, context, target.getLooper()); /** * Updates interface state variables. * Called on link state changes or on startup. */ private void updateInterfaceState(String iface, boolean up) { if (!mIface.equals(iface)) { return; } Log.d(TAG, "updateInterface: " + iface + " link " + (up ? "up" : "down")); synchronized(this) { mLinkUp = up; mNetworkInfo.setIsAvailable(up); if (!up) { // Tell the agent we're disconnected. It will call disconnect(). mNetworkInfo.setDetailedState(DetailedState.DISCONNECTED, null, mHwAddr); sendEthernetStateChangedBroadcast(EthernetManager.ETHER_STATE_DISCONNECTED); } updateAgent(); // set our score lower than any network could go // so we get dropped. TODO - just unregister the factory // when link goes down. mFactory.setScoreFilter(up ? NETWORK_SCORE : -1); } }