summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2020-08-24 17:09:25 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-08-24 17:09:25 +0000
commitcfb75e7ccb8a912ff6647fdf5142abbc083cc4c1 (patch)
tree73687d4398b7ebc161f844b59258825731db183d
parenta15056fede28509e49c4854d933f789cedfcc37f (diff)
parent915b6d1dcf2c075a35b5087487c1e1a5fd372435 (diff)
Merge "[WifiTrackerLib] Add isDefaultNetwork boolean to WifiEntry" into rvc-qpr-dev
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java48
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/NetworkDetailsTracker.java53
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java55
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java6
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java57
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java5
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java14
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java17
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java14
-rw-r--r--libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java36
-rw-r--r--libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java35
11 files changed, 250 insertions, 90 deletions
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java
index 18611e242..af434bcaf 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java
@@ -133,6 +133,7 @@ public class BaseWifiTracker implements LifecycleObserver {
protected final long mScanIntervalMillis;
protected final ScanResultUpdater mScanResultUpdater;
protected final WifiNetworkScoreCache mWifiNetworkScoreCache;
+ protected boolean mIsWifiDefaultRoute;
private final Set<NetworkKey> mRequestedScoreKeys = new HashSet<>();
// Network request for listening on changes to Wifi link properties and network capabilities
@@ -154,6 +155,33 @@ public class BaseWifiTracker implements LifecycleObserver {
}
};
+ private final ConnectivityManager.NetworkCallback mDefaultNetworkCallback =
+ new ConnectivityManager.NetworkCallback() {
+ @Override
+ public void onCapabilitiesChanged(Network network,
+ NetworkCapabilities networkCapabilities) {
+ if (mIsWifiDefaultRoute != networkCapabilities.hasTransport(TRANSPORT_WIFI)) {
+ mIsWifiDefaultRoute = !mIsWifiDefaultRoute;
+ if (isVerboseLoggingEnabled()) {
+ if (mIsWifiDefaultRoute) {
+ Log.v(mTag, "Wifi is the default route");
+ } else {
+ Log.v(mTag, "Wifi is not the default route");
+ }
+ }
+ handleDefaultRouteChanged();
+ }
+ }
+
+ public void onLost(@NonNull Network network) {
+ mIsWifiDefaultRoute = false;
+ if (isVerboseLoggingEnabled()) {
+ Log.v(mTag, "Wifi is not the default route");
+ }
+ handleDefaultRouteChanged();
+ }
+ };
+
/**
* Constructor for BaseWifiTracker.
*
@@ -220,6 +248,12 @@ public class BaseWifiTracker implements LifecycleObserver {
/* broadcastPermission */ null, mWorkerHandler);
mConnectivityManager.registerNetworkCallback(mNetworkRequest, mNetworkCallback,
mWorkerHandler);
+ mConnectivityManager.registerDefaultNetworkCallback(mDefaultNetworkCallback,
+ mWorkerHandler);
+ final NetworkCapabilities defaultNetworkCapabilities = mConnectivityManager
+ .getNetworkCapabilities(mConnectivityManager.getActiveNetwork());
+ mIsWifiDefaultRoute = defaultNetworkCapabilities != null
+ && defaultNetworkCapabilities.hasTransport(TRANSPORT_WIFI);
mNetworkScoreManager.registerNetworkScoreCache(
NetworkKey.TYPE_WIFI,
mWifiNetworkScoreCache,
@@ -241,6 +275,7 @@ public class BaseWifiTracker implements LifecycleObserver {
mWorkerHandler.post(mScanner::stop);
mContext.unregisterReceiver(mBroadcastReceiver);
mConnectivityManager.unregisterNetworkCallback(mNetworkCallback);
+ mConnectivityManager.unregisterNetworkCallback(mDefaultNetworkCallback);
mNetworkScoreManager.unregisterNetworkScoreCache(NetworkKey.TYPE_WIFI,
mWifiNetworkScoreCache);
mWorkerHandler.post(mRequestedScoreKeys::clear);
@@ -326,6 +361,15 @@ public class BaseWifiTracker implements LifecycleObserver {
}
/**
+ * Handle when the default route changes. Whether Wifi is the default route is stored in
+ * mIsWifiDefaultRoute.
+ */
+ @WorkerThread
+ protected void handleDefaultRouteChanged() {
+ // Do nothing.
+ }
+
+ /**
* Handle updates to the Wifi network score cache, which is stored in mWifiNetworkScoreCache
*/
@WorkerThread
@@ -393,8 +437,8 @@ public class BaseWifiTracker implements LifecycleObserver {
*/
protected interface BaseWifiTrackerCallback {
/**
- * Called when the state of Wi-Fi has changed. The new value can be read through
- * {@link #getWifiState()}
+ * Called when the values for {@link #getWifiState()}
+ * or {@link #isWifiDefaultNetwork()} have changed.
*/
@MainThread
void onWifiStateChanged();
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/NetworkDetailsTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/NetworkDetailsTracker.java
index 91805f776..b6ae631ec 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/NetworkDetailsTracker.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/NetworkDetailsTracker.java
@@ -16,14 +16,24 @@
package com.android.wifitrackerlib;
+import static androidx.core.util.Preconditions.checkNotNull;
+
+import static com.android.wifitrackerlib.WifiEntry.CONNECTED_STATE_CONNECTED;
+
import android.content.Context;
+import android.content.Intent;
import android.net.ConnectivityManager;
+import android.net.LinkProperties;
+import android.net.NetworkCapabilities;
+import android.net.NetworkInfo;
import android.net.NetworkScoreManager;
import android.net.wifi.WifiManager;
import android.os.Handler;
import androidx.annotation.AnyThread;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.annotation.WorkerThread;
import androidx.lifecycle.Lifecycle;
import java.time.Clock;
@@ -75,6 +85,8 @@ public abstract class NetworkDetailsTracker extends BaseWifiTracker {
}
}
+ protected NetworkInfo mCurrentNetworkInfo;
+
/**
* Abstract constructor for NetworkDetailsTracker.
* Clients must use {@link NetworkDetailsTracker#createNetworkDetailsTracker} for creating
@@ -95,6 +107,47 @@ public abstract class NetworkDetailsTracker extends BaseWifiTracker {
null /* listener */, tag);
}
+ @WorkerThread
+ @Override
+ protected void handleNetworkStateChangedAction(@NonNull Intent intent) {
+ checkNotNull(intent, "Intent cannot be null!");
+ mCurrentNetworkInfo = (NetworkInfo) intent.getExtra(WifiManager.EXTRA_NETWORK_INFO);
+ getWifiEntry().updateConnectionInfo(mWifiManager.getConnectionInfo(), mCurrentNetworkInfo);
+ }
+
+ @WorkerThread
+ @Override
+ protected void handleRssiChangedAction() {
+ getWifiEntry().updateConnectionInfo(mWifiManager.getConnectionInfo(), mCurrentNetworkInfo);
+ }
+
+ @WorkerThread
+ @Override
+ protected void handleLinkPropertiesChanged(@Nullable LinkProperties linkProperties) {
+ final WifiEntry chosenEntry = getWifiEntry();
+ if (chosenEntry.getConnectedState() == CONNECTED_STATE_CONNECTED) {
+ chosenEntry.updateLinkProperties(linkProperties);
+ }
+ }
+
+ @WorkerThread
+ @Override
+ protected void handleNetworkCapabilitiesChanged(@Nullable NetworkCapabilities capabilities) {
+ final WifiEntry chosenEntry = getWifiEntry();
+ if (chosenEntry.getConnectedState() == CONNECTED_STATE_CONNECTED) {
+ chosenEntry.updateNetworkCapabilities(capabilities);
+ }
+ }
+
+ @WorkerThread
+ @Override
+ protected void handleDefaultRouteChanged() {
+ final WifiEntry chosenEntry = getWifiEntry();
+ if (chosenEntry.getConnectedState() == CONNECTED_STATE_CONNECTED) {
+ chosenEntry.setDefaultNetwork(mIsWifiDefaultRoute);
+ }
+ }
+
/**
* Returns the WifiEntry object representing the single network being tracked.
*/
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java
index 9ec431736..4266940ac 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java
@@ -19,13 +19,11 @@ package com.android.wifitrackerlib;
import static androidx.core.util.Preconditions.checkNotNull;
import static com.android.wifitrackerlib.PasspointWifiEntry.uniqueIdToPasspointWifiEntryKey;
-import static com.android.wifitrackerlib.WifiEntry.CONNECTED_STATE_CONNECTED;
import static com.android.wifitrackerlib.WifiEntry.WIFI_LEVEL_UNREACHABLE;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
-import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkInfo;
import android.net.NetworkScoreManager;
@@ -101,16 +99,6 @@ class PasspointNetworkDetailsTracker extends NetworkDetailsTracker {
"Cannot find config for given PasspointWifiEntry key!");
}
}
-
- cacheNewScanResults();
- conditionallyUpdateScanResults(true /* lastScanSucceeded */);
- conditionallyUpdateConfig();
- final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
- final Network currentNetwork = mWifiManager.getCurrentNetwork();
- mCurrentNetworkInfo = mConnectivityManager.getNetworkInfo(currentNetwork);
- mChosenEntry.updateConnectionInfo(wifiInfo, mCurrentNetworkInfo);
- handleLinkPropertiesChanged(mConnectivityManager.getLinkProperties(
- mWifiManager.getCurrentNetwork()));
}
@AnyThread
@@ -122,6 +110,21 @@ class PasspointNetworkDetailsTracker extends NetworkDetailsTracker {
@WorkerThread
@Override
+ protected void handleOnStart() {
+ conditionallyUpdateScanResults(true /* lastScanSucceeded */);
+ conditionallyUpdateConfig();
+ final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
+ final Network currentNetwork = mWifiManager.getCurrentNetwork();
+ mCurrentNetworkInfo = mConnectivityManager.getNetworkInfo(currentNetwork);
+ mChosenEntry.updateConnectionInfo(wifiInfo, mCurrentNetworkInfo);
+ handleNetworkCapabilitiesChanged(
+ mConnectivityManager.getNetworkCapabilities(currentNetwork));
+ handleLinkPropertiesChanged(mConnectivityManager.getLinkProperties(currentNetwork));
+ mChosenEntry.setDefaultNetwork(mIsWifiDefaultRoute);
+ }
+
+ @WorkerThread
+ @Override
protected void handleWifiStateChangedAction() {
conditionallyUpdateScanResults(true /* lastScanSucceeded */);
}
@@ -142,34 +145,6 @@ class PasspointNetworkDetailsTracker extends NetworkDetailsTracker {
}
@WorkerThread
- @Override
- protected void handleRssiChangedAction() {
- mChosenEntry.updateConnectionInfo(mWifiManager.getConnectionInfo(), mCurrentNetworkInfo);
- }
-
- @WorkerThread
- @Override
- protected void handleNetworkStateChangedAction(@NonNull Intent intent) {
- checkNotNull(intent, "Intent cannot be null!");
- mCurrentNetworkInfo = (NetworkInfo) intent.getExtra(WifiManager.EXTRA_NETWORK_INFO);
- mChosenEntry.updateConnectionInfo(mWifiManager.getConnectionInfo(), mCurrentNetworkInfo);
- }
-
- @WorkerThread
- @Override
- protected void handleLinkPropertiesChanged(@NonNull LinkProperties linkProperties) {
- if (mChosenEntry.getConnectedState() == CONNECTED_STATE_CONNECTED) {
- mChosenEntry.updateLinkProperties(linkProperties);
- }
- }
-
- @WorkerThread
- @Override
- protected void handleNetworkScoreCacheUpdated() {
- mChosenEntry.onScoreCacheUpdated();
- }
-
- @WorkerThread
private void updatePasspointWifiEntryScans(@NonNull List<ScanResult> scanResults) {
checkNotNull(scanResults, "Scan Result list should not be null!");
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java
index 1fca6a4e5..1b71fc847 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java
@@ -245,8 +245,12 @@ public class PasspointWifiEntry extends WifiEntry implements WifiEntry.WifiEntry
? carrierName
: suggestorLabel);
}
+
+ final boolean isDefaultNetwork = mConnectedInfo != null
+ && mConnectedInfo.isDefaultNetwork;
String networkCapabilitiesinformation =
- getCurrentNetworkCapabilitiesInformation(mContext, mNetworkCapabilities);
+ getCurrentNetworkCapabilitiesInformation(mContext, mNetworkCapabilities,
+ isDefaultNetwork);
if (!TextUtils.isEmpty(networkCapabilitiesinformation)) {
return networkCapabilitiesinformation;
}
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java
index 3ef1b4727..ef13acc24 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java
@@ -21,16 +21,13 @@ import static androidx.core.util.Preconditions.checkNotNull;
import static com.android.wifitrackerlib.NetworkRequestEntry.wifiConfigToNetworkRequestEntryKey;
import static com.android.wifitrackerlib.StandardWifiEntry.wifiConfigToStandardWifiEntryKey;
import static com.android.wifitrackerlib.Utils.getSecurityTypesFromScanResult;
-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.Network;
-import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkScoreManager;
import android.net.wifi.WifiConfiguration;
@@ -41,7 +38,6 @@ import android.text.TextUtils;
import androidx.annotation.AnyThread;
import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
import androidx.lifecycle.Lifecycle;
@@ -81,14 +77,6 @@ class StandardNetworkDetailsTracker extends NetworkDetailsTracker {
mChosenEntry = new StandardWifiEntry(mContext, mMainHandler, key, mWifiManager,
mWifiNetworkScoreCache, false /* forSavedNetworksPage */);
}
- cacheNewScanResults();
- conditionallyUpdateScanResults(true /* lastScanSucceeded */);
- conditionallyUpdateConfig();
- final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
- final Network currentNetwork = mWifiManager.getCurrentNetwork();
- mCurrentNetworkInfo = mConnectivityManager.getNetworkInfo(currentNetwork);
- mChosenEntry.updateConnectionInfo(wifiInfo, mCurrentNetworkInfo);
- handleLinkPropertiesChanged(mConnectivityManager.getLinkProperties(currentNetwork));
}
@AnyThread
@@ -100,6 +88,21 @@ class StandardNetworkDetailsTracker extends NetworkDetailsTracker {
@WorkerThread
@Override
+ protected void handleOnStart() {
+ conditionallyUpdateScanResults(true /* lastScanSucceeded */);
+ conditionallyUpdateConfig();
+ final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
+ final Network currentNetwork = mWifiManager.getCurrentNetwork();
+ mCurrentNetworkInfo = mConnectivityManager.getNetworkInfo(currentNetwork);
+ mChosenEntry.updateConnectionInfo(wifiInfo, mCurrentNetworkInfo);
+ handleNetworkCapabilitiesChanged(
+ mConnectivityManager.getNetworkCapabilities(currentNetwork));
+ handleLinkPropertiesChanged(mConnectivityManager.getLinkProperties(currentNetwork));
+ mChosenEntry.setDefaultNetwork(mIsWifiDefaultRoute);
+ }
+
+ @WorkerThread
+ @Override
protected void handleWifiStateChangedAction() {
conditionallyUpdateScanResults(true /* lastScanSucceeded */);
}
@@ -134,36 +137,6 @@ class StandardNetworkDetailsTracker extends NetworkDetailsTracker {
@WorkerThread
@Override
- protected void handleNetworkStateChangedAction(@NonNull Intent intent) {
- checkNotNull(intent, "Intent cannot be null!");
- mCurrentNetworkInfo = (NetworkInfo) intent.getExtra(WifiManager.EXTRA_NETWORK_INFO);
- mChosenEntry.updateConnectionInfo(mWifiManager.getConnectionInfo(), mCurrentNetworkInfo);
- }
-
- @WorkerThread
- @Override
- protected void handleRssiChangedAction() {
- mChosenEntry.updateConnectionInfo(mWifiManager.getConnectionInfo(), mCurrentNetworkInfo);
- }
-
- @WorkerThread
- @Override
- protected void handleLinkPropertiesChanged(@Nullable LinkProperties linkProperties) {
- if (mChosenEntry.getConnectedState() == CONNECTED_STATE_CONNECTED) {
- mChosenEntry.updateLinkProperties(linkProperties);
- }
- }
-
- @WorkerThread
- @Override
- protected void handleNetworkCapabilitiesChanged(@Nullable NetworkCapabilities capabilities) {
- if (mChosenEntry.getConnectedState() == CONNECTED_STATE_CONNECTED) {
- mChosenEntry.updateNetworkCapabilities(capabilities);
- }
- }
-
- @WorkerThread
- @Override
protected void handleNetworkScoreCacheUpdated() {
mChosenEntry.onScoreCacheUpdated();
}
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java
index 56cd16503..5292e179a 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java
@@ -284,8 +284,11 @@ public class StandardWifiEntry extends WifiEntry {
return mContext.getString(R.string.connected_via_network_scorer_default);
}
+ final boolean isDefaultNetwork = mConnectedInfo != null
+ && mConnectedInfo.isDefaultNetwork;
String networkCapabilitiesinformation =
- getCurrentNetworkCapabilitiesInformation(mContext, mNetworkCapabilities);
+ getCurrentNetworkCapabilitiesInformation(mContext, mNetworkCapabilities,
+ isDefaultNetwork);
if (!TextUtils.isEmpty(networkCapabilitiesinformation)) {
return networkCapabilitiesinformation;
}
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java
index 62bbe0f96..a21dd1cb5 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java
@@ -494,6 +494,12 @@ class Utils {
sj.add(wifiInfoDescription);
}
+ WifiEntry.ConnectedInfo connectedInfo = wifiEntry.getConnectedInfo();
+ if (connectedInfo != null) {
+ sj.add("isValidated=" + connectedInfo.isValidated);
+ sj.add("isDefaultNetwork=" + connectedInfo.isDefaultNetwork);
+ }
+
final String scanResultsDescription = wifiEntry.getScanResultDescription();
if (!TextUtils.isEmpty(scanResultsDescription)) {
sj.add(scanResultsDescription);
@@ -541,7 +547,7 @@ class Utils {
}
static String getCurrentNetworkCapabilitiesInformation(Context context,
- NetworkCapabilities networkCapabilities) {
+ NetworkCapabilities networkCapabilities, boolean isDefaultNetwork) {
if (context == null || networkCapabilities == null) {
return "";
}
@@ -556,7 +562,11 @@ class Utils {
return context.getString(R.string.wifi_limited_connection);
}
- if (!networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)) {
+ if (networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)) {
+ if (!isDefaultNetwork) {
+ return context.getString(R.string.wifi_connected_low_quality);
+ }
+ } else {
if (networkCapabilities.isPrivateDnsBroken()) {
return context.getString(R.string.private_dns_broken);
}
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java
index c7dc5c4da..ea448e926 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java
@@ -359,6 +359,8 @@ public abstract class WifiEntry implements Comparable<WifiEntry> {
public List<String> ipv6Addresses = new ArrayList<>();
public String gateway;
public String subnetMask;
+ public boolean isValidated;
+ public boolean isDefaultNetwork;
}
// User actions on a network
@@ -686,10 +688,25 @@ public abstract class WifiEntry implements Comparable<WifiEntry> {
notifyOnUpdated();
}
+ @WorkerThread
+ void setDefaultNetwork(boolean isDefaultNetwork) {
+ if (mConnectedInfo == null) {
+ return;
+ }
+ mConnectedInfo.isDefaultNetwork = isDefaultNetwork;
+ notifyOnUpdated();
+ }
+
// Method for WifiTracker to update a connected WifiEntry's network capabilities.
@WorkerThread
void updateNetworkCapabilities(@Nullable NetworkCapabilities capabilities) {
mNetworkCapabilities = capabilities;
+ if (mConnectedInfo == null) {
+ return;
+ }
+ mConnectedInfo.isValidated = mNetworkCapabilities != null
+ && mNetworkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
+ notifyOnUpdated();
}
String getWifiInfoDescription() {
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
index 0a9bc5634..f8fa8890e 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
@@ -195,10 +195,15 @@ public class WifiPickerTracker extends BaseWifiTracker {
final Network currentNetwork = mWifiManager.getCurrentNetwork();
mCurrentNetworkInfo = mConnectivityManager.getNetworkInfo(currentNetwork);
updateConnectionInfo(wifiInfo, mCurrentNetworkInfo);
- handleLinkPropertiesChanged(mConnectivityManager.getLinkProperties(currentNetwork));
notifyOnNumSavedNetworksChanged();
notifyOnNumSavedSubscriptionsChanged();
updateWifiEntries();
+
+ // Populate mConnectedWifiEntry with information from missed callbacks.
+ handleNetworkCapabilitiesChanged(
+ mConnectivityManager.getNetworkCapabilities(currentNetwork));
+ handleLinkPropertiesChanged(mConnectivityManager.getLinkProperties(currentNetwork));
+ handleDefaultRouteChanged();
}
@WorkerThread
@@ -280,6 +285,13 @@ public class WifiPickerTracker extends BaseWifiTracker {
}
@WorkerThread
+ protected void handleDefaultRouteChanged() {
+ if (mConnectedWifiEntry != null) {
+ mConnectedWifiEntry.setDefaultNetwork(mIsWifiDefaultRoute);
+ }
+ }
+
+ @WorkerThread
@Override
protected void handleNetworkScoreCacheUpdated() {
for (StandardWifiEntry entry : mStandardWifiEntryCache.values()) {
diff --git a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java
index 9fa6a2f40..a2960153b 100644
--- a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java
+++ b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java
@@ -23,6 +23,7 @@ import static com.android.wifitrackerlib.WifiEntry.SPEED_SLOW;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -30,6 +31,7 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.res.Resources;
import android.net.ConnectivityManager;
+import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkKey;
import android.net.ScoredNetwork;
@@ -147,7 +149,8 @@ public class PasspointWifiEntryTest {
ConnectivityManager mockConnectivityManager = mock(ConnectivityManager.class);
when(mMockContext.getSystemService(Context.CONNECTIVITY_SERVICE))
.thenReturn(mockConnectivityManager);
-
+ final NetworkCapabilities networkCapabilities = new NetworkCapabilities.Builder()
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED).build();
WifiInfo wifiInfo = mock(WifiInfo.class);
when(wifiInfo.isPasspointAp()).thenReturn(true);
when(wifiInfo.getPasspointFqdn()).thenReturn(FQDN);
@@ -159,11 +162,42 @@ public class PasspointWifiEntryTest {
getPasspointConfiguration(), mMockWifiManager, mMockScoreCache,
false /* forSavedNetworksPage */);
entry.updateConnectionInfo(wifiInfo, networkInfo);
+ entry.updateNetworkCapabilities(networkCapabilities);
+ entry.setDefaultNetwork(true);
assertThat(entry.getSummary()).isEqualTo("Connected");
}
@Test
+ public void testGetSummary_validatedAndNotDefault_showsLowQuality() {
+ final Resources mockResources = mock(Resources.class);
+ when(mMockContext.getResources()).thenReturn(mockResources);
+ when(mockResources.getString(anyInt())).thenReturn("");
+ when(mockResources.getString(R.string.wifi_connected_low_quality))
+ .thenReturn("Low quality");
+ ConnectivityManager mockConnectivityManager = mock(ConnectivityManager.class);
+ when(mMockContext.getSystemService(Context.CONNECTIVITY_SERVICE))
+ .thenReturn(mockConnectivityManager);
+ final NetworkCapabilities networkCapabilities = new NetworkCapabilities.Builder()
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED).build();
+ WifiInfo wifiInfo = mock(WifiInfo.class);
+ when(wifiInfo.isPasspointAp()).thenReturn(true);
+ when(wifiInfo.getPasspointFqdn()).thenReturn(FQDN);
+ final NetworkInfo networkInfo =
+ new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", "");
+ networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, "", "");
+
+ PasspointWifiEntry entry = new PasspointWifiEntry(mMockContext, mTestHandler,
+ getPasspointConfiguration(), mMockWifiManager, mMockScoreCache,
+ false /* forSavedNetworksPage */);
+ entry.updateConnectionInfo(wifiInfo, networkInfo);
+ entry.updateNetworkCapabilities(networkCapabilities);
+ entry.setDefaultNetwork(false);
+
+ assertThat(entry.getSummary()).isEqualTo("Low quality");
+ }
+
+ @Test
public void testGetSpeed_cacheUpdated_speedValueChanges() {
when(mMockScoredNetwork.calculateBadge(GOOD_RSSI)).thenReturn(SPEED_FAST);
PasspointWifiEntry entry = new PasspointWifiEntry(mMockContext, mTestHandler,
diff --git a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java
index 81b20348d..f067d2ed5 100644
--- a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java
+++ b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java
@@ -40,6 +40,7 @@ import static com.android.wifitrackerlib.WifiEntry.WIFI_LEVEL_UNREACHABLE;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
@@ -622,6 +623,8 @@ public class StandardWifiEntryTest {
when(mockResources.getString(R.string.summary_separator)).thenReturn(summarySeparator);
when(mockResources.getStringArray(R.array.wifi_status)).thenReturn(wifiStatusArray);
final ConnectivityManager mockConnectivityManager = mock(ConnectivityManager.class);
+ final NetworkCapabilities networkCapabilities = new NetworkCapabilities.Builder()
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED).build();
when(mMockContext.getSystemService(Context.CONNECTIVITY_SERVICE))
.thenReturn(mockConnectivityManager);
@@ -638,11 +641,43 @@ public class StandardWifiEntryTest {
mMockWifiManager, mMockScoreCache, false /* forSavedNetworksPage */);
entry.updateConnectionInfo(wifiInfo, networkInfo);
+ entry.updateNetworkCapabilities(networkCapabilities);
+ entry.setDefaultNetwork(true);
assertThat(entry.getSummary()).isEqualTo("Connected");
}
@Test
+ public void testGetSummary_validatedAndNotDefault_showsLowQuality() {
+ final int networkId = 1;
+ final Resources mockResources = mock(Resources.class);
+ when(mMockContext.getResources()).thenReturn(mockResources);
+ when(mockResources.getString(anyInt())).thenReturn("");
+ when(mockResources.getString(R.string.wifi_connected_low_quality))
+ .thenReturn("Low quality");
+ when(mMockContext.getSystemService(Context.CONNECTIVITY_SERVICE))
+ .thenReturn(mMockConnectivityManager);
+ final NetworkCapabilities networkCapabilities = new NetworkCapabilities.Builder()
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED).build();
+ final WifiInfo wifiInfo = new WifiInfo.Builder().setNetworkId(networkId).build();
+ final NetworkInfo networkInfo =
+ new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", "");
+ networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, "", "");
+ final WifiConfiguration config = new WifiConfiguration();
+ config.SSID = "\"ssid\"";
+ config.networkId = networkId;
+ final StandardWifiEntry entry = new StandardWifiEntry(mMockContext, mTestHandler,
+ ssidAndSecurityToStandardWifiEntryKey("ssid", SECURITY_NONE), config,
+ mMockWifiManager, mMockScoreCache, false /* forSavedNetworksPage */);
+
+ entry.updateConnectionInfo(wifiInfo, networkInfo);
+ entry.updateNetworkCapabilities(networkCapabilities);
+ entry.setDefaultNetwork(false);
+
+ assertThat(entry.getSummary()).isEqualTo("Low quality");
+ }
+
+ @Test
public void testGetSecurityString_pskTypeWpa2_getWpa2() {
final StandardWifiEntry entry =
getSavedStandardWifiEntry(WifiConfiguration.SECURITY_TYPE_PSK);