Merge "Call broadcastAuthenticationFailureEvent with the assocRejectInfo's SSID instead of the cached SSID, during the handling of an association rejection event." into tm-mainline-prod
diff --git a/service/java/com/android/server/wifi/ActiveModeWarden.java b/service/java/com/android/server/wifi/ActiveModeWarden.java
index 570508b..2b6d204 100644
--- a/service/java/com/android/server/wifi/ActiveModeWarden.java
+++ b/service/java/com/android/server/wifi/ActiveModeWarden.java
@@ -137,6 +137,7 @@
private boolean mIsMultiplePrimaryBugreportTaken = false;
private boolean mIsShuttingdown = false;
private boolean mVerboseLoggingEnabled = false;
+ private boolean mAllowRootToGetLocalOnlyCmm = true;
/** Cache to store the external scorer for primary and secondary (MBB) client mode manager. */
@Nullable private Pair<IBinder, IWifiConnectedNetworkScorer> mClientModeManagerScorer;
@@ -425,6 +426,15 @@
}
/**
+ * Used for testing with wifi shell command. If enabled the root will be able to request for a
+ * secondary local-only CMM when commands like add-request is used. If disabled, add-request
+ * will fallback to using the primary CMM.
+ */
+ public void allowRootToGetLocalOnlyCmm(boolean enabled) {
+ mAllowRootToGetLocalOnlyCmm = enabled;
+ }
+
+ /**
* Enable verbose logging.
*/
public void enableVerboseLogging(boolean verbose) {
@@ -2120,6 +2130,9 @@
WorkSource workSource = requestInfo.requestorWs;
for (int i = 0; i < workSource.size(); i++) {
int curUid = workSource.getUid(i);
+ if (mAllowRootToGetLocalOnlyCmm && curUid == 0) { // 0 is root UID.
+ continue;
+ }
if (mWifiPermissionsUtil.checkEnterCarModePrioritized(curUid)) {
requestInfo.listener.onAnswer(primaryManager);
if (mVerboseLoggingEnabled) {
diff --git a/service/java/com/android/server/wifi/WifiShellCommand.java b/service/java/com/android/server/wifi/WifiShellCommand.java
index d15be8a..b2a29c1 100644
--- a/service/java/com/android/server/wifi/WifiShellCommand.java
+++ b/service/java/com/android/server/wifi/WifiShellCommand.java
@@ -1067,6 +1067,11 @@
printWifiNetworkSuggestions(pw, suggestions);
return 0;
}
+ case "allow-root-to-get-local-only-cmm": {
+ boolean enabled = getNextArgRequiredTrueOrFalse("enabled", "disabled");
+ mActiveModeWarden.allowRootToGetLocalOnlyCmm(enabled);
+ return 0;
+ }
case "add-request": {
Pair<String, NetworkRequest> result = buildNetworkRequest(pw);
String ssid = result.first;
@@ -2532,6 +2537,9 @@
pw.println(" each on a separate line.");
pw.println(" settings-reset");
pw.println(" Initiates wifi settings reset");
+ pw.println(" allow-root-to-get-local-only-cmm enabled|disabled");
+ pw.println(" sets whether the shell running as root could use the local-only secondary "
+ + "STA");
pw.println(" add-request [-g] [-i] [-n] [-s] <ssid> open|owe|wpa2|wpa3 [<passphrase>]"
+ " [-b <bssid>] [-d <band=2|5|6|60>]");
pw.println(" Add a network request with provided params");
diff --git a/service/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java b/service/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java
index a4e99a6..09d658a 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java
@@ -3795,6 +3795,55 @@
}
@Test
+ public void testRequestForSecondaryLocalOnlyForShell() throws Exception {
+ // mock caller to have ENTER_CAR_MODE_PRIORITIZED
+ when(mWifiPermissionsUtil.checkEnterCarModePrioritized(anyInt())).thenReturn(true);
+ // Ensure that we can create more client ifaces.
+ when(mWifiNative.isItPossibleToCreateStaIface(any())).thenReturn(true);
+ when(mResources.getBoolean(R.bool.config_wifiMultiStaLocalOnlyConcurrencyEnabled))
+ .thenReturn(true);
+ when(mResources.getBoolean(R.bool.config_wifiMultiStaRestrictedConcurrencyEnabled))
+ .thenReturn(true);
+ assertTrue(mActiveModeWarden.canRequestMoreClientModeManagersInRole(
+ TEST_WORKSOURCE, ROLE_CLIENT_LOCAL_ONLY, false));
+ assertTrue(mActiveModeWarden.canRequestMoreClientModeManagersInRole(
+ TEST_WORKSOURCE, ROLE_CLIENT_SECONDARY_LONG_LIVED, false));
+
+ enterClientModeActiveState();
+ ArgumentCaptor<ClientModeManager> requestedClientModeManager =
+ ArgumentCaptor.forClass(ClientModeManager.class);
+ ExternalClientModeManagerRequestListener externalRequestListener = mock(
+ ExternalClientModeManagerRequestListener.class);
+ Mutable<Listener<ConcreteClientModeManager>> additionalClientListener =
+ new Mutable<>();
+ ConcreteClientModeManager additionalClientModeManager =
+ mock(ConcreteClientModeManager.class);
+ doAnswer((invocation) -> {
+ Object[] args = invocation.getArguments();
+ additionalClientListener.value =
+ (Listener<ConcreteClientModeManager>) args[0];
+ return additionalClientModeManager;
+ }).when(mWifiInjector).makeClientModeManager(
+ any(Listener.class), any(), any(), anyBoolean());
+ when(additionalClientModeManager.getInterfaceName()).thenReturn(WIFI_IFACE_NAME_1);
+ when(additionalClientModeManager.getRole()).thenReturn(ROLE_CLIENT_LOCAL_ONLY);
+
+ // Request will shell uid for local-only STA and verify the secondary is provided instead.
+ WorkSource shellWs = new WorkSource(0, "shell");
+ mActiveModeWarden.requestLocalOnlyClientModeManager(
+ externalRequestListener, shellWs, TEST_SSID_2, TEST_BSSID_2, false);
+ mLooper.dispatchAll();
+ verify(mWifiInjector).makeClientModeManager(any(), any(),
+ eq(ROLE_CLIENT_LOCAL_ONLY), anyBoolean());
+ additionalClientListener.value.onStarted(additionalClientModeManager);
+ mLooper.dispatchAll();
+ verify(externalRequestListener).onAnswer(requestedClientModeManager.capture());
+ verify(mWifiInjector).makeClientModeManager(
+ any(), any(), eq(ROLE_CLIENT_LOCAL_ONLY), anyBoolean());
+ assertEquals(ROLE_CLIENT_LOCAL_ONLY, requestedClientModeManager.getValue().getRole());
+ }
+
+ @Test
public void configureHwOnMbbSwitch()
throws Exception {
// Ensure that we can create more client ifaces.