Commit ed90e451 authored by Tarun Bansal's avatar Tarun Bansal Committed by Commit Bot

Update AndroidNetworkLibrary getSSID function to handle lack of permissions.

getSSID on Android may return a special pre-defined string if the app
does not have permissions to get the SSID.

In that case, the method returns an empty string.

Change-Id: I58c99301b4d611124c8434e93fd787edbec32da3
Bug: 827212
Reviewed-on: https://chromium-review.googlesource.com/987306Reviewed-by: default avatarPaul Jensen <pauljensen@chromium.org>
Commit-Queue: Tarun Bansal <tbansal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548650}
parent 041244a9
...@@ -213,8 +213,11 @@ class AndroidNetworkLibrary { ...@@ -213,8 +213,11 @@ class AndroidNetworkLibrary {
} }
/** /**
* Gets the SSID of the currently associated WiFi access point if there is one. Otherwise, * Gets the SSID of the currently associated WiFi access point if there is one, and it is
* returns empty string. * available. SSID may not be available if the app does not have permissions to access it. On
* Android M+, the app accessing SSID needs to have ACCESS_COARSE_LOCATION or
* ACCESS_FINE_LOCATION. If there is no WiFi access point or its SSID is unavailable, an empty
* string is returned.
*/ */
@CalledByNative @CalledByNative
public static String getWifiSSID() { public static String getWifiSSID() {
...@@ -224,7 +227,9 @@ class AndroidNetworkLibrary { ...@@ -224,7 +227,9 @@ class AndroidNetworkLibrary {
final WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO); final WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
if (wifiInfo != null) { if (wifiInfo != null) {
final String ssid = wifiInfo.getSSID(); final String ssid = wifiInfo.getSSID();
if (ssid != null) { // On Android M+, the platform APIs may return "<unknown ssid>" as the SSID if the
// app does not have sufficient permissions. In that case, return an empty string.
if (ssid != null && !ssid.equals("<unknown ssid>")) {
return ssid; return ssid;
} }
} }
......
...@@ -77,8 +77,11 @@ NET_EXPORT bool GetIsRoaming(); ...@@ -77,8 +77,11 @@ NET_EXPORT bool GetIsRoaming();
// Marshmallow and later versions. Returns false on earlier versions. // Marshmallow and later versions. Returns false on earlier versions.
NET_EXPORT bool GetIsCaptivePortal(); NET_EXPORT bool GetIsCaptivePortal();
// Gets the SSID of the currently associated WiFi access point if there is one. // Gets the SSID of the currently associated WiFi access point if there is one,
// Otherwise, returns empty string. // and it is available. SSID may not be available if the app does not have
// permissions to access it. On Android M+, the app accessing SSID needs to have
// ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION. If there is no WiFi access
// point or its SSID is unavailable, an empty string is returned.
NET_EXPORT_PRIVATE std::string GetWifiSSID(); NET_EXPORT_PRIVATE std::string GetWifiSSID();
// Gets the DNS servers and puts them in |dns_servers|. // Gets the DNS servers and puts them in |dns_servers|.
......
...@@ -86,8 +86,11 @@ enum HostAddressSelectionPolicy { ...@@ -86,8 +86,11 @@ enum HostAddressSelectionPolicy {
NET_EXPORT bool GetNetworkList(NetworkInterfaceList* networks, NET_EXPORT bool GetNetworkList(NetworkInterfaceList* networks,
int policy); int policy);
// Gets the SSID of the currently associated WiFi access point if there is one. // Gets the SSID of the currently associated WiFi access point if there is one,
// Otherwise, returns empty string. // and it is available. SSID may not be available if the app does not have
// permissions to access it. On Android M+, the app accessing SSID needs to have
// ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION. If there is no WiFi access
// point or its SSID is unavailable, an empty string is returned.
// Currently only implemented on Linux, ChromeOS, Android and Windows. // Currently only implemented on Linux, ChromeOS, Android and Windows.
NET_EXPORT std::string GetWifiSSID(); NET_EXPORT std::string GetWifiSSID();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment