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

Commit 870084d2 authored by Irfan Sheriff's avatar Irfan Sheriff Committed by Android (Google) Code Review
Browse files

Merge "Initial support for concurrency"

parents e4104b83 7d6d9c00
Loading
Loading
Loading
Loading
+3 −9
Original line number Diff line number Diff line
@@ -116,14 +116,9 @@ static jboolean android_net_wifi_unloadDriver(JNIEnv* env, jobject)
    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);
}

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

static jboolean android_net_wifi_killSupplicant(JNIEnv* env, jobject)
@@ -207,8 +202,7 @@ static JNINativeMethod gWifiMethods[] = {
    { "loadDriver", "()Z",  (void *)android_net_wifi_loadDriver },
    { "isDriverLoaded", "()Z",  (void *)android_net_wifi_isDriverLoaded },
    { "unloadDriver", "()Z",  (void *)android_net_wifi_unloadDriver },
    { "startSupplicant", "()Z",  (void *)android_net_wifi_startSupplicant },
    { "startP2pSupplicant", "()Z",  (void *)android_net_wifi_startP2pSupplicant },
    { "startSupplicant", "(Z)Z",  (void *)android_net_wifi_startSupplicant },
    { "killSupplicant", "()Z",  (void *)android_net_wifi_killSupplicant },
    { "connectToSupplicant", "(Ljava/lang/String;)Z",
            (void *)android_net_wifi_connectToSupplicant },
+0 −8
Original line number Diff line number Diff line
@@ -2708,11 +2708,6 @@
    <!-- Do not translate. Default access point SSID used for tethering -->
    <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="decline">Decline</string>
    <string name="wifi_p2p_invitation_sent_title">Invitation sent</string>
@@ -2723,9 +2718,6 @@
    <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_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 -->
    <string name="select_character">Insert character</string>

+0 −11
Original line number Diff line number Diff line
@@ -365,17 +365,6 @@ public class WifiMonitor {
                } else if (event == DRIVER_STATE) {
                    handleDriverEvent(eventData);
                } 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
                     * too many recv errors
+11 −3
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ import java.util.List;
 */
public class WifiNative {

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

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

    public native static boolean unloadDriver();

    public native static boolean startSupplicant();

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

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

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

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

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

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

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

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

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

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

    private final boolean mP2pSupported;

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

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

    private static final int CONNECT_MODE   = 1;
    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 */
    private State mSoftApStoppingState = new SoftApStoppingState();

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

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

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

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

        setInitialState(mInitialState);

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

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

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

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

@@ -3348,7 +3345,6 @@ public class WifiStateMachine extends StateMachine {
                case CMD_START_PACKET_FILTERING:
                case CMD_STOP_PACKET_FILTERING:
                case CMD_TETHER_STATE_CHANGE:
                case WifiP2pService.P2P_ENABLE_PENDING:
                    deferMessage(message);
                    break;
                case WifiStateMachine.CMD_RESPONSE_AP_CONFIG:
@@ -3412,55 +3408,6 @@ public class WifiStateMachine extends StateMachine {
                        transitionTo(mTetheringState);
                    }
                    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:
                    return NOT_HANDLED;
            }
@@ -3510,7 +3457,6 @@ public class WifiStateMachine extends StateMachine {
                case CMD_SET_FREQUENCY_BAND:
                case CMD_START_PACKET_FILTERING:
                case CMD_STOP_PACKET_FILTERING:
                case WifiP2pService.P2P_ENABLE_PENDING:
                    deferMessage(message);
                    break;
                default:
@@ -3606,7 +3552,6 @@ public class WifiStateMachine extends StateMachine {
                case CMD_SET_FREQUENCY_BAND:
                case CMD_START_PACKET_FILTERING:
                case CMD_STOP_PACKET_FILTERING:
                case WifiP2pService.P2P_ENABLE_PENDING:
                    deferMessage(message);
                    break;
                default:
Loading