android / android/nowinandroid

Missing implementation of NET_CAPABILITY_VALIDATED in ConnectivityManager

Open
#1,290 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
Kotlin
Stars
21.8k
Forks
4.6k
Avg merge
19h 20m
Merged PRs (30d)
2

Description

**The current implementation of ConnectivityManager.isCurrentlyConnected() does not check for the NET_CAPABILITY_VALIDATED capability, leading to incorrect behavior when determining network connectivity status.**

Steps to Reproduce:

- Connect to a Wi-Fi network or cellular network that requires login/authentication but does not have internet access.
- Observe that the app does not display a Snackbar or any indication of lack of internet access.
- Expected Behavior:
- The app should detect that the network does not have internet access and display a Snackbar or some form of notification to inform the user.
**I propose updating the isCurrentlyConnected() function in ConnectivityManager to include a check for the NET_CAPABILITY_VALIDATED capability. Here's the modified code:**

`private fun ConnectivityManager.isCurrentlyConnected() = when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> {
activeNetwork
?.let { network ->
getNetworkCapabilities(network)?.let { capabilities ->
capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) &&
capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)
}
} ?: false
}
else -> activeNetworkInfo?.isConnected ?: false
}`

` val networkCapabilities = connectivityManager.getNetworkCapabilities(network)
val hasInternetCapability =
networkCapabilities?.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)
if (hasInternetCapability == true) {
networks += network
channel.trySend(true)
}`

Contributor guide

Open the contributing guide

Research direction

Locate ConnectivityManager.isCurrentlyConnected() and the connectivity-monitoring entry point described in the issue. Compare the current capability checks with the proposed NET_CAPABILITY_VALIDATED behavior, then reproduce the authenticated Wi-Fi or cellular case and verify that the app reports the lack of internet access.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
mobile-dev, networking
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.