From e42fc5ff7624e666dbe8d067eb7b0be11161aaa6 Mon Sep 17 00:00:00 2001 From: junyulai Date: Fri, 8 Jan 2021 20:22:27 +0800 Subject: [PATCH] [FUI14] Get SSID from NetworkCapabilities This allows subsequent patches to remove the need of exposing SSID in NetworkState. Test: atest NetworkStatsServiceTest Bug: 174123988 Change-Id: Ib9ab07c9610954c9a5de035a3aefbf6d0bb0b53b --- core/java/android/net/NetworkIdentity.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/core/java/android/net/NetworkIdentity.java b/core/java/android/net/NetworkIdentity.java index a0dc72d4ad..b644ed56ad 100644 --- a/core/java/android/net/NetworkIdentity.java +++ b/core/java/android/net/NetworkIdentity.java @@ -194,13 +194,15 @@ public class NetworkIdentity implements Comparable { subscriberId = state.subscriberId; if (type == TYPE_WIFI) { - if (state.networkId != null) { - networkId = state.networkId; - } else { - final WifiManager wifi = (WifiManager) context.getSystemService( - Context.WIFI_SERVICE); - final WifiInfo info = wifi.getConnectionInfo(); - networkId = info != null ? info.getSSID() : null; + if (state.networkCapabilities.getSsid() != null) { + networkId = state.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; + } } }