diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2020-04-28 14:55:28 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-04-28 14:55:28 +0000 |
commit | 194aaadd0b7ef5e1069dfabfd16648326b5bb77a (patch) | |
tree | 9db540403197bb83462c6bb3d1aa96aafc458966 | |
parent | 1ff9259c149d0e857fb212358c0e1855f7835bcc (diff) | |
parent | 149d9f9e040bd339ce29386af448c56704e36ba1 (diff) |
Merge "Show Wi-Fi editor for authentication failures" into rvc-dev am: e6c66ed74e am: 149d9f9e04
Change-Id: I84539916e8c5f388594e5452aaa70e073642fd6e
3 files changed, 145 insertions, 0 deletions
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java index 965a1c21d..4a1be50f4 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java @@ -16,6 +16,10 @@ package com.android.wifitrackerlib; +import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.DISABLED_AUTHENTICATION_FAILURE; +import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.DISABLED_AUTHENTICATION_NO_CREDENTIALS; +import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD; +import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.NETWORK_SELECTION_ENABLED; import static android.net.wifi.WifiInfo.sanitizeSsid; import static androidx.core.util.Preconditions.checkNotNull; @@ -44,6 +48,7 @@ import android.net.NetworkScoreManager; import android.net.NetworkScorerAppData; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiConfiguration.NetworkSelectionStatus; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Handler; @@ -641,6 +646,34 @@ public class StandardWifiEntry extends WifiEntry { return false; } + @Override + public boolean shouldEditBeforeConnect() { + WifiConfiguration wifiConfig = getWifiConfiguration(); + if (wifiConfig == null) { + return false; + } + + // The secured Wi-Fi entry is never connected. + if (getSecurity() != SECURITY_NONE && getSecurity() != SECURITY_OWE + && !wifiConfig.getNetworkSelectionStatus().hasEverConnected()) { + return true; + } + + // The network is disabled because of one of the authentication problems. + NetworkSelectionStatus networkSelectionStatus = wifiConfig.getNetworkSelectionStatus(); + if (networkSelectionStatus.getNetworkSelectionStatus() != NETWORK_SELECTION_ENABLED) { + if (networkSelectionStatus.getDisableReasonCounter(DISABLED_AUTHENTICATION_FAILURE) > 0 + || networkSelectionStatus.getDisableReasonCounter( + DISABLED_BY_WRONG_PASSWORD) > 0 + || networkSelectionStatus.getDisableReasonCounter( + DISABLED_AUTHENTICATION_NO_CREDENTIALS) > 0) { + return true; + } + } + + return false; + } + @WorkerThread void updateScanResultInfo(@Nullable List<ScanResult> scanResults) throws IllegalArgumentException { diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java index c5d224e39..fb43d4bd2 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java @@ -434,6 +434,15 @@ public abstract class WifiEntry implements Comparable<WifiEntry> { } /** + * 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 + * security or password before connecting. Or users will always get connection fail results. + */ + public boolean shouldEditBeforeConnect() { + return false; + } + + /** * Sets the callback listener for WifiEntryCallback methods. * Subsequent calls will overwrite the previous listener. */ diff --git a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java index e7d126097..63b096ecc 100644 --- a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java +++ b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java @@ -16,6 +16,12 @@ package com.android.wifitrackerlib; +import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.DISABLED_AUTHENTICATION_FAILURE; +import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.DISABLED_AUTHENTICATION_NO_CREDENTIALS; +import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD; +import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.NETWORK_SELECTION_PERMANENTLY_DISABLED; +import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.NETWORK_SELECTION_TEMPORARY_DISABLED; + import static com.android.wifitrackerlib.StandardWifiEntry.ssidAndSecurityToStandardWifiEntryKey; import static com.android.wifitrackerlib.StandardWifiEntry.wifiConfigToStandardWifiEntryKey; import static com.android.wifitrackerlib.TestUtils.buildScanResult; @@ -23,6 +29,7 @@ import static com.android.wifitrackerlib.WifiEntry.CONNECTED_STATE_CONNECTED; import static com.android.wifitrackerlib.WifiEntry.CONNECTED_STATE_DISCONNECTED; import static com.android.wifitrackerlib.WifiEntry.SECURITY_EAP; import static com.android.wifitrackerlib.WifiEntry.SECURITY_NONE; +import static com.android.wifitrackerlib.WifiEntry.SECURITY_OWE; import static com.android.wifitrackerlib.WifiEntry.SECURITY_PSK; import static com.android.wifitrackerlib.WifiEntry.SECURITY_WEP; import static com.android.wifitrackerlib.WifiEntry.WIFI_LEVEL_UNREACHABLE; @@ -31,6 +38,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.fail; import static org.mockito.Mockito.any; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -48,6 +56,7 @@ import android.net.NetworkInfo; import android.net.NetworkScoreManager; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiConfiguration.NetworkSelectionStatus; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Handler; @@ -664,4 +673,98 @@ public class StandardWifiEntryTest { verify(mMockConnectivityManager, times(1)).startCaptivePortalApp(any()); } + + @Test + public void testShouldEditBeforeConnect_nullWifiConfig_returnFalse() { + StandardWifiEntry entry = new StandardWifiEntry(mMockContext, mTestHandler, + ssidAndSecurityToStandardWifiEntryKey("ssid", SECURITY_EAP), + mMockWifiManager, false /* forSavedNetworksPage */); + + assertThat(entry.shouldEditBeforeConnect()).isFalse(); + } + + @Test + public void testShouldEditBeforeConnect_openNetwork_returnFalse() { + // Test open networks. + WifiConfiguration wifiConfig = new WifiConfiguration(); + wifiConfig.SSID = "\"ssid\""; + wifiConfig.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OPEN); + StandardWifiEntry entry = new StandardWifiEntry(mMockContext, mTestHandler, + ssidAndSecurityToStandardWifiEntryKey("ssid", SECURITY_NONE), + wifiConfig, mMockWifiManager, false /* forSavedNetworksPage */); + + assertThat(entry.shouldEditBeforeConnect()).isFalse(); + + // Test enhanced open networks. + wifiConfig.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OWE); + entry = new StandardWifiEntry(mMockContext, mTestHandler, + ssidAndSecurityToStandardWifiEntryKey("ssid", SECURITY_OWE), + wifiConfig, mMockWifiManager, false /* forSavedNetworksPage */); + + assertThat(entry.shouldEditBeforeConnect()).isFalse(); + } + + @Test + public void testShouldEditBeforeConnect_securedNetwork_returnTrueIfNeverConnected() { + // Test never connected. + WifiConfiguration wifiConfig = spy(new WifiConfiguration()); + wifiConfig.SSID = "\"ssid\""; + wifiConfig.setSecurityParams(WifiConfiguration.SECURITY_TYPE_PSK); + StandardWifiEntry entry = new StandardWifiEntry(mMockContext, mTestHandler, + ssidAndSecurityToStandardWifiEntryKey("ssid", SECURITY_PSK), + wifiConfig, mMockWifiManager, false /* forSavedNetworksPage */); + NetworkSelectionStatus networkSelectionStatus = + spy(new NetworkSelectionStatus.Builder().build()); + doReturn(networkSelectionStatus).when(wifiConfig).getNetworkSelectionStatus(); + + assertThat(entry.shouldEditBeforeConnect()).isTrue(); + + // Test ever connected. + doReturn(true).when(networkSelectionStatus).hasEverConnected(); + + assertThat(entry.shouldEditBeforeConnect()).isFalse(); + } + + @Test + public void testShouldEditBeforeConnect_authenticationFailure_returnTrue() { + // Test DISABLED_AUTHENTICATION_FAILURE. + WifiConfiguration wifiConfig = spy(new WifiConfiguration()); + wifiConfig.SSID = "\"ssid\""; + wifiConfig.setSecurityParams(WifiConfiguration.SECURITY_TYPE_PSK); + StandardWifiEntry entry = new StandardWifiEntry(mMockContext, mTestHandler, + ssidAndSecurityToStandardWifiEntryKey("ssid", SECURITY_PSK), + wifiConfig, mMockWifiManager, false /* forSavedNetworksPage */); + NetworkSelectionStatus.Builder statusBuilder = new NetworkSelectionStatus.Builder(); + NetworkSelectionStatus networkSelectionStatus = spy(statusBuilder.setNetworkSelectionStatus( + NETWORK_SELECTION_TEMPORARY_DISABLED) + .setNetworkSelectionDisableReason( + DISABLED_AUTHENTICATION_FAILURE) + .build()); + doReturn(1).when(networkSelectionStatus).getDisableReasonCounter( + DISABLED_AUTHENTICATION_FAILURE); + doReturn(true).when(networkSelectionStatus).hasEverConnected(); + doReturn(networkSelectionStatus).when(wifiConfig).getNetworkSelectionStatus(); + + assertThat(entry.shouldEditBeforeConnect()).isTrue(); + + // Test DISABLED_BY_WRONG_PASSWORD. + networkSelectionStatus = spy(statusBuilder.setNetworkSelectionStatus( + NETWORK_SELECTION_PERMANENTLY_DISABLED) + .setNetworkSelectionDisableReason(DISABLED_BY_WRONG_PASSWORD) + .build()); + doReturn(1).when(networkSelectionStatus).getDisableReasonCounter( + DISABLED_BY_WRONG_PASSWORD); + + assertThat(entry.shouldEditBeforeConnect()).isTrue(); + + // Test DISABLED_AUTHENTICATION_NO_CREDENTIALS. + networkSelectionStatus = spy(statusBuilder.setNetworkSelectionStatus( + NETWORK_SELECTION_PERMANENTLY_DISABLED) + .setNetworkSelectionDisableReason(DISABLED_AUTHENTICATION_NO_CREDENTIALS) + .build()); + doReturn(1).when(networkSelectionStatus).getDisableReasonCounter( + DISABLED_AUTHENTICATION_NO_CREDENTIALS); + + assertThat(entry.shouldEditBeforeConnect()).isTrue(); + } } |