Skip to content

Commit 7405b90

Browse files
isheriffAndroid (Google) Code Review
authored andcommitted
Merge "P2p fixes"
2 parents cbc41de + 55bfa42 commit 7405b90

File tree

2 files changed

+86
-12
lines changed

2 files changed

+86
-12
lines changed

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,25 @@ public boolean startWpsPbc(String bssid) {
396396
}
397397
}
398398

399+
public boolean startWpsPbc(String iface, String bssid) {
400+
if (TextUtils.isEmpty(bssid)) {
401+
return doBooleanCommand("WPS_PBC interface=" + iface);
402+
} else {
403+
return doBooleanCommand("WPS_PBC interface=" + iface + " " + bssid);
404+
}
405+
}
406+
399407
public boolean startWpsPinKeypad(String pin) {
400408
if (TextUtils.isEmpty(pin)) return false;
401409
return doBooleanCommand("WPS_PIN any " + pin);
402410
}
403411

412+
public boolean startWpsPinKeypad(String iface, String pin) {
413+
if (TextUtils.isEmpty(pin)) return false;
414+
return doBooleanCommand("WPS_PIN interface=" + iface + " any " + pin);
415+
}
416+
417+
404418
public String startWpsPinDisplay(String bssid) {
405419
if (TextUtils.isEmpty(bssid)) {
406420
return doStringCommand("WPS_PIN any");
@@ -409,6 +423,14 @@ public String startWpsPinDisplay(String bssid) {
409423
}
410424
}
411425

426+
public String startWpsPinDisplay(String iface, String bssid) {
427+
if (TextUtils.isEmpty(bssid)) {
428+
return doStringCommand("WPS_PIN interface=" + iface + " any");
429+
} else {
430+
return doStringCommand("WPS_PIN interface=" + iface + " " + bssid);
431+
}
432+
}
433+
412434
/* Configures an access point connection */
413435
public boolean startWpsRegistrar(String bssid, String pin) {
414436
if (TextUtils.isEmpty(bssid) || TextUtils.isEmpty(pin)) return false;
@@ -440,6 +462,26 @@ public boolean setP2pSsidPostfix(String postfix) {
440462
return doBooleanCommand("SET p2p_ssid_postfix " + postfix);
441463
}
442464

465+
public boolean setP2pGroupIdle(String iface, int time) {
466+
return doBooleanCommand("SET interface=" + iface + " p2p_group_idle " + time);
467+
}
468+
469+
public boolean setP2pPowerSave(String iface, boolean enabled) {
470+
if (enabled) {
471+
return doBooleanCommand("P2P_SET interface=" + iface + " ps 1");
472+
} else {
473+
return doBooleanCommand("P2P_SET interface=" + iface + " ps 0");
474+
}
475+
}
476+
477+
/**
478+
* "sta" prioritizes STA connection over P2P and "p2p" prioritizes
479+
* P2P connection over STA
480+
*/
481+
public boolean setConcurrencyPriority(String s) {
482+
return doBooleanCommand("P2P_SET conc_priority " + s);
483+
}
484+
443485
public boolean p2pFind() {
444486
return doBooleanCommand("P2P_FIND");
445487
}

wifi/java/android/net/wifi/p2p/WifiP2pService.java

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
109109
/* Set a two minute discover timeout to avoid STA scans from being blocked */
110110
private static final int DISCOVER_TIMEOUT_S = 120;
111111

112+
/* Idle time after a peer is gone when the group is torn down */
113+
private static final int GROUP_IDLE_TIME_S = 2;
114+
112115
/**
113116
* Delay between restarts upon failure to setup connection with supplicant
114117
*/
@@ -343,10 +346,21 @@ public boolean processMessage(Message message) {
343346
case WifiMonitor.NETWORK_CONNECTION_EVENT:
344347
case WifiMonitor.NETWORK_DISCONNECTION_EVENT:
345348
case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
349+
case WifiMonitor.P2P_GROUP_REMOVED_EVENT:
346350
case PEER_CONNECTION_USER_ACCEPT:
347351
case PEER_CONNECTION_USER_REJECT:
348352
case GROUP_CREATING_TIMED_OUT:
349353
break;
354+
/* unexpected group created, remove */
355+
case WifiMonitor.P2P_GROUP_STARTED_EVENT:
356+
mGroup = (WifiP2pGroup) message.obj;
357+
loge("Unexpected group creation, remove " + mGroup);
358+
mWifiNative.p2pGroupRemove(mGroup.getInterface());
359+
break;
360+
case WifiMonitor.P2P_GROUP_FORMATION_FAILURE_EVENT:
361+
loge("Unexpected group failure, flush peers");
362+
mWifiNative.p2pFlush();
363+
break;
350364
default:
351365
loge("Unhandled message " + message);
352366
return NOT_HANDLED;
@@ -476,6 +490,7 @@ public void enter() {
476490
if (DBG) logd(getName());
477491
sendP2pStateChangedBroadcast(true);
478492
mNetworkInfo.setIsAvailable(true);
493+
sendP2pConnectionChangedBroadcast();
479494
initializeP2pSettings();
480495
}
481496

@@ -561,9 +576,11 @@ public boolean processMessage(Message message) {
561576
//If peer is a GO, we do not need to send provisional discovery,
562577
//the supplicant takes care of it.
563578
if (mWifiNative.isGroupOwner(mSavedPeerConfig.deviceAddress)) {
579+
if (DBG) logd("Sending join to GO");
564580
p2pConnectWithPinDisplay(mSavedPeerConfig, JOIN_GROUP);
565581
transitionTo(mGroupNegotiationState);
566582
} else {
583+
if (DBG) logd("Sending prov disc");
567584
transitionTo(mProvisionDiscoveryState);
568585
}
569586
}
@@ -651,9 +668,7 @@ public boolean processMessage(Message message) {
651668
case GROUP_CREATING_TIMED_OUT:
652669
if (mGroupCreatingTimeoutIndex == message.arg1) {
653670
if (DBG) logd("Group negotiation timed out");
654-
updateDeviceStatus(mSavedPeerConfig.deviceAddress, WifiP2pDevice.FAILED);
655-
mSavedPeerConfig = null;
656-
sendP2pPeersChangedBroadcast();
671+
handleGroupCreationFailure();
657672
transitionTo(mInactiveState);
658673
}
659674
break;
@@ -663,12 +678,15 @@ public boolean processMessage(Message message) {
663678
WifiP2pManager.BUSY);
664679
break;
665680
case WifiP2pManager.CANCEL_CONNECT:
666-
if (mWifiNative.p2pCancelConnect()) {
667-
replyToMessage(message, WifiP2pManager.CANCEL_CONNECT_SUCCEEDED);
668-
} else {
669-
replyToMessage(message, WifiP2pManager.CANCEL_CONNECT_FAILED,
670-
WifiP2pManager.ERROR);
671-
}
681+
//Do a supplicant p2p_cancel which only cancels an ongoing
682+
//group negotiation. This will fail for a pending provision
683+
//discovery or for a pending user action, but at the framework
684+
//level, we always treat cancel as succeded and enter
685+
//an inactive state
686+
mWifiNative.p2pCancelConnect();
687+
handleGroupCreationFailure();
688+
transitionTo(mInactiveState);
689+
replyToMessage(message, WifiP2pManager.CANCEL_CONNECT_SUCCEEDED);
672690
break;
673691
default:
674692
return NOT_HANDLED;
@@ -811,9 +829,7 @@ public boolean processMessage(Message message) {
811829
case WifiMonitor.P2P_GO_NEGOTIATION_FAILURE_EVENT:
812830
case WifiMonitor.P2P_GROUP_FORMATION_FAILURE_EVENT:
813831
if (DBG) logd(getName() + " go failure");
814-
updateDeviceStatus(mSavedPeerConfig.deviceAddress, WifiP2pDevice.FAILED);
815-
mSavedPeerConfig = null;
816-
sendP2pPeersChangedBroadcast();
832+
handleGroupCreationFailure();
817833
transitionTo(mInactiveState);
818834
break;
819835
default:
@@ -838,6 +854,10 @@ public void enter() {
838854
setWifiP2pInfoOnGroupFormation(SERVER_ADDRESS);
839855
sendP2pConnectionChangedBroadcast();
840856
}
857+
858+
if (!mPersistGroup) {
859+
mWifiNative.setP2pGroupIdle(mGroup.getInterface(), GROUP_IDLE_TIME_S);
860+
}
841861
}
842862

843863
@Override
@@ -886,6 +906,8 @@ public boolean processMessage(Message message) {
886906
if (DBG) logd("DhcpInfo: " + dhcpInfo);
887907
setWifiP2pInfoOnGroupFormation(dhcpInfo.serverAddress);
888908
sendP2pConnectionChangedBroadcast();
909+
//Turn on power save on client
910+
mWifiNative.setP2pPowerSave(mGroup.getInterface(), true);
889911
} else {
890912
loge("DHCP failed");
891913
mWifiNative.p2pGroupRemove(mGroup.getInterface());
@@ -1258,6 +1280,8 @@ private void initializeP2pSettings() {
12581280
//The supplicant default is to support everything, but a bug necessitates
12591281
//the framework to specify this explicitly
12601282
mWifiNative.setConfigMethods("keypad display push_button");
1283+
//STA has higher priority over P2P
1284+
mWifiNative.setConcurrencyPriority("sta");
12611285

12621286
mThisDevice.deviceAddress = mWifiNative.p2pGetDeviceAddress();
12631287
updateThisDevice(WifiP2pDevice.AVAILABLE);
@@ -1269,6 +1293,14 @@ private void updateThisDevice(int status) {
12691293
sendThisDeviceChangedBroadcast();
12701294
}
12711295

1296+
private void handleGroupCreationFailure() {
1297+
mSavedPeerConfig = null;
1298+
/* After cancelling group formation, new connections on existing peers can fail
1299+
* at supplicant. Flush and restart discovery */
1300+
mWifiNative.p2pFlush();
1301+
sendMessage(WifiP2pManager.DISCOVER_PEERS);
1302+
}
1303+
12721304
//State machine initiated requests can have replyTo set to null indicating
12731305
//there are no recepients, we ignore those reply actions
12741306
private void replyToMessage(Message msg, int what) {

0 commit comments

Comments
 (0)