Loading packages/NetworkStack/src/android/net/ip/IpClient.java +46 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ import android.os.SystemClock; import android.text.TextUtils; import android.util.LocalLog; import android.util.Log; import android.util.Pair; import android.util.SparseArray; import com.android.internal.annotations.VisibleForTesting; Loading Loading @@ -298,6 +299,7 @@ public class IpClient extends StateMachine { private static final int EVENT_READ_PACKET_FILTER_COMPLETE = 12; private static final int CMD_ADD_KEEPALIVE_PACKET_FILTER_TO_APF = 13; private static final int CMD_REMOVE_KEEPALIVE_PACKET_FILTER_FROM_APF = 14; private static final int CMD_UPDATE_L2KEY_GROUPHINT = 15; // Internal commands to use instead of trying to call transitionTo() inside // a given State's enter() method. Calling transitionTo() from enter/exit Loading Loading @@ -364,6 +366,8 @@ public class IpClient extends StateMachine { private String mTcpBufferSizes; private ProxyInfo mHttpProxy; private ApfFilter mApfFilter; private String mL2Key; // The L2 key for this network, for writing into the memory store private String mGroupHint; // The group hint for this network, for writing into the memory store private boolean mMulticastFiltering; private long mStartTimeMillis; Loading Loading @@ -524,6 +528,11 @@ public class IpClient extends StateMachine { IpClient.this.stop(); } @Override public void setL2KeyAndGroupHint(String l2Key, String groupHint) { checkNetworkStackCallingPermission(); IpClient.this.setL2KeyAndGroupHint(l2Key, groupHint); } @Override public void setTcpBufferSizes(String tcpBufferSizes) { checkNetworkStackCallingPermission(); IpClient.this.setTcpBufferSizes(tcpBufferSizes); Loading Loading @@ -651,6 +660,13 @@ public class IpClient extends StateMachine { sendMessage(CMD_UPDATE_TCP_BUFFER_SIZES, tcpBufferSizes); } /** * Set the L2 key and group hint for storing info into the memory store. */ public void setL2KeyAndGroupHint(String l2Key, String groupHint) { sendMessage(CMD_UPDATE_L2KEY_GROUPHINT, new Pair<>(l2Key, groupHint)); } /** * Set the HTTP Proxy configuration to use. * Loading Loading @@ -1068,6 +1084,10 @@ public class IpClient extends StateMachine { return true; } final int delta = setLinkProperties(newLp); // Most of the attributes stored in the memory store are deduced from // the link properties, therefore when the properties update the memory // store record should be updated too. maybeSaveNetworkToIpMemoryStore(); if (sendCallbacks) { dispatchCallback(delta, newLp); } Loading @@ -1083,6 +1103,7 @@ public class IpClient extends StateMachine { Log.d(mTag, "onNewDhcpResults(" + Objects.toString(dhcpResults) + ")"); } mCallback.onNewDhcpResults(dhcpResults); maybeSaveNetworkToIpMemoryStore(); dispatchCallback(delta, newLp); } Loading Loading @@ -1213,6 +1234,10 @@ public class IpClient extends StateMachine { mInterfaceCtrl.clearAllAddresses(); } private void maybeSaveNetworkToIpMemoryStore() { // TODO : implement this } class StoppedState extends State { @Override public void enter() { Loading Loading @@ -1258,6 +1283,13 @@ public class IpClient extends StateMachine { handleLinkPropertiesUpdate(NO_CALLBACKS); break; case CMD_UPDATE_L2KEY_GROUPHINT: { final Pair<String, String> args = (Pair<String, String>) msg.obj; mL2Key = args.first; mGroupHint = args.second; break; } case CMD_SET_MULTICAST_FILTER: mMulticastFiltering = (boolean) msg.obj; break; Loading Loading @@ -1357,6 +1389,20 @@ public class IpClient extends StateMachine { } break; case CMD_UPDATE_L2KEY_GROUPHINT: { final Pair<String, String> args = (Pair<String, String>) msg.obj; mL2Key = args.first; mGroupHint = args.second; // TODO : attributes should be saved to the memory store with // these new values if they differ from the previous ones. // If the state machine is in pure StartedState, then the values to input // are not known yet and should be updated when the LinkProperties are updated. // If the state machine is in RunningState (which is a child of StartedState) // then the next NUD check should be used to store the new values to avoid // inputting current values for what may be a different L3 network. break; } case EVENT_PROVISIONING_TIMEOUT: handleProvisioningFailure(); break; Loading packages/NetworkStack/tests/src/android/net/ip/IpClientTest.java +22 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import static org.mockito.Mockito.reset; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import android.app.AlarmManager; Loading @@ -40,7 +41,9 @@ import android.net.IpPrefix; import android.net.LinkAddress; import android.net.LinkProperties; import android.net.MacAddress; import android.net.NetworkStackIpMemoryStore; import android.net.RouteInfo; import android.net.ipmemorystore.NetworkAttributes; import android.net.shared.InitialConfiguration; import android.net.shared.ProvisioningConfiguration; import android.net.util.InterfaceParams; Loading Loading @@ -81,6 +84,8 @@ public class IpClientTest { // See RFC 7042#section-2.1.2 for EUI-48 documentation values. private static final MacAddress TEST_MAC = MacAddress.fromString("00:00:5E:00:53:01"); private static final int TEST_TIMEOUT_MS = 400; private static final String TEST_L2KEY = "some l2key"; private static final String TEST_GROUPHINT = "some grouphint"; @Mock private Context mContext; @Mock private ConnectivityManager mCm; Loading @@ -92,6 +97,7 @@ public class IpClientTest { @Mock private IpClient.Dependencies mDependencies; @Mock private ContentResolver mContentResolver; @Mock private NetworkStackService.NetworkStackServiceManager mNetworkStackServiceManager; @Mock private NetworkStackIpMemoryStore mIpMemoryStore; private NetworkObserver mObserver; private InterfaceParams mIfParams; Loading Loading @@ -141,6 +147,12 @@ public class IpClientTest { return empty; } private void verifyNetworkAttributesStored(final String l2Key, final NetworkAttributes attributes) { // TODO : when storing is implemented, turn this on // verify(mIpMemoryStore).storeNetworkAttributes(eq(l2Key), eq(attributes), any()); } @Test public void testNullInterfaceNameMostDefinitelyThrows() throws Exception { setTestInterfaceParams(null); Loading Loading @@ -173,6 +185,7 @@ public class IpClientTest { setTestInterfaceParams(TEST_IFNAME); final IpClient ipc = new IpClient(mContext, TEST_IFNAME, mCb, mObserverRegistry, mNetworkStackServiceManager, mDependencies); verifyNoMoreInteractions(mIpMemoryStore); ipc.shutdown(); } Loading @@ -183,6 +196,7 @@ public class IpClientTest { mNetworkStackServiceManager, mDependencies); ipc.startProvisioning(new ProvisioningConfiguration()); verify(mCb, times(1)).onProvisioningFailure(any()); verify(mIpMemoryStore, never()).storeNetworkAttributes(any(), any(), any()); ipc.shutdown(); } Loading @@ -202,6 +216,7 @@ public class IpClientTest { verify(mCb, times(1)).setNeighborDiscoveryOffload(true); verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)).setFallbackMulticastFilter(false); verify(mCb, never()).onProvisioningFailure(any()); verify(mIpMemoryStore, never()).storeNetworkAttributes(any(), any(), any()); ipc.shutdown(); verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceSetEnableIPv6(iface, false); Loading @@ -214,6 +229,8 @@ public class IpClientTest { public void testProvisioningWithInitialConfiguration() throws Exception { final String iface = TEST_IFNAME; final IpClient ipc = makeIpClient(iface); final String l2Key = TEST_L2KEY; final String groupHint = TEST_GROUPHINT; String[] addresses = { "fe80::a4be:f92:e1f7:22d1/64", Loading @@ -232,6 +249,7 @@ public class IpClientTest { verify(mCb, times(1)).setNeighborDiscoveryOffload(true); verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)).setFallbackMulticastFilter(false); verify(mCb, never()).onProvisioningFailure(any()); ipc.setL2KeyAndGroupHint(l2Key, groupHint); for (String addr : addresses) { String[] parts = addr.split("/"); Loading @@ -253,12 +271,16 @@ public class IpClientTest { LinkProperties want = linkproperties(links(addresses), routes(prefixes)); want.setInterfaceName(iface); verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)).onProvisioningSuccess(want); verifyNetworkAttributesStored(l2Key, new NetworkAttributes.Builder() .setGroupHint(groupHint) .build()); ipc.shutdown(); verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceSetEnableIPv6(iface, false); verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceClearAddrs(iface); verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)) .onLinkPropertiesChange(makeEmptyLinkProperties(iface)); verifyNoMoreInteractions(mIpMemoryStore); } @Test Loading services/net/java/android/net/ip/IIpClient.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ oneway interface IIpClient { void shutdown(); void startProvisioning(in ProvisioningConfigurationParcelable req); void stop(); void setL2KeyAndGroupHint(in String l2Key, in String groupHint); void setTcpBufferSizes(in String tcpBufferSizes); void setHttpProxy(in ProxyInfo proxyInfo); void setMulticastFilter(boolean enabled); Loading Loading
packages/NetworkStack/src/android/net/ip/IpClient.java +46 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ import android.os.SystemClock; import android.text.TextUtils; import android.util.LocalLog; import android.util.Log; import android.util.Pair; import android.util.SparseArray; import com.android.internal.annotations.VisibleForTesting; Loading Loading @@ -298,6 +299,7 @@ public class IpClient extends StateMachine { private static final int EVENT_READ_PACKET_FILTER_COMPLETE = 12; private static final int CMD_ADD_KEEPALIVE_PACKET_FILTER_TO_APF = 13; private static final int CMD_REMOVE_KEEPALIVE_PACKET_FILTER_FROM_APF = 14; private static final int CMD_UPDATE_L2KEY_GROUPHINT = 15; // Internal commands to use instead of trying to call transitionTo() inside // a given State's enter() method. Calling transitionTo() from enter/exit Loading Loading @@ -364,6 +366,8 @@ public class IpClient extends StateMachine { private String mTcpBufferSizes; private ProxyInfo mHttpProxy; private ApfFilter mApfFilter; private String mL2Key; // The L2 key for this network, for writing into the memory store private String mGroupHint; // The group hint for this network, for writing into the memory store private boolean mMulticastFiltering; private long mStartTimeMillis; Loading Loading @@ -524,6 +528,11 @@ public class IpClient extends StateMachine { IpClient.this.stop(); } @Override public void setL2KeyAndGroupHint(String l2Key, String groupHint) { checkNetworkStackCallingPermission(); IpClient.this.setL2KeyAndGroupHint(l2Key, groupHint); } @Override public void setTcpBufferSizes(String tcpBufferSizes) { checkNetworkStackCallingPermission(); IpClient.this.setTcpBufferSizes(tcpBufferSizes); Loading Loading @@ -651,6 +660,13 @@ public class IpClient extends StateMachine { sendMessage(CMD_UPDATE_TCP_BUFFER_SIZES, tcpBufferSizes); } /** * Set the L2 key and group hint for storing info into the memory store. */ public void setL2KeyAndGroupHint(String l2Key, String groupHint) { sendMessage(CMD_UPDATE_L2KEY_GROUPHINT, new Pair<>(l2Key, groupHint)); } /** * Set the HTTP Proxy configuration to use. * Loading Loading @@ -1068,6 +1084,10 @@ public class IpClient extends StateMachine { return true; } final int delta = setLinkProperties(newLp); // Most of the attributes stored in the memory store are deduced from // the link properties, therefore when the properties update the memory // store record should be updated too. maybeSaveNetworkToIpMemoryStore(); if (sendCallbacks) { dispatchCallback(delta, newLp); } Loading @@ -1083,6 +1103,7 @@ public class IpClient extends StateMachine { Log.d(mTag, "onNewDhcpResults(" + Objects.toString(dhcpResults) + ")"); } mCallback.onNewDhcpResults(dhcpResults); maybeSaveNetworkToIpMemoryStore(); dispatchCallback(delta, newLp); } Loading Loading @@ -1213,6 +1234,10 @@ public class IpClient extends StateMachine { mInterfaceCtrl.clearAllAddresses(); } private void maybeSaveNetworkToIpMemoryStore() { // TODO : implement this } class StoppedState extends State { @Override public void enter() { Loading Loading @@ -1258,6 +1283,13 @@ public class IpClient extends StateMachine { handleLinkPropertiesUpdate(NO_CALLBACKS); break; case CMD_UPDATE_L2KEY_GROUPHINT: { final Pair<String, String> args = (Pair<String, String>) msg.obj; mL2Key = args.first; mGroupHint = args.second; break; } case CMD_SET_MULTICAST_FILTER: mMulticastFiltering = (boolean) msg.obj; break; Loading Loading @@ -1357,6 +1389,20 @@ public class IpClient extends StateMachine { } break; case CMD_UPDATE_L2KEY_GROUPHINT: { final Pair<String, String> args = (Pair<String, String>) msg.obj; mL2Key = args.first; mGroupHint = args.second; // TODO : attributes should be saved to the memory store with // these new values if they differ from the previous ones. // If the state machine is in pure StartedState, then the values to input // are not known yet and should be updated when the LinkProperties are updated. // If the state machine is in RunningState (which is a child of StartedState) // then the next NUD check should be used to store the new values to avoid // inputting current values for what may be a different L3 network. break; } case EVENT_PROVISIONING_TIMEOUT: handleProvisioningFailure(); break; Loading
packages/NetworkStack/tests/src/android/net/ip/IpClientTest.java +22 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import static org.mockito.Mockito.reset; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import android.app.AlarmManager; Loading @@ -40,7 +41,9 @@ import android.net.IpPrefix; import android.net.LinkAddress; import android.net.LinkProperties; import android.net.MacAddress; import android.net.NetworkStackIpMemoryStore; import android.net.RouteInfo; import android.net.ipmemorystore.NetworkAttributes; import android.net.shared.InitialConfiguration; import android.net.shared.ProvisioningConfiguration; import android.net.util.InterfaceParams; Loading Loading @@ -81,6 +84,8 @@ public class IpClientTest { // See RFC 7042#section-2.1.2 for EUI-48 documentation values. private static final MacAddress TEST_MAC = MacAddress.fromString("00:00:5E:00:53:01"); private static final int TEST_TIMEOUT_MS = 400; private static final String TEST_L2KEY = "some l2key"; private static final String TEST_GROUPHINT = "some grouphint"; @Mock private Context mContext; @Mock private ConnectivityManager mCm; Loading @@ -92,6 +97,7 @@ public class IpClientTest { @Mock private IpClient.Dependencies mDependencies; @Mock private ContentResolver mContentResolver; @Mock private NetworkStackService.NetworkStackServiceManager mNetworkStackServiceManager; @Mock private NetworkStackIpMemoryStore mIpMemoryStore; private NetworkObserver mObserver; private InterfaceParams mIfParams; Loading Loading @@ -141,6 +147,12 @@ public class IpClientTest { return empty; } private void verifyNetworkAttributesStored(final String l2Key, final NetworkAttributes attributes) { // TODO : when storing is implemented, turn this on // verify(mIpMemoryStore).storeNetworkAttributes(eq(l2Key), eq(attributes), any()); } @Test public void testNullInterfaceNameMostDefinitelyThrows() throws Exception { setTestInterfaceParams(null); Loading Loading @@ -173,6 +185,7 @@ public class IpClientTest { setTestInterfaceParams(TEST_IFNAME); final IpClient ipc = new IpClient(mContext, TEST_IFNAME, mCb, mObserverRegistry, mNetworkStackServiceManager, mDependencies); verifyNoMoreInteractions(mIpMemoryStore); ipc.shutdown(); } Loading @@ -183,6 +196,7 @@ public class IpClientTest { mNetworkStackServiceManager, mDependencies); ipc.startProvisioning(new ProvisioningConfiguration()); verify(mCb, times(1)).onProvisioningFailure(any()); verify(mIpMemoryStore, never()).storeNetworkAttributes(any(), any(), any()); ipc.shutdown(); } Loading @@ -202,6 +216,7 @@ public class IpClientTest { verify(mCb, times(1)).setNeighborDiscoveryOffload(true); verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)).setFallbackMulticastFilter(false); verify(mCb, never()).onProvisioningFailure(any()); verify(mIpMemoryStore, never()).storeNetworkAttributes(any(), any(), any()); ipc.shutdown(); verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceSetEnableIPv6(iface, false); Loading @@ -214,6 +229,8 @@ public class IpClientTest { public void testProvisioningWithInitialConfiguration() throws Exception { final String iface = TEST_IFNAME; final IpClient ipc = makeIpClient(iface); final String l2Key = TEST_L2KEY; final String groupHint = TEST_GROUPHINT; String[] addresses = { "fe80::a4be:f92:e1f7:22d1/64", Loading @@ -232,6 +249,7 @@ public class IpClientTest { verify(mCb, times(1)).setNeighborDiscoveryOffload(true); verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)).setFallbackMulticastFilter(false); verify(mCb, never()).onProvisioningFailure(any()); ipc.setL2KeyAndGroupHint(l2Key, groupHint); for (String addr : addresses) { String[] parts = addr.split("/"); Loading @@ -253,12 +271,16 @@ public class IpClientTest { LinkProperties want = linkproperties(links(addresses), routes(prefixes)); want.setInterfaceName(iface); verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)).onProvisioningSuccess(want); verifyNetworkAttributesStored(l2Key, new NetworkAttributes.Builder() .setGroupHint(groupHint) .build()); ipc.shutdown(); verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceSetEnableIPv6(iface, false); verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceClearAddrs(iface); verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)) .onLinkPropertiesChange(makeEmptyLinkProperties(iface)); verifyNoMoreInteractions(mIpMemoryStore); } @Test Loading
services/net/java/android/net/ip/IIpClient.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ oneway interface IIpClient { void shutdown(); void startProvisioning(in ProvisioningConfigurationParcelable req); void stop(); void setL2KeyAndGroupHint(in String l2Key, in String groupHint); void setTcpBufferSizes(in String tcpBufferSizes); void setHttpProxy(in ProxyInfo proxyInfo); void setMulticastFilter(boolean enabled); Loading