summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorNingyuan Wang <nywang@google.com>2017-03-22 19:24:22 -0700
committerNingyuan Wang <nywang@google.com>2017-03-23 21:01:17 +0000
commit1316bfba023da3371bbc590ab2edee19c9475c03 (patch)
treefc7624c9379e368a1ea2e8e43d7801c1599501c4 /service
parentde3a7c0e948c41d7663aae426606889d72b5e9f1 (diff)
Do not initialize connection upon SAVE_NEWORK
This removes the connection request in WifiStateMachine upon SAVE_NETWORK command. This also cleans up the handling and logging of CONNECT_NETWORK and SAVE_NETWORK in WifiServiceImpl. This fixes that bug where WifiStateMachine tries to connect to a network twice because Settings UI calls both save() and connect(). Bug: 36530065 Test: compile, unit tests, manual test Change-Id: I6466c438324220ffa0d5bdea8ef7496f301bcb50
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java57
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java14
2 files changed, 37 insertions, 34 deletions
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index dd8405dce..a95ddabc8 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -201,42 +201,45 @@ public class WifiServiceImpl extends IWifiManager.Stub {
ac.connect(mContext, this, msg.replyTo);
break;
}
- /* Client commands are forwarded to state machine */
- case WifiManager.CONNECT_NETWORK:
- case WifiManager.SAVE_NETWORK: {
+ case WifiManager.CONNECT_NETWORK: {
WifiConfiguration config = (WifiConfiguration) msg.obj;
int networkId = msg.arg1;
- if (msg.what == WifiManager.SAVE_NETWORK) {
- Slog.d("WiFiServiceImpl ", "SAVE"
- + " nid=" + Integer.toString(networkId)
- + " uid=" + msg.sendingUid
- + " name="
- + mContext.getPackageManager().getNameForUid(msg.sendingUid));
- }
- if (msg.what == WifiManager.CONNECT_NETWORK) {
- Slog.d("WiFiServiceImpl ", "CONNECT "
- + " nid=" + Integer.toString(networkId)
- + " uid=" + msg.sendingUid
- + " name="
- + mContext.getPackageManager().getNameForUid(msg.sendingUid));
- }
-
+ Slog.d("WiFiServiceImpl ", "CONNECT "
+ + " nid=" + Integer.toString(networkId)
+ + " uid=" + msg.sendingUid
+ + " name="
+ + mContext.getPackageManager().getNameForUid(msg.sendingUid));
if (config != null && isValid(config)) {
- if (DBG) Slog.d(TAG, "Connect with config" + config);
+ if (DBG) Slog.d(TAG, "Connect with config " + config);
+ /* Command is forwarded to state machine */
mWifiStateMachine.sendMessage(Message.obtain(msg));
} else if (config == null
&& networkId != WifiConfiguration.INVALID_NETWORK_ID) {
- if (DBG) Slog.d(TAG, "Connect with networkId" + networkId);
+ if (DBG) Slog.d(TAG, "Connect with networkId " + networkId);
mWifiStateMachine.sendMessage(Message.obtain(msg));
} else {
Slog.e(TAG, "ClientHandler.handleMessage ignoring invalid msg=" + msg);
- if (msg.what == WifiManager.CONNECT_NETWORK) {
- replyFailed(msg, WifiManager.CONNECT_NETWORK_FAILED,
- WifiManager.INVALID_ARGS);
- } else {
- replyFailed(msg, WifiManager.SAVE_NETWORK_FAILED,
- WifiManager.INVALID_ARGS);
- }
+ replyFailed(msg, WifiManager.CONNECT_NETWORK_FAILED,
+ WifiManager.INVALID_ARGS);
+ }
+ break;
+ }
+ case WifiManager.SAVE_NETWORK: {
+ WifiConfiguration config = (WifiConfiguration) msg.obj;
+ int networkId = msg.arg1;
+ Slog.d("WiFiServiceImpl ", "SAVE"
+ + " nid=" + Integer.toString(networkId)
+ + " uid=" + msg.sendingUid
+ + " name="
+ + mContext.getPackageManager().getNameForUid(msg.sendingUid));
+ if (config != null && isValid(config)) {
+ if (DBG) Slog.d(TAG, "Save network with config " + config);
+ /* Command is forwarded to state machine */
+ mWifiStateMachine.sendMessage(Message.obtain(msg));
+ } else {
+ Slog.e(TAG, "ClientHandler.handleMessage ignoring invalid msg=" + msg);
+ replyFailed(msg, WifiManager.SAVE_NETWORK_FAILED,
+ WifiManager.INVALID_ARGS);
}
break;
}
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index 77d9dd13d..5c5ace5b9 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -5118,13 +5118,13 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
mIpManager.setHttpProxy(
getCurrentWifiConfiguration().getHttpProxy());
}
- } else {
- if (!connectToUserSelectNetwork(netId, message.sendingUid)) {
- messageHandlingStatus = MESSAGE_HANDLING_STATUS_FAIL;
- replyToMessage(message, WifiManager.SAVE_NETWORK_FAILED,
- WifiManager.NOT_AUTHORIZED);
- break;
- }
+ } else if (!mWifiConfigManager.enableNetwork(result.getNetworkId(),
+ false, message.sendingUid)) {
+ loge("ENABLE_NETWORK config=" + config + " failed");
+ messageHandlingStatus = MESSAGE_HANDLING_STATUS_FAIL;
+ replyToMessage(message, WifiManager.SAVE_NETWORK_FAILED,
+ WifiManager.ERROR);
+ break;
}
broadcastWifiCredentialChanged(WifiManager.WIFI_CREDENTIAL_SAVED, config);
replyToMessage(message, WifiManager.SAVE_NETWORK_SUCCEEDED);