Detect connection type through NetworkCapabilities on API 23+ - #992
Open
Madroid2 wants to merge 1 commit into
Open
Detect connection type through NetworkCapabilities on API 23+#992Madroid2 wants to merge 1 commit into
Madroid2 wants to merge 1 commit into
Conversation
NetworkConnectionInfoManager determined CELL vs WIFI from ConnectivityManager.getActiveNetworkInfo() and the ConnectivityManager.TYPE_* constants. NetworkInfo was deprecated in API 29 and the TYPE_* constants in API 28; on modern Android getActiveNetworkInfo() is a compatibility shim over the capabilities API and reports nothing useful for transports that have no legacy TYPE_ equivalent. From API 23 the type is now read from getActiveNetwork() plus getNetworkCapabilities(), using TRANSPORT_CELLULAR to distinguish CELL and NET_CAPABILITY_INTERNET as the equivalent of the old isConnected() check. minSdk is still below 23, so the NetworkInfo path is kept for older devices behind a version check and marked @SuppressWarnings("deprecation") so it stops producing build warnings for the whole class. The mapping is deliberately unchanged: a cellular transport reports CELL and any other active transport reports WIFI, exactly as the TYPE_MOBILE* check did before. This is an API modernisation, not a change to what the SDK sends in the bid request. The permission and null checks are hoisted to the top of getConnectionType() so both paths share them, and a missing ACCESS_NETWORK_STATE now returns OFFLINE explicitly rather than falling through the nested conditionals. Extends NetworkConnectionInfoManagerTest with the capabilities path at sdk 29 -- cellular, non-cellular, no active network, and missing permission. The existing sdk 19 test is untouched and still exercises the legacy branch. Partially addresses prebid#956 (network connection type). The location permission and display metrics items in that issue are handled separately.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change Log with reasoning
NetworkConnectionInfoManager determined CELL vs WIFI from ConnectivityManager.getActiveNetworkInfo() and the ConnectivityManager.TYPE_* constants. NetworkInfo was deprecated in API 29 and the TYPE_* constants in API 28; on modern Android getActiveNetworkInfo() is a compatibility shim over the capabilities API and reports nothing useful for transports that have no legacy TYPE_ equivalent.
From API 23 the type is now read from getActiveNetwork() plus getNetworkCapabilities(), using TRANSPORT_CELLULAR to distinguish CELL and NET_CAPABILITY_INTERNET as the equivalent of the old isConnected() check. minSdk is still below 23, so the NetworkInfo path is kept for older devices behind a version check and marked @SuppressWarnings("deprecation") so it stops producing build warnings for the whole class.
The mapping is deliberately unchanged: a cellular transport reports CELL and any other active transport reports WIFI, exactly as the TYPE_MOBILE* check did before. This is an API modernisation, not a change to what the SDK sends in the bid request.
The permission and null checks are hoisted to the top of getConnectionType() so both paths share them, and a missing ACCESS_NETWORK_STATE now returns OFFLINE explicitly rather than falling through the nested conditionals.
Extends NetworkConnectionInfoManagerTest with the capabilities path at sdk 29 -- cellular, non-cellular, no active network, and missing permission. The existing sdk 19 test is untouched and still exercises the legacy branch.
Partially addresses Deprecated API usage for device and user info #956 (network connection type). The location permission and display metrics items in that issue are handled separately.