Android15 Framework自定义服务调用package/modules下的EthernetManager接口

一、环境配置

软件系统: Android 15
设备平台:RK3576

二、背景说明

实际项目开发中,往往需要定制Framework 服务,例如突破系统API限制为,APP提供可直接调用协调级API(例如:获取和配置网络端口)
Android13 Framework自定义服务调用package/modules一文中我们实现framework调用EthernetManager接口,但在Android15上,这一情况又有所不同:
在Framework/base下自定义服务中调用mEthernetManager.getConfiguration()会报错:

frameworks/base/services/core/java/com/android/server/xxx/CustomerManagerService.java:548: error: cannot find symbol
        mEthernetService.setConfiguration(iface, ipConfiguration);
                        ^
  symbol:   method setConfiguration(String,IpConfiguration)
  location: variable mEthernetService of type EthernetManager

对比Android13与Android15此接口代码:

    //////Android13
    /**
     * Get Ethernet configuration.
     * @return the Ethernet Configuration, contained in {@link IpConfiguration}.
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
    @SystemApi(client = MODULE_LIBRARIES)
    @NonNull
    public IpConfiguration getConfiguration(@NonNull String iface) {
        try {
            return mService.getConfiguration(iface);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /////Android15
    /**
     * Get Ethernet configuration.
     * @return the Ethernet Configuration, contained in {@link IpConfiguration}.
     * @hide
     */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public IpConfiguration getConfiguration(String iface) {
        try {
            return mService.getConfiguration(iface);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

对比可知代码没变,编译规则变了,Android 15 的 build 系统把“@hide 接口”默认屏蔽掉了

三、代码修改

对需要的接口修改注解,如下:
packages/modules/Connectivity/framework-t/src/android/net/EthernetManager.java

    /**
     * Get Ethernet configuration.
     * @return the Ethernet Configuration, contained in {@link IpConfiguration}.
     * @hide
     */
-   @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
+   @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
+   @SystemApi(client = MODULE_LIBRARIES)
+   @NonNull
    public IpConfiguration getConfiguration(String iface) {
        try {
            return mService.getConfiguration(iface);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值