Loading tests/net/java/com/android/server/ConnectivityServiceTest.java +55 −45 Original line number Diff line number Diff line Loading @@ -2158,6 +2158,24 @@ public class ConnectivityServiceTest { } } static void expectOnLost(TestNetworkAgentWrapper network, TestNetworkCallback ... callbacks) { for (TestNetworkCallback c : callbacks) { c.expectCallback(CallbackEntry.LOST, network); } } static void expectAvailableCallbacksUnvalidatedWithSpecifier(TestNetworkAgentWrapper network, NetworkSpecifier specifier, TestNetworkCallback ... callbacks) { for (TestNetworkCallback c : callbacks) { c.expectCallback(CallbackEntry.AVAILABLE, network); c.expectCapabilitiesThat(network, (nc) -> !nc.hasCapability(NET_CAPABILITY_VALIDATED) && Objects.equals(specifier, nc.getNetworkSpecifier())); c.expectCallback(CallbackEntry.LINK_PROPERTIES_CHANGED, network); c.expectCallback(CallbackEntry.BLOCKED_STATUS, network); } } @Test public void testStateChangeNetworkCallbacks() throws Exception { final TestNetworkCallback genericNetworkCallback = new TestNetworkCallback(); Loading Loading @@ -3521,11 +3539,9 @@ public class ConnectivityServiceTest { /** * Verify request matching behavior with network specifiers. * * Note: this test is somewhat problematic since it involves removing capabilities from * agents - i.e. agents rejecting requests which they previously accepted. This is flagged * as a WTF bug in * {@link ConnectivityService#mixInCapabilities(NetworkAgentInfo, NetworkCapabilities)} but * does work. * This test does not check updating the specifier on a live network because the specifier is * immutable and this triggers a WTF in * {@link ConnectivityService#mixInCapabilities(NetworkAgentInfo, NetworkCapabilities)}. */ @Test public void testNetworkSpecifier() throws Exception { Loading Loading @@ -3610,60 +3626,49 @@ public class ConnectivityServiceTest { mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI); mWiFiNetworkAgent.connect(false); cEmpty1.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent); cEmpty2.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent); cEmpty3.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent); cEmpty4.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent); expectAvailableCallbacksUnvalidatedWithSpecifier(mWiFiNetworkAgent, null /* specifier */, cEmpty1, cEmpty2, cEmpty3, cEmpty4); assertNoCallbacks(cFoo, cBar); mWiFiNetworkAgent.disconnect(); expectOnLost(mWiFiNetworkAgent, cEmpty1, cEmpty2, cEmpty3, cEmpty4); mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI); mWiFiNetworkAgent.setNetworkSpecifier(nsFoo); cFoo.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent); for (TestNetworkCallback c: emptyCallbacks) { c.expectCapabilitiesThat(mWiFiNetworkAgent, (caps) -> caps.getNetworkSpecifier().equals(nsFoo)); } cFoo.expectCapabilitiesThat(mWiFiNetworkAgent, (caps) -> caps.getNetworkSpecifier().equals(nsFoo)); mWiFiNetworkAgent.connect(false); expectAvailableCallbacksUnvalidatedWithSpecifier(mWiFiNetworkAgent, nsFoo, cEmpty1, cEmpty2, cEmpty3, cEmpty4, cFoo); cBar.assertNoCallback(); assertEquals(nsFoo, mCm.getNetworkCapabilities(mWiFiNetworkAgent.getNetwork()).getNetworkSpecifier()); cFoo.assertNoCallback(); assertNoCallbacks(cEmpty1, cEmpty2, cEmpty3, cEmpty4, cFoo); mWiFiNetworkAgent.disconnect(); expectOnLost(mWiFiNetworkAgent, cEmpty1, cEmpty2, cEmpty3, cEmpty4, cFoo); mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI); mWiFiNetworkAgent.setNetworkSpecifier(nsBar); cFoo.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent); cBar.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent); for (TestNetworkCallback c: emptyCallbacks) { c.expectCapabilitiesThat(mWiFiNetworkAgent, (caps) -> caps.getNetworkSpecifier().equals(nsBar)); } cBar.expectCapabilitiesThat(mWiFiNetworkAgent, (caps) -> caps.getNetworkSpecifier().equals(nsBar)); mWiFiNetworkAgent.connect(false); expectAvailableCallbacksUnvalidatedWithSpecifier(mWiFiNetworkAgent, nsBar, cEmpty1, cEmpty2, cEmpty3, cEmpty4, cBar); cFoo.assertNoCallback(); assertEquals(nsBar, mCm.getNetworkCapabilities(mWiFiNetworkAgent.getNetwork()).getNetworkSpecifier()); cBar.assertNoCallback(); mWiFiNetworkAgent.disconnect(); expectOnLost(mWiFiNetworkAgent, cEmpty1, cEmpty2, cEmpty3, cEmpty4, cBar); cFoo.assertNoCallback(); mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI); mWiFiNetworkAgent.setNetworkSpecifier(new ConfidentialMatchAllNetworkSpecifier()); cFoo.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent); for (TestNetworkCallback c : emptyCallbacks) { c.expectCapabilitiesThat(mWiFiNetworkAgent, (caps) -> caps.getNetworkSpecifier() == null); } cFoo.expectCapabilitiesThat(mWiFiNetworkAgent, (caps) -> caps.getNetworkSpecifier() == null); cBar.expectCapabilitiesThat(mWiFiNetworkAgent, (caps) -> caps.getNetworkSpecifier() == null); mWiFiNetworkAgent.connect(false); expectAvailableCallbacksUnvalidatedWithSpecifier(mWiFiNetworkAgent, null /* specifier */, cEmpty1, cEmpty2, cEmpty3, cEmpty4, cFoo, cBar); assertNull( mCm.getNetworkCapabilities(mWiFiNetworkAgent.getNetwork()).getNetworkSpecifier()); cFoo.assertNoCallback(); cBar.assertNoCallback(); mWiFiNetworkAgent.setNetworkSpecifier(null); cFoo.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent); cBar.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent); for (TestNetworkCallback c: emptyCallbacks) { c.expectCallback(CallbackEntry.NETWORK_CAPS_UPDATED, mWiFiNetworkAgent); } assertNoCallbacks(cEmpty1, cEmpty2, cEmpty3, cEmpty4, cFoo, cBar); mWiFiNetworkAgent.disconnect(); expectOnLost(mWiFiNetworkAgent, cEmpty1, cEmpty2, cEmpty3, cEmpty4, cFoo, cBar); } /** Loading Loading @@ -6818,6 +6823,7 @@ public class ConnectivityServiceTest { .thenReturn(UserHandle.getUid(RESTRICTED_USER, VPN_UID)); final Intent addedIntent = new Intent(ACTION_USER_ADDED); addedIntent.putExtra(Intent.EXTRA_USER, UserHandle.of(RESTRICTED_USER)); addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, RESTRICTED_USER); // Send a USER_ADDED broadcast for it. Loading @@ -6844,6 +6850,7 @@ public class ConnectivityServiceTest { // Send a USER_REMOVED broadcast and expect to lose the UID range for the restricted user. final Intent removedIntent = new Intent(ACTION_USER_REMOVED); removedIntent.putExtra(Intent.EXTRA_USER, UserHandle.of(RESTRICTED_USER)); removedIntent.putExtra(Intent.EXTRA_USER_HANDLE, RESTRICTED_USER); processBroadcastForVpn(removedIntent); Loading Loading @@ -6901,6 +6908,7 @@ public class ConnectivityServiceTest { RESTRICTED_USER_INFO)); // TODO: check that VPN app within restricted profile still has access, etc. final Intent addedIntent = new Intent(ACTION_USER_ADDED); addedIntent.putExtra(Intent.EXTRA_USER, UserHandle.of(RESTRICTED_USER)); addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, RESTRICTED_USER); processBroadcastForVpn(addedIntent); assertNull(mCm.getActiveNetworkForUid(uid)); Loading @@ -6911,6 +6919,7 @@ public class ConnectivityServiceTest { // Send a USER_REMOVED broadcast and expect to lose the UID range for the restricted user. final Intent removedIntent = new Intent(ACTION_USER_REMOVED); removedIntent.putExtra(Intent.EXTRA_USER, UserHandle.of(RESTRICTED_USER)); removedIntent.putExtra(Intent.EXTRA_USER_HANDLE, RESTRICTED_USER); processBroadcastForVpn(removedIntent); assertNull(mCm.getActiveNetworkForUid(uid)); Loading Loading @@ -7505,6 +7514,7 @@ public class ConnectivityServiceTest { // Send a USER_UNLOCKED broadcast so CS starts LockdownVpnTracker. final int userId = UserHandle.getUserId(Process.myUid()); final Intent addedIntent = new Intent(ACTION_USER_UNLOCKED); addedIntent.putExtra(Intent.EXTRA_USER, UserHandle.of(userId)); addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId); processBroadcastForVpn(addedIntent); Loading tests/net/java/com/android/server/connectivity/NetworkNotificationManagerTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ import com.android.server.connectivity.NetworkNotificationManager.NotificationTy import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.AdditionalAnswers; Loading Loading @@ -183,6 +184,9 @@ public class NetworkNotificationManagerTest { } @Test @Ignore // Ignored because the code under test calls Log.wtf, which crashes the tests on eng builds. // TODO: re-enable after fixing this (e.g., turn Log.wtf into exceptions that this test catches) public void testNoInternetNotificationsNotShownForCellular() { mManager.showNotification(100, NO_INTERNET, mCellNai, mWifiNai, null, false); mManager.showNotification(101, LOST_INTERNET, mCellNai, mWifiNai, null, false); Loading Loading
tests/net/java/com/android/server/ConnectivityServiceTest.java +55 −45 Original line number Diff line number Diff line Loading @@ -2158,6 +2158,24 @@ public class ConnectivityServiceTest { } } static void expectOnLost(TestNetworkAgentWrapper network, TestNetworkCallback ... callbacks) { for (TestNetworkCallback c : callbacks) { c.expectCallback(CallbackEntry.LOST, network); } } static void expectAvailableCallbacksUnvalidatedWithSpecifier(TestNetworkAgentWrapper network, NetworkSpecifier specifier, TestNetworkCallback ... callbacks) { for (TestNetworkCallback c : callbacks) { c.expectCallback(CallbackEntry.AVAILABLE, network); c.expectCapabilitiesThat(network, (nc) -> !nc.hasCapability(NET_CAPABILITY_VALIDATED) && Objects.equals(specifier, nc.getNetworkSpecifier())); c.expectCallback(CallbackEntry.LINK_PROPERTIES_CHANGED, network); c.expectCallback(CallbackEntry.BLOCKED_STATUS, network); } } @Test public void testStateChangeNetworkCallbacks() throws Exception { final TestNetworkCallback genericNetworkCallback = new TestNetworkCallback(); Loading Loading @@ -3521,11 +3539,9 @@ public class ConnectivityServiceTest { /** * Verify request matching behavior with network specifiers. * * Note: this test is somewhat problematic since it involves removing capabilities from * agents - i.e. agents rejecting requests which they previously accepted. This is flagged * as a WTF bug in * {@link ConnectivityService#mixInCapabilities(NetworkAgentInfo, NetworkCapabilities)} but * does work. * This test does not check updating the specifier on a live network because the specifier is * immutable and this triggers a WTF in * {@link ConnectivityService#mixInCapabilities(NetworkAgentInfo, NetworkCapabilities)}. */ @Test public void testNetworkSpecifier() throws Exception { Loading Loading @@ -3610,60 +3626,49 @@ public class ConnectivityServiceTest { mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI); mWiFiNetworkAgent.connect(false); cEmpty1.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent); cEmpty2.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent); cEmpty3.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent); cEmpty4.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent); expectAvailableCallbacksUnvalidatedWithSpecifier(mWiFiNetworkAgent, null /* specifier */, cEmpty1, cEmpty2, cEmpty3, cEmpty4); assertNoCallbacks(cFoo, cBar); mWiFiNetworkAgent.disconnect(); expectOnLost(mWiFiNetworkAgent, cEmpty1, cEmpty2, cEmpty3, cEmpty4); mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI); mWiFiNetworkAgent.setNetworkSpecifier(nsFoo); cFoo.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent); for (TestNetworkCallback c: emptyCallbacks) { c.expectCapabilitiesThat(mWiFiNetworkAgent, (caps) -> caps.getNetworkSpecifier().equals(nsFoo)); } cFoo.expectCapabilitiesThat(mWiFiNetworkAgent, (caps) -> caps.getNetworkSpecifier().equals(nsFoo)); mWiFiNetworkAgent.connect(false); expectAvailableCallbacksUnvalidatedWithSpecifier(mWiFiNetworkAgent, nsFoo, cEmpty1, cEmpty2, cEmpty3, cEmpty4, cFoo); cBar.assertNoCallback(); assertEquals(nsFoo, mCm.getNetworkCapabilities(mWiFiNetworkAgent.getNetwork()).getNetworkSpecifier()); cFoo.assertNoCallback(); assertNoCallbacks(cEmpty1, cEmpty2, cEmpty3, cEmpty4, cFoo); mWiFiNetworkAgent.disconnect(); expectOnLost(mWiFiNetworkAgent, cEmpty1, cEmpty2, cEmpty3, cEmpty4, cFoo); mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI); mWiFiNetworkAgent.setNetworkSpecifier(nsBar); cFoo.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent); cBar.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent); for (TestNetworkCallback c: emptyCallbacks) { c.expectCapabilitiesThat(mWiFiNetworkAgent, (caps) -> caps.getNetworkSpecifier().equals(nsBar)); } cBar.expectCapabilitiesThat(mWiFiNetworkAgent, (caps) -> caps.getNetworkSpecifier().equals(nsBar)); mWiFiNetworkAgent.connect(false); expectAvailableCallbacksUnvalidatedWithSpecifier(mWiFiNetworkAgent, nsBar, cEmpty1, cEmpty2, cEmpty3, cEmpty4, cBar); cFoo.assertNoCallback(); assertEquals(nsBar, mCm.getNetworkCapabilities(mWiFiNetworkAgent.getNetwork()).getNetworkSpecifier()); cBar.assertNoCallback(); mWiFiNetworkAgent.disconnect(); expectOnLost(mWiFiNetworkAgent, cEmpty1, cEmpty2, cEmpty3, cEmpty4, cBar); cFoo.assertNoCallback(); mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI); mWiFiNetworkAgent.setNetworkSpecifier(new ConfidentialMatchAllNetworkSpecifier()); cFoo.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent); for (TestNetworkCallback c : emptyCallbacks) { c.expectCapabilitiesThat(mWiFiNetworkAgent, (caps) -> caps.getNetworkSpecifier() == null); } cFoo.expectCapabilitiesThat(mWiFiNetworkAgent, (caps) -> caps.getNetworkSpecifier() == null); cBar.expectCapabilitiesThat(mWiFiNetworkAgent, (caps) -> caps.getNetworkSpecifier() == null); mWiFiNetworkAgent.connect(false); expectAvailableCallbacksUnvalidatedWithSpecifier(mWiFiNetworkAgent, null /* specifier */, cEmpty1, cEmpty2, cEmpty3, cEmpty4, cFoo, cBar); assertNull( mCm.getNetworkCapabilities(mWiFiNetworkAgent.getNetwork()).getNetworkSpecifier()); cFoo.assertNoCallback(); cBar.assertNoCallback(); mWiFiNetworkAgent.setNetworkSpecifier(null); cFoo.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent); cBar.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent); for (TestNetworkCallback c: emptyCallbacks) { c.expectCallback(CallbackEntry.NETWORK_CAPS_UPDATED, mWiFiNetworkAgent); } assertNoCallbacks(cEmpty1, cEmpty2, cEmpty3, cEmpty4, cFoo, cBar); mWiFiNetworkAgent.disconnect(); expectOnLost(mWiFiNetworkAgent, cEmpty1, cEmpty2, cEmpty3, cEmpty4, cFoo, cBar); } /** Loading Loading @@ -6818,6 +6823,7 @@ public class ConnectivityServiceTest { .thenReturn(UserHandle.getUid(RESTRICTED_USER, VPN_UID)); final Intent addedIntent = new Intent(ACTION_USER_ADDED); addedIntent.putExtra(Intent.EXTRA_USER, UserHandle.of(RESTRICTED_USER)); addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, RESTRICTED_USER); // Send a USER_ADDED broadcast for it. Loading @@ -6844,6 +6850,7 @@ public class ConnectivityServiceTest { // Send a USER_REMOVED broadcast and expect to lose the UID range for the restricted user. final Intent removedIntent = new Intent(ACTION_USER_REMOVED); removedIntent.putExtra(Intent.EXTRA_USER, UserHandle.of(RESTRICTED_USER)); removedIntent.putExtra(Intent.EXTRA_USER_HANDLE, RESTRICTED_USER); processBroadcastForVpn(removedIntent); Loading Loading @@ -6901,6 +6908,7 @@ public class ConnectivityServiceTest { RESTRICTED_USER_INFO)); // TODO: check that VPN app within restricted profile still has access, etc. final Intent addedIntent = new Intent(ACTION_USER_ADDED); addedIntent.putExtra(Intent.EXTRA_USER, UserHandle.of(RESTRICTED_USER)); addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, RESTRICTED_USER); processBroadcastForVpn(addedIntent); assertNull(mCm.getActiveNetworkForUid(uid)); Loading @@ -6911,6 +6919,7 @@ public class ConnectivityServiceTest { // Send a USER_REMOVED broadcast and expect to lose the UID range for the restricted user. final Intent removedIntent = new Intent(ACTION_USER_REMOVED); removedIntent.putExtra(Intent.EXTRA_USER, UserHandle.of(RESTRICTED_USER)); removedIntent.putExtra(Intent.EXTRA_USER_HANDLE, RESTRICTED_USER); processBroadcastForVpn(removedIntent); assertNull(mCm.getActiveNetworkForUid(uid)); Loading Loading @@ -7505,6 +7514,7 @@ public class ConnectivityServiceTest { // Send a USER_UNLOCKED broadcast so CS starts LockdownVpnTracker. final int userId = UserHandle.getUserId(Process.myUid()); final Intent addedIntent = new Intent(ACTION_USER_UNLOCKED); addedIntent.putExtra(Intent.EXTRA_USER, UserHandle.of(userId)); addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId); processBroadcastForVpn(addedIntent); Loading
tests/net/java/com/android/server/connectivity/NetworkNotificationManagerTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ import com.android.server.connectivity.NetworkNotificationManager.NotificationTy import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.AdditionalAnswers; Loading Loading @@ -183,6 +184,9 @@ public class NetworkNotificationManagerTest { } @Test @Ignore // Ignored because the code under test calls Log.wtf, which crashes the tests on eng builds. // TODO: re-enable after fixing this (e.g., turn Log.wtf into exceptions that this test catches) public void testNoInternetNotificationsNotShownForCellular() { mManager.showNotification(100, NO_INTERNET, mCellNai, mWifiNai, null, false); mManager.showNotification(101, LOST_INTERNET, mCellNai, mWifiNai, null, false); Loading