Android12上實現雙以太網卡共存同時訪問外網

具體實現如下:

修改main 表優先級到9999, 作用:eth0?eth1 訪問

不去teardown 低分數網線

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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/43014.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/43014.shtml
英文地址,請注明出處:http://en.pswp.cn/web/43014.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Ubuntu 22.04 設置swap交換空間

經常爆內存&#xff0c;導致很多應用沒有辦法一直正常運行&#xff0c;可以通過設置swap來緩解一下&#xff0c;雖然和內存的速度無法媲美&#xff0c;但是能一定程度緩解一下問題。 一、查看當前分區 查看當前系統的swap大小 free -m 二、關閉現有的swap分區 將/etc/fstab…

CUDA Kernel調試與優化--背景知識掃盲(LLM生成)

CUDA Kernel調試與優化–背景知識掃盲(LLM生成) 對于使用CUDA進行調試與性能優化&#xff0c;官方提供了豐富的參考資料和工具。以下是一些關鍵資源&#xff0c;可以幫助你更好地調試和優化CUDA代碼&#xff1a; 官方文檔和指南 CUDA Toolkit Documentation URL: CUDA Toolk…

強化學習總結(有具體代碼實現)

文章目錄 第一部分 強化學習基礎第1章 強化學習概述1.1 強化學習概念1.2 強化學習的環境1.3 強化學習的目標1.4 強化學習的數據 第2章 多臂老虎機問題&#xff08;MAB問題&#xff09;2.1 問題描述2.1.1 問題定義2.1.2 形式化描述2.1.3 累積懊悔2.1.4 估計期望獎勵 2.2 解決方法…

CSS 【詳解】CSS 函數(含 calc,min,max,clamp,cubic-bezier,env,steps 等)

函數描述CSS 版本attr()返回選擇元素的屬性值。2calc()允許計算 CSS 的屬性值&#xff0c;比如動態計算長度值。3cubic-bezier()定義了一個貝塞爾曲線(Cubic Bezier)。3hsl()使用色相、飽和度、亮度來定義顏色。3hsla()使用色相、飽和度、亮度、透明度來定義顏色。3linear-grad…

Bert 變種, T5模型

NLP-預訓練模型-2019-NLU&#xff1a;DistilBERT【 BERT模型壓縮】【模型大小減小了40%&#xff08;66M&#xff09;&#xff0c;推斷速度提升了60%&#xff0c;但性能只降低了約3%】_distillbert-CSDN博客 https://zhuanlan.zhihu.com/p/673535548 大語言模型系列-T5_t5模型…

【機器學習】必會數學知識:一文掌握數據科學核心數學知識點(上),值得收藏~

核心數學知識點 1、引言2、數據科學必會數學知識2.1 線性代數2.2 微積分2.3 概率論2.4 數理統計2.5 隨機過程2.6 數據分布2.7 貝葉斯統計2.8 線性回歸2.9 邏輯回歸2.10 矩陣分解2.11 主成分分析&#xff08;PCA&#xff09;2.12 奇異值分解&#xff08;SVD&#xff09; 3、總結…

【Git 入門】初始化配置與新建倉庫

文章目錄 前言配置git新建倉庫倉庫的概念創建倉庫命令總結前言 在現代軟件開發中,版本控制系統已經成為了不可或缺的工具。其中,Git 是最為廣泛使用的版本控制系統之一。Git 不僅可以幫助我們管理和跟蹤代碼的變化,還可以方便地與他人協作。本文將介紹 Git 的基礎知識,包括…

【人工智能大語言模型技術發展研究報告 2024】

文末?有福利&#xff01; 人工智能作為引領新一輪科技產業革命的戰略性技術和新質生產力重要驅動力&#xff0c;正在引發經濟、社會、文化等領域的變革和重塑&#xff0c;2023 年以來&#xff0c;以 ChatGPT、GPT-4 為代表的大模型技術的出臺&#xff0c;因其強大的內容生成及…

提升教師健康,聚焦智慧校園人事系統的職工體檢功能

智慧校園人事管理系統內置的職工體檢管理&#xff0c;是專為教職員工設計的一項健康管理創新實踐&#xff0c;巧妙融合先進信息技術&#xff0c;致力于為教職工提供更加便捷、易懂且持續性的健康檢查與管理支持。該服務從多個維度出發&#xff0c;全面呵護教職工的身心健康。 該…

給你的博客加上評論區

一個網站如果有評論功能&#xff0c;可以更好的和讀者互動。VuePress 也有很多評論插件&#xff0c;這里簡單介紹下&#xff0c;最后介紹本站所使用的 Twikoo。 大部分評論插件都是使用的 Github 或 Gitee 的 issue 功能&#xff0c;也就是用 issue 去存儲評論&#xff1b;而 …

自然語言處理(NLP)與大語言模型(LLM) 主要差異

一、簡述 NLP 和 LLM 技術是大規模分析和生成人類語言的核心。隨著它們的日益普及&#xff0c;區分 LLM 與 NLP 變得越來越重要。 NLP 包含一套用于理解、操縱和生成人類語言的算法。自 20 世紀 50 年代誕生以來&#xff0c;NLP 已發展到分析文本關系的階段。它使用詞性標注、命…

腳本實現保留文本中特定字符之后的字符串

#目的背景 原始txt文本如下圖 目的是為了去除序號&#xff0c;每行只單獨呈現域名 手工刪除漫長又麻煩&#xff0c;使用腳本快捷些 代碼實現邏輯&#xff1a; 1.使用open函數打開文本&#xff0c;之后用變量lines存儲文本的所有行&#xff0c;使用for循環&#xff0c;讓變量te…

暑假學習計劃怎么做 用待辦計劃軟件安排更科學

暑期來臨&#xff0c;無論是學生還是老師&#xff0c;做好暑期計劃都至關重要。記得去年暑假&#xff0c;我給自己定下了閱讀十本書的目標&#xff0c;卻因為缺乏明確的計劃&#xff0c;最后只草草讀完了兩本。而今年&#xff0c;我決定嘗試一種新的方式——使用待辦計劃軟件來…

大學生數學競賽教程(蒲和平)

大學生數學競賽教程(蒲和平) https://pan.baidu.com/s/1ytcIbVcZpof9WM1xa2dDfA 提取碼: kf2r 源文件來自于&#xff1a;大學生數學競賽教程【蒲和平】

谷粒商城實戰筆記-24-分布式組件-SpringCloud Alibaba-Nacos配置中心-命名空間與配置分組

文章目錄 一&#xff0c;命名空間1&#xff0c;簡介1.1&#xff0c;命名空間的主要功能和特點1.2&#xff0c;使用場景1.3&#xff0c;如何指定命名空間 2&#xff0c;命名空間實戰2.1&#xff0c;環境隔離2.2&#xff0c;服務隔離 二&#xff0c;配置集三&#xff0c;配置集ID…

【數據基礎】— 基于Go1.19的站點模板爬蟲的實現

目錄 1. 定義目標站點 2. 使用Go的庫 3. 發送HTTP請求 4. 解析HTML并提取數據 5. 存儲數據 6. 并發處理 示例代碼 基于Go 1.19的站點模板爬蟲實現通常涉及幾個關鍵步驟&#xff1a;定義目標站點、解析HTML頁面、提取所需數據、存儲數據以及可能的并發處理。下面我將詳細…

js原型和類---prototype,__proto__,new,class

原型和原型鏈 在js中&#xff0c;所有的變量都有原型&#xff0c;原型也可以有原型&#xff0c;原型最終都指向Object 什么是原型 在js中&#xff0c;一個變量被創建出來&#xff0c;它就會被綁定一個原型&#xff1b;比如說&#xff0c;任何一個變量都可以使用console.log打…

PostgreSQL 中如何實現數據的增量更新和全量更新的平衡?

文章目錄 一、增量更新與全量更新的概念增量更新全量更新 二、考慮的因素1. 數據量2. 數據更改的頻率和規模3. 數據一致性要求4. 系統性能和資源利用5. 業務邏輯和流程 三、解決方案&#xff08;一&#xff09;混合使用增量更新和全量更新&#xff08;二&#xff09;使用臨時表…

暑期旅游季必備,用這款客服神器應對爆棚的客流咨詢

解決暑期旅游客流高峰問題 暑期是旅游高峰季節&#xff0c;客流量劇增&#xff0c;客戶咨詢紛至沓來。在這個時候&#xff0c;如何高效處理客戶的咨詢成為每家旅游機構和景點不可忽視的挑戰。 聊天寶快捷回復助手是一款強大的工具&#xff0c;可幫助企業在客流高峰期快速回復客…

QDataStream的尷尬

最近在編寫一個網絡功能&#xff0c;需要將一個文件內容傳遞到客戶端并將改內容以文件形式保存下來。由于文件內容是個加密文件且采用了二進制形式于是客戶端就采用了QDataStream這個對象來保存文件。粗略的測試下來沒有什么問題&#xff0c;可是在獲取寫入的文件是否發現寫入的…