[Thread] use immutable BorderRouterConfiguration
This CL refactors the code of ThreadNetworkControllerService to use immutable BorderRouterConfiguration. Bug: 358012289 Test: CI Change-Id: Ifabf0144d5e8f5b5da2b8d64fc9e53c46f917dbb
This commit is contained in:
parent
f6c565dfb8
commit
ed24de9b64
1 changed files with 47 additions and 22 deletions
|
|
@ -238,7 +238,11 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub
|
|||
mInfraIfController = infraIfController;
|
||||
mUpstreamNetworkRequest = newUpstreamNetworkRequest();
|
||||
mNetworkToInterface = new HashMap<Network, String>();
|
||||
mBorderRouterConfig = new BorderRouterConfiguration();
|
||||
mBorderRouterConfig =
|
||||
new BorderRouterConfiguration.Builder()
|
||||
.setIsBorderRoutingEnabled(true)
|
||||
.setInfraInterfaceName(null)
|
||||
.build();
|
||||
mPersistentSettings = persistentSettings;
|
||||
mNsdPublisher = nsdPublisher;
|
||||
mUserManager = userManager;
|
||||
|
|
@ -1228,40 +1232,54 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub
|
|||
}
|
||||
}
|
||||
|
||||
private void enableBorderRouting(String infraIfName) {
|
||||
if (mBorderRouterConfig.isBorderRoutingEnabled
|
||||
&& infraIfName.equals(mBorderRouterConfig.infraInterfaceName)) {
|
||||
private void configureBorderRouter(BorderRouterConfiguration borderRouterConfig) {
|
||||
if (mBorderRouterConfig.equals(borderRouterConfig)) {
|
||||
return;
|
||||
}
|
||||
Log.i(TAG, "Enable border routing on AIL: " + infraIfName);
|
||||
Log.i(
|
||||
TAG,
|
||||
"Configuring Border Router: " + mBorderRouterConfig + " -> " + borderRouterConfig);
|
||||
mBorderRouterConfig = borderRouterConfig;
|
||||
ParcelFileDescriptor infraIcmp6Socket = null;
|
||||
if (mBorderRouterConfig.infraInterfaceName != null) {
|
||||
try {
|
||||
infraIcmp6Socket =
|
||||
mInfraIfController.createIcmp6Socket(
|
||||
mBorderRouterConfig.infraInterfaceName);
|
||||
} catch (IOException e) {
|
||||
Log.i(TAG, "Failed to create ICMPv6 socket on infra network interface", e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
mBorderRouterConfig.infraInterfaceName = infraIfName;
|
||||
mBorderRouterConfig.isBorderRoutingEnabled = true;
|
||||
ParcelFileDescriptor infraIcmp6Socket =
|
||||
mInfraIfController.createIcmp6Socket(infraIfName);
|
||||
getOtDaemon()
|
||||
.configureBorderRouter(
|
||||
mBorderRouterConfig,
|
||||
infraIcmp6Socket,
|
||||
new ConfigureBorderRouterStatusReceiver());
|
||||
} catch (RemoteException | IOException | ThreadNetworkException e) {
|
||||
Log.w(TAG, "Failed to enable border routing", e);
|
||||
} catch (RemoteException | ThreadNetworkException e) {
|
||||
Log.w(TAG, "Failed to configure border router " + mBorderRouterConfig, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void enableBorderRouting(String infraIfName) {
|
||||
BorderRouterConfiguration borderRouterConfig =
|
||||
newBorderRouterConfigBuilder(mBorderRouterConfig)
|
||||
.setIsBorderRoutingEnabled(true)
|
||||
.setInfraInterfaceName(infraIfName)
|
||||
.build();
|
||||
Log.i(TAG, "Enable border routing on AIL: " + infraIfName);
|
||||
configureBorderRouter(borderRouterConfig);
|
||||
}
|
||||
|
||||
private void disableBorderRouting() {
|
||||
mUpstreamNetwork = null;
|
||||
mBorderRouterConfig.infraInterfaceName = null;
|
||||
mBorderRouterConfig.isBorderRoutingEnabled = false;
|
||||
try {
|
||||
getOtDaemon()
|
||||
.configureBorderRouter(
|
||||
mBorderRouterConfig,
|
||||
null /* infraIcmp6Socket */,
|
||||
new ConfigureBorderRouterStatusReceiver());
|
||||
} catch (RemoteException | ThreadNetworkException e) {
|
||||
Log.w(TAG, "Failed to disable border routing", e);
|
||||
}
|
||||
BorderRouterConfiguration borderRouterConfig =
|
||||
newBorderRouterConfigBuilder(mBorderRouterConfig)
|
||||
.setIsBorderRoutingEnabled(false)
|
||||
.setInfraInterfaceName(null)
|
||||
.build();
|
||||
Log.i(TAG, "Disabling border routing");
|
||||
configureBorderRouter(borderRouterConfig);
|
||||
}
|
||||
|
||||
private void handleThreadInterfaceStateChanged(boolean isUp) {
|
||||
|
|
@ -1362,6 +1380,13 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub
|
|||
return builder.build();
|
||||
}
|
||||
|
||||
private static BorderRouterConfiguration.Builder newBorderRouterConfigBuilder(
|
||||
BorderRouterConfiguration brConfig) {
|
||||
return new BorderRouterConfiguration.Builder()
|
||||
.setIsBorderRoutingEnabled(brConfig.isBorderRoutingEnabled)
|
||||
.setInfraInterfaceName(brConfig.infraInterfaceName);
|
||||
}
|
||||
|
||||
private static final class CallbackMetadata {
|
||||
private static long gId = 0;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue