diff options
author | Irfan Sheriff <isheriff@google.com> | 2012-09-17 16:04:57 -0700 |
---|---|---|
committer | Irfan Sheriff <isheriff@google.com> | 2012-09-17 20:52:23 -0700 |
commit | 3809f500c3411af2ab5ab6c706cdb4373940123e (patch) | |
tree | 33c11bfe84a705c8c9d1b178028ff4e1b9eee82c /wifi/java | |
parent | 9da603c2da67207869d7fde18817165fa95d3592 (diff) | |
download | frameworks_base-3809f500c3411af2ab5ab6c706cdb4373940123e.zip frameworks_base-3809f500c3411af2ab5ab6c706cdb4373940123e.tar.gz frameworks_base-3809f500c3411af2ab5ab6c706cdb4373940123e.tar.bz2 |
Disable notification scans when p2p is connected
Also reduce scan interval for STA scans to one minute.
Bug: 7138968
Change-Id: I03620f6d462e4ec90d9bb25bbfe709f63173df21
Diffstat (limited to 'wifi/java')
-rw-r--r-- | wifi/java/android/net/wifi/WifiStateMachine.java | 34 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/p2p/WifiP2pService.java | 17 |
2 files changed, 33 insertions, 18 deletions
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index 9fe1c60..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); @@ -2011,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; @@ -2408,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, @@ -3486,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); } @@ -3497,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); @@ -3557,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 edd1dac..35dd764 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 = 5; - /** - * 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(); @@ -1597,6 +1588,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() { |