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

Commit e4c56c96 authored by Irfan Sheriff's avatar Irfan Sheriff
Browse files

Fix WPS to provides immediate feedback

If WPS is already active, we drop user's request
and convey an in progress message

If WPS fails to start, a failure indication is conveyed
to the user

Bug: 3316078
Change-Id: I238c55973cb29cf5c1be66197ffcb4978316cb89
parent c69d5f3b
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.net.wifi.WifiConfiguration;
import android.net.wifi.SupplicantState;
import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.WpsConfiguration;
import android.net.wifi.WpsResult;
import android.net.ConnectivityManager;
import android.net.InterfaceConfiguration;
import android.net.DhcpInfo;
@@ -841,13 +842,13 @@ public class WifiService extends IWifiManager.Stub {
        mWifiStateMachine.forgetNetwork(netId);
    }

    public String startWps(WpsConfiguration config) {
    public WpsResult startWps(WpsConfiguration config) {
        enforceChangePermission();
        if (mChannel != null) {
            return mWifiStateMachine.startWps(mChannel, config);
        } else {
            Slog.e(TAG, "mChannel is not initialized");
            return "";
            return new WpsResult(WpsResult.Status.FAILURE);
        }
    }

+2 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.net.wifi;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WpsConfiguration;
import android.net.wifi.WpsResult;
import android.net.wifi.ScanResult;
import android.net.DhcpInfo;

@@ -109,6 +110,6 @@ interface IWifiManager

    void forgetNetwork(int networkId);

    String startWps(in WpsConfiguration config);
    WpsResult startWps(in WpsConfiguration config);
}
+22 −14
Original line number Diff line number Diff line
@@ -370,44 +370,52 @@ class WifiConfigStore {
     * Start WPS pin method configuration with pin obtained
     * from the access point
     */
    static boolean startWpsWithPinFromAccessPoint(WpsConfiguration config) {
    static WpsResult startWpsWithPinFromAccessPoint(WpsConfiguration config) {
        WpsResult result = new WpsResult();
        if (WifiNative.startWpsWithPinFromAccessPointCommand(config.BSSID, config.pin)) {
            /* WPS leaves all networks disabled */
            markAllNetworksDisabled();
            return true;
        }
            result.status = WpsResult.Status.SUCCESS;
        } else {
            Log.e(TAG, "Failed to start WPS pin method configuration");
        return false;
            result.status = WpsResult.Status.FAILURE;
        }
        return result;
    }

    /**
     * Start WPS pin method configuration with pin obtained
     * from the device
     * @return empty string on failure. null is never returned.
     * @return WpsResult indicating status and pin
     */
    static String startWpsWithPinFromDevice(WpsConfiguration config) {
        String pin = WifiNative.startWpsWithPinFromDeviceCommand(config.BSSID);
    static WpsResult startWpsWithPinFromDevice(WpsConfiguration config) {
        WpsResult result = new WpsResult();
        result.pin = WifiNative.startWpsWithPinFromDeviceCommand(config.BSSID);
        /* WPS leaves all networks disabled */
        if (!TextUtils.isEmpty(pin)) {
        if (!TextUtils.isEmpty(result.pin)) {
            markAllNetworksDisabled();
            result.status = WpsResult.Status.SUCCESS;
        } else {
            Log.e(TAG, "Failed to start WPS pin method configuration");
            pin = "";
            result.status = WpsResult.Status.FAILURE;
        }
        return pin;
        return result;
    }

    /**
     * Start WPS push button configuration
     */
    static boolean startWpsPbc(WpsConfiguration config) {
    static WpsResult startWpsPbc(WpsConfiguration config) {
        WpsResult result = new WpsResult();
        if (WifiNative.startWpsPbcCommand(config.BSSID)) {
            /* WPS leaves all networks disabled */
            markAllNetworksDisabled();
            return true;
        }
            result.status = WpsResult.Status.SUCCESS;
        } else {
            Log.e(TAG, "Failed to start WPS push button configuration");
        return false;
            result.status = WpsResult.Status.FAILURE;
        }
        return result;
    }

    /**
+3 −3
Original line number Diff line number Diff line
@@ -1074,15 +1074,15 @@ public class WifiManager {
     * Start Wi-fi Protected Setup
     *
     * @param config WPS configuration
     * @return pin generated by device, if any
     * @return WpsResult containing pin and status
     * @hide
     * TODO: with use of AsyncChannel, return value should go away
     */
    public String startWps(WpsConfiguration config) {
    public WpsResult startWps(WpsConfiguration config) {
        try {
            return mService.startWps(config);
        } catch (RemoteException e) {
            return null;
            return new WpsResult(WpsResult.Status.FAILURE);
        }
    }

+16 −14
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo.DetailedState;
import android.net.LinkProperties;
import android.net.wifi.NetworkUpdateResult;
import android.net.wifi.WpsResult.Status;
import android.os.Binder;
import android.os.Message;
import android.os.IBinder;
@@ -302,10 +303,11 @@ public class WifiStateMachine extends HierarchicalStateMachine {
    /* Reset the supplicant state tracker */
    static final int CMD_RESET_SUPPLICANT_STATE           = 111;


    /* Commands/events reported by WpsStateMachine */
    /* Indicates the completion of WPS activity */
    static final int WPS_COMPLETED_EVENT                  = 121;
    /* Reset the WPS state machine */
    static final int CMD_RESET_WPS_STATE                  = 122;

    private static final int CONNECT_MODE   = 1;
    private static final int SCAN_ONLY_MODE = 2;
@@ -793,18 +795,19 @@ public class WifiStateMachine extends HierarchicalStateMachine {
        sendMessage(obtainMessage(CMD_FORGET_NETWORK, netId, 0));
    }

    public String startWps(AsyncChannel channel, WpsConfiguration config) {
        String result = null;
    public WpsResult startWps(AsyncChannel channel, WpsConfiguration config) {
        WpsResult result;
        switch (config.setup) {
            case PIN_FROM_DEVICE:
            case PBC:
            case PIN_FROM_ACCESS_POINT:
                //TODO: will go away with AsyncChannel use from settings
                Message resultMsg = channel.sendMessageSynchronously(CMD_START_WPS, config);
                result = (String) resultMsg.obj;
                result = (WpsResult) resultMsg.obj;
                resultMsg.recycle();
                break;
            case PBC:
            case PIN_FROM_ACCESS_POINT:
                sendMessage(obtainMessage(CMD_START_WPS, config));
            default:
                result = new WpsResult(Status.FAILURE);
                break;
        }
        return result;
@@ -1511,13 +1514,9 @@ public class WifiStateMachine extends HierarchicalStateMachine {
                case CMD_ENABLE_ALL_NETWORKS:
                    break;
                case CMD_START_WPS:
                    WpsConfiguration config = (WpsConfiguration) message.obj;
                    switch (config.setup) {
                        case PIN_FROM_DEVICE:
                            String pin = "";
                            mReplyChannel.replyToMessage(message, message.what, pin);
                            break;
                    }
                    /* Return failure when the state machine cannot handle WPS initiation*/
                    mReplyChannel.replyToMessage(message, message.what,
                                new WpsResult(Status.FAILURE));
                    break;
                default:
                    Log.e(TAG, "Error! unhandled message" + message);
@@ -1803,6 +1802,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
                    /* Reset the supplicant state to indicate the supplicant
                     * state is not known at this time */
                    mSupplicantStateTracker.sendMessage(CMD_RESET_SUPPLICANT_STATE);
                    mWpsStateMachine.sendMessage(CMD_RESET_WPS_STATE);
                    /* Initialize data structures */
                    mLastBssid = null;
                    mLastNetworkId = -1;
@@ -1884,6 +1884,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
                    setWifiState(WIFI_STATE_DISABLING);
                    sendSupplicantConnectionChangedBroadcast(false);
                    mSupplicantStateTracker.sendMessage(CMD_RESET_SUPPLICANT_STATE);
                    mWpsStateMachine.sendMessage(CMD_RESET_WPS_STATE);
                    transitionTo(mSupplicantStoppingState);
                    break;
                case SUP_DISCONNECTION_EVENT:  /* Supplicant connection lost */
@@ -1894,6 +1895,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
                    handleNetworkDisconnect();
                    sendSupplicantConnectionChangedBroadcast(false);
                    mSupplicantStateTracker.sendMessage(CMD_RESET_SUPPLICANT_STATE);
                    mWpsStateMachine.sendMessage(CMD_RESET_WPS_STATE);
                    transitionTo(mDriverLoadedState);
                    sendMessageDelayed(CMD_START_SUPPLICANT, SUPPLICANT_RESTART_INTERVAL_MSECS);
                    break;
Loading