一、环境配置
软件系统: 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();
}
}
556

被折叠的 条评论
为什么被折叠?



