8888import java .util .List ;
8989
9090/**
91- * WifiP2pService inclues a state machine to perform Wi-Fi p2p operations. Applications
91+ * WifiP2pService includes a state machine to perform Wi-Fi p2p operations. Applications
9292 * communicate with this service to issue device discovery and connectivity requests
9393 * through the WifiP2pManager interface. The state machine communicates with the wifi
9494 * driver through wpa_supplicant and handles the event responses through WifiMonitor.
@@ -432,9 +432,10 @@ public boolean processMessage(Message message) {
432432 loge ("Unexpected group creation, remove " + mGroup );
433433 mWifiNative .p2pGroupRemove (mGroup .getInterface ());
434434 break ;
435+ // A group formation failure is always followed by
436+ // a group removed event. Flushing things at group formation
437+ // failure causes supplicant issues. Ignore right now.
435438 case WifiMonitor .P2P_GROUP_FORMATION_FAILURE_EVENT :
436- loge ("Unexpected group failure, flush peers" );
437- mWifiNative .p2pFlush ();
438439 break ;
439440 default :
440441 loge ("Unhandled message " + message );
@@ -838,8 +839,10 @@ public boolean processMessage(Message message) {
838839 //group negotiation comes through causes issues
839840 break ;
840841 case WifiP2pManager .CREATE_GROUP :
841- mAutonomousGroup = true ;
842- if (mWifiNative .p2pGroupAdd ()) {
842+ mAutonomousGroup = true ;
843+ // An autonomous GO requires group idle settings to be reset
844+ mWifiNative .setP2pGroupIdle (0 );
845+ if (mWifiNative .p2pGroupAdd ()) {
843846 replyToMessage (message , WifiP2pManager .CREATE_GROUP_SUCCEEDED );
844847 } else {
845848 replyToMessage (message , WifiP2pManager .CREATE_GROUP_FAILED ,
@@ -860,6 +863,11 @@ public void enter() {
860863 if (DBG ) logd (getName ());
861864 sendMessageDelayed (obtainMessage (GROUP_CREATING_TIMED_OUT ,
862865 ++mGroupCreatingTimeoutIndex , 0 ), GROUP_CREATING_WAIT_TIME_MS );
866+
867+ // Set default group idle settings
868+ if (!mAutonomousGroup ) {
869+ mWifiNative .setP2pGroupIdle (GROUP_IDLE_TIME_S );
870+ }
863871 }
864872
865873 @ Override
@@ -882,7 +890,7 @@ public boolean processMessage(Message message) {
882890 //Do a supplicant p2p_cancel which only cancels an ongoing
883891 //group negotiation. This will fail for a pending provision
884892 //discovery or for a pending user action, but at the framework
885- //level, we always treat cancel as succeded and enter
893+ //level, we always treat cancel as succeeded and enter
886894 //an inactive state
887895 mWifiNative .p2pCancelConnect ();
888896 handleGroupCreationFailure ();
@@ -1034,11 +1042,16 @@ public boolean processMessage(Message message) {
10341042 transitionTo (mGroupCreatedState );
10351043 break ;
10361044 case WifiMonitor .P2P_GO_NEGOTIATION_FAILURE_EVENT :
1037- case WifiMonitor .P2P_GROUP_FORMATION_FAILURE_EVENT :
1045+ case WifiMonitor .P2P_GROUP_REMOVED_EVENT :
10381046 if (DBG ) logd (getName () + " go failure" );
10391047 handleGroupCreationFailure ();
10401048 transitionTo (mInactiveState );
10411049 break ;
1050+ // A group formation failure is always followed by
1051+ // a group removed event. Flushing things at group formation
1052+ // failure causes supplicant issues. Ignore right now.
1053+ case WifiMonitor .P2P_GROUP_FORMATION_FAILURE_EVENT :
1054+ break ;
10421055 default :
10431056 return NOT_HANDLED ;
10441057 }
@@ -1061,10 +1074,6 @@ public void enter() {
10611074 setWifiP2pInfoOnGroupFormation (SERVER_ADDRESS );
10621075 sendP2pConnectionChangedBroadcast ();
10631076 }
1064-
1065- if (!mAutonomousGroup ) {
1066- mWifiNative .setP2pGroupIdle (mGroup .getInterface (), GROUP_IDLE_TIME_S );
1067- }
10681077 }
10691078
10701079 @ Override
@@ -1155,6 +1164,7 @@ public boolean processMessage(Message message) {
11551164
11561165 mGroup = null ;
11571166 mWifiNative .p2pFlush ();
1167+ mServiceDiscReqId = null ;
11581168 if (changed ) sendP2pPeersChangedBroadcast ();
11591169 transitionTo (mInactiveState );
11601170 break ;
@@ -1537,13 +1547,13 @@ private void initializeP2pSettings() {
15371547 mWifiNative .setPersistentReconnect (true );
15381548 mThisDevice .deviceName = getPersistedDeviceName ();
15391549 mWifiNative .setDeviceName (mThisDevice .deviceName );
1540- //DIRECT-XY-DEVICENAME (XY is randomly generated)
1550+ // DIRECT-XY-DEVICENAME (XY is randomly generated)
15411551 mWifiNative .setP2pSsidPostfix ("-" + mThisDevice .deviceName );
15421552 mWifiNative .setDeviceType (mThisDevice .primaryDeviceType );
1543- //The supplicant default is to support everything, but a bug necessitates
1544- //the framework to specify this explicitly
1545- mWifiNative .setConfigMethods ("keypad display push_button " );
1546- //STA has higher priority over P2P
1553+ // Supplicant defaults to using virtual display with display
1554+ // which refers to a remote display. Use physical_display
1555+ mWifiNative .setConfigMethods ("virtual_push_button physical_display keypad " );
1556+ // STA has higher priority over P2P
15471557 mWifiNative .setConcurrencyPriority ("sta" );
15481558
15491559 mThisDevice .deviceAddress = mWifiNative .p2pGetDeviceAddress ();
@@ -1567,11 +1577,12 @@ private void handleGroupCreationFailure() {
15671577 /* After cancelling group formation, new connections on existing peers can fail
15681578 * at supplicant. Flush and restart discovery */
15691579 mWifiNative .p2pFlush ();
1580+ mServiceDiscReqId = null ;
15701581 sendMessage (WifiP2pManager .DISCOVER_PEERS );
15711582 }
15721583
15731584 //State machine initiated requests can have replyTo set to null indicating
1574- //there are no recepients , we ignore those reply actions
1585+ //there are no recipients , we ignore those reply actions
15751586 private void replyToMessage (Message msg , int what ) {
15761587 if (msg .replyTo == null ) return ;
15771588 Message dstMsg = obtainMessage (msg );
@@ -1650,7 +1661,7 @@ private void clearSupplicantServiceRequest() {
16501661 mServiceDiscReqId = null ;
16511662 }
16521663
1653- /* TODO: We could track individual service adds seperately and avoid
1664+ /* TODO: We could track individual service adds separately and avoid
16541665 * having to do update all service requests on every new request
16551666 */
16561667 private boolean addServiceRequest (Messenger m , WifiP2pServiceRequest req ) {
0 commit comments