Merge "[Thread] resolve open comments for aosp/2737373" into main
This commit is contained in:
commit
b46d21a898
3 changed files with 22 additions and 11 deletions
|
|
@ -223,6 +223,7 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub
|
|||
return mOtDaemon;
|
||||
}
|
||||
|
||||
// TODO(b/309792480): restarts the OT daemon service
|
||||
private void onOtDaemonDied() {
|
||||
Log.w(TAG, "OT daemon became dead, clean up...");
|
||||
OperationReceiverWrapper.onOtDaemonDied();
|
||||
|
|
@ -566,9 +567,15 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub
|
|||
private void handleDeviceRoleChanged(@DeviceRole int deviceRole) {
|
||||
if (ThreadNetworkController.isAttached(deviceRole)) {
|
||||
Log.d(TAG, "Attached to the Thread network");
|
||||
|
||||
// This is an idempotent method which can be called for multiple times when the device
|
||||
// is already attached (e.g. going from Child to Router)
|
||||
registerThreadNetwork();
|
||||
} else {
|
||||
Log.d(TAG, "Detached from the Thread network");
|
||||
|
||||
// This is an idempotent method which can be called for multiple times when the device
|
||||
// is already detached or stopped
|
||||
unregisterThreadNetwork();
|
||||
}
|
||||
}
|
||||
|
|
@ -625,7 +632,7 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub
|
|||
public void registerStateCallback(IStateCallback callback) {
|
||||
checkOnHandlerThread();
|
||||
if (mStateCallbacks.containsKey(callback)) {
|
||||
return;
|
||||
throw new IllegalStateException("Registering the same IStateCallback twice");
|
||||
}
|
||||
|
||||
IBinder.DeathRecipient deathRecipient =
|
||||
|
|
@ -657,7 +664,8 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub
|
|||
public void registerDatasetCallback(IOperationalDatasetCallback callback) {
|
||||
checkOnHandlerThread();
|
||||
if (mOpDatasetCallbacks.containsKey(callback)) {
|
||||
return;
|
||||
throw new IllegalStateException(
|
||||
"Registering the same IOperationalDatasetCallback twice");
|
||||
}
|
||||
|
||||
IBinder.DeathRecipient deathRecipient =
|
||||
|
|
@ -732,7 +740,7 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub
|
|||
mActiveDataset = newActiveDataset;
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Is unlikely that OT will generate invalid Operational Dataset
|
||||
Log.w(TAG, "Ignoring invalid Active Operational Dataset changes", e);
|
||||
Log.wtf(TAG, "Invalid Active Operational Dataset from OpenThread", e);
|
||||
}
|
||||
|
||||
PendingOperationalDataset newPendingDataset;
|
||||
|
|
@ -746,7 +754,8 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub
|
|||
onPendingOperationalDatasetChanged(newPendingDataset, listenerId);
|
||||
mPendingDataset = newPendingDataset;
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.w(TAG, "Ignoring invalid Pending Operational Dataset changes", e);
|
||||
// Is unlikely that OT will generate invalid Operational Dataset
|
||||
Log.wtf(TAG, "Invalid Pending Operational Dataset from OpenThread", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package com.android.server.thread;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.net.LinkAddress;
|
||||
import android.net.util.SocketUtils;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
|
|
@ -34,6 +35,7 @@ import java.io.IOException;
|
|||
/** Controller for virtual/tunnel network interfaces. */
|
||||
public class TunInterfaceController {
|
||||
private static final String TAG = "TunIfController";
|
||||
private static final long INFINITE_LIFETIME = 0xffffffffL;
|
||||
static final int MTU = 1280;
|
||||
|
||||
static {
|
||||
|
|
@ -76,6 +78,7 @@ public class TunInterfaceController {
|
|||
}
|
||||
|
||||
/** Returns the FD of the tunnel interface. */
|
||||
@Nullable
|
||||
public ParcelFileDescriptor getTunFd() {
|
||||
return mParcelTunFd;
|
||||
}
|
||||
|
|
@ -98,7 +101,7 @@ public class TunInterfaceController {
|
|||
|
||||
if (address.getDeprecationTime() == LinkAddress.LIFETIME_PERMANENT
|
||||
|| address.getDeprecationTime() == LinkAddress.LIFETIME_UNKNOWN) {
|
||||
validLifetimeSeconds = 0xffffffffL;
|
||||
validLifetimeSeconds = INFINITE_LIFETIME;
|
||||
} else {
|
||||
validLifetimeSeconds =
|
||||
Math.max(
|
||||
|
|
@ -108,7 +111,7 @@ public class TunInterfaceController {
|
|||
|
||||
if (address.getExpirationTime() == LinkAddress.LIFETIME_PERMANENT
|
||||
|| address.getExpirationTime() == LinkAddress.LIFETIME_UNKNOWN) {
|
||||
preferredLifetimeSeconds = 0xffffffffL;
|
||||
preferredLifetimeSeconds = INFINITE_LIFETIME;
|
||||
} else {
|
||||
preferredLifetimeSeconds =
|
||||
Math.max(
|
||||
|
|
|
|||
|
|
@ -53,25 +53,25 @@ static jint com_android_server_thread_TunInterfaceController_createTunInterface(
|
|||
strlcpy(ifr.ifr_name, ifName.c_str(), sizeof(ifr.ifr_name));
|
||||
|
||||
if (ioctl(fd, TUNSETIFF, &ifr, sizeof(ifr)) != 0) {
|
||||
close(fd);
|
||||
jniThrowExceptionFmt(env, "java/io/IOException", "ioctl(TUNSETIFF) failed (%s)",
|
||||
strerror(errno));
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int inet6 = socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, IPPROTO_IP);
|
||||
if (inet6 == -1) {
|
||||
close(fd);
|
||||
jniThrowExceptionFmt(env, "java/io/IOException", "create inet6 socket failed (%s)",
|
||||
strerror(errno));
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
ifr.ifr_mtu = mtu;
|
||||
if (ioctl(inet6, SIOCSIFMTU, &ifr) != 0) {
|
||||
close(fd);
|
||||
close(inet6);
|
||||
jniThrowExceptionFmt(env, "java/io/IOException", "ioctl(SIOCSIFMTU) failed (%s)",
|
||||
strerror(errno));
|
||||
close(fd);
|
||||
close(inet6);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -94,7 +94,6 @@ static void com_android_server_thread_TunInterfaceController_setInterfaceUp(
|
|||
}
|
||||
|
||||
if (ioctl(inet6, SIOCSIFFLAGS, &ifr) != 0) {
|
||||
close(inet6);
|
||||
jniThrowExceptionFmt(env, "java/io/IOException", "ioctl(SIOCSIFFLAGS) failed (%s)",
|
||||
strerror(errno));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue