Revert "ConnectivityManager: no double NetworkCallback registration" because oit caused regressions http://b/35955593, http://b/35921499.
This reverts commit ca4bf6edc3.
Change-Id: I86c07c113f24753be7c977e6d7f570b99391e1b5
This commit is contained in:
@@ -36,36 +36,21 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.anyInt;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.net.ConnectivityManager.NetworkCallback;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkCapabilities;
|
||||
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class ConnectivityManagerTest {
|
||||
|
||||
@Mock Context mCtx;
|
||||
@Mock IConnectivityManager mService;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
static NetworkCapabilities verifyNetworkCapabilities(
|
||||
int legacyType, int transportType, int... capabilities) {
|
||||
final NetworkCapabilities nc = ConnectivityManager.networkCapabilitiesForType(legacyType);
|
||||
@@ -188,34 +173,4 @@ public class ConnectivityManagerTest {
|
||||
verifyUnrestrictedNetworkCapabilities(
|
||||
ConnectivityManager.TYPE_ETHERNET, TRANSPORT_ETHERNET);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoDoubleCallbackRegistration() throws Exception {
|
||||
ConnectivityManager manager = new ConnectivityManager(mCtx, mService);
|
||||
NetworkRequest request = new NetworkRequest.Builder().clearCapabilities().build();
|
||||
NetworkCallback callback = new ConnectivityManager.NetworkCallback();
|
||||
ApplicationInfo info = new ApplicationInfo();
|
||||
info.targetSdkVersion = VERSION_CODES.N_MR1 + 1;
|
||||
|
||||
when(mCtx.getApplicationInfo()).thenReturn(info);
|
||||
when(mService.requestNetwork(any(), any(), anyInt(), any(), anyInt())).thenReturn(request);
|
||||
|
||||
manager.requestNetwork(request, callback);
|
||||
|
||||
// Callback is already registered, reregistration should fail.
|
||||
Class<IllegalArgumentException> wantException = IllegalArgumentException.class;
|
||||
expectThrowable(() -> manager.requestNetwork(request, callback), wantException);
|
||||
}
|
||||
|
||||
static void expectThrowable(Runnable block, Class<? extends Throwable> throwableType) {
|
||||
try {
|
||||
block.run();
|
||||
} catch (Throwable t) {
|
||||
if (t.getClass().equals(throwableType)) {
|
||||
return;
|
||||
}
|
||||
fail("expected exception of type " + throwableType + ", but was " + t.getClass());
|
||||
}
|
||||
fail("expected exception of type " + throwableType);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user