当前位置: 首页 > 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…...

css实现圆环展示百分比,根据值动态展示所占比例

代码如下 <view class""><view class"circle-chart"><view v-if"!!num" class"pie-item" :style"{background: conic-gradient(var(--one-color) 0%,#E9E6F1 ${num}%),}"></view><view v-else …...

练习(含atoi的模拟实现,自定义类型等练习)

一、结构体大小的计算及位段 &#xff08;结构体大小计算及位段 详解请看&#xff1a;自定义类型&#xff1a;结构体进阶-CSDN博客&#xff09; 1.在32位系统环境&#xff0c;编译选项为4字节对齐&#xff0c;那么sizeof(A)和sizeof(B)是多少&#xff1f; #pragma pack(4)st…...

线程同步:确保多线程程序的安全与高效!

全文目录&#xff1a; 开篇语前序前言第一部分&#xff1a;线程同步的概念与问题1.1 线程同步的概念1.2 线程同步的问题1.3 线程同步的解决方案 第二部分&#xff1a;synchronized关键字的使用2.1 使用 synchronized修饰方法2.2 使用 synchronized修饰代码块 第三部分&#xff…...

Qt Widget类解析与代码注释

#include "widget.h" #include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget) {ui->setupUi(this); }Widget::~Widget() {delete ui; }//解释这串代码&#xff0c;写上注释 当然可以&#xff01;这段代码是 Qt …...

CMake基础:构建流程详解

目录 1.CMake构建过程的基本流程 2.CMake构建的具体步骤 2.1.创建构建目录 2.2.使用 CMake 生成构建文件 2.3.编译和构建 2.4.清理构建文件 2.5.重新配置和构建 3.跨平台构建示例 4.工具链与交叉编译 5.CMake构建后的项目结构解析 5.1.CMake构建后的目录结构 5.2.构…...

华为OD机试-食堂供餐-二分法

import java.util.Arrays; import java.util.Scanner;public class DemoTest3 {public static void main(String[] args) {Scanner in new Scanner(System.in);// 注意 hasNext 和 hasNextLine 的区别while (in.hasNextLine()) { // 注意 while 处理多个 caseint a in.nextIn…...

ios苹果系统,js 滑动屏幕、锚定无效

现象&#xff1a;window.addEventListener监听touch无效&#xff0c;划不动屏幕&#xff0c;但是代码逻辑都有执行到。 scrollIntoView也无效。 原因&#xff1a;这是因为 iOS 的触摸事件处理机制和 touch-action: none 的设置有关。ios有太多得交互动作&#xff0c;从而会影响…...

安宝特案例丨Vuzix AR智能眼镜集成专业软件,助力卢森堡医院药房转型,赢得辉瑞创新奖

在Vuzix M400 AR智能眼镜的助力下&#xff0c;卢森堡罗伯特舒曼医院&#xff08;the Robert Schuman Hospitals, HRS&#xff09;凭借在无菌制剂生产流程中引入增强现实技术&#xff08;AR&#xff09;创新项目&#xff0c;荣获了2024年6月7日由卢森堡医院药剂师协会&#xff0…...

【SSH疑难排查】轻松解决新版OpenSSH连接旧服务器的“no matching...“系列算法协商失败问题

【SSH疑难排查】轻松解决新版OpenSSH连接旧服务器的"no matching..."系列算法协商失败问题 摘要&#xff1a; 近期&#xff0c;在使用较新版本的OpenSSH客户端连接老旧SSH服务器时&#xff0c;会遇到 "no matching key exchange method found"​, "n…...

C语言中提供的第三方库之哈希表实现

一. 简介 前面一篇文章简单学习了C语言中第三方库&#xff08;uthash库&#xff09;提供对哈希表的操作&#xff0c;文章如下&#xff1a; C语言中提供的第三方库uthash常用接口-CSDN博客 本文简单学习一下第三方库 uthash库对哈希表的操作。 二. uthash库哈希表操作示例 u…...