From b0e21ab9af58e65eea042898468fa9139d5ff2dc Mon Sep 17 00:00:00 2001 From: lesl Date: Tue, 9 Mar 2021 23:50:11 +0800 Subject: [PATCH] Fix Wi-Fi SSID null handling When Wi-Fi SSID is null in NetworkCapabilities, get Wi-Fi SSID from connection info (WifiInfo) which is non-null design. Bug: 176396812 Test: FrameworksNetTests NetworkPolicyManagerServiceTest Change-Id: I59c7d8f7e176d0c6bb100721269f3f6165f0ca21 --- core/java/android/net/NetworkIdentity.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/core/java/android/net/NetworkIdentity.java b/core/java/android/net/NetworkIdentity.java index b037261f0b..1eef7d9a53 100644 --- a/core/java/android/net/NetworkIdentity.java +++ b/core/java/android/net/NetworkIdentity.java @@ -198,15 +198,11 @@ public class NetworkIdentity implements Comparable { final int oemManaged = getOemBitfield(snapshot.networkCapabilities); if (legacyType == TYPE_WIFI) { - if (snapshot.networkCapabilities.getSsid() != null) { - networkId = snapshot.networkCapabilities.getSsid(); - if (networkId == null) { - // TODO: Figure out if this code path never runs. If so, remove them. - final WifiManager wifi = (WifiManager) context.getSystemService( - Context.WIFI_SERVICE); - final WifiInfo info = wifi.getConnectionInfo(); - networkId = info != null ? info.getSSID() : null; - } + networkId = snapshot.networkCapabilities.getSsid(); + if (networkId == null) { + final WifiManager wifi = context.getSystemService(WifiManager.class); + final WifiInfo info = wifi.getConnectionInfo(); + networkId = info != null ? info.getSSID() : null; } }