[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
This commit is contained in:
junyulai
2021-01-08 20:22:27 +08:00
parent 1f69d15939
commit c44d11ccec

View File

@@ -194,15 +194,17 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
subscriberId = state.subscriberId; subscriberId = state.subscriberId;
if (type == TYPE_WIFI) { if (type == TYPE_WIFI) {
if (state.networkId != null) { if (state.networkCapabilities.getSsid() != null) {
networkId = state.networkId; networkId = state.networkCapabilities.getSsid();
} else { if (networkId == null) {
// TODO: Figure out if this code path never runs. If so, remove them.
final WifiManager wifi = (WifiManager) context.getSystemService( final WifiManager wifi = (WifiManager) context.getSystemService(
Context.WIFI_SERVICE); Context.WIFI_SERVICE);
final WifiInfo info = wifi.getConnectionInfo(); final WifiInfo info = wifi.getConnectionInfo();
networkId = info != null ? info.getSSID() : null; networkId = info != null ? info.getSSID() : null;
} }
} }
}
return new NetworkIdentity(type, subType, subscriberId, networkId, roaming, metered, return new NetworkIdentity(type, subType, subscriberId, networkId, roaming, metered,
defaultNetwork); defaultNetwork);