Android 13 Ethernet变更
Android13 有线变更
以太网相关的功能在Android12 和13 网络部分变化是不大的,Android11 到Android 12 网络部分无论是代码存放目录和代码逻辑都是有较多修改的,主要包括以下几个部分
-
限制了设置有线网参数设置接口方法
-
新增有线网开启关闭接口方法
-
新增了 updateConfiguration 接口方法
-
有线网设置的静态ip和代理信息重启后无效
-
EthernetManager相关代码从framework移到packages/modules/Connectivity/ (之前目录:frameworks\base\core\java\android\net\EthernetManager.java) 后面开发Android12 或新版本代码,你会发现wifi 、蓝牙、热点 之前 framework 的源码都移动到了下面的package目录:
基于以上变更。如果app api (targetSdkVersion)设置成Android12 ,应用用无法用以前的接口设置有线网信息。
-
限制了设置有线网参数设置接口方法
//packages\modules\Connectivity\framework-t\src\android\net\EthernetManager.java/*** Get Ethernet configuration.* @return the Ethernet Configuration, contained in {@link IpConfiguration}.* @hide*/@SystemApi(client = MODULE_LIBRARIES)public @NonNull IpConfiguration getConfiguration(@NonNull String iface) {try {return mService.getConfiguration(iface);} catch (RemoteException e) {throw e.rethrowFromSystemServer();}}/*** Set Ethernet configuration.* @hide*/@SystemApi(client = MODULE_LIBRARIES)public void setConfiguration(@NonNull String iface, @NonNull IpConfiguration config) {try {mService.setConfiguration(iface, config);} catch (RemoteException e) {throw e.rethrowFromSystemServer();}}@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)public String[] getAvailableInterfaces() {try {return mService.getAvailableInterfaces();} catch (RemoteException e) {throw e.rethrowAsRuntimeException();}}
从上面看,主要是api加了限制 :maxTargetSdk = Build.VERSION_CODES.R //Android11
所以Android 12 或者更新的版本,在EthernetManager 是调用不到上面几个接口方法的
-
新增有线网开启关闭接口方法
//packages\modules\Connectivity\framework-t\src\android\net\EthernetManager.java@RequiresPermission(anyOf = {NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK,android.Manifest.permission.NETWORK_STACK,android.Manifest.permission.NETWORK_SETTINGS})@SystemApi(client = MODULE_LIBRARIES)public void setEthernetEnabled(boolean enabled) {try {mService.setEthernetEnabled(enabled);} catch (RemoteException e) {throw e.rethrowFromSystemServer();}}
这个是新增的接口方法 setEthernetEnabled ,之前是要自己实现有线网开关的。需要的权限上面已经说明的,基本是要系统签名的应用才能调用。
-
新增了 updateConfiguration 接口方法
//packages\modules\Connectivity\framework-t\src\android\net\EthernetManager.java@SystemApi@RequiresPermission(anyOf = {NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK,android.Manifest.permission.NETWORK_STACK,android.Manifest.permission.MANAGE_ETHERNET_NETWORKS})public void updateConfiguration(@NonNull String iface,@NonNull EthernetNetworkUpdateRequest request,@Nullable @CallbackExecutor Executor executor,@Nullable OutcomeReceiver<String, EthernetNetworkManagementException> callback) {Objects.requireNonNull(iface, "iface must be non-null");Objects.requireNonNull(request, "request must be non-null");final NetworkInterfaceOutcomeReceiver proxy = makeNetworkInterfaceOutcomeReceiver(executor, callback);try {mService.updateConfiguration(iface, request, proxy);} catch (RemoteException e) {throw e.rethrowFromSystemServer();}}
String iface //节点名称:eth0 / eth1
EthernetNetworkUpdateRequest request 对象是包含静态ip和代理信息对象和特征属性对象。
后面两个是回调监听,未要求非空,是可以传null 的。
另外在有线网服务,新api 增加了限制!
//packages\modules\Connectivity\service-t\src\com\android\server\ethernet\EthernetServiceImpl.java@Overridepublic void updateConfiguration(@NonNull final String iface,@NonNull final EthernetNetworkUpdateRequest request,@Nullable final INetworkInterfaceOutcomeReceiver listener) {Objects.requireNonNull(iface);Objects.requireNonNull(request);throwIfEthernetNotStarted();// TODO: validate that iface is listed in overlay config_ethernet_interfaces// only automotive devices are allowed to set the NetworkCapabilities using this API//only automotive devices 表明,只有 车载设备支持设置该方法
+ // 非车载项目必须注释调方法:enforceAdminPermission ,否则会报错,这里是校验是否是车载项目
+ //enforceAdminPermission(iface, request.getNetworkCapabilities() != null,
+ // "updateConfiguration() with non-null capabilities");
+ Log.i(TAG, " lwz add updateConfiguration with: iface=" + iface + ", listener=" + listener);maybeValidateTestCapabilities(iface, request.getNetworkCapabilities());mTracker.updateConfiguration(iface, request.getIpConfiguration(), request.getNetworkCapabilities(), listener);}
所以要在自己项目中调用新的api ,必须设置属性让自己的设备识别为车载项目或者把车载判断的逻辑去除即可
-
有线网设置的静态ip和代理信息重启后无效
//查看有线网配置信息保存的类:
packages\modules\Connectivity\service-t\src\com\android\server\ethernet\EthernetConfigStore.javaprivate static final String CONFIG_FILE = "ipconfig.txt";private static final String FILE_PATH = "/misc/ethernet/";private static final String LEGACY_IP_CONFIG_FILE_PATH = Environment.getDataDirectory() + FILE_PATH;//Android13 新增下面路径:private static final String APEX_IP_CONFIG_FILE_PATH = ApexEnvironment.getApexEnvironment(TETHERING_MODULE_NAME).getDeviceProtectedDataDir() + FILE_PATH; // TETHERING_MODULE_NAME --》com.android.tethering/**
可以看到之前的路径是:
/data/misc/ethernet/ipconfig.txt
最新的有线网配置文件保存目录:
/data/misc/apexdata/com.android.tethering/misc/ethernet/ipconfig.txt
可能存在因为未成功保存本地配置文件,所以每次开机重启后,无法读取到静态ip和代理等信息。
所以出现 有线网设置的静态ip和代理信息重启后无效 问题。主要原因为开机读取的时候,目录未成功创建,故保存未成功。
可以参考如下:
*///packages\modules\Connectivity/service-t/src/com/android/server/ethernet/EthernetConfigStore.java@VisibleForTestingvoid read(final String newFilePath, final String oldFilePath, final String filename) {try {synchronized (mSync) {// Attempt to read the IP configuration from apex file path first.if (doesConfigFileExist(newFilePath + filename)) {loadConfigFileLocked(newFilePath + filename);return;}//ik-phoebe add for create dir data/misc/apexdata/com.android.tethering/misc/ethernetfinal File directory = new File(newFilePath);if (!directory.exists()) {boolean mkdirs = directory.mkdirs();Log.d(TAG, "zmm add for mkdirs:" + newFilePath + ",result:" + mkdirs);}// If the config file doesn't exist in the apex file path, attempt to read it from// the legacy file path, if config file exists, write the legacy IP configuration to// apex config file path, this should just happen on the first boot. New or updated// config entries are only written to the apex config file later.if (!doesConfigFileExist(oldFilePath + filename)) return;loadConfigFileLocked(oldFilePath + filename);writeLegacyIpConfigToApexPath(newFilePath, oldFilePath, filename);}} catch (Exception e) {e.printStackTrace();Log.e(TAG, "zmm add for read exception:" + e.getMessage());}}
Android13 有线网适配思路
主要是从以下两个方面:
(1)使用新api接口设置静态ip和代理信息
(2)移除源码中限制接口的版本号 目前我采用的是二,但是如果项目需要过gms认证,则只能使用一,因为gms合入mainline,packages\modules\Connectivity生成的jar会被覆盖。
diff --git a/framework-t/api/module-lib-current.txt b/framework-t/api/module-lib-current.txt
index 5a8d47b..177f6c5 100644
--- a/framework-t/api/module-lib-current.txt
+++ b/framework-t/api/module-lib-current.txt
@@ -44,9 +44,11 @@ package android.net {public class EthernetManager {method @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) public void addEthernetStateListener(@NonNull java.util.concurrent.Executor, @NonNull java.util.function.IntConsumer);method @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) public void addInterfaceStateListener(@NonNull java.util.concurrent.Executor, @NonNull android.net.EthernetManager.InterfaceStateListener);
+ method @NonNull public android.net.IpConfiguration getConfiguration(@NonNull String);method @NonNull @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) public java.util.List<java.lang.String> getInterfaceList();method @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) public void removeEthernetStateListener(@NonNull java.util.function.IntConsumer);method public void removeInterfaceStateListener(@NonNull android.net.EthernetManager.InterfaceStateListener);
+ method public void setConfiguration(@NonNull String, @NonNull android.net.IpConfiguration);method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public void setEthernetEnabled(boolean);method public void setIncludeTestInterfaces(boolean);field public static final int ETHERNET_STATE_DISABLED = 0; // 0x0
diff --git a/framework-t/src/android/net/EthernetManager.java b/framework-t/src/android/net/EthernetManager.java
index 886d194..9c675fb 100644
--- a/framework-t/src/android/net/EthernetManager.java
+++ b/framework-t/src/android/net/EthernetManager.java
@@ -191,8 +191,8 @@ public class EthernetManager {* @return the Ethernet Configuration, contained in {@link IpConfiguration}.* @hide*/
- @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
- public IpConfiguration getConfiguration(String iface) {
+ @SystemApi(client = MODULE_LIBRARIES)
+ public @NonNull IpConfiguration getConfiguration(@NonNull String iface) {try {return mService.getConfiguration(iface);} catch (RemoteException e) {
@@ -204,7 +204,7 @@ public class EthernetManager {* Set Ethernet configuration.* @hide*/
- @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
+ @SystemApi(client = MODULE_LIBRARIES)public void setConfiguration(@NonNull String iface, @NonNull IpConfiguration config) {try {mService.setConfiguration(iface, config);
--
2.17.1
当然最好的还是使用系统提供的更新ip方法:
IpConfiguration.Builder build = new IpConfiguration.Builder();EthernetNetworkUpdateRequest.Builder requestBuilder = new EthernetNetworkUpdateRequest.Builder();build.setHttpProxy(proxyinfo);
//如果是静态ip,需要创建对应的静态staticIpConfigurationbuild.setStaticIpConfiguration(staticIpConfiguration);requestBuilder.setIpConfiguration(build.build());mEthManager.updateConfiguration("eth0", requestBuilder.build(), null, null);
以上为Android13 以太网相关的更新
单曲循环《大悲咒》
相关文章:
Android 13 Ethernet变更
Android13 有线变更 以太网相关的功能在Android12 和13 网络部分变化是不大的,Android11 到Android 12 网络部分无论是代码存放目录和代码逻辑都是有较多修改的,主要包括以下几个部分 限制了设置有线网参数设置接口方法 新增有线网开启关闭接口方法 新…...
基于单片机的超声波语音测距系统
一、系统方案 超声波具有指向性强,能量消耗缓慢,在介质中传播的距离较远,因而超声波经常用于距离的测量,如测距仪和物位测量仪等都可以通过超声波来实现。利用超声波检测往往比较迅速、方便、计算简单、易于做到实时控制ÿ…...
算法系列-力扣876-求链表的中间节点
# 求链表中间节点,如果有两个中间节点取后面那个 链表定义 // lc codestart /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val val; } * …...
SpringBoot集成Redis、Redisson保姆教程【附源码】
1. SpringBoot集成Redis 关于Redis的安装,这里就不重复介绍了,需要的朋友可以看我之前的博文Redis多系统安装(Windows、Linux、Ubuntu) Redis原生命令大全,作者整理的很详细,大部分命令转化为java命令基本也是关键词 Redis 命令参考 接下来开始我们的正题,一起学习下…...
c++多线程中常用的使用方法
1)promise(保证)和future的联合使用,实现两个线程的数据传递 #include <iostream> #include<thread> #include<future>using namespace std;//promise用法:可以给线程一个值,而从另一个线程读出该值 // 实现了两个线程的数…...
【dart】dart基础学习使用(一):变量、操作符、注释和库操作
前言 学习dart语言。 注释 Dart 支持单行注释、多行注释和文档注释。 单行注释 单行注释以 // 开头。Dart 编译器将忽略从 // 到行尾之间的所有内容。 void main() {// 这是单行注释print(Welcome to my Llama farm!); }多行注释 多行注释以 /* 开始,以 / 结…...
element-plus 设置 el-date-picker 弹出框位置
前言 概述:el-date-picker 组件会自动根据空间范围进行选择比较好的弹出位置,但特定情况下,它自动计算出的弹出位置并不符合我们的实际需求,故需要我们手动设置。 存在的问题:element-plus 中 el-date-picker 文档中并…...
C++day7(auto关键字、lambda表达式、C++中的数据类型转换、C++标准模板库(STL)、list、文件操作)
一、Xmind整理: 关键词总结: 二、上课笔记整理: 1.auto关键字 #include <iostream>using namespace std;int fun(int a, int b, float *c, char d, double *e,int f) {return 12; }int main() {//定义一个函数指针,指向fu…...
纽扣电池/锂电池UN38.3安全检测报告
根据规章要求,航空公司和机场货物收运部门应对锂电池进行运输文件审查,重要的是每种型号的锂电池UN38.3安全检测报告。该报告可由的三方检测机构。如不能提供此项检测报告,将禁止锂电池进行航空运输. UN38.3包含产品:1、 锂电池2…...
K8S:K8S自动化运维容器Docker集群
文章目录 一.k8s概述1.k8s是什么2.为什么要用K8S3.作用及功能4.k8s容器集群管理系统 二.K8S的特性1.弹性伸缩2.自我修复3.服务发现和复制均衡4.自动发布和回滚5.集中化配置管理和秘钥管理6.存储编排7.任务批量处理运行 三.K8S的集群架构四.K8S的核心组件1.Master组件࿰…...
Java的guava 限流写法
第一步先引入 maven <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>32.0.1-jre</version> </dependency> 然后上方法 private final double rateLimiter10 1.0 / 10.0; // 每…...
[uniapp] scroll-view 简单实现 u-tabbar效果
文章目录 方案踩坑1.scroll-view 横向失败2.点击item不滚动?3. scrollLeft从哪里来? 效果图 方案 官方scroll-view 进行封装 配合属性 scroll-left Number/String 设置横向滚动条位置 即可 scroll-into-view 属性尝试过,方案较难实现 踩坑 1.scroll-view 横向失败 安装…...
vue常见问题汇总
来源:https://www.fly63.com/ Q1:安装超时(install timeout) 方案有这么些: cnpm : 国内对npm的镜像版本/*cnpm website: https://npm.taobao.org/*/npm install -g cnpm --registryhttps://registry.npm.taobao.org// cnpm 的大多命令跟 npm 的是一致的…...
GPT-3在化学中进行低数据发现是否足够?
今天介绍一份洛桑联邦理工学院进行的工作,这份工作被发表在化学期刊预印本网站上。 对于这份工作,有兴趣的朋友可以通过我们的国内ChatGPT镜像站进行测试使用,我们的站点并没有针对特定任务进行建设,是通用性质的。 化学领域进行…...
gitlab升级
1.下载需要的版本 wget -c https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-15.7.6-ce.0.el7.x86_64.rpm --no-check-certificate gitlab-ce-15.4.6-ce.0.el7.x86_64.rpm gitlab-ce-15.7.6-ce.0.el7.x86_64.rpm gitlab-ce-15.9.7-ce.0.el7.x86_64.rpm g…...
Matlab图像处理-灰度插值法
最近邻法 最近邻法是一种最简单的插值算法,输出像素的值为输入图像中与其最邻近的采样点的像素值。是将(u0,v0)(u_0,v_0)点最近的整数坐标u,v(u,v)点的灰度值取为(u0,v0)(u_0,v_0)点的灰度值。 在(u0,v0)(u_0,v_0)点各相邻像素间灰度变化较小时,这种方…...
axios 或 fetch 如何实现对发出的请求的终止?
终止 HTTP 请求是一个重要的功能,特别是在需要优化性能、避免不必要的请求或在某些事件发生时(例如用户点击取消)中断正在进行的请求时。以下是如何使用 axios 和 fetch 实现请求终止的方法: 1. axios axios 使用了 CancelToken…...
ChatGPT Prompting开发实战(四)
一、chaining prompts应用解析及输出文本的设定 由于输入和输出都是字符串形式的自然语言,为了方便输入和输出信息与系统设定使用的JSON格式之间进行转换,接下来定义从输入字符串转为JSON list的方法: 定义从JSON list转为输出字符串的方法&…...
Windows和Linux环境中安装Zookeeper具体操作
1.Windows环境中安装Zookeeper 1.1 下载Zookeeper安装包 ZooKeeper官网下载地址 建议下载稳定版本的 下载后进行解压后得到如下文件: 1.2 修改本地配置文件 进入解压后的目录,将zoo_example.cfg复制一份并重命名为zoo.cfg,如图所示: 打…...
41、Flink之Hive 方言介绍及详细示例
Flink 系列文章 1、Flink 部署、概念介绍、source、transformation、sink使用示例、四大基石介绍和示例等系列综合文章链接 13、Flink 的table api与sql的基本概念、通用api介绍及入门示例 14、Flink 的table api与sql之数据类型: 内置数据类型以及它们的属性 15、Flink 的ta…...
synchronized 学习
学习源: https://www.bilibili.com/video/BV1aJ411V763?spm_id_from333.788.videopod.episodes&vd_source32e1c41a9370911ab06d12fbc36c4ebc 1.应用场景 不超卖,也要考虑性能问题(场景) 2.常见面试问题: sync出…...
Linux 文件类型,目录与路径,文件与目录管理
文件类型 后面的字符表示文件类型标志 普通文件:-(纯文本文件,二进制文件,数据格式文件) 如文本文件、图片、程序文件等。 目录文件:d(directory) 用来存放其他文件或子目录。 设备…...
脑机新手指南(八):OpenBCI_GUI:从环境搭建到数据可视化(下)
一、数据处理与分析实战 (一)实时滤波与参数调整 基础滤波操作 60Hz 工频滤波:勾选界面右侧 “60Hz” 复选框,可有效抑制电网干扰(适用于北美地区,欧洲用户可调整为 50Hz)。 平滑处理&…...
Day131 | 灵神 | 回溯算法 | 子集型 子集
Day131 | 灵神 | 回溯算法 | 子集型 子集 78.子集 78. 子集 - 力扣(LeetCode) 思路: 笔者写过很多次这道题了,不想写题解了,大家看灵神讲解吧 回溯算法套路①子集型回溯【基础算法精讲 14】_哔哩哔哩_bilibili 完…...
微信小程序 - 手机震动
一、界面 <button type"primary" bindtap"shortVibrate">短震动</button> <button type"primary" bindtap"longVibrate">长震动</button> 二、js逻辑代码 注:文档 https://developers.weixin.qq…...
相机从app启动流程
一、流程框架图 二、具体流程分析 1、得到cameralist和对应的静态信息 目录如下: 重点代码分析: 启动相机前,先要通过getCameraIdList获取camera的个数以及id,然后可以通过getCameraCharacteristics获取对应id camera的capabilities(静态信息)进行一些openCamera前的…...
【Go语言基础【13】】函数、闭包、方法
文章目录 零、概述一、函数基础1、函数基础概念2、参数传递机制3、返回值特性3.1. 多返回值3.2. 命名返回值3.3. 错误处理 二、函数类型与高阶函数1. 函数类型定义2. 高阶函数(函数作为参数、返回值) 三、匿名函数与闭包1. 匿名函数(Lambda函…...
【MATLAB代码】基于最大相关熵准则(MCC)的三维鲁棒卡尔曼滤波算法(MCC-KF),附源代码|订阅专栏后可直接查看
文章所述的代码实现了基于最大相关熵准则(MCC)的三维鲁棒卡尔曼滤波算法(MCC-KF),针对传感器观测数据中存在的脉冲型异常噪声问题,通过非线性加权机制提升滤波器的抗干扰能力。代码通过对比传统KF与MCC-KF在含异常值场景下的表现,验证了后者在状态估计鲁棒性方面的显著优…...
NPOI操作EXCEL文件 ——CAD C# 二次开发
缺点:dll.版本容易加载错误。CAD加载插件时,没有加载所有类库。插件运行过程中用到某个类库,会从CAD的安装目录找,找不到就报错了。 【方案2】让CAD在加载过程中把类库加载到内存 【方案3】是发现缺少了哪个库,就用插件程序加载进…...
aardio 自动识别验证码输入
技术尝试 上周在发学习日志时有网友提议“在网页上识别验证码”,于是尝试整合图像识别与网页自动化技术,完成了这套模拟登录流程。核心思路是:截图验证码→OCR识别→自动填充表单→提交并验证结果。 代码在这里 import soImage; import we…...
