Skip to content

Commit

Permalink
Handle wired network transport type (#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaciejCzekanski authored Oct 31, 2024
1 parent c0ce0ea commit c0cea66
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum NetworkState {
NO_NETWORK_AVAILABLE(NetworkConnectionTypeValues.UNAVAILABLE),
TRANSPORT_CELLULAR(NetworkConnectionTypeValues.CELL),
TRANSPORT_WIFI(NetworkConnectionTypeValues.WIFI),
TRANSPORT_WIRED(NetworkConnectionTypeValues.WIRED),
TRANSPORT_UNKNOWN(NetworkConnectionTypeValues.UNKNOWN),
// this one doesn't seem to have an otel value at this point.
TRANSPORT_VPN("vpn");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public CurrentNetwork detectCurrentNetwork() {
return CurrentNetwork.builder(NetworkState.TRANSPORT_VPN)
.subType(activeNetwork.getSubtypeName())
.build();
case ConnectivityManager.TYPE_ETHERNET:
return CurrentNetwork.builder(NetworkState.TRANSPORT_WIRED)
.subType(activeNetwork.getSubtypeName())
.build();
}
// there is an active network, but it doesn't fall into the neat buckets above
return UNKNOWN_NETWORK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,30 @@ public void vpn() {
CurrentNetwork.builder(NetworkState.TRANSPORT_VPN).build(), currentNetwork);
}

@Test
public void wired() {
ConnectivityManager connectivityManager =
(ConnectivityManager)
ApplicationProvider.getApplicationContext()
.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo networkInfo =
ShadowNetworkInfo.newInstance(
NetworkInfo.DetailedState.CONNECTED,
ConnectivityManager.TYPE_ETHERNET,
0,
true,
NetworkInfo.State.CONNECTED);
Shadows.shadowOf(connectivityManager).setActiveNetworkInfo(networkInfo);

SimpleNetworkDetector networkDetector = new SimpleNetworkDetector(connectivityManager);

CurrentNetwork currentNetwork = networkDetector.detectCurrentNetwork();

Assert.assertEquals(
CurrentNetwork.builder(NetworkState.TRANSPORT_WIRED).build(), currentNetwork);
}

@Test
public void cellularWithSubtype() {
ConnectivityManager connectivityManager =
Expand Down

0 comments on commit c0cea66

Please sign in to comment.