summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2020-04-22 15:18:15 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-04-22 15:18:15 +0000
commitb54fb03c140d7608e07d4db6d88e8dfa2c350f7f (patch)
tree8e55e9e92ceac5e296ed4384b561b8906f90bb33 /libs
parentc4bffe9215bb5c0c95c1d402d3826ddca5807829 (diff)
parentac59d7ce4c4f6063e929d55db9f5f6b75f8bfd29 (diff)
Merge "[WifiTrackerLib] Add support for ephemeral connections" into rvc-dev
Diffstat (limited to 'libs')
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/OsuWifiEntry.java5
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java6
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java18
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java40
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java14
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java72
6 files changed, 93 insertions, 62 deletions
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/OsuWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/OsuWifiEntry.java
index b3b99e0b9..55709d1be 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/OsuWifiEntry.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/OsuWifiEntry.java
@@ -130,6 +130,11 @@ class OsuWifiEntry extends WifiEntry {
}
@Override
+ public boolean isSuggestion() {
+ return false;
+ }
+
+ @Override
public boolean isSubscription() {
return false;
}
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java
index e7ed15362..0bcd7ccfb 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java
@@ -213,6 +213,12 @@ public class PasspointWifiEntry extends WifiEntry {
}
@Override
+ public boolean isSuggestion() {
+ // TODO(b/70983952): Fill this method in when passpoint suggestions are in
+ return false;
+ }
+
+ @Override
public boolean isSubscription() {
return true;
}
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java
index 65560d60f..f97ae643f 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java
@@ -175,19 +175,17 @@ class StandardNetworkDetailsTracker extends NetworkDetailsTracker {
}
/**
- * Updates the tracked entry's WifiConfiguration from getConfiguredNetworks(), or sets it to
- * null if it does not exist.
+ * Updates the tracked entry's WifiConfiguration from getPrivilegedConfiguredNetworks(), or sets
+ * it to null if it does not exist.
*/
private void conditionallyUpdateConfig() {
- WifiConfiguration config = mWifiManager.getConfiguredNetworks().stream()
- .filter(savedConfig -> TextUtils.equals(
- wifiConfigToStandardWifiEntryKey(savedConfig), mChosenEntry.getKey()))
- .findAny().orElse(mWifiManager.getPrivilegedConfiguredNetworks().stream()
- .filter(suggestedConfig -> TextUtils.equals(
- wifiConfigToStandardWifiEntryKey(suggestedConfig),
+ WifiConfiguration updatedConfig = mWifiManager.getPrivilegedConfiguredNetworks().stream()
+ .filter(cachedConfig -> !cachedConfig.isPasspoint()
+ && TextUtils.equals(
+ wifiConfigToStandardWifiEntryKey(cachedConfig),
mChosenEntry.getKey()))
- .findAny().orElse(null));
- mChosenEntry.updateConfig(config);
+ .findAny().orElse(null);
+ mChosenEntry.updateConfig(updatedConfig);
}
/**
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java
index f6c3a2b2e..bc164bf1d 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java
@@ -199,7 +199,7 @@ public class StandardWifiEntry extends WifiEntry {
sj.add(mContext.getString(R.string.wifi_disconnected));
} else if (!mForSavedNetworksPage) {
// Summary for unconnected suggested network
- if (mWifiConfig != null && mWifiConfig.fromWifiNetworkSuggestion) {
+ if (isSuggestion()) {
String carrierName = getCarrierNameForSubId(mContext,
getSubIdForConfig(mContext, mWifiConfig));
sj.add(mContext.getString(R.string.available_via_app, carrierName != null
@@ -241,7 +241,7 @@ public class StandardWifiEntry extends WifiEntry {
private String getConnectStateDescription() {
if (getConnectedState() == CONNECTED_STATE_CONNECTED) {
- if (!isSaved()) {
+ if (!isSaved() && !isSuggestion()) {
// Special case for connected + ephemeral networks.
if (!TextUtils.isEmpty(mRecommendationServiceLabel)) {
return String.format(mContext.getString(R.string.connected_via_network_scorer),
@@ -311,7 +311,12 @@ public class StandardWifiEntry extends WifiEntry {
@Override
public boolean isSaved() {
- return mWifiConfig != null;
+ return mWifiConfig != null && !mWifiConfig.isEphemeral();
+ }
+
+ @Override
+ public boolean isSuggestion() {
+ return mWifiConfig != null && mWifiConfig.fromWifiNetworkSuggestion;
}
@Override
@@ -321,10 +326,10 @@ public class StandardWifiEntry extends WifiEntry {
@Override
public WifiConfiguration getWifiConfiguration() {
- if (mWifiConfig != null && !mWifiConfig.fromWifiNetworkSuggestion) {
- return mWifiConfig;
+ if (!isSaved()) {
+ return null;
}
- return null;
+ return mWifiConfig;
}
@Override
@@ -344,7 +349,11 @@ public class StandardWifiEntry extends WifiEntry {
// We should flag this network to auto-open captive portal since this method represents
// the user manually connecting to a network (i.e. not auto-join).
mShouldAutoOpenCaptivePortal = true;
- if (mWifiConfig == null) {
+
+ if (isSaved() || isSuggestion()) {
+ // Saved/suggested network
+ mWifiManager.connect(mWifiConfig.networkId, new ConnectActionListener());
+ } else {
// Unsaved network
if (mSecurity == SECURITY_NONE
|| mSecurity == SECURITY_OWE) {
@@ -368,9 +377,6 @@ public class StandardWifiEntry extends WifiEntry {
ConnectCallback.CONNECT_STATUS_FAILURE_NO_CONFIG));
}
}
- } else {
- // Saved network
- mWifiManager.connect(mWifiConfig.networkId, new ConnectActionListener());
}
}
@@ -525,7 +531,7 @@ public class StandardWifiEntry extends WifiEntry {
@Override
public boolean canSetPrivacy() {
- return getWifiConfiguration() != null;
+ return isSaved();
}
@Override
@@ -552,7 +558,7 @@ public class StandardWifiEntry extends WifiEntry {
@Override
public boolean isAutoJoinEnabled() {
- if (!isSaved()) {
+ if (mWifiConfig == null) {
return false;
}
@@ -561,11 +567,15 @@ public class StandardWifiEntry extends WifiEntry {
@Override
public boolean canSetAutoJoinEnabled() {
- return isSaved();
+ return isSaved() || isSuggestion();
}
@Override
public void setAutoJoinEnabled(boolean enabled) {
+ if (!canSetAutoJoinEnabled()) {
+ return;
+ }
+
mWifiManager.allowAutojoin(mWifiConfig.networkId, enabled);
}
@@ -746,10 +756,6 @@ public class StandardWifiEntry extends WifiEntry {
}
if (mWifiConfig != null) {
- if (mWifiConfig.fromWifiNetworkSuggestion) {
- // Match network suggestions with SSID since the net id is prone to change.
- return TextUtils.equals(mSsid, sanitizeSsid(wifiInfo.getSSID()));
- }
if (mWifiConfig.networkId == wifiInfo.getNetworkId()) {
return true;
}
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java
index afe8b5fba..78b339bf2 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java
@@ -287,6 +287,11 @@ public abstract class WifiEntry implements Comparable<WifiEntry> {
public abstract boolean isSaved();
/**
+ * Indicates whether or not an entry is for a saved configuration.
+ */
+ public abstract boolean isSuggestion();
+
+ /**
* Indicates whether or not an entry is for a subscription.
*/
public abstract boolean isSubscription();
@@ -729,6 +734,9 @@ public abstract class WifiEntry implements Comparable<WifiEntry> {
if (isSaved() && !other.isSaved()) return -1;
if (!isSaved() && other.isSaved()) return 1;
+ if (isSuggestion() && !other.isSuggestion()) return -1;
+ if (!isSuggestion() && other.isSuggestion()) return 1;
+
if (getLevel() > other.getLevel()) return -1;
if (getLevel() < other.getLevel()) return 1;
@@ -749,6 +757,12 @@ public abstract class WifiEntry implements Comparable<WifiEntry> {
.append(getTitle())
.append(",summary:")
.append(getSummary())
+ .append(",isSaved:")
+ .append(isSaved())
+ .append(",isSubscription:")
+ .append(isSubscription())
+ .append(",isSuggestion:")
+ .append(isSuggestion())
.append(",level:")
.append(getLevel())
.append(",security:")
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
index c48ca738d..33a9b777a 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
@@ -164,7 +164,8 @@ public class WifiPickerTracker extends BaseWifiTracker {
*/
@AnyThread
public int getNumSavedNetworks() {
- return mWifiConfigCache.size();
+ return (int) mWifiConfigCache.values().stream()
+ .filter(config -> !config.isEphemeral()).count();
}
/**
@@ -178,10 +179,8 @@ public class WifiPickerTracker extends BaseWifiTracker {
@WorkerThread
@Override
protected void handleOnStart() {
- updateStandardWifiEntryConfigs(mWifiManager.getConfiguredNetworks());
- updateSuggestedWifiEntryConfigs(mWifiManager.getPrivilegedConfiguredNetworks().stream()
- .filter(config -> config.fromWifiNetworkSuggestion).collect(toList()));
- updatePasspointWifiEntryConfigs(mWifiManager.getPasspointConfigurations());
+ updateWifiConfigurations(mWifiManager.getPrivilegedConfiguredNetworks());
+ updatePasspointConfigurations(mWifiManager.getPasspointConfigurations());
mScanResultUpdater.update(mWifiManager.getScanResults());
conditionallyUpdateScanResults(true /* lastScanSucceeded */);
final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
@@ -218,16 +217,13 @@ public class WifiPickerTracker extends BaseWifiTracker {
final WifiConfiguration config =
(WifiConfiguration) intent.getExtra(WifiManager.EXTRA_WIFI_CONFIGURATION);
- if (config != null && !config.isEphemeral() && !config.isPasspoint()) {
- updateStandardWifiEntryConfig(
+ if (config != null && !config.isPasspoint()) {
+ updateWifiConfiguration(
config, (Integer) intent.getExtra(WifiManager.EXTRA_CHANGE_REASON));
} else {
- updateStandardWifiEntryConfigs(mWifiManager.getConfiguredNetworks());
- updateSuggestedWifiEntryConfigs(mWifiManager.getPrivilegedConfiguredNetworks().stream()
- .filter((privilegedConfig) -> privilegedConfig.fromWifiNetworkSuggestion)
- .collect(toList()));
+ updateWifiConfigurations(mWifiManager.getPrivilegedConfiguredNetworks());
}
- updatePasspointWifiEntryConfigs(mWifiManager.getPasspointConfigurations());
+ updatePasspointConfigurations(mWifiManager.getPasspointConfigurations());
// Update scans since config changes may result in different entries being shown.
final List<ScanResult> scanResults = mScanResultUpdater.getScanResults();
updateStandardWifiEntryScans(scanResults);
@@ -433,7 +429,7 @@ public class WifiPickerTracker extends BaseWifiTracker {
wifiEntry.updateConfig(mSuggestedConfigCache.get(key));
wifiEntry.setUserShareable(false);
}
- return !wifiEntry.isSaved();
+ return !wifiEntry.isSuggestion();
});
}
@@ -533,19 +529,21 @@ public class WifiPickerTracker extends BaseWifiTracker {
}
/**
- * Updates a single WifiConfiguration for the corresponding StandardWifiEntry if it exists.
+ * Updates the WifiConfiguration caches for a single saved/ephemeral/suggested network and
+ * updates the corresponding WifiEntry with the new config.
*
* @param config WifiConfiguration to update
* @param changeReason WifiManager.CHANGE_REASON_ADDED, WifiManager.CHANGE_REASON_REMOVED, or
* WifiManager.CHANGE_REASON_CONFIG_CHANGE
*/
@WorkerThread
- private void updateStandardWifiEntryConfig(@NonNull WifiConfiguration config,
+ private void updateWifiConfiguration(@NonNull WifiConfiguration config,
int changeReason) {
checkNotNull(config, "Config should not be null!");
final String key = wifiConfigToStandardWifiEntryKey(config);
final StandardWifiEntry entry = mStandardWifiEntryCache.get(key);
+ final StandardWifiEntry suggestedEntry = mSuggestedWifiEntryCache.get(key);
if (entry != null) {
if (changeReason == WifiManager.CHANGE_REASON_REMOVED) {
@@ -554,21 +552,34 @@ public class WifiPickerTracker extends BaseWifiTracker {
mWifiConfigCache.put(key, config);
}
entry.updateConfig(mWifiConfigCache.get(key));
+ } else if (suggestedEntry != null) {
+ if (changeReason == WifiManager.CHANGE_REASON_REMOVED) {
+ mWifiConfigCache.remove(key);
+ } else { // CHANGE_REASON_ADDED || CHANGE_REASON_CONFIG_CHANGE
+ mWifiConfigCache.put(key, config);
+ }
+ suggestedEntry.updateConfig(mWifiConfigCache.get(key));
}
}
/**
- * Updates all saved WifiConfigurations for the corresponding StandardWifiEntries if they exist.
+ * Updates the WifiConfiguration caches for saved/ephemeral/suggested networks and updates the
+ * corresponding WifiEntries with the new configs.
*
- * @param configs List of saved WifiConfigurations
+ * @param configs List of all saved/ephemeral/suggested WifiConfigurations
*/
@WorkerThread
- private void updateStandardWifiEntryConfigs(@NonNull List<WifiConfiguration> configs) {
+ private void updateWifiConfigurations(@NonNull List<WifiConfiguration> configs) {
checkNotNull(configs, "Config list should not be null!");
mWifiConfigCache.clear();
- mWifiConfigCache.putAll(configs.stream().collect(Collectors.toMap(
- StandardWifiEntry::wifiConfigToStandardWifiEntryKey,
- Function.identity())));
+ mSuggestedConfigCache.clear();
+ for (WifiConfiguration config : configs) {
+ if (config.fromWifiNetworkSuggestion) {
+ mSuggestedConfigCache.put(wifiConfigToStandardWifiEntryKey(config), config);
+ } else {
+ mWifiConfigCache.put(wifiConfigToStandardWifiEntryKey(config), config);
+ }
+ }
// Iterate through current entries and update each entry's config
mStandardWifiEntryCache.entrySet().forEach((entry) -> {
@@ -576,17 +587,8 @@ public class WifiPickerTracker extends BaseWifiTracker {
final String key = wifiEntry.getKey();
wifiEntry.updateConfig(mWifiConfigCache.get(key));
});
- }
-
- @WorkerThread
- private void updateSuggestedWifiEntryConfigs(@NonNull List<WifiConfiguration> configs) {
- checkNotNull(configs, "Config list should not be null!");
- mSuggestedConfigCache.clear();
- mSuggestedConfigCache.putAll(configs.stream().collect(Collectors.toMap(
- StandardWifiEntry::wifiConfigToStandardWifiEntryKey,
- Function.identity())));
- // Iterate through current entries and update each entry's config
+ // Iterate through current suggestion entries and update each entry's config
mSuggestedWifiEntryCache.entrySet().removeIf((entry) -> {
final StandardWifiEntry wifiEntry = entry.getValue();
final String key = wifiEntry.getKey();
@@ -601,7 +603,7 @@ public class WifiPickerTracker extends BaseWifiTracker {
}
@WorkerThread
- private void updatePasspointWifiEntryConfigs(@NonNull List<PasspointConfiguration> configs) {
+ private void updatePasspointConfigurations(@NonNull List<PasspointConfiguration> configs) {
checkNotNull(configs, "Config list should not be null!");
mPasspointConfigCache.clear();
mPasspointConfigCache.putAll(configs.stream().collect(
@@ -691,11 +693,11 @@ public class WifiPickerTracker extends BaseWifiTracker {
return;
}
+ final int connectedNetId = wifiInfo.getNetworkId();
mSuggestedConfigCache.values().stream()
.filter(config ->
- TextUtils.equals(config.SSID, wifiInfo.getSSID())
- && !mSuggestedWifiEntryCache.containsKey(
- wifiConfigToStandardWifiEntryKey(config)))
+ config.networkId == connectedNetId && !mSuggestedWifiEntryCache.containsKey(
+ wifiConfigToStandardWifiEntryKey(config)))
.findAny().ifPresent(config -> {
final StandardWifiEntry connectedEntry =
new StandardWifiEntry(mContext, mMainHandler,