@@ -194,31 +194,6 @@ void enableAllNetworks() {
194194 }
195195 }
196196
197- /**
198- * Selects the specified network config for connection. This involves
199- * addition/update of the specified config, updating the priority of
200- * all the networks and enabling the given network while disabling others.
201- *
202- * Selecting a network will leave the other networks disabled and
203- * a call to enableAllNetworks() needs to be issued upon a connection
204- * or a failure event from supplicant
205- *
206- * @param config The configuration details in WifiConfiguration
207- * @return the networkId now associated with the specified configuration
208- */
209- int selectNetwork (WifiConfiguration config ) {
210- if (config != null ) {
211- NetworkUpdateResult result = addOrUpdateNetworkNative (config );
212- int netId = result .getNetworkId ();
213- if (netId != INVALID_NETWORK_ID ) {
214- selectNetwork (netId );
215- } else {
216- loge ("Failed to update network " + config );
217- }
218- return netId ;
219- }
220- return INVALID_NETWORK_ID ;
221- }
222197
223198 /**
224199 * Selects the specified network for connection. This involves
@@ -230,8 +205,11 @@ int selectNetwork(WifiConfiguration config) {
230205 * or a failure event from supplicant
231206 *
232207 * @param netId network to select for connection
208+ * @return false if the network id is invalid
233209 */
234- void selectNetwork (int netId ) {
210+ boolean selectNetwork (int netId ) {
211+ if (netId == INVALID_NETWORK_ID ) return false ;
212+
235213 // Reset the priority of each network at start or if it goes too high.
236214 if (mLastPriority == -1 || mLastPriority > 1000000 ) {
237215 for (WifiConfiguration config : mConfiguredNetworks .values ()) {
@@ -256,6 +234,7 @@ void selectNetwork(int netId) {
256234
257235 /* Avoid saving the config & sending a broadcast to prevent settings
258236 * from displaying a disabled list of networks */
237+ return true ;
259238 }
260239
261240 /**
@@ -265,6 +244,12 @@ void selectNetwork(int netId) {
265244 * @return network update result
266245 */
267246 NetworkUpdateResult saveNetwork (WifiConfiguration config ) {
247+ // A new network cannot have null SSID
248+ if (config == null || (config .networkId == INVALID_NETWORK_ID &&
249+ config .SSID == null )) {
250+ return new NetworkUpdateResult (INVALID_NETWORK_ID );
251+ }
252+
268253 boolean newNetwork = (config .networkId == INVALID_NETWORK_ID );
269254 NetworkUpdateResult result = addOrUpdateNetworkNative (config );
270255 int netId = result .getNetworkId ();
0 commit comments