diff options
author | Quang Luong <qal@google.com> | 2020-08-10 18:36:13 -0700 |
---|---|---|
committer | Quang Luong <qal@google.com> | 2020-08-12 10:03:00 -0700 |
commit | 4976b67589de4033211b4495b1e1c5274cf03474 (patch) | |
tree | 97165e3128bdbaf9a7345d5b805315c7f1ffd7aa /libs | |
parent | 1252c1e8cd21a9b5878c2bdff1f9c1d234b74745 (diff) |
[WifiTrackerLib] Handle isAutoJoinEnabled when no configs available
PasspointWifiEntry may have cases where mPasspointConfig and mWifiConfig
are both null, which can happen for a suggestion passpoint entry that
goes out of range, or the brief moment when a subscription passpoint
entry is forgotten but not yet removed. isAutoJoinEnabled needs to
default to false in case both configs are missing. In addition, to
prevent the wrong value from appearing for the out of range suggestion
case, keep a reference to the old WifiConfig when updating with null
scans.
Bug: 163084959
Test: atest WifiTrackerLibTests
Change-Id: I5eb40308cc01dc6e6f25b90828dd551f0cf4c633
Diffstat (limited to 'libs')
3 files changed, 29 insertions, 14 deletions
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java index e2d7acc8e..9ec431736 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java @@ -45,7 +45,6 @@ import androidx.annotation.WorkerThread; import androidx.lifecycle.Lifecycle; import java.time.Clock; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; @@ -59,6 +58,7 @@ class PasspointNetworkDetailsTracker extends NetworkDetailsTracker { private final PasspointWifiEntry mChosenEntry; private OsuWifiEntry mOsuWifiEntry; private NetworkInfo mCurrentNetworkInfo; + private WifiConfiguration mCurrentWifiConfig; PasspointNetworkDetailsTracker(@NonNull Lifecycle lifecycle, @NonNull Context context, @@ -180,14 +180,16 @@ class PasspointNetworkDetailsTracker extends NetworkDetailsTracker { final String key = uniqueIdToPasspointWifiEntryKey(wifiConfig.getKey()); if (TextUtils.equals(key, mChosenEntry.getKey())) { - mChosenEntry.updateScanResultInfo(wifiConfig, + mCurrentWifiConfig = wifiConfig; + mChosenEntry.updateScanResultInfo(mCurrentWifiConfig, pair.second.get(WifiManager.PASSPOINT_HOME_NETWORK), pair.second.get(WifiManager.PASSPOINT_ROAMING_NETWORK)); return; } } - // No AP in range; set scan results and connection config to null. - mChosenEntry.updateScanResultInfo(null /* wifiConfig */, + // No AP in range; set scan results to null but keep the last seen WifiConfig to display + // the previous information while out of range. + mChosenEntry.updateScanResultInfo(mCurrentWifiConfig, null /* homeScanResults */, null /* roamingScanResults */); } @@ -235,8 +237,9 @@ class PasspointNetworkDetailsTracker extends NetworkDetailsTracker { */ private void conditionallyUpdateScanResults(boolean lastScanSucceeded) { if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLED) { - mChosenEntry.updateScanResultInfo(null /* wifiConfig */, - Collections.emptyList(), Collections.emptyList()); + mChosenEntry.updateScanResultInfo(mCurrentWifiConfig, + null /* homeScanResults */, + null /* roamingScanResults */); return; } diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java index 36c855898..1fca6a4e5 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java @@ -476,26 +476,27 @@ public class PasspointWifiEntry extends WifiEntry implements WifiEntry.WifiEntry @Override public boolean isAutoJoinEnabled() { // Suggestion network; use WifiConfig instead - if (mPasspointConfig == null && mWifiConfig != null) { + if (mPasspointConfig != null) { + return mPasspointConfig.isAutojoinEnabled(); + } + if (mWifiConfig != null) { return mWifiConfig.allowAutojoin; } - - return mPasspointConfig.isAutojoinEnabled(); + return false; } @Override public boolean canSetAutoJoinEnabled() { - return true; + return mPasspointConfig != null || mWifiConfig != null; } @Override public void setAutoJoinEnabled(boolean enabled) { - if (mPasspointConfig == null && mWifiConfig != null) { + if (mPasspointConfig != null) { + mWifiManager.allowAutojoinPasspoint(mPasspointConfig.getHomeSp().getFqdn(), enabled); + } else if (mWifiConfig != null) { mWifiManager.allowAutojoin(mWifiConfig.networkId, enabled); - return; } - - mWifiManager.allowAutojoinPasspoint(mPasspointConfig.getHomeSp().getFqdn(), enabled); } @Override diff --git a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java index fa7812fe6..9fa6a2f40 100644 --- a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java +++ b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java @@ -246,4 +246,15 @@ public class PasspointWifiEntryTest { assertThat(entry.getMacAddress()).isEqualTo(wifiInfoMac); } + + @Test + public void testIsAutoJoinEnabled_nullConfigs_returnsFalse() { + PasspointWifiEntry entry = new PasspointWifiEntry(mMockContext, mTestHandler, + getPasspointConfiguration(), mMockWifiManager, mMockScoreCache, + false /* forSavedNetworksPage */); + + entry.updatePasspointConfig(null); + + assertThat(entry.isAutoJoinEnabled()).isFalse(); + } } |