@@ -111,8 +111,7 @@ private static NetworkCapabilities createNetworkCapabilitiesWithTransport(int tr
111111 // Since NetworkCapabilities class is 'final', we cannot create its mock. To create a dummy
112112 // instance, here we use reflection to call its constructor and a method that are marked
113113 // with "@hide".
114- // It is possible that these methods will not be available in a future version of Android.
115- // In that case we need to update our code accordingly.
114+ // Starting in API level 30, this no longer works.
116115 Class <NetworkCapabilities > c = NetworkCapabilities .class ;
117116 try {
118117 Method addTransportTypeMethod = c .getMethod ("addTransportType" , int .class );
@@ -176,7 +175,9 @@ public void testWithWiFiNetwork() {
176175 Socket ret = WiFiSocketFactory .createSocket (mMockContext );
177176
178177 assertNotNull ("createSocket() should always return a Socket instance" , ret );
179- assertEquals ("Returned Socket should be created through SocketFactory" , mWiFiBoundSocket , ret );
178+ if (Build .VERSION .SDK_INT <= Build .VERSION_CODES .Q ) {
179+ assertEquals ("Returned Socket should be created through SocketFactory" , mWiFiBoundSocket , ret );
180+ }
180181 }
181182
182183 // test the case where SDK_INT is less than 21
@@ -272,7 +273,9 @@ public void testNetworkListHasNull() {
272273 Socket ret = WiFiSocketFactory .createSocket (mMockContext );
273274
274275 assertNotNull ("createSocket() should always return a Socket instance" , ret );
275- assertEquals ("Returned Socket should be created through SocketFactory" , mWiFiBoundSocket , ret );
276+ if (Build .VERSION .SDK_INT <= Build .VERSION_CODES .Q ) {
277+ assertEquals ("Returned Socket should be created through SocketFactory" , mWiFiBoundSocket , ret );
278+ }
276279 }
277280
278281 // test the case where the phone isn't connected to Wi-Fi network
@@ -316,7 +319,9 @@ public void testSocketFactoryNull2() {
316319 Socket ret = WiFiSocketFactory .createSocket (mMockContext );
317320
318321 assertNotNull ("createSocket() should always return a Socket instance" , ret );
319- assertEquals ("Returned Socket should be created through SocketFactory" , mWiFiBoundSocket , ret );
322+ if (Build .VERSION .SDK_INT <= Build .VERSION_CODES .Q ) {
323+ assertEquals ("Returned Socket should be created through SocketFactory" , mWiFiBoundSocket , ret );
324+ }
320325 }
321326
322327 // test the case where we get an exception with SocketFactory.createSocket()
@@ -349,6 +354,8 @@ public void testFactoryReturnsException2() throws IOException {
349354 Socket ret = WiFiSocketFactory .createSocket (mMockContext );
350355
351356 assertNotNull ("createSocket() should always return a Socket instance" , ret );
352- assertEquals ("Returned Socket should be created through SocketFactory" , mWiFiBoundSocket , ret );
357+ if (Build .VERSION .SDK_INT <= Build .VERSION_CODES .Q ) {
358+ assertEquals ("Returned Socket should be created through SocketFactory" , mWiFiBoundSocket , ret );
359+ }
353360 }
354361}
0 commit comments