diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/ConnectionUtil.java b/splunk-otel-android/src/main/java/com/splunk/rum/ConnectionUtil.java index d88c62f6..2c485f5d 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/ConnectionUtil.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/ConnectionUtil.java @@ -53,9 +53,14 @@ void startMonitoring(Supplier createNetworkMonitoringRequest, Co } CurrentNetwork refreshNetworkStatus() { - CurrentNetwork activeNetwork = networkDetector.detectCurrentNetwork(); - currentNetwork = activeNetwork; - return activeNetwork; + try { + currentNetwork = networkDetector.detectCurrentNetwork(); + } catch (Exception e) { + //guard against security issues/bugs when accessing the Android connectivityManager. + // see: https://issuetracker.google.com/issues/175055271 + currentNetwork = UNKNOWN_NETWORK; + } + return currentNetwork; } static NetworkRequest createNetworkMonitoringRequest() { diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/PostApi29NetworkDetector.java b/splunk-otel-android/src/main/java/com/splunk/rum/PostApi29NetworkDetector.java index 06481085..38bdbb4d 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/PostApi29NetworkDetector.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/PostApi29NetworkDetector.java @@ -16,6 +16,9 @@ package com.splunk.rum; +import static com.splunk.rum.ConnectionUtil.NO_NETWORK; +import static com.splunk.rum.ConnectionUtil.UNKNOWN_NETWORK; + import android.Manifest; import android.annotation.SuppressLint; import android.content.Context; @@ -28,9 +31,6 @@ import androidx.annotation.RequiresApi; import androidx.core.app.ActivityCompat; -import static com.splunk.rum.ConnectionUtil.NO_NETWORK; -import static com.splunk.rum.ConnectionUtil.UNKNOWN_NETWORK; - @RequiresApi(api = Build.VERSION_CODES.Q) class PostApi29NetworkDetector implements NetworkDetector { private final ConnectivityManager connectivityManager; diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/SimpleNetworkDetector.java b/splunk-otel-android/src/main/java/com/splunk/rum/SimpleNetworkDetector.java index 0d7e29ad..a1c4d025 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/SimpleNetworkDetector.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/SimpleNetworkDetector.java @@ -16,12 +16,12 @@ package com.splunk.rum; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; - import static com.splunk.rum.ConnectionUtil.NO_NETWORK; import static com.splunk.rum.ConnectionUtil.UNKNOWN_NETWORK; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; + class SimpleNetworkDetector implements NetworkDetector { private final ConnectivityManager connectivityManager; diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/ConnectionUtilTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/ConnectionUtilTest.java index c6bf0307..8348dee9 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/ConnectionUtilTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/ConnectionUtilTest.java @@ -122,6 +122,15 @@ public void quiznos() { assertEquals(2, notified.get()); } + @Test + public void networkDetectorException() { + NetworkDetector networkDetector = mock(NetworkDetector.class); + when(networkDetector.detectCurrentNetwork()).thenThrow(new SecurityException("bug")); + + ConnectionUtil connectionUtil = new ConnectionUtil(networkDetector); + assertEquals(ConnectionUtil.UNKNOWN_NETWORK, connectionUtil.refreshNetworkStatus()); + } + @Test @Config(sdk = Build.VERSION_CODES.LOLLIPOP) public void shouldNotFailOnImmediateConnectionManagerCall_lollipop() { diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/PostApi29NetworkDetectorTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/PostApi29NetworkDetectorTest.java index 548e59ce..6d7e22fc 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/PostApi29NetworkDetectorTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/PostApi29NetworkDetectorTest.java @@ -16,6 +16,10 @@ package com.splunk.rum; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import android.content.Context; import android.net.ConnectivityManager; import android.net.Network; @@ -28,10 +32,6 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - @RunWith(RobolectricTestRunner.class) @Config(sdk = Build.VERSION_CODES.Q) public class PostApi29NetworkDetectorTest { diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/SimpleNetworkDetectorTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/SimpleNetworkDetectorTest.java index 7fb4c444..4456bf10 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/SimpleNetworkDetectorTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/SimpleNetworkDetectorTest.java @@ -16,6 +16,10 @@ package com.splunk.rum; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; @@ -30,10 +34,6 @@ import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowNetworkInfo; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - @RunWith(RobolectricTestRunner.class) @Config(sdk = Build.VERSION_CODES.P) public class SimpleNetworkDetectorTest {