Skip to content

Commit 870084d

Browse files
isheriffAndroid (Google) Code Review
authored andcommitted
Merge "Initial support for concurrency"
2 parents e4104b8 + 7d6d9c0 commit 870084d

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
@@ -2708,11 +2708,6 @@
27082708
<!-- Do not translate. Default access point SSID used for tethering -->
27092709
<string name="wifi_tether_configure_ssid_default" translatable="false">AndroidAP</string>
27102710

2711-
<!-- Wi-Fi p2p dialog title-->
2712-
<string name="wifi_p2p_dialog_title">Wi-Fi Direct</string>
2713-
<string name="wifi_p2p_turnon_message">Start Wi-Fi Direct. This will turn off Wi-Fi client/hotspot.</string>
2714-
<string name="wifi_p2p_failed_message">Couldn\'t start Wi-Fi Direct.</string>
2715-
27162711
<string name="accept">Accept</string>
27172712
<string name="decline">Decline</string>
27182713
<string name="wifi_p2p_invitation_sent_title">Invitation sent</string>
@@ -2723,9 +2718,6 @@
27232718
<string name="wifi_p2p_enter_pin_message">Type the required PIN: </string>
27242719
<string name="wifi_p2p_show_pin_message">PIN: </string>
27252720

2726-
<string name="wifi_p2p_enabled_notification_title">Wi-Fi Direct is on</string>
2727-
<string name="wifi_p2p_enabled_notification_message">Touch for settings</string>
2728-
27292721
<!-- Name of the dialog that lets the user choose an accented character to insert -->
27302722
<string name="select_character">Insert character</string>
27312723

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

@@ -1896,11 +1898,6 @@ public boolean processMessage(Message message) {
18961898
mReplyChannel.replyToMessage(message, WifiManager.CMD_WPS_COMPLETED,
18971899
new WpsResult(Status.FAILURE));
18981900
break;
1899-
case WifiP2pService.P2P_ENABLE_PENDING:
1900-
// turn off wifi and defer to be handled in DriverUnloadedState
1901-
setWifiEnabled(false);
1902-
deferMessage(message);
1903-
break;
19041901
default:
19051902
loge("Error! unhandled message" + message);
19061903
break;
@@ -2060,7 +2057,7 @@ public boolean processMessage(Message message) {
20602057
loge("Unable to change interface settings: " + ie);
20612058
}
20622059

2063-
if(mWifiNative.startSupplicant()) {
2060+
if(mWifiNative.startSupplicant(mP2pSupported)) {
20642061
if (DBG) log("Supplicant start successful");
20652062
mWifiMonitor.startMonitoring();
20662063
transitionTo(mSupplicantStartingState);
@@ -2172,11 +2169,7 @@ public boolean processMessage(Message message) {
21722169
if (DBG) log(getName() + message.toString() + "\n");
21732170
switch (message.what) {
21742171
case CMD_LOAD_DRIVER:
2175-
mWifiP2pChannel.sendMessage(WIFI_ENABLE_PENDING);
2176-
transitionTo(mWaitForP2pDisableState);
2177-
break;
2178-
case WifiP2pService.P2P_ENABLE_PENDING:
2179-
mReplyChannel.replyToMessage(message, P2P_ENABLE_PROCEED);
2172+
transitionTo(mDriverLoadingState);
21802173
break;
21812174
default:
21822175
return NOT_HANDLED;
@@ -2556,13 +2549,15 @@ public void enter() {
25562549
mWifiNative.status();
25572550
transitionTo(mDisconnectedState);
25582551
}
2552+
2553+
if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_ENABLE_P2P);
25592554
}
25602555
@Override
25612556
public boolean processMessage(Message message) {
25622557
if (DBG) log(getName() + message.toString() + "\n");
25632558
boolean eventLoggingEnabled = true;
25642559
switch(message.what) {
2565-
case CMD_SET_SCAN_TYPE:
2560+
case CMD_SET_SCAN_TYPE:
25662561
mSetScanActive = (message.arg1 == SCAN_ACTIVE);
25672562
mWifiNative.setScanMode(mSetScanActive);
25682563
break;
@@ -2675,6 +2670,8 @@ public void exit() {
26752670
mIsRunning = false;
26762671
updateBatteryWorkSource(null);
26772672
mScanResults = null;
2673+
2674+
if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_DISABLE_P2P);
26782675
}
26792676
}
26802677

@@ -3348,7 +3345,6 @@ public boolean processMessage(Message message) {
33483345
case CMD_START_PACKET_FILTERING:
33493346
case CMD_STOP_PACKET_FILTERING:
33503347
case CMD_TETHER_STATE_CHANGE:
3351-
case WifiP2pService.P2P_ENABLE_PENDING:
33523348
deferMessage(message);
33533349
break;
33543350
case WifiStateMachine.CMD_RESPONSE_AP_CONFIG:
@@ -3412,55 +3408,6 @@ public boolean processMessage(Message message) {
34123408
transitionTo(mTetheringState);
34133409
}
34143410
break;
3415-
case WifiP2pService.P2P_ENABLE_PENDING:
3416-
// turn of soft Ap and defer to be handled in DriverUnloadedState
3417-
setWifiApEnabled(null, false);
3418-
deferMessage(message);
3419-
break;
3420-
default:
3421-
return NOT_HANDLED;
3422-
}
3423-
EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
3424-
return HANDLED;
3425-
}
3426-
}
3427-
3428-
class WaitForP2pDisableState extends State {
3429-
private int mSavedArg;
3430-
@Override
3431-
public void enter() {
3432-
if (DBG) log(getName() + "\n");
3433-
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
3434-
3435-
//Preserve the argument arg1 that has information used in DriverLoadingState
3436-
mSavedArg = getCurrentMessage().arg1;
3437-
}
3438-
@Override
3439-
public boolean processMessage(Message message) {
3440-
if (DBG) log(getName() + message.toString() + "\n");
3441-
switch(message.what) {
3442-
case WifiP2pService.WIFI_ENABLE_PROCEED:
3443-
//restore argument from original message (CMD_LOAD_DRIVER)
3444-
message.arg1 = mSavedArg;
3445-
transitionTo(mDriverLoadingState);
3446-
break;
3447-
case CMD_LOAD_DRIVER:
3448-
case CMD_UNLOAD_DRIVER:
3449-
case CMD_START_SUPPLICANT:
3450-
case CMD_STOP_SUPPLICANT:
3451-
case CMD_START_AP:
3452-
case CMD_STOP_AP:
3453-
case CMD_START_DRIVER:
3454-
case CMD_STOP_DRIVER:
3455-
case CMD_SET_SCAN_MODE:
3456-
case CMD_SET_SCAN_TYPE:
3457-
case CMD_SET_HIGH_PERF_MODE:
3458-
case CMD_SET_COUNTRY_CODE:
3459-
case CMD_SET_FREQUENCY_BAND:
3460-
case CMD_START_PACKET_FILTERING:
3461-
case CMD_STOP_PACKET_FILTERING:
3462-
deferMessage(message);
3463-
break;
34643411
default:
34653412
return NOT_HANDLED;
34663413
}
@@ -3510,7 +3457,6 @@ public boolean processMessage(Message message) {
35103457
case CMD_SET_FREQUENCY_BAND:
35113458
case CMD_START_PACKET_FILTERING:
35123459
case CMD_STOP_PACKET_FILTERING:
3513-
case WifiP2pService.P2P_ENABLE_PENDING:
35143460
deferMessage(message);
35153461
break;
35163462
default:
@@ -3606,7 +3552,6 @@ public boolean processMessage(Message message) {
36063552
case CMD_SET_FREQUENCY_BAND:
36073553
case CMD_START_PACKET_FILTERING:
36083554
case CMD_STOP_PACKET_FILTERING:
3609-
case WifiP2pService.P2P_ENABLE_PENDING:
36103555
deferMessage(message);
36113556
break;
36123557
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)