From dfdf77373982a9b3da32784b3705ef713f4fd2c8 Mon Sep 17 00:00:00 2001 From: lesl Date: Mon, 22 Jun 2020 12:51:42 +0800 Subject: wifi: Use overlay to control reset SAP configration during restoring The AOSP setting(UI) doesn't support several SAP configration. ex: Channel selection, hidden network option, autoShutDown timer selection etc... Once those UI depends features config are restored from cloud. It will causes User use wrong config and it can't modify anymore. Bug: 159572880 Bug: 159325231 Test: atest FrameworksWifiTests Change-Id: I7a6bf855fbb08a4808af5f166e5354f4bf67e4cd --- .../com/android/server/wifi/WifiApConfigStore.java | 77 +++++++++++++++++----- service/res/values/config.xml | 15 ++++- service/res/values/overlayable.xml | 4 ++ 3 files changed, 76 insertions(+), 20 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/WifiApConfigStore.java b/service/java/com/android/server/wifi/WifiApConfigStore.java index 961cbbd3b..eb2b11245 100644 --- a/service/java/com/android/server/wifi/WifiApConfigStore.java +++ b/service/java/com/android/server/wifi/WifiApConfigStore.java @@ -153,10 +153,13 @@ public class WifiApConfigStore { /** * Returns SoftApConfiguration in which some parameters might be reset to supported default - * config. + * config since it depends on UI or HW. * - * MaxNumberOfClients and setClientControlByUserEnabled will need HAL support client force - * disconnect. Reset to default when device doesn't support it. + * MaxNumberOfClients and isClientControlByUserEnabled will need HAL support client force + * disconnect, and Band setting (5g/6g) need HW support. + * + * HiddenSsid, Channel, ShutdownTimeoutMillis and AutoShutdownEnabled are features + * which need UI(Setting) support. * * SAE/SAE-Transition need hardware support, reset to secured WPA2 security type when device * doesn't support it. @@ -164,15 +167,20 @@ public class WifiApConfigStore { public SoftApConfiguration resetToDefaultForUnsupportedConfig( @NonNull SoftApConfiguration config) { SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder(config); - if (!ApConfigUtil.isClientForceDisconnectSupported(mContext)) { - configBuilder.setMaxNumberOfClients(0); + if ((!ApConfigUtil.isClientForceDisconnectSupported(mContext) + || mContext.getResources().getBoolean( + R.bool.config_wifiSoftapResetUserControlConfig)) + && config.isClientControlByUserEnabled()) { configBuilder.setClientControlByUserEnabled(false); - if (config.getMaxNumberOfClients() != 0) { - Log.e(TAG, "Reset MaxNumberOfClients to 0 due to device doesn't support"); - } - if (config.isClientControlByUserEnabled()) { - Log.e(TAG, "Reset ClientControlByUser to false due to device doesn't support"); - } + Log.i(TAG, "Reset ClientControlByUser to false due to device doesn't support"); + } + + if ((!ApConfigUtil.isClientForceDisconnectSupported(mContext) + || mContext.getResources().getBoolean( + R.bool.config_wifiSoftapResetMaxClientSettingConfig)) + && config.getMaxNumberOfClients() != 0) { + configBuilder.setMaxNumberOfClients(0); + Log.i(TAG, "Reset MaxNumberOfClients to 0 due to device doesn't support"); } if (!ApConfigUtil.isWpa3SaeSupported(mContext) && (config.getSecurityType() @@ -181,18 +189,51 @@ public class WifiApConfigStore { == SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION)) { configBuilder.setPassphrase(generatePassword(), SoftApConfiguration.SECURITY_TYPE_WPA2_PSK); - Log.e(TAG, "Device doesn't support WPA3-SAE, reset config to WPA2"); + Log.i(TAG, "Device doesn't support WPA3-SAE, reset config to WPA2"); } - if (mContext.getResources().getBoolean(R.bool.config_wifiSoftapResetChannelConfig)) { + if (mContext.getResources().getBoolean(R.bool.config_wifiSoftapResetChannelConfig) + && config.getChannel() != 0) { // The device might not support customize channel or forced channel might not // work in some countries. Need to reset it. - if (config.getChannel() != 0) { - // Add 2.4G by default - configBuilder.setBand(SoftApConfiguration.BAND_2GHZ | config.getBand()); - Log.i(TAG, "Reset SAP channel configuration"); - } + // Add 2.4G by default + configBuilder.setBand(config.getBand() | SoftApConfiguration.BAND_2GHZ); + Log.i(TAG, "Reset SAP channel configuration"); + } + + int newBand = config.getBand(); + if (!mContext.getResources().getBoolean(R.bool.config_wifi6ghzSupport) + && (newBand & SoftApConfiguration.BAND_6GHZ) != 0) { + newBand &= ~SoftApConfiguration.BAND_6GHZ; + Log.i(TAG, "Device doesn't support 6g, remove 6G band from band setting"); } + + if (!mContext.getResources().getBoolean(R.bool.config_wifi5ghzSupport) + && (newBand & SoftApConfiguration.BAND_5GHZ) != 0) { + newBand &= ~SoftApConfiguration.BAND_5GHZ; + Log.i(TAG, "Device doesn't support 5g, remove 5G band from band setting"); + } + + if (newBand != config.getBand()) { + // Always added 2.4G by default when reset the band. + Log.i(TAG, "Reset band from " + config.getBand() + " to " + + (newBand | SoftApConfiguration.BAND_2GHZ)); + configBuilder.setBand(newBand | SoftApConfiguration.BAND_2GHZ); + } + + if (mContext.getResources().getBoolean(R.bool.config_wifiSoftapResetHiddenConfig) + && config.isHiddenSsid()) { + configBuilder.setHiddenSsid(false); + Log.i(TAG, "Reset SAP Hidden Network configuration"); + } + + if (mContext.getResources().getBoolean( + R.bool.config_wifiSoftapResetAutoShutdownTimerConfig) + && config.getShutdownTimeoutMillis() != 0) { + configBuilder.setShutdownTimeoutMillis(0); + Log.i(TAG, "Reset SAP auto shutdown configuration"); + } + mWifiMetrics.noteSoftApConfigReset(config, configBuilder.build()); return configBuilder.build(); } diff --git a/service/res/values/config.xml b/service/res/values/config.xml index 7e35eed19..4ea23adc0 100644 --- a/service/res/values/config.xml +++ b/service/res/values/config.xml @@ -133,13 +133,24 @@ are no connected devices. --> 600000 - 16 - + true + + true + + + true + + + true + + + true + diff --git a/service/res/values/overlayable.xml b/service/res/values/overlayable.xml index bf96fde62..b02eb9e77 100644 --- a/service/res/values/overlayable.xml +++ b/service/res/values/overlayable.xml @@ -58,6 +58,10 @@ + + + + -- cgit v1.2.3 From e81be4c68c3d0bd693dc42220a95f61aa01ba559 Mon Sep 17 00:00:00 2001 From: lesl Date: Mon, 22 Jun 2020 16:22:44 +0800 Subject: wifi: Support blocked list when ClientControlEnabled is false Control whether framework should disconnect a new/unknown client(MAC) initially or not based on the ClientControlEnabled flag. ClientControlEnabled (false) -> New/unknown Clients will be allowed to connect initially i.e. framework will not blindly disconnect a new client. Framework will instead only provide a callback notification about new client connection. Clients would be disconnected only after user action i.e. user decides to adds the new client to Blocklist This avoids unnecessarily client disconnect in the case user chooses *not* to add client to Blocklist. ClientControlEnabled (true) -> New/unknown Clients will *not* be allowed to connect initially until user approval i.e. framework will disconnect the new client and provide callback notification about new client connection. Clients would be allowed (next attempt) only after user/setting approves the new client to be added to "allow list". Impact: No impact for ClientControlEnabled is enable. No impact for non-supported client control feature device because it will check overlay config: OFTAP_FEATURE_CLIENT_FORCE_DISCONNECT, i.e. No impact with Pixel. Bug: 159582750 Test: atest FrameworksWifiTests Change-Id: I1c8fdbcdbacfb1bca418584bf7480192dc0a9951 --- .../com/android/server/wifi/SoftApManager.java | 44 +++++++++++----------- .../com/android/server/wifi/WifiApConfigStore.java | 5 ++- .../com/android/server/wifi/util/ApConfigUtil.java | 3 +- 3 files changed, 29 insertions(+), 23 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/SoftApManager.java b/service/java/com/android/server/wifi/SoftApManager.java index f9720477b..ffbb388cc 100644 --- a/service/java/com/android/server/wifi/SoftApManager.java +++ b/service/java/com/android/server/wifi/SoftApManager.java @@ -469,12 +469,17 @@ public class SoftApManager implements ActiveModeManager { return true; } + if (mBlockedClientList.contains(newClient.getMacAddress())) { + Log.d(TAG, "Force disconnect for client: " + newClient + "in blocked list"); + mWifiNative.forceClientDisconnect( + mApInterfaceName, newClient.getMacAddress(), + WifiManager.SAP_CLIENT_BLOCK_REASON_CODE_BLOCKED_BY_USER); + return false; + } if (config.isClientControlByUserEnabled() && !mAllowedClientList.contains(newClient.getMacAddress())) { - if (!mBlockedClientList.contains(newClient.getMacAddress())) { - mSoftApCallback.onBlockedClientConnecting(newClient, - WifiManager.SAP_CLIENT_BLOCK_REASON_CODE_BLOCKED_BY_USER); - } + mSoftApCallback.onBlockedClientConnecting(newClient, + WifiManager.SAP_CLIENT_BLOCK_REASON_CODE_BLOCKED_BY_USER); Log.d(TAG, "Force disconnect for unauthorized client: " + newClient); mWifiNative.forceClientDisconnect( mApInterfaceName, newClient.getMacAddress(), @@ -667,25 +672,22 @@ public class SoftApManager implements ActiveModeManager { } int targetDisconnectClientNumber = mConnectedClients.size() - finalMaxClientCount; List allowedConnectedList = new ArrayList<>(); - if (mApConfig.getSoftApConfiguration().isClientControlByUserEnabled()) { - // Check allow list first - Iterator iterator = mConnectedClients.iterator(); - while (iterator.hasNext()) { - WifiClient client = iterator.next(); - if (mAllowedClientList.contains(client.getMacAddress())) { - allowedConnectedList.add(client); - } else { - Log.d(TAG, "Force disconnect for not allowed client: " + client); - mWifiNative.forceClientDisconnect( - mApInterfaceName, client.getMacAddress(), - WifiManager - .SAP_CLIENT_BLOCK_REASON_CODE_BLOCKED_BY_USER); - targetDisconnectClientNumber--; - } + Iterator iterator = mConnectedClients.iterator(); + while (iterator.hasNext()) { + WifiClient client = iterator.next(); + if (mBlockedClientList.contains(client.getMacAddress()) + || (mApConfig.getSoftApConfiguration().isClientControlByUserEnabled() + && !mAllowedClientList.contains(client.getMacAddress()))) { + Log.d(TAG, "Force disconnect for not allowed client: " + client); + mWifiNative.forceClientDisconnect( + mApInterfaceName, client.getMacAddress(), + WifiManager.SAP_CLIENT_BLOCK_REASON_CODE_BLOCKED_BY_USER); + targetDisconnectClientNumber--; + } else { + allowedConnectedList.add(client); } - } else { - allowedConnectedList = new ArrayList<>(mConnectedClients); } + if (targetDisconnectClientNumber > 0) { Iterator allowedClientIterator = allowedConnectedList.iterator(); while (allowedClientIterator.hasNext()) { diff --git a/service/java/com/android/server/wifi/WifiApConfigStore.java b/service/java/com/android/server/wifi/WifiApConfigStore.java index eb2b11245..3de99711b 100644 --- a/service/java/com/android/server/wifi/WifiApConfigStore.java +++ b/service/java/com/android/server/wifi/WifiApConfigStore.java @@ -33,6 +33,7 @@ import com.android.wifi.resources.R; import java.nio.charset.StandardCharsets; import java.security.SecureRandom; +import java.util.ArrayList; import java.util.Random; import javax.annotation.Nullable; @@ -170,8 +171,10 @@ public class WifiApConfigStore { if ((!ApConfigUtil.isClientForceDisconnectSupported(mContext) || mContext.getResources().getBoolean( R.bool.config_wifiSoftapResetUserControlConfig)) - && config.isClientControlByUserEnabled()) { + && (config.isClientControlByUserEnabled() + || config.getBlockedClientList().size() != 0)) { configBuilder.setClientControlByUserEnabled(false); + configBuilder.setBlockedClientList(new ArrayList<>()); Log.i(TAG, "Reset ClientControlByUser to false due to device doesn't support"); } diff --git a/service/java/com/android/server/wifi/util/ApConfigUtil.java b/service/java/com/android/server/wifi/util/ApConfigUtil.java index b385369a7..39d0df5f5 100644 --- a/service/java/com/android/server/wifi/util/ApConfigUtil.java +++ b/service/java/com/android/server/wifi/util/ApConfigUtil.java @@ -529,7 +529,8 @@ public class ApConfigUtil { SoftApCapability capability) { if (!capability.areFeaturesSupported( SoftApCapability.SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT) - && (config.getMaxNumberOfClients() != 0 || config.isClientControlByUserEnabled())) { + && (config.getMaxNumberOfClients() != 0 || config.isClientControlByUserEnabled() + || config.getBlockedClientList().size() != 0)) { Log.d(TAG, "Error, Client control requires HAL support"); return false; } -- cgit v1.2.3