@@ -111,8 +111,7 @@ private static NetworkCapabilities createNetworkCapabilitiesWithTransport(int tr
111
111
// Since NetworkCapabilities class is 'final', we cannot create its mock. To create a dummy
112
112
// instance, here we use reflection to call its constructor and a method that are marked
113
113
// 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.
116
115
Class <NetworkCapabilities > c = NetworkCapabilities .class ;
117
116
try {
118
117
Method addTransportTypeMethod = c .getMethod ("addTransportType" , int .class );
@@ -176,7 +175,9 @@ public void testWithWiFiNetwork() {
176
175
Socket ret = WiFiSocketFactory .createSocket (mMockContext );
177
176
178
177
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
+ }
180
181
}
181
182
182
183
// test the case where SDK_INT is less than 21
@@ -272,7 +273,9 @@ public void testNetworkListHasNull() {
272
273
Socket ret = WiFiSocketFactory .createSocket (mMockContext );
273
274
274
275
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
+ }
276
279
}
277
280
278
281
// test the case where the phone isn't connected to Wi-Fi network
@@ -316,7 +319,9 @@ public void testSocketFactoryNull2() {
316
319
Socket ret = WiFiSocketFactory .createSocket (mMockContext );
317
320
318
321
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
+ }
320
325
}
321
326
322
327
// test the case where we get an exception with SocketFactory.createSocket()
@@ -349,6 +354,8 @@ public void testFactoryReturnsException2() throws IOException {
349
354
Socket ret = WiFiSocketFactory .createSocket (mMockContext );
350
355
351
356
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
+ }
353
360
}
354
361
}
0 commit comments