当前位置: 首页 > news >正文

Android 13 Ethernet变更

Android13 有线变更

以太网相关的功能在Android12 和13 网络部分变化是不大的,Android11 到Android 12 网络部分无论是代码存放目录和代码逻辑都是有较多修改的,主要包括以下几个部分

  1. 限制了设置有线网参数设置接口方法

  2. 新增有线网开启关闭接口方法

  3. 新增了 updateConfiguration 接口方法

  4. 有线网设置的静态ip和代理信息重启后无效

  5. 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 网络部分变化是不大的&#xff0c;Android11 到Android 12 网络部分无论是代码存放目录和代码逻辑都是有较多修改的&#xff0c;主要包括以下几个部分 限制了设置有线网参数设置接口方法 新增有线网开启关闭接口方法 新…...

基于单片机的超声波语音测距系统

一、系统方案 超声波具有指向性强&#xff0c;能量消耗缓慢&#xff0c;在介质中传播的距离较远&#xff0c;因而超声波经常用于距离的测量&#xff0c;如测距仪和物位测量仪等都可以通过超声波来实现。利用超声波检测往往比较迅速、方便、计算简单、易于做到实时控制&#xff…...

算法系列-力扣876-求链表的中间节点

# 求链表中间节点&#xff0c;如果有两个中间节点取后面那个 链表定义 // 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的联合使用&#xff0c;实现两个线程的数据传递 #include <iostream> #include<thread> #include<future>using namespace std;//promise用法&#xff1a;可以给线程一个值&#xff0c;而从另一个线程读出该值 // 实现了两个线程的数…...

【dart】dart基础学习使用(一):变量、操作符、注释和库操作

前言 学习dart语言。 注释 Dart 支持单行注释、多行注释和文档注释。 单行注释 单行注释以 // 开头。Dart 编译器将忽略从 // 到行尾之间的所有内容。 void main() {// 这是单行注释print(Welcome to my Llama farm!); }多行注释 多行注释以 /* 开始&#xff0c;以 / 结…...

element-plus 设置 el-date-picker 弹出框位置

前言 概述&#xff1a;el-date-picker 组件会自动根据空间范围进行选择比较好的弹出位置&#xff0c;但特定情况下&#xff0c;它自动计算出的弹出位置并不符合我们的实际需求&#xff0c;故需要我们手动设置。 存在的问题&#xff1a;element-plus 中 el-date-picker 文档中并…...

C++day7(auto关键字、lambda表达式、C++中的数据类型转换、C++标准模板库(STL)、list、文件操作)

一、Xmind整理&#xff1a; 关键词总结&#xff1a; 二、上课笔记整理&#xff1a; 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() {//定义一个函数指针&#xff0c;指向fu…...

纽扣电池/锂电池UN38.3安全检测报告

根据规章要求&#xff0c;航空公司和机场货物收运部门应对锂电池进行运输文件审查&#xff0c;重要的是每种型号的锂电池UN38.3安全检测报告。该报告可由的三方检测机构。如不能提供此项检测报告&#xff0c;将禁止锂电池进行航空运输. UN38.3包含产品&#xff1a;1、 锂电池2…...

K8S:K8S自动化运维容器Docker集群

文章目录 一.k8s概述1.k8s是什么2.为什么要用K8S3.作用及功能4.k8s容器集群管理系统 二.K8S的特性1.弹性伸缩2.自我修复3.服务发现和复制均衡4.自动发布和回滚5.集中化配置管理和秘钥管理6.存储编排7.任务批量处理运行 三.K8S的集群架构四.K8S的核心组件1.Master组件&#xff0…...

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常见问题汇总

来源&#xff1a;https://www.fly63.com/ Q1&#xff1a;安装超时(install timeout) 方案有这么些: cnpm : 国内对npm的镜像版本/*cnpm website: https://npm.taobao.org/*/npm install -g cnpm --registryhttps://registry.npm.taobao.org// cnpm 的大多命令跟 npm 的是一致的…...

GPT-3在化学中进行低数据发现是否足够?

今天介绍一份洛桑联邦理工学院进行的工作&#xff0c;这份工作被发表在化学期刊预印本网站上。 对于这份工作&#xff0c;有兴趣的朋友可以通过我们的国内ChatGPT镜像站进行测试使用&#xff0c;我们的站点并没有针对特定任务进行建设&#xff0c;是通用性质的。 化学领域进行…...

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图像处理-灰度插值法

最近邻法 最近邻法是一种最简单的插值算法&#xff0c;输出像素的值为输入图像中与其最邻近的采样点的像素值。是将(u0,v0)(u_0,v_0)点最近的整数坐标u,v(u,v)点的灰度值取为(u0,v0)(u_0,v_0)点的灰度值。 在(u0,v0)(u_0,v_0)点各相邻像素间灰度变化较小时&#xff0c;这种方…...

axios 或 fetch 如何实现对发出的请求的终止?

终止 HTTP 请求是一个重要的功能&#xff0c;特别是在需要优化性能、避免不必要的请求或在某些事件发生时&#xff08;例如用户点击取消&#xff09;中断正在进行的请求时。以下是如何使用 axios 和 fetch 实现请求终止的方法&#xff1a; 1. axios axios 使用了 CancelToken…...

ChatGPT Prompting开发实战(四)

一、chaining prompts应用解析及输出文本的设定 由于输入和输出都是字符串形式的自然语言&#xff0c;为了方便输入和输出信息与系统设定使用的JSON格式之间进行转换&#xff0c;接下来定义从输入字符串转为JSON list的方法&#xff1a; 定义从JSON list转为输出字符串的方法&…...

Windows和Linux环境中安装Zookeeper具体操作

1.Windows环境中安装Zookeeper 1.1 下载Zookeeper安装包 ZooKeeper官网下载地址 建议下载稳定版本的 下载后进行解压后得到如下文件&#xff1a; 1.2 修改本地配置文件 进入解压后的目录&#xff0c;将zoo_example.cfg复制一份并重命名为zoo.cfg,如图所示&#xff1a; 打…...

41、Flink之Hive 方言介绍及详细示例

Flink 系列文章 1、Flink 部署、概念介绍、source、transformation、sink使用示例、四大基石介绍和示例等系列综合文章链接 13、Flink 的table api与sql的基本概念、通用api介绍及入门示例 14、Flink 的table api与sql之数据类型: 内置数据类型以及它们的属性 15、Flink 的ta…...

Objective-C常用命名规范总结

【OC】常用命名规范总结 文章目录 【OC】常用命名规范总结1.类名&#xff08;Class Name)2.协议名&#xff08;Protocol Name)3.方法名&#xff08;Method Name)4.属性名&#xff08;Property Name&#xff09;5.局部变量/实例变量&#xff08;Local / Instance Variables&…...

微信小程序 - 手机震动

一、界面 <button type"primary" bindtap"shortVibrate">短震动</button> <button type"primary" bindtap"longVibrate">长震动</button> 二、js逻辑代码 注&#xff1a;文档 https://developers.weixin.qq…...

【RockeMQ】第2节|RocketMQ快速实战以及核⼼概念详解(二)

升级Dledger高可用集群 一、主从架构的不足与Dledger的定位 主从架构缺陷 数据备份依赖Slave节点&#xff0c;但无自动故障转移能力&#xff0c;Master宕机后需人工切换&#xff0c;期间消息可能无法读取。Slave仅存储数据&#xff0c;无法主动升级为Master响应请求&#xff…...

Springboot社区养老保险系统小程序

一、前言 随着我国经济迅速发展&#xff0c;人们对手机的需求越来越大&#xff0c;各种手机软件也都在被广泛应用&#xff0c;但是对于手机进行数据信息管理&#xff0c;对于手机的各种软件也是备受用户的喜爱&#xff0c;社区养老保险系统小程序被用户普遍使用&#xff0c;为方…...

基于 TAPD 进行项目管理

起因 自己写了个小工具&#xff0c;仓库用的Github。之前在用markdown进行需求管理&#xff0c;现在随着功能的增加&#xff0c;感觉有点难以管理了&#xff0c;所以用TAPD这个工具进行需求、Bug管理。 操作流程 注册 TAPD&#xff0c;需要提供一个企业名新建一个项目&#…...

Razor编程中@Html的方法使用大全

文章目录 1. 基础HTML辅助方法1.1 Html.ActionLink()1.2 Html.RouteLink()1.3 Html.Display() / Html.DisplayFor()1.4 Html.Editor() / Html.EditorFor()1.5 Html.Label() / Html.LabelFor()1.6 Html.TextBox() / Html.TextBoxFor() 2. 表单相关辅助方法2.1 Html.BeginForm() …...

【LeetCode】3309. 连接二进制表示可形成的最大数值(递归|回溯|位运算)

LeetCode 3309. 连接二进制表示可形成的最大数值&#xff08;中等&#xff09; 题目描述解题思路Java代码 题目描述 题目链接&#xff1a;LeetCode 3309. 连接二进制表示可形成的最大数值&#xff08;中等&#xff09; 给你一个长度为 3 的整数数组 nums。 现以某种顺序 连接…...

脑机新手指南(七):OpenBCI_GUI:从环境搭建到数据可视化(上)

一、OpenBCI_GUI 项目概述 &#xff08;一&#xff09;项目背景与目标 OpenBCI 是一个开源的脑电信号采集硬件平台&#xff0c;其配套的 OpenBCI_GUI 则是专为该硬件设计的图形化界面工具。对于研究人员、开发者和学生而言&#xff0c;首次接触 OpenBCI 设备时&#xff0c;往…...

android RelativeLayout布局

<?xml version"1.0" encoding"utf-8"?> <RelativeLayout xmlns:android"http://schemas.android.com/apk/res/android"android:layout_width"match_parent"android:layout_height"match_parent"android:gravity&…...

LangFlow技术架构分析

&#x1f527; LangFlow 的可视化技术栈 前端节点编辑器 底层框架&#xff1a;基于 &#xff08;一个现代化的 React 节点绘图库&#xff09; 功能&#xff1a; 拖拽式构建 LangGraph 状态机 实时连线定义节点依赖关系 可视化调试循环和分支逻辑 与 LangGraph 的深…...