diff options
Diffstat (limited to 'wifi/java/android')
| -rw-r--r-- | wifi/java/android/net/wifi/WifiStateMachine.java | 44 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/p2p/WifiP2pService.java | 17 |
2 files changed, 39 insertions, 22 deletions
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index b3260b1..4aa092b 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -75,6 +75,7 @@ import android.util.EventLog; import android.util.Log; import android.util.LruCache; +import com.android.internal.R; import com.android.internal.app.IBatteryStats; import com.android.internal.util.AsyncChannel; import com.android.internal.util.Protocol; @@ -112,6 +113,7 @@ public class WifiStateMachine extends StateMachine { private ConnectivityManager mCm; private final boolean mP2pSupported; + private final AtomicBoolean mP2pConnected = new AtomicBoolean(false); private final String mPrimaryDeviceType; /* Scan results handling */ @@ -595,16 +597,16 @@ public class WifiStateMachine extends StateMachine { mScanIntent = PendingIntent.getBroadcast(mContext, SCAN_REQUEST, scanIntent, 0); mDefaultFrameworkScanIntervalMs = mContext.getResources().getInteger( - com.android.internal.R.integer.config_wifi_framework_scan_interval); + R.integer.config_wifi_framework_scan_interval); mDriverStopDelayMs = mContext.getResources().getInteger( - com.android.internal.R.integer.config_wifi_driver_stop_delay); + R.integer.config_wifi_driver_stop_delay); mBackgroundScanSupported = mContext.getResources().getBoolean( - com.android.internal.R.bool.config_wifi_background_scan_support); + R.bool.config_wifi_background_scan_support); mPrimaryDeviceType = mContext.getResources().getString( - com.android.internal.R.string.config_wifi_p2p_device_type); + R.string.config_wifi_p2p_device_type); mUserWantsSuspendOpt.set(Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.WIFI_SUSPEND_OPTIMIZATIONS_ENABLED, 1) == 1); @@ -1771,15 +1773,18 @@ public class WifiStateMachine extends StateMachine { } /* Disable power save and suspend optimizations during DHCP */ - mWifiNative.setPowerSave(false); + // Note: The order here is important for now. Brcm driver changes + // power settings when we control suspend mode optimizations. + // TODO: Remove this comment when the driver is fixed. setSuspendOptimizationsNative(SUSPEND_DUE_TO_DHCP, false); + mWifiNative.setPowerSave(false); } void handlePostDhcpSetup() { /* Restore power save and suspend optimizations */ - mWifiNative.setPowerSave(true); setSuspendOptimizationsNative(SUSPEND_DUE_TO_DHCP, true); + mWifiNative.setPowerSave(true); // Set the coexistence mode back to its default value mWifiNative.setBluetoothCoexistenceMode( @@ -2008,6 +2013,10 @@ public class WifiStateMachine extends StateMachine { replyToMessage(message, WifiManager.RSSI_PKTCNT_FETCH_FAILED, WifiManager.BUSY); break; + case WifiP2pService.P2P_CONNECTION_CHANGED: + NetworkInfo info = (NetworkInfo) message.obj; + mP2pConnected.set(info.isConnected()); + break; default: loge("Error! unhandled message" + message); break; @@ -2405,7 +2414,7 @@ public class WifiStateMachine extends StateMachine { mNetworkInfo.setIsAvailable(true); int defaultInterval = mContext.getResources().getInteger( - com.android.internal.R.integer.config_wifi_supplicant_scan_interval); + R.integer.config_wifi_supplicant_scan_interval); mSupplicantScanIntervalMs = Settings.Global.getLong(mContext.getContentResolver(), Settings.Global.WIFI_SUPPLICANT_SCAN_INTERVAL_MS, @@ -2710,8 +2719,6 @@ public class WifiStateMachine extends StateMachine { mWifiNative.stopFilteringMulticastV4Packets(); } - mWifiNative.setPowerSave(true); - if (mIsScanMode) { mWifiNative.setScanResultHandling(SCAN_ONLY_MODE); mWifiNative.disconnect(); @@ -2736,6 +2743,7 @@ public class WifiStateMachine extends StateMachine { mWifiNative.setSuspendOptimizations(mSuspendOptNeedsDisabled == 0 && mUserWantsSuspendOpt.get()); } + mWifiNative.setPowerSave(true); if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_ENABLE_P2P); } @@ -3484,7 +3492,7 @@ public class WifiStateMachine extends StateMachine { * The scans are useful to notify the user of the presence of an open network. * Note that these are not wake up scans. */ - if (mWifiConfigStore.getConfiguredNetworks().size() == 0) { + if (!mP2pConnected.get() && mWifiConfigStore.getConfiguredNetworks().size() == 0) { sendMessageDelayed(obtainMessage(CMD_NO_NETWORKS_PERIODIC_SCAN, ++mPeriodicScanToken, 0), mSupplicantScanIntervalMs); } @@ -3495,6 +3503,7 @@ public class WifiStateMachine extends StateMachine { boolean ret = HANDLED; switch (message.what) { case CMD_NO_NETWORKS_PERIODIC_SCAN: + if (mP2pConnected.get()) break; if (message.arg1 == mPeriodicScanToken && mWifiConfigStore.getConfiguredNetworks().size() == 0) { sendMessage(CMD_START_SCAN); @@ -3555,6 +3564,21 @@ public class WifiStateMachine extends StateMachine { /* Handled in parent state */ ret = NOT_HANDLED; break; + case WifiP2pService.P2P_CONNECTION_CHANGED: + NetworkInfo info = (NetworkInfo) message.obj; + mP2pConnected.set(info.isConnected()); + if (mP2pConnected.get()) { + int defaultInterval = mContext.getResources().getInteger( + R.integer.config_wifi_scan_interval_p2p_connected); + long scanIntervalMs = Settings.Global.getLong(mContext.getContentResolver(), + Settings.Global.WIFI_SCAN_INTERVAL_WHEN_P2P_CONNECTED_MS, + defaultInterval); + mWifiNative.setScanInterval((int) scanIntervalMs/1000); + } else if (mWifiConfigStore.getConfiguredNetworks().size() == 0) { + if (DBG) log("Turn on scanning after p2p disconnected"); + sendMessageDelayed(obtainMessage(CMD_NO_NETWORKS_PERIODIC_SCAN, + ++mPeriodicScanToken, 0), mSupplicantScanIntervalMs); + } default: ret = NOT_HANDLED; } diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pService.java b/wifi/java/android/net/wifi/p2p/WifiP2pService.java index 58fcc55..dfe1297 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pService.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pService.java @@ -137,18 +137,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub { /* Idle time after a peer is gone when the group is torn down */ private static final int GROUP_IDLE_TIME_S = 20; - /** - * Delay between restarts upon failure to setup connection with supplicant - */ - private static final int P2P_RESTART_INTERVAL_MSECS = 5000; - - /** - * Number of times we attempt to restart p2p - */ - private static final int P2P_RESTART_TRIES = 5; - - private int mP2pRestartCount = 0; - private static final int BASE = Protocol.BASE_WIFI_P2P_SERVICE; /* Delayed message to timeout group creation */ @@ -159,6 +147,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub { /* User rejected a peer request */ private static final int PEER_CONNECTION_USER_REJECT = BASE + 3; + /* Commands to the WifiStateMachine */ + public static final int P2P_CONNECTION_CHANGED = BASE + 11; + private final boolean mP2pSupported; private WifiP2pDevice mThisDevice = new WifiP2pDevice(); @@ -1594,6 +1585,8 @@ public class WifiP2pService extends IWifiP2pManager.Stub { intent.putExtra(WifiP2pManager.EXTRA_WIFI_P2P_INFO, new WifiP2pInfo(mWifiP2pInfo)); intent.putExtra(WifiP2pManager.EXTRA_NETWORK_INFO, new NetworkInfo(mNetworkInfo)); mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); + mWifiChannel.sendMessage(WifiP2pService.P2P_CONNECTION_CHANGED, + new NetworkInfo(mNetworkInfo)); } private void sendP2pPersistentGroupsChangedBroadcast() { |
