7

I am programming a Wifi Direct game, but have run into a problem with the WifiP2pDevice Status when one user declines the invitation to join the connection.

  1. Phone A initiates connection to Phone B
  2. Phone B status becomes INVITED (as displayed on Phone A)
  3. Phone B decline invitation from Phone A
  4. Phone B status is still INVITED (as displayed on Phone A)

Shouldn't the status be shifted back to AVAILABLE as displayed on Phone A? I have refreshed the list of Available devices, but the status remains unchanged. even if I restart the app, it still shows the status of Phone B as invited?

Is this supposed to happen based on the API of WifiDirect? or am I missing something?

Edit: More Information

In the BroadcastReciever, when the intent is WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION, then the manager requests the peers using a Fragment that implements a PeerListListener, which just prints a list of available devices and information (including status) of those devices. So when Phone A sends an invitation with manager.connect() it changes the status to INVITED. But if Phone B declines, the status remains as INVITED. And those statuses are triggered on a notifyDataSetChanged(). It is not so much a question about code, but how wifi direct determines and changes statuses of the devices. But I can provide code if needed.

The4thIceman
  • 3,709
  • 2
  • 29
  • 36
  • What are you using to see Invited/Available? please explain more, the question is not clear. – Saeid Farivar Feb 27 '14 at 00:19
  • Updated my question to provide some more information. Thanks – The4thIceman Feb 27 '14 at 03:33
  • Take a look at [this link](https://android.googlesource.com/platform/frameworks/base/+/b267554/wifi/java/android/net/wifi/p2p/WifiP2pService.java) if you search for updateStatus you will see how the status is changing... From what I see in the code after decline there is no status update that's why the status is still Invited. Hope it helps. – Saeid Farivar Feb 27 '14 at 16:28
  • Thanks for the link. It does seem that no status update is happening after a decline. also on line 1707 it says: "// TODO: figure out updating the status to declined when invitation is rejected". I guess that solves that problem. – The4thIceman Mar 01 '14 at 19:17
  • hey @The4thIceman... i am working on wifi p2p. i am also facing the same problem . Apart from this, also once the status is INVITED, next time when i try to send the connection request ..it fails . Also hte result of peers list is showig the new entered device , but not clear the list if any device got out of range. pls help – Abhishek choudhary Mar 20 '14 at 11:20
  • @Abhishekchoudhary - I am having that same problem (the request failing the second time after a failed invite). I haven't solved it yet. Since the status isn't resetting from INVITED. it messes the rest up. As far as the out of range, when the broadcast receiver receives notice of WIFI_P2P_CONNECTION_CHANGED_ACTION, your code needs to manually disconnect the users via removeGroup(). this should also trigger a WIFI_P2P_PEERS_CHANGED_ACTION in which you requestPeers() again. Anytime (connected or not) the peer list changes, the broadcast receiver should receive a WIFI_P2P_PEERS_CHANGED_ACTION. – The4thIceman Mar 28 '14 at 20:30

1 Answers1

2

You can cancel the connection if the status is "Invited"

 if (fragment.getDevice().status == WifiP2pDevice.AVAILABLE
                || fragment.getDevice().status == WifiP2pDevice.INVITED) {

            manager.cancelConnect(channel, new ActionListener() {

                @Override
                public void onSuccess() {
                    Toast.makeText(WiFiDirectActivity.this, "Aborting connection",
                            Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onFailure(int reasonCode) {
                    Toast.makeText(WiFiDirectActivity.this,
                            "Connect abort request failed. Reason Code: " + reasonCode,
                            Toast.LENGTH_SHORT).show();
                }
            });
        }
Pay
  • 29
  • 5