From 0fd222632e10cfbfac8122a477db0139f80c3385 Mon Sep 17 00:00:00 2001 From: Arif Hussain Date: Tue, 16 Jan 2018 18:16:32 -0800 Subject: WiFi: Ignore connectivity scans during WFD session Any scans will impact WiFi performance including WFD performance. So during WFD session, ignore all connectivity scans initiated internally by wifi work source. This change will not impact any scan triggered due to user activity and will allow those scans. Change-Id: I6a855a8c4853a21fb0ff054c6a5155719ee12b3d CRs-Fixed: 2136506 --- .../com/android/server/wifi/ClientModeImpl.java | 4 ++++ .../server/wifi/WifiConnectivityManager.java | 22 ++++++++++++++++++++++ .../server/wifi/p2p/WifiP2pServiceImpl.java | 5 +++++ 3 files changed, 31 insertions(+) diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index d6645dfd8..14866c87e 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -3515,6 +3515,10 @@ public class ClientModeImpl extends StateMachine { mTemporarilyDisconnectWifi = (message.arg1 == 1); replyToMessage(message, WifiP2pServiceImpl.DISCONNECT_WIFI_RESPONSE); break; + case WifiP2pServiceImpl.SET_MIRACAST_MODE: + if (mVerboseLoggingEnabled) logd("SET_MIRACAST_MODE: " + (int)message.arg1); + mWifiConnectivityManager.saveMiracastMode((int)message.arg1); + break; /* Link configuration (IP address, DNS, ...) changes notified via netlink */ case CMD_UPDATE_LINKPROPERTIES: updateLinkProperties((LinkProperties) message.obj); diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java index 12c64b542..6413f9711 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityManager.java +++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java @@ -23,6 +23,7 @@ import android.annotation.NonNull; import android.app.AlarmManager; import android.content.Context; import android.net.MacAddress; +import android.net.wifi.p2p.WifiP2pManager; import android.net.wifi.ScanResult; import android.net.wifi.SupplicantState; import android.net.wifi.WifiConfiguration; @@ -160,6 +161,7 @@ public class WifiConnectivityManager { private boolean mAutoJoinEnabled = false; // disabled by default, enabled by external triggers private boolean mRunning = false; private boolean mScreenOn = false; + private int mMiracastMode = WifiP2pManager.MIRACAST_DISABLED; private int mWifiState = WIFI_STATE_UNKNOWN; private int mInitialScanState = INITIAL_SCAN_STATE_COMPLETE; private boolean mAutoJoinEnabledExternal = true; // enabled by default @@ -1256,6 +1258,17 @@ public class WifiConnectivityManager { // Start a single scan private void startForcedSingleScan(boolean isFullBandScan, WorkSource workSource) { + // Any scans will impact wifi performance including WFD performance, + // So at least ignore scans triggered internally by ConnectivityManager + // when WFD session is active. We still allow connectivity scans initiated + // by other work source. + if (WIFI_WORK_SOURCE.equals(workSource) && + (mMiracastMode == WifiP2pManager.MIRACAST_SOURCE || + mMiracastMode == WifiP2pManager.MIRACAST_SINK)) { + localLog("Ignore connectivity scan, MiracastMode:" + mMiracastMode); + return; + } + mPnoScanListener.resetLowRssiNetworkRetryDelay(); ScanSettings settings = new ScanSettings(); @@ -1595,6 +1608,15 @@ public class WifiConnectivityManager { startConnectivityScan(SCAN_ON_SCHEDULE); } + /** + * Save current miracast mode, it will be used to ignore + * connectivity scan during the time when miracast is enabled. + */ + public void saveMiracastMode(int mode) { + localLog("saveMiracastMode: mode=" + mode); + mMiracastMode = mode; + } + /** * Helper function that converts the WIFI_STATE_XXX constants to string */ diff --git a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java index eb2a89c4e..05b00f4d9 100644 --- a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java +++ b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java @@ -706,6 +706,11 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { public void setMiracastMode(int mode) { checkConfigureWifiDisplayPermission(); mP2pStateMachine.sendMessage(SET_MIRACAST_MODE, mode); + if (mWifiChannel != null) { + mWifiChannel.sendMessage(WifiP2pServiceImpl.SET_MIRACAST_MODE, mode); + } else { + Log.e(TAG, "setMiracastMode(): WifiChannel is null"); + } } @Override -- cgit v1.2.3