diff options
author | Ahmed ElArabawy <arabawy@google.com> | 2019-12-19 02:30:13 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-12-19 02:30:13 +0000 |
commit | d59de80372e11f40ff51f91f3abdede8361f548d (patch) | |
tree | f9d2d9e8f67ed2134c68e88769ee6e0bb0cd315d | |
parent | ed64293f289fe8bd4cb5e432fb45fb1b7a76f37f (diff) | |
parent | 12e7eecdf27040164f39cea666392d8a43453210 (diff) |
Merge "Support 6GHz band for softAP"
18 files changed, 907 insertions, 245 deletions
diff --git a/service/java/com/android/server/wifi/HostapdHal.java b/service/java/com/android/server/wifi/HostapdHal.java index e1e4556ea..fb1a6df95 100644 --- a/service/java/com/android/server/wifi/HostapdHal.java +++ b/service/java/com/android/server/wifi/HostapdHal.java @@ -62,6 +62,7 @@ public class HostapdHal { private final Context mContext; private final Handler mEventHandler; private boolean mForceApChannel = false; + private int mForcedApBand; private int mForcedApChannel; // Hostapd HAL interface objects @@ -158,6 +159,20 @@ public class HostapdHal { } /** + * Checks if the service is running HAL version 1.2 on the device. + * @return true if supported, false otherwise. + */ + private boolean isV1_2() { + try { + return (getHostapdMockableV1_2() != null); + } catch (RemoteException e) { + Log.e(TAG, "Exception while operating on IServiceManager: " + e); + handleRemoteException(e, "getHostapdMockableV1_2"); + return false; + } + } + + /** * Link to death for IServiceManager object. * @return true on success, false otherwise. */ @@ -298,9 +313,10 @@ public class HostapdHal { * Enable force-soft-AP-channel mode which takes effect when soft AP starts next time * @param forcedApChannel The forced IEEE channel number */ - void enableForceSoftApChannel(int forcedApChannel) { + void enableForceSoftApChannel(int forcedApChannel, int forcedApBand) { mForceApChannel = true; mForcedApChannel = forcedApChannel; + mForcedApBand = forcedApBand; } /** @@ -328,35 +344,20 @@ public class HostapdHal { ifaceParams.hwModeParams.enable80211AC = mContext.getResources().getBoolean( R.bool.config_wifi_softap_ieee80211ac_supported); - try { - ifaceParams.channelParams.band = getBand(config); - } catch (IllegalArgumentException e) { - Log.e(TAG, "Unrecognized apBand " + config.getBand()); - return false; - } + int band; if (mForceApChannel) { ifaceParams.channelParams.enableAcs = false; ifaceParams.channelParams.channel = mForcedApChannel; - if (mForcedApChannel <= ApConfigUtil.HIGHEST_2G_AP_CHANNEL) { - ifaceParams.channelParams.band = IHostapd.Band.BAND_2_4_GHZ; - } else { - ifaceParams.channelParams.band = IHostapd.Band.BAND_5_GHZ; - } + band = mForcedApBand; } else if (mContext.getResources().getBoolean( R.bool.config_wifi_softap_acs_supported)) { ifaceParams.channelParams.enableAcs = true; ifaceParams.channelParams.acsShouldExcludeDfs = true; + band = config.getBand(); } else { - // Downgrade IHostapd.Band.BAND_ANY to IHostapd.Band.BAND_2_4_GHZ if ACS - // is not supported. - // We should remove this workaround once channel selection is moved from - // ApConfigUtil to here. - if (ifaceParams.channelParams.band == IHostapd.Band.BAND_ANY) { - Log.d(TAG, "ACS is not supported on this device, using 2.4 GHz band."); - ifaceParams.channelParams.band = IHostapd.Band.BAND_2_4_GHZ; - } ifaceParams.channelParams.enableAcs = false; ifaceParams.channelParams.channel = config.getChannel(); + band = config.getBand(); } IHostapd.NetworkParams nwParams = new IHostapd.NetworkParams(); @@ -372,28 +373,61 @@ public class HostapdHal { if (!checkHostapdAndLogFailure(methodStr)) return false; try { HostapdStatus status; - if (isV1_1()) { + if (!isV1_1() && !isV1_2()) { + ifaceParams.channelParams.band = getHalBand(band); + status = mIHostapd.addAccessPoint(ifaceParams, nwParams); + if (!checkStatusAndLogFailure(status, methodStr)) { + return false; + } + } else { android.hardware.wifi.hostapd.V1_1.IHostapd.IfaceParams ifaceParams1_1 = new android.hardware.wifi.hostapd.V1_1.IHostapd.IfaceParams(); ifaceParams1_1.V1_0 = ifaceParams; - if (mContext.getResources().getBoolean( - R.bool.config_wifi_softap_acs_supported)) { + if (ifaceParams.channelParams.enableAcs) { ifaceParams1_1.channelParams.acsChannelRanges.addAll( toAcsChannelRanges(mContext.getResources().getString( R.string.config_wifi_softap_acs_supported_channel_list))); } - android.hardware.wifi.hostapd.V1_1.IHostapd iHostapdV1_1 = - getHostapdMockableV1_1(); - if (iHostapdV1_1 == null) return false; - status = iHostapdV1_1.addAccessPoint_1_1(ifaceParams1_1, nwParams); - } else { - status = mIHostapd.addAccessPoint(ifaceParams, nwParams); - } - if (!checkStatusAndLogFailure(status, methodStr)) { - return false; + + if (!isV1_2()) { + android.hardware.wifi.hostapd.V1_1.IHostapd iHostapdV1_1 = + getHostapdMockableV1_1(); + if (iHostapdV1_1 == null) return false; + + ifaceParams.channelParams.band = getHalBand(band); + status = iHostapdV1_1.addAccessPoint_1_1(ifaceParams1_1, nwParams); + if (!checkStatusAndLogFailure(status, methodStr)) { + return false; + } + } else { + android.hardware.wifi.hostapd.V1_2.HostapdStatus status12; + android.hardware.wifi.hostapd.V1_2.IHostapd.IfaceParams ifaceParams1_2 = + new android.hardware.wifi.hostapd.V1_2.IHostapd.IfaceParams(); + ifaceParams1_2.V1_1 = ifaceParams1_1; + + ifaceParams1_2.hwModeParams.enable80211AX = + mContext.getResources().getBoolean( + R.bool.config_wifiSoftapIeee80211axSupported); + ifaceParams1_2.hwModeParams.enable6GhzBand = + mContext.getResources().getBoolean( + R.bool.config_wifiSoftap6ghzSupported); + ifaceParams1_2.channelParams.bandMask = getHalBandMask(band); + + android.hardware.wifi.hostapd.V1_2.IHostapd iHostapdV1_2 = + getHostapdMockableV1_2(); + if (iHostapdV1_2 == null) return false; + status12 = iHostapdV1_2.addAccessPoint_1_2(ifaceParams1_2, nwParams); + if (!checkStatusAndLogFailure12(status12, methodStr)) { + return false; + } + } } + mSoftApFailureListeners.put(ifaceName, onFailureListener); return true; + } catch (IllegalArgumentException e) { + Log.e(TAG, "Unrecognized apBand: " + band); + return false; } catch (RemoteException e) { handleRemoteException(e, methodStr); return false; @@ -578,6 +612,19 @@ public class HostapdHal { } } + @VisibleForTesting + protected android.hardware.wifi.hostapd.V1_2.IHostapd getHostapdMockableV1_2() + throws RemoteException { + synchronized (mLock) { + try { + return android.hardware.wifi.hostapd.V1_2.IHostapd.castFrom(mIHostapd); + } catch (NoSuchElementException e) { + Log.e(TAG, "Failed to get IHostapd", e); + return null; + } + } + } + private static int getEncryptionType(SoftApConfiguration localConfig) { int encryptionType; switch (localConfig.getSecurityType()) { @@ -596,22 +643,39 @@ public class HostapdHal { return encryptionType; } - private static int getBand(SoftApConfiguration localConfig) { - int bandType; - switch (localConfig.getBand()) { + private static int getHalBandMask(int apBand) { + int bandMask = 0; + + if (!ApConfigUtil.isBandValid(apBand)) { + throw new IllegalArgumentException(); + } + + if (ApConfigUtil.containsBand(apBand, SoftApConfiguration.BAND_2GHZ)) { + bandMask |= android.hardware.wifi.hostapd.V1_2.IHostapd.BandMask.BAND_2_GHZ; + } + if (ApConfigUtil.containsBand(apBand, SoftApConfiguration.BAND_5GHZ)) { + bandMask |= android.hardware.wifi.hostapd.V1_2.IHostapd.BandMask.BAND_5_GHZ; + } + if (ApConfigUtil.containsBand(apBand, SoftApConfiguration.BAND_6GHZ)) { + bandMask |= android.hardware.wifi.hostapd.V1_2.IHostapd.BandMask.BAND_6_GHZ; + } + + return bandMask; + } + + private static int getHalBand(int apBand) { + if (!ApConfigUtil.isBandValid(apBand)) { + throw new IllegalArgumentException(); + } + + switch (apBand) { case SoftApConfiguration.BAND_2GHZ: - bandType = IHostapd.Band.BAND_2_4_GHZ; - break; + return IHostapd.Band.BAND_2_4_GHZ; case SoftApConfiguration.BAND_5GHZ: - bandType = IHostapd.Band.BAND_5_GHZ; - break; - case SoftApConfiguration.BAND_ANY: - bandType = IHostapd.Band.BAND_ANY; - break; + return IHostapd.Band.BAND_5_GHZ; default: - throw new IllegalArgumentException(); + return IHostapd.Band.BAND_ANY; } - return bandType; } /** @@ -687,6 +751,26 @@ public class HostapdHal { } } + /** + * Returns true if provided status code is SUCCESS, logs debug message and returns false + * otherwise + */ + private boolean checkStatusAndLogFailure12( + android.hardware.wifi.hostapd.V1_2.HostapdStatus status, String methodStr) { + synchronized (mLock) { + if (status.code != HostapdStatusCode.SUCCESS) { + Log.e(TAG, "IHostapd." + methodStr + " failed: " + status.code + + ", " + status.debugMessage); + return false; + } else { + if (mVerboseLoggingEnabled) { + Log.d(TAG, "IHostapd." + methodStr + " succeeded"); + } + return true; + } + } + } + private void handleRemoteException(RemoteException e, String methodStr) { synchronized (mLock) { hostapdServiceDiedHandler(mDeathRecipientCookie); diff --git a/service/java/com/android/server/wifi/SoftApBackupRestore.java b/service/java/com/android/server/wifi/SoftApBackupRestore.java index fc3e541a2..477c1a06d 100644 --- a/service/java/com/android/server/wifi/SoftApBackupRestore.java +++ b/service/java/com/android/server/wifi/SoftApBackupRestore.java @@ -21,6 +21,8 @@ import android.net.wifi.WifiConfiguration; import android.util.BackupUtils; import android.util.Log; +import com.android.server.wifi.util.ApConfigUtil; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; @@ -98,8 +100,20 @@ public class SoftApBackupRestore { if (version == 1) return null; // Version 1 is a bad dataset. configBuilder.setSsid(BackupUtils.readString(in)); - configBuilder.setBand(in.readInt()); - configBuilder.setChannel(in.readInt()); + + int band; + if (version < 4) { + band = ApConfigUtil.convertWifiConfigBandToSoftApConfigBand(in.readInt()); + } else { + band = in.readInt(); + } + int channel = in.readInt(); + + if (channel == 0) { + configBuilder.setBand(band); + } else { + configBuilder.setChannel(channel, band); + } String wpa2Passphrase = BackupUtils.readString(in); int securityType = in.readInt(); if ((version < 4 && securityType == WifiConfiguration.KeyMgmt.WPA2_PSK) || ( diff --git a/service/java/com/android/server/wifi/SoftApManager.java b/service/java/com/android/server/wifi/SoftApManager.java index 34b8e9b35..7be1e5f11 100644 --- a/service/java/com/android/server/wifi/SoftApManager.java +++ b/service/java/com/android/server/wifi/SoftApManager.java @@ -228,7 +228,7 @@ public class SoftApManager implements ActiveModeManager { pw.println("mApConfig.targetMode: " + mApConfig.getTargetMode()); SoftApConfiguration softApConfig = mApConfig.getSoftApConfiguration(); pw.println("mApConfig.SoftApConfiguration.SSID: " + softApConfig.getSsid()); - pw.println("mApConfig.SoftApConfiguration.apBand: " + softApConfig.getBand()); + pw.println("mApConfig.SoftApConfiguration.mBand: " + softApConfig.getBand()); pw.println("mApConfig.SoftApConfiguration.hiddenSSID: " + softApConfig.isHiddenSsid()); pw.println("mConnectedClients.size(): " + mConnectedClients.size()); pw.println("mTimeoutEnabled: " + mTimeoutEnabled); @@ -318,7 +318,7 @@ public class SoftApManager implements ActiveModeManager { Log.e(TAG, "Failed to set country code, required for setting up soft ap in 5GHz"); return ERROR_GENERIC; } - // Failure to set country code is not fatal for 2Ghz & Any band options. + // Failure to set country code is not fatal for other band options. } return SUCCESS; } @@ -351,9 +351,11 @@ public class SoftApManager implements ActiveModeManager { // Make a copy of configuration for updating AP band and channel. SoftApConfiguration.Builder localConfigBuilder = new SoftApConfiguration.Builder(config); + boolean acsEnabled = mContext.getResources() + .getBoolean(R.bool.config_wifi_softap_acs_supported); result = ApConfigUtil.updateApChannelConfig( mWifiNative, mCountryCode, - mWifiApConfigStore.getAllowed2GChannel(), localConfigBuilder, config); + mWifiApConfigStore.getAllowed2GChannel(), localConfigBuilder, config, acsEnabled); if (result != SUCCESS) { Log.e(TAG, "Failed to update AP band and channel"); @@ -737,10 +739,16 @@ public class SoftApManager implements ActiveModeManager { private void updateUserBandPreferenceViolationMetricsIfNeeded() { int band = mApConfig.getSoftApConfiguration().getBand(); boolean bandPreferenceViolated = - (band == SoftApConfiguration.BAND_2GHZ - && ScanResult.is5GHz(mCurrentSoftApInfo.getFrequency())) - || (band == SoftApConfiguration.BAND_5GHZ - && ScanResult.is24GHz(mCurrentSoftApInfo.getFrequency())); + (ScanResult.is24GHz(mCurrentSoftApInfo.getFrequency()) + && !ApConfigUtil.containsBand(band, + SoftApConfiguration.BAND_2GHZ)) + || (ScanResult.is5GHz(mCurrentSoftApInfo.getFrequency()) + && !ApConfigUtil.containsBand(band, + SoftApConfiguration.BAND_5GHZ)) + || (ScanResult.is6GHz(mCurrentSoftApInfo.getFrequency()) + && !ApConfigUtil.containsBand(band, + SoftApConfiguration.BAND_6GHZ)); + if (bandPreferenceViolated) { Log.e(TAG, "Channel does not satisfy user band preference: " + mCurrentSoftApInfo.getFrequency()); diff --git a/service/java/com/android/server/wifi/SoftApStoreData.java b/service/java/com/android/server/wifi/SoftApStoreData.java index 456519912..be8dcd891 100644 --- a/service/java/com/android/server/wifi/SoftApStoreData.java +++ b/service/java/com/android/server/wifi/SoftApStoreData.java @@ -114,6 +114,8 @@ public class SoftApStoreData implements WifiConfigStore.StoreData { int securityType = SoftApConfiguration.SECURITY_TYPE_OPEN; String wpa2Passphrase = null; String ssid = null; + int band = -1; + int channel = -1; while (!XmlUtil.isNextSectionEnd(in, outerTagDepth)) { String[] valueName = new String[1]; Object value = XmlUtil.readCurrentValue(in, valueName); @@ -126,10 +128,10 @@ public class SoftApStoreData implements WifiConfigStore.StoreData { softApConfigBuilder.setSsid((String) value); break; case XML_TAG_BAND: - softApConfigBuilder.setBand((int) value); + band = (int) value; break; case XML_TAG_CHANNEL: - softApConfigBuilder.setChannel((int) value); + channel = (int) value; break; case XML_TAG_HIDDEN_SSID: softApConfigBuilder.setHiddenSsid((boolean) value); @@ -146,6 +148,15 @@ public class SoftApStoreData implements WifiConfigStore.StoreData { } } + // Set channel and band + if (channel == 0) { + if (band != -1) { + softApConfigBuilder.setBand(band); + } + } else if ((channel != -1) && (band != -1)) { + softApConfigBuilder.setChannel(channel, band); + } + // We should at-least have SSID restored from store. if (ssid == null) { Log.e(TAG, "Failed to parse SSID"); diff --git a/service/java/com/android/server/wifi/WifiApConfigStore.java b/service/java/com/android/server/wifi/WifiApConfigStore.java index 143f8a18e..8b7d94697 100644 --- a/service/java/com/android/server/wifi/WifiApConfigStore.java +++ b/service/java/com/android/server/wifi/WifiApConfigStore.java @@ -28,6 +28,7 @@ import android.text.TextUtils; import android.util.Log; import com.android.internal.annotations.VisibleForTesting; +import com.android.server.wifi.util.ApConfigUtil; import com.android.wifi.resources.R; import java.io.BufferedInputStream; @@ -75,9 +76,6 @@ public class WifiApConfigStore { @VisibleForTesting static final int PSK_MAX_LEN = 63; - @VisibleForTesting - static final int AP_CHANNEL_DEFAULT = 0; - private SoftApConfiguration mPersistentWifiApConfig = null; private final Context mContext; @@ -227,24 +225,39 @@ public class WifiApConfigStore { if (mContext.getResources().getBoolean(R.bool.config_wifi_convert_apband_5ghz_to_any)) { // some devices are unable to support 5GHz only operation, check for 5GHz and - // move to ANY if apBand conversion is required. + // allow for 2GHz if apBand conversion is required. if (config.getBand() == SoftApConfiguration.BAND_5GHZ) { - Log.w(TAG, "Supplied ap config band was 5GHz only, converting to ANY"); + Log.w(TAG, "Supplied ap config band was 5GHz only, Allowing for 2.4GHz"); if (convertedConfigBuilder == null) { convertedConfigBuilder = new SoftApConfiguration.Builder(config); } - convertedConfigBuilder.setBand(SoftApConfiguration.BAND_ANY); - convertedConfigBuilder.setChannel(AP_CHANNEL_DEFAULT); + convertedConfigBuilder.setBand(SoftApConfiguration.BAND_5GHZ + | SoftApConfiguration.BAND_2GHZ); } } else { - // this is a single mode device, we do not support ANY. Convert all ANY to 5GHz - if (config.getBand() == SoftApConfiguration.BAND_ANY) { - Log.w(TAG, "Supplied ap config band was ANY, converting to 5GHz"); + // this is a single mode device, convert band to 5GHz if allowed + int targetBand = 0; + int apBand = config.getBand(); + if (ApConfigUtil.isMultiband(apBand)) { + if (ApConfigUtil.containsBand(apBand, SoftApConfiguration.BAND_5GHZ)) { + Log.w(TAG, "Supplied ap config band is multiband , converting to 5GHz"); + targetBand = SoftApConfiguration.BAND_5GHZ; + } else if (ApConfigUtil.containsBand(apBand, + SoftApConfiguration.BAND_2GHZ)) { + Log.w(TAG, "Supplied ap config band is multiband , converting to 2GHz"); + targetBand = SoftApConfiguration.BAND_2GHZ; + } else if (ApConfigUtil.containsBand(apBand, + SoftApConfiguration.BAND_6GHZ)) { + Log.w(TAG, "Supplied ap config band is multiband , converting to 6GHz"); + targetBand = SoftApConfiguration.BAND_6GHZ; + } + } + + if (targetBand != 0) { if (convertedConfigBuilder == null) { convertedConfigBuilder = new SoftApConfiguration.Builder(config); } - convertedConfigBuilder.setBand(SoftApConfiguration.BAND_5GHZ); - convertedConfigBuilder.setChannel(AP_CHANNEL_DEFAULT); + convertedConfigBuilder.setBand(targetBand); } } return convertedConfigBuilder == null ? config : convertedConfigBuilder.build(); @@ -276,8 +289,14 @@ public class WifiApConfigStore { configBuilder.setSsid(in.readUTF()); if (version >= 2) { - configBuilder.setBand(in.readInt()); - configBuilder.setChannel(in.readInt()); + int band = in.readInt(); + int channel = in.readInt(); + + if (channel == 0) { + configBuilder.setBand(band); + } else { + configBuilder.setChannel(channel, band); + } } if (version >= 3) { diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index afea1d0a8..08053423b 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -784,6 +784,30 @@ public class WifiServiceImpl extends BaseWifiService { } } + private boolean validateSoftApBand(int apBand) { + if (!ApConfigUtil.isBandValid(apBand)) { + mLog.err("Invalid SoftAp band. ").flush(); + return false; + } + + if (ApConfigUtil.containsBand(apBand, SoftApConfiguration.BAND_5GHZ) + && !is5GhzBandSupportedInternal()) { + mLog.err("Can not start softAp with 5GHz band, not supported.").flush(); + return false; + } + + if (ApConfigUtil.containsBand(apBand, SoftApConfiguration.BAND_6GHZ)) { + if (!is6GhzBandSupportedInternal() + || !mContext.getResources().getBoolean( + R.bool.config_wifiSoftap6ghzSupported)) { + mLog.err("Can not start softAp with 6GHz band, not supported.").flush(); + return false; + } + } + + return true; + } + /** * see {@link android.net.wifi.WifiManager#startTetheredHotspot(SoftApConfiguration)} * @param softApConfig SSID, security and channel details as part of SoftApConfiguration @@ -823,7 +847,9 @@ public class WifiServiceImpl extends BaseWifiService { // null wifiConfig is a meaningful input for CMD_SET_AP; it means to use the persistent // AP config. SoftApConfiguration softApConfig = apConfig.getSoftApConfiguration(); - if (softApConfig != null && !WifiApConfigStore.validateApWifiConfiguration(softApConfig)) { + if (softApConfig != null + && (!WifiApConfigStore.validateApWifiConfiguration(softApConfig) + || !validateSoftApBand(softApConfig.getBand()))) { Log.e(TAG, "Invalid SoftApConfiguration"); return false; } @@ -1188,8 +1214,7 @@ public class WifiServiceImpl extends BaseWifiService { R.bool.config_wifi_local_only_hotspot_5ghz) && is5GhzBandSupportedInternal(); - int band = is5Ghz ? WifiConfiguration.AP_BAND_5GHZ - : WifiConfiguration.AP_BAND_2GHZ; + int band = is5Ghz ? SoftApConfiguration.BAND_5GHZ : SoftApConfiguration.BAND_2GHZ; SoftApConfiguration softApConfig = WifiApConfigStore.generateLocalOnlyHotspotConfig( mContext, band, request.getCustomConfig()); @@ -2408,6 +2433,10 @@ public class WifiServiceImpl extends BaseWifiService { mLog.info("is6GHzBandSupported uid=%").c(Binder.getCallingUid()).flush(); } + return is6GhzBandSupportedInternal(); + } + + private boolean is6GhzBandSupportedInternal() { return mContext.getResources().getBoolean(R.bool.config_wifi6ghzSupport); } diff --git a/service/java/com/android/server/wifi/WifiShellCommand.java b/service/java/com/android/server/wifi/WifiShellCommand.java index 2d7636e0c..fa468c7fe 100644 --- a/service/java/com/android/server/wifi/WifiShellCommand.java +++ b/service/java/com/android/server/wifi/WifiShellCommand.java @@ -18,6 +18,7 @@ package com.android.server.wifi; import android.content.Context; import android.net.wifi.IWifiManager; +import android.net.wifi.SoftApConfiguration; import android.net.wifi.WifiCondManager; import android.net.wifi.WifiScanner; import android.os.Binder; @@ -206,12 +207,26 @@ public class WifiShellCommand extends ShellCommand { return -1; } int apChannel = ApConfigUtil.convertFrequencyToChannel(apChannelMHz); - if (apChannel == -1 || !isApChannelMHzValid(apChannelMHz)) { + int band = ApConfigUtil.convertFrequencyToBand(apChannelMHz); + if (apChannel == -1 || band == -1 || !isApChannelMHzValid(apChannelMHz)) { pw.println("Invalid argument to 'force-softap-channel enabled' " + "- must be a valid WLAN channel"); return -1; } - mHostapdHal.enableForceSoftApChannel(apChannel); + + // validate that device support this band + IWifiManager wifiManager = IWifiManager.Stub.asInterface( + ServiceManager.getService(Context.WIFI_SERVICE)); + if ((band == SoftApConfiguration.BAND_5GHZ + && !wifiManager.is5GHzBandSupported()) + || (band == SoftApConfiguration.BAND_6GHZ + && !wifiManager.is6GHzBandSupported())) { + pw.println("Invalid argument to 'force-softap-channel enabled' " + + "- channel band is not supported by the device"); + return -1; + } + + mHostapdHal.enableForceSoftApChannel(apChannel, band); return 0; } else if ("disabled".equals(nextArg)) { mHostapdHal.disableForceSoftApChannel(); @@ -335,6 +350,7 @@ public class WifiShellCommand extends ShellCommand { int[] allowed5gFreq = mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ); int[] allowed5gDfsFreq = mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ_DFS_ONLY); + int[] allowed6gFreq = mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_6_GHZ); if (allowed2gFreq == null) { allowed2gFreq = new int[0]; } @@ -344,9 +360,14 @@ public class WifiShellCommand extends ShellCommand { if (allowed5gDfsFreq == null) { allowed5gDfsFreq = new int[0]; } + if (allowed6gFreq == null) { + allowed6gFreq = new int[0]; + } + return (Arrays.binarySearch(allowed2gFreq, apChannelMHz) >= 0 || Arrays.binarySearch(allowed5gFreq, apChannelMHz) >= 0 - || Arrays.binarySearch(allowed5gDfsFreq, apChannelMHz) >= 0); + || Arrays.binarySearch(allowed5gDfsFreq, apChannelMHz) >= 0) + || Arrays.binarySearch(allowed6gFreq, apChannelMHz) >= 0; } private void checkRootPermission() { diff --git a/service/java/com/android/server/wifi/util/ApConfigUtil.java b/service/java/com/android/server/wifi/util/ApConfigUtil.java index 691e829ac..793b98497 100644 --- a/service/java/com/android/server/wifi/util/ApConfigUtil.java +++ b/service/java/com/android/server/wifi/util/ApConfigUtil.java @@ -19,6 +19,7 @@ package com.android.server.wifi.util; import android.annotation.NonNull; import android.net.MacAddress; import android.net.wifi.SoftApConfiguration; +import android.net.wifi.SoftApConfiguration.BandType; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiScanner; import android.util.Log; @@ -46,6 +47,41 @@ public class ApConfigUtil { private static final Random sRandom = new Random(); /** + * Convert channel/band to frequency. + * Note: the utility does not perform any regulatory domain compliance. + * @param channel number to convert + * @param band of channel to convert + * @return center frequency in Mhz of the channel, -1 if no match + */ + public static int convertChannelToFrequency(int channel, int band) { + if (band == SoftApConfiguration.BAND_2GHZ) { + if (channel == 14) { + return 2484; + } else if (channel >= 1 && channel <= 14) { + return ((channel - 1) * 5) + 2412; + } else { + return -1; + } + } + if (band == SoftApConfiguration.BAND_5GHZ) { + if (channel >= 34 && channel <= 173) { + return ((channel - 34) * 5) + 5170; + } else { + return -1; + } + } + if (band == SoftApConfiguration.BAND_6GHZ) { + if (channel >= 1 && channel <= 254) { + return (channel * 5) + 5940; + } else { + return -1; + } + } + + return -1; + } + + /** * Convert frequency to channel. * Note: the utility does not perform any regulatory domain compliance. * @param frequency frequency to convert @@ -59,52 +95,144 @@ public class ApConfigUtil { } else if (frequency >= 5170 && frequency <= 5865) { /* DFS is included. */ return (frequency - 5170) / 5 + 34; + } else if (frequency > 5940 && frequency < 7210) { + return ((frequency - 5940) / 5); } return -1; } /** + * Convert frequency to band. + * Note: the utility does not perform any regulatory domain compliance. + * @param frequency frequency to convert + * @return band, -1 if no match + */ + public static int convertFrequencyToBand(int frequency) { + if (frequency >= 2412 && frequency <= 2484) { + return SoftApConfiguration.BAND_2GHZ; + } else if (frequency >= 5170 && frequency <= 5865) { + return SoftApConfiguration.BAND_5GHZ; + } else if (frequency > 5940 && frequency < 7210) { + return SoftApConfiguration.BAND_6GHZ; + } + + return -1; + } + + /** + * Convert band from WifiConfiguration into SoftApConfiguration + * + * @param wifiConfigBand band encoded as WifiConfiguration.AP_BAND_xxxx + * @return band as encoded as SoftApConfiguration.BAND_xxx + */ + public static int convertWifiConfigBandToSoftApConfigBand(int wifiConfigBand) { + switch (wifiConfigBand) { + case WifiConfiguration.AP_BAND_2GHZ: + return SoftApConfiguration.BAND_2GHZ; + case WifiConfiguration.AP_BAND_5GHZ: + return SoftApConfiguration.BAND_5GHZ; + case WifiConfiguration.AP_BAND_ANY: + return SoftApConfiguration.BAND_2GHZ | SoftApConfiguration.BAND_5GHZ; + default: + return -1; + } + } + + /** + * Checks if band is a valid combination of {link SoftApConfiguration#BandType} values + */ + public static boolean isBandValid(@BandType int band) { + return ((band != 0) && ((band & ~SoftApConfiguration.BAND_ANY) == 0)); + } + + /** + * Check if the band contains a certain sub-band + * + * @param band The combination of bands to validate + * @param testBand the test band to validate on + * @return true if band contains testBand, false otherwise + */ + public static boolean containsBand(@BandType int band, @BandType int testBand) { + return ((band & testBand) != 0); + } + + /** + * Checks if band contains multiple sub-bands + * @param band a combination of sub-bands + * @return true if band has multiple sub-bands, false otherwise + */ + public static boolean isMultiband(@BandType int band) { + return ((band & (band - 1)) != 0); + } + + /** * Return a channel number for AP setup based on the frequency band. - * @param apBand one of the value of SoftApConfiguration.BAND_*. + * @param apBand one or combination of the values of SoftApConfiguration.BAND_*. * @param allowed2GChannels list of allowed 2GHz channels * @param allowed5GFreqList list of allowed 5GHz frequencies - * @return a valid channel number on success, -1 on failure. + * @param allowed6GFreqList list of allowed 6GHz frequencies + * @return a valid channel frequency on success, -1 on failure. */ public static int chooseApChannel(int apBand, ArrayList<Integer> allowed2GChannels, - int[] allowed5GFreqList) { - if (apBand != SoftApConfiguration.BAND_2GHZ - && apBand != SoftApConfiguration.BAND_5GHZ - && apBand != SoftApConfiguration.BAND_ANY) { + int[] allowed5GFreqList, + int[] allowed6GFreqList) { + if (!isBandValid(apBand)) { Log.e(TAG, "Invalid band: " + apBand); return -1; } - // TODO(b/72120668): Create channel selection logic for AP_BAND_ANY. - if (apBand == SoftApConfiguration.BAND_2GHZ - || apBand == SoftApConfiguration.BAND_ANY) { - /* Select a channel from 2GHz band. */ - if (allowed2GChannels == null || allowed2GChannels.size() == 0) { - Log.d(TAG, "2GHz allowed channel list not specified"); + int totalChannelCount = 0; + int size2gList = (allowed2GChannels != null) ? allowed2GChannels.size() : 0; + int size5gList = (allowed5GFreqList != null) ? allowed5GFreqList.length : 0; + int size6gList = (allowed6GFreqList != null) ? allowed6GFreqList.length : 0; + + if ((apBand & SoftApConfiguration.BAND_2GHZ) != 0) { + totalChannelCount += size2gList; + } + if ((apBand & SoftApConfiguration.BAND_5GHZ) != 0) { + totalChannelCount += size5gList; + } + if ((apBand & SoftApConfiguration.BAND_6GHZ) != 0) { + totalChannelCount += size6gList; + } + + if (totalChannelCount == 0) { + // If the default AP band is allowed, just use the default channel + if (containsBand(apBand, DEFAULT_AP_BAND)) { + Log.d(TAG, "Allowed channel list not specified, selecting default channel"); /* Use default channel. */ - return DEFAULT_AP_CHANNEL; + return convertChannelToFrequency(DEFAULT_AP_CHANNEL, + DEFAULT_AP_BAND); + } else { + Log.e(TAG, "No available channels"); + return -1; } + } + + // Pick a channel + int selectedChannelIndex = sRandom.nextInt(totalChannelCount); - /* Pick a random channel. */ - int index = sRandom.nextInt(allowed2GChannels.size()); - return allowed2GChannels.get(index).intValue(); + if ((apBand & SoftApConfiguration.BAND_2GHZ) != 0) { + if (selectedChannelIndex < size2gList) { + return convertChannelToFrequency( + allowed2GChannels.get(selectedChannelIndex).intValue(), + SoftApConfiguration.BAND_2GHZ); + } else { + selectedChannelIndex -= size2gList; + } } - /* 5G without DFS. */ - if (allowed5GFreqList != null && allowed5GFreqList.length > 0) { - /* Pick a random channel from the list of supported channels. */ - return convertFrequencyToChannel( - allowed5GFreqList[sRandom.nextInt(allowed5GFreqList.length)]); + if ((apBand & SoftApConfiguration.BAND_5GHZ) != 0) { + if (selectedChannelIndex < size5gList) { + return allowed5GFreqList[selectedChannelIndex]; + } else { + selectedChannelIndex -= size5gList; + } } - Log.e(TAG, "No available channels on 5GHz band"); - return -1; + return allowed6GFreqList[selectedChannelIndex]; } /** @@ -120,11 +248,11 @@ public class ApConfigUtil { String countryCode, ArrayList<Integer> allowed2GChannels, SoftApConfiguration.Builder configBuilder, - SoftApConfiguration config) { + SoftApConfiguration config, + boolean acsEnabled) { /* Use default band and channel for device without HAL. */ if (!wifiNative.isHalStarted()) { - configBuilder.setBand(DEFAULT_AP_BAND); - configBuilder.setChannel(DEFAULT_AP_CHANNEL); + configBuilder.setChannel(DEFAULT_AP_CHANNEL, DEFAULT_AP_BAND); return SUCCESS; } @@ -135,16 +263,18 @@ public class ApConfigUtil { return ERROR_GENERIC; } - /* Select a channel if it is not specified. */ - if (config.getChannel() == 0) { - int channel = chooseApChannel(config.getBand(), allowed2GChannels, - wifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ)); - if (channel == -1) { + /* Select a channel if it is not specified and ACS is not enabled */ + if ((config.getChannel() == 0) && !acsEnabled) { + int freq = chooseApChannel(config.getBand(), allowed2GChannels, + wifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ), + wifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_6_GHZ)); + if (freq == -1) { /* We're not able to get channel from wificond. */ Log.e(TAG, "Failed to get available channel."); return ERROR_NO_CHANNEL; } - configBuilder.setChannel(channel); + configBuilder.setChannel( + convertFrequencyToChannel(freq), convertFrequencyToBand(freq)); } return SUCCESS; @@ -152,6 +282,8 @@ public class ApConfigUtil { /** * Helper function for converting SoftapConfiguration to WifiConfiguration. + * Note that WifiConfiguration only Supports 2GHz, 5GHz, 2GHz+5GHz bands, + * so conversion is limited to these bands. */ @NonNull public static WifiConfiguration convertToWifiConfiguration( @@ -194,6 +326,8 @@ public class ApConfigUtil { * Helper function for converting WifiConfiguration to SoftApConfiguration. * * Only Support None and WPA2 configuration conversion. + * Note that WifiConfiguration only Supports 2GHz, 5GHz, 2GHz+5GHz bands, + * so conversion is limited to these bands. */ @NonNull public static SoftApConfiguration fromWifiConfiguration( @@ -207,18 +341,25 @@ public class ApConfigUtil { configBuilder.setWpa2Passphrase(wifiConfig.preSharedKey); } configBuilder.setHiddenSsid(wifiConfig.hiddenSSID); + + int band; switch (wifiConfig.apBand) { case WifiConfiguration.AP_BAND_2GHZ: - configBuilder.setBand(SoftApConfiguration.BAND_2GHZ); + band = SoftApConfiguration.BAND_2GHZ; break; case WifiConfiguration.AP_BAND_5GHZ: - configBuilder.setBand(SoftApConfiguration.BAND_5GHZ); + band = SoftApConfiguration.BAND_5GHZ; break; default: - configBuilder.setBand(SoftApConfiguration.BAND_ANY); + // WifiConfiguration.AP_BAND_ANY means only 2GHz and 5GHz bands + band = SoftApConfiguration.BAND_2GHZ | SoftApConfiguration.BAND_5GHZ; break; } - configBuilder.setChannel(wifiConfig.apChannel); + if (wifiConfig.apChannel == 0) { + configBuilder.setBand(band); + } else { + configBuilder.setChannel(wifiConfig.apChannel, band); + } return configBuilder.build(); } } diff --git a/service/res/values/config.xml b/service/res/values/config.xml index 589a62a63..c6090e84b 100644 --- a/service/res/values/config.xml +++ b/service/res/values/config.xml @@ -148,6 +148,12 @@ <!-- Wifi driver supports IEEE80211AC for softap --> <bool translatable="false" name="config_wifi_softap_ieee80211ac_supported">false</bool> + <!-- Wifi driver supports IEEE80211AX for softap --> + <bool translatable="false" name="config_wifiSoftapIeee80211axSupported">false</bool> + + <!-- Wifi driver supports 6GHz band for softap --> + <bool translatable="false" name="config_wifiSoftap6ghzSupported">false</bool> + <!-- Indicates that local-only hotspot should be brought up at 5GHz. This option is for automotive builds only (the one that have PackageManager#FEATURE_AUTOMOTIVE) --> <bool translatable="false" name="config_wifi_local_only_hotspot_5ghz">false</bool> diff --git a/service/res/values/overlayable.xml b/service/res/values/overlayable.xml index 324afe0ce..2b4fa71c0 100644 --- a/service/res/values/overlayable.xml +++ b/service/res/values/overlayable.xml @@ -69,6 +69,8 @@ <item type="bool" name="config_wifi_softap_acs_supported" /> <item type="string" name="config_wifi_softap_acs_supported_channel_list" /> <item type="bool" name="config_wifi_softap_ieee80211ac_supported" /> + <item type="bool" name="config_wifiSoftapIeee80211axSupported" /> + <item type="bool" name="config_wifiSoftap6ghzSupported" /> <item type="bool" name="config_wifi_local_only_hotspot_5ghz" /> <item type="bool" name="config_wifi_connected_mac_randomization_supported" /> <item type="bool" name="config_wifi_p2p_mac_randomization_supported" /> diff --git a/tests/wifitests/Android.bp b/tests/wifitests/Android.bp index 918c6633a..611b2b1e3 100644 --- a/tests/wifitests/Android.bp +++ b/tests/wifitests/Android.bp @@ -44,6 +44,7 @@ android_test { "android.hardware.wifi-V1.4-java", "android.hardware.wifi.hostapd-V1.0-java", "android.hardware.wifi.hostapd-V1.1-java", + "android.hardware.wifi.hostapd-V1.2-java", "android.hardware.wifi.supplicant-V1.0-java", "android.hardware.wifi.supplicant-V1.1-java", "android.hardware.wifi.supplicant-V1.2-java", diff --git a/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java b/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java index a129de5b5..32e2c08f4 100644 --- a/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java @@ -66,7 +66,8 @@ public class HostapdHalTest extends WifiBaseTest { private @Mock IHostapd mIHostapdMock; private @Mock WifiNative.HostapdDeathEventHandler mHostapdHalDeathHandler; private @Mock WifiCondManager.SoftApListener mSoftApListener; - private android.hardware.wifi.hostapd.V1_1.IHostapd mIHostapdMockV1_1; + private android.hardware.wifi.hostapd.V1_1.IHostapd mIHostapdMockV11; + private android.hardware.wifi.hostapd.V1_2.IHostapd mIHostapdMockV12; private IHostapdCallback mIHostapdCallback; private MockResources mResources; HostapdStatus mStatusSuccess; @@ -107,7 +108,13 @@ public class HostapdHalTest extends WifiBaseTest { @Override protected android.hardware.wifi.hostapd.V1_1.IHostapd getHostapdMockableV1_1() throws RemoteException { - return mIHostapdMockV1_1; + return mIHostapdMockV11; + } + + @Override + protected android.hardware.wifi.hostapd.V1_2.IHostapd getHostapdMockableV1_2() + throws RemoteException { + return mIHostapdMockV12; } } @@ -117,6 +124,8 @@ public class HostapdHalTest extends WifiBaseTest { mResources = new MockResources(); mResources.setBoolean(R.bool.config_wifi_softap_acs_supported, false); mResources.setBoolean(R.bool.config_wifi_softap_ieee80211ac_supported, false); + mResources.setBoolean(R.bool.config_wifiSoftapIeee80211axSupported, false); + mResources.setBoolean(R.bool.config_wifiSoftap6ghzSupported, false); mResources.setString(R.string.config_wifi_softap_acs_supported_channel_list, ""); mStatusSuccess = createHostapdStatus(HostapdStatusCode.SUCCESS); @@ -173,7 +182,7 @@ public class HostapdHalTest extends WifiBaseTest { public void testInitialize_successV1_1() throws Exception { when(mServiceManagerMock.getTransport(anyString(), anyString())) .thenReturn(IServiceManager.Transport.HWBINDER); - mIHostapdMockV1_1 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class); + mIHostapdMockV11 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class); executeAndValidateInitializationSequenceV1_1(false); } @@ -184,7 +193,7 @@ public class HostapdHalTest extends WifiBaseTest { public void testInitialize_registerCallbackFailureV1_1() throws Exception { when(mServiceManagerMock.getTransport(anyString(), anyString())) .thenReturn(IServiceManager.Transport.HWBINDER); - mIHostapdMockV1_1 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class); + mIHostapdMockV11 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class); executeAndValidateInitializationSequenceV1_1(true); } @@ -226,8 +235,7 @@ public class HostapdHalTest extends WifiBaseTest { configurationBuilder.setSsid(NETWORK_SSID); configurationBuilder.setHiddenSsid(false); configurationBuilder.setWpa2Passphrase(NETWORK_PSK); - configurationBuilder.setChannel(apChannel); - configurationBuilder.setBand(SoftApConfiguration.BAND_2GHZ); + configurationBuilder.setChannel(apChannel, SoftApConfiguration.BAND_2GHZ); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configurationBuilder.build(), @@ -255,13 +263,12 @@ public class HostapdHalTest extends WifiBaseTest { @Test public void testAddAccessPointSuccess_Open_Band5G() throws Exception { executeAndValidateInitializationSequence(); - final int apChannel = 18; + final int apChannel = 149; Builder configurationBuilder = new SoftApConfiguration.Builder(); configurationBuilder.setSsid(NETWORK_SSID); configurationBuilder.setHiddenSsid(true); - configurationBuilder.setChannel(apChannel); - configurationBuilder.setBand(SoftApConfiguration.BAND_5GHZ); + configurationBuilder.setChannel(apChannel, SoftApConfiguration.BAND_5GHZ); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configurationBuilder.build(), @@ -289,14 +296,13 @@ public class HostapdHalTest extends WifiBaseTest { @Test public void testAddAccessPointSuccess_Psk_Band5G_Hidden() throws Exception { executeAndValidateInitializationSequence(); - final int apChannel = 18; + final int apChannel = 149; Builder configurationBuilder = new SoftApConfiguration.Builder(); configurationBuilder.setSsid(NETWORK_SSID); configurationBuilder.setHiddenSsid(true); configurationBuilder.setWpa2Passphrase(NETWORK_PSK); - configurationBuilder.setChannel(apChannel); - configurationBuilder.setBand(SoftApConfiguration.BAND_5GHZ); + configurationBuilder.setChannel(apChannel, SoftApConfiguration.BAND_5GHZ); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configurationBuilder.build(), @@ -334,8 +340,7 @@ public class HostapdHalTest extends WifiBaseTest { configurationBuilder.setSsid(NETWORK_SSID); configurationBuilder.setHiddenSsid(false); configurationBuilder.setWpa2Passphrase(NETWORK_PSK); - configurationBuilder.setChannel(apChannel); - configurationBuilder.setBand(SoftApConfiguration.BAND_2GHZ); + configurationBuilder.setChannel(apChannel, SoftApConfiguration.BAND_2GHZ); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configurationBuilder.build(), @@ -373,8 +378,7 @@ public class HostapdHalTest extends WifiBaseTest { configurationBuilder.setSsid(NETWORK_SSID); configurationBuilder.setHiddenSsid(false); configurationBuilder.setWpa2Passphrase(NETWORK_PSK); - configurationBuilder.setChannel(apChannel); - configurationBuilder.setBand(SoftApConfiguration.BAND_2GHZ); + configurationBuilder.setChannel(apChannel, SoftApConfiguration.BAND_2GHZ); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configurationBuilder.build(), @@ -405,13 +409,11 @@ public class HostapdHalTest extends WifiBaseTest { mHostapdHal = new HostapdHalSpy(); executeAndValidateInitializationSequence(); - final int apChannel = 6; Builder configurationBuilder = new SoftApConfiguration.Builder(); configurationBuilder.setSsid(NETWORK_SSID); configurationBuilder.setHiddenSsid(false); configurationBuilder.setWpa2Passphrase(NETWORK_PSK); - configurationBuilder.setChannel(apChannel); configurationBuilder.setBand(SoftApConfiguration.BAND_ANY); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, @@ -435,22 +437,19 @@ public class HostapdHalTest extends WifiBaseTest { /** * Verifies the successful addition of access point. - * Verifies that BAND_ANY is downgraded to 2.4GHz if ACS is disabled. */ @Test - public void testAddAccessPointSuccess_Psk_BandAny_Downgraded_WithoutACS() throws Exception { + public void testAddAccessPointSuccess_Psk_WithoutACS() throws Exception { // Disable ACS in the config. mResources.setBoolean(R.bool.config_wifi_softap_acs_supported, false); mHostapdHal = new HostapdHalSpy(); executeAndValidateInitializationSequence(); - final int apChannel = 6; Builder configurationBuilder = new SoftApConfiguration.Builder(); configurationBuilder.setSsid(NETWORK_SSID); configurationBuilder.setHiddenSsid(false); configurationBuilder.setWpa2Passphrase(NETWORK_PSK); - configurationBuilder.setChannel(apChannel); configurationBuilder.setBand(SoftApConfiguration.BAND_ANY); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, @@ -461,9 +460,6 @@ public class HostapdHalTest extends WifiBaseTest { assertEquals(IFACE_NAME, mIfaceParamsCaptor.getValue().ifaceName); assertTrue(mIfaceParamsCaptor.getValue().hwModeParams.enable80211N); assertFalse(mIfaceParamsCaptor.getValue().hwModeParams.enable80211AC); - // Verify the band is downgraded to 2.4GHz. - assertEquals(IHostapd.Band.BAND_2_4_GHZ, - mIfaceParamsCaptor.getValue().channelParams.band); assertFalse(mIfaceParamsCaptor.getValue().channelParams.enableAcs); assertEquals(NativeUtil.stringToByteArrayList(NETWORK_SSID), @@ -481,7 +477,7 @@ public class HostapdHalTest extends WifiBaseTest { public void testAddAccessPointSuccess_Psk_BandAny_WithACS_AcsChannels() throws Exception { when(mServiceManagerMock.getTransport(anyString(), anyString())) .thenReturn(IServiceManager.Transport.HWBINDER); - mIHostapdMockV1_1 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class); + mIHostapdMockV11 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class); // Enable ACS and set available channels in the config. final String acsChannelStr = "1,6,11-13,40"; android.hardware.wifi.hostapd.V1_1.IHostapd.AcsChannelRange channelRange1 = @@ -507,7 +503,7 @@ public class HostapdHalTest extends WifiBaseTest { mResources.setString(R.string.config_wifi_softap_acs_supported_channel_list, acsChannelStr); mHostapdHal = new HostapdHalSpy(); - when(mIHostapdMockV1_1.addAccessPoint_1_1( + when(mIHostapdMockV11.addAccessPoint_1_1( mIfaceParamsCaptorV1_1.capture(), mNetworkParamsCaptor.capture())) .thenReturn(mStatusSuccess); @@ -522,7 +518,7 @@ public class HostapdHalTest extends WifiBaseTest { assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configurationBuilder.build(), () -> mSoftApListener.onFailure())); - verify(mIHostapdMockV1_1).addAccessPoint_1_1(any(), any()); + verify(mIHostapdMockV11).addAccessPoint_1_1(any(), any()); assertEquals(IFACE_NAME, mIfaceParamsCaptorV1_1.getValue().V1_0.ifaceName); assertTrue(mIfaceParamsCaptorV1_1.getValue().V1_0.hwModeParams.enable80211N); @@ -552,8 +548,7 @@ public class HostapdHalTest extends WifiBaseTest { Builder configurationBuilder = new SoftApConfiguration.Builder(); configurationBuilder.setSsid(NETWORK_SSID); configurationBuilder.setHiddenSsid(true); - configurationBuilder.setChannel(6); - configurationBuilder.setBand(SoftApConfiguration.BAND_2GHZ); + configurationBuilder.setChannel(6, SoftApConfiguration.BAND_2GHZ); assertFalse(mHostapdHal.addAccessPoint(IFACE_NAME, configurationBuilder.build(), @@ -572,7 +567,7 @@ public class HostapdHalTest extends WifiBaseTest { Builder configurationBuilder = new SoftApConfiguration.Builder(); configurationBuilder.setSsid(NETWORK_SSID); configurationBuilder.setHiddenSsid(true); - configurationBuilder.setChannel(6); + configurationBuilder.setChannel(6, SoftApConfiguration.BAND_2GHZ); assertFalse(mHostapdHal.addAccessPoint(IFACE_NAME, configurationBuilder.build(), @@ -622,8 +617,8 @@ public class HostapdHalTest extends WifiBaseTest { public void testOnFailureCallbackHandling() throws Exception { when(mServiceManagerMock.getTransport(anyString(), anyString())) .thenReturn(IServiceManager.Transport.HWBINDER); - mIHostapdMockV1_1 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class); - when(mIHostapdMockV1_1.addAccessPoint_1_1( + mIHostapdMockV11 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class); + when(mIHostapdMockV11.addAccessPoint_1_1( mIfaceParamsCaptorV1_1.capture(), mNetworkParamsCaptor.capture())) .thenReturn(mStatusSuccess); executeAndValidateInitializationSequenceV1_1(false); @@ -635,7 +630,7 @@ public class HostapdHalTest extends WifiBaseTest { assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configurationBuilder.build(), () -> mSoftApListener.onFailure())); - verify(mIHostapdMockV1_1).addAccessPoint_1_1(any(), any()); + verify(mIHostapdMockV11).addAccessPoint_1_1(any(), any()); // Trigger on failure. mIHostapdCallback.onFailure(IFACE_NAME); @@ -702,7 +697,45 @@ public class HostapdHalTest extends WifiBaseTest { throws RemoteException { return mStatusFailure; } - }).when(mIHostapdMockV1_1).registerCallback(any(IHostapdCallback.class)); + }).when(mIHostapdMockV11).registerCallback(any(IHostapdCallback.class)); + } else { + doAnswer(new MockAnswerUtil.AnswerWithArguments() { + public HostapdStatus answer(IHostapdCallback cb) + throws RemoteException { + mIHostapdCallback = cb; + return mStatusSuccess; + } + }).when(mIHostapdMockV11).registerCallback(any(IHostapdCallback.class)); + } + // Initialize HostapdHal, should call serviceManager.registerForNotifications + assertTrue(mHostapdHal.initialize()); + // verify: service manager initialization sequence + mInOrder.verify(mServiceManagerMock).linkToDeath(mServiceManagerDeathCaptor.capture(), + anyLong()); + mInOrder.verify(mServiceManagerMock).registerForNotifications( + eq(IHostapd.kInterfaceName), eq(""), mServiceNotificationCaptor.capture()); + // act: cause the onRegistration(...) callback to execute + mServiceNotificationCaptor.getValue().onRegistration(IHostapd.kInterfaceName, "", true); + assertEquals(shouldSucceed, mHostapdHal.isInitializationComplete()); + mInOrder.verify(mIHostapdMock).linkToDeath(mHostapdDeathCaptor.capture(), anyLong()); + verify(mIHostapdMockV11).registerCallback(any(IHostapdCallback.class)); + } + + /** + * Calls.initialize(), mocking various callback answers and verifying flow, asserting for the + * expected result. Verifies if IHostapd manager is initialized or reset. + */ + private void executeAndValidateInitializationSequenceV1_2( + boolean causeCallbackFailure) throws Exception { + boolean shouldSucceed = !causeCallbackFailure; + mInOrder = inOrder(mServiceManagerMock, mIHostapdMock); + if (causeCallbackFailure) { + doAnswer(new MockAnswerUtil.AnswerWithArguments() { + public HostapdStatus answer(IHostapdCallback cb) + throws RemoteException { + return mStatusFailure; + } + }).when(mIHostapdMockV12).registerCallback(any(IHostapdCallback.class)); } else { doAnswer(new MockAnswerUtil.AnswerWithArguments() { public HostapdStatus answer(IHostapdCallback cb) @@ -710,7 +743,7 @@ public class HostapdHalTest extends WifiBaseTest { mIHostapdCallback = cb; return mStatusSuccess; } - }).when(mIHostapdMockV1_1).registerCallback(any(IHostapdCallback.class)); + }).when(mIHostapdMockV12).registerCallback(any(IHostapdCallback.class)); } // Initialize HostapdHal, should call serviceManager.registerForNotifications assertTrue(mHostapdHal.initialize()); @@ -723,7 +756,7 @@ public class HostapdHalTest extends WifiBaseTest { mServiceNotificationCaptor.getValue().onRegistration(IHostapd.kInterfaceName, "", true); assertEquals(shouldSucceed, mHostapdHal.isInitializationComplete()); mInOrder.verify(mIHostapdMock).linkToDeath(mHostapdDeathCaptor.capture(), anyLong()); - verify(mIHostapdMockV1_1).registerCallback(any(IHostapdCallback.class)); + verify(mIHostapdMockV12).registerCallback(any(IHostapdCallback.class)); } private HostapdStatus createHostapdStatus(int code) { diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java index 5826b7ae0..56d856081 100644 --- a/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java @@ -51,8 +51,7 @@ public class SoftApBackupRestoreTest extends WifiBaseTest { public void testSoftApConfigBackupAndRestoreWithWpa2Config() throws Exception { SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder(); configBuilder.setSsid("TestAP"); - configBuilder.setBand(SoftApConfiguration.BAND_5GHZ); - configBuilder.setChannel(40); + configBuilder.setChannel(40, SoftApConfiguration.BAND_5GHZ); configBuilder.setWpa2Passphrase("TestPsk"); configBuilder.setHiddenSsid(true); SoftApConfiguration config = configBuilder.build(); @@ -71,8 +70,7 @@ public class SoftApBackupRestoreTest extends WifiBaseTest { public void testSoftApConfigBackupAndRestoreWithOpenSecurityConfig() throws Exception { SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder(); configBuilder.setSsid("TestAP"); - configBuilder.setBand(SoftApConfiguration.BAND_2GHZ); - configBuilder.setChannel(12); + configBuilder.setChannel(12, SoftApConfiguration.BAND_2GHZ); configBuilder.setHiddenSsid(false); SoftApConfiguration config = configBuilder.build(); diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java index 93260ce4e..1b420fa90 100644 --- a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java @@ -536,7 +536,6 @@ public class SoftApManagerTest extends WifiBaseTest { public void startSoftApFailNoChannel() throws Exception { Builder configBuilder = new SoftApConfiguration.Builder(); configBuilder.setBand(SoftApConfiguration.BAND_5GHZ); - configBuilder.setChannel(0); configBuilder.setSsid(TEST_SSID); SoftApModeConfiguration softApConfig = new SoftApModeConfiguration( WifiManager.IFACE_IP_MODE_TETHERED, configBuilder.build()); @@ -1320,13 +1319,11 @@ public class SoftApManagerTest extends WifiBaseTest { if (config == null) { when(mWifiApConfigStore.getApConfiguration()).thenReturn(mDefaultApConfig); expectedConfig = new SoftApConfiguration.Builder(mDefaultApConfig) - .setBand(SoftApConfiguration.BAND_2GHZ) - .setChannel(DEFAULT_AP_CHANNEL) + .setChannel(DEFAULT_AP_CHANNEL, SoftApConfiguration.BAND_2GHZ) .build(); } else { expectedConfig = new SoftApConfiguration.Builder(config) - .setBand(SoftApConfiguration.BAND_2GHZ) - .setChannel(DEFAULT_AP_CHANNEL) + .setChannel(DEFAULT_AP_CHANNEL, SoftApConfiguration.BAND_2GHZ) .build(); } diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java index d368e9510..ee6821528 100644 --- a/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java @@ -139,7 +139,6 @@ public class SoftApStoreDataTest extends WifiBaseTest { softApConfigBuilder.setSsid(TEST_SSID); softApConfigBuilder.setWpa2Passphrase(TEST_WPA2_PASSPHRASE); softApConfigBuilder.setBand(TEST_BAND); - softApConfigBuilder.setChannel(TEST_CHANNEL); when(mDataSource.toSerialize()).thenReturn(softApConfigBuilder.build()); byte[] actualData = serializeData(); @@ -179,8 +178,6 @@ public class SoftApStoreDataTest extends WifiBaseTest { softApConfigBuilder.setSsid(TEST_SSID); softApConfigBuilder.setWpa2Passphrase(TEST_WPA2_PASSPHRASE); softApConfigBuilder.setBand(TEST_BAND); - softApConfigBuilder.setChannel(TEST_CHANNEL); - SoftApConfiguration softApConfig = softApConfigBuilder.build(); // Serialize first. diff --git a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java index d0670181d..b476589cc 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java @@ -161,8 +161,11 @@ public class WifiApConfigStoreTest extends WifiBaseTest { Builder configBuilder = new SoftApConfiguration.Builder(); configBuilder.setSsid(ssid); configBuilder.setWpa2Passphrase(preSharedKey); - configBuilder.setBand(band); - configBuilder.setChannel(channel); + if (channel == 0) { + configBuilder.setBand(band); + } else { + configBuilder.setChannel(channel, band); + } configBuilder.setHiddenSsid(hiddenSSID); return configBuilder.build(); } @@ -240,7 +243,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "ConfiguredAP", /* SSID */ "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ - 1, /* AP band (5GHz) */ + SoftApConfiguration.BAND_5GHZ, /* AP band (5GHz) */ 40, /* AP channel */ true /* Hidden SSID */); /* Create a temporary file for AP config file storage. */ @@ -276,7 +279,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "ConfiguredAP", /* SSID */ "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ - 1, /* AP band (5GHz) */ + SoftApConfiguration.BAND_5GHZ, /* AP band (5GHz) */ 40, /* AP channel */ true /* Hidden SSID */); WifiApConfigStore store = createWifiApConfigStore(); @@ -307,7 +310,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ SoftApConfiguration.BAND_2GHZ, /* AP band */ - 40, /* AP channel */ + 0, /* AP channel */ true /* Hidden SSID */); store.setApConfiguration(expectedConfig); verifyApConfig(expectedConfig, store.getApConfiguration()); @@ -334,7 +337,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ SoftApConfiguration.BAND_ANY, /* AP band (ANY) */ - 40, /* AP channel */ + 0, /* AP channel */ false /* Hidden SSID */); SoftApConfiguration expectedConfig = setupApConfig( @@ -342,7 +345,42 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ SoftApConfiguration.BAND_5GHZ, /* AP band (5GHz) */ - WifiApConfigStore.AP_CHANNEL_DEFAULT, /* AP channel */ + 0, /* AP channel */ + false /* Hidden SSID */); + store.setApConfiguration(providedConfig); + verifyApConfig(expectedConfig, store.getApConfiguration()); + verifyApConfig(expectedConfig, mDataStoreSource.toSerialize()); + verify(mWifiConfigManager, times(2)).saveToStore(true); + verify(mBackupManagerProxy, times(2)).notifyDataChanged(); + } + + /** + * Due to different device hw capabilities, some bands are not available if a device is + * dual/single mode capable. This test verifies that a single mode device will have apBand + * is a multiband not including 5GHz converted into 2GHz. + */ + @Test + public void convertSingleModeDeviceMultibandTo2Ghz() throws Exception { + /* Initialize WifiApConfigStore with default configuration. */ + WifiApConfigStore store = createWifiApConfigStore(); + verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID); + verify(mWifiConfigManager).saveToStore(true); + + /* Update with a valid configuration. */ + SoftApConfiguration providedConfig = setupApConfig( + "ConfiguredAP", /* SSID */ + "randomKey", /* preshared key */ + SECURITY_TYPE_WPA2_PSK, /* security type */ + SoftApConfiguration.BAND_2GHZ | SoftApConfiguration.BAND_6GHZ, /* AP band */ + 0, /* AP channel */ + false /* Hidden SSID */); + + SoftApConfiguration expectedConfig = setupApConfig( + "ConfiguredAP", /* SSID */ + "randomKey", /* preshared key */ + SECURITY_TYPE_WPA2_PSK, /* security type */ + SoftApConfiguration.BAND_2GHZ, /* AP band (5GHz) */ + 0, /* AP channel */ false /* Hidden SSID */); store.setApConfiguration(providedConfig); verifyApConfig(expectedConfig, store.getApConfiguration()); @@ -381,7 +419,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest { /** * Due to different device hw capabilities, some bands are not available if a device is * dual/single mode capable. This test verifies that a dual mode device will have apBand = - * 5GHz converted to ANY. + * 5GHz converted to include 2.4GHz. */ @Test public void convertDualModeDevice5GhzToAny() throws Exception { @@ -405,8 +443,9 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "ConfiguredAP", /* SSID */ "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ - SoftApConfiguration.BAND_ANY, /* AP band */ - WifiApConfigStore.AP_CHANNEL_DEFAULT, /* AP channel */ + SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_5GHZ, /* AP band */ + 0, /* AP channel */ false /* Hidden SSID */); store.setApConfiguration(providedConfig); verifyApConfig(expectedConfig, store.getApConfiguration()); @@ -435,7 +474,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ SoftApConfiguration.BAND_ANY, /* AP band */ - 40, /* AP channel */ + 0, /* AP channel */ false /* Hidden SSID */); store.setApConfiguration(expectedConfig); verifyApConfig(expectedConfig, store.getApConfiguration()); @@ -457,14 +496,14 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ SoftApConfiguration.BAND_ANY, /* AP band */ - 40, /* AP channel */ + 0, /* AP channel */ false /* Hidden SSID */); SoftApConfiguration expectedConfig = setupApConfig( "ConfiguredAP", /* SSID */ "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ SoftApConfiguration.BAND_5GHZ, /* AP band */ - WifiApConfigStore.AP_CHANNEL_DEFAULT, /* AP channel */ + 0, /* AP channel */ false /* Hidden SSID */); WifiApConfigStore store = createWifiApConfigStore(); mDataStoreSource.fromDeserialized(persistedConfig); @@ -499,7 +538,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest { /** * Due to different device hw capabilities, some bands are not available if a device is * dual/single mode capable. This test verifies that a dual mode device converts a persisted ap - * config with 5GHz only set for the apBand to ANY. + * config with 5GHz only set for the apBand to include 2.4GHz. */ @Test public void dualModeDevice5GhzConvertedToAnyAtRetrieval() throws Exception { @@ -516,8 +555,9 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "ConfiguredAP", /* SSID */ "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ - SoftApConfiguration.BAND_ANY, /* AP band */ - WifiApConfigStore.AP_CHANNEL_DEFAULT, /* AP channel */ + SoftApConfiguration.BAND_5GHZ + | SoftApConfiguration.BAND_2GHZ, /* AP band */ + 0, /* AP channel */ false /* Hidden SSID */); WifiApConfigStore store = createWifiApConfigStore(); @@ -542,7 +582,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ SoftApConfiguration.BAND_ANY, /* AP band */ - 40, /* AP channel */ + 0, /* AP channel */ false /* Hidden SSID */); WifiApConfigStore store = createWifiApConfigStore(); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index f3cf19fd6..4381a4a73 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -1289,6 +1289,112 @@ public class WifiServiceImplTest extends WifiBaseTest { } /** + * Verify attempt to start softAp with a supported 5GHz band succeeds. + */ + @Test + public void testStartTetheredHotspotWithSupported5gBand() { + when(mResources.getBoolean( + eq(R.bool.config_wifi5ghzSupport))) + .thenReturn(true); + SoftApConfiguration config = new SoftApConfiguration.Builder() + .setSsid("TestAp") + .setWpa2Passphrase("thisIsABadPassword") + .setBand(SoftApConfiguration.BAND_5GHZ) + .build(); + + boolean result = mWifiServiceImpl.startTetheredHotspot(config); + assertTrue(result); + verify(mActiveModeWarden).startSoftAp(mSoftApModeConfigCaptor.capture()); + assertThat(config).isEqualTo(mSoftApModeConfigCaptor.getValue().getSoftApConfiguration()); + } + + /** + * Verify attempt to start softAp with a non-supported 5GHz band fails. + */ + @Test + public void testStartTetheredHotspotWithUnSupported5gBand() { + when(mResources.getBoolean( + eq(R.bool.config_wifi5ghzSupport))) + .thenReturn(false); + SoftApConfiguration config = new SoftApConfiguration.Builder() + .setSsid("TestAp") + .setWpa2Passphrase("thisIsABadPassword") + .setBand(SoftApConfiguration.BAND_5GHZ) + .build(); + + boolean result = mWifiServiceImpl.startTetheredHotspot(config); + assertFalse(result); + verifyZeroInteractions(mActiveModeWarden); + } + + /** + * Verify attempt to start softAp with a supported 6GHz band succeeds. + */ + @Test + public void testStartTetheredHotspotWithSupported6gBand() { + when(mResources.getBoolean( + eq(R.bool.config_wifi6ghzSupport))) + .thenReturn(true); + when(mResources.getBoolean( + eq(R.bool.config_wifiSoftap6ghzSupported))) + .thenReturn(true); + + SoftApConfiguration config = new SoftApConfiguration.Builder() + .setSsid("TestAp") + .setWpa2Passphrase("thisIsABadPassword") + .setBand(SoftApConfiguration.BAND_6GHZ) + .build(); + + boolean result = mWifiServiceImpl.startTetheredHotspot(config); + assertTrue(result); + verify(mActiveModeWarden).startSoftAp(mSoftApModeConfigCaptor.capture()); + assertThat(config).isEqualTo(mSoftApModeConfigCaptor.getValue().getSoftApConfiguration()); + } + + /** + * Verify attempt to start softAp with a non-supported 6GHz band fails. + */ + @Test + public void testStartTetheredHotspotWithUnSupported6gBand() { + when(mResources.getBoolean( + eq(R.bool.config_wifi6ghzSupport))) + .thenReturn(true); + when(mResources.getBoolean( + eq(R.bool.config_wifiSoftap6ghzSupported))) + .thenReturn(false); + + SoftApConfiguration config = new SoftApConfiguration.Builder() + .setSsid("TestAp") + .setWpa2Passphrase("thisIsABadPassword") + .setBand(SoftApConfiguration.BAND_6GHZ) + .build(); + + boolean result = mWifiServiceImpl.startTetheredHotspot(config); + assertFalse(result); + verifyZeroInteractions(mActiveModeWarden); + } + + /** + * Verify attempt to start softAp with a supported band succeeds. + */ + @Test + public void testStartTetheredHotspotWithSupportedBand() { + when(mResources.getBoolean( + eq(R.bool.config_wifi5ghzSupport))) + .thenReturn(true); + SoftApConfiguration config = new SoftApConfiguration.Builder() + .setSsid("TestAp") + .setWpa2Passphrase("thisIsABadPassword") + .setBand(SoftApConfiguration.BAND_5GHZ) + .build(); + + boolean result = mWifiServiceImpl.startTetheredHotspot(config); + assertTrue(result); + verify(mActiveModeWarden).startSoftAp(mSoftApModeConfigCaptor.capture()); + assertThat(config).isEqualTo(mSoftApModeConfigCaptor.getValue().getSoftApConfiguration()); + } + + /** * Verify a SecurityException is thrown when a caller without the correct permission attempts to * start softap. */ diff --git a/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java index db48f833d..6da587d5e 100644 --- a/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java +++ b/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java @@ -17,11 +17,14 @@ package com.android.server.wifi.util; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; import android.net.wifi.SoftApConfiguration; import android.net.wifi.SoftApConfiguration.Builder; +import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiScanner; import androidx.test.filters.SmallTest; @@ -51,61 +54,68 @@ public class ApConfigUtilTest extends WifiBaseTest { * even indices are frequencies and odd indices are channels. */ private static final int[] FREQUENCY_TO_CHANNEL_MAP = { - 2412, 1, - 2417, 2, - 2422, 3, - 2427, 4, - 2432, 5, - 2437, 6, - 2442, 7, - 2447, 8, - 2452, 9, - 2457, 10, - 2462, 11, + 2412, SoftApConfiguration.BAND_2GHZ, 1, + 2417, SoftApConfiguration.BAND_2GHZ, 2, + 2422, SoftApConfiguration.BAND_2GHZ, 3, + 2427, SoftApConfiguration.BAND_2GHZ, 4, + 2432, SoftApConfiguration.BAND_2GHZ, 5, + 2437, SoftApConfiguration.BAND_2GHZ, 6, + 2442, SoftApConfiguration.BAND_2GHZ, 7, + 2447, SoftApConfiguration.BAND_2GHZ, 8, + 2452, SoftApConfiguration.BAND_2GHZ, 9, + 2457, SoftApConfiguration.BAND_2GHZ, 10, + 2462, SoftApConfiguration.BAND_2GHZ, 11, /* 12, 13 are only legitimate outside the US. */ - 2467, 12, - 2472, 13, + 2467, SoftApConfiguration.BAND_2GHZ, 12, + 2472, SoftApConfiguration.BAND_2GHZ, 13, /* 14 is for Japan, DSSS and CCK only. */ - 2484, 14, + 2484, SoftApConfiguration.BAND_2GHZ, 14, /* 34 valid in Japan. */ - 5170, 34, - 5180, 36, - 5190, 38, - 5200, 40, - 5210, 42, - 5220, 44, - 5230, 46, - 5240, 48, - 5260, 52, - 5280, 56, - 5300, 60, - 5320, 64, - 5500, 100, - 5520, 104, - 5540, 108, - 5560, 112, - 5580, 116, + 5170, SoftApConfiguration.BAND_5GHZ, 34, + 5180, SoftApConfiguration.BAND_5GHZ, 36, + 5190, SoftApConfiguration.BAND_5GHZ, 38, + 5200, SoftApConfiguration.BAND_5GHZ, 40, + 5210, SoftApConfiguration.BAND_5GHZ, 42, + 5220, SoftApConfiguration.BAND_5GHZ, 44, + 5230, SoftApConfiguration.BAND_5GHZ, 46, + 5240, SoftApConfiguration.BAND_5GHZ, 48, + 5260, SoftApConfiguration.BAND_5GHZ, 52, + 5280, SoftApConfiguration.BAND_5GHZ, 56, + 5300, SoftApConfiguration.BAND_5GHZ, 60, + 5320, SoftApConfiguration.BAND_5GHZ, 64, + 5500, SoftApConfiguration.BAND_5GHZ, 100, + 5520, SoftApConfiguration.BAND_5GHZ, 104, + 5540, SoftApConfiguration.BAND_5GHZ, 108, + 5560, SoftApConfiguration.BAND_5GHZ, 112, + 5580, SoftApConfiguration.BAND_5GHZ, 116, /* 120, 124, 128 valid in Europe/Japan. */ - 5600, 120, - 5620, 124, - 5640, 128, + 5600, SoftApConfiguration.BAND_5GHZ, 120, + 5620, SoftApConfiguration.BAND_5GHZ, 124, + 5640, SoftApConfiguration.BAND_5GHZ, 128, /* 132+ valid in US. */ - 5660, 132, - 5680, 136, - 5700, 140, + 5660, SoftApConfiguration.BAND_5GHZ, 132, + 5680, SoftApConfiguration.BAND_5GHZ, 136, + 5700, SoftApConfiguration.BAND_5GHZ, 140, /* 144 is supported by a subset of WiFi chips. */ - 5720, 144, - 5745, 149, - 5765, 153, - 5785, 157, - 5805, 161, - 5825, 165, - 5845, 169, - 5865, 173 + 5720, SoftApConfiguration.BAND_5GHZ, 144, + 5745, SoftApConfiguration.BAND_5GHZ, 149, + 5765, SoftApConfiguration.BAND_5GHZ, 153, + 5785, SoftApConfiguration.BAND_5GHZ, 157, + 5805, SoftApConfiguration.BAND_5GHZ, 161, + 5825, SoftApConfiguration.BAND_5GHZ, 165, + 5845, SoftApConfiguration.BAND_5GHZ, 169, + 5865, SoftApConfiguration.BAND_5GHZ, 173, + /* Now some 6GHz channels */ + 5945, SoftApConfiguration.BAND_6GHZ, 1, + 5960, SoftApConfiguration.BAND_6GHZ, 4, + 6100, SoftApConfiguration.BAND_6GHZ, 32 }; + + private static final Integer[] ALLOWED_2G_CHANNELS = {1, 2, 3, 4}; private static final int[] ALLOWED_5G_FREQS = {5180, 5190, 5200}; + private static final int[] ALLOWED_6G_FREQS = {5945, 5965}; private static final int[] ALLOWED_5G_CHANNELS = {36, 38, 40}; @Mock WifiNative mWifiNative; @@ -121,14 +131,100 @@ public class ApConfigUtilTest extends WifiBaseTest { } /** - * Verify frequency to channel conversion for all possible frequencies. + * verify convert WifiConfiguration Band to SoftApConfigurationBand. + */ + @Test + public void convertWifiConfigBandToSoftapConfigBandTest() throws Exception { + assertEquals(SoftApConfiguration.BAND_2GHZ, ApConfigUtil + .convertWifiConfigBandToSoftApConfigBand(WifiConfiguration.AP_BAND_2GHZ)); + assertEquals(SoftApConfiguration.BAND_5GHZ, ApConfigUtil + .convertWifiConfigBandToSoftApConfigBand(WifiConfiguration.AP_BAND_5GHZ)); + assertEquals(SoftApConfiguration.BAND_2GHZ | SoftApConfiguration.BAND_5GHZ, ApConfigUtil + .convertWifiConfigBandToSoftApConfigBand(WifiConfiguration.AP_BAND_ANY)); + } + + + + /** + * Verify isMultiband success + */ + @Test + public void isMultibandSuccess() throws Exception { + assertTrue(ApConfigUtil.isMultiband(SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_6GHZ)); + assertTrue(ApConfigUtil.isMultiband(SoftApConfiguration.BAND_5GHZ + | SoftApConfiguration.BAND_6GHZ)); + assertTrue(ApConfigUtil.isMultiband(SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_6GHZ)); + assertTrue(ApConfigUtil.isMultiband(SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_5GHZ | SoftApConfiguration.BAND_6GHZ)); + } + + /** + * Verify isMultiband failure + */ + @Test + public void isMultibandFailure() throws Exception { + assertFalse(ApConfigUtil.isMultiband(SoftApConfiguration.BAND_2GHZ)); + assertFalse(ApConfigUtil.isMultiband(SoftApConfiguration.BAND_5GHZ)); + assertFalse(ApConfigUtil.isMultiband(SoftApConfiguration.BAND_6GHZ)); + } + + /** + * Verify containsBand success + */ + @Test + public void containsBandSuccess() throws Exception { + assertTrue(ApConfigUtil.containsBand(SoftApConfiguration.BAND_2GHZ, + SoftApConfiguration.BAND_2GHZ)); + assertTrue(ApConfigUtil.containsBand(SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_6GHZ, SoftApConfiguration.BAND_2GHZ)); + assertTrue(ApConfigUtil.containsBand(SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_5GHZ | SoftApConfiguration.BAND_6GHZ, + SoftApConfiguration.BAND_6GHZ)); + } + + /** + * Verify containsBand failure + */ + @Test + public void containsBandFailure() throws Exception { + assertFalse(ApConfigUtil.containsBand(SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_5GHZ, SoftApConfiguration.BAND_6GHZ)); + assertFalse(ApConfigUtil.containsBand(SoftApConfiguration.BAND_5GHZ, + SoftApConfiguration.BAND_6GHZ)); + } + + /** + * Verify isBandValidSuccess + */ + @Test + public void isBandValidSuccess() throws Exception { + assertTrue(ApConfigUtil.isBandValid(SoftApConfiguration.BAND_2GHZ)); + assertTrue(ApConfigUtil.isBandValid(SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_6GHZ)); + assertTrue(ApConfigUtil.isBandValid(SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_5GHZ | SoftApConfiguration.BAND_6GHZ)); + } + + /** + * Verify isBandValidFailure + */ + @Test + public void isBandValidFailure() throws Exception { + assertFalse(ApConfigUtil.isBandValid(0)); + assertFalse(ApConfigUtil.isBandValid(SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_6GHZ | 0x0F)); + } + + /** + * verify frequency to channel conversion for all possible frequencies. */ @Test public void convertFrequencyToChannel() throws Exception { - for (int i = 0; i < FREQUENCY_TO_CHANNEL_MAP.length; i += 2) { - assertEquals(FREQUENCY_TO_CHANNEL_MAP[i + 1], - ApConfigUtil.convertFrequencyToChannel( - FREQUENCY_TO_CHANNEL_MAP[i])); + for (int i = 0; i < FREQUENCY_TO_CHANNEL_MAP.length; i += 3) { + assertEquals(FREQUENCY_TO_CHANNEL_MAP[i + 2], + ApConfigUtil.convertFrequencyToChannel(FREQUENCY_TO_CHANNEL_MAP[i])); } } @@ -137,7 +233,31 @@ public class ApConfigUtilTest extends WifiBaseTest { */ @Test public void convertFrequencyToChannelWithInvalidFreq() throws Exception { - assertEquals(-1, ApConfigUtil.convertFrequencyToChannel(6200)); + assertEquals(-1, ApConfigUtil.convertFrequencyToChannel(8000)); + } + + /** + * verify frequency to band conversion for all possible frequencies. + */ + @Test + public void convertFrequencytoBand() throws Exception { + for (int i = 0; i < FREQUENCY_TO_CHANNEL_MAP.length; i += 3) { + assertEquals(FREQUENCY_TO_CHANNEL_MAP[i + 1], + ApConfigUtil.convertFrequencyToBand( + FREQUENCY_TO_CHANNEL_MAP[i])); + } + } + + /** + * verify channel/band to frequency conversion for all possible channels. + */ + @Test + public void convertChannelToFrequency() throws Exception { + for (int i = 0; i < FREQUENCY_TO_CHANNEL_MAP.length; i += 3) { + assertEquals(FREQUENCY_TO_CHANNEL_MAP[i], + ApConfigUtil.convertChannelToFrequency( + FREQUENCY_TO_CHANNEL_MAP[i + 2], FREQUENCY_TO_CHANNEL_MAP[i + 1])); + } } /** @@ -146,8 +266,9 @@ public class ApConfigUtilTest extends WifiBaseTest { */ @Test public void chooseApChannel2GBandWithNoAllowedChannel() throws Exception { - assertEquals(ApConfigUtil.DEFAULT_AP_CHANNEL, ApConfigUtil.chooseApChannel( - SoftApConfiguration.BAND_2GHZ, null, ALLOWED_5G_FREQS)); + int freq = ApConfigUtil.chooseApChannel(SoftApConfiguration.BAND_2GHZ, + null, ALLOWED_5G_FREQS, ALLOWED_6G_FREQS); + assertEquals(ApConfigUtil.DEFAULT_AP_CHANNEL, ApConfigUtil.convertFrequencyToChannel(freq)); } /** @@ -155,9 +276,10 @@ public class ApConfigUtilTest extends WifiBaseTest { */ @Test public void chooseApChannel2GBandWithAllowedChannels() throws Exception { - int channel = ApConfigUtil.chooseApChannel( - SoftApConfiguration.BAND_2GHZ, mAllowed2GChannels, ALLOWED_5G_FREQS); - assertTrue(mAllowed2GChannels.contains(channel)); + int freq = ApConfigUtil.chooseApChannel( + SoftApConfiguration.BAND_2GHZ, mAllowed2GChannels, ALLOWED_5G_FREQS, + ALLOWED_6G_FREQS); + assertTrue(mAllowed2GChannels.contains(ApConfigUtil.convertFrequencyToChannel(freq))); } /** @@ -165,9 +287,11 @@ public class ApConfigUtilTest extends WifiBaseTest { */ @Test public void chooseApChannel5GBandWithAllowedChannels() throws Exception { - int channel = ApConfigUtil.chooseApChannel( - SoftApConfiguration.BAND_5GHZ, mAllowed2GChannels, ALLOWED_5G_FREQS); - assertTrue(ArrayUtils.contains(ALLOWED_5G_CHANNELS, channel)); + int freq = ApConfigUtil.chooseApChannel( + SoftApConfiguration.BAND_5GHZ, mAllowed2GChannels, ALLOWED_5G_FREQS, + ALLOWED_6G_FREQS); + assertTrue(ArrayUtils.contains(ALLOWED_5G_CHANNELS, + ApConfigUtil.convertFrequencyToChannel(freq))); } /** @@ -177,7 +301,7 @@ public class ApConfigUtilTest extends WifiBaseTest { @Test public void chooseApChannel5GBandWithNoAllowedChannels() throws Exception { assertEquals(-1, ApConfigUtil.chooseApChannel( - SoftApConfiguration.BAND_5GHZ, mAllowed2GChannels, null)); + SoftApConfiguration.BAND_5GHZ, mAllowed2GChannels, null, null)); } /** @@ -187,13 +311,12 @@ public class ApConfigUtilTest extends WifiBaseTest { @Test public void updateApChannelConfigWithoutHal() throws Exception { Builder configBuilder = new SoftApConfiguration.Builder(); - configBuilder.setChannel(36); - configBuilder.setBand(SoftApConfiguration.BAND_5GHZ); + configBuilder.setChannel(36, SoftApConfiguration.BAND_5GHZ); when(mWifiNative.isHalStarted()).thenReturn(false); assertEquals(ApConfigUtil.SUCCESS, ApConfigUtil.updateApChannelConfig(mWifiNative, TEST_COUNTRY_CODE, - mAllowed2GChannels, configBuilder, configBuilder.build())); + mAllowed2GChannels, configBuilder, configBuilder.build(), false)); /* Verify default band and channel is used. */ assertEquals(ApConfigUtil.DEFAULT_AP_BAND, configBuilder.build().getBand()); assertEquals(ApConfigUtil.DEFAULT_AP_CHANNEL, configBuilder.build().getChannel()); @@ -210,7 +333,7 @@ public class ApConfigUtilTest extends WifiBaseTest { when(mWifiNative.isHalStarted()).thenReturn(true); assertEquals(ApConfigUtil.ERROR_GENERIC, ApConfigUtil.updateApChannelConfig(mWifiNative, null, mAllowed2GChannels, - configBuilder, configBuilder.build())); + configBuilder, configBuilder.build(), false)); } /** @@ -219,12 +342,11 @@ public class ApConfigUtilTest extends WifiBaseTest { @Test public void updateApChannelConfigWithChannelSpecified() throws Exception { Builder configBuilder = new SoftApConfiguration.Builder(); - configBuilder.setBand(SoftApConfiguration.BAND_5GHZ); - configBuilder.setChannel(36); + configBuilder.setChannel(36, SoftApConfiguration.BAND_5GHZ); when(mWifiNative.isHalStarted()).thenReturn(true); assertEquals(ApConfigUtil.SUCCESS, ApConfigUtil.updateApChannelConfig(mWifiNative, TEST_COUNTRY_CODE, - mAllowed2GChannels, configBuilder, configBuilder.build())); + mAllowed2GChannels, configBuilder, configBuilder.build(), false)); assertEquals(SoftApConfiguration.BAND_5GHZ, configBuilder.build().getBand()); assertEquals(36, configBuilder.build().getChannel()); } @@ -242,6 +364,39 @@ public class ApConfigUtilTest extends WifiBaseTest { .thenReturn(null); assertEquals(ApConfigUtil.ERROR_NO_CHANNEL, ApConfigUtil.updateApChannelConfig(mWifiNative, TEST_COUNTRY_CODE, - mAllowed2GChannels, configBuilder, configBuilder.build())); + mAllowed2GChannels, configBuilder, configBuilder.build(), false)); + } + + /** + * Verify updateApChannelConfig will select a channel number and band when acs is + * disabled. + */ + @Test + public void updateApChannelConfigWithAcsDisabled() throws Exception { + Builder configBuilder = new SoftApConfiguration.Builder(); + configBuilder.setBand(SoftApConfiguration.BAND_5GHZ | SoftApConfiguration.BAND_2GHZ); + when(mWifiNative.isHalStarted()).thenReturn(true); + assertEquals(ApConfigUtil.SUCCESS, + ApConfigUtil.updateApChannelConfig(mWifiNative, TEST_COUNTRY_CODE, + mAllowed2GChannels, configBuilder, configBuilder.build(), false)); + assertFalse(ApConfigUtil.isMultiband(configBuilder.build().getBand())); + assertNotEquals(0, configBuilder.build().getChannel()); + } + + /** + * Verify updateApChannelConfig will not select a channel number and band when acs is + * enabled. + */ + @Test + public void updateApChannelConfigWithAcsEnabled() throws Exception { + Builder configBuilder = new SoftApConfiguration.Builder(); + configBuilder.setBand(SoftApConfiguration.BAND_5GHZ | SoftApConfiguration.BAND_2GHZ); + when(mWifiNative.isHalStarted()).thenReturn(true); + assertEquals(ApConfigUtil.SUCCESS, + ApConfigUtil.updateApChannelConfig(mWifiNative, TEST_COUNTRY_CODE, + mAllowed2GChannels, configBuilder, configBuilder.build(), true)); + assertEquals(SoftApConfiguration.BAND_5GHZ | SoftApConfiguration.BAND_2GHZ, + configBuilder.build().getBand()); + assertEquals(0, configBuilder.build().getChannel()); } } |