diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2020-06-11 01:04:16 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2020-06-11 01:04:16 +0000 |
commit | 74ceeb115e450c773044af4a8b851bc5812745db (patch) | |
tree | 911a5a1a6722d07cf866adf78ca69f7a71156cb3 | |
parent | 7ba5599eed4bf85c30ed553e872a3ac55b270d4d (diff) | |
parent | 26f301289715dc01a3906c04ce867d051f0a8553 (diff) |
Snap for 6578268 from 26f301289715dc01a3906c04ce867d051f0a8553 to rvc-release
Change-Id: I25f3e87109b7cd02f8149138ab66a1b7a0fd79c7
6 files changed, 132 insertions, 20 deletions
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/OsuWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/OsuWifiEntry.java index 16e55fb96..89d780eba 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/OsuWifiEntry.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/OsuWifiEntry.java @@ -61,6 +61,7 @@ class OsuWifiEntry extends WifiEntry { @NonNull private final Context mContext; @NonNull private OsuProvider mOsuProvider; private String mOsuStatusString; + private boolean mIsAlreadyProvisioned = false; /** * Create n OsuWifiEntry with the associated OsuProvider @@ -92,8 +93,14 @@ class OsuWifiEntry extends WifiEntry { @Override public String getSummary(boolean concise) { // TODO(b/70983952): Add verbose summary - return mOsuStatusString != null - ? mOsuStatusString : mContext.getString(R.string.tap_to_sign_up); + if (mOsuStatusString != null) { + return mOsuStatusString; + } else if (isAlreadyProvisioned()) { + return concise ? mContext.getString(R.string.wifi_passpoint_expired) + : mContext.getString(R.string.tap_to_renew_subscription_and_connect); + } else { + return mContext.getString(R.string.tap_to_sign_up); + } } @Override @@ -308,6 +315,14 @@ class OsuWifiEntry extends WifiEntry { return mOsuProvider; } + boolean isAlreadyProvisioned() { + return mIsAlreadyProvisioned; + } + + void setAlreadyProvisioned(boolean isAlreadyProvisioned) { + mIsAlreadyProvisioned = isAlreadyProvisioned; + } + class OsuWifiEntryProvisioningCallback extends ProvisioningCallback { @Override @MainThread public void onProvisioningFailure(int status) { diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java index 00c786fac..9bd2a5905 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java @@ -20,6 +20,7 @@ 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; @@ -31,6 +32,7 @@ import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; +import android.net.wifi.hotspot2.OsuProvider; import android.net.wifi.hotspot2.PasspointConfiguration; import android.os.Handler; import android.text.TextUtils; @@ -54,6 +56,7 @@ class PasspointNetworkDetailsTracker extends NetworkDetailsTracker { private static final String TAG = "PasspointNetworkDetailsTracker"; private final PasspointWifiEntry mChosenEntry; + private OsuWifiEntry mOsuWifiEntry; PasspointNetworkDetailsTracker(@NonNull Lifecycle lifecycle, @NonNull Context context, @@ -187,6 +190,43 @@ class PasspointNetworkDetailsTracker extends NetworkDetailsTracker { null /* roamingScanResults */); } + @WorkerThread + private void updateOsuWifiEntryScans(@NonNull List<ScanResult> scanResults) { + checkNotNull(scanResults, "Scan Result list should not be null!"); + + Map<OsuProvider, List<ScanResult>> osuProviderToScans = + mWifiManager.getMatchingOsuProviders(scanResults); + Map<OsuProvider, PasspointConfiguration> osuProviderToPasspointConfig = + mWifiManager.getMatchingPasspointConfigsForOsuProviders( + osuProviderToScans.keySet()); + + if (mOsuWifiEntry != null) { + mOsuWifiEntry.updateScanResultInfo(osuProviderToScans.get( + mOsuWifiEntry.getOsuProvider())); + } else { + // Create a new OsuWifiEntry to link to the chosen PasspointWifiEntry + for (OsuProvider provider : osuProviderToScans.keySet()) { + PasspointConfiguration provisionedConfig = + osuProviderToPasspointConfig.get(provider); + if (provisionedConfig != null && TextUtils.equals(mChosenEntry.getKey(), + uniqueIdToPasspointWifiEntryKey(provisionedConfig.getUniqueId()))) { + mOsuWifiEntry = new OsuWifiEntry(mContext, mMainHandler, provider, mWifiManager, + mWifiNetworkScoreCache, false /* forSavedNetworksPage */); + mOsuWifiEntry.updateScanResultInfo(osuProviderToScans.get(provider)); + mOsuWifiEntry.setAlreadyProvisioned(true); + mChosenEntry.setOsuWifiEntry(mOsuWifiEntry); + return; + } + } + } + + // Remove mOsuWifiEntry if it is no longer reachable + if (mOsuWifiEntry != null && mOsuWifiEntry.getLevel() == WIFI_LEVEL_UNREACHABLE) { + mChosenEntry.setOsuWifiEntry(null); + mOsuWifiEntry = null; + } + } + /** * 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. @@ -207,7 +247,9 @@ class PasspointNetworkDetailsTracker extends NetworkDetailsTracker { scanAgeWindow += mScanIntervalMillis; } - updatePasspointWifiEntryScans(mScanResultUpdater.getScanResults(scanAgeWindow)); + List<ScanResult> currentScans = mScanResultUpdater.getScanResults(scanAgeWindow); + updatePasspointWifiEntryScans(currentScans); + updateOsuWifiEntryScans(currentScans); } /** diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java index ebabadef3..20a87e760 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java @@ -62,7 +62,7 @@ import java.util.StringJoiner; * WifiEntry representation of a subscribed Passpoint network, uniquely identified by FQDN. */ @VisibleForTesting -public class PasspointWifiEntry extends WifiEntry { +public class PasspointWifiEntry extends WifiEntry implements WifiEntry.WifiEntryCallback { static final String KEY_PREFIX = "PasspointWifiEntry:"; private final Object mLock = new Object(); @@ -81,6 +81,7 @@ public class PasspointWifiEntry extends WifiEntry { @Nullable private WifiConfiguration mWifiConfig; private @Security int mSecurity = SECURITY_EAP; private boolean mIsRoaming = false; + private OsuWifiEntry mOsuWifiEntry; protected long mSubscriptionExpirationTimeInMillis; @@ -143,19 +144,33 @@ public class PasspointWifiEntry extends WifiEntry { } @Override + @ConnectedState + public int getConnectedState() { + if (isExpired()) { + if (super.getConnectedState() == CONNECTED_STATE_DISCONNECTED + && mOsuWifiEntry != null) { + return mOsuWifiEntry.getConnectedState(); + } + } + return super.getConnectedState(); + } + + @Override public String getTitle() { return mFriendlyName; } @Override public String getSummary(boolean concise) { - if (isExpired()) { - return mContext.getString(R.string.wifi_passpoint_expired); - } - StringJoiner sj = new StringJoiner(mContext.getString(R.string.summary_separator)); - if (getConnectedState() == CONNECTED_STATE_DISCONNECTED) { + if (isExpired()) { + if (mOsuWifiEntry != null) { + sj.add(mOsuWifiEntry.getSummary(concise)); + } else { + sj.add(mContext.getString(R.string.wifi_passpoint_expired)); + } + } else if (getConnectedState() == CONNECTED_STATE_DISCONNECTED) { String disconnectDescription = getDisconnectedStateDescription(mContext, this); if (TextUtils.isEmpty(disconnectDescription)) { if (concise) { @@ -257,7 +272,6 @@ public class PasspointWifiEntry extends WifiEntry { @Override @Security public int getSecurity() { - // TODO(b/70983952): Fill this method in return mSecurity; } @@ -280,7 +294,6 @@ public class PasspointWifiEntry extends WifiEntry { @Override public boolean isSuggestion() { - // TODO(b/70983952): Fill this method in when passpoint suggestions are in return mWifiConfig != null && mWifiConfig.fromWifiNetworkSuggestion; } @@ -296,12 +309,23 @@ public class PasspointWifiEntry extends WifiEntry { @Override public boolean canConnect() { + if (isExpired()) { + return mOsuWifiEntry != null && mOsuWifiEntry.canConnect(); + } + return mLevel != WIFI_LEVEL_UNREACHABLE && getConnectedState() == CONNECTED_STATE_DISCONNECTED && mWifiConfig != null; } @Override public void connect(@Nullable ConnectCallback callback) { + if (isExpired()) { + if (mOsuWifiEntry != null) { + mOsuWifiEntry.connect(callback); + return; + } + } + mConnectCallback = callback; if (mWifiConfig == null) { @@ -593,4 +617,16 @@ public class PasspointWifiEntry extends WifiEntry { String getNetworkSelectionDescription() { return Utils.getNetworkSelectionDescription(mWifiConfig); } + + /** Pass a reference to a matching OsuWifiEntry for expiration handling */ + void setOsuWifiEntry(OsuWifiEntry osuWifiEntry) { + mOsuWifiEntry = osuWifiEntry; + mOsuWifiEntry.setListener(this); + } + + /** Callback for updates to the linked OsuWifiEntry */ + @Override + public void onUpdated() { + notifyOnUpdated(); + } } diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java index 751e8b9b7..2b433bb76 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java @@ -348,7 +348,8 @@ public class WifiPickerTracker extends BaseWifiTracker { mWifiEntries.addAll(mPasspointWifiEntryCache.values().stream().filter(entry -> entry.getConnectedState() == CONNECTED_STATE_DISCONNECTED).collect(toList())); mWifiEntries.addAll(mOsuWifiEntryCache.values().stream().filter(entry -> - entry.getConnectedState() == CONNECTED_STATE_DISCONNECTED).collect(toList())); + entry.getConnectedState() == CONNECTED_STATE_DISCONNECTED + && !entry.isAlreadyProvisioned()).collect(toList())); Collections.sort(mWifiEntries); if (isVerboseLoggingEnabled()) { Log.v(TAG, "Connected WifiEntry: " + mConnectedWifiEntry); @@ -500,9 +501,9 @@ public class WifiPickerTracker extends BaseWifiTracker { Map<OsuProvider, List<ScanResult>> osuProviderToScans = mWifiManager.getMatchingOsuProviders(scanResults); - Set<OsuProvider> alreadyProvisioned = - mWifiManager.getMatchingPasspointConfigsForOsuProviders(osuProviderToScans.keySet()) - .keySet(); + Map<OsuProvider, PasspointConfiguration> osuProviderToPasspointConfig = + mWifiManager.getMatchingPasspointConfigsForOsuProviders( + osuProviderToScans.keySet()); // Update each OsuWifiEntry with new scans (or empty scans). for (OsuWifiEntry entry : mOsuWifiEntryCache.values()) { entry.updateScanResultInfo(osuProviderToScans.remove(entry.getOsuProvider())); @@ -516,10 +517,27 @@ public class WifiPickerTracker extends BaseWifiTracker { mOsuWifiEntryCache.put(osuProviderToOsuWifiEntryKey(provider), newEntry); } - // Remove entries that are now unreachable or already provisioned + // Pass a reference of each OsuWifiEntry to any matching provisioned PasspointWifiEntries + // for expiration handling. + mOsuWifiEntryCache.values().forEach(osuEntry -> { + PasspointConfiguration provisionedConfig = + osuProviderToPasspointConfig.get(osuEntry.getOsuProvider()); + if (provisionedConfig == null) { + osuEntry.setAlreadyProvisioned(false); + return; + } + osuEntry.setAlreadyProvisioned(true); + PasspointWifiEntry provisionedEntry = mPasspointWifiEntryCache.get( + uniqueIdToPasspointWifiEntryKey(provisionedConfig.getUniqueId())); + if (provisionedEntry == null) { + return; + } + provisionedEntry.setOsuWifiEntry(osuEntry); + }); + + // Remove entries that are now unreachable mOsuWifiEntryCache.entrySet() - .removeIf(entry -> entry.getValue().getLevel() == WIFI_LEVEL_UNREACHABLE - || alreadyProvisioned.contains(entry.getValue().getOsuProvider())); + .removeIf(entry -> entry.getValue().getLevel() == WIFI_LEVEL_UNREACHABLE); } @WorkerThread diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index e10d5367e..10a41f5dc 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -5852,6 +5852,9 @@ public class ClientModeImpl extends StateMachine { && mTargetWifiConfiguration.networkId == requestData.networkId) { logd("id matches targetWifiConfiguration"); + } else if (mLastNetworkId != WifiConfiguration.INVALID_NETWORK_ID + && mLastNetworkId == requestData.networkId) { + logd("id matches currentWifiConfiguration"); } else { logd("id does not match targetWifiConfiguration"); return; diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java index 6f0de57e2..f7fc9c2db 100644 --- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java @@ -50,7 +50,6 @@ import com.android.server.wifi.util.NativeUtil; import com.android.wifi.resources.R; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -249,7 +248,6 @@ public class SupplicantStaNetworkHalTest extends WifiBaseTest { /** * Tests the saving/loading of WifiConfiguration to wpa_supplicant. */ - @Ignore("b/148963201: flaky test") @Test public void testWepNetworkWifiConfigurationSaveLoad() throws Exception { WifiConfiguration config = WifiConfigurationTestUtil.createWepHiddenNetwork(); |