summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorlesl <lesl@google.com>2019-12-27 17:53:49 +0800
committerLes Lee <lesl@google.com>2020-01-10 08:35:21 +0000
commit066601945d79a3d312348e053431c39d93a5d4ed (patch)
treeed7b59214e336b31bcecd732ec0a2d2335ad0e54 /service
parent754475229c25766f0278b410b3f364a86049f531 (diff)
softap: Add timeoutdelay customize and config update support.
1. Add timeoutdelay customize support. 2. Add config update support Bug: 142752869 Test: atest frameworks/opt/net/wifi/tests/wifitests/ Test: Manual Test, fake shutdown timout configuration change to force configuration update. Checked the log and UI behavior. Change-Id: I7ef086b5115111892450b8c67840c58049e0a167
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/ActiveModeWarden.java18
-rw-r--r--service/java/com/android/server/wifi/SoftApManager.java89
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java1
-rw-r--r--service/java/com/android/server/wifi/util/ApConfigUtil.java16
-rw-r--r--service/res/values/config.xml7
-rw-r--r--service/res/values/overlayable.xml2
6 files changed, 98 insertions, 35 deletions
diff --git a/service/java/com/android/server/wifi/ActiveModeWarden.java b/service/java/com/android/server/wifi/ActiveModeWarden.java
index f3f261c43..ae14ca795 100644
--- a/service/java/com/android/server/wifi/ActiveModeWarden.java
+++ b/service/java/com/android/server/wifi/ActiveModeWarden.java
@@ -26,6 +26,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.location.LocationManager;
import android.net.wifi.SoftApCapability;
+import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiManager;
import android.os.BatteryStatsManager;
import android.os.Handler;
@@ -176,6 +177,11 @@ public class ActiveModeWarden {
mWifiController.sendMessage(WifiController.CMD_UPDATE_AP_CAPABILITY, capability);
}
+ /** Update SoftAp Configuration. */
+ public void updateSoftApConfiguration(SoftApConfiguration config) {
+ mWifiController.sendMessage(WifiController.CMD_UPDATE_AP_CONFIG, config);
+ }
+
/** Emergency Callback Mode has changed. */
public void emergencyCallbackModeChanged(boolean isInEmergencyCallbackMode) {
mWifiController.sendMessage(
@@ -308,6 +314,14 @@ public class ActiveModeWarden {
}
}
+ private void updateConfigurationToSoftApModeManager(SoftApConfiguration config) {
+ for (ActiveModeManager manager : mActiveModeManagers) {
+ if (!(manager instanceof SoftApManager)) continue;
+ SoftApManager softApManager = (SoftApManager) manager;
+ softApManager.updateConfiguration(config);
+ }
+ }
+
/**
* Method to enable a new client mode manager.
*/
@@ -550,6 +564,7 @@ public class ActiveModeWarden {
static final int CMD_DEFERRED_RECOVERY_RESTART_WIFI = BASE + 22;
static final int CMD_AP_START_FAILURE = BASE + 23;
static final int CMD_UPDATE_AP_CAPABILITY = BASE + 24;
+ static final int CMD_UPDATE_AP_CONFIG = BASE + 25;
private final EnabledState mEnabledState = new EnabledState();
private final DisabledState mDisabledState = new DisabledState();
@@ -710,6 +725,9 @@ public class ActiveModeWarden {
case CMD_UPDATE_AP_CAPABILITY:
updateCapabilityToSoftApModeManager((SoftApCapability) msg.obj);
break;
+ case CMD_UPDATE_AP_CONFIG:
+ updateConfigurationToSoftApModeManager((SoftApConfiguration) msg.obj);
+ break;
default:
throw new RuntimeException("WifiController.handleMessage " + msg.what);
}
diff --git a/service/java/com/android/server/wifi/SoftApManager.java b/service/java/com/android/server/wifi/SoftApManager.java
index 58c7f7e09..742a3d05d 100644
--- a/service/java/com/android/server/wifi/SoftApManager.java
+++ b/service/java/com/android/server/wifi/SoftApManager.java
@@ -70,9 +70,6 @@ import java.util.Locale;
public class SoftApManager implements ActiveModeManager {
private static final String TAG = "SoftApManager";
- // Minimum limit to use for timeout delay if the value from overlay setting is too small.
- private static final int MIN_SOFT_AP_TIMEOUT_DELAY_MS = 600_000; // 10 minutes
-
@VisibleForTesting
public static final String SOFT_AP_SEND_MESSAGE_TIMEOUT_TAG = TAG
+ " Soft AP Send Message Timeout";
@@ -96,6 +93,8 @@ public class SoftApManager implements ActiveModeManager {
private final WifiMetrics mWifiMetrics;
+ private boolean mIsRandomizeBssid;
+
@NonNull
private SoftApModeConfiguration mApConfig;
@@ -173,6 +172,7 @@ public class SoftApManager implements ActiveModeManager {
// may still be null if we fail to load the default config
}
if (softApConfig != null) {
+ mIsRandomizeBssid = softApConfig.getBssid() == null;
softApConfig = mWifiApConfigStore.randomizeBssidIfUnset(mContext, softApConfig);
}
mApConfig = new SoftApModeConfiguration(apConfig.getTargetMode(),
@@ -232,6 +232,16 @@ public class SoftApManager implements ActiveModeManager {
}
/**
+ * Update AP configuration. Called when setting update config via
+ * {@link WifiManager#setSoftApConfiguration(SoftApConfiguration)}
+ *
+ * @param config new AP config.
+ */
+ public void updateConfiguration(@NonNull SoftApConfiguration config) {
+ mStateMachine.sendMessage(SoftApStateMachine.CMD_UPDATE_CONFIG, config);
+ }
+
+ /**
* Dump info about this softap manager.
*/
@Override
@@ -452,6 +462,7 @@ public class SoftApManager implements ActiveModeManager {
public static final int CMD_INTERFACE_DOWN = 8;
public static final int CMD_SOFT_AP_CHANNEL_SWITCHED = 9;
public static final int CMD_UPDATE_CAPABILITY = 10;
+ public static final int CMD_UPDATE_CONFIG = 11;
private final State mIdleState = new IdleState();
private final State mStartedState = new StartedState();
@@ -542,6 +553,11 @@ public class SoftApManager implements ActiveModeManager {
mCurrentSoftApCapability = new SoftApCapability(capability);
}
break;
+ case CMD_UPDATE_CONFIG:
+ SoftApConfiguration newConfig = (SoftApConfiguration) message.obj;
+ mApConfig = new SoftApModeConfiguration(mApConfig.getTargetMode(),
+ newConfig, mCurrentSoftApCapability);
+ break;
default:
// Ignore all other commands.
break;
@@ -552,7 +568,6 @@ public class SoftApManager implements ActiveModeManager {
}
private class StartedState extends State {
- private int mTimeoutDelay;
private WakeupMessage mSoftApTimeoutMessage;
private SoftApTimeoutEnabledSettingObserver mSettingObserver;
@@ -589,23 +604,20 @@ public class SoftApManager implements ActiveModeManager {
}
}
- private int getConfigSoftApTimeoutDelay() {
- int delay = mContext.getResources().getInteger(
- R.integer.config_wifi_framework_soft_ap_timeout_delay);
- if (delay < MIN_SOFT_AP_TIMEOUT_DELAY_MS) {
- delay = MIN_SOFT_AP_TIMEOUT_DELAY_MS;
- Log.w(TAG, "Overriding timeout delay with minimum limit value");
- }
- Log.d(TAG, "Timeout delay: " + delay);
- return delay;
- }
-
private void scheduleTimeoutMessage() {
- if (!mTimeoutEnabled) {
+ if (!mTimeoutEnabled || mConnectedClients.size() != 0) {
+ cancelTimeoutMessage();
return;
}
- mSoftApTimeoutMessage.schedule(SystemClock.elapsedRealtime() + mTimeoutDelay);
- Log.d(TAG, "Timeout message scheduled");
+ int timeout = mApConfig.getSoftApConfiguration().getShutdownTimeoutMillis();
+ if (timeout == 0) {
+ timeout = mContext.getResources().getInteger(
+ R.integer.config_wifiFrameworkSoftApShutDownTimeoutMilliseconds);
+ }
+ mSoftApTimeoutMessage.schedule(SystemClock.elapsedRealtime()
+ + timeout);
+ Log.d(TAG, "Timeout message scheduled, delay = "
+ + timeout);
}
private void cancelTimeoutMessage() {
@@ -689,11 +701,7 @@ public class SoftApManager implements ActiveModeManager {
mWifiMetrics.addSoftApNumAssociatedStationsChangedEvent(
mConnectedClients.size(), mApConfig.getTargetMode());
- if (mConnectedClients.size() == 0) {
- scheduleTimeoutMessage();
- } else {
- cancelTimeoutMessage();
- }
+ scheduleTimeoutMessage();
}
private void setSoftApChannel(int freq, @WifiAnnotations.Bandwidth int apBandwidth) {
@@ -745,7 +753,6 @@ public class SoftApManager implements ActiveModeManager {
mIfaceIsDestroyed = false;
onUpChanged(mWifiNative.isInterfaceUp(mApInterfaceName));
- mTimeoutDelay = getConfigSoftApTimeoutDelay();
Handler handler = mStateMachine.getHandler();
mSoftApTimeoutMessage = new WakeupMessage(mContext, handler,
SOFT_AP_SEND_MESSAGE_TIMEOUT_TAG,
@@ -852,12 +859,7 @@ public class SoftApManager implements ActiveModeManager {
break;
}
mTimeoutEnabled = isEnabled;
- if (!mTimeoutEnabled) {
- cancelTimeoutMessage();
- }
- if (mTimeoutEnabled && mConnectedClients.size() == 0) {
- scheduleTimeoutMessage();
- }
+ scheduleTimeoutMessage();
break;
case CMD_INTERFACE_STATUS_CHANGED:
boolean isUp = message.arg1 == 1;
@@ -909,6 +911,33 @@ public class SoftApManager implements ActiveModeManager {
updateClientConnection();
}
break;
+ case CMD_UPDATE_CONFIG:
+ SoftApConfiguration newConfig = (SoftApConfiguration) message.obj;
+ SoftApConfiguration currentConfig = mApConfig.getSoftApConfiguration();
+ if (mIsRandomizeBssid) {
+ // Current bssid is ramdon because unset. Set back to null..
+ currentConfig = new SoftApConfiguration.Builder(currentConfig)
+ .setBssid(null)
+ .build();
+ }
+ if (!ApConfigUtil.checkConfigurationChangeNeedToRestart(
+ currentConfig, newConfig)) {
+ Log.d(TAG, "Configuration changed to " + newConfig);
+ boolean needRescheduleTimer =
+ mApConfig.getSoftApConfiguration().getShutdownTimeoutMillis()
+ != newConfig.getShutdownTimeoutMillis();
+ mApConfig = new SoftApModeConfiguration(mApConfig.getTargetMode(),
+ newConfig, mCurrentSoftApCapability);
+ updateClientConnection();
+ if (needRescheduleTimer) {
+ cancelTimeoutMessage();
+ scheduleTimeoutMessage();
+ }
+ } else {
+ Log.d(TAG, "Ignore the config: " + newConfig
+ + " update since it requires restart");
+ }
+ break;
default:
return NOT_HANDLED;
}
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index 2bf5f473e..eb8a50227 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -1786,6 +1786,7 @@ public class WifiServiceImpl extends BaseWifiService {
mLog.info("setSoftApConfiguration uid=%").c(uid).flush();
if (softApConfig == null) return false;
if (WifiApConfigStore.validateApWifiConfiguration(softApConfig)) {
+ mActiveModeWarden.updateSoftApConfiguration(softApConfig);
mWifiThreadRunner.post(() -> mWifiApConfigStore.setApConfiguration(softApConfig));
return true;
} else {
diff --git a/service/java/com/android/server/wifi/util/ApConfigUtil.java b/service/java/com/android/server/wifi/util/ApConfigUtil.java
index 467327613..45d3a9a12 100644
--- a/service/java/com/android/server/wifi/util/ApConfigUtil.java
+++ b/service/java/com/android/server/wifi/util/ApConfigUtil.java
@@ -530,4 +530,20 @@ public class ApConfigUtil {
return context.getResources().getBoolean(
R.bool.config_wifi_softap_sae_supported);
}
+
+ /**
+ * Helper function for comparing two SoftApConfiguration.
+ *
+ * Return true if the difference between the two configurations requires a restart to apply.
+ */
+ public static boolean checkConfigurationChangeNeedToRestart(
+ SoftApConfiguration currentConfig, SoftApConfiguration newConfig) {
+ return currentConfig.getSsid() != newConfig.getSsid()
+ || currentConfig.getBssid() != newConfig.getBssid()
+ || currentConfig.getSecurityType() != newConfig.getSecurityType()
+ || currentConfig.getPassphrase() != newConfig.getPassphrase()
+ || currentConfig.isHiddenSsid() != newConfig.isHiddenSsid()
+ || currentConfig.getBand() != newConfig.getBand()
+ || currentConfig.getChannel() != newConfig.getChannel();
+ }
}
diff --git a/service/res/values/config.xml b/service/res/values/config.xml
index 98a005e6d..2ba4e6a88 100644
--- a/service/res/values/config.xml
+++ b/service/res/values/config.xml
@@ -122,10 +122,9 @@
<integer translatable="false" name="config_wifiFrameworkScoreGoodRssiThreshold6ghz">-57</integer>
<!-- Integer delay in milliseconds before shutting down soft AP when there
- are no connected devices. Framework will enforce a minimum limit on
- this value and this setting will be overridden if the provided value is
- smaller than the limit. -->
- <integer translatable="false" name="config_wifi_framework_soft_ap_timeout_delay">600000</integer>
+ are no connected devices. -->
+ <integer translatable="false" name="config_wifiFrameworkSoftApShutDownTimeoutMilliseconds">600000</integer>
+
<!-- Integer indicating maximum hardware supported client number of soft ap -->
<integer translatable="false" name="config_wifiHardwareSoftapMaxClientCount">16</integer>
diff --git a/service/res/values/overlayable.xml b/service/res/values/overlayable.xml
index 7d63b3448..9d70aa9d8 100644
--- a/service/res/values/overlayable.xml
+++ b/service/res/values/overlayable.xml
@@ -54,7 +54,7 @@
<item type="integer" name="config_wifiFrameworkScoreEntryRssiThreshold6ghz" />
<item type="integer" name="config_wifiFrameworkScoreLowRssiThreshold6ghz" />
<item type="integer" name="config_wifiFrameworkScoreGoodRssiThreshold6ghz" />
- <item type="integer" name="config_wifi_framework_soft_ap_timeout_delay" />
+ <item type="integer" name="config_wifiFrameworkSoftApShutDownTimeoutMilliseconds" />
<item type="string" name="config_wifi_random_mac_oui" />
<item type="string" name="config_wifiSoftap2gChannelList" />
<item type="string" name="config_wifiSoftap5gChannelList" />