diff options
author | Nate(Qiang) Jiang <qiangjiang@google.com> | 2020-02-21 14:08:15 -0800 |
---|---|---|
committer | Nate Jiang <qiangjiang@google.com> | 2020-02-24 18:00:16 +0000 |
commit | 34abfd0239ba324b4f2ec50a7296973b08417e82 (patch) | |
tree | 17636b1a725c612eafee0701e495b1a62452b559 | |
parent | 54618ce5ed136854c9e5d621bb231bfeabfecb5f (diff) |
Move create intenal wificonfig into ExtendedWifiNetworkSuggestion
Bug: 140204283
Test: atest com.android.server.wifi
Change-Id: Ie06b5a5fd08c5411e0dd4824ee1c9e6117fcda3e
-rw-r--r-- | service/java/com/android/server/wifi/NetworkSuggestionNominator.java | 21 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java | 12 |
2 files changed, 16 insertions, 17 deletions
diff --git a/service/java/com/android/server/wifi/NetworkSuggestionNominator.java b/service/java/com/android/server/wifi/NetworkSuggestionNominator.java index 61afce1ea..bc5873484 100644 --- a/service/java/com/android/server/wifi/NetworkSuggestionNominator.java +++ b/service/java/com/android/server/wifi/NetworkSuggestionNominator.java @@ -177,8 +177,8 @@ public class NetworkSuggestionNominator implements WifiNetworkSelector.NetworkNo ExtendedWifiNetworkSuggestion matchingExtNetworkSuggestion = matchingExtNetworkSuggestionsFromSamePackage.stream().findFirst().get(); // Update the WifiConfigManager with the latest WifiConfig - WifiConfiguration config = createConfigForAddingToWifiConfigManager( - matchingExtNetworkSuggestion, true); + WifiConfiguration config = + matchingExtNetworkSuggestion.createInternalWifiConfiguration(); NetworkUpdateResult result = mWifiConfigManager.addOrUpdateNetwork( config, matchingExtNetworkSuggestion.perAppInfo.uid, @@ -224,8 +224,7 @@ public class NetworkSuggestionNominator implements WifiNetworkSelector.NetworkNo if (!ewns.wns.isUserAllowedToManuallyConnect) { continue; } - WifiConfiguration config = - createConfigForAddingToWifiConfigManager(ewns, false); + WifiConfiguration config = ewns.createInternalWifiConfiguration(); WifiConfiguration wCmConfiguredNetwork = mWifiConfigManager.getConfiguredNetwork(config.getKey()); NetworkUpdateResult result = mWifiConfigManager.addOrUpdateNetwork( @@ -256,8 +255,7 @@ public class NetworkSuggestionNominator implements WifiNetworkSelector.NetworkNo // Returns the copy of WifiConfiguration with the allocated network ID filled in. private WifiConfiguration addCandidateToWifiConfigManager( @NonNull ExtendedWifiNetworkSuggestion ewns) { - WifiConfiguration wifiConfiguration = - createConfigForAddingToWifiConfigManager(ewns, true); + WifiConfiguration wifiConfiguration = ewns.createInternalWifiConfiguration(); NetworkUpdateResult result = mWifiConfigManager.addOrUpdateNetwork(wifiConfiguration, ewns.perAppInfo.uid, ewns.perAppInfo.packageName); @@ -274,17 +272,6 @@ public class NetworkSuggestionNominator implements WifiNetworkSelector.NetworkNo return mWifiConfigManager.getConfiguredNetwork(candidateNetworkId); } - private WifiConfiguration createConfigForAddingToWifiConfigManager( - ExtendedWifiNetworkSuggestion ewns, boolean allowAutojoin) { - WifiConfiguration wifiConfiguration = new WifiConfiguration(ewns.wns.wifiConfiguration); - // Mark the network ephemeral because we don't want these persisted by WifiConfigManager. - wifiConfiguration.ephemeral = true; - wifiConfiguration.fromWifiNetworkSuggestion = true; - wifiConfiguration.allowAutojoin = allowAutojoin; - wifiConfiguration.trusted = !ewns.wns.isNetworkUntrusted; - return wifiConfiguration; - } - @Override public @NominatorId int getId() { return NOMINATOR_ID_SUGGESTION; diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java index 176625087..ad7dc7abb 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java +++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java @@ -268,6 +268,18 @@ public class WifiNetworkSuggestionsManager { @NonNull PerAppInfo perAppInfo, boolean isAutoJoinEnabled) { return new ExtendedWifiNetworkSuggestion(wns, perAppInfo, isAutoJoinEnabled); } + + /** + * Create a {@link WifiConfiguration} from suggestion for framework internal use. + */ + public WifiConfiguration createInternalWifiConfiguration() { + WifiConfiguration config = new WifiConfiguration(wns.getWifiConfiguration()); + config.ephemeral = true; + config.fromWifiNetworkSuggestion = true; + config.allowAutojoin = isAutojoinEnabled; + config.trusted = !wns.isNetworkUntrusted; + return config; + } } /** |