Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5436af5 authored by lesl's avatar lesl
Browse files

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<WifiClient>) will send  a. registration b. clients changed
4. onConnectedClientsChanged(SoftApInfo, List<WifiClient>) 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<SoftApInfo>) &
      onConnectedClientsChanged(SoftApInfo, List<WifiClient>)
   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
parent 54028c11
Loading
Loading
Loading
Loading
+70 −10
Original line number Diff line number Diff line
@@ -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<SoftApInfo>)} callback in bridged AP mode.
         * {@link #onInfoChanged(List<SoftApInfo>)} 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<String, List<WifiClient>> mCurrentClients = new HashMap<>();
        private Map<String, SoftApInfo> mCurrentInfos = new HashMap<>();

        private List<WifiClient> getConnectedClientList(Map<String, List<WifiClient>> clientsMap) {
            List<WifiClient> connectedClientList = new ArrayList<>();
@@ -4132,22 +4133,81 @@ public class WifiManager {
            });
        }

        // TODO: b/175351193, integrate callbacks to simplify the logic.
        @Override
        public void onConnectedClientsOrInfoChanged(Map<String, SoftApInfo> infos,
                Map<String, List<WifiClient>> clients, boolean isBridged, boolean isRegistration) {
            if (mVerboseLoggingEnabled) {
                Log.v(TAG, "SoftApCallbackProxy: onConnectedClientsChanged: clients="
                        + clients + " infos" + infos + "isBridged is " + isBridged
                        + "isRegistration is " + isRegistration);
            }
            // TODO: b/175351193 Now handle onConnectedClientsChanged in single AP mode first
            boolean shouldSendOnConnectedClientsChanged = isRegistration
                    || (getConnectedClientList(mCurrentClients).size()
                    != getConnectedClientList(clients).size());
                Log.v(TAG, "SoftApCallbackProxy: onConnectedClientsOrInfoChanged: clients: "
                        + clients + ", infos: " + infos + ", isBridged is " + isBridged
                        + ", isRegistration is " + isRegistration);
            }

            List<SoftApInfo> changedInfoList = new ArrayList<>(infos.values());
            Map<SoftApInfo, List<WifiClient>> 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<WifiClient> 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;
            }
            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));
                });
+302 −48

File changed.

Preview size limit exceeded, changes collapsed.