Android13 有线变更
以太网相关的功能在Android12 和13 网络部分变化是不大的,Android11 到Android 12 网络部分无论是代码存放目录和代码逻辑都是有较多修改的,主要包括以下几个部分
-
限制了设置有线网参数设置接口方法
-
新增有线网开启关闭接口方法
-
新增了 updateConfiguration 接口方法
-
有线网设置的静态ip和代理信息重启后无效
-
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 setEthernetEnab