From 044ed3b954c8995f5a671b79d36524d53652a060 Mon Sep 17 00:00:00 2001 From: CeRRiLLo89 <56557070+CeRRiLLo89@users.noreply.github.com> Date: Fri, 31 Jul 2026 19:20:53 +0200 Subject: [PATCH 1/6] WifiChipAidlImpl: cache unsupported usable channel query The AIDL Wi-Fi HAL may report ERROR_NOT_SUPPORTED for getUsableChannels. Cache that permanent result for the lifetime of the WifiChipAidlImpl instance to avoid repeated unsupported Binder calls and error logging. Other service-specific and transient errors continue using the existing handling. --- .../com/android/server/wifi/hal/WifiChipAidlImpl.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/service/java/com/android/server/wifi/hal/WifiChipAidlImpl.java b/service/java/com/android/server/wifi/hal/WifiChipAidlImpl.java index f380f91162..08ff59cd02 100644 --- a/service/java/com/android/server/wifi/hal/WifiChipAidlImpl.java +++ b/service/java/com/android/server/wifi/hal/WifiChipAidlImpl.java @@ -95,6 +95,7 @@ public class WifiChipAidlImpl implements IWifiChip { private Context mContext; private SsidTranslator mSsidTranslator; private long mHalFeatureSet; + private boolean mGetUsableChannelsSupported = true; public WifiChipAidlImpl(@NonNull android.hardware.wifi.IWifiChip chip, @NonNull Context context, @NonNull SsidTranslator ssidTranslator) { @@ -713,6 +714,7 @@ public List getUsableChannels(@WifiScanner.WifiBand int ba synchronized (mLock) { try { if (!checkIfaceAndLogFailure(methodStr)) return null; + if (!mGetUsableChannelsSupported) return null; WifiUsableChannel[] halChannels = mWifiChip.getUsableChannels( frameworkToHalWifiBand(band), frameworkToHalIfaceMode(mode), @@ -727,7 +729,12 @@ ch.channel, halToFrameworkIfaceMode(ch.ifaceModeMask), } catch (RemoteException e) { handleRemoteException(e, methodStr); } catch (ServiceSpecificException e) { - handleServiceSpecificException(e, methodStr); + if (e.errorCode == WifiStatusCode.ERROR_NOT_SUPPORTED) { + Log.w(TAG, methodStr + " is not supported by the HAL"); + mGetUsableChannelsSupported = false; + } else { + handleServiceSpecificException(e, methodStr); + } } catch (IllegalArgumentException e) { handleIllegalArgumentException(e, methodStr); } From 295129466b5d8e2eca69b0f6ea10d65803ff2a69 Mon Sep 17 00:00:00 2001 From: CeRRiLLo89 <56557070+CeRRiLLo89@users.noreply.github.com> Date: Fri, 31 Jul 2026 19:42:11 +0200 Subject: [PATCH 2/6] WifiChipAidlImplTest: verify usable channel support caching Verify that ERROR_NOT_SUPPORTED is cached after the first getUsableChannels call. Also verify that transient service errors such as ERROR_BUSY are not cached and the HAL is queried again. --- .../server/wifi/hal/WifiChipAidlImplTest.java | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/service/tests/wifitests/src/com/android/server/wifi/hal/WifiChipAidlImplTest.java b/service/tests/wifitests/src/com/android/server/wifi/hal/WifiChipAidlImplTest.java index f4104ab87f..7473e4bdc5 100644 --- a/service/tests/wifitests/src/com/android/server/wifi/hal/WifiChipAidlImplTest.java +++ b/service/tests/wifitests/src/com/android/server/wifi/hal/WifiChipAidlImplTest.java @@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; @@ -29,8 +30,9 @@ import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; @@ -46,7 +48,9 @@ import android.hardware.wifi.WifiDebugRingBufferStatus; import android.hardware.wifi.WifiDebugRingBufferVerboseLevel; import android.hardware.wifi.WifiStatusCode; +import android.net.wifi.WifiAvailableChannel; import android.net.wifi.WifiManager; +import android.net.wifi.WifiScanner; import android.os.RemoteException; import android.os.ServiceSpecificException; @@ -115,6 +119,42 @@ public void testGetIdServiceSpecificException() throws Exception { verify(mIWifiChipMock).getId(); } + @Test + public void testGetUsableChannelsNotSupportedIsCached() throws Exception { + doThrow(new ServiceSpecificException(WifiStatusCode.ERROR_NOT_SUPPORTED)) + .when(mIWifiChipMock).getUsableChannels(anyInt(), anyInt(), anyInt()); + + assertNull(mDut.getUsableChannels( + WifiScanner.WIFI_BAND_24_GHZ, + WifiAvailableChannel.OP_MODE_STA, + WifiAvailableChannel.FILTER_REGULATORY)); + assertNull(mDut.getUsableChannels( + WifiScanner.WIFI_BAND_24_GHZ, + WifiAvailableChannel.OP_MODE_STA, + WifiAvailableChannel.FILTER_REGULATORY)); + + verify(mIWifiChipMock, times(1)) + .getUsableChannels(anyInt(), anyInt(), anyInt()); + } + + @Test + public void testGetUsableChannelsTransientErrorIsNotCached() throws Exception { + doThrow(new ServiceSpecificException(WifiStatusCode.ERROR_BUSY)) + .when(mIWifiChipMock).getUsableChannels(anyInt(), anyInt(), anyInt()); + + assertNull(mDut.getUsableChannels( + WifiScanner.WIFI_BAND_24_GHZ, + WifiAvailableChannel.OP_MODE_STA, + WifiAvailableChannel.FILTER_REGULATORY)); + assertNull(mDut.getUsableChannels( + WifiScanner.WIFI_BAND_24_GHZ, + WifiAvailableChannel.OP_MODE_STA, + WifiAvailableChannel.FILTER_REGULATORY)); + + verify(mIWifiChipMock, times(2)) + .getUsableChannels(anyInt(), anyInt(), anyInt()); + } + /** * Test translation to WifiManager.WIFI_FEATURE_* */ From ffbee290abd91a6e67b2cbee753d831e8778e96e Mon Sep 17 00:00:00 2001 From: CeRRiLLo89 <56557070+CeRRiLLo89@users.noreply.github.com> Date: Fri, 31 Jul 2026 19:50:50 +0200 Subject: [PATCH 3/6] WifiChipAidlImplTest: fix test formatting Remove trailing whitespace from the usable channel tests. From e9fb29bfc623b666e99fd7633311ab8c591cd591 Mon Sep 17 00:00:00 2001 From: CeRRiLLo89 <56557070+CeRRiLLo89@users.noreply.github.com> Date: Fri, 31 Jul 2026 20:02:51 +0200 Subject: [PATCH 4/6] WifiChipAidlImplTest: remove trailing whitespace Remove the remaining whitespace from the blank line between tests. --- .../com/android/server/wifi/hal/WifiChipAidlImplTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/service/tests/wifitests/src/com/android/server/wifi/hal/WifiChipAidlImplTest.java b/service/tests/wifitests/src/com/android/server/wifi/hal/WifiChipAidlImplTest.java index 7473e4bdc5..9a8c061e06 100644 --- a/service/tests/wifitests/src/com/android/server/wifi/hal/WifiChipAidlImplTest.java +++ b/service/tests/wifitests/src/com/android/server/wifi/hal/WifiChipAidlImplTest.java @@ -154,8 +154,8 @@ public void testGetUsableChannelsTransientErrorIsNotCached() throws Exception { verify(mIWifiChipMock, times(2)) .getUsableChannels(anyInt(), anyInt(), anyInt()); } - - /** + + /** * Test translation to WifiManager.WIFI_FEATURE_* */ @Test @@ -168,9 +168,9 @@ public void testChipFeatureMaskTranslation() { BitSet expected = createCapabilityBitset(WifiManager.WIFI_FEATURE_TX_POWER_LIMIT, WifiManager.WIFI_FEATURE_D2D_RTT, WifiManager.WIFI_FEATURE_D2AP_RTT); assertTrue(expected.equals(mDut.halToFrameworkChipFeatureSet(halFeatures))); - } + } - /** + /** * Test that getRingBufferStatus gets and translates its values correctly. */ @Test From cc75d160a4efef7093a8644ea628d5a4764ffc1e Mon Sep 17 00:00:00 2001 From: CeRRiLLo89 <56557070+CeRRiLLo89@users.noreply.github.com> Date: Fri, 31 Jul 2026 20:06:40 +0200 Subject: [PATCH 5/6] WifiChipAidlImplTest: restore test indentation Restore the original indentation around the existing unit tests. --- .../com/android/server/wifi/hal/WifiChipAidlImplTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/service/tests/wifitests/src/com/android/server/wifi/hal/WifiChipAidlImplTest.java b/service/tests/wifitests/src/com/android/server/wifi/hal/WifiChipAidlImplTest.java index 9a8c061e06..b21d290314 100644 --- a/service/tests/wifitests/src/com/android/server/wifi/hal/WifiChipAidlImplTest.java +++ b/service/tests/wifitests/src/com/android/server/wifi/hal/WifiChipAidlImplTest.java @@ -151,11 +151,11 @@ public void testGetUsableChannelsTransientErrorIsNotCached() throws Exception { WifiAvailableChannel.OP_MODE_STA, WifiAvailableChannel.FILTER_REGULATORY)); - verify(mIWifiChipMock, times(2)) + verify(mIWifiChipMock, times(2)) .getUsableChannels(anyInt(), anyInt(), anyInt()); } - /** + /** * Test translation to WifiManager.WIFI_FEATURE_* */ @Test @@ -168,9 +168,9 @@ public void testChipFeatureMaskTranslation() { BitSet expected = createCapabilityBitset(WifiManager.WIFI_FEATURE_TX_POWER_LIMIT, WifiManager.WIFI_FEATURE_D2D_RTT, WifiManager.WIFI_FEATURE_D2AP_RTT); assertTrue(expected.equals(mDut.halToFrameworkChipFeatureSet(halFeatures))); - } + } - /** + /** * Test that getRingBufferStatus gets and translates its values correctly. */ @Test From f157424b04f69f2e258a193dc458c5e20747b055 Mon Sep 17 00:00:00 2001 From: CeRRiLLo89 <56557070+CeRRiLLo89@users.noreply.github.com> Date: Fri, 31 Jul 2026 20:09:28 +0200 Subject: [PATCH 6/6] WifiChipAidlImplTest: fix verify indentation Restore the expected indentation in the transient error test. --- .../src/com/android/server/wifi/hal/WifiChipAidlImplTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/tests/wifitests/src/com/android/server/wifi/hal/WifiChipAidlImplTest.java b/service/tests/wifitests/src/com/android/server/wifi/hal/WifiChipAidlImplTest.java index b21d290314..72566b3589 100644 --- a/service/tests/wifitests/src/com/android/server/wifi/hal/WifiChipAidlImplTest.java +++ b/service/tests/wifitests/src/com/android/server/wifi/hal/WifiChipAidlImplTest.java @@ -151,7 +151,7 @@ public void testGetUsableChannelsTransientErrorIsNotCached() throws Exception { WifiAvailableChannel.OP_MODE_STA, WifiAvailableChannel.FILTER_REGULATORY)); - verify(mIWifiChipMock, times(2)) + verify(mIWifiChipMock, times(2)) .getUsableChannels(anyInt(), anyInt(), anyInt()); }