diff options
author | Quang Luong <qal@google.com> | 2020-01-06 18:14:25 -0800 |
---|---|---|
committer | Quang Luong <qal@google.com> | 2020-01-08 17:36:49 -0800 |
commit | 059413165f41ac22f6ffd290fc649044252d043b (patch) | |
tree | 3612567abffa01de34b5c8beea48c560df3c35b5 | |
parent | 79648dfaf0f3e3902ea8d1ac4c46fc81f9550184 (diff) |
Implement WifiEntry.getConnectedInfo()
Implemented getConnectedInfo() for all WifiEntry types. This data will appear under Network Details in the Network Details Page.
Test: atest WifiTrackerLibTests
Bug: 70983952
Change-Id: Idaffbd88584eb48474bb03ee476ede28049ca079
7 files changed, 249 insertions, 74 deletions
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java index 28a2eb652..e52622e3c 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java @@ -16,11 +16,16 @@ package com.android.wifitrackerlib; +import static android.net.NetworkCapabilities.TRANSPORT_WIFI; + import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.ConnectivityManager; +import android.net.LinkProperties; +import android.net.Network; +import android.net.NetworkRequest; import android.net.NetworkScoreManager; import android.net.wifi.WifiManager; import android.os.Handler; @@ -30,6 +35,7 @@ import android.util.Log; import androidx.annotation.AnyThread; import androidx.annotation.MainThread; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; @@ -118,6 +124,18 @@ public class BaseWifiTracker implements LifecycleObserver { protected final long mScanIntervalMillis; protected final ScanResultUpdater mScanResultUpdater; + // Network request for listening on changes to Wifi link properties. + private final NetworkRequest mNetworkRequest = new NetworkRequest.Builder() + .clearCapabilities().addTransportType(TRANSPORT_WIFI).build(); + + private final ConnectivityManager.NetworkCallback mNetworkCallback = + new ConnectivityManager.NetworkCallback() { + @Override + public void onLinkPropertiesChanged(Network network, LinkProperties lp) { + handleLinkPropertiesChanged(lp); + } + }; + /** * Constructor for BaseWifiTracker. * @@ -175,6 +193,8 @@ public class BaseWifiTracker implements LifecycleObserver { filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); mContext.registerReceiver(mBroadcastReceiver, filter, /* broadcastPermission */ null, mWorkerHandler); + mConnectivityManager.registerNetworkCallback(mNetworkRequest, mNetworkCallback, + mWorkerHandler); if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED) { mScanner.start(); } else { @@ -192,6 +212,7 @@ public class BaseWifiTracker implements LifecycleObserver { // TODO (b/70983952): Unregister score cache and receivers for network callbacks. mScanner.stop(); mContext.unregisterReceiver(mBroadcastReceiver); + mConnectivityManager.unregisterNetworkCallback(mNetworkCallback); } /** @@ -249,6 +270,11 @@ public class BaseWifiTracker implements LifecycleObserver { // Do nothing. }; + @WorkerThread + protected void handleLinkPropertiesChanged(@Nullable LinkProperties linkProperties) { + // Do nothing. + }; + /** * Scanner to handle starting scans every SCAN_INTERVAL_MILLIS */ diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java index e83c519d5..68d7adc8a 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java @@ -320,6 +320,17 @@ class PasspointWifiEntry extends WifiEntry { notifyOnUpdated(); } + @WorkerThread + @Override + protected boolean connectionInfoMatches(@NonNull WifiInfo wifiInfo, + @NonNull NetworkInfo networkInfo) { + if (!wifiInfo.isPasspointAp()) { + return false; + } + + return mWifiConfig != null && mWifiConfig.networkId == wifiInfo.getNetworkId(); + } + @NonNull static String fqdnToPasspointWifiEntryKey(@NonNull String fqdn) { checkNotNull(fqdn, "Cannot create key with null fqdn!"); diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java index 3f0870dad..6190b98ce 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java @@ -20,12 +20,14 @@ import static androidx.core.util.Preconditions.checkNotNull; import static com.android.wifitrackerlib.StandardWifiEntry.scanResultToStandardWifiEntryKey; import static com.android.wifitrackerlib.StandardWifiEntry.wifiConfigToStandardWifiEntryKey; +import static com.android.wifitrackerlib.WifiEntry.CONNECTED_STATE_CONNECTED; import static java.util.stream.Collectors.toList; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; +import android.net.LinkProperties; import android.net.NetworkInfo; import android.net.NetworkScoreManager; import android.net.wifi.WifiConfiguration; @@ -71,6 +73,8 @@ class StandardNetworkDetailsTracker extends NetworkDetailsTracker { final WifiInfo wifiInfo = mWifiManager.getConnectionInfo(); final NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo(); mChosenEntry.updateConnectionInfo(wifiInfo, networkInfo); + handleLinkPropertiesChanged(mConnectivityManager.getLinkProperties( + mWifiManager.getCurrentNetwork())); } @AnyThread @@ -123,6 +127,14 @@ class StandardNetworkDetailsTracker extends NetworkDetailsTracker { (NetworkInfo) intent.getExtra(WifiManager.EXTRA_NETWORK_INFO)); } + @WorkerThread + @Override + protected void handleLinkPropertiesChanged(@NonNull LinkProperties linkProperties) { + if (mChosenEntry.getConnectedState() == CONNECTED_STATE_CONNECTED) { + mChosenEntry.updateLinkProperties(linkProperties); + } + } + /** * Updates the tracked entry's scan results up to the max scan age (or more, if the last scan * was unsuccessful). If Wifi is disabled, the tracked entry's level will be cleared. diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java index d4b01b20a..54dddcb8e 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java @@ -16,7 +16,6 @@ package com.android.wifitrackerlib; -import static android.net.wifi.WifiInfo.INVALID_RSSI; import static android.net.wifi.WifiInfo.removeDoubleQuotes; import static androidx.core.util.Preconditions.checkNotNull; @@ -55,15 +54,9 @@ class StandardWifiEntry extends WifiEntry { @NonNull private final String mSsid; private final @Security int mSecurity; @Nullable private WifiConfiguration mWifiConfig; - @Nullable private NetworkInfo mNetworkInfo; - @Nullable private WifiInfo mWifiInfo; @Nullable private ConnectCallback mConnectCallback; @Nullable private DisconnectCallback mDisconnectCallback; @Nullable private ForgetCallback mForgetCallback; - private boolean mCalledConnect = false; - private boolean mCalledDisconnect = false; - - private int mLevel = WIFI_LEVEL_UNREACHABLE; StandardWifiEntry(@NonNull Handler callbackHandler, @NonNull List<ScanResult> scanResults, @NonNull WifiManager wifiManager) throws IllegalArgumentException { @@ -117,28 +110,6 @@ class StandardWifiEntry extends WifiEntry { } @Override - @ConnectedState - public int getConnectedState() { - if (mNetworkInfo == null) { - return CONNECTED_STATE_DISCONNECTED; - } - - switch (mNetworkInfo.getDetailedState()) { - case SCANNING: - case CONNECTING: - case AUTHENTICATING: - case OBTAINING_IPADDR: - case VERIFYING_POOR_LINK: - case CAPTIVE_PORTAL_CHECK: - return CONNECTED_STATE_CONNECTING; - case CONNECTED: - return CONNECTED_STATE_CONNECTED; - default: - return CONNECTED_STATE_DISCONNECTED; - } - } - - @Override public String getTitle() { return mSsid; } @@ -208,8 +179,7 @@ class StandardWifiEntry extends WifiEntry { @Override public ConnectedInfo getConnectedInfo() { - // TODO(b/70983952): Fill this method in - return null; + return mConnectedInfo; } @Override @@ -503,42 +473,14 @@ class StandardWifiEntry extends WifiEntry { notifyOnUpdated(); } - /** - * Updates information regarding the current network connection. If the supplied WifiInfo and - * NetworkInfo do not represent this WifiEntry, then the WifiEntry will update to be - * unconnected. - */ @WorkerThread - void updateConnectionInfo(@Nullable WifiInfo wifiInfo, @Nullable NetworkInfo networkInfo) { - if (mWifiConfig != null && wifiInfo != null - && mWifiConfig.networkId == wifiInfo.getNetworkId()) { - mNetworkInfo = networkInfo; - mWifiInfo = wifiInfo; - final int wifiInfoRssi = wifiInfo.getRssi(); - if (wifiInfoRssi != INVALID_RSSI) { - mLevel = mWifiManager.calculateSignalLevel(wifiInfoRssi); - } - if (mCalledConnect && getConnectedState() == CONNECTED_STATE_CONNECTED) { - mCalledConnect = false; - mCallbackHandler.post(() -> { - if (mConnectCallback != null) { - mConnectCallback.onConnectResult(ConnectCallback.CONNECT_STATUS_SUCCESS); - } - }); - } - } else { - mNetworkInfo = null; - } - if (mCalledDisconnect && getConnectedState() == CONNECTED_STATE_DISCONNECTED) { - mCalledDisconnect = false; - mCallbackHandler.post(() -> { - if (mDisconnectCallback != null) { - mDisconnectCallback.onDisconnectResult( - DisconnectCallback.DISCONNECT_STATUS_SUCCESS); - } - }); + protected boolean connectionInfoMatches(@NonNull WifiInfo wifiInfo, + @NonNull NetworkInfo networkInfo) { + if (wifiInfo.isPasspointAp() || wifiInfo.isOsuAp()) { + return false; } - notifyOnUpdated(); + + return mWifiConfig != null && mWifiConfig.networkId == wifiInfo.getNetworkId(); } @NonNull diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java index 4752e8449..08801d045 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java @@ -16,9 +16,17 @@ package com.android.wifitrackerlib; +import static android.net.wifi.WifiInfo.INVALID_RSSI; + import static androidx.core.util.Preconditions.checkNotNull; +import android.net.LinkAddress; +import android.net.LinkProperties; +import android.net.NetworkInfo; +import android.net.NetworkUtils; +import android.net.RouteInfo; import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Handler; @@ -27,10 +35,17 @@ import androidx.annotation.IntDef; import androidx.annotation.MainThread; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.WorkerThread; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.net.Inet4Address; +import java.net.Inet6Address; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; /** * Abstract base class for an entry representing a Wi-Fi network in a Wi-Fi picker/settings. @@ -136,6 +151,17 @@ public abstract class WifiEntry implements Comparable<WifiEntry> { private WifiEntryCallback mListener; protected Handler mCallbackHandler; + protected int mLevel = WIFI_LEVEL_UNREACHABLE; + protected WifiInfo mWifiInfo; + protected NetworkInfo mNetworkInfo; + protected ConnectedInfo mConnectedInfo; + + protected ConnectCallback mConnectCallback; + protected DisconnectCallback mDisconnectCallback; + + protected boolean mCalledConnect = false; + protected boolean mCalledDisconnect = false; + WifiEntry(@NonNull Handler callbackHandler, boolean forSavedNetworksPage, @NonNull WifiManager wifiManager) throws IllegalArgumentException { checkNotNull(callbackHandler, "Cannot construct with null handler!"); @@ -152,7 +178,26 @@ public abstract class WifiEntry implements Comparable<WifiEntry> { /** Returns connection state of the network defined by the CONNECTED_STATE constants */ @ConnectedState - public abstract int getConnectedState(); + public int getConnectedState() { + if (mNetworkInfo == null) { + return CONNECTED_STATE_DISCONNECTED; + } + + switch (mNetworkInfo.getDetailedState()) { + case SCANNING: + case CONNECTING: + case AUTHENTICATING: + case OBTAINING_IPADDR: + case VERIFYING_POOR_LINK: + case CAPTIVE_PORTAL_CHECK: + return CONNECTED_STATE_CONNECTING; + case CONNECTED: + return CONNECTED_STATE_CONNECTED; + default: + return CONNECTED_STATE_DISCONNECTED; + } + } + /** Returns the display title. This is most commonly the SSID of a network. */ public abstract String getTitle(); @@ -206,7 +251,9 @@ public abstract class WifiEntry implements Comparable<WifiEntry> { * * Returns null if getConnectedState() != CONNECTED_STATE_CONNECTED. */ - public abstract ConnectedInfo getConnectedInfo(); + public ConnectedInfo getConnectedInfo() { + return mConnectedInfo; + } /** * Info associated with the active connection. @@ -214,10 +261,10 @@ public abstract class WifiEntry implements Comparable<WifiEntry> { public static class ConnectedInfo { @Frequency public int frequencyMhz; - public List<String> dnsServers; + public List<String> dnsServers = new ArrayList<>(); public int linkSpeedMbps; public String ipAddress; - public List<String> ipv6Addresses; + public List<String> ipv6Addresses = new ArrayList<>(); public String gateway; public String subnetMask; } @@ -408,6 +455,105 @@ public abstract class WifiEntry implements Comparable<WifiEntry> { void onSignInResult(@SignInStatus int status); } + /** + * Returns whether or not the supplied WifiInfo and NetworkInfo represent this WifiEntry + */ + protected abstract boolean connectionInfoMatches(@NonNull WifiInfo wifiInfo, + @NonNull NetworkInfo networkInfo); + + /** + * Updates information regarding the current network connection. If the supplied WifiInfo and + * NetworkInfo do not match this WifiEntry, then the WifiEntry will update to be + * unconnected. + */ + @WorkerThread + void updateConnectionInfo(@Nullable WifiInfo wifiInfo, @Nullable NetworkInfo networkInfo) { + if (wifiInfo != null && networkInfo != null + && connectionInfoMatches(wifiInfo, networkInfo)) { + // Connection info matches, so the WifiInfo/NetworkInfo represent this network and + // the network is currently connecting or connected. + mWifiInfo = wifiInfo; + mNetworkInfo = networkInfo; + final int wifiInfoRssi = wifiInfo.getRssi(); + if (wifiInfoRssi != INVALID_RSSI) { + mLevel = mWifiManager.calculateSignalLevel(wifiInfoRssi); + } + if (getConnectedState() == CONNECTED_STATE_CONNECTED) { + if (mCalledConnect) { + mCalledConnect = false; + mCallbackHandler.post(() -> { + if (mConnectCallback != null) { + mConnectCallback.onConnectResult( + ConnectCallback.CONNECT_STATUS_SUCCESS); + } + }); + } + + if (mConnectedInfo == null) { + mConnectedInfo = new ConnectedInfo(); + } + mConnectedInfo.frequencyMhz = wifiInfo.getFrequency(); + mConnectedInfo.linkSpeedMbps = wifiInfo.getLinkSpeed(); + } + } else { // Connection info doesn't matched, so this network is disconnected + mNetworkInfo = null; + mConnectedInfo = null; + if (mCalledDisconnect) { + mCalledDisconnect = false; + mCallbackHandler.post(() -> { + if (mDisconnectCallback != null) { + mDisconnectCallback.onDisconnectResult( + DisconnectCallback.DISCONNECT_STATUS_SUCCESS); + } + }); + } + } + notifyOnUpdated(); + } + + // Method for WifiTracker to update the link properties, which is valid for all WifiEntry types. + @WorkerThread + void updateLinkProperties(@Nullable LinkProperties linkProperties) { + if (getConnectedState() != CONNECTED_STATE_CONNECTED) { + return; + } + + if (mConnectedInfo == null) { + mConnectedInfo = new ConnectedInfo(); + } + // Find IPv4 and IPv6 addresses, and subnet mask + List<String> ipv6Addresses = new ArrayList<>(); + for (LinkAddress addr : linkProperties.getLinkAddresses()) { + if (addr.getAddress() instanceof Inet4Address) { + mConnectedInfo.ipAddress = addr.getAddress().getHostAddress(); + try { + InetAddress all = InetAddress.getByAddress( + new byte[]{(byte) 255, (byte) 255, (byte) 255, (byte) 255}); + mConnectedInfo.subnetMask = NetworkUtils.getNetworkPart( + all, addr.getPrefixLength()).getHostAddress(); + } catch (UnknownHostException e) { + // Leave subnet null; + } + } else if (addr.getAddress() instanceof Inet6Address) { + ipv6Addresses.add(addr.getAddress().getHostAddress()); + } + } + mConnectedInfo.ipv6Addresses = ipv6Addresses; + + // Find IPv4 default gateway. + for (RouteInfo routeInfo : linkProperties.getRoutes()) { + if (routeInfo.isIPv4Default() && routeInfo.hasGateway()) { + mConnectedInfo.gateway = routeInfo.getGateway().getHostAddress(); + break; + } + } + + // Find DNS servers + mConnectedInfo.dnsServers = linkProperties.getDnsServers().stream() + .map(InetAddress::getHostAddress).collect(Collectors.toList()); + + notifyOnUpdated(); + } // TODO (b/70983952) Come up with a sorting scheme that does the right thing. @Override @@ -446,6 +592,10 @@ public abstract class WifiEntry implements Comparable<WifiEntry> { .append(getLevel()) .append(",security:") .append(getSecurity()) + .append(",connected:") + .append(getConnectedState() == CONNECTED_STATE_CONNECTED ? "true" : "false") + .append(",connectedInfo:") + .append(getConnectedInfo()) .toString(); } } diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java index a97751124..50b7a244b 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java @@ -31,6 +31,7 @@ import static java.util.stream.Collectors.toMap; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; +import android.net.LinkProperties; import android.net.NetworkInfo; import android.net.NetworkScoreManager; import android.net.wifi.ScanResult; @@ -173,9 +174,11 @@ public class WifiPickerTracker extends BaseWifiTracker { conditionallyUpdateScanResults(true /* lastScanSucceeded */); final WifiInfo wifiInfo = mWifiManager.getConnectionInfo(); final NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo(); - updateStandardWifiEntryConnectionInfo(wifiInfo, networkInfo); + updateConnectionInfo(wifiInfo, networkInfo); // Create a StandardWifiEntry for the current connection if there are no scan results yet. conditionallyCreateConnectedStandardWifiEntry(wifiInfo, networkInfo); + handleLinkPropertiesChanged(mConnectivityManager.getLinkProperties( + mWifiManager.getCurrentNetwork())); notifyOnNumSavedNetworksChanged(); notifyOnNumSavedSubscriptionsChanged(); updateWifiEntries(); @@ -224,11 +227,20 @@ public class WifiPickerTracker extends BaseWifiTracker { @Override protected void handleNetworkStateChangedAction(@NonNull Intent intent) { checkNotNull(intent, "Intent cannot be null!"); - updateStandardWifiEntryConnectionInfo(mWifiManager.getConnectionInfo(), + updateConnectionInfo(mWifiManager.getConnectionInfo(), (NetworkInfo) intent.getExtra(WifiManager.EXTRA_NETWORK_INFO)); updateWifiEntries(); } + @WorkerThread + @Override + protected void handleLinkPropertiesChanged(@NonNull LinkProperties linkProperties) { + if (mConnectedWifiEntry != null + && mConnectedWifiEntry.getConnectedState() == CONNECTED_STATE_CONNECTED) { + mConnectedWifiEntry.updateLinkProperties(linkProperties); + } + } + /** * Update the list returned by getWifiEntries() with the current states of the entry caches. */ @@ -402,14 +414,17 @@ public class WifiPickerTracker extends BaseWifiTracker { } /** - * Updates all StandardWifiEntries with the current connection info. + * Updates all WifiEntries with the current connection info. * @param wifiInfo WifiInfo of the current connection * @param networkInfo NetworkInfo of the current connection */ @WorkerThread - private void updateStandardWifiEntryConnectionInfo(@Nullable WifiInfo wifiInfo, + private void updateConnectionInfo(@Nullable WifiInfo wifiInfo, @Nullable NetworkInfo networkInfo) { - for (StandardWifiEntry entry : mStandardWifiEntryCache.values()) { + for (WifiEntry entry : mStandardWifiEntryCache.values()) { + entry.updateConnectionInfo(wifiInfo, networkInfo); + } + for (WifiEntry entry : mPasspointWifiEntryCache.values()) { entry.updateConnectionInfo(wifiInfo, networkInfo); } } diff --git a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java index bb5f814bd..a94d2bd79 100644 --- a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java +++ b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java @@ -30,6 +30,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import android.net.LinkProperties; import android.net.MacAddress; import android.net.NetworkInfo; import android.net.wifi.ScanResult; @@ -497,6 +498,24 @@ public class StandardWifiEntryTest { assertThat(oweWifiEntry.canEasyConnect()).isFalse(); } + @Test + public void testUpdateLinkProperties_updatesConnectedInfo() { + final WifiConfiguration config = new WifiConfiguration(); + config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP); + config.SSID = "\"ssid\""; + config.networkId = 1; + final StandardWifiEntry entry = new StandardWifiEntry(mTestHandler, config, + mMockWifiManager); + when(mMockWifiInfo.getNetworkId()).thenReturn(1); + when(mMockWifiInfo.getRssi()).thenReturn(GOOD_RSSI); + when(mMockNetworkInfo.getDetailedState()).thenReturn(NetworkInfo.DetailedState.CONNECTED); + entry.updateConnectionInfo(mMockWifiInfo, mMockNetworkInfo); + + entry.updateLinkProperties(new LinkProperties()); + + assertThat(entry.getConnectedInfo()).isNotNull(); + } + private StandardWifiEntry getSavedStandardWifiEntry(int wifiConfigurationSecureType) { final WifiConfiguration config = new WifiConfiguration(); config.SSID = "\"ssid\""; |