2.4.2 systemReady函数详解
最后更新于:2022-04-02 06:01:51
systemReady函数详解如下所示。
**NetworkManagementService.java::systemReady**
~~~
public void systemReady() {
prepareNativeDaemon();
}
~~~
prepareNativeDaemon用于将系统中一些与带宽控制、防火墙相关的规则发送给Netd去执行,其代码如下所示。
**NetworkManagementService.java::prepareNativeDaemon**
~~~
private void prepareNativeDaemon() {
mBandwidthControlEnabled = false;
// 判断kernel是否支持bandwidthcontrol
final boolean hasKernelSupport = new File("/proc/net/xt_qtaguid/ctrl").exists();
if (hasKernelSupport) {
try {
mConnector.execute("bandwidth", "enable");// 使能bandwidth功能
mBandwidthControlEnabled = true;
} catch .......
}
// 设置Android系统属性"net.qtaguid_enabled"
SystemProperties.set(PROP_QTAGUID_ENABLED, mBandwidthControlEnabled ? "1" : "0");
// 设置Bandwidth规则
synchronized (mQuotaLock) {
int size = mActiveQuotas.size();
if (size > 0) {
// mActiveQuotas保存了每个interface的配额设置
final HashMap activeQuotas = mActiveQuotas;
mActiveQuotas = Maps.newHashMap();
for (Map.Entry entry : activeQuotas.entrySet())
setInterfaceQuota(entry.getKey(), entry.getValue());
}
......// 其他规则
}
// 设置防火墙规则
setFirewallEnabled(mFirewallEnabled || LockdownVpnTracker.isEnabled());
}
~~~
以setFireWallEnabled函数为例,它和Netd交互的方法如下。
**NetworkManagementService.java::setFirewallEnabled**
~~~
public void setFirewallEnabled(boolean enabled) {
enforceSystemUid();
try {// 发送firewall相关的Command给Netd
mConnector.execute("firewall", enabled ? "enable" : "disable");
mFirewallEnabled = enabled;
}catch ......
}
~~~
systemReady函数非常简单,本章就不详述了。
';