Merge "Refactor RouterAdvertisementDaemon to build new RA in HandlerThread" into main

This commit is contained in:
KH Shi 2023-11-23 05:51:04 +00:00 • committed by Gerrit Code Review
commit 29f70feb01

View file

@ -47,8 +47,10 @@ import android.system.ErrnoException;
import android.system.Os;
import android.system.StructTimeval;
import android.util.Log;
import android.util.Pair;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.internal.annotations.GuardedBy;
import com.android.net.module.util.FdEventsReader;
@ -112,8 +114,9 @@ public class RouterAdvertisementDaemon {
private static final int DAY_IN_SECONDS = 86_400;
// Commands for IpServer to control RouterAdvertisementDaemon
private static final int CMD_START = 1;
private static final int CMD_STOP = 2;
private static final int CMD_START = 1;
private static final int CMD_STOP = 2;
private static final int CMD_BUILD_NEW_RA = 3;
private final InterfaceParams mInterface;
private final InetSocketAddress mAllNodes;
@ -278,6 +281,26 @@ public class RouterAdvertisementDaemon {
mRsPacketListener = null;
}
break;
case CMD_BUILD_NEW_RA:
synchronized (mLock) {
// raInfo.first is deprecatedParams and raInfo.second is newParams.
final Pair<RaParams, RaParams> raInfo = (Pair<RaParams, RaParams>) msg.obj;
if (raInfo.first != null) {
mDeprecatedInfoTracker.putPrefixes(raInfo.first.prefixes);
mDeprecatedInfoTracker.putDnses(raInfo.first.dnses);
}
if (raInfo.second != null) {
// Process information that is no longer deprecated.
mDeprecatedInfoTracker.removePrefixes(raInfo.second.prefixes);
mDeprecatedInfoTracker.removeDnses(raInfo.second.dnses);
}
mRaParams = raInfo.second;
assembleRaLocked();
}
maybeNotifyMulticastTransmitter();
break;
default:
Log.e(TAG, "Unknown message, cmd = " + String.valueOf(msg.what));
break;
@ -336,23 +359,8 @@ public class RouterAdvertisementDaemon {
/** Build new RA.*/
public void buildNewRa(RaParams deprecatedParams, RaParams newParams) {
synchronized (mLock) {
if (deprecatedParams != null) {
mDeprecatedInfoTracker.putPrefixes(deprecatedParams.prefixes);
mDeprecatedInfoTracker.putDnses(deprecatedParams.dnses);
}
if (newParams != null) {
// Process information that is no longer deprecated.
mDeprecatedInfoTracker.removePrefixes(newParams.prefixes);
mDeprecatedInfoTracker.removeDnses(newParams.dnses);
}
mRaParams = newParams;
assembleRaLocked();
}
maybeNotifyMulticastTransmitter();
final Pair<RaParams, RaParams> raInfo = new Pair<>(deprecatedParams, newParams);
sendMessage(CMD_BUILD_NEW_RA, raInfo);
}
/** Start router advertisement daemon. */
@ -660,11 +668,16 @@ public class RouterAdvertisementDaemon {
}
private boolean sendMessage(int cmd) {
return sendMessage(cmd, null);
}
private boolean sendMessage(int cmd, @Nullable Object obj) {
if (mRaMessageHandler == null) {
return false;
}
return mRaMessageHandler.sendMessage(Message.obtain(mRaMessageHandler, cmd));
return mRaMessageHandler.sendMessage(
Message.obtain(mRaMessageHandler, cmd, obj));
}
// TODO: Consider moving this to run on a provided Looper as a Handler,