Refactor RouterAdvertisementDaemon to build new RA in HandlerThread
HandlerThread was introduced in aosp/2493357. This patch moves the
code originally located in buildNewRa() into the HandlerThread.
Bug: 246928127
Test: atest TetheringPrivilegedTests TetheringIntegrationTests \
TetheringTests
Change-Id: I5f6df0a3a79d7f4a865cfec7f88bc28816b1db95
This commit is contained in:
parent
bdcd7db9d8
commit
23a2158c38
1 changed files with 33 additions and 20 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue