diff options
author | Robert Greenwalt <rgreenwalt@google.com> | 2013-06-28 15:55:28 -0700 |
---|---|---|
committer | Robert Greenwalt <rgreenwalt@google.com> | 2013-07-11 11:10:08 -0700 |
commit | 6433ef29006cc151930dd9efdca82e6a4d2833e9 (patch) | |
tree | 017586a076794af532e17874b29f0000dcf00e91 /wifi | |
parent | 0f22b5c311fbe47ae6d26de6c2002acddaa1e086 (diff) | |
download | frameworks_base-6433ef29006cc151930dd9efdca82e6a4d2833e9.zip frameworks_base-6433ef29006cc151930dd9efdca82e6a4d2833e9.tar.gz frameworks_base-6433ef29006cc151930dd9efdca82e6a4d2833e9.tar.bz2 |
Block Wifi P2p discovery while doing dhcp.
bug:9531609
bug:9302399
Change-Id: Ie4b7c3a75245a0e7cc09fa89ddb1187d349779a1
Diffstat (limited to 'wifi')
-rw-r--r-- | wifi/java/android/net/wifi/WifiStateMachine.java | 11 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/p2p/WifiP2pService.java | 64 |
2 files changed, 74 insertions, 1 deletions
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index 82f1084..0077354 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -1771,6 +1771,14 @@ public class WifiStateMachine extends StateMachine { // TODO: Remove this comment when the driver is fixed. setSuspendOptimizationsNative(SUSPEND_DUE_TO_DHCP, false); mWifiNative.setPowerSave(false); + + /* P2p discovery breaks dhcp, shut it down in order to get through this */ + Message msg = new Message(); + msg.what = WifiP2pService.BLOCK_DISCOVERY; + msg.arg1 = WifiP2pService.ENABLED; + msg.arg2 = DhcpStateMachine.CMD_PRE_DHCP_ACTION_COMPLETE; + msg.obj = mDhcpStateMachine; + mWifiP2pChannel.sendMessage(msg); } @@ -1797,6 +1805,8 @@ public class WifiStateMachine extends StateMachine { setSuspendOptimizationsNative(SUSPEND_DUE_TO_DHCP, true); mWifiNative.setPowerSave(true); + mWifiP2pChannel.sendMessage(WifiP2pService.BLOCK_DISCOVERY, WifiP2pService.DISABLED); + // Set the coexistence mode back to its default value mWifiNative.setBluetoothCoexistenceMode( mWifiNative.BLUETOOTH_COEXISTENCE_MODE_SENSE); @@ -2986,7 +2996,6 @@ public class WifiStateMachine extends StateMachine { switch (message.what) { case DhcpStateMachine.CMD_PRE_DHCP_ACTION: handlePreDhcpSetup(); - mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_PRE_DHCP_ACTION_COMPLETE); break; case DhcpStateMachine.CMD_POST_DHCP_ACTION: handlePostDhcpSetup(); diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pService.java b/wifi/java/android/net/wifi/p2p/WifiP2pService.java index 4cfc4ac..68a082a 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pService.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pService.java @@ -166,6 +166,16 @@ public class WifiP2pService extends IWifiP2pManager.Stub { public static final int SET_MIRACAST_MODE = BASE + 14; + // During dhcp (and perhaps other times) we can't afford to drop packets + // but Discovery will switch our channel enough we will. + // msg.arg1 = ENABLED for blocking, DISABLED for resumed. + // msg.arg2 = msg to send when blocked + // msg.obj = StateMachine to send to when blocked + public static final int BLOCK_DISCOVERY = BASE + 15; + + public static final int ENABLED = 1; + public static final int DISABLED = 0; + private final boolean mP2pSupported; private WifiP2pDevice mThisDevice = new WifiP2pDevice(); @@ -182,6 +192,15 @@ public class WifiP2pService extends IWifiP2pManager.Stub { * broadcasts */ private boolean mDiscoveryStarted; + /* Track whether servcice/peer discovery is blocked in favor of other wifi actions + * (notably dhcp) + */ + private boolean mDiscoveryBlocked; + + /* + * remember if we were in a scan when it had to be stopped + */ + private boolean mDiscoveryPostponed = false; private NetworkInfo mNetworkInfo; @@ -479,6 +498,20 @@ public class WifiP2pService extends IWifiP2pManager.Stub { AsyncChannel ac = new AsyncChannel(); ac.connect(mContext, getHandler(), message.replyTo); break; + case BLOCK_DISCOVERY: + mDiscoveryBlocked = (message.arg1 == ENABLED ? true : false); + // always reset this - we went to a state that doesn't support discovery so + // it would have stopped regardless + mDiscoveryPostponed = false; + if (mDiscoveryBlocked) { + try { + StateMachine m = (StateMachine)message.obj; + m.sendMessage(message.arg2); + } catch (Exception e) { + loge("unable to send BLOCK_DISCOVERY response: " + e); + } + } + break; case WifiP2pManager.DISCOVER_PEERS: replyToMessage(message, WifiP2pManager.DISCOVER_PEERS_FAILED, WifiP2pManager.BUSY); @@ -851,7 +884,33 @@ public class WifiP2pService extends IWifiP2pManager.Stub { } break; } + case BLOCK_DISCOVERY: + boolean blocked = (message.arg1 == ENABLED ? true : false); + if (mDiscoveryBlocked == blocked) break; + mDiscoveryBlocked = blocked; + if (blocked && mDiscoveryStarted) { + mWifiNative.p2pStopFind(); + mDiscoveryPostponed = true; + } + if (!blocked && mDiscoveryPostponed) { + mDiscoveryPostponed = false; + mWifiNative.p2pFind(DISCOVER_TIMEOUT_S); + } + if (blocked) { + try { + StateMachine m = (StateMachine)message.obj; + m.sendMessage(message.arg2); + } catch (Exception e) { + loge("unable to send BLOCK_DISCOVERY response: " + e); + } + } + break; case WifiP2pManager.DISCOVER_PEERS: + if (mDiscoveryBlocked) { + replyToMessage(message, WifiP2pManager.DISCOVER_PEERS_FAILED, + WifiP2pManager.BUSY); + break; + } // do not send service discovery request while normal find operation. clearSupplicantServiceRequest(); if (mWifiNative.p2pFind(DISCOVER_TIMEOUT_S)) { @@ -874,6 +933,11 @@ public class WifiP2pService extends IWifiP2pManager.Stub { } break; case WifiP2pManager.DISCOVER_SERVICES: + if (mDiscoveryBlocked) { + replyToMessage(message, WifiP2pManager.DISCOVER_SERVICES_FAILED, + WifiP2pManager.BUSY); + break; + } if (DBG) logd(getName() + " discover services"); if (!updateSupplicantServiceRequest()) { replyToMessage(message, WifiP2pManager.DISCOVER_SERVICES_FAILED, |