Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network Type may not be being verified in project #12

Open
amazuerar opened this issue Aug 15, 2021 · 0 comments
Open

Network Type may not be being verified in project #12

amazuerar opened this issue Aug 15, 2021 · 0 comments

Comments

@amazuerar
Copy link

Dear Developer!

My name is Alejandro Mazuera-Rozo, I am a PhD Student at Universidad de los Andes, and at Università della Svizzera italiana. I am part of a research on the usage of network libraries within android apps. As a result of this we identified some code locations that might have network related problems.

In this case, we present the code locations that are related to a missing validation of network type within the project since some network operations are being performed in the project. As you might know, a device can have various types of network connections. For the full list of possible network types, see https://developer.android.com/reference/android/net/ConnectivityManager. Therefore it is recommended for the app to identify the type of network available before performing a network operation.

In order to address this issue we recommend you to visit:

  1. https://developer.android.com/training/basics/network-ops/managing
  2. https://developer.android.com/training/efficient-downloads/connectivity_patterns

Potential Code Location without Network type validation

Despite the fact the verification of WIFI exists by using getTypeName(), this approach was deprecated in API level 28. Applications should instead use NetworkCapabilities#hasTransport or requestNetwork(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback) to request an appropriate network.

final NetworkInfo ni = cm.getNetworkInfo(network);
if (ni.getTypeName().equalsIgnoreCase("WIFI")) {
if (ni.isConnected()) {
hasWifi = true;
}

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

No branches or pull requests

1 participant