diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2020-04-02 03:38:55 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-04-02 03:38:55 +0000 |
commit | c8e9ee6d5a3c085972947e9a11aa71ca7c42ab7b (patch) | |
tree | 4e8eb8a8c60594207f6c742503f96f4c08ae2d44 | |
parent | 609329c636398be2d1fe6eb4a5f63f1fecdd0bce (diff) | |
parent | 79acc0e265cf99c62c3601a28b8f89373255b533 (diff) |
Merge "ClientModeManager: Invoke onStarted() callback only after setting role" into rvc-dev
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. + } } |