diff options
author | lesl <lesl@google.com> | 2019-12-04 16:29:49 +0800 |
---|---|---|
committer | lesl <lesl@google.com> | 2019-12-10 15:05:03 +0800 |
commit | 82297e81b711504ffdae34c237edf921d967f3d1 (patch) | |
tree | dc65e035f5a1da35b1286aa305b6f037ead2923c /service | |
parent | fcd87af28d921bba79f2a0c4e818945682fb772c (diff) |
SoftAp: Revise callback onConnectedClientsChanged
New feature: Client control, i.e. MaxClient and Black/White List,
need to check client to decide allow it connect or force it disconnect.
Revise callback to 1 by 1, let framework accumulate the total number
of softap client.
Bug: 142752869
Test: Manual
Test: atest frameworks/opt/net/wifi/tests/wifitests/
Change-Id: Ifa91d4016b6f682aedd64dc259f9b6d54bda6289
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/SoftApManager.java | 56 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WificondControl.java | 13 |
2 files changed, 45 insertions, 24 deletions
diff --git a/service/java/com/android/server/wifi/SoftApManager.java b/service/java/com/android/server/wifi/SoftApManager.java index 7585bd4c8..4a80088d6 100644 --- a/service/java/com/android/server/wifi/SoftApManager.java +++ b/service/java/com/android/server/wifi/SoftApManager.java @@ -123,9 +123,13 @@ public class SoftApManager implements ActiveModeManager { } @Override - public void onConnectedClientsChanged(List<NativeWifiClient> clients) { - mStateMachine.sendMessage(SoftApStateMachine.CMD_ASSOCIATED_STATIONS_CHANGED, - clients); + public void onConnectedClientsChanged(NativeWifiClient client, boolean isConnected) { + if (client != null) { + mStateMachine.sendMessage(SoftApStateMachine.CMD_ASSOCIATED_STATIONS_CHANGED, + isConnected ? 1 : 0, 0, client); + } else { + Log.e(TAG, "onConnectedClientsChanged: Invalid type returned"); + } } @Override @@ -546,19 +550,25 @@ public class SoftApManager implements ActiveModeManager { * Set stations associated with this soft AP * @param clients The connected stations */ - private void setConnectedClients(List<NativeWifiClient> clients) { - if (clients == null) { + private void updateConnectedClients(WifiClient client, boolean isConnected) { + if (client == null) { return; } - List<WifiClient> convertedClients = createWifiClients(clients); - if (mConnectedClients.equals(convertedClients)) { + int index = mConnectedClients.indexOf(client); + if ((index != -1) == isConnected) { + Log.e(TAG, "Duplicate client updated event, client " + + client + "isConnected: " + isConnected); return; } + if (isConnected) { + mConnectedClients.add(client); + } else { + mConnectedClients.remove(index); + } - mConnectedClients = new ArrayList<>(convertedClients); Log.d(TAG, "The connected wifi stations have changed with count: " - + clients.size() + ": " + convertedClients); + + mConnectedClients.size() + ": " + mConnectedClients); if (mSoftApCallback != null) { mSoftApCallback.onConnectedClientsChanged(mConnectedClients); @@ -684,7 +694,7 @@ public class SoftApManager implements ActiveModeManager { mSarManager.setSapWifiState(WifiManager.WIFI_AP_STATE_ENABLED); Log.d(TAG, "Resetting connected clients on start"); - mConnectedClients = new ArrayList<>(); + mConnectedClients.clear(); scheduleTimeoutMessage(); } @@ -698,7 +708,14 @@ public class SoftApManager implements ActiveModeManager { mSettingObserver.unregister(); } Log.d(TAG, "Resetting num stations on stop"); - setConnectedClients(new ArrayList<>()); + if (mConnectedClients.size() != 0) { + mConnectedClients.clear(); + if (mSoftApCallback != null) { + mSoftApCallback.onConnectedClientsChanged(mConnectedClients); + } + mWifiMetrics.addSoftApNumAssociatedStationsChangedEvent( + 0, mApConfig.getTargetMode()); + } cancelTimeoutMessage(); // Need this here since we are exiting |Started| state and won't handle any @@ -735,15 +752,22 @@ public class SoftApManager implements ActiveModeManager { public boolean processMessage(Message message) { switch (message.what) { case CMD_ASSOCIATED_STATIONS_CHANGED: - if (!(message.obj instanceof List)) { + if (!(message.obj instanceof NativeWifiClient)) { Log.e(TAG, "Invalid type returned for" + " CMD_ASSOCIATED_STATIONS_CHANGED"); break; } - - Log.d(TAG, "Setting connected stations on" - + " CMD_ASSOCIATED_STATIONS_CHANGED"); - setConnectedClients((List<NativeWifiClient>) message.obj); + NativeWifiClient nativeClient = (NativeWifiClient) message.obj; + boolean isConnected = (message.arg1 == 1); + if (nativeClient != null && nativeClient.macAddress != null) { + MacAddress clientMacAddress = + MacAddress.fromBytes(nativeClient.macAddress); + WifiClient client = new WifiClient(clientMacAddress); + Log.d(TAG, "CMD_ASSOCIATED_STATIONS_CHANGED, Client: " + + clientMacAddress.toString() + " isConnected: " + isConnected); + // TODO : client check here before call updateConnectedClients + updateConnectedClients(client, isConnected); + } break; case CMD_SOFT_AP_CHANNEL_SWITCHED: if (message.arg1 < 0) { diff --git a/service/java/com/android/server/wifi/WificondControl.java b/service/java/com/android/server/wifi/WificondControl.java index 2c8d1ac0c..968a286df 100644 --- a/service/java/com/android/server/wifi/WificondControl.java +++ b/service/java/com/android/server/wifi/WificondControl.java @@ -53,7 +53,6 @@ import com.android.server.wifi.wificond.SingleScanSettings; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -165,7 +164,7 @@ public class WificondControl implements IBinder.DeathRecipient { /** * Invoked when the associated stations changes. */ - void onConnectedClientsChanged(List<NativeWifiClient> clients); + void onConnectedClientsChanged(NativeWifiClient client, boolean isConnected); /** * Invoked when the channel switch event happens. @@ -284,15 +283,13 @@ public class WificondControl implements IBinder.DeathRecipient { } @Override - public void onConnectedClientsChanged(NativeWifiClient[] clients) { + public void onConnectedClientsChanged(NativeWifiClient client, boolean isConnected) { if (mVerboseLoggingEnabled) { - Log.d(TAG, "onConnectedClientsChanged called with " + clients.length + " clients"); - for (int i = 0; i < clients.length; i++) { - Log.d(TAG, " mac " + clients[i].macAddress); - } + Log.d(TAG, "onConnectedClientsChanged called with " + + client.macAddress + " isConnected: " + isConnected); } - mSoftApListener.onConnectedClientsChanged(Arrays.asList(clients)); + mSoftApListener.onConnectedClientsChanged(client, isConnected); } @Override |