Skip to content

Detect connection type through NetworkCapabilities on API 23+ - #992

Open
Madroid2 wants to merge 1 commit into
prebid:masterfrom
Madroid2:fix/network-connection-deprecated-api-956
Open

Detect connection type through NetworkCapabilities on API 23+#992
Madroid2 wants to merge 1 commit into
prebid:masterfrom
Madroid2:fix/network-connection-deprecated-api-956

Conversation

@Madroid2

@Madroid2 Madroid2 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant