summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java58
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/NetworkDetailsTracker.java4
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java3
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java9
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java3
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java9
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java15
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java50
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java4
-rw-r--r--libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java32
-rw-r--r--libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java32
-rw-r--r--libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java53
12 files changed, 205 insertions, 67 deletions
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java
index af434bcaf..28b1a4907 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java
@@ -16,6 +16,8 @@
package com.android.wifitrackerlib;
+import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
+import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
import static java.util.stream.Collectors.toList;
@@ -133,7 +135,9 @@ public class BaseWifiTracker implements LifecycleObserver {
protected final long mScanIntervalMillis;
protected final ScanResultUpdater mScanResultUpdater;
protected final WifiNetworkScoreCache mWifiNetworkScoreCache;
+ protected boolean mIsWifiValidated;
protected boolean mIsWifiDefaultRoute;
+ protected boolean mIsCellDefaultRoute;
private final Set<NetworkKey> mRequestedScoreKeys = new HashSet<>();
// Network request for listening on changes to Wifi link properties and network capabilities
@@ -144,30 +148,42 @@ public class BaseWifiTracker implements LifecycleObserver {
private final ConnectivityManager.NetworkCallback mNetworkCallback =
new ConnectivityManager.NetworkCallback() {
@Override
- public void onLinkPropertiesChanged(Network network, LinkProperties lp) {
+ public void onLinkPropertiesChanged(@NonNull Network network,
+ @NonNull LinkProperties lp) {
handleLinkPropertiesChanged(lp);
}
@Override
- public void onCapabilitiesChanged(Network network,
- NetworkCapabilities networkCapabilities) {
+ public void onCapabilitiesChanged(@NonNull Network network,
+ @NonNull NetworkCapabilities networkCapabilities) {
+ final boolean oldWifiValidated = mIsWifiValidated;
+ mIsWifiValidated = networkCapabilities.hasCapability(NET_CAPABILITY_VALIDATED);
+ if (isVerboseLoggingEnabled() && mIsWifiValidated != oldWifiValidated) {
+ Log.v(mTag, "Is Wifi validated: " + mIsWifiValidated);
+ }
handleNetworkCapabilitiesChanged(networkCapabilities);
}
+
+ @Override
+ public void onLost(@NonNull Network network) {
+ mIsWifiValidated = false;
+ }
};
private final ConnectivityManager.NetworkCallback mDefaultNetworkCallback =
new ConnectivityManager.NetworkCallback() {
@Override
- public void onCapabilitiesChanged(Network network,
- NetworkCapabilities networkCapabilities) {
- if (mIsWifiDefaultRoute != networkCapabilities.hasTransport(TRANSPORT_WIFI)) {
- mIsWifiDefaultRoute = !mIsWifiDefaultRoute;
+ public void onCapabilitiesChanged(@NonNull Network network,
+ @NonNull NetworkCapabilities networkCapabilities) {
+ final boolean oldWifiDefault = mIsWifiDefaultRoute;
+ final boolean oldCellDefault = mIsCellDefaultRoute;
+ mIsWifiDefaultRoute = networkCapabilities.hasTransport(TRANSPORT_WIFI);
+ mIsCellDefaultRoute = networkCapabilities.hasTransport(TRANSPORT_CELLULAR);
+ if (mIsWifiDefaultRoute != oldWifiDefault
+ || mIsCellDefaultRoute != oldCellDefault) {
if (isVerboseLoggingEnabled()) {
- if (mIsWifiDefaultRoute) {
- Log.v(mTag, "Wifi is the default route");
- } else {
- Log.v(mTag, "Wifi is not the default route");
- }
+ Log.v(mTag, "Wifi is the default route: " + mIsWifiDefaultRoute);
+ Log.v(mTag, "Cell is the default route: " + mIsCellDefaultRoute);
}
handleDefaultRouteChanged();
}
@@ -175,8 +191,10 @@ public class BaseWifiTracker implements LifecycleObserver {
public void onLost(@NonNull Network network) {
mIsWifiDefaultRoute = false;
+ mIsCellDefaultRoute = false;
if (isVerboseLoggingEnabled()) {
- Log.v(mTag, "Wifi is not the default route");
+ Log.v(mTag, "Wifi is the default route: false");
+ Log.v(mTag, "Cell is the default route: false");
}
handleDefaultRouteChanged();
}
@@ -252,8 +270,15 @@ public class BaseWifiTracker implements LifecycleObserver {
mWorkerHandler);
final NetworkCapabilities defaultNetworkCapabilities = mConnectivityManager
.getNetworkCapabilities(mConnectivityManager.getActiveNetwork());
- mIsWifiDefaultRoute = defaultNetworkCapabilities != null
- && defaultNetworkCapabilities.hasTransport(TRANSPORT_WIFI);
+ if (defaultNetworkCapabilities != null) {
+ mIsWifiDefaultRoute = defaultNetworkCapabilities.hasTransport(TRANSPORT_WIFI);
+ mIsCellDefaultRoute = defaultNetworkCapabilities.hasTransport(TRANSPORT_CELLULAR);
+ }
+ if (isVerboseLoggingEnabled()) {
+ Log.v(mTag, "Wifi is the default route: " + mIsWifiDefaultRoute);
+ Log.v(mTag, "Cell is the default route: " + mIsCellDefaultRoute);
+ }
+
mNetworkScoreManager.registerNetworkScoreCache(
NetworkKey.TYPE_WIFI,
mWifiNetworkScoreCache,
@@ -437,8 +462,7 @@ public class BaseWifiTracker implements LifecycleObserver {
*/
protected interface BaseWifiTrackerCallback {
/**
- * Called when the values for {@link #getWifiState()}
- * or {@link #isWifiDefaultNetwork()} have changed.
+ * Called when the value for {@link #getWifiState() has 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 b6ae631ec..be50679e2 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/NetworkDetailsTracker.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/NetworkDetailsTracker.java
@@ -136,6 +136,7 @@ public abstract class NetworkDetailsTracker extends BaseWifiTracker {
final WifiEntry chosenEntry = getWifiEntry();
if (chosenEntry.getConnectedState() == CONNECTED_STATE_CONNECTED) {
chosenEntry.updateNetworkCapabilities(capabilities);
+ chosenEntry.setIsLowQuality(mIsWifiValidated && mIsCellDefaultRoute);
}
}
@@ -144,7 +145,8 @@ public abstract class NetworkDetailsTracker extends BaseWifiTracker {
protected void handleDefaultRouteChanged() {
final WifiEntry chosenEntry = getWifiEntry();
if (chosenEntry.getConnectedState() == CONNECTED_STATE_CONNECTED) {
- chosenEntry.setDefaultNetwork(mIsWifiDefaultRoute);
+ chosenEntry.setIsDefaultNetwork(mIsWifiDefaultRoute);
+ chosenEntry.setIsLowQuality(mIsWifiValidated && mIsCellDefaultRoute);
}
}
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java
index 4266940ac..e4efcb997 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java
@@ -120,7 +120,8 @@ class PasspointNetworkDetailsTracker extends NetworkDetailsTracker {
handleNetworkCapabilitiesChanged(
mConnectivityManager.getNetworkCapabilities(currentNetwork));
handleLinkPropertiesChanged(mConnectivityManager.getLinkProperties(currentNetwork));
- mChosenEntry.setDefaultNetwork(mIsWifiDefaultRoute);
+ mChosenEntry.setIsDefaultNetwork(mIsWifiDefaultRoute);
+ mChosenEntry.setIsLowQuality(mIsWifiValidated && mIsCellDefaultRoute);
}
@WorkerThread
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java
index 1b71fc847..1f0a34be7 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java
@@ -246,11 +246,12 @@ public class PasspointWifiEntry extends WifiEntry implements WifiEntry.WifiEntry
: suggestorLabel);
}
- final boolean isDefaultNetwork = mConnectedInfo != null
- && mConnectedInfo.isDefaultNetwork;
+ if (mIsLowQuality) {
+ return mContext.getString(R.string.wifi_connected_low_quality);
+ }
+
String networkCapabilitiesinformation =
- getCurrentNetworkCapabilitiesInformation(mContext, mNetworkCapabilities,
- isDefaultNetwork);
+ getCurrentNetworkCapabilitiesInformation(mContext, mNetworkCapabilities);
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 ef13acc24..356af410c 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java
@@ -98,7 +98,8 @@ class StandardNetworkDetailsTracker extends NetworkDetailsTracker {
handleNetworkCapabilitiesChanged(
mConnectivityManager.getNetworkCapabilities(currentNetwork));
handleLinkPropertiesChanged(mConnectivityManager.getLinkProperties(currentNetwork));
- mChosenEntry.setDefaultNetwork(mIsWifiDefaultRoute);
+ mChosenEntry.setIsDefaultNetwork(mIsWifiDefaultRoute);
+ mChosenEntry.setIsLowQuality(mIsWifiValidated && mIsCellDefaultRoute);
}
@WorkerThread
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java
index 5292e179a..2095e95e3 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java
@@ -284,11 +284,12 @@ public class StandardWifiEntry extends WifiEntry {
return mContext.getString(R.string.connected_via_network_scorer_default);
}
- final boolean isDefaultNetwork = mConnectedInfo != null
- && mConnectedInfo.isDefaultNetwork;
+ if (mIsLowQuality) {
+ return mContext.getString(R.string.wifi_connected_low_quality);
+ }
+
String networkCapabilitiesinformation =
- getCurrentNetworkCapabilitiesInformation(mContext, mNetworkCapabilities,
- isDefaultNetwork);
+ getCurrentNetworkCapabilitiesInformation(mContext, mNetworkCapabilities);
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 a21dd1cb5..5a14ec4ba 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java
@@ -494,10 +494,9 @@ 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 networkCapabilityDescription = wifiEntry.getNetworkCapabilityDescription();
+ if (!TextUtils.isEmpty(networkCapabilityDescription)) {
+ sj.add(networkCapabilityDescription);
}
final String scanResultsDescription = wifiEntry.getScanResultDescription();
@@ -547,7 +546,7 @@ class Utils {
}
static String getCurrentNetworkCapabilitiesInformation(Context context,
- NetworkCapabilities networkCapabilities, boolean isDefaultNetwork) {
+ NetworkCapabilities networkCapabilities) {
if (context == null || networkCapabilities == null) {
return "";
}
@@ -562,11 +561,7 @@ class Utils {
return context.getString(R.string.wifi_limited_connection);
}
- if (networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)) {
- if (!isDefaultNetwork) {
- return context.getString(R.string.wifi_connected_low_quality);
- }
- } else {
+ if (!networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)) {
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 ea448e926..675c80d0a 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java
@@ -223,6 +223,10 @@ public abstract class WifiEntry implements Comparable<WifiEntry> {
protected boolean mCalledConnect = false;
protected boolean mCalledDisconnect = false;
+ private boolean mIsValidated;
+ private boolean mIsDefaultNetwork;
+ protected boolean mIsLowQuality;
+
WifiEntry(@NonNull Handler callbackHandler, @NonNull WifiManager wifiManager,
@NonNull WifiNetworkScoreCache scoreCache,
boolean forSavedNetworksPage) throws IllegalArgumentException {
@@ -289,6 +293,14 @@ public abstract class WifiEntry implements Comparable<WifiEntry> {
return mLevel;
};
+ /**
+ * Returns whether the level icon for this network should show an X or not.
+ */
+ public boolean shouldShowXLevelIcon() {
+ return getConnectedState() != CONNECTED_STATE_DISCONNECTED
+ && (!mIsValidated || !mIsDefaultNetwork) && !canSignIn();
+ }
+
/** Returns the speed value of the network defined by the SPEED constants */
@Speed
public int getSpeed() {
@@ -359,8 +371,6 @@ 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
@@ -454,6 +464,20 @@ public abstract class WifiEntry implements Comparable<WifiEntry> {
return "";
}
+ /** Returns the network capability information of a WifiEntry */
+ String getNetworkCapabilityDescription() {
+ final StringBuilder sb = new StringBuilder();
+ if (getConnectedState() == CONNECTED_STATE_CONNECTED) {
+ sb.append("isValidated:")
+ .append(mIsValidated)
+ .append(", isDefaultNetwork:")
+ .append(mIsDefaultNetwork)
+ .append(", isLowQuality:")
+ .append(mIsLowQuality);
+ }
+ return sb.toString();
+ }
+
/**
* In Wi-Fi picker, when users click a saved network, it will connect to the Wi-Fi network.
* However, for some special cases, Wi-Fi picker should show Wi-Fi editor UI for users to edit
@@ -629,6 +653,9 @@ public abstract class WifiEntry implements Comparable<WifiEntry> {
mNetworkInfo = null;
mNetworkCapabilities = null;
mConnectedInfo = null;
+ mIsValidated = false;
+ mIsDefaultNetwork = false;
+ mIsLowQuality = false;
if (mCalledDisconnect) {
mCalledDisconnect = false;
mCallbackHandler.post(() -> {
@@ -689,14 +716,16 @@ public abstract class WifiEntry implements Comparable<WifiEntry> {
}
@WorkerThread
- void setDefaultNetwork(boolean isDefaultNetwork) {
- if (mConnectedInfo == null) {
- return;
- }
- mConnectedInfo.isDefaultNetwork = isDefaultNetwork;
+ void setIsDefaultNetwork(boolean isDefaultNetwork) {
+ mIsDefaultNetwork = isDefaultNetwork;
notifyOnUpdated();
}
+ @WorkerThread
+ void setIsLowQuality(boolean isLowQuality) {
+ mIsLowQuality = isLowQuality;
+ }
+
// Method for WifiTracker to update a connected WifiEntry's network capabilities.
@WorkerThread
void updateNetworkCapabilities(@Nullable NetworkCapabilities capabilities) {
@@ -704,7 +733,7 @@ public abstract class WifiEntry implements Comparable<WifiEntry> {
if (mConnectedInfo == null) {
return;
}
- mConnectedInfo.isValidated = mNetworkCapabilities != null
+ mIsValidated = mNetworkCapabilities != null
&& mNetworkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
notifyOnUpdated();
}
@@ -820,12 +849,17 @@ public abstract class WifiEntry implements Comparable<WifiEntry> {
.append(isSuggestion())
.append(",level:")
.append(getLevel())
+ .append(shouldShowXLevelIcon() ? "X" : "")
.append(",security:")
.append(getSecurity())
.append(",connected:")
.append(getConnectedState() == CONNECTED_STATE_CONNECTED ? "true" : "false")
.append(",connectedInfo:")
.append(getConnectedInfo())
+ .append(",isValidated:")
+ .append(mIsValidated)
+ .append(",isDefaultNetwork:")
+ .append(mIsDefaultNetwork)
.toString();
}
}
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
index f8fa8890e..eef865abe 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
@@ -281,13 +281,15 @@ public class WifiPickerTracker extends BaseWifiTracker {
if (mConnectedWifiEntry != null
&& mConnectedWifiEntry.getConnectedState() == CONNECTED_STATE_CONNECTED) {
mConnectedWifiEntry.updateNetworkCapabilities(capabilities);
+ mConnectedWifiEntry.setIsLowQuality(mIsWifiValidated && mIsCellDefaultRoute);
}
}
@WorkerThread
protected void handleDefaultRouteChanged() {
if (mConnectedWifiEntry != null) {
- mConnectedWifiEntry.setDefaultNetwork(mIsWifiDefaultRoute);
+ mConnectedWifiEntry.setIsDefaultNetwork(mIsWifiDefaultRoute);
+ mConnectedWifiEntry.setIsLowQuality(mIsWifiValidated && mIsCellDefaultRoute);
}
}
diff --git a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java
index a2960153b..aa96fb8c7 100644
--- a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java
+++ b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java
@@ -23,7 +23,6 @@ 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;
@@ -163,18 +162,13 @@ public class PasspointWifiEntryTest {
false /* forSavedNetworksPage */);
entry.updateConnectionInfo(wifiInfo, networkInfo);
entry.updateNetworkCapabilities(networkCapabilities);
- entry.setDefaultNetwork(true);
+ entry.setIsDefaultNetwork(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");
+ public void testShouldShowXLevelIcon_unvalidatedOrNotDefault_returnsTrue() {
ConnectivityManager mockConnectivityManager = mock(ConnectivityManager.class);
when(mMockContext.getSystemService(Context.CONNECTIVITY_SERVICE))
.thenReturn(mockConnectivityManager);
@@ -190,11 +184,29 @@ public class PasspointWifiEntryTest {
PasspointWifiEntry entry = new PasspointWifiEntry(mMockContext, mTestHandler,
getPasspointConfiguration(), mMockWifiManager, mMockScoreCache,
false /* forSavedNetworksPage */);
+
+ // Disconnected should return false;
+ assertThat(entry.shouldShowXLevelIcon()).isEqualTo(false);
+
+ // Not validated, Not Default
entry.updateConnectionInfo(wifiInfo, networkInfo);
+
+ assertThat(entry.shouldShowXLevelIcon()).isEqualTo(true);
+
+ // Not Validated, Default
+ entry.setIsDefaultNetwork(true);
+
+ assertThat(entry.shouldShowXLevelIcon()).isEqualTo(true);
+
+ // Validated, Default
entry.updateNetworkCapabilities(networkCapabilities);
- entry.setDefaultNetwork(false);
- assertThat(entry.getSummary()).isEqualTo("Low quality");
+ assertThat(entry.shouldShowXLevelIcon()).isEqualTo(false);
+
+ // Validated, Not Default
+ entry.setIsDefaultNetwork(false);
+
+ assertThat(entry.shouldShowXLevelIcon()).isEqualTo(true);
}
@Test
diff --git a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java
index f067d2ed5..24449fb3a 100644
--- a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java
+++ b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java
@@ -40,7 +40,6 @@ 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;
@@ -642,19 +641,14 @@ public class StandardWifiEntryTest {
entry.updateConnectionInfo(wifiInfo, networkInfo);
entry.updateNetworkCapabilities(networkCapabilities);
- entry.setDefaultNetwork(true);
+ entry.setIsDefaultNetwork(true);
assertThat(entry.getSummary()).isEqualTo("Connected");
}
@Test
- public void testGetSummary_validatedAndNotDefault_showsLowQuality() {
+ public void testShouldShowXLevelIcon_unvalidatedOrNotDefault_returnsTrue() {
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()
@@ -666,15 +660,33 @@ public class StandardWifiEntryTest {
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 */);
+ // Disconnected should return false;
+ assertThat(entry.shouldShowXLevelIcon()).isEqualTo(false);
+
+ // Not validated, Not Default
entry.updateConnectionInfo(wifiInfo, networkInfo);
+
+ assertThat(entry.shouldShowXLevelIcon()).isEqualTo(true);
+
+ // Not Validated, Default
+ entry.setIsDefaultNetwork(true);
+
+ assertThat(entry.shouldShowXLevelIcon()).isEqualTo(true);
+
+ // Validated, Default
entry.updateNetworkCapabilities(networkCapabilities);
- entry.setDefaultNetwork(false);
- assertThat(entry.getSummary()).isEqualTo("Low quality");
+ assertThat(entry.shouldShowXLevelIcon()).isEqualTo(false);
+
+ // Validated, Not Default
+ entry.setIsDefaultNetwork(false);
+
+ assertThat(entry.shouldShowXLevelIcon()).isEqualTo(true);
}
@Test
diff --git a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java
index 553b731d4..1260266c7 100644
--- a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java
+++ b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/WifiPickerTrackerTest.java
@@ -21,6 +21,7 @@ import static com.android.wifitrackerlib.TestUtils.buildScanResult;
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.atLeastOnce;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -29,7 +30,10 @@ import static org.mockito.Mockito.when;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.content.res.Resources;
import android.net.ConnectivityManager;
+import android.net.Network;
+import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkScoreManager;
import android.net.wifi.ScanResult;
@@ -73,6 +77,8 @@ public class WifiPickerTrackerTest {
@Mock
private Context mMockContext;
@Mock
+ private Resources mMockResources;
+ @Mock
private WifiManager mMockWifiManager;
@Mock
private ConnectivityManager mMockConnectivityManager;
@@ -86,11 +92,19 @@ public class WifiPickerTrackerTest {
private WifiInfo mMockWifiInfo;
@Mock
private NetworkInfo mMockNetworkInfo;
+ @Mock
+ private Network mMockNetwork;
private TestLooper mTestLooper;
private final ArgumentCaptor<BroadcastReceiver> mBroadcastReceiverCaptor =
ArgumentCaptor.forClass(BroadcastReceiver.class);
+ private final ArgumentCaptor<ConnectivityManager.NetworkCallback>
+ mNetworkCallbackCaptor =
+ ArgumentCaptor.forClass(ConnectivityManager.NetworkCallback.class);
+ private final ArgumentCaptor<ConnectivityManager.NetworkCallback>
+ mDefaultNetworkCallbackCaptor =
+ ArgumentCaptor.forClass(ConnectivityManager.NetworkCallback.class);
private WifiPickerTracker createTestWifiPickerTracker() {
final Handler testHandler = new Handler(mTestLooper.getLooper());
@@ -121,6 +135,7 @@ public class WifiPickerTrackerTest {
when(mMockWifiInfo.getRssi()).thenReturn(WifiInfo.INVALID_RSSI);
when(mMockNetworkInfo.getDetailedState()).thenReturn(
NetworkInfo.DetailedState.DISCONNECTED);
+ when(mMockContext.getResources()).thenReturn(mMockResources);
when(mMockContext.getSystemService(Context.NETWORK_SCORE_SERVICE))
.thenReturn(mMockNetworkScoreManager);
}
@@ -504,6 +519,44 @@ public class WifiPickerTrackerTest {
}
/**
+ * Tests that a connected WifiEntry will return "Low quality" as the summary if Wifi is
+ * validated but cell is the default route.
+ */
+ @Test
+ public void testGetConnectedEntry_wifiValidatedCellDefault_isLowQuality() {
+ final String lowQuality = "Low quality";
+ when(mMockResources.getString(anyInt())).thenReturn("");
+ when(mMockResources.getString(R.string.wifi_connected_low_quality)).thenReturn(lowQuality);
+ final WifiPickerTracker wifiPickerTracker = createTestWifiPickerTracker();
+ final WifiConfiguration config = new WifiConfiguration();
+ config.SSID = "\"ssid\"";
+ config.networkId = 1;
+ when(mMockWifiManager.getPrivilegedConfiguredNetworks())
+ .thenReturn(Collections.singletonList(config));
+ when(mMockWifiManager.getScanResults()).thenReturn(Arrays.asList(
+ buildScanResult("ssid", "bssid", START_MILLIS)));
+ when(mMockWifiInfo.getNetworkId()).thenReturn(1);
+ when(mMockWifiInfo.getRssi()).thenReturn(-50);
+ when(mMockNetworkInfo.getDetailedState()).thenReturn(NetworkInfo.DetailedState.CONNECTED);
+ when(mMockConnectivityManager.getNetworkInfo(any())).thenReturn(mMockNetworkInfo);
+ wifiPickerTracker.onStart();
+ verify(mMockConnectivityManager)
+ .registerNetworkCallback(any(), mNetworkCallbackCaptor.capture(), any());
+ verify(mMockConnectivityManager)
+ .registerDefaultNetworkCallback(mDefaultNetworkCallbackCaptor.capture(), any());
+ mTestLooper.dispatchAll();
+
+ mNetworkCallbackCaptor.getValue().onCapabilitiesChanged(mMockNetwork,
+ new NetworkCapabilities.Builder()
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED).build());
+ mDefaultNetworkCallbackCaptor.getValue().onCapabilitiesChanged(mMockNetwork,
+ new NetworkCapabilities.Builder()
+ .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR).build());
+
+ assertThat(wifiPickerTracker.getConnectedWifiEntry().getSummary()).isEqualTo(lowQuality);
+ }
+
+ /**
* Tests that a PasspointWifiEntry is returned when Passpoint scans are visible.
*/
@Test