diff options
author | Roshan Pius <rpius@google.com> | 2020-04-01 13:28:00 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2020-04-01 14:49:05 -0700 |
commit | 79acc0e265cf99c62c3601a28b8f89373255b533 (patch) | |
tree | a425a083dd805fdcbb150a762651a18e15b4dcc6 | |
parent | 5bbf5ad184a11aedfc4cb6a9599cb72b95423f00 (diff) |
ClientModeManager: Invoke onStarted() callback only after setting role
ActiveModeWarden on getting the onStarted() needs to evaluate whether
scanner needs to be turned on or off. If the role is not set, then the
ActiveModeManager.getRole() will return UNSPECIFIED when scan only mode
is being turned on and hence scanner will not be turned on.
Also,
a) Ensure that we trigger onStarted() callback if we transition
between various connectivity roles (this code path is unused currently
because we don't support STA + STA).
b) Add a new shell command to toggling wifi scan always available
setting.
Bug: 146824945
Test: Manual verification (failing scenario)
a) Reboot device with wifi off & wifi scanning off.
b) Toggle wifi scanning on.
c) Ensure scans work.
Test: atest com.android.server.wifi
Change-Id: I129f7876cd7f34d51a3cb4036de5259875a7cd2e
3 files changed, 38 insertions, 3 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeManager.java b/service/java/com/android/server/wifi/ClientModeManager.java index fd077d309..66495ae9e 100644 --- a/service/java/com/android/server/wifi/ClientModeManager.java +++ b/service/java/com/android/server/wifi/ClientModeManager.java @@ -505,8 +505,8 @@ public class ClientModeManager implements ActiveModeManager { Log.d(TAG, "entering ScanOnlyModeState"); mClientModeImpl.setOperationalMode(ClientModeImpl.SCAN_ONLY_MODE, mClientInterfaceName); - mModeListener.onStarted(); mRole = ROLE_CLIENT_SCAN_ONLY; + mModeListener.onStarted(); // Inform sar manager that scan only is being enabled mSarManager.setScanOnlyWifiState(WifiManager.WIFI_STATE_ENABLED); @@ -551,8 +551,12 @@ public class ClientModeManager implements ActiveModeManager { public boolean processMessage(Message message) { switch (message.what) { case CMD_SWITCH_TO_CONNECT_MODE: - mRole = message.arg1; - // Already in connect mode, ignore this command. + int newRole = message.arg1; + // Already in connect mode, only switching the connectivity roles. + if (newRole != mRole) { + mRole = newRole; + mModeListener.onStarted(); + } break; case CMD_SWITCH_TO_SCAN_ONLY_MODE: updateConnectModeState(WifiManager.WIFI_STATE_DISABLING, diff --git a/service/java/com/android/server/wifi/WifiShellCommand.java b/service/java/com/android/server/wifi/WifiShellCommand.java index 02e6c19aa..cbab50cd4 100644 --- a/service/java/com/android/server/wifi/WifiShellCommand.java +++ b/service/java/com/android/server/wifi/WifiShellCommand.java @@ -87,6 +87,7 @@ public class WifiShellCommand extends BasicShellCommandHandler { "list-suggestions", "remove-suggestion", "remove-all-suggestions", + "set-scan-always-available", "set-verbose-logging", "set-wifi-enabled", "start-scan", @@ -331,6 +332,11 @@ public class WifiShellCommand extends BasicShellCommandHandler { mWifiService.setWifiEnabled(SHELL_PACKAGE_NAME, enabled); return 0; } + case "set-scan-always-available": { + boolean enabled = getNextArgRequiredTrueOrFalse("enabled", "disabled"); + mWifiService.setScanAlwaysAvailable(enabled); + return 0; + } case "get-softap-supported-features": // This command is used for vts to check softap supported features. if (ApConfigUtil.isAcsSupported(mContext)) { @@ -430,6 +436,9 @@ public class WifiShellCommand extends BasicShellCommandHandler { case "status": boolean wifiEnabled = mWifiService.getWifiEnabledState() == WIFI_STATE_ENABLED; pw.println("Wifi is " + (wifiEnabled ? "enabled" : "disabled")); + pw.println("Wifi scanning is " + + (mWifiService.isScanAlwaysAvailable() + ? "always available" : "only available when wifi is enabled")); WifiInfo info = mWifiService.getConnectionInfo(SHELL_PACKAGE_NAME, null); if (wifiEnabled) { @@ -744,6 +753,8 @@ public class WifiShellCommand extends BasicShellCommandHandler { pw.println(" Gets country code as a two-letter string"); pw.println(" set-wifi-enabled enabled|disabled"); pw.println(" Enables/disables Wifi on this device."); + pw.println(" set-scan-always-available enabled|disabled"); + pw.println(" Sets whether scanning should be available even when wifi is off."); pw.println(" list-scan-results"); pw.println(" Lists the latest scan results"); pw.println(" start-scan"); diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeManagerTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeManagerTest.java index cb3251487..182e8e4f8 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeManagerTest.java @@ -1198,4 +1198,24 @@ public class ClientModeManagerTest extends WifiBaseTest { assertNull(mImsMmTelManagerRegistrationCallback); verify(mWifiMetrics, never()).noteWifiOff(anyBoolean(), anyBoolean(), anyInt()); } + + /** + * ClientMode starts up in connect mode and then change connectivity roles. + */ + @Test + public void clientInConnectModeChangeRoles() throws Exception { + startClientInConnectModeAndVerifyEnabled(); + reset(mListener); + + // Set the same role again, no-op. + assertEquals(ActiveModeManager.ROLE_CLIENT_PRIMARY, mClientModeManager.getRole()); + mClientModeManager.setRole(ActiveModeManager.ROLE_CLIENT_PRIMARY); + mLooper.dispatchAll(); + verify(mListener, never()).onStarted(); // no callback sent. + + // Change the connectivity role. + mClientModeManager.setRole(ActiveModeManager.ROLE_CLIENT_SECONDARY); + mLooper.dispatchAll(); + verify(mListener).onStarted(); // callback sent. + } } |