summaryrefslogtreecommitdiffstats
path: root/wifi
diff options
context:
space:
mode:
authorIrfan Sheriff <isheriff@google.com>2012-10-18 12:39:22 -0700
committerIrfan Sheriff <isheriff@google.com>2012-10-18 13:35:57 -0700
commit62fa6de135269a7da135bb89b1eb047a4f11d343 (patch)
tree29162bb3e5e460eafe55fa1e42ab66e815bc3c00 /wifi
parent23fa0320b88bd2141742d47eaf2626369cb03b22 (diff)
downloadframeworks_base-62fa6de135269a7da135bb89b1eb047a4f11d343.zip
frameworks_base-62fa6de135269a7da135bb89b1eb047a4f11d343.tar.gz
frameworks_base-62fa6de135269a7da135bb89b1eb047a4f11d343.tar.bz2
Do a clean shutdown of p2p
We were doing a lazy shutdown and stopping supplicant behind p2p's back. Make sure we stop p2p, before we go ahead with shutting down. Bug: 7368832 Change-Id: I941e9cd69d6f27532207d3dc00b03c55c0e6335c
Diffstat (limited to 'wifi')
-rw-r--r--wifi/java/android/net/wifi/WifiStateMachine.java87
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pService.java44
2 files changed, 117 insertions, 14 deletions
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index 196bf2e..fd76fc8 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -359,8 +359,12 @@ public class WifiStateMachine extends StateMachine {
static final int CMD_RESET_SUPPLICANT_STATE = BASE + 111;
/* P2p commands */
+ /* We are ok with no response here since we wont do much with it anyway */
public static final int CMD_ENABLE_P2P = BASE + 131;
- public static final int CMD_DISABLE_P2P = BASE + 132;
+ /* In order to shut down supplicant cleanly, we wait till p2p has
+ * been disabled */
+ public static final int CMD_DISABLE_P2P_REQ = BASE + 132;
+ public static final int CMD_DISABLE_P2P_RSP = BASE + 133;
private static final int CONNECT_MODE = 1;
private static final int SCAN_ONLY_MODE = 2;
@@ -458,6 +462,11 @@ public class WifiStateMachine extends StateMachine {
private State mDriverStartingState = new DriverStartingState();
/* Driver started */
private State mDriverStartedState = new DriverStartedState();
+ /* Wait until p2p is disabled
+ * This is a special state which is entered right after we exit out of DriverStartedState
+ * before transitioning to another state.
+ */
+ private State mWaitForP2pDisableState = new WaitForP2pDisableState();
/* Driver stopping */
private State mDriverStoppingState = new DriverStoppingState();
/* Driver stopped */
@@ -699,6 +708,7 @@ public class WifiStateMachine extends StateMachine {
addState(mDisconnectingState, mConnectModeState);
addState(mDisconnectedState, mConnectModeState);
addState(mWpsRunningState, mConnectModeState);
+ addState(mWaitForP2pDisableState, mSupplicantStartedState);
addState(mDriverStoppingState, mSupplicantStartedState);
addState(mDriverStoppedState, mSupplicantStartedState);
addState(mSupplicantStoppingState, mDefaultState);
@@ -2433,7 +2443,11 @@ public class WifiStateMachine extends StateMachine {
WifiConfiguration config;
switch(message.what) {
case CMD_STOP_SUPPLICANT: /* Supplicant stopped by user */
- transitionTo(mSupplicantStoppingState);
+ if (mP2pSupported) {
+ transitionTo(mWaitForP2pDisableState);
+ } else {
+ transitionTo(mSupplicantStoppingState);
+ }
break;
case WifiMonitor.SUP_DISCONNECTION_EVENT: /* Supplicant connection lost */
loge("Connection lost, restart supplicant");
@@ -2443,7 +2457,11 @@ public class WifiStateMachine extends StateMachine {
handleNetworkDisconnect();
sendSupplicantConnectionChangedBroadcast(false);
mSupplicantStateTracker.sendMessage(CMD_RESET_SUPPLICANT_STATE);
- transitionTo(mDriverLoadedState);
+ if (mP2pSupported) {
+ transitionTo(mWaitForP2pDisableState);
+ } else {
+ transitionTo(mDriverLoadedState);
+ }
sendMessageDelayed(CMD_START_SUPPLICANT, SUPPLICANT_RESTART_INTERVAL_MSECS);
break;
case WifiMonitor.SCAN_RESULTS_EVENT:
@@ -2838,8 +2856,12 @@ public class WifiStateMachine extends StateMachine {
}
mWakeLock.acquire();
mWifiNative.stopDriver();
- transitionTo(mDriverStoppingState);
mWakeLock.release();
+ if (mP2pSupported) {
+ transitionTo(mWaitForP2pDisableState);
+ } else {
+ transitionTo(mDriverStoppingState);
+ }
break;
case CMD_START_PACKET_FILTERING:
if (message.arg1 == MULTICAST_V6) {
@@ -2885,8 +2907,63 @@ public class WifiStateMachine extends StateMachine {
mIsRunning = false;
updateBatteryWorkSource(null);
mScanResults = new ArrayList<ScanResult>();
+ }
+ }
- if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_DISABLE_P2P);
+ class WaitForP2pDisableState extends State {
+ private State mTransitionToState;
+ @Override
+ public void enter() {
+ if (DBG) log(getName() + "\n");
+ EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
+ switch (getCurrentMessage().what) {
+ case WifiMonitor.SUP_DISCONNECTION_EVENT:
+ mTransitionToState = mDriverLoadedState;
+ break;
+ case CMD_DELAYED_STOP_DRIVER:
+ mTransitionToState = mDriverStoppingState;
+ break;
+ case CMD_STOP_SUPPLICANT:
+ mTransitionToState = mSupplicantStoppingState;
+ break;
+ default:
+ mTransitionToState = mDriverStoppingState;
+ break;
+ }
+ mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_DISABLE_P2P_REQ);
+ }
+ @Override
+ public boolean processMessage(Message message) {
+ if (DBG) log(getName() + message.toString() + "\n");
+ switch(message.what) {
+ case WifiStateMachine.CMD_DISABLE_P2P_RSP:
+ transitionTo(mTransitionToState);
+ break;
+ /* Defer wifi start/shut and driver commands */
+ case CMD_LOAD_DRIVER:
+ case CMD_UNLOAD_DRIVER:
+ case CMD_START_SUPPLICANT:
+ case CMD_STOP_SUPPLICANT:
+ case CMD_START_AP:
+ case CMD_STOP_AP:
+ case CMD_START_DRIVER:
+ case CMD_STOP_DRIVER:
+ case CMD_SET_SCAN_MODE:
+ case CMD_SET_SCAN_TYPE:
+ case CMD_SET_COUNTRY_CODE:
+ case CMD_SET_FREQUENCY_BAND:
+ case CMD_START_PACKET_FILTERING:
+ case CMD_STOP_PACKET_FILTERING:
+ case CMD_START_SCAN:
+ case CMD_DISCONNECT:
+ case CMD_REASSOCIATE:
+ case CMD_RECONNECT:
+ deferMessage(message);
+ break;
+ default:
+ return NOT_HANDLED;
+ }
+ return HANDLED;
}
}
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pService.java b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
index 4b90901..7f32431 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pService.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
@@ -134,6 +134,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
private static final int GROUP_CREATING_WAIT_TIME_MS = 120 * 1000;
private static int mGroupCreatingTimeoutIndex = 0;
+ private static final int DISABLE_P2P_WAIT_TIME_MS = 5 * 1000;
+ private static int mDisableP2pTimeoutIndex = 0;
+
/* Set a two minute discover timeout to avoid STA scans from being blocked */
private static final int DISCOVER_TIMEOUT_S = 120;
@@ -153,6 +156,8 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
private static final int DROP_WIFI_USER_ACCEPT = BASE + 4;
/* User wants to keep his wifi connection and drop p2p */
private static final int DROP_WIFI_USER_REJECT = BASE + 5;
+ /* Delayed message to timeout p2p disable */
+ public static final int DISABLE_P2P_TIMED_OUT = BASE + 6;
/* Commands to the WifiStateMachine */
@@ -574,19 +579,25 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
case WifiMonitor.P2P_DEVICE_LOST_EVENT:
case WifiMonitor.P2P_FIND_STOPPED_EVENT:
case WifiMonitor.P2P_SERV_DISC_RESP_EVENT:
- case WifiStateMachine.CMD_ENABLE_P2P:
- case WifiStateMachine.CMD_DISABLE_P2P:
case PEER_CONNECTION_USER_ACCEPT:
case PEER_CONNECTION_USER_REJECT:
case DISCONNECT_WIFI_RESPONSE:
case DROP_WIFI_USER_ACCEPT:
case DROP_WIFI_USER_REJECT:
case GROUP_CREATING_TIMED_OUT:
+ case DISABLE_P2P_TIMED_OUT:
case DhcpStateMachine.CMD_PRE_DHCP_ACTION:
case DhcpStateMachine.CMD_POST_DHCP_ACTION:
case DhcpStateMachine.CMD_ON_QUIT:
case WifiMonitor.P2P_PROV_DISC_FAILURE_EVENT:
break;
+ case WifiStateMachine.CMD_ENABLE_P2P:
+ // Enable is lazy and has no response
+ break;
+ case WifiStateMachine.CMD_DISABLE_P2P_REQ:
+ // If we end up handling in default, p2p is not enabled
+ mWifiChannel.sendMessage(WifiStateMachine.CMD_DISABLE_P2P_RSP);
+ break;
/* unexpected group created, remove */
case WifiMonitor.P2P_GROUP_STARTED_EVENT:
mGroup = (WifiP2pGroup) message.obj;
@@ -689,6 +700,13 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
class P2pDisablingState extends State {
@Override
+ public void enter() {
+ if (DBG) logd(getName());
+ sendMessageDelayed(obtainMessage(DISABLE_P2P_TIMED_OUT,
+ ++mDisableP2pTimeoutIndex, 0), DISABLE_P2P_WAIT_TIME_MS);
+ }
+
+ @Override
public boolean processMessage(Message message) {
if (DBG) logd(getName() + message.toString());
switch (message.what) {
@@ -697,14 +715,25 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
transitionTo(mP2pDisabledState);
break;
case WifiStateMachine.CMD_ENABLE_P2P:
- case WifiStateMachine.CMD_DISABLE_P2P:
+ case WifiStateMachine.CMD_DISABLE_P2P_REQ:
deferMessage(message);
break;
+ case DISABLE_P2P_TIMED_OUT:
+ if (mGroupCreatingTimeoutIndex == message.arg1) {
+ loge("P2p disable timed out");
+ transitionTo(mP2pDisabledState);
+ }
+ break;
default:
return NOT_HANDLED;
}
return HANDLED;
}
+
+ @Override
+ public void exit() {
+ mWifiChannel.sendMessage(WifiStateMachine.CMD_DISABLE_P2P_RSP);
+ }
}
class P2pDisabledState extends State {
@@ -728,9 +757,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
mWifiMonitor.startMonitoring();
transitionTo(mP2pEnablingState);
break;
- case WifiStateMachine.CMD_DISABLE_P2P:
- //Nothing to do
- break;
default:
return NOT_HANDLED;
}
@@ -757,7 +783,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
transitionTo(mP2pDisabledState);
break;
case WifiStateMachine.CMD_ENABLE_P2P:
- case WifiStateMachine.CMD_DISABLE_P2P:
+ case WifiStateMachine.CMD_DISABLE_P2P_REQ:
deferMessage(message);
break;
default:
@@ -788,7 +814,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
case WifiStateMachine.CMD_ENABLE_P2P:
//Nothing to do
break;
- case WifiStateMachine.CMD_DISABLE_P2P:
+ case WifiStateMachine.CMD_DISABLE_P2P_REQ:
if (mPeers.clear()) sendP2pPeersChangedBroadcast();
if (mGroups.clear()) sendP2pPersistentGroupsChangedBroadcast();
@@ -1534,7 +1560,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
}
// Do the regular device lost handling
return NOT_HANDLED;
- case WifiStateMachine.CMD_DISABLE_P2P:
+ case WifiStateMachine.CMD_DISABLE_P2P_REQ:
sendMessage(WifiP2pManager.REMOVE_GROUP);
deferMessage(message);
break;