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); } 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..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 @@ -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_* */