summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorAhmed ElArabawy <arabawy@google.com>2020-05-12 01:10:10 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-05-12 01:10:10 +0000
commit245a2c1ab3db68440222a8a22ca2f7304172b31d (patch)
tree7c830e89ce380007ef6a8358f00a326eed82b947 /service
parent73a607348813b0733f17cd34cf536e19e489944a (diff)
parentf9b987b98584034239b217f4e2729ae71bddf18f (diff)
Merge "Correct band frequency ranges" into rvc-dev
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/BubbleFunScorer.java3
-rw-r--r--service/java/com/android/server/wifi/CompatibilityScorer.java6
-rw-r--r--service/java/com/android/server/wifi/ScoreCardBasedScorer.java6
-rw-r--r--service/java/com/android/server/wifi/ScoringParams.java23
-rw-r--r--service/java/com/android/server/wifi/ThroughputPredictor.java2
-rw-r--r--service/java/com/android/server/wifi/VelocityBasedConnectedScore.java3
-rw-r--r--service/java/com/android/server/wifi/WifiConnectivityManager.java7
-rw-r--r--service/java/com/android/server/wifi/WifiDataStall.java14
-rw-r--r--service/java/com/android/server/wifi/WifiMetrics.java8
-rw-r--r--service/java/com/android/server/wifi/WifiShellCommand.java2
-rw-r--r--service/java/com/android/server/wifi/scanner/KnownBandsChannelHelper.java20
-rw-r--r--service/java/com/android/server/wifi/util/ApConfigUtil.java75
12 files changed, 68 insertions, 101 deletions
diff --git a/service/java/com/android/server/wifi/BubbleFunScorer.java b/service/java/com/android/server/wifi/BubbleFunScorer.java
index e14fef0eb..fd18c14eb 100644
--- a/service/java/com/android/server/wifi/BubbleFunScorer.java
+++ b/service/java/com/android/server/wifi/BubbleFunScorer.java
@@ -17,6 +17,7 @@
package com.android.server.wifi;
import android.annotation.NonNull;
+import android.net.wifi.ScanResult;
import com.android.server.wifi.WifiCandidates.Candidate;
import com.android.server.wifi.WifiCandidates.ScoredCandidate;
@@ -74,7 +75,7 @@ final class BubbleFunScorer implements WifiCandidates.CandidateScorer {
// Prefer 5GHz/6GHz when all are strong, but at the fringes, 2.4 might be better
// Typically the entry rssi is lower for the 2.4 band, which provides the fringe boost
- if (candidate.getFrequency() < ScoringParams.MINIMUM_5GHZ_BAND_FREQUENCY_IN_MEGAHERTZ) {
+ if (ScanResult.is24GHz(candidate.getFrequency())) {
score *= LOW_BAND_FACTOR;
gain *= LOW_BAND_FACTOR;
}
diff --git a/service/java/com/android/server/wifi/CompatibilityScorer.java b/service/java/com/android/server/wifi/CompatibilityScorer.java
index 996324b0a..96b5004f5 100644
--- a/service/java/com/android/server/wifi/CompatibilityScorer.java
+++ b/service/java/com/android/server/wifi/CompatibilityScorer.java
@@ -17,6 +17,7 @@
package com.android.server.wifi;
import android.annotation.NonNull;
+import android.net.wifi.ScanResult;
import com.android.server.wifi.WifiCandidates.Candidate;
import com.android.server.wifi.WifiCandidates.ScoredCandidate;
@@ -79,10 +80,9 @@ final class CompatibilityScorer implements WifiCandidates.CandidateScorer {
int rssi = Math.min(candidate.getScanRssi(), rssiSaturationThreshold);
int score = (rssi + RSSI_SCORE_OFFSET) * RSSI_SCORE_SLOPE_IS_4;
- if (candidate.getFrequency() > ScoringParams.MINIMUM_6GHZ_BAND_FREQUENCY_IN_MEGAHERTZ) {
+ if (ScanResult.is6GHz(candidate.getFrequency())) {
score += BAND_6GHZ_AWARD_IS_40;
- } else if (candidate.getFrequency()
- >= ScoringParams.MINIMUM_5GHZ_BAND_FREQUENCY_IN_MEGAHERTZ) {
+ } else if (ScanResult.is5GHz(candidate.getFrequency())) {
score += BAND_5GHZ_AWARD_IS_40;
}
score += (int) (candidate.getLastSelectionWeight() * LAST_SELECTION_AWARD_IS_480);
diff --git a/service/java/com/android/server/wifi/ScoreCardBasedScorer.java b/service/java/com/android/server/wifi/ScoreCardBasedScorer.java
index 3ced720c3..7363a771b 100644
--- a/service/java/com/android/server/wifi/ScoreCardBasedScorer.java
+++ b/service/java/com/android/server/wifi/ScoreCardBasedScorer.java
@@ -17,6 +17,7 @@
package com.android.server.wifi;
import android.annotation.NonNull;
+import android.net.wifi.ScanResult;
import com.android.server.wifi.WifiCandidates.Candidate;
import com.android.server.wifi.WifiCandidates.ScoredCandidate;
@@ -88,10 +89,9 @@ final class ScoreCardBasedScorer implements WifiCandidates.CandidateScorer {
int cutoff = estimatedCutoff(candidate);
int score = (rssi - cutoff) * RSSI_SCORE_SLOPE_IS_4;
- if (candidate.getFrequency() > ScoringParams.MINIMUM_6GHZ_BAND_FREQUENCY_IN_MEGAHERTZ) {
+ if (ScanResult.is6GHz(candidate.getFrequency())) {
score += BAND_6GHZ_AWARD_IS_40;
- } else if (candidate.getFrequency()
- >= ScoringParams.MINIMUM_5GHZ_BAND_FREQUENCY_IN_MEGAHERTZ) {
+ } else if (ScanResult.is5GHz(candidate.getFrequency())) {
score += BAND_5GHZ_AWARD_IS_40;
}
score += (int) (candidate.getLastSelectionWeight() * LAST_SELECTION_AWARD_IS_480);
diff --git a/service/java/com/android/server/wifi/ScoringParams.java b/service/java/com/android/server/wifi/ScoringParams.java
index 16230fa34..460cb9c20 100644
--- a/service/java/com/android/server/wifi/ScoringParams.java
+++ b/service/java/com/android/server/wifi/ScoringParams.java
@@ -18,6 +18,7 @@ package com.android.server.wifi;
import android.annotation.NonNull;
import android.content.Context;
+import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
import android.util.Log;
@@ -33,10 +34,6 @@ import com.android.wifi.resources.R;
*
*/
public class ScoringParams {
- // A long name that describes itself pretty well
- public static final int MINIMUM_5GHZ_BAND_FREQUENCY_IN_MEGAHERTZ = 5000;
- public static final int MINIMUM_6GHZ_BAND_FREQUENCY_IN_MEGAHERTZ = 5925;
-
private final Context mContext;
private static final String TAG = "WifiScoringParams";
@@ -337,15 +334,6 @@ public class ScoringParams {
return printable;
}
- /** Constant to denote someplace in the 2.4 GHz band */
- public static final int BAND2 = 2400;
-
- /** Constant to denote someplace in the 5 GHz band */
- public static final int BAND5 = 5000;
-
- /** Constant to denote someplace in the 6 GHz band */
- public static final int BAND6 = 6000;
-
/**
* Returns the RSSI value at which the connection is deemed to be unusable,
* in the absence of other indications.
@@ -498,13 +486,16 @@ public class ScoringParams {
private int[] getRssiArray(int frequency) {
loadResources(mContext);
- if (frequency < MINIMUM_5GHZ_BAND_FREQUENCY_IN_MEGAHERTZ) {
+ if (ScanResult.is24GHz(frequency)) {
return mVal.rssi2;
- } else if (frequency < MINIMUM_6GHZ_BAND_FREQUENCY_IN_MEGAHERTZ) {
+ } else if (ScanResult.is5GHz(frequency)) {
return mVal.rssi5;
- } else {
+ } else if (ScanResult.is6GHz(frequency)) {
return mVal.rssi6;
}
+ // Invalid frequency use
+ Log.e(TAG, "Invalid frequency(" + frequency + "), using 5G as default rssi array");
+ return mVal.rssi5;
}
@Override
diff --git a/service/java/com/android/server/wifi/ThroughputPredictor.java b/service/java/com/android/server/wifi/ThroughputPredictor.java
index 0e750efc5..5cd8a5ce9 100644
--- a/service/java/com/android/server/wifi/ThroughputPredictor.java
+++ b/service/java/com/android/server/wifi/ThroughputPredictor.java
@@ -381,7 +381,7 @@ public class ThroughputPredictor {
private int getValidChannelUtilization(int frequency, int channelUtilizationBssLoad,
int channelUtilizationLinkLayerStats, boolean isBluetoothConnected) {
int channelUtilization;
- boolean is2G = (frequency < ScoringParams.MINIMUM_5GHZ_BAND_FREQUENCY_IN_MEGAHERTZ);
+ boolean is2G = ScanResult.is24GHz(frequency);
if (isValidUtilizationRatio(channelUtilizationBssLoad)) {
channelUtilization = channelUtilizationBssLoad;
} else if (isValidUtilizationRatio(channelUtilizationLinkLayerStats)) {
diff --git a/service/java/com/android/server/wifi/VelocityBasedConnectedScore.java b/service/java/com/android/server/wifi/VelocityBasedConnectedScore.java
index b7f45dbec..b931689a2 100644
--- a/service/java/com/android/server/wifi/VelocityBasedConnectedScore.java
+++ b/service/java/com/android/server/wifi/VelocityBasedConnectedScore.java
@@ -16,6 +16,7 @@
package com.android.server.wifi;
+import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
import com.android.server.wifi.util.KalmanFilter;
@@ -29,7 +30,7 @@ public class VelocityBasedConnectedScore extends ConnectedScore {
private final ScoringParams mScoringParams;
- private int mFrequency = ScoringParams.BAND5;
+ private int mFrequency = ScanResult.BAND_5_GHZ_START_FREQ_MHZ;
private double mThresholdAdjustment;
private final KalmanFilter mFilter;
private long mLastMillis;
diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java
index 9148e3a9e..975d446ea 100644
--- a/service/java/com/android/server/wifi/WifiConnectivityManager.java
+++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java
@@ -1388,9 +1388,10 @@ public class WifiConnectivityManager {
pnoSettings.networkList = new PnoSettings.PnoNetwork[listSize];
pnoSettings.networkList = pnoNetworkList.toArray(pnoSettings.networkList);
- pnoSettings.min6GHzRssi = mScoringParams.getEntryRssi(ScoringParams.BAND6);
- pnoSettings.min5GHzRssi = mScoringParams.getEntryRssi(ScoringParams.BAND5);
- pnoSettings.min24GHzRssi = mScoringParams.getEntryRssi(ScoringParams.BAND2);
+ pnoSettings.min6GHzRssi = mScoringParams.getEntryRssi(ScanResult.BAND_6_GHZ_START_FREQ_MHZ);
+ pnoSettings.min5GHzRssi = mScoringParams.getEntryRssi(ScanResult.BAND_5_GHZ_START_FREQ_MHZ);
+ pnoSettings.min24GHzRssi = mScoringParams.getEntryRssi(
+ ScanResult.BAND_24_GHZ_START_FREQ_MHZ);
// Initialize scan settings
ScanSettings scanSettings = new ScanSettings();
diff --git a/service/java/com/android/server/wifi/WifiDataStall.java b/service/java/com/android/server/wifi/WifiDataStall.java
index ba1de327c..8dea0df61 100644
--- a/service/java/com/android/server/wifi/WifiDataStall.java
+++ b/service/java/com/android/server/wifi/WifiDataStall.java
@@ -19,6 +19,7 @@ package com.android.server.wifi;
import static com.android.server.wifi.util.InformationElementUtil.BssLoad.CHANNEL_UTILIZATION_SCALE;
import android.content.Context;
+import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager.DeviceMobilityState;
import android.os.Handler;
@@ -501,18 +502,18 @@ public class WifiDataStall {
private int getBand(int frequency) {
int band;
- if (frequency >= KnownBandsChannelHelper.BAND_24_GHZ_START_FREQ
- && frequency <= KnownBandsChannelHelper.BAND_24_GHZ_END_FREQ) {
+ if (ScanResult.is24GHz(frequency)) {
band = WifiStatsLog.WIFI_HEALTH_STAT_REPORTED__BAND__BAND_2G;
- } else if (frequency >= KnownBandsChannelHelper.BAND_5_GHZ_START_FREQ
- && frequency <= KnownBandsChannelHelper.BAND_6_GHZ_END_FREQ) {
+ } else if (ScanResult.is5GHz(frequency)) {
if (frequency <= KnownBandsChannelHelper.BAND_5_GHZ_LOW_END_FREQ) {
band = WifiStatsLog.WIFI_HEALTH_STAT_REPORTED__BAND__BAND_5G_LOW;
} else if (frequency <= KnownBandsChannelHelper.BAND_5_GHZ_MID_END_FREQ) {
band = WifiStatsLog.WIFI_HEALTH_STAT_REPORTED__BAND__BAND_5G_MIDDLE;
- } else if (frequency <= KnownBandsChannelHelper.BAND_5_GHZ_END_FREQ) {
+ } else {
band = WifiStatsLog.WIFI_HEALTH_STAT_REPORTED__BAND__BAND_5G_HIGH;
- } else if (frequency <= KnownBandsChannelHelper.BAND_6_GHZ_LOW_END_FREQ) {
+ }
+ } else if (ScanResult.is6GHz(frequency)) {
+ if (frequency <= KnownBandsChannelHelper.BAND_6_GHZ_LOW_END_FREQ) {
band = WifiStatsLog.WIFI_HEALTH_STAT_REPORTED__BAND__BAND_6G_LOW;
} else if (frequency <= KnownBandsChannelHelper.BAND_6_GHZ_MID_END_FREQ) {
band = WifiStatsLog.WIFI_HEALTH_STAT_REPORTED__BAND__BAND_6G_MIDDLE;
@@ -524,6 +525,7 @@ public class WifiDataStall {
}
return band;
}
+
private void logd(String string) {
if (mVerboseLoggingEnabled) {
Log.d(TAG, string);
diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java
index da07edfc1..8aa027c60 100644
--- a/service/java/com/android/server/wifi/WifiMetrics.java
+++ b/service/java/com/android/server/wifi/WifiMetrics.java
@@ -2114,7 +2114,7 @@ public class WifiMetrics {
return;
}
synchronized (mLock) {
- if (frequency <= KnownBandsChannelHelper.BAND_24_GHZ_END_FREQ) {
+ if (ScanResult.is24GHz(frequency)) {
mTxLinkSpeedCount2g.increment(txLinkSpeed);
} else if (frequency <= KnownBandsChannelHelper.BAND_5_GHZ_LOW_END_FREQ) {
mTxLinkSpeedCount5gLow.increment(txLinkSpeed);
@@ -2139,7 +2139,7 @@ public class WifiMetrics {
return;
}
synchronized (mLock) {
- if (frequency <= KnownBandsChannelHelper.BAND_24_GHZ_END_FREQ) {
+ if (ScanResult.is24GHz(frequency)) {
mRxLinkSpeedCount2g.increment(rxLinkSpeed);
} else if (frequency <= KnownBandsChannelHelper.BAND_5_GHZ_LOW_END_FREQ) {
mRxLinkSpeedCount5gLow.increment(rxLinkSpeed);
@@ -2163,7 +2163,7 @@ public class WifiMetrics {
return;
}
synchronized (mLock) {
- if (frequency <= KnownBandsChannelHelper.BAND_24_GHZ_END_FREQ) {
+ if (ScanResult.is24GHz(frequency)) {
mChannelUtilizationHistogram2G.increment(channelUtilization);
} else {
mChannelUtilizationHistogramAbove2G.increment(channelUtilization);
@@ -2181,7 +2181,7 @@ public class WifiMetrics {
public void incrementThroughputKbpsCount(int txThroughputKbps, int rxThroughputKbps,
int frequency) {
synchronized (mLock) {
- if (frequency <= KnownBandsChannelHelper.BAND_24_GHZ_END_FREQ) {
+ if (ScanResult.is24GHz(frequency)) {
if (txThroughputKbps >= 0) {
mTxThroughputMbpsHistogram2G.increment(txThroughputKbps / 1000);
}
diff --git a/service/java/com/android/server/wifi/WifiShellCommand.java b/service/java/com/android/server/wifi/WifiShellCommand.java
index fd3649fec..842493c6d 100644
--- a/service/java/com/android/server/wifi/WifiShellCommand.java
+++ b/service/java/com/android/server/wifi/WifiShellCommand.java
@@ -281,7 +281,7 @@ public class WifiShellCommand extends BasicShellCommandHandler {
+ "- must be a positive integer");
return -1;
}
- int apChannel = ApConfigUtil.convertFrequencyToChannel(apChannelMHz);
+ int apChannel = ScanResult.convertFrequencyMhzToChannel(apChannelMHz);
int band = ApConfigUtil.convertFrequencyToBand(apChannelMHz);
if (apChannel == -1 || band == -1 || !isApChannelMHzValid(apChannelMHz)) {
pw.println("Invalid argument to 'force-softap-channel enabled' "
diff --git a/service/java/com/android/server/wifi/scanner/KnownBandsChannelHelper.java b/service/java/com/android/server/wifi/scanner/KnownBandsChannelHelper.java
index f2a744c31..ec43cde6c 100644
--- a/service/java/com/android/server/wifi/scanner/KnownBandsChannelHelper.java
+++ b/service/java/com/android/server/wifi/scanner/KnownBandsChannelHelper.java
@@ -28,6 +28,7 @@ import static android.net.wifi.WifiScanner.WIFI_BAND_INDEX_6_GHZ;
import static android.net.wifi.WifiScanner.WIFI_BAND_MAX;
import static android.net.wifi.WifiScanner.WIFI_BAND_UNSPECIFIED;
+import android.net.wifi.ScanResult;
import android.net.wifi.WifiAnnotations.WifiBandBasic;
import android.net.wifi.WifiScanner;
import android.net.wifi.WifiScanner.WifiBandIndex;
@@ -44,25 +45,18 @@ import java.util.stream.Collectors;
* This allows more fine operations on channels than if band channels are not known.
*/
public class KnownBandsChannelHelper extends ChannelHelper {
- public static final int BAND_24_GHZ_START_FREQ = 2400;
- public static final int BAND_24_GHZ_END_FREQ = 2500;
- public static final int BAND_5_GHZ_START_FREQ = 4900;
- public static final int BAND_5_GHZ_END_FREQ = 5875;
- public static final int BAND_6_GHZ_START_FREQ = 5925;
- public static final int BAND_6_GHZ_END_FREQ = 7125;
-
// 5G low includes U-NII-1 and Japan 4.9G band
public static final int BAND_5_GHZ_LOW_END_FREQ = 5240;
// 5G middle includes U-NII-2A and U-NII-2C
public static final int BAND_5_GHZ_MID_END_FREQ = 5710;
// 5G high includes U-NII-3
- public static final int BAND_5_GHZ_HIGH_END_FREQ = BAND_5_GHZ_END_FREQ;
+ public static final int BAND_5_GHZ_HIGH_END_FREQ = ScanResult.BAND_5_GHZ_END_FREQ_MHZ;
// 6G low includes UNII-5
public static final int BAND_6_GHZ_LOW_END_FREQ = 6425;
// 6G middle includes UNII-6 and UNII-7
public static final int BAND_6_GHZ_MID_END_FREQ = 6875;
// 6G high includes UNII-8
- public static final int BAND_6_GHZ_HIGH_END_FREQ = BAND_6_GHZ_END_FREQ;
+ public static final int BAND_6_GHZ_HIGH_END_FREQ = ScanResult.BAND_6_GHZ_END_FREQ_MHZ;
private WifiScanner.ChannelSpec[][] mBandsToChannels;
@@ -175,15 +169,15 @@ public class KnownBandsChannelHelper extends ChannelHelper {
// TODO this should be rewritten to be based on the input data instead of hardcoded ranges
private int getBandFromChannel(int frequency) {
- if (BAND_24_GHZ_START_FREQ <= frequency && frequency < BAND_24_GHZ_END_FREQ) {
+ if (ScanResult.is24GHz(frequency)) {
return WIFI_BAND_24_GHZ;
- } else if (BAND_5_GHZ_START_FREQ <= frequency && frequency < BAND_5_GHZ_END_FREQ) {
+ } else if (ScanResult.is5GHz(frequency)) {
if (isDfsChannel(frequency)) {
return WIFI_BAND_5_GHZ_DFS_ONLY;
} else {
return WIFI_BAND_5_GHZ;
}
- } else if (BAND_6_GHZ_START_FREQ <= frequency && frequency < BAND_6_GHZ_END_FREQ) {
+ } else if (ScanResult.is6GHz(frequency)) {
return WIFI_BAND_6_GHZ;
} else {
return WIFI_BAND_UNSPECIFIED;
@@ -198,6 +192,8 @@ public class KnownBandsChannelHelper extends ChannelHelper {
return WIFI_BAND_INDEX_5_GHZ;
case WIFI_BAND_5_GHZ_DFS_ONLY:
return WIFI_BAND_INDEX_5_GHZ_DFS_ONLY;
+ case WIFI_BAND_6_GHZ:
+ return WIFI_BAND_INDEX_6_GHZ;
default:
return -1;
}
diff --git a/service/java/com/android/server/wifi/util/ApConfigUtil.java b/service/java/com/android/server/wifi/util/ApConfigUtil.java
index cc286fad7..b385369a7 100644
--- a/service/java/com/android/server/wifi/util/ApConfigUtil.java
+++ b/service/java/com/android/server/wifi/util/ApConfigUtil.java
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.content.res.Resources;
+import android.net.wifi.ScanResult;
import android.net.wifi.SoftApCapability;
import android.net.wifi.SoftApConfiguration;
import android.net.wifi.SoftApConfiguration.BandType;
@@ -89,59 +90,33 @@ public class ApConfigUtil {
}
/**
- * 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
+ * Convert band from SoftApConfiguration.BandType to WifiScanner.WifiBand
+ * @param band in SoftApConfiguration.BandType
+ * @return band in WifiScanner.WifiBand
*/
- public static int convertChannelToFrequency(int channel, @BandType 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;
- }
+ public static @WifiScanner.WifiBand int apConfig2wifiScannerBand(@BandType int band) {
+ switch(band) {
+ case SoftApConfiguration.BAND_2GHZ:
+ return WifiScanner.WIFI_BAND_24_GHZ;
+ case SoftApConfiguration.BAND_5GHZ:
+ return WifiScanner.WIFI_BAND_5_GHZ;
+ case SoftApConfiguration.BAND_6GHZ:
+ return WifiScanner.WIFI_BAND_6_GHZ;
+ default:
+ return WifiScanner.WIFI_BAND_UNSPECIFIED;
}
-
- return -1;
}
/**
- * Convert frequency to channel.
+ * Convert channel/band to frequency.
* Note: the utility does not perform any regulatory domain compliance.
- * @param frequency frequency to convert
- * @return channel number associated with given frequency, -1 if no match
+ * @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 convertFrequencyToChannel(int frequency) {
- if (frequency >= 2412 && frequency <= 2472) {
- return (frequency - 2412) / 5 + 1;
- } else if (frequency == 2484) {
- return 14;
- } 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;
+ public static int convertChannelToFrequency(int channel, @BandType int band) {
+ return ScanResult.convertChannelToFrequencyMhz(channel,
+ apConfig2wifiScannerBand(band));
}
/**
@@ -151,11 +126,11 @@ public class ApConfigUtil {
* @return band, -1 if no match
*/
public static int convertFrequencyToBand(int frequency) {
- if (frequency >= 2412 && frequency <= 2484) {
+ if (ScanResult.is24GHz(frequency)) {
return SoftApConfiguration.BAND_2GHZ;
- } else if (frequency >= 5170 && frequency <= 5865) {
+ } else if (ScanResult.is5GHz(frequency)) {
return SoftApConfiguration.BAND_5GHZ;
- } else if (frequency > 5940 && frequency < 7210) {
+ } else if (ScanResult.is6GHz(frequency)) {
return SoftApConfiguration.BAND_6GHZ;
}
@@ -400,7 +375,7 @@ public class ApConfigUtil {
return ERROR_NO_CHANNEL;
}
configBuilder.setChannel(
- convertFrequencyToChannel(freq), convertFrequencyToBand(freq));
+ ScanResult.convertFrequencyMhzToChannel(freq), convertFrequencyToBand(freq));
}
return SUCCESS;