Skip to content

Commit 7d6d9c0

Browse files
committed
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
1 parent ea77ed0 commit 7d6d9c0

File tree

8 files changed

+128
-449
lines changed

8 files changed

+128
-449
lines changed

core/jni/android_net_wifi_Wifi.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,9 @@ static jboolean android_net_wifi_unloadDriver(JNIEnv* env, jobject)
116116
return (jboolean)(::wifi_unload_driver() == 0);
117117
}
118118

119-
static jboolean android_net_wifi_startSupplicant(JNIEnv* env, jobject)
119+
static jboolean android_net_wifi_startSupplicant(JNIEnv* env, jobject, jboolean p2pSupported)
120120
{
121-
return (jboolean)(::wifi_start_supplicant() == 0);
122-
}
123-
124-
static jboolean android_net_wifi_startP2pSupplicant(JNIEnv* env, jobject)
125-
{
126-
return (jboolean)(::wifi_start_p2p_supplicant() == 0);
121+
return (jboolean)(::wifi_start_supplicant(p2pSupported) == 0);
127122
}
128123

129124
static jboolean android_net_wifi_killSupplicant(JNIEnv* env, jobject)
@@ -207,8 +202,7 @@ static JNINativeMethod gWifiMethods[] = {
207202
{ "loadDriver", "()Z", (void *)android_net_wifi_loadDriver },
208203
{ "isDriverLoaded", "()Z", (void *)android_net_wifi_isDriverLoaded },
209204
{ "unloadDriver", "()Z", (void *)android_net_wifi_unloadDriver },
210-
{ "startSupplicant", "()Z", (void *)android_net_wifi_startSupplicant },
211-
{ "startP2pSupplicant", "()Z", (void *)android_net_wifi_startP2pSupplicant },
205+
{ "startSupplicant", "(Z)Z", (void *)android_net_wifi_startSupplicant },
212206
{ "killSupplicant", "()Z", (void *)android_net_wifi_killSupplicant },
213207
{ "connectToSupplicant", "(Ljava/lang/String;)Z",
214208
(void *)android_net_wifi_connectToSupplicant },

core/res/res/values/strings.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,11 +2696,6 @@
26962696
<!-- Do not translate. Default access point SSID used for tethering -->
26972697
<string name="wifi_tether_configure_ssid_default" translatable="false">AndroidAP</string>
26982698

2699-
<!-- Wi-Fi p2p dialog title-->
2700-
<string name="wifi_p2p_dialog_title">Wi-Fi Direct</string>
2701-
<string name="wifi_p2p_turnon_message">Start Wi-Fi Direct. This will turn off Wi-Fi client/hotspot.</string>
2702-
<string name="wifi_p2p_failed_message">Couldn\'t start Wi-Fi Direct.</string>
2703-
27042699
<string name="accept">Accept</string>
27052700
<string name="decline">Decline</string>
27062701
<string name="wifi_p2p_invitation_sent_title">Invitation sent</string>
@@ -2711,9 +2706,6 @@
27112706
<string name="wifi_p2p_enter_pin_message">Type the required PIN: </string>
27122707
<string name="wifi_p2p_show_pin_message">PIN: </string>
27132708

2714-
<string name="wifi_p2p_enabled_notification_title">Wi-Fi Direct is on</string>
2715-
<string name="wifi_p2p_enabled_notification_message">Touch for settings</string>
2716-
27172709
<!-- Name of the dialog that lets the user choose an accented character to insert -->
27182710
<string name="select_character">Insert character</string>
27192711

wifi/java/android/net/wifi/WifiMonitor.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -365,17 +365,6 @@ else if (event == STATE_CHANGE || event == EAP_FAILURE) {
365365
} else if (event == DRIVER_STATE) {
366366
handleDriverEvent(eventData);
367367
} else if (event == TERMINATING) {
368-
/**
369-
* If monitor socket is closed, we have already
370-
* stopped the supplicant, simply exit the monitor thread
371-
*/
372-
if (eventData.startsWith(MONITOR_SOCKET_CLOSED_STR)) {
373-
if (false) {
374-
Log.d(TAG, "Monitor socket is closed, exiting thread");
375-
}
376-
break;
377-
}
378-
379368
/**
380369
* Close the supplicant connection if we see
381370
* too many recv errors

wifi/java/android/net/wifi/WifiNative.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
*/
4040
public class WifiNative {
4141

42+
private static final boolean DBG = false;
43+
private final String mTAG;
4244
private static final int DEFAULT_GROUP_OWNER_INTENT = 7;
4345

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

5456
public native static boolean unloadDriver();
5557

56-
public native static boolean startSupplicant();
57-
58-
public native static boolean startP2pSupplicant();
58+
public native static boolean startSupplicant(boolean p2pSupported);
5959

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

8080
public WifiNative(String iface) {
8181
mInterface = iface;
82+
mTAG = "WifiNative-" + iface;
8283
}
8384

8485
public boolean connectToSupplicant() {
@@ -94,14 +95,17 @@ public String waitForEvent() {
9495
}
9596

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

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

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

@@ -437,6 +441,10 @@ public boolean p2pFind(int timeout) {
437441
return doBooleanCommand("P2P_FIND " + timeout);
438442
}
439443

444+
public boolean p2pStopFind() {
445+
return doBooleanCommand("P2P_STOP_FIND");
446+
}
447+
440448
public boolean p2pListen() {
441449
return doBooleanCommand("P2P_LISTEN");
442450
}

wifi/java/android/net/wifi/WifiStateMachine.java

Lines changed: 16 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import android.content.Context;
4646
import android.content.Intent;
4747
import android.content.IntentFilter;
48+
import android.content.pm.PackageManager;
4849
import android.net.ConnectivityManager;
4950
import android.net.DhcpInfo;
5051
import android.net.DhcpInfoInternal;
@@ -118,6 +119,8 @@ public class WifiStateMachine extends StateMachine {
118119
private INetworkManagementService mNwService;
119120
private ConnectivityManager mCm;
120121

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

364-
/* Interaction with WifiP2pService */
365-
public static final int WIFI_ENABLE_PENDING = BASE + 131;
366-
public static final int P2P_ENABLE_PROCEED = BASE + 132;
367+
/* P2p commands */
368+
public static final int CMD_ENABLE_P2P = BASE + 131;
369+
public static final int CMD_DISABLE_P2P = BASE + 132;
367370

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

485-
/* Wait till p2p is disabled */
486-
private State mWaitForP2pDisableState = new WaitForP2pDisableState();
487-
488488
private class TetherStateChange {
489489
ArrayList<String> available;
490490
ArrayList<String> active;
@@ -556,6 +556,9 @@ public WifiStateMachine(Context context, String wlanInterface) {
556556
IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
557557
mNwService = INetworkManagementService.Stub.asInterface(b);
558558

559+
mP2pSupported = mContext.getPackageManager().hasSystemFeature(
560+
PackageManager.FEATURE_WIFI_DIRECT);
561+
559562
mWifiNative = new WifiNative(mInterfaceName);
560563
mWifiConfigStore = new WifiConfigStore(context, mWifiNative);
561564
mWifiMonitor = new WifiMonitor(this, mWifiNative);
@@ -639,7 +642,6 @@ public void onReceive(Context context, Intent intent) {
639642
addState(mTetheringState, mSoftApStartedState);
640643
addState(mTetheredState, mSoftApStartedState);
641644
addState(mSoftApStoppingState, mDefaultState);
642-
addState(mWaitForP2pDisableState, mDefaultState);
643645

644646
setInitialState(mInitialState);
645647

@@ -1892,11 +1894,6 @@ public boolean processMessage(Message message) {
18921894
mReplyChannel.replyToMessage(message, WifiManager.CMD_WPS_COMPLETED,
18931895
new WpsResult(Status.FAILURE));
18941896
break;
1895-
case WifiP2pService.P2P_ENABLE_PENDING:
1896-
// turn off wifi and defer to be handled in DriverUnloadedState
1897-
setWifiEnabled(false);
1898-
deferMessage(message);
1899-
break;
19001897
default:
19011898
loge("Error! unhandled message" + message);
19021899
break;
@@ -2056,7 +2053,7 @@ public boolean processMessage(Message message) {
20562053
loge("Unable to change interface settings: " + ie);
20572054
}
20582055

2059-
if(mWifiNative.startSupplicant()) {
2056+
if(mWifiNative.startSupplicant(mP2pSupported)) {
20602057
if (DBG) log("Supplicant start successful");
20612058
mWifiMonitor.startMonitoring();
20622059
transitionTo(mSupplicantStartingState);
@@ -2168,11 +2165,7 @@ public boolean processMessage(Message message) {
21682165
if (DBG) log(getName() + message.toString() + "\n");
21692166
switch (message.what) {
21702167
case CMD_LOAD_DRIVER:
2171-
mWifiP2pChannel.sendMessage(WIFI_ENABLE_PENDING);
2172-
transitionTo(mWaitForP2pDisableState);
2173-
break;
2174-
case WifiP2pService.P2P_ENABLE_PENDING:
2175-
mReplyChannel.replyToMessage(message, P2P_ENABLE_PROCEED);
2168+
transitionTo(mDriverLoadingState);
21762169
break;
21772170
default:
21782171
return NOT_HANDLED;
@@ -2549,13 +2542,15 @@ public void enter() {
25492542
mWifiNative.status();
25502543
transitionTo(mDisconnectedState);
25512544
}
2545+
2546+
if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_ENABLE_P2P);
25522547
}
25532548
@Override
25542549
public boolean processMessage(Message message) {
25552550
if (DBG) log(getName() + message.toString() + "\n");
25562551
boolean eventLoggingEnabled = true;
25572552
switch(message.what) {
2558-
case CMD_SET_SCAN_TYPE:
2553+
case CMD_SET_SCAN_TYPE:
25592554
mSetScanActive = (message.arg1 == SCAN_ACTIVE);
25602555
mWifiNative.setScanMode(mSetScanActive);
25612556
break;
@@ -2668,6 +2663,8 @@ public void exit() {
26682663
mIsRunning = false;
26692664
updateBatteryWorkSource(null);
26702665
mScanResults = null;
2666+
2667+
if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_DISABLE_P2P);
26712668
}
26722669
}
26732670

@@ -3341,7 +3338,6 @@ public boolean processMessage(Message message) {
33413338
case CMD_START_PACKET_FILTERING:
33423339
case CMD_STOP_PACKET_FILTERING:
33433340
case CMD_TETHER_STATE_CHANGE:
3344-
case WifiP2pService.P2P_ENABLE_PENDING:
33453341
deferMessage(message);
33463342
break;
33473343
case WifiStateMachine.CMD_RESPONSE_AP_CONFIG:
@@ -3405,55 +3401,6 @@ public boolean processMessage(Message message) {
34053401
transitionTo(mTetheringState);
34063402
}
34073403
break;
3408-
case WifiP2pService.P2P_ENABLE_PENDING:
3409-
// turn of soft Ap and defer to be handled in DriverUnloadedState
3410-
setWifiApEnabled(null, false);
3411-
deferMessage(message);
3412-
break;
3413-
default:
3414-
return NOT_HANDLED;
3415-
}
3416-
EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
3417-
return HANDLED;
3418-
}
3419-
}
3420-
3421-
class WaitForP2pDisableState extends State {
3422-
private int mSavedArg;
3423-
@Override
3424-
public void enter() {
3425-
if (DBG) log(getName() + "\n");
3426-
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
3427-
3428-
//Preserve the argument arg1 that has information used in DriverLoadingState
3429-
mSavedArg = getCurrentMessage().arg1;
3430-
}
3431-
@Override
3432-
public boolean processMessage(Message message) {
3433-
if (DBG) log(getName() + message.toString() + "\n");
3434-
switch(message.what) {
3435-
case WifiP2pService.WIFI_ENABLE_PROCEED:
3436-
//restore argument from original message (CMD_LOAD_DRIVER)
3437-
message.arg1 = mSavedArg;
3438-
transitionTo(mDriverLoadingState);
3439-
break;
3440-
case CMD_LOAD_DRIVER:
3441-
case CMD_UNLOAD_DRIVER:
3442-
case CMD_START_SUPPLICANT:
3443-
case CMD_STOP_SUPPLICANT:
3444-
case CMD_START_AP:
3445-
case CMD_STOP_AP:
3446-
case CMD_START_DRIVER:
3447-
case CMD_STOP_DRIVER:
3448-
case CMD_SET_SCAN_MODE:
3449-
case CMD_SET_SCAN_TYPE:
3450-
case CMD_SET_HIGH_PERF_MODE:
3451-
case CMD_SET_COUNTRY_CODE:
3452-
case CMD_SET_FREQUENCY_BAND:
3453-
case CMD_START_PACKET_FILTERING:
3454-
case CMD_STOP_PACKET_FILTERING:
3455-
deferMessage(message);
3456-
break;
34573404
default:
34583405
return NOT_HANDLED;
34593406
}
@@ -3503,7 +3450,6 @@ public boolean processMessage(Message message) {
35033450
case CMD_SET_FREQUENCY_BAND:
35043451
case CMD_START_PACKET_FILTERING:
35053452
case CMD_STOP_PACKET_FILTERING:
3506-
case WifiP2pService.P2P_ENABLE_PENDING:
35073453
deferMessage(message);
35083454
break;
35093455
default:
@@ -3599,7 +3545,6 @@ public boolean processMessage(Message message) {
35993545
case CMD_SET_FREQUENCY_BAND:
36003546
case CMD_START_PACKET_FILTERING:
36013547
case CMD_STOP_PACKET_FILTERING:
3602-
case WifiP2pService.P2P_ENABLE_PENDING:
36033548
deferMessage(message);
36043549
break;
36053550
default:

wifi/java/android/net/wifi/p2p/WifiP2pDevice.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ public WifiP2pDevice[] newArray(int size) {
301301
private String trimQuotes(String str) {
302302
str = str.trim();
303303
if (str.startsWith("'") && str.endsWith("'")) {
304-
return str.substring(1, str.length()-1);
304+
if (str.length() <= 2) return "";
305+
else return str.substring(1, str.length()-1);
305306
}
306307
return str;
307308
}

0 commit comments

Comments
 (0)