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

Commit b2416132 authored by Les Lee's avatar Les Lee Committed by Android (Google) Code Review
Browse files

Merge changes from topic "bridged_AP_callback"

* changes:
  wifi: Add callback onConnectedClientsOrInfoChanged handling
  wifi: Add new callback to support use case in bridged mode
parents cf749b91 e5436af5
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -639,8 +639,9 @@ package android.net.wifi {
    method public default void onBlockedClientConnecting(@NonNull android.net.wifi.WifiClient, int);
    method public default void onCapabilityChanged(@NonNull android.net.wifi.SoftApCapability);
    method public default void onConnectedClientsChanged(@NonNull java.util.List<android.net.wifi.WifiClient>);
    method public default void onConnectedClientsChanged(@NonNull android.net.wifi.SoftApInfo, @NonNull java.util.List<android.net.wifi.WifiClient>);
    method public default void onInfoChanged(@NonNull android.net.wifi.SoftApInfo);
    method public default void onInfoListChanged(@NonNull java.util.List<android.net.wifi.SoftApInfo>);
    method public default void onInfoChanged(@NonNull java.util.List<android.net.wifi.SoftApInfo>);
    method public default void onStateChanged(int, int);
  }

+7 −16
Original line number Diff line number Diff line
@@ -39,26 +39,17 @@ oneway interface ISoftApCallback
     */
    void onStateChanged(int state, int failureReason);

    /**
     * Service to manager callback providing connected client's information.
     *
     * @param clients the currently connected clients
     */
    void onConnectedClientsChanged(in List<WifiClient> clients);

    /**
     * Service to manager callback providing information of softap.
     *
     * @param softApInfo is the softap information. {@link SoftApInfo}
     */
    void onInfoChanged(in SoftApInfo softApInfo);

    /**
     * Service to manager callback providing informations of softap.
     *
     * @param softApInfoList is the list of the softap informations. {@link SoftApInfo}
     * @param infos The currently {@link SoftApInfo} in each AP instance.
     * @param clients The currently connected clients in each AP instance.
     * @param isBridged whether or not the current AP enabled on bridged mode.
     * @param isRegistration whether or not the callbackk was triggered when register.
     */
    void onInfoListChanged(in List<SoftApInfo> softApInfoList);
    void onConnectedClientsOrInfoChanged(in Map<String, SoftApInfo> infos,
            in Map<String, List<WifiClient>> clients, boolean isBridged,
	    boolean isRegistration);

    /**
     * Service to manager callback providing capability of softap.
+117 −28
Original line number Diff line number Diff line
@@ -4026,13 +4026,33 @@ public class WifiManager {
         */
        default void onConnectedClientsChanged(@NonNull List<WifiClient> clients) {}


        /**
         * Called when the connected clients for a soft AP instance change.
         *
         * When the Soft AP is configured in single AP mode, this callback is invoked
         * with the same {@link SoftApInfo} for all connected clients changes.
         * When the Soft AP is configured in bridged mode, this callback is invoked with
         * the corresponding {@link SoftApInfo} for the instance in which the connected clients
         * changed.
         *
         * Use {@link #onConnectedClientsChanged(List<WifiClient>)} if you don't care about
         * the mapping from SoftApInfo instance to connected clients.
         *
         * @param info The {@link SoftApInfo} of the AP.
         * @param clients The currently connected clients on the AP instance specified by
         *                {@code info}.
         */
        default void onConnectedClientsChanged(@NonNull SoftApInfo info,
                @NonNull List<WifiClient> clients) {}

        /**
         * Called when information of softap changes.
         *
         * 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}
         */
@@ -4050,11 +4070,15 @@ public class WifiManager {
         * as a single AP, and two information elements will be returned in the list
         * when the Soft AP is configured in bridged mode.
         *
         * Note: One of the Soft APs may be shut down independently of the other by the framework,
         * for instance if no devices are connected to it for some duration.
         * In that case, one information element will be returned in the list in bridged mode.
         *
         * See {@link #isBridgedApConcurrencySupported()} for the detail of the bridged AP.
         *
         * @param softApInfoList is the list of the softap information elements. {@link SoftApInfo}
         */
        default void onInfoListChanged(@NonNull List<SoftApInfo> softApInfoList) {
        default void onInfoChanged(@NonNull List<SoftApInfo> softApInfoList) {
            // Do nothing: can be updated to add SoftApInfo details (e.g. channel) to the UI.
        }

@@ -4093,6 +4117,16 @@ public class WifiManager {
    private class SoftApCallbackProxy extends ISoftApCallback.Stub {
        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<>();
            for (List<WifiClient> it : clientsMap.values()) {
                connectedClientList.addAll(it);
            }
            return connectedClientList;
        }

        SoftApCallbackProxy(Executor executor, SoftApCallback callback) {
            mExecutor = executor;
@@ -4113,42 +4147,85 @@ public class WifiManager {
        }

        @Override
        public void onConnectedClientsChanged(List<WifiClient> clients) {
        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.size() + " clients");
                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();
            // 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(clients);
                    mCallback.onConnectedClientsChanged(
                            changedInfo, changedInfoClients.get(changedInfo));
                });
            }

        @Override
        public void onInfoChanged(SoftApInfo softApInfo) {
            if (mVerboseLoggingEnabled) {
                Log.v(TAG, "SoftApCallbackProxy: onInfoChange: softApInfo=" + softApInfo);
            }

            Binder.clearCallingIdentity();
            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(softApInfo);
                        mCallback.onInfoChanged(newInfo);
                    });
                }

        @Override
        public void onInfoListChanged(List<SoftApInfo> softApInfoList) {
            if (mVerboseLoggingEnabled) {
                Log.v(TAG, "SoftApCallbackProxy: onInfoListChange: softApInfoList="
                        + softApInfoList);
                Log.v(TAG, "SoftApCallbackProxy: send InfoChanged, changedInfoList: "
                        + changedInfoList);
                mExecutor.execute(() -> {
                    mCallback.onInfoChanged(changedInfoList);
                });
            }

            Binder.clearCallingIdentity();
            if (isRegistration || !changedInfoClients.isEmpty()) {
                Log.v(TAG, "SoftApCallbackProxy: send onConnectedClientsChanged(clients): "
                        + getConnectedClientList(clients));
                mExecutor.execute(() -> {
                mCallback.onInfoListChanged(softApInfoList);
                    mCallback.onConnectedClientsChanged(getConnectedClientList(clients));
                });
            }
        }

        @Override
        public void onCapabilityChanged(SoftApCapability capability) {
@@ -4184,8 +4261,20 @@ public class WifiManager {
     * <li> {@link SoftApCallback#onStateChanged(int, int)}</li>
     * <li> {@link SoftApCallback#onConnectedClientsChanged(List<WifiClient>)}</li>
     * <li> {@link SoftApCallback#onInfoChanged(SoftApInfo)}</li>
     * <li> {@link SoftApCallback#onInfoChanged(List<SoftApInfo>)}</li>
     * <li> {@link SoftApCallback#onCapabilityChanged(SoftApCapability)}</li>
     * </ul>
     *
     * Use {@link SoftApCallback#onConnectedClientsChanged(List<WifiClient>)} to know if there are
     * any clients connected to any of the bridged instances of this AP (if bridged AP is enabled).
     * Use {@link SoftApCallback#onConnectedClientsChanged(SoftApInfo, List<WifiClient>)} to know
     * if there are any clients connected to a specific bridged instance of this AP
     * (if bridged AP is enabled).
     *
     * Note: Caller will receive the callback
     * {@link SoftApCallback#onConnectedClientsChangedWithApInfo(SoftApInfo, List<WifiClient>)}
     * on registration when there are clients connected to AP.
     *
     * These will be dispatched on registration to provide the caller with the current state
     * (and are not an indication of any current change). Note that receiving an immediate
     * WIFI_AP_STATE_FAILED value for soft AP state indicates that the latest attempt to start
+301 −34

File changed.

Preview size limit exceeded, changes collapsed.