Created
February 7, 2017 12:27
-
-
Save dmpatel151282/8a22100a917938578ba36b51bf85d4b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Open the following file from Android framework. | |
- /android/frameworks/base/services/java/com/android/server/ConnectivityService.java | |
- Add below code at appropriate place. | |
// the set of network types that can only be enabled by system/sig apps | |
List mProtectedNetworks; | |
+// Wifi/Eth coexist strategy V0.3 | |
+private NetworkInfo mSecondaryNetworkInfo = null; | |
+private int mActiveSecondaryNetwork = -1; | |
+// End | |
- Go to "handleDisconnect" function. Add below code at appropriate place. | |
int prevNetType = info.getType(); | |
+// Wifi/Eth coexist strategy V0.3 | |
+if (prevNetType == ConnectivityManager.TYPE_WIFI) { | |
+ log("Wifi Disconnected!"); | |
+ mSecondaryNetworkInfo = null; | |
+ mActiveSecondaryNetwork = -1; | |
+} | |
+// End | |
... | |
if (mActiveDefaultNetwork != -1) { | |
sendConnectedBroadcastDelayed(mNetTrackers[mActiveDefaultNetwork].getNetworkInfo(), | |
getConnectivityChangeDelay()); | |
} | |
+// Wifi/Eth coexist strategy V0.3 | |
+if (prevNetType == ConnectivityManager.TYPE_ETHERNET && mActiveSecondaryNetwork != -1) { | |
+ log("Ethernet disconnect, refresh netowrk info to wifi."); | |
+ handleConnect(mSecondaryNetworkInfo); | |
+ log("Add wlan0 default route info"); | |
+ LinkProperties wifiLp = mNetTrackers[mActiveDefaultNetwork].getLinkProperties(); | |
+ String ifname = wifiLp.getInterfaceName(); | |
+ for(RouteInfo r : wifiLp.getRoutes()) { | |
+ try { | |
+ if (r.isDefaultRoute()) { | |
+ log(ifname + "add default route: " + r); | |
+ mNetd.addRoute(ifname, r); | |
+ } | |
+ } catch (Exception e) { | |
+ // never crash - catch them all | |
+ if (DBG) loge("Exception trying to remove a route: " + e); | |
+ //return false; | |
+ } | |
+ } | |
+} | |
+// End | |
- Go to "handleConnectionFailure" function. Add below code at appropriate place. | |
mNetTrackers[info.getType()].setTeardownRequested(false); | |
+// Wifi/Eth coexist strategy V0.3 | |
+if (info.getType() == ConnectivityManager.TYPE_WIFI) { | |
+ log("Wifi Disconnected!"); | |
+ mSecondaryNetworkInfo = null; | |
+ mActiveSecondaryNetwork = -1; | |
+} | |
+// End | |
... | |
if (mActiveDefaultNetwork != -1) { | |
sendConnectedBroadcast(mNetTrackers[mActiveDefaultNetwork].getNetworkInfo()); | |
} | |
+// Wifi/Eth coexixt strategy V0.3 | |
+if (info.getType() == ConnectivityManager.TYPE_ETHERNET && mActiveSecondaryNetwork != -1) { | |
+ log("Ethernet disconnect, refresh netowrk info to wifi.[handleConnectionFailure]"); | |
+ handleConnect(mSecondaryNetworkInfo); | |
+ log("Add wlan0 default route info[handleConnectionFailure]"); | |
+ LinkProperties wifiLp = mNetTrackers[mActiveDefaultNetwork].getLinkProperties(); | |
+ String ifname = wifiLp.getInterfaceName(); | |
+ for(RouteInfo r : wifiLp.getRoutes()) { | |
+ try { | |
+ if (r.isDefaultRoute()) { | |
+ log(ifname + "add default route: " + r); | |
+ mNetd.addRoute(ifname, r); | |
+ } | |
+ } catch (Exception e) { | |
+ // never crash - catch them all | |
+ if (DBG) loge("Exception trying to remove a route: " + e); | |
+ //return false; | |
+ } | |
+ } | |
+} | |
+// End | |
- Go to "handleConnect" function. Add below code at appropriate place. | |
final int newNetType = info.getType(); | |
+// Wifi/Eth coexist strategy V0.3 | |
+log("Connected type: " + newNetType); | |
+log("Current preferred type: " + mNetworkPreference); | |
+// End | |
... | |
// if this is a default net and other default is running | |
// kill the one not preferred | |
if (mNetConfigs[newNetType].isDefault()) { | |
if (mActiveDefaultNetwork != -1 && mActiveDefaultNetwork != newNetType) { | |
if (isNewNetTypePreferredOverCurrentNetType(newNetType)) { | |
+// Wifi/Eth coexist strategy V0.3 | |
+if (newNetType == ConnectivityManager.TYPE_ETHERNET && | |
+ mActiveDefaultNetwork == ConnectivityManager.TYPE_WIFI) { | |
+ log("Wifi already connected, but Eth connected after. Eth&Wifi coexit"); | |
+ mSecondaryNetworkInfo = mNetTrackers[ConnectivityManager.TYPE_WIFI].getNetworkInfo();; | |
+ mActiveSecondaryNetwork = mActiveDefaultNetwork; | |
+ log("Delete wlan0 default route info"); | |
+ LinkProperties wifiLp = mNetTrackers[mActiveDefaultNetwork].getLinkProperties(); | |
+ String ifname = wifiLp.getInterfaceName(); | |
+ for(RouteInfo r : wifiLp.getRoutes()) { | |
+ try { | |
+ if (r.isDefaultRoute()) { | |
+ log(ifname + "remove default route: " + r); | |
+ mNetd.removeRoute(ifname, r); | |
+ } | |
+ } catch (Exception e) { | |
+ // never crash - catch them all | |
+ if (DBG) loge("Exception trying to remove a route: " + e); | |
+ //return false; | |
+ } | |
+ } | |
+} else { | |
+ // tear down the other | |
+ NetworkStateTracker otherNet = mNetTrackers[mActiveDefaultNetwork]; | |
+ if (DBG) { | |
+ log("Policy requires " + otherNet.getNetworkInfo().getTypeName() + | |
+ " teardown"); | |
+ } | |
+ if (!teardown(otherNet)) { | |
+ loge("Network declined teardown request"); | |
+ teardown(thisNet); | |
+ return; | |
+ } | |
+} | |
+// End | |
} else { | |
+// Wifi/Eth coexist strategy V0.3 | |
+if (newNetType == ConnectivityManager.TYPE_WIFI && | |
+ mActiveDefaultNetwork == ConnectivityManager.TYPE_ETHERNET) { | |
+ mSecondaryNetworkInfo = info; | |
+ mActiveSecondaryNetwork = newNetType; | |
+ log("Eth already connected, but wifi connected after. Eth&Wifi coexist."); | |
+ log("Eth default active \t Wifi seconday active"); | |
+ return; | |
+} else { | |
+ // don't accept this one | |
+ if (VDBG) { | |
+ log("Not broadcasting CONNECT_ACTION " + | |
+ "to torn down network " + info.getTypeName()); | |
+ } | |
+ teardown(thisNet); | |
+ return; | |
+} | |
+// End | |
} | |
} | |
synchronized (ConnectivityService.this) { | |
// have a new default network, release the transition wakelock in a second | |
// if it's held. The second pause is to allow apps to reconnect over the | |
// new network | |
if (mNetTransitionWakeLock.isHeld()) { | |
mHandler.sendMessageDelayed(mHandler.obtainMessage( | |
EVENT_CLEAR_NET_TRANSITION_WAKELOCK, | |
mNetTransitionWakeLockSerialNumber, 0), | |
1000); | |
} | |
} | |
mActiveDefaultNetwork = newNetType; | |
// this will cause us to come up initially as unconnected and switching | |
// to connected after our normal pause unless somebody reports us as reall | |
// disconnected | |
mDefaultInetConditionPublished = 0; | |
mDefaultConnectionSequence++; | |
mInetConditionChangeInFlight = false; | |
// Don't do this - if we never sign in stay, grey | |
//reportNetworkCondition(mActiveDefaultNetwork, 100); | |
} | |
- Go to "handleCaptivePortalTrackerCheck" function. Add below code at appropriate place. | |
if (DBG) log("Tear down low priority net " + info.getTypeName()); | |
+// Wifi/Eth coexist strategy V0.3 | |
+//teardown(thisNet); | |
+if (mActiveDefaultNetwork == ConnectivityManager.TYPE_ETHERNET) | |
+ mCaptivePortalTracker.detectCaptivePortal(new NetworkInfo(info)); | |
+// End | |
return; | |
Hello @TobianVorsmann
Have you got any solution of it???
If not then add below patch line in frameworks/base/services/core/java/com/android/server/ConnectivityService.java file.
+ final NetworkRequest mEthernetRequest = createDefaultInternetRequestForTransport(
+ NetworkCapabilities.TRANSPORT_ETHERNET,
+ NetworkRequest.Type.REQUEST);
+ NetworkRequestInfo ethernetNRI = new NetworkRequestInfo(null, mEthernetRequest, new Binder());
+ mNetworkRequests.put(mEthernetRequest, ethernetNRI);
+ mNetworkRequestInfoLogs.log("REGISTER " + ethernetNRI);
mDefaultMobileDataRequest = createDefaultInternetRequestForTransport(
| NetworkCapabilities.TRANSPORT_CELLULAR, NetworkRequest.Type.BACKGROUND_REQUEST);
I have tried in Android Q and it's working.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @dmpatel151282
Thanks for your help. I am trying to find a solution parallelly for sure :)