Merge changes Iec53a9fd,Iac4cfe70
am: 8621e44c39
Change-Id: I8fae2c4d23d6e904b473b1e906094f997c8e446c
This commit is contained in:
@@ -4879,7 +4879,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
final NetworkCapabilities nc = new NetworkCapabilities(networkCapabilities);
|
||||
final NetworkAgentInfo nai = new NetworkAgentInfo(messenger, new AsyncChannel(),
|
||||
new Network(reserveNetId()), new NetworkInfo(networkInfo), lp, nc, currentScore,
|
||||
mContext, mTrackerHandler, new NetworkMisc(networkMisc), this);
|
||||
mContext, mTrackerHandler, new NetworkMisc(networkMisc), this, mNetd, mNMS);
|
||||
// Make sure the network capabilities reflect what the agent info says.
|
||||
nai.networkCapabilities = mixInCapabilities(nai, nc);
|
||||
final String extraInfo = networkInfo.getExtraInfo();
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
|
||||
package com.android.server.connectivity;
|
||||
|
||||
import android.net.InterfaceConfiguration;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.INetd;
|
||||
import android.net.InterfaceConfiguration;
|
||||
import android.net.LinkAddress;
|
||||
import android.net.LinkProperties;
|
||||
import android.net.NetworkInfo;
|
||||
@@ -59,6 +60,7 @@ public class Nat464Xlat extends BaseNetworkObserver {
|
||||
NetworkInfo.State.SUSPENDED,
|
||||
};
|
||||
|
||||
private final INetd mNetd;
|
||||
private final INetworkManagementService mNMService;
|
||||
|
||||
// The network we're running on, and its type.
|
||||
@@ -76,7 +78,8 @@ public class Nat464Xlat extends BaseNetworkObserver {
|
||||
private String mIface;
|
||||
private State mState = State.IDLE;
|
||||
|
||||
public Nat464Xlat(INetworkManagementService nmService, NetworkAgentInfo nai) {
|
||||
public Nat464Xlat(NetworkAgentInfo nai, INetd netd, INetworkManagementService nmService) {
|
||||
mNetd = netd;
|
||||
mNMService = nmService;
|
||||
mNetwork = nai;
|
||||
}
|
||||
@@ -140,7 +143,7 @@ public class Nat464Xlat extends BaseNetworkObserver {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
mNMService.startClatd(baseIface);
|
||||
mNetd.clatdStart(baseIface);
|
||||
} catch(RemoteException|IllegalStateException e) {
|
||||
Slog.e(TAG, "Error starting clatd on " + baseIface, e);
|
||||
}
|
||||
@@ -162,7 +165,7 @@ public class Nat464Xlat extends BaseNetworkObserver {
|
||||
*/
|
||||
private void enterStoppingState() {
|
||||
try {
|
||||
mNMService.stopClatd(mBaseIface);
|
||||
mNetd.clatdStop(mBaseIface);
|
||||
} catch(RemoteException|IllegalStateException e) {
|
||||
Slog.e(TAG, "Error stopping clatd on " + mBaseIface, e);
|
||||
}
|
||||
@@ -204,7 +207,7 @@ public class Nat464Xlat extends BaseNetworkObserver {
|
||||
Slog.e(TAG, "startClat: Can't start clat on null interface");
|
||||
return;
|
||||
}
|
||||
// TODO: should we only do this if mNMService.startClatd() succeeds?
|
||||
// TODO: should we only do this if mNetd.clatdStart() succeeds?
|
||||
Slog.i(TAG, "Starting clatd on " + baseIface);
|
||||
enterStartingState(baseIface);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.server.connectivity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.INetd;
|
||||
import android.net.INetworkMonitor;
|
||||
import android.net.LinkProperties;
|
||||
import android.net.Network;
|
||||
@@ -239,12 +240,15 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
|
||||
private static final String TAG = ConnectivityService.class.getSimpleName();
|
||||
private static final boolean VDBG = false;
|
||||
private final ConnectivityService mConnService;
|
||||
private final INetd mNetd;
|
||||
private final INetworkManagementService mNMS;
|
||||
private final Context mContext;
|
||||
private final Handler mHandler;
|
||||
|
||||
public NetworkAgentInfo(Messenger messenger, AsyncChannel ac, Network net, NetworkInfo info,
|
||||
LinkProperties lp, NetworkCapabilities nc, int score, Context context, Handler handler,
|
||||
NetworkMisc misc, ConnectivityService connService) {
|
||||
NetworkMisc misc, ConnectivityService connService, INetd netd,
|
||||
INetworkManagementService nms) {
|
||||
this.messenger = messenger;
|
||||
asyncChannel = ac;
|
||||
network = net;
|
||||
@@ -253,6 +257,8 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
|
||||
networkCapabilities = nc;
|
||||
currentScore = score;
|
||||
mConnService = connService;
|
||||
mNetd = netd;
|
||||
mNMS = nms;
|
||||
mContext = context;
|
||||
mHandler = handler;
|
||||
networkMisc = misc;
|
||||
@@ -587,18 +593,18 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
|
||||
|
||||
public void updateClat(INetworkManagementService netd) {
|
||||
if (Nat464Xlat.requiresClat(this)) {
|
||||
maybeStartClat(netd);
|
||||
maybeStartClat();
|
||||
} else {
|
||||
maybeStopClat();
|
||||
}
|
||||
}
|
||||
|
||||
/** Ensure clat has started for this network. */
|
||||
public void maybeStartClat(INetworkManagementService netd) {
|
||||
public void maybeStartClat() {
|
||||
if (clatd != null && clatd.isStarted()) {
|
||||
return;
|
||||
}
|
||||
clatd = new Nat464Xlat(netd, this);
|
||||
clatd = new Nat464Xlat(this, mNetd, mNMS);
|
||||
clatd.start();
|
||||
}
|
||||
|
||||
|
||||
@@ -849,6 +849,18 @@ public class LinkPropertiesTest {
|
||||
assertEquals(new ArraySet<>(expectRemoved), (new ArraySet<>(result.removed)));
|
||||
}
|
||||
|
||||
private void assertParcelingIsLossless(LinkProperties source) {
|
||||
Parcel p = Parcel.obtain();
|
||||
source.writeToParcel(p, /* flags */ 0);
|
||||
p.setDataPosition(0);
|
||||
final byte[] marshalled = p.marshall();
|
||||
p = Parcel.obtain();
|
||||
p.unmarshall(marshalled, 0, marshalled.length);
|
||||
p.setDataPosition(0);
|
||||
LinkProperties dest = LinkProperties.CREATOR.createFromParcel(p);
|
||||
assertEquals(source, dest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLinkPropertiesParcelable() throws Exception {
|
||||
LinkProperties source = new LinkProperties();
|
||||
@@ -870,15 +882,12 @@ public class LinkPropertiesTest {
|
||||
|
||||
source.setNat64Prefix(new IpPrefix("2001:db8:1:2:64:64::/96"));
|
||||
|
||||
Parcel p = Parcel.obtain();
|
||||
source.writeToParcel(p, /* flags */ 0);
|
||||
p.setDataPosition(0);
|
||||
final byte[] marshalled = p.marshall();
|
||||
p = Parcel.obtain();
|
||||
p.unmarshall(marshalled, 0, marshalled.length);
|
||||
p.setDataPosition(0);
|
||||
LinkProperties dest = LinkProperties.CREATOR.createFromParcel(p);
|
||||
assertParcelingIsLossless(source);
|
||||
}
|
||||
|
||||
assertEquals(source, dest);
|
||||
@Test
|
||||
public void testParcelUninitialized() throws Exception {
|
||||
LinkProperties empty = new LinkProperties();
|
||||
assertParcelingIsLossless(empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4683,7 +4683,7 @@ public class ConnectivityServiceTest {
|
||||
mCellNetworkAgent.sendLinkProperties(cellLp);
|
||||
mCellNetworkAgent.connect(true);
|
||||
networkCallback.expectAvailableThenValidatedCallbacks(mCellNetworkAgent);
|
||||
verify(mNetworkManagementService, times(1)).startClatd(MOBILE_IFNAME);
|
||||
verify(mMockNetd, times(1)).clatdStart(MOBILE_IFNAME);
|
||||
Nat464Xlat clat = mService.getNat464Xlat(mCellNetworkAgent);
|
||||
|
||||
// Clat iface up, expect stack link updated.
|
||||
@@ -4710,7 +4710,7 @@ public class ConnectivityServiceTest {
|
||||
mCellNetworkAgent.sendLinkProperties(cellLp);
|
||||
waitForIdle();
|
||||
networkCallback.expectCallback(CallbackState.LINK_PROPERTIES, mCellNetworkAgent);
|
||||
verify(mNetworkManagementService, times(1)).stopClatd(MOBILE_IFNAME);
|
||||
verify(mMockNetd, times(1)).clatdStop(MOBILE_IFNAME);
|
||||
|
||||
// Clat iface removed, expect linkproperties revert to original one
|
||||
clat.interfaceRemoved(CLAT_PREFIX + MOBILE_IFNAME);
|
||||
|
||||
@@ -32,11 +32,13 @@ import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.INetd;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.NetworkMisc;
|
||||
import android.net.NetworkStack;
|
||||
import android.os.INetworkManagementService;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.text.format.DateUtils;
|
||||
@@ -66,6 +68,8 @@ public class LingerMonitorTest {
|
||||
LingerMonitor mMonitor;
|
||||
|
||||
@Mock ConnectivityService mConnService;
|
||||
@Mock INetd mNetd;
|
||||
@Mock INetworkManagementService mNMS;
|
||||
@Mock Context mCtx;
|
||||
@Mock NetworkMisc mMisc;
|
||||
@Mock NetworkNotificationManager mNotifier;
|
||||
@@ -352,7 +356,7 @@ public class LingerMonitorTest {
|
||||
caps.addCapability(0);
|
||||
caps.addTransportType(transport);
|
||||
NetworkAgentInfo nai = new NetworkAgentInfo(null, null, new Network(netId), info, null,
|
||||
caps, 50, mCtx, null, mMisc, mConnService);
|
||||
caps, 50, mCtx, null, mMisc, mConnService, mNetd, mNMS);
|
||||
nai.everValidated = true;
|
||||
return nai;
|
||||
}
|
||||
|
||||
@@ -17,9 +17,7 @@
|
||||
package com.android.server.connectivity;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -27,6 +25,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.INetd;
|
||||
import android.net.InterfaceConfiguration;
|
||||
import android.net.LinkAddress;
|
||||
import android.net.LinkProperties;
|
||||
@@ -57,6 +56,7 @@ public class Nat464XlatTest {
|
||||
|
||||
@Mock ConnectivityService mConnectivity;
|
||||
@Mock NetworkMisc mMisc;
|
||||
@Mock INetd mNetd;
|
||||
@Mock INetworkManagementService mNms;
|
||||
@Mock InterfaceConfiguration mConfig;
|
||||
@Mock NetworkAgentInfo mNai;
|
||||
@@ -65,7 +65,7 @@ public class Nat464XlatTest {
|
||||
Handler mHandler;
|
||||
|
||||
Nat464Xlat makeNat464Xlat() {
|
||||
return new Nat464Xlat(mNms, mNai);
|
||||
return new Nat464Xlat(mNai, mNetd, mNms);
|
||||
}
|
||||
|
||||
@Before
|
||||
@@ -129,7 +129,7 @@ public class Nat464XlatTest {
|
||||
nat.start();
|
||||
|
||||
verify(mNms).registerObserver(eq(nat));
|
||||
verify(mNms).startClatd(eq(BASE_IFACE));
|
||||
verify(mNetd).clatdStart(eq(BASE_IFACE));
|
||||
|
||||
// Stacked interface up notification arrives.
|
||||
nat.interfaceLinkStateChanged(STACKED_IFACE, true);
|
||||
@@ -144,7 +144,7 @@ public class Nat464XlatTest {
|
||||
// ConnectivityService stops clat (Network disconnects, IPv4 addr appears, ...).
|
||||
nat.stop();
|
||||
|
||||
verify(mNms).stopClatd(eq(BASE_IFACE));
|
||||
verify(mNetd).clatdStop(eq(BASE_IFACE));
|
||||
|
||||
// Stacked interface removed notification arrives.
|
||||
nat.interfaceRemoved(STACKED_IFACE);
|
||||
@@ -156,7 +156,7 @@ public class Nat464XlatTest {
|
||||
assertFalse(c.getValue().getAllInterfaceNames().contains(STACKED_IFACE));
|
||||
assertIdle(nat);
|
||||
|
||||
verifyNoMoreInteractions(mNms, mConnectivity);
|
||||
verifyNoMoreInteractions(mNetd, mNms, mConnectivity);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -168,7 +168,7 @@ public class Nat464XlatTest {
|
||||
nat.start();
|
||||
|
||||
verify(mNms).registerObserver(eq(nat));
|
||||
verify(mNms).startClatd(eq(BASE_IFACE));
|
||||
verify(mNetd).clatdStart(eq(BASE_IFACE));
|
||||
|
||||
// Stacked interface up notification arrives.
|
||||
nat.interfaceLinkStateChanged(STACKED_IFACE, true);
|
||||
@@ -185,7 +185,7 @@ public class Nat464XlatTest {
|
||||
mLooper.dispatchNext();
|
||||
|
||||
verify(mNms).unregisterObserver(eq(nat));
|
||||
verify(mNms).stopClatd(eq(BASE_IFACE));
|
||||
verify(mNetd).clatdStop(eq(BASE_IFACE));
|
||||
verify(mConnectivity, times(2)).handleUpdateLinkProperties(eq(mNai), c.capture());
|
||||
assertTrue(c.getValue().getStackedLinks().isEmpty());
|
||||
assertFalse(c.getValue().getAllInterfaceNames().contains(STACKED_IFACE));
|
||||
@@ -194,7 +194,7 @@ public class Nat464XlatTest {
|
||||
// ConnectivityService stops clat: no-op.
|
||||
nat.stop();
|
||||
|
||||
verifyNoMoreInteractions(mNms, mConnectivity);
|
||||
verifyNoMoreInteractions(mNetd, mNms, mConnectivity);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -205,13 +205,13 @@ public class Nat464XlatTest {
|
||||
nat.start();
|
||||
|
||||
verify(mNms).registerObserver(eq(nat));
|
||||
verify(mNms).startClatd(eq(BASE_IFACE));
|
||||
verify(mNetd).clatdStart(eq(BASE_IFACE));
|
||||
|
||||
// ConnectivityService immediately stops clat (Network disconnects, IPv4 addr appears, ...)
|
||||
nat.stop();
|
||||
|
||||
verify(mNms).unregisterObserver(eq(nat));
|
||||
verify(mNms).stopClatd(eq(BASE_IFACE));
|
||||
verify(mNetd).clatdStop(eq(BASE_IFACE));
|
||||
assertIdle(nat);
|
||||
|
||||
// In-flight interface up notification arrives: no-op
|
||||
@@ -225,7 +225,7 @@ public class Nat464XlatTest {
|
||||
|
||||
assertIdle(nat);
|
||||
|
||||
verifyNoMoreInteractions(mNms, mConnectivity);
|
||||
verifyNoMoreInteractions(mNetd, mNms, mConnectivity);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -236,16 +236,16 @@ public class Nat464XlatTest {
|
||||
nat.start();
|
||||
|
||||
verify(mNms).registerObserver(eq(nat));
|
||||
verify(mNms).startClatd(eq(BASE_IFACE));
|
||||
verify(mNetd).clatdStart(eq(BASE_IFACE));
|
||||
|
||||
// ConnectivityService immediately stops clat (Network disconnects, IPv4 addr appears, ...)
|
||||
nat.stop();
|
||||
|
||||
verify(mNms).unregisterObserver(eq(nat));
|
||||
verify(mNms).stopClatd(eq(BASE_IFACE));
|
||||
verify(mNetd).clatdStop(eq(BASE_IFACE));
|
||||
assertIdle(nat);
|
||||
|
||||
verifyNoMoreInteractions(mNms, mConnectivity);
|
||||
verifyNoMoreInteractions(mNetd, mNms, mConnectivity);
|
||||
}
|
||||
|
||||
static void assertIdle(Nat464Xlat nat) {
|
||||
|
||||
Reference in New Issue
Block a user