From e5436af58ca25daef3f22d707346fb368238e69c Mon Sep 17 00:00:00 2001 From: lesl Date: Sat, 19 Dec 2020 23:53:59 +0800 Subject: wifi: Add callback onConnectedClientsOrInfoChanged handling Now service will only send onConnectedClientsOrInfoChanged to Manager side. Add callback handling to dispatch correct callback base on below scenarios. 1. onInfoChanged(SoftApInfo) will send when a. registration (non bridged) b. non bridged and info changed 2. onInfoChanged(List) will send when a. registration b. info changed 3. onConnectedClientsChanged(List) will send a. registration b. clients changed 4. onConnectedClientsChanged(SoftApInfo, List) will send a. when registration and client connected b. client changed on specific instance. It will also need to handle when info changed(dismisssed), it means that an instance shutdown. It needs to send empty list if previous instance has client connected. AP+AP Part 6 includes: Support dual SoftApInfo callback a. New callback onInfoChanged(List) & onConnectedClientsChanged(SoftApInfo, List) b. Callback refactoring c. Support shutdown idle instance in bridged mode Bug: 162686273 Bug: 175351193 Test: FrameworksWifiApiTests Test: Manual Test, check the log and check SystemUI to confirm clients update correctly. Change-Id: Id587125edbb1167f58bba6b50a708be12888490f --- wifi/java/android/net/wifi/WifiManager.java | 80 +++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 10 deletions(-) (limited to 'wifi/java') diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index b5baee5b42a6..d7fcd54c9534 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -4039,7 +4039,7 @@ public class WifiManager { * Note: this API is only valid when the Soft AP is configured as a single AP * - not as a bridged AP (2 Soft APs). When the Soft AP is configured as bridged AP * this callback will not be triggered - use the - * {@link #onInfoListChanged(List)} callback in bridged AP mode. + * {@link #onInfoChanged(List)} callback in bridged AP mode. * * @param softApInfo is the softap information. {@link SoftApInfo} */ @@ -4105,6 +4105,7 @@ public class WifiManager { private final Executor mExecutor; private final SoftApCallback mCallback; private Map> mCurrentClients = new HashMap<>(); + private Map mCurrentInfos = new HashMap<>(); private List getConnectedClientList(Map> clientsMap) { List connectedClientList = new ArrayList<>(); @@ -4132,22 +4133,81 @@ public class WifiManager { }); } - // TODO: b/175351193, integrate callbacks to simplify the logic. @Override public void onConnectedClientsOrInfoChanged(Map infos, Map> clients, boolean isBridged, boolean isRegistration) { if (mVerboseLoggingEnabled) { - Log.v(TAG, "SoftApCallbackProxy: onConnectedClientsChanged: clients=" - + clients + " infos" + infos + "isBridged is " + isBridged - + "isRegistration is " + isRegistration); + Log.v(TAG, "SoftApCallbackProxy: onConnectedClientsOrInfoChanged: clients: " + + clients + ", infos: " + infos + ", isBridged is " + isBridged + + ", isRegistration is " + isRegistration); + } + + List changedInfoList = new ArrayList<>(infos.values()); + Map> changedInfoClients = new HashMap<>(); + boolean isInfoChanged = infos.size() != mCurrentInfos.size(); + for (SoftApInfo info : mCurrentInfos.values()) { + String changedInstance = info.getApInstanceIdentifier(); + if (!changedInfoList.contains(info)) { + isInfoChanged = true; + if (mCurrentClients.getOrDefault(changedInstance, + Collections.emptyList()).size() > 0) { + Log.d(TAG, "SoftApCallbackProxy: info changed on client connected" + + " instance(Shut Down case)"); + //Here should notify client changed on old info + changedInfoClients.put(info, Collections.emptyList()); + } + } else { + // info doesn't change, check client list + List changedClientList = clients.getOrDefault( + changedInstance, Collections.emptyList()); + if (changedClientList.size() + != mCurrentClients + .getOrDefault(changedInstance, Collections.emptyList()).size()) { + // Here should notify client changed on new info(same as old info) + changedInfoClients.put(info, changedClientList); + Log.d(TAG, "SoftApCallbackProxy: client changed on " + info + + " list: " + changedClientList); + } + } + } + + if (!isInfoChanged && changedInfoClients.isEmpty() + && !isRegistration) { + Log.v(TAG, "SoftApCallbackProxy: No changed & Not Registration," + + " don't need to notify the client"); + return; } - // TODO: b/175351193 Now handle onConnectedClientsChanged in single AP mode first - boolean shouldSendOnConnectedClientsChanged = isRegistration - || (getConnectedClientList(mCurrentClients).size() - != getConnectedClientList(clients).size()); mCurrentClients = clients; + mCurrentInfos = infos; Binder.clearCallingIdentity(); - if (shouldSendOnConnectedClientsChanged) { + // Notify the clients changed first for old info shutdown case + for (SoftApInfo changedInfo : changedInfoClients.keySet()) { + Log.v(TAG, "send onConnectedClientsChanged, changedInfo is " + changedInfo); + mExecutor.execute(() -> { + mCallback.onConnectedClientsChanged( + changedInfo, changedInfoClients.get(changedInfo)); + }); + } + + if (isInfoChanged || isRegistration) { + if (!isBridged) { + SoftApInfo newInfo = changedInfoList.isEmpty() + ? new SoftApInfo() : changedInfoList.get(0); + Log.v(TAG, "SoftApCallbackProxy: send InfoChanged, newInfo: " + newInfo); + mExecutor.execute(() -> { + mCallback.onInfoChanged(newInfo); + }); + } + Log.v(TAG, "SoftApCallbackProxy: send InfoChanged, changedInfoList: " + + changedInfoList); + mExecutor.execute(() -> { + mCallback.onInfoChanged(changedInfoList); + }); + } + + if (isRegistration || !changedInfoClients.isEmpty()) { + Log.v(TAG, "SoftApCallbackProxy: send onConnectedClientsChanged(clients): " + + getConnectedClientList(clients)); mExecutor.execute(() -> { mCallback.onConnectedClientsChanged(getConnectedClientList(clients)); }); -- cgit v1.2.3-59-g8ed1b