Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -713,6 +714,7 @@ public List<WifiAvailableChannel> 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),
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
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;
import static org.mockito.Mockito.doThrow;
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;
Expand All @@ -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;

Expand Down Expand Up @@ -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_*
*/
Expand Down