Skip to content

Commit c41096e

Browse files
committed
P2p fixes
- Add wfdInfo details in group to allow display stack to filter - Handle provision discovery failure and reset - Do a discovery after group removal - Handle failure to reinvoke and fall back to negotiation - Avoid multiple REMOVE_GROUP calls that lead to removal of persisted network Bug: 7210856 Change-Id: Ia2e613e9b1191b919a185f0411439341e2e151bc
1 parent a5e1d21 commit c41096e

File tree

3 files changed

+61
-8
lines changed

3 files changed

+61
-8
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ public class WifiMonitor {
217217
pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
218218
group_capab=0x0 */
219219
private static final String P2P_PROV_DISC_SHOW_PIN_STR = "P2P-PROV-DISC-SHOW-PIN";
220+
/* P2P-PROV-DISC-FAILURE p2p_dev_addr=42:fc:89:e1:e2:27 */
221+
private static final String P2P_PROV_DISC_FAILURE_STR = "P2P-PROV-DISC-FAILURE";
220222

221223
/*
222224
* Protocol format is as follows.<br>
@@ -319,6 +321,7 @@ public class WifiMonitor {
319321
public static final int P2P_PROV_DISC_SHOW_PIN_EVENT = BASE + 36;
320322
public static final int P2P_FIND_STOPPED_EVENT = BASE + 37;
321323
public static final int P2P_SERV_DISC_RESP_EVENT = BASE + 38;
324+
public static final int P2P_PROV_DISC_FAILURE_EVENT = BASE + 39;
322325

323326
/* hostap events */
324327
public static final int AP_STA_DISCONNECTED_EVENT = BASE + 41;
@@ -615,6 +618,8 @@ private void handleP2pEvents(String dataString) {
615618
} else if (dataString.startsWith(P2P_PROV_DISC_SHOW_PIN_STR)) {
616619
mStateMachine.sendMessage(P2P_PROV_DISC_SHOW_PIN_EVENT,
617620
new WifiP2pProvDiscEvent(dataString));
621+
} else if (dataString.startsWith(P2P_PROV_DISC_FAILURE_STR)) {
622+
mStateMachine.sendMessage(P2P_PROV_DISC_FAILURE_EVENT);
618623
} else if (dataString.startsWith(P2P_SERV_DISC_RESP_STR)) {
619624
List<WifiP2pServiceResponse> list = WifiP2pServiceResponse.newInstance(dataString);
620625
if (list != null) {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,18 @@ public boolean isGroupLimit() {
260260
return (groupCapability & GROUP_CAPAB_GROUP_LIMIT) != 0;
261261
}
262262

263+
/** @hide */
264+
public void update(WifiP2pDevice device) {
265+
if (device == null || device.deviceAddress == null) return;
266+
deviceName = device.deviceName;
267+
primaryDeviceType = device.primaryDeviceType;
268+
secondaryDeviceType = device.secondaryDeviceType;
269+
wpsConfigMethodsSupported = device.wpsConfigMethodsSupported;
270+
deviceCapability = device.deviceCapability;
271+
groupCapability = device.groupCapability;
272+
wfdInfo = device.wfdInfo;
273+
}
274+
263275
@Override
264276
public boolean equals(Object obj) {
265277
if (this == obj) return true;

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

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ private class P2pStateMachine extends StateMachine {
346346

347347
private GroupCreatedState mGroupCreatedState = new GroupCreatedState();
348348
private UserAuthorizingJoinState mUserAuthorizingJoinState = new UserAuthorizingJoinState();
349+
private OngoingGroupRemovalState mOngoingGroupRemovalState = new OngoingGroupRemovalState();
349350

350351
private WifiNative mWifiNative = new WifiNative(mInterface);
351352
private WifiMonitor mWifiMonitor = new WifiMonitor(this, mWifiNative);
@@ -389,6 +390,7 @@ public void onDeleteGroup(int netId) {
389390
addState(mGroupNegotiationState, mGroupCreatingState);
390391
addState(mGroupCreatedState, mP2pEnabledState);
391392
addState(mUserAuthorizingJoinState, mGroupCreatedState);
393+
addState(mOngoingGroupRemovalState, mGroupCreatedState);
392394

393395
if (p2pSupported) {
394396
setInitialState(mP2pDisabledState);
@@ -545,6 +547,7 @@ public boolean processMessage(Message message) {
545547
case DhcpStateMachine.CMD_PRE_DHCP_ACTION:
546548
case DhcpStateMachine.CMD_POST_DHCP_ACTION:
547549
case DhcpStateMachine.CMD_ON_QUIT:
550+
case WifiMonitor.P2P_PROV_DISC_FAILURE_EVENT:
548551
break;
549552
/* unexpected group created, remove */
550553
case WifiMonitor.P2P_GROUP_STARTED_EVENT:
@@ -1183,6 +1186,11 @@ public boolean processMessage(Message message) {
11831186
transitionTo(mGroupNegotiationState);
11841187
}
11851188
break;
1189+
case WifiMonitor.P2P_PROV_DISC_FAILURE_EVENT:
1190+
loge("provision discovery failed");
1191+
handleGroupCreationFailure();
1192+
transitionTo(mInactiveState);
1193+
break;
11861194
default:
11871195
return NOT_HANDLED;
11881196
}
@@ -1228,6 +1236,8 @@ public boolean processMessage(Message message) {
12281236
P2pStateMachine.this, mGroup.getInterface());
12291237
mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_START_DHCP);
12301238
WifiP2pDevice groupOwner = mGroup.getOwner();
1239+
/* update group owner details with the ones found at discovery */
1240+
groupOwner.update(mPeers.get(groupOwner.deviceAddress));
12311241
mPeers.updateStatus(groupOwner.deviceAddress, WifiP2pDevice.CONNECTED);
12321242
sendP2pPeersChangedBroadcast();
12331243
}
@@ -1303,7 +1313,7 @@ public boolean processMessage(Message message) {
13031313
deviceAddress.equals(mSavedProvDiscDevice.deviceAddress)) {
13041314
mSavedProvDiscDevice = null;
13051315
}
1306-
mGroup.addClient(deviceAddress);
1316+
mGroup.addClient(mPeers.get(deviceAddress));
13071317
mPeers.updateStatus(deviceAddress, WifiP2pDevice.CONNECTED);
13081318
if (DBG) logd(getName() + " ap sta connected");
13091319
sendP2pPeersChangedBroadcast();
@@ -1357,6 +1367,7 @@ public boolean processMessage(Message message) {
13571367
case WifiP2pManager.REMOVE_GROUP:
13581368
if (DBG) logd(getName() + " remove group");
13591369
if (mWifiNative.p2pGroupRemove(mGroup.getInterface())) {
1370+
transitionTo(mOngoingGroupRemovalState);
13601371
replyToMessage(message, WifiP2pManager.REMOVE_GROUP_SUCCEEDED);
13611372
} else {
13621373
handleGroupRemoved();
@@ -1534,6 +1545,30 @@ public void exit() {
15341545
}
15351546
}
15361547

1548+
class OngoingGroupRemovalState extends State {
1549+
@Override
1550+
public void enter() {
1551+
if (DBG) logd(getName());
1552+
}
1553+
1554+
@Override
1555+
public boolean processMessage(Message message) {
1556+
if (DBG) logd(getName() + message.toString());
1557+
switch (message.what) {
1558+
// Group removal ongoing. Multiple calls
1559+
// end up removing persisted network. Do nothing.
1560+
case WifiP2pManager.REMOVE_GROUP:
1561+
replyToMessage(message, WifiP2pManager.REMOVE_GROUP_SUCCEEDED);
1562+
break;
1563+
// Parent state will transition out of this state
1564+
// when removal is complete
1565+
default:
1566+
return NOT_HANDLED;
1567+
}
1568+
return HANDLED;
1569+
}
1570+
}
1571+
15371572
private void sendP2pStateChangedBroadcast(boolean enabled) {
15381573
final Intent intent = new Intent(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
15391574
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
@@ -1858,15 +1893,16 @@ private int connect(WifiP2pConfig config, boolean tryInvocation) {
18581893
}
18591894
if (DBG) logd("netId related with " + dev.deviceAddress + " = " + netId);
18601895
if (netId >= 0) {
1861-
18621896
// Invoke the persistent group.
1863-
if (!mWifiNative.p2pReinvoke(netId, dev.deviceAddress)) {
1864-
loge("p2pReinvoke() failed");
1865-
return CONNECT_FAILURE;
1897+
if (mWifiNative.p2pReinvoke(netId, dev.deviceAddress)) {
1898+
// Save network id. It'll be used when an invitation result event is received.
1899+
mSavedPeerConfig.netId = netId;
1900+
return CONNECT_SUCCESS;
1901+
} else {
1902+
loge("p2pReinvoke() failed, update networks");
1903+
updatePersistentNetworks();
1904+
// continue with negotiation
18661905
}
1867-
// Save network id. It'll be used when an invitation result event is received.
1868-
mSavedPeerConfig.netId = netId;
1869-
return CONNECT_SUCCESS;
18701906
}
18711907
}
18721908

0 commit comments

Comments
 (0)