summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorPatrik Fimml <patrikf@google.com>2019-09-11 20:30:05 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-09-11 20:30:05 +0000
commit1db7be148f49a8d6d5e88d297a63e7727719d230 (patch)
tree088fc486cfb4026cc8f91fd734bc57ec54c2475b /service
parentb96dde171a8cdc5c1f5058caf376c6696c5f571c (diff)
parent1c3c829525be19bb14ae31a0bd978b7a1b0f00cd (diff)
Merge "SoftApManager: Use SoftApModeConfiguration consistently"
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/SoftApManager.java117
1 files changed, 60 insertions, 57 deletions
diff --git a/service/java/com/android/server/wifi/SoftApManager.java b/service/java/com/android/server/wifi/SoftApManager.java
index c6be91760..b02ec2402 100644
--- a/service/java/com/android/server/wifi/SoftApManager.java
+++ b/service/java/com/android/server/wifi/SoftApManager.java
@@ -84,8 +84,8 @@ public class SoftApManager implements ActiveModeManager {
private final WifiMetrics mWifiMetrics;
- private final int mMode;
- private WifiConfiguration mApConfig;
+ @NonNull
+ private SoftApModeConfiguration mApConfig;
private int mReportedFrequency = -1;
private int mReportedBandwidth = -1;
@@ -141,12 +141,10 @@ public class SoftApManager implements ActiveModeManager {
mCountryCode = countryCode;
mCallback = callback;
mWifiApConfigStore = wifiApConfigStore;
- mMode = apConfig.getTargetMode();
- WifiConfiguration config = apConfig.getWifiConfiguration();
- if (config == null) {
- mApConfig = mWifiApConfigStore.getApConfiguration();
- } else {
- mApConfig = config;
+ mApConfig = apConfig;
+ if (mApConfig.getWifiConfiguration() == null) {
+ WifiConfiguration wifiConfig = mWifiApConfigStore.getApConfiguration();
+ mApConfig = new SoftApModeConfiguration(mApConfig.getTargetMode(), wifiConfig);
}
mWifiMetrics = wifiMetrics;
mSarManager = sarManager;
@@ -155,10 +153,10 @@ public class SoftApManager implements ActiveModeManager {
}
/**
- * Start soft AP with the supplied config.
+ * Start soft AP, as configured in the constructor.
*/
public void start() {
- mStateMachine.sendMessage(SoftApStateMachine.CMD_START, mApConfig);
+ mStateMachine.sendMessage(SoftApStateMachine.CMD_START);
}
/**
@@ -183,7 +181,7 @@ public class SoftApManager implements ActiveModeManager {
}
public int getIpMode() {
- return mMode;
+ return mApConfig.getTargetMode();
}
/**
@@ -195,15 +193,12 @@ public class SoftApManager implements ActiveModeManager {
pw.println("current StateMachine mode: " + getCurrentStateName());
pw.println("mApInterfaceName: " + mApInterfaceName);
pw.println("mIfaceIsUp: " + mIfaceIsUp);
- pw.println("mMode: " + mMode);
pw.println("mSoftApCountryCode: " + mCountryCode);
- if (mApConfig != null) {
- pw.println("mApConfig.SSID: " + mApConfig.SSID);
- pw.println("mApConfig.apBand: " + mApConfig.apBand);
- pw.println("mApConfig.hiddenSSID: " + mApConfig.hiddenSSID);
- } else {
- pw.println("mApConfig: null");
- }
+ pw.println("mApConfig.targetMode: " + mApConfig.getTargetMode());
+ WifiConfiguration wifiConfig = mApConfig.getWifiConfiguration();
+ pw.println("mApConfig.wifiConfiguration.SSID: " + wifiConfig.SSID);
+ pw.println("mApConfig.wifiConfiguration.apBand: " + wifiConfig.apBand);
+ pw.println("mApConfig.wifiConfiguration.hiddenSSID: " + wifiConfig.hiddenSSID);
pw.println("mNumAssociatedStations: " + mNumAssociatedStations);
pw.println("mTimeoutEnabled: " + mTimeoutEnabled);
pw.println("mReportedFrequency: " + mReportedFrequency);
@@ -241,49 +236,59 @@ public class SoftApManager implements ActiveModeManager {
}
intent.putExtra(WifiManager.EXTRA_WIFI_AP_INTERFACE_NAME, mApInterfaceName);
- intent.putExtra(WifiManager.EXTRA_WIFI_AP_MODE, mMode);
+ intent.putExtra(WifiManager.EXTRA_WIFI_AP_MODE, mApConfig.getTargetMode());
mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
}
- /**
- * Start a soft AP instance with the given configuration.
- * @param config AP configuration
- * @return integer result code
- */
- private int startSoftAp(WifiConfiguration config) {
- if (config == null || config.SSID == null) {
- Log.e(TAG, "Unable to start soft AP without valid configuration");
- return ERROR_GENERIC;
- }
-
- Log.d(TAG, "band " + config.apBand + " iface "
- + mApInterfaceName + " country " + mCountryCode);
-
- // Setup country code
+ private int setCountryCode() {
+ int band = mApConfig.getWifiConfiguration().apBand;
if (TextUtils.isEmpty(mCountryCode)) {
- if (config.apBand == WifiConfiguration.AP_BAND_5GHZ) {
+ if (band == WifiConfiguration.AP_BAND_5GHZ) {
// Country code is mandatory for 5GHz band.
- Log.e(TAG, "Invalid country code, required for setting up "
- + "soft ap in 5GHz");
+ Log.e(TAG, "Invalid country code, required for setting up soft ap in 5GHz");
return ERROR_GENERIC;
}
// Absence of country code is not fatal for 2Ghz & Any band options.
- } else if (!mWifiNative.setCountryCodeHal(
+ return SUCCESS;
+ }
+
+ if (!mWifiNative.setCountryCodeHal(
mApInterfaceName, mCountryCode.toUpperCase(Locale.ROOT))) {
- if (config.apBand == WifiConfiguration.AP_BAND_5GHZ) {
+ if (band == WifiConfiguration.AP_BAND_5GHZ) {
// Return an error if failed to set country code when AP is configured for
// 5GHz band.
- Log.e(TAG, "Failed to set country code, required for setting up "
- + "soft ap in 5GHz");
+ 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.
}
+ return SUCCESS;
+ }
+
+ /**
+ * Start a soft AP instance as configured.
+ *
+ * @return integer result code
+ */
+ private int startSoftAp() {
+ WifiConfiguration config = mApConfig.getWifiConfiguration();
+ if (config == null || config.SSID == null) {
+ Log.e(TAG, "Unable to start soft AP without valid configuration");
+ return ERROR_GENERIC;
+ }
+
+ Log.d(TAG, "band " + config.apBand + " iface "
+ + mApInterfaceName + " country " + mCountryCode);
+
+ int result = setCountryCode();
+ if (result != SUCCESS) {
+ return result;
+ }
// Make a copy of configuration for updating AP band and channel.
WifiConfiguration localConfig = new WifiConfiguration(config);
- int result = ApConfigUtil.updateApChannelConfig(
+ result = ApConfigUtil.updateApChannelConfig(
mWifiNative, mCountryCode,
mWifiApConfigStore.getAllowed2GChannel(), localConfig);
@@ -389,7 +394,7 @@ public class SoftApManager implements ActiveModeManager {
}
updateApState(WifiManager.WIFI_AP_STATE_ENABLING,
WifiManager.WIFI_AP_STATE_DISABLED, 0);
- int result = startSoftAp((WifiConfiguration) message.obj);
+ int result = startSoftAp();
if (result != SUCCESS) {
int failureReason = WifiManager.SAP_START_FAILURE_GENERAL;
if (result == ERROR_NO_CHANNEL) {
@@ -491,8 +496,8 @@ public class SoftApManager implements ActiveModeManager {
} else {
Log.e(TAG, "SoftApCallback is null. Dropping NumClientsChanged event.");
}
- mWifiMetrics.addSoftApNumAssociatedStationsChangedEvent(mNumAssociatedStations,
- mMode);
+ mWifiMetrics.addSoftApNumAssociatedStationsChangedEvent(
+ mNumAssociatedStations, mApConfig.getTargetMode());
if (mNumAssociatedStations == 0) {
scheduleTimeoutMessage();
@@ -518,7 +523,7 @@ public class SoftApManager implements ActiveModeManager {
// the interface was up, but goes down
sendMessage(CMD_INTERFACE_DOWN);
}
- mWifiMetrics.addSoftApUpChangedEvent(isUp, mMode);
+ mWifiMetrics.addSoftApUpChangedEvent(isUp, mApConfig.getTargetMode());
}
@Override
@@ -559,7 +564,7 @@ public class SoftApManager implements ActiveModeManager {
cancelTimeoutMessage();
// Need this here since we are exiting |Started| state and won't handle any
// future CMD_INTERFACE_STATUS_CHANGED events after this point
- mWifiMetrics.addSoftApUpChangedEvent(false, mMode);
+ mWifiMetrics.addSoftApUpChangedEvent(false, mApConfig.getTargetMode());
updateApState(WifiManager.WIFI_AP_STATE_DISABLED,
WifiManager.WIFI_AP_STATE_DISABLING, 0);
@@ -571,14 +576,12 @@ public class SoftApManager implements ActiveModeManager {
}
private void updateUserBandPreferenceViolationMetricsIfNeeded() {
- boolean bandPreferenceViolated = false;
- if (mApConfig.apBand == WifiConfiguration.AP_BAND_2GHZ
- && ScanResult.is5GHz(mReportedFrequency)) {
- bandPreferenceViolated = true;
- } else if (mApConfig.apBand == WifiConfiguration.AP_BAND_5GHZ
- && ScanResult.is24GHz(mReportedFrequency)) {
- bandPreferenceViolated = true;
- }
+ int band = mApConfig.getWifiConfiguration().apBand;
+ boolean bandPreferenceViolated =
+ (band == WifiConfiguration.AP_BAND_2GHZ
+ && ScanResult.is5GHz(mReportedFrequency))
+ || (band == WifiConfiguration.AP_BAND_5GHZ
+ && ScanResult.is24GHz(mReportedFrequency));
if (bandPreferenceViolated) {
Log.e(TAG, "Channel does not satisfy user band preference: "
+ mReportedFrequency);
@@ -603,7 +606,7 @@ public class SoftApManager implements ActiveModeManager {
Log.d(TAG, "Channel switched. Frequency: " + mReportedFrequency
+ " Bandwidth: " + mReportedBandwidth);
mWifiMetrics.addSoftApChannelSwitchedEvent(mReportedFrequency,
- mReportedBandwidth, mMode);
+ mReportedBandwidth, mApConfig.getTargetMode());
updateUserBandPreferenceViolationMetricsIfNeeded();
break;
case CMD_TIMEOUT_TOGGLE_CHANGED: