From 640b9947b634973b2b0bee781d3688bd0e96543e Mon Sep 17 00:00:00 2001 From: jkwatson Date: Mon, 27 Sep 2021 10:02:57 -0700 Subject: [PATCH 1/6] Add try/catch around trying to access the connectivityManager APIs. See https://issuetracker.google.com/issues/175055271 for the root Android bug. --- .../splunk/rum/PostApi29NetworkDetector.java | 44 +++++++++++-------- .../com/splunk/rum/SimpleNetworkDetector.java | 38 +++++++++------- .../rum/PostApi29NetworkDetectorTest.java | 23 ++++++++-- .../splunk/rum/SimpleNetworkDetectorTest.java | 21 +++++++-- 4 files changed, 83 insertions(+), 43 deletions(-) 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..e14a0942 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; @@ -46,24 +46,30 @@ class PostApi29NetworkDetector implements NetworkDetector { @SuppressLint("MissingPermission") @Override public CurrentNetwork detectCurrentNetwork() { - NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(connectivityManager.getActiveNetwork()); - if (capabilities == null) { - return NO_NETWORK; - } - String subType = null; - if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) { - // If the app has the permission, use it to get a subtype. - if (hasPermission(Manifest.permission.READ_PHONE_STATE)) { - subType = getDataNetworkTypeName(telephonyManager.getDataNetworkType()); + try { + NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(connectivityManager.getActiveNetwork()); + if (capabilities == null) { + return NO_NETWORK; + } + String subType = null; + if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) { + // If the app has the permission, use it to get a subtype. + if (hasPermission(Manifest.permission.READ_PHONE_STATE)) { + subType = getDataNetworkTypeName(telephonyManager.getDataNetworkType()); + } + return new CurrentNetwork(NetworkState.TRANSPORT_CELLULAR, subType); + } else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { + return new CurrentNetwork(NetworkState.TRANSPORT_WIFI, null); + } else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) { + return new CurrentNetwork(NetworkState.TRANSPORT_VPN, null); } - return new CurrentNetwork(NetworkState.TRANSPORT_CELLULAR, subType); - } else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { - return new CurrentNetwork(NetworkState.TRANSPORT_WIFI, null); - } else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) { - return new CurrentNetwork(NetworkState.TRANSPORT_VPN, null); + //there is an active network, but it doesn't fall into the neat buckets above + return UNKNOWN_NETWORK; + } catch (Exception e) { + //guard against possible bugs/security issues with using the connectivityManager. + // see: https://issuetracker.google.com/issues/175055271 + return UNKNOWN_NETWORK; } - //there is an active network, but it doesn't fall into the neat buckets above - return UNKNOWN_NETWORK; } //visible for testing 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..d611125e 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; @@ -31,20 +31,26 @@ class SimpleNetworkDetector implements NetworkDetector { @Override public CurrentNetwork detectCurrentNetwork() { - NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); // Deprecated in API 29 - if (activeNetwork == null) { - return NO_NETWORK; - } - switch (activeNetwork.getType()) { - case ConnectivityManager.TYPE_MOBILE: // Deprecated in API 28 - return new CurrentNetwork(NetworkState.TRANSPORT_CELLULAR, activeNetwork.getSubtypeName()); - case ConnectivityManager.TYPE_WIFI: // Deprecated in API 28 - return new CurrentNetwork(NetworkState.TRANSPORT_WIFI, activeNetwork.getSubtypeName()); - case ConnectivityManager.TYPE_VPN: - return new CurrentNetwork(NetworkState.TRANSPORT_VPN, activeNetwork.getSubtypeName()); + try { + NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); // Deprecated in API 29 + if (activeNetwork == null) { + return NO_NETWORK; + } + switch (activeNetwork.getType()) { + case ConnectivityManager.TYPE_MOBILE: // Deprecated in API 28 + return new CurrentNetwork(NetworkState.TRANSPORT_CELLULAR, activeNetwork.getSubtypeName()); + case ConnectivityManager.TYPE_WIFI: // Deprecated in API 28 + return new CurrentNetwork(NetworkState.TRANSPORT_WIFI, activeNetwork.getSubtypeName()); + case ConnectivityManager.TYPE_VPN: + return new CurrentNetwork(NetworkState.TRANSPORT_VPN, activeNetwork.getSubtypeName()); + } + //there is an active network, but it doesn't fall into the neat buckets above + return UNKNOWN_NETWORK; + } catch (Exception e) { + //guard against security issues/bugs when accessing the connectivityManager. + // see: https://issuetracker.google.com/issues/175055271 + return UNKNOWN_NETWORK; } - //there is an active network, but it doesn't fall into the neat buckets above - return UNKNOWN_NETWORK; } } 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..5815b462 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 { @@ -51,6 +51,21 @@ public void none() { assertEquals(new CurrentNetwork(NetworkState.NO_NETWORK_AVAILABLE, null), currentNetwork); } + @Test + public void exception() { + ConnectivityManager connectivityManager = mock(ConnectivityManager.class); + TelephonyManager telephonyManager = mock(TelephonyManager.class); + Context context = mock(Context.class); + + Network network = mock(Network.class); + when(connectivityManager.getActiveNetwork()).thenReturn(network); + when(connectivityManager.getNetworkCapabilities(network)).thenThrow(new SecurityException("bug")); + + PostApi29NetworkDetector networkDetector = new PostApi29NetworkDetector(connectivityManager, telephonyManager, context); + CurrentNetwork currentNetwork = networkDetector.detectCurrentNetwork(); + assertEquals(new CurrentNetwork(NetworkState.TRANSPORT_UNKNOWN, null), currentNetwork); + } + @Test public void wifi() { ConnectivityManager connectivityManager = mock(ConnectivityManager.class); 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..4060bae9 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 { @@ -50,6 +50,19 @@ public void none() { assertEquals(new CurrentNetwork(NetworkState.NO_NETWORK_AVAILABLE, null), currentNetwork); } + @Test + public void exception() { + ConnectivityManager connectivityManager = + mock(ConnectivityManager.class); + + when(connectivityManager.getActiveNetworkInfo()).thenThrow(new SecurityException("bug")); + SimpleNetworkDetector networkDetector = new SimpleNetworkDetector(connectivityManager); + + CurrentNetwork currentNetwork = networkDetector.detectCurrentNetwork(); + + assertEquals(new CurrentNetwork(NetworkState.TRANSPORT_UNKNOWN, null), currentNetwork); + } + @Test public void other() { ConnectivityManager connectivityManager = From b8f9acee132417cf9a4acffca597aa25bd1ecec8 Mon Sep 17 00:00:00 2001 From: jkwatson Date: Mon, 27 Sep 2021 10:35:44 -0700 Subject: [PATCH 2/6] a small tweak from PR review --- .../src/main/java/com/splunk/rum/PostApi29NetworkDetector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e14a0942..5573686d 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 @@ -51,8 +51,8 @@ public CurrentNetwork detectCurrentNetwork() { if (capabilities == null) { return NO_NETWORK; } - String subType = null; if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) { + String subType = null; // If the app has the permission, use it to get a subtype. if (hasPermission(Manifest.permission.READ_PHONE_STATE)) { subType = getDataNetworkTypeName(telephonyManager.getDataNetworkType()); From ad67cc51390503783b74b920d2118729339132b7 Mon Sep 17 00:00:00 2001 From: jkwatson Date: Mon, 27 Sep 2021 11:35:19 -0700 Subject: [PATCH 3/6] catch the exception one layer higher for simplicity and clarity. --- .../java/com/splunk/rum/ConnectionUtil.java | 12 ++++-- .../splunk/rum/PostApi29NetworkDetector.java | 38 ++++++++----------- .../com/splunk/rum/SimpleNetworkDetector.java | 32 +++++++--------- .../com/splunk/rum/ConnectionUtilTest.java | 9 +++++ .../rum/PostApi29NetworkDetectorTest.java | 15 -------- .../splunk/rum/SimpleNetworkDetectorTest.java | 13 ------- 6 files changed, 47 insertions(+), 72 deletions(-) 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..29783e04 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,15 @@ void startMonitoring(Supplier createNetworkMonitoringRequest, Co } CurrentNetwork refreshNetworkStatus() { - CurrentNetwork activeNetwork = networkDetector.detectCurrentNetwork(); - currentNetwork = activeNetwork; - return activeNetwork; + CurrentNetwork activeNetwork; + try { + activeNetwork = networkDetector.detectCurrentNetwork(); + } catch (Exception e) { + //guard against security issues/bugs when accessing the Android connectivityManager. + // see: https://issuetracker.google.com/issues/175055271 + activeNetwork = UNKNOWN_NETWORK; + } + return currentNetwork = activeNetwork; } 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 5573686d..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 @@ -46,30 +46,24 @@ class PostApi29NetworkDetector implements NetworkDetector { @SuppressLint("MissingPermission") @Override public CurrentNetwork detectCurrentNetwork() { - try { - NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(connectivityManager.getActiveNetwork()); - if (capabilities == null) { - return NO_NETWORK; - } - if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) { - String subType = null; - // If the app has the permission, use it to get a subtype. - if (hasPermission(Manifest.permission.READ_PHONE_STATE)) { - subType = getDataNetworkTypeName(telephonyManager.getDataNetworkType()); - } - return new CurrentNetwork(NetworkState.TRANSPORT_CELLULAR, subType); - } else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { - return new CurrentNetwork(NetworkState.TRANSPORT_WIFI, null); - } else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) { - return new CurrentNetwork(NetworkState.TRANSPORT_VPN, null); + NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(connectivityManager.getActiveNetwork()); + if (capabilities == null) { + return NO_NETWORK; + } + String subType = null; + if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) { + // If the app has the permission, use it to get a subtype. + if (hasPermission(Manifest.permission.READ_PHONE_STATE)) { + subType = getDataNetworkTypeName(telephonyManager.getDataNetworkType()); } - //there is an active network, but it doesn't fall into the neat buckets above - return UNKNOWN_NETWORK; - } catch (Exception e) { - //guard against possible bugs/security issues with using the connectivityManager. - // see: https://issuetracker.google.com/issues/175055271 - return UNKNOWN_NETWORK; + return new CurrentNetwork(NetworkState.TRANSPORT_CELLULAR, subType); + } else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { + return new CurrentNetwork(NetworkState.TRANSPORT_WIFI, null); + } else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) { + return new CurrentNetwork(NetworkState.TRANSPORT_VPN, null); } + //there is an active network, but it doesn't fall into the neat buckets above + return UNKNOWN_NETWORK; } //visible for testing 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 d611125e..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 @@ -31,26 +31,20 @@ class SimpleNetworkDetector implements NetworkDetector { @Override public CurrentNetwork detectCurrentNetwork() { - try { - NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); // Deprecated in API 29 - if (activeNetwork == null) { - return NO_NETWORK; - } - switch (activeNetwork.getType()) { - case ConnectivityManager.TYPE_MOBILE: // Deprecated in API 28 - return new CurrentNetwork(NetworkState.TRANSPORT_CELLULAR, activeNetwork.getSubtypeName()); - case ConnectivityManager.TYPE_WIFI: // Deprecated in API 28 - return new CurrentNetwork(NetworkState.TRANSPORT_WIFI, activeNetwork.getSubtypeName()); - case ConnectivityManager.TYPE_VPN: - return new CurrentNetwork(NetworkState.TRANSPORT_VPN, activeNetwork.getSubtypeName()); - } - //there is an active network, but it doesn't fall into the neat buckets above - return UNKNOWN_NETWORK; - } catch (Exception e) { - //guard against security issues/bugs when accessing the connectivityManager. - // see: https://issuetracker.google.com/issues/175055271 - return UNKNOWN_NETWORK; + NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); // Deprecated in API 29 + if (activeNetwork == null) { + return NO_NETWORK; } + switch (activeNetwork.getType()) { + case ConnectivityManager.TYPE_MOBILE: // Deprecated in API 28 + return new CurrentNetwork(NetworkState.TRANSPORT_CELLULAR, activeNetwork.getSubtypeName()); + case ConnectivityManager.TYPE_WIFI: // Deprecated in API 28 + return new CurrentNetwork(NetworkState.TRANSPORT_WIFI, activeNetwork.getSubtypeName()); + case ConnectivityManager.TYPE_VPN: + return new CurrentNetwork(NetworkState.TRANSPORT_VPN, activeNetwork.getSubtypeName()); + } + //there is an active network, but it doesn't fall into the neat buckets above + return UNKNOWN_NETWORK; } } 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 5815b462..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 @@ -51,21 +51,6 @@ public void none() { assertEquals(new CurrentNetwork(NetworkState.NO_NETWORK_AVAILABLE, null), currentNetwork); } - @Test - public void exception() { - ConnectivityManager connectivityManager = mock(ConnectivityManager.class); - TelephonyManager telephonyManager = mock(TelephonyManager.class); - Context context = mock(Context.class); - - Network network = mock(Network.class); - when(connectivityManager.getActiveNetwork()).thenReturn(network); - when(connectivityManager.getNetworkCapabilities(network)).thenThrow(new SecurityException("bug")); - - PostApi29NetworkDetector networkDetector = new PostApi29NetworkDetector(connectivityManager, telephonyManager, context); - CurrentNetwork currentNetwork = networkDetector.detectCurrentNetwork(); - assertEquals(new CurrentNetwork(NetworkState.TRANSPORT_UNKNOWN, null), currentNetwork); - } - @Test public void wifi() { ConnectivityManager connectivityManager = mock(ConnectivityManager.class); 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 4060bae9..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 @@ -50,19 +50,6 @@ public void none() { assertEquals(new CurrentNetwork(NetworkState.NO_NETWORK_AVAILABLE, null), currentNetwork); } - @Test - public void exception() { - ConnectivityManager connectivityManager = - mock(ConnectivityManager.class); - - when(connectivityManager.getActiveNetworkInfo()).thenThrow(new SecurityException("bug")); - SimpleNetworkDetector networkDetector = new SimpleNetworkDetector(connectivityManager); - - CurrentNetwork currentNetwork = networkDetector.detectCurrentNetwork(); - - assertEquals(new CurrentNetwork(NetworkState.TRANSPORT_UNKNOWN, null), currentNetwork); - } - @Test public void other() { ConnectivityManager connectivityManager = From bc95ca6dce3f7ef45cfa2417db0f3d11d0490c62 Mon Sep 17 00:00:00 2001 From: jkwatson Date: Mon, 27 Sep 2021 11:38:03 -0700 Subject: [PATCH 4/6] small tweak --- .../src/main/java/com/splunk/rum/ConnectionUtil.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 29783e04..9fdaa52b 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 @@ -61,7 +61,8 @@ CurrentNetwork refreshNetworkStatus() { // see: https://issuetracker.google.com/issues/175055271 activeNetwork = UNKNOWN_NETWORK; } - return currentNetwork = activeNetwork; + currentNetwork = activeNetwork; + return currentNetwork; } static NetworkRequest createNetworkMonitoringRequest() { From 25f23ee4b75b9e1d7862d493e07b0dd9cf705d12 Mon Sep 17 00:00:00 2001 From: jkwatson Date: Mon, 27 Sep 2021 12:20:59 -0700 Subject: [PATCH 5/6] small tweak 2 --- .../src/main/java/com/splunk/rum/ConnectionUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9fdaa52b..2bc74a1d 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 @@ -62,7 +62,7 @@ CurrentNetwork refreshNetworkStatus() { activeNetwork = UNKNOWN_NETWORK; } currentNetwork = activeNetwork; - return currentNetwork; + return activeNetwork; } static NetworkRequest createNetworkMonitoringRequest() { From c4bdcdde4dbda5c39adf65cd41b491ec6107a8de Mon Sep 17 00:00:00 2001 From: jkwatson Date: Mon, 27 Sep 2021 12:57:47 -0700 Subject: [PATCH 6/6] remove unneeded local var --- .../src/main/java/com/splunk/rum/ConnectionUtil.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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 2bc74a1d..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,16 +53,14 @@ void startMonitoring(Supplier createNetworkMonitoringRequest, Co } CurrentNetwork refreshNetworkStatus() { - CurrentNetwork activeNetwork; try { - activeNetwork = networkDetector.detectCurrentNetwork(); + currentNetwork = networkDetector.detectCurrentNetwork(); } catch (Exception e) { //guard against security issues/bugs when accessing the Android connectivityManager. // see: https://issuetracker.google.com/issues/175055271 - activeNetwork = UNKNOWN_NETWORK; + currentNetwork = UNKNOWN_NETWORK; } - currentNetwork = activeNetwork; - return activeNetwork; + return currentNetwork; } static NetworkRequest createNetworkMonitoringRequest() {