当前位置:   article > 正文

Android12上实现双以太网卡共存同时访问外网

Android12上实现双以太网卡共存同时访问外网

具体实现如下:

修改main 表优先级到9999, 作用:eth0 eth1 访问

不去teardown 低分数网线

  1. diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java
  2. index 418e9e3..72d15d5 100644
  3. --- a/service/src/com/android/server/ConnectivityService.java
  4. +++ b/service/src/com/android/server/ConnectivityService.java
  5. @@ -291,8 +291,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
  6. private static final String REQUEST_ARG = "requests";
  7. private static final boolean DBG = true;
  8. - private static final boolean DDBG = Log.isLoggable(TAG, Log.DEBUG);
  9. - private static final boolean VDBG = Log.isLoggable(TAG, Log.VERBOSE);
  10. + private static final boolean DDBG = true; //Log.isLoggable(TAG, Log.DEBUG);
  11. + private static final boolean VDBG = true; //Log.isLoggable(TAG, Log.VERBOSE);
  12. private static final boolean LOGD_BLOCKED_NETWORKINFO = true;
  13. @@ -1587,7 +1587,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
  14. handleAlwaysOnNetworkRequest(mDefaultMobileDataRequest,
  15. ConnectivitySettingsManager.MOBILE_DATA_ALWAYS_ON, true /* defaultValue */);
  16. handleAlwaysOnNetworkRequest(mDefaultWifiRequest,
  17. - ConnectivitySettingsManager.WIFI_ALWAYS_REQUESTED, false /* defaultValue */);
  18. + ConnectivitySettingsManager.WIFI_ALWAYS_REQUESTED, true/* defaultValue */);
  19. final boolean vehicleAlwaysRequested = mResources.get().getBoolean(
  20. R.bool.config_vehicleInternalNetworkAlwaysRequested);
  21. handleAlwaysOnNetworkRequest(mDefaultVehicleRequest, vehicleAlwaysRequested);
  22. @@ -3797,6 +3797,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
  23. // 2. If the network was inactive and there are now requests, unset inactive.
  24. // 3. If this network is unneeded (which implies it is not lingering), and there is at least
  25. // one lingered request, set inactive.
  26. + /****
  27. nai.updateInactivityTimer();
  28. if (nai.isInactive() && nai.numForegroundNetworkRequests() > 0) {
  29. if (DBG) log("Unsetting inactive " + nai.toShortString());
  30. @@ -3811,6 +3812,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
  31. logNetworkEvent(nai, NetworkEvent.NETWORK_LINGER);
  32. return true;
  33. }
  34. + ****/
  35. + loge("wade skip updateInactivityState.");
  36. return false;
  37. }
  38. @@ -6853,7 +6856,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
  39. return;
  40. }
  41. mNetworkOffers.add(noi);
  42. - issueNetworkNeeds(noi);
  43. + //issueNetworkNeeds(noi);
  44. }
  45. private void handleUnregisterNetworkOffer(@NonNull final NetworkOfferInfo noi) {
  46. @@ -7780,6 +7783,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
  47. }
  48. private void teardownUnneededNetwork(NetworkAgentInfo nai) {
  49. + /**
  50. if (nai.numRequestNetworkRequests() != 0) {
  51. for (int i = 0; i < nai.numNetworkRequests(); i++) {
  52. NetworkRequest nr = nai.requestAt(i);
  53. @@ -7790,6 +7794,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
  54. }
  55. }
  56. nai.disconnect();
  57. + **/
  58. + loge("wade skip teardownUnneededNetwork.");
  59. }
  60. private void handleLingerComplete(NetworkAgentInfo oldNetwork) {
  61. @@ -8113,6 +8119,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
  62. // Remove default networking if disallowed for managed default requests.
  63. bestNetwork = mNoServiceNetwork;
  64. }
  65. + loge("wade bestNetwork = " + bestNetwork + "bestRequest = " + bestRequest);
  66. if (nri.getSatisfier() != bestNetwork) {
  67. // bestNetwork may be null if no network can satisfy this request.
  68. changes.addRequestReassignment(new NetworkReassignment.RequestReassignment(
  69. @@ -8150,7 +8157,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
  70. log(changes.toString()); // Shorter form, only one line of log
  71. }
  72. applyNetworkReassignment(changes, now);
  73. - issueNetworkNeeds();
  74. + //issueNetworkNeeds();
  75. }
  76. private void applyNetworkReassignment(@NonNull final NetworkReassignment changes,
  1. diff --git a/server/RouteController.cpp b/server/RouteController.cpp
  2. index ba305e6..d38aec5 100644
  3. --- a/server/RouteController.cpp
  4. +++ b/server/RouteController.cpp
  5. @@ -721,6 +721,18 @@ int RouteController::configureDummyNetwork() {
  6. return 0;
  7. }
  8. +// Add a new rule to look up the 'main' table, with the same selectors as the "default network"
  9. +// rule, but with a lower priority. We will never create routes in the main table; it should only be
  10. +// used for directly-connected routes implicitly created by the kernel when adding IP addresses.
  11. +// This is necessary, for example, when adding a route through a directly-connected gateway: in
  12. +// order to add the route, there must already be a directly-connected route that covers the gateway.
  13. +[[nodiscard]] static int addDirectlyConnectedRule() {
  14. +
  15. + return modifyIpRule(RTM_NEWRULE, RULE_PRIORITY_DIRECTLY_CONNECTED, RT_TABLE_MAIN,
  16. + 0, 0/*, IIF_NONE, OIF_NONE, UID_ROOT, UID_ROOT*/);
  17. +}
  18. +
  19. +
  20. // Add an explicit unreachable rule close to the end of the prioriy list to make it clear that
  21. // relying on the kernel-default "from all lookup main" rule at priority 32766 is not intended
  22. // behaviour. We do flush the kernel-default rules at startup, but having an explicit unreachable
  23. @@ -1160,6 +1172,11 @@ int RouteController::Init(unsigned localNetId) {
  24. if (int ret = addUnreachableRule()) {
  25. return ret;
  26. }
  27. +
  28. + if (int ret = addDirectlyConnectedRule()) {
  29. + return ret;
  30. + }
  31. +
  32. // Don't complain if we can't add the dummy network, since not all devices support it.
  33. configureDummyNetwork();
  34. diff --git a/server/RouteController.h b/server/RouteController.h
  35. index 38d2d62..43ee148 100644
  36. --- a/server/RouteController.h
  37. +++ b/server/RouteController.h
  38. @@ -30,6 +30,7 @@
  39. namespace android::net {
  40. // clang-format off
  41. +const uint32_t RULE_PRIORITY_DIRECTLY_CONNECTED = 9999;
  42. const uint32_t RULE_PRIORITY_VPN_OVERRIDE_SYSTEM = 10000;
  43. const uint32_t RULE_PRIORITY_VPN_OVERRIDE_OIF = 11000;
  44. const uint32_t RULE_PRIORITY_VPN_OUTPUT_TO_LOCAL = 12000;

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号