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.mzph.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;可是在获取写入的文件是否发现写入的…