Android 13 Ethernet变更

这篇具有很好参考价值的文章主要介绍了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

    @Override
    public 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.java

    private 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

    @VisibleForTesting
    void 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/ethernet
                final 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,需要创建对应的静态staticIpConfiguration
 build.setStaticIpConfiguration(staticIpConfiguration);
   requestBuilder.setIpConfiguration(build.build());
        mEthManager.updateConfiguration("eth0", requestBuilder.build(), null, null);

以上为Android13 以太网相关的更新

单曲循环《大悲咒》文章来源地址https://www.toymoban.com/news/detail-782722.html

到了这里,关于Android 13 Ethernet变更的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Android的WIFI和以太网连接状态

    在一些 Android 设备上同时具有以太网和Wifi网络连接 我们可以使用 ConnectivityManager 类来判断设备的网络状态。以下是一个 Kotlin 示例,说明了如何检查网络连接状态以及连接类型(例如 Wi-Fi 或移动数据):

    2024年02月16日
    浏览(45)
  • rk3399 android以太网和wifi共存

    1.修改 frameworks/base/core/java/android/net/NetworkFactory.java evalRequest 方法 注释两行 2.修改frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetNetworkFactory.java文件修改 NETWORK_SCORE=30  降低优先级 这样以太网和wifi都能连接成功 frameworksoptnetethernetjavacomandroidserverethernetEthernetNetwork

    2024年02月09日
    浏览(36)
  • Android 11.0 以太网设置默认静态ip地址

    在11.0的系统rom开发过程中,在进行以太网产品开发的过程中,有功能要求设置默认静态ip地址的功能,不使用动态ip, 方便ip地址管理所以就需要熟悉以太网的ip设置流程,然后设置对应的ip地址就可以了

    2024年02月16日
    浏览(33)
  • 10Mbps以太网Ethernet的几种形式分别介绍

    1、10Base-5 (1)以太网的最初形式,数字信号采用曼彻斯特编码; (2)传输介质为直径10mm的粗同轴电缆; (3)电缆最大长度为500m。 2、10Base-2 (1)采用阻抗为50Ω的基带细同轴电缆为传输介质。 (2)数字信号采用曼彻斯特编码。 (3)不使用中继器时电缆的最大长度为18

    2024年02月05日
    浏览(47)
  • Android P 9.0 增加以太网静态IP功能

    1、vendormediatekproprietarypackagesappsMtkSettingsresxmlnetwork_and_internet.xml 在 mobile_network_settings 和 tether_settings 之间增加如上代码, 对应的 icon 资源文件是我从 SystemUI 中拷贝过来的,稍微调整了下大小,也贴给你们吧 2、vendormediatekproprietarypackagesappsMtkSettingsresdrawableic_ethern

    2024年02月22日
    浏览(41)
  • 触摸屏与PLC之间 EtherNet/IP无线以太网通信

    在实际系统中,同一个车间里分布多台PLC,用触摸屏集中控制。通常所有设备距离在几十米到上百米不等。在有通讯需求的时候,如果布线的话,工程量较大耽误工期,这种情况下比较适合采用无线通信方式。 本方案以MCGS触摸屏和2台三菱FX5u PLC为例,介绍触摸屏与多台 PLC的

    2024年02月11日
    浏览(36)
  • 【网络技术】【Kali Linux】Wireshark嗅探(十一)以太网Ethernet协议报文捕获及分析

    往期 Kali Linux 上的 Wireshark 嗅探实验见博客: 【网络技术】【Kali Linux】Wireshark嗅探(一)ping 和 ICMP 【网络技术】【Kali Linux】Wireshark嗅探(二)TCP 协议 【网络技术】【Kali Linux】Wireshark嗅探(三)用户数据报(UDP)协议 【网络技术】【Kali Linux】Wireshark嗅探(四)域名系统(

    2024年04月27日
    浏览(31)
  • 欧姆龙NJ/NX系列PLC 基于以太网的CIP通讯(EtherNet/IP)

    CIP (Common Industrial Protocol, 通用工业协议) 是由 ODVA组织提出并维护的具有增强服务的自动化通讯协议。是一种使用生产者-消费者通信模型的与媒体无关的协议,并且是上层的严格面向对象的协议。每个CIP对象都有属性(数据)、服务(命令)、连接和行为(属性值和服务之间

    2024年01月22日
    浏览(60)
  • Chapter 7 - 15. Congestion Management in Ethernet Storage Networks以太网存储网络的拥塞管理

    Congestion Notification in Routed Lossless Ethernet Networks End devices and their applications may not be aware of congestion in the network. A culprit device may continue to send (or solicit) more traffic on the network making the severity of congestion worse or increasing its duration. To solve this problem, the network switches can ‘explicitly’ notif

    2024年01月22日
    浏览(43)
  • Chapter 7 - 14. Congestion Management in Ethernet Storage Networks以太网存储网络的拥塞管理

    PFC Watchdog PFC watchdog works similarly to Pause timeout, but it only drops the traffic in the queue that is unable to transmit continuously for a timeout duration because of receiving PFC Pause frames. PFC 进程看门狗的工作原理与暂停超时类似,但它只会丢弃队列中因收到 PFC 暂停帧而无法在超时时间内连续传输的流量。

    2024年01月22日
    浏览(38)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包