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

fix(network_info_plus): Get SSID on Android 12 and newer #1231

Merged
merged 2 commits into from
Oct 13, 2022

Conversation

vbuberen
Copy link
Collaborator

Description

As it turned out in Android 12 and newer SSID and BSSID are considered a location sensitive info, thus the new API to get WifiInfo via getNetworkCapabilities() returned all info except these 2 values. And it doesn't matter that app has required permissions. Explanation is provided in the official docs:
https://developer.android.com/reference/android/net/ConnectivityManager#getNetworkCapabilities(android.net.Network)

The suggested way to register a callback with required flag seems not the best option for the network_info_plus as we want to get info on demand, not wait till something changes in network configuration.

It seems we are not the only ones, who issue this problem: https://stackoverflow.com/questions/71281724/getting-wifi-ssid-from-connectivitymanager-networkcapabilities-synchronously

Based on the info above I decided to revert one of changes I made in #1151 and rely on deprecated function to get needed required info. I think we are safe to live till time comes to kill this deprecated API in next Android releases. However, hope that Google introduces some better API to not have only callbacks way.

Related Issues

Closes #1181

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I titled the PR using Conventional Commits.
  • I did not modify the CHANGELOG.md nor the pubspec.yaml files.
  • All existing and new tests are passing.
  • The analyzer (flutter analyze) does not report any problems on my PR.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate that with a ! in the title as explained in Conventional Commits).
  • No, this is not a breaking change.

@vbuberen vbuberen merged commit 40d7e13 into main Oct 13, 2022
@vbuberen vbuberen deleted the fix/network_info_android_13 branch October 13, 2022 11:53
@miquelbeltran miquelbeltran added the Hacktoberfest Issues taking part in Hacktoberfest label Oct 13, 2022
@kostadin24
Copy link

Is this fixing BSSID also?

@vbuberen
Copy link
Collaborator Author

vbuberen commented Oct 22, 2022

Is this fixing BSSID also?

Yes. It is mentioned in the PR description if you read it carefully.

@DaYang816
Copy link

DaYang816 commented Dec 13, 2022

Give user positioning permissions why you can't get SSID?
SSID = NULL
BSSID = 02:00:00:00:00:00
Positioning permissions I requested according to the Permission_handler plug -in.
Access_network_State does this require the user's consent?

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Future<void> setNetwork() async {
final info = NetworkInfo();
var locationStatus = await Permission.location.status;
if (locationStatus.isDenied) {
  await Permission.locationWhenInUse.request();
}
if (await Permission.location.isRestricted) {
  openAppSettings();
}

if (await Permission.location.isGranted) {
  var wifiName = await info.getWifiName();
  log('wifiName $wifiName');
  }
}

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: getWifiName() return null on Android 13
4 participants