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

Commit 7d6d9c00 authored by Irfan Sheriff's avatar Irfan Sheriff
Browse files

Initial support for concurrency

Use of multiple socket connections over wlan0 and p2p and
p2p state machine is now controlled entirely from wifi state machine

Add discovery stop to allow STA scans to proceed after p2p is used

Change-Id: I790c9112d3f475f638f06fc3ae9e191f6d90ef35
parent ea77ed02
Loading
Loading
Loading
Loading
+3 −9
Original line number Original line Diff line number Diff line
@@ -116,14 +116,9 @@ static jboolean android_net_wifi_unloadDriver(JNIEnv* env, jobject)
    return (jboolean)(::wifi_unload_driver() == 0);
    return (jboolean)(::wifi_unload_driver() == 0);
}
}


static jboolean android_net_wifi_startSupplicant(JNIEnv* env, jobject)
static jboolean android_net_wifi_startSupplicant(JNIEnv* env, jobject, jboolean p2pSupported)
{
{
    return (jboolean)(::wifi_start_supplicant() == 0);
    return (jboolean)(::wifi_start_supplicant(p2pSupported) == 0);
}

static jboolean android_net_wifi_startP2pSupplicant(JNIEnv* env, jobject)
{
    return (jboolean)(::wifi_start_p2p_supplicant() == 0);
}
}


static jboolean android_net_wifi_killSupplicant(JNIEnv* env, jobject)
static jboolean android_net_wifi_killSupplicant(JNIEnv* env, jobject)
@@ -207,8 +202,7 @@ static JNINativeMethod gWifiMethods[] = {
    { "loadDriver", "()Z",  (void *)android_net_wifi_loadDriver },
    { "loadDriver", "()Z",  (void *)android_net_wifi_loadDriver },
    { "isDriverLoaded", "()Z",  (void *)android_net_wifi_isDriverLoaded },
    { "isDriverLoaded", "()Z",  (void *)android_net_wifi_isDriverLoaded },
    { "unloadDriver", "()Z",  (void *)android_net_wifi_unloadDriver },
    { "unloadDriver", "()Z",  (void *)android_net_wifi_unloadDriver },
    { "startSupplicant", "()Z",  (void *)android_net_wifi_startSupplicant },
    { "startSupplicant", "(Z)Z",  (void *)android_net_wifi_startSupplicant },
    { "startP2pSupplicant", "()Z",  (void *)android_net_wifi_startP2pSupplicant },
    { "killSupplicant", "()Z",  (void *)android_net_wifi_killSupplicant },
    { "killSupplicant", "()Z",  (void *)android_net_wifi_killSupplicant },
    { "connectToSupplicant", "(Ljava/lang/String;)Z",
    { "connectToSupplicant", "(Ljava/lang/String;)Z",
            (void *)android_net_wifi_connectToSupplicant },
            (void *)android_net_wifi_connectToSupplicant },
+0 −8
Original line number Original line Diff line number Diff line
@@ -2696,11 +2696,6 @@
    <!-- Do not translate. Default access point SSID used for tethering -->
    <!-- Do not translate. Default access point SSID used for tethering -->
    <string name="wifi_tether_configure_ssid_default" translatable="false">AndroidAP</string>
    <string name="wifi_tether_configure_ssid_default" translatable="false">AndroidAP</string>


    <!-- Wi-Fi p2p dialog title-->
    <string name="wifi_p2p_dialog_title">Wi-Fi Direct</string>
    <string name="wifi_p2p_turnon_message">Start Wi-Fi Direct. This will turn off Wi-Fi client/hotspot.</string>
    <string name="wifi_p2p_failed_message">Couldn\'t start Wi-Fi Direct.</string>

    <string name="accept">Accept</string>
    <string name="accept">Accept</string>
    <string name="decline">Decline</string>
    <string name="decline">Decline</string>
    <string name="wifi_p2p_invitation_sent_title">Invitation sent</string>
    <string name="wifi_p2p_invitation_sent_title">Invitation sent</string>
@@ -2711,9 +2706,6 @@
    <string name="wifi_p2p_enter_pin_message">Type the required PIN: </string>
    <string name="wifi_p2p_enter_pin_message">Type the required PIN: </string>
    <string name="wifi_p2p_show_pin_message">PIN: </string>
    <string name="wifi_p2p_show_pin_message">PIN: </string>


    <string name="wifi_p2p_enabled_notification_title">Wi-Fi Direct is on</string>
    <string name="wifi_p2p_enabled_notification_message">Touch for settings</string>

    <!-- Name of the dialog that lets the user choose an accented character to insert -->
    <!-- Name of the dialog that lets the user choose an accented character to insert -->
    <string name="select_character">Insert character</string>
    <string name="select_character">Insert character</string>


+0 −11
Original line number Original line Diff line number Diff line
@@ -365,17 +365,6 @@ public class WifiMonitor {
                } else if (event == DRIVER_STATE) {
                } else if (event == DRIVER_STATE) {
                    handleDriverEvent(eventData);
                    handleDriverEvent(eventData);
                } else if (event == TERMINATING) {
                } else if (event == TERMINATING) {
                    /**
                     * If monitor socket is closed, we have already
                     * stopped the supplicant, simply exit the monitor thread
                     */
                    if (eventData.startsWith(MONITOR_SOCKET_CLOSED_STR)) {
                        if (false) {
                            Log.d(TAG, "Monitor socket is closed, exiting thread");
                        }
                        break;
                    }

                    /**
                    /**
                     * Close the supplicant connection if we see
                     * Close the supplicant connection if we see
                     * too many recv errors
                     * too many recv errors
+11 −3
Original line number Original line Diff line number Diff line
@@ -39,6 +39,8 @@ import java.util.List;
 */
 */
public class WifiNative {
public class WifiNative {


    private static final boolean DBG = false;
    private final String mTAG;
    private static final int DEFAULT_GROUP_OWNER_INTENT = 7;
    private static final int DEFAULT_GROUP_OWNER_INTENT = 7;


    static final int BLUETOOTH_COEXISTENCE_MODE_ENABLED = 0;
    static final int BLUETOOTH_COEXISTENCE_MODE_ENABLED = 0;
@@ -53,9 +55,7 @@ public class WifiNative {


    public native static boolean unloadDriver();
    public native static boolean unloadDriver();


    public native static boolean startSupplicant();
    public native static boolean startSupplicant(boolean p2pSupported);

    public native static boolean startP2pSupplicant();


    /* Sends a kill signal to supplicant. To be used when we have lost connection
    /* Sends a kill signal to supplicant. To be used when we have lost connection
       or when the supplicant is hung */
       or when the supplicant is hung */
@@ -79,6 +79,7 @@ public class WifiNative {


    public WifiNative(String iface) {
    public WifiNative(String iface) {
        mInterface = iface;
        mInterface = iface;
        mTAG = "WifiNative-" + iface;
    }
    }


    public boolean connectToSupplicant() {
    public boolean connectToSupplicant() {
@@ -94,14 +95,17 @@ public class WifiNative {
    }
    }


    private boolean doBooleanCommand(String command) {
    private boolean doBooleanCommand(String command) {
        if (DBG) Log.d(mTAG, "doBoolean: " + command);
        return doBooleanCommand(mInterface, command);
        return doBooleanCommand(mInterface, command);
    }
    }


    private int doIntCommand(String command) {
    private int doIntCommand(String command) {
        if (DBG) Log.d(mTAG, "doInt: " + command);
        return doIntCommand(mInterface, command);
        return doIntCommand(mInterface, command);
    }
    }


    private String doStringCommand(String command) {
    private String doStringCommand(String command) {
        if (DBG) Log.d(mTAG, "doString: " + command);
        return doStringCommand(mInterface, command);
        return doStringCommand(mInterface, command);
    }
    }


@@ -437,6 +441,10 @@ public class WifiNative {
        return doBooleanCommand("P2P_FIND " + timeout);
        return doBooleanCommand("P2P_FIND " + timeout);
    }
    }


    public boolean p2pStopFind() {
       return doBooleanCommand("P2P_STOP_FIND");
    }

    public boolean p2pListen() {
    public boolean p2pListen() {
        return doBooleanCommand("P2P_LISTEN");
        return doBooleanCommand("P2P_LISTEN");
    }
    }
+16 −71
Original line number Original line Diff line number Diff line
@@ -45,6 +45,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.ConnectivityManager;
import android.net.DhcpInfo;
import android.net.DhcpInfo;
import android.net.DhcpInfoInternal;
import android.net.DhcpInfoInternal;
@@ -118,6 +119,8 @@ public class WifiStateMachine extends StateMachine {
    private INetworkManagementService mNwService;
    private INetworkManagementService mNwService;
    private ConnectivityManager mCm;
    private ConnectivityManager mCm;


    private final boolean mP2pSupported;

    /* Scan results handling */
    /* Scan results handling */
    private List<ScanResult> mScanResults;
    private List<ScanResult> mScanResults;
    private static final Pattern scanResultPattern = Pattern.compile("\t+");
    private static final Pattern scanResultPattern = Pattern.compile("\t+");
@@ -361,9 +364,9 @@ public class WifiStateMachine extends StateMachine {
    /* Reset the WPS state machine */
    /* Reset the WPS state machine */
    static final int CMD_RESET_WPS_STATE                  = BASE + 122;
    static final int CMD_RESET_WPS_STATE                  = BASE + 122;


    /* Interaction with WifiP2pService */
    /* P2p commands */
    public static final int WIFI_ENABLE_PENDING           = BASE + 131;
    public static final int CMD_ENABLE_P2P                = BASE + 131;
    public static final int P2P_ENABLE_PROCEED            = BASE + 132;
    public static final int CMD_DISABLE_P2P               = BASE + 132;


    private static final int CONNECT_MODE   = 1;
    private static final int CONNECT_MODE   = 1;
    private static final int SCAN_ONLY_MODE = 2;
    private static final int SCAN_ONLY_MODE = 2;
@@ -482,9 +485,6 @@ public class WifiStateMachine extends StateMachine {
    /* Waiting for untether confirmation to stop soft Ap */
    /* Waiting for untether confirmation to stop soft Ap */
    private State mSoftApStoppingState = new SoftApStoppingState();
    private State mSoftApStoppingState = new SoftApStoppingState();


    /* Wait till p2p is disabled */
    private State mWaitForP2pDisableState = new WaitForP2pDisableState();

    private class TetherStateChange {
    private class TetherStateChange {
        ArrayList<String> available;
        ArrayList<String> available;
        ArrayList<String> active;
        ArrayList<String> active;
@@ -556,6 +556,9 @@ public class WifiStateMachine extends StateMachine {
        IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
        IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
        mNwService = INetworkManagementService.Stub.asInterface(b);
        mNwService = INetworkManagementService.Stub.asInterface(b);


        mP2pSupported = mContext.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_WIFI_DIRECT);

        mWifiNative = new WifiNative(mInterfaceName);
        mWifiNative = new WifiNative(mInterfaceName);
        mWifiConfigStore = new WifiConfigStore(context, mWifiNative);
        mWifiConfigStore = new WifiConfigStore(context, mWifiNative);
        mWifiMonitor = new WifiMonitor(this, mWifiNative);
        mWifiMonitor = new WifiMonitor(this, mWifiNative);
@@ -639,7 +642,6 @@ public class WifiStateMachine extends StateMachine {
                addState(mTetheringState, mSoftApStartedState);
                addState(mTetheringState, mSoftApStartedState);
                addState(mTetheredState, mSoftApStartedState);
                addState(mTetheredState, mSoftApStartedState);
            addState(mSoftApStoppingState, mDefaultState);
            addState(mSoftApStoppingState, mDefaultState);
            addState(mWaitForP2pDisableState, mDefaultState);


        setInitialState(mInitialState);
        setInitialState(mInitialState);


@@ -1892,11 +1894,6 @@ public class WifiStateMachine extends StateMachine {
                    mReplyChannel.replyToMessage(message, WifiManager.CMD_WPS_COMPLETED,
                    mReplyChannel.replyToMessage(message, WifiManager.CMD_WPS_COMPLETED,
                                new WpsResult(Status.FAILURE));
                                new WpsResult(Status.FAILURE));
                    break;
                    break;
                case WifiP2pService.P2P_ENABLE_PENDING:
                    // turn off wifi and defer to be handled in DriverUnloadedState
                    setWifiEnabled(false);
                    deferMessage(message);
                    break;
                default:
                default:
                    loge("Error! unhandled message" + message);
                    loge("Error! unhandled message" + message);
                    break;
                    break;
@@ -2056,7 +2053,7 @@ public class WifiStateMachine extends StateMachine {
                        loge("Unable to change interface settings: " + ie);
                        loge("Unable to change interface settings: " + ie);
                    }
                    }


                    if(mWifiNative.startSupplicant()) {
                    if(mWifiNative.startSupplicant(mP2pSupported)) {
                        if (DBG) log("Supplicant start successful");
                        if (DBG) log("Supplicant start successful");
                        mWifiMonitor.startMonitoring();
                        mWifiMonitor.startMonitoring();
                        transitionTo(mSupplicantStartingState);
                        transitionTo(mSupplicantStartingState);
@@ -2168,11 +2165,7 @@ public class WifiStateMachine extends StateMachine {
            if (DBG) log(getName() + message.toString() + "\n");
            if (DBG) log(getName() + message.toString() + "\n");
            switch (message.what) {
            switch (message.what) {
                case CMD_LOAD_DRIVER:
                case CMD_LOAD_DRIVER:
                    mWifiP2pChannel.sendMessage(WIFI_ENABLE_PENDING);
                    transitionTo(mDriverLoadingState);
                    transitionTo(mWaitForP2pDisableState);
                    break;
                case WifiP2pService.P2P_ENABLE_PENDING:
                    mReplyChannel.replyToMessage(message, P2P_ENABLE_PROCEED);
                    break;
                    break;
                default:
                default:
                    return NOT_HANDLED;
                    return NOT_HANDLED;
@@ -2549,6 +2542,8 @@ public class WifiStateMachine extends StateMachine {
                mWifiNative.status();
                mWifiNative.status();
                transitionTo(mDisconnectedState);
                transitionTo(mDisconnectedState);
            }
            }

            if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_ENABLE_P2P);
        }
        }
        @Override
        @Override
        public boolean processMessage(Message message) {
        public boolean processMessage(Message message) {
@@ -2668,6 +2663,8 @@ public class WifiStateMachine extends StateMachine {
            mIsRunning = false;
            mIsRunning = false;
            updateBatteryWorkSource(null);
            updateBatteryWorkSource(null);
            mScanResults = null;
            mScanResults = null;

            if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_DISABLE_P2P);
        }
        }
    }
    }


@@ -3341,7 +3338,6 @@ public class WifiStateMachine extends StateMachine {
                case CMD_START_PACKET_FILTERING:
                case CMD_START_PACKET_FILTERING:
                case CMD_STOP_PACKET_FILTERING:
                case CMD_STOP_PACKET_FILTERING:
                case CMD_TETHER_STATE_CHANGE:
                case CMD_TETHER_STATE_CHANGE:
                case WifiP2pService.P2P_ENABLE_PENDING:
                    deferMessage(message);
                    deferMessage(message);
                    break;
                    break;
                case WifiStateMachine.CMD_RESPONSE_AP_CONFIG:
                case WifiStateMachine.CMD_RESPONSE_AP_CONFIG:
@@ -3405,55 +3401,6 @@ public class WifiStateMachine extends StateMachine {
                        transitionTo(mTetheringState);
                        transitionTo(mTetheringState);
                    }
                    }
                    break;
                    break;
                case WifiP2pService.P2P_ENABLE_PENDING:
                    // turn of soft Ap and defer to be handled in DriverUnloadedState
                    setWifiApEnabled(null, false);
                    deferMessage(message);
                    break;
                default:
                    return NOT_HANDLED;
            }
            EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
            return HANDLED;
        }
    }

    class WaitForP2pDisableState extends State {
        private int mSavedArg;
        @Override
        public void enter() {
            if (DBG) log(getName() + "\n");
            EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());

            //Preserve the argument arg1 that has information used in DriverLoadingState
            mSavedArg = getCurrentMessage().arg1;
        }
        @Override
        public boolean processMessage(Message message) {
            if (DBG) log(getName() + message.toString() + "\n");
            switch(message.what) {
                case WifiP2pService.WIFI_ENABLE_PROCEED:
                    //restore argument from original message (CMD_LOAD_DRIVER)
                    message.arg1 = mSavedArg;
                    transitionTo(mDriverLoadingState);
                    break;
                case CMD_LOAD_DRIVER:
                case CMD_UNLOAD_DRIVER:
                case CMD_START_SUPPLICANT:
                case CMD_STOP_SUPPLICANT:
                case CMD_START_AP:
                case CMD_STOP_AP:
                case CMD_START_DRIVER:
                case CMD_STOP_DRIVER:
                case CMD_SET_SCAN_MODE:
                case CMD_SET_SCAN_TYPE:
                case CMD_SET_HIGH_PERF_MODE:
                case CMD_SET_COUNTRY_CODE:
                case CMD_SET_FREQUENCY_BAND:
                case CMD_START_PACKET_FILTERING:
                case CMD_STOP_PACKET_FILTERING:
                    deferMessage(message);
                    break;
                default:
                default:
                    return NOT_HANDLED;
                    return NOT_HANDLED;
            }
            }
@@ -3503,7 +3450,6 @@ public class WifiStateMachine extends StateMachine {
                case CMD_SET_FREQUENCY_BAND:
                case CMD_SET_FREQUENCY_BAND:
                case CMD_START_PACKET_FILTERING:
                case CMD_START_PACKET_FILTERING:
                case CMD_STOP_PACKET_FILTERING:
                case CMD_STOP_PACKET_FILTERING:
                case WifiP2pService.P2P_ENABLE_PENDING:
                    deferMessage(message);
                    deferMessage(message);
                    break;
                    break;
                default:
                default:
@@ -3599,7 +3545,6 @@ public class WifiStateMachine extends StateMachine {
                case CMD_SET_FREQUENCY_BAND:
                case CMD_SET_FREQUENCY_BAND:
                case CMD_START_PACKET_FILTERING:
                case CMD_START_PACKET_FILTERING:
                case CMD_STOP_PACKET_FILTERING:
                case CMD_STOP_PACKET_FILTERING:
                case WifiP2pService.P2P_ENABLE_PENDING:
                    deferMessage(message);
                    deferMessage(message);
                    break;
                    break;
                default:
                default:
Loading