diff options
author | 2025-02-26 18:15:27 -0800 | |
---|---|---|
committer | 2025-02-26 18:15:27 -0800 | |
commit | ad8b57fa9a672ff0f09bfcb9168ee1ba0d5c5894 (patch) | |
tree | 197fc4cc9d3e54e08ff9a5df4864852d26c5ee9b | |
parent | 3b08a24edb6ebebd6c47f03d7e11ad867e15c930 (diff) | |
parent | b4d172f28775240bcf7ad444131265e5137534c5 (diff) |
Merge "Fix scan mode switch issue" into main
-rw-r--r-- | service/java/com/android/server/wifi/WifiNative.java | 42 | ||||
-rw-r--r-- | service/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java | 4 |
2 files changed, 36 insertions, 10 deletions
diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index 017c85017c..93291a66fb 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -1823,15 +1823,26 @@ public class WifiNative { public boolean switchClientInterfaceToScanMode(@NonNull String ifaceName, @NonNull WorkSource requestorWs) { synchronized (mLock) { - final Iface iface = mIfaceMgr.getIface(ifaceName); + Iface iface = null; + Iterator<Integer> ifaceIdIter = mIfaceMgr.getIfaceIdIter(); + while (ifaceIdIter.hasNext()) { + Iface nextIface = mIfaceMgr.getIface(ifaceIdIter.next()); + if (nextIface.name.equals(ifaceName)) { + if (nextIface.type == Iface.IFACE_TYPE_STA_FOR_CONNECTIVITY) { + iface = nextIface; + break; + } else if (nextIface.type == Iface.IFACE_TYPE_STA_FOR_SCAN) { + Log.e(TAG, "Already in scan mode on iface=" + ifaceName); + return true; + } + } + } + if (iface == null) { Log.e(TAG, "Trying to switch to scan mode on an invalid iface=" + ifaceName); return false; } - if (iface.type == Iface.IFACE_TYPE_STA_FOR_SCAN) { - Log.e(TAG, "Already in scan mode on iface=" + ifaceName); - return true; - } + if (mWifiVendorHal.isVendorHalSupported() && !mWifiVendorHal.replaceStaIfaceRequestorWs(iface.name, requestorWs)) { Log.e(TAG, "Failed to replace requestor ws on " + iface); @@ -1866,16 +1877,27 @@ public class WifiNative { public boolean switchClientInterfaceToConnectivityMode(@NonNull String ifaceName, @NonNull WorkSource requestorWs) { synchronized (mLock) { - final Iface iface = mIfaceMgr.getIface(ifaceName); + Iface iface = null; + Iterator<Integer> ifaceIdIter = mIfaceMgr.getIfaceIdIter(); + while (ifaceIdIter.hasNext()) { + Iface nextIface = mIfaceMgr.getIface(ifaceIdIter.next()); + if (nextIface.name.equals(ifaceName)) { + if (nextIface.type == Iface.IFACE_TYPE_STA_FOR_SCAN) { + iface = nextIface; + break; + } else if (nextIface.type == Iface.IFACE_TYPE_STA_FOR_CONNECTIVITY) { + Log.e(TAG, "Already in connectivity mode on iface=" + ifaceName); + return true; + } + } + } + if (iface == null) { Log.e(TAG, "Trying to switch to connectivity mode on an invalid iface=" + ifaceName); return false; } - if (iface.type == Iface.IFACE_TYPE_STA_FOR_CONNECTIVITY) { - Log.e(TAG, "Already in connectivity mode on iface=" + ifaceName); - return true; - } + if (mWifiVendorHal.isVendorHalSupported() && !mWifiVendorHal.replaceStaIfaceRequestorWs(iface.name, requestorWs)) { Log.e(TAG, "Failed to replace requestor ws on " + iface); diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java b/service/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java index c8ffb61a17..931c97eff5 100644 --- a/service/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java +++ b/service/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java @@ -2300,6 +2300,10 @@ public class WifiNativeInterfaceManagementTest extends WifiBaseTest { validateStartHal(hasStaIface || hasApIface || hasP2pIface || hasNanIface, true); assertNotNull(mActiveNanIface); assertEquals(mActiveNanIface.iface, mActiveWifiNanIface); + // Make sure switch client interface will not work on Aware interfaces + assertFalse(mWifiNative.switchClientInterfaceToScanMode(IFACE_NAME_AWARE, TEST_WORKSOURCE)); + assertFalse(mWifiNative.switchClientInterfaceToConnectivityMode(IFACE_NAME_AWARE, + TEST_WORKSOURCE)); } private void executeAndValidateTeardownNanInterface( |