Merge "Add discovery broadcasts for p2p"
This commit is contained in:
committed by
Android (Google) Code Review
commit
8901de0af6
@@ -12735,12 +12735,16 @@ package android.net.wifi.p2p {
|
||||
method public void requestPeers(android.net.wifi.p2p.WifiP2pManager.Channel, android.net.wifi.p2p.WifiP2pManager.PeerListListener);
|
||||
field public static final int BUSY = 2; // 0x2
|
||||
field public static final int ERROR = 0; // 0x0
|
||||
field public static final java.lang.String EXTRA_DISCOVERY_STATE = "discoveryState";
|
||||
field public static final java.lang.String EXTRA_NETWORK_INFO = "networkInfo";
|
||||
field public static final java.lang.String EXTRA_WIFI_P2P_DEVICE = "wifiP2pDevice";
|
||||
field public static final java.lang.String EXTRA_WIFI_P2P_INFO = "wifiP2pInfo";
|
||||
field public static final java.lang.String EXTRA_WIFI_STATE = "wifi_p2p_state";
|
||||
field public static final int P2P_UNSUPPORTED = 1; // 0x1
|
||||
field public static final java.lang.String WIFI_P2P_CONNECTION_CHANGED_ACTION = "android.net.wifi.p2p.CONNECTION_STATE_CHANGE";
|
||||
field public static final java.lang.String WIFI_P2P_DISCOVERY_CHANGED_ACTION = "android.net.wifi.p2p.DISCOVERY_STATE_CHANGE";
|
||||
field public static final int WIFI_P2P_DISCOVERY_STARTED = 2; // 0x2
|
||||
field public static final int WIFI_P2P_DISCOVERY_STOPPED = 1; // 0x1
|
||||
field public static final java.lang.String WIFI_P2P_PEERS_CHANGED_ACTION = "android.net.wifi.p2p.PEERS_CHANGED";
|
||||
field public static final java.lang.String WIFI_P2P_STATE_CHANGED_ACTION = "android.net.wifi.p2p.STATE_CHANGED";
|
||||
field public static final int WIFI_P2P_STATE_DISABLED = 1; // 0x1
|
||||
|
||||
@@ -166,6 +166,9 @@ public class WifiMonitor {
|
||||
/* P2P-DEVICE-LOST p2p_dev_addr=42:fc:89:e1:e2:27 */
|
||||
private static final String P2P_DEVICE_LOST_STR = "P2P-DEVICE-LOST";
|
||||
|
||||
/* P2P-FIND-STOPPED */
|
||||
private static final String P2P_FIND_STOPPED_STR = "P2P-FIND-STOPPED";
|
||||
|
||||
/* P2P-GO-NEG-REQUEST 42:fc:89:a8:96:09 dev_passwd_id=4 */
|
||||
private static final String P2P_GO_NEG_REQUEST_STR = "P2P-GO-NEG-REQUEST";
|
||||
|
||||
@@ -264,6 +267,7 @@ public class WifiMonitor {
|
||||
public static final int P2P_PROV_DISC_PBC_RSP_EVENT = BASE + 34;
|
||||
public static final int P2P_PROV_DISC_ENTER_PIN_EVENT = BASE + 35;
|
||||
public static final int P2P_PROV_DISC_SHOW_PIN_EVENT = BASE + 36;
|
||||
public static final int P2P_FIND_STOPPED_EVENT = BASE + 37;
|
||||
|
||||
/* hostap events */
|
||||
public static final int AP_STA_DISCONNECTED_EVENT = BASE + 41;
|
||||
@@ -516,6 +520,8 @@ public class WifiMonitor {
|
||||
mStateMachine.sendMessage(P2P_DEVICE_FOUND_EVENT, new WifiP2pDevice(dataString));
|
||||
} else if (dataString.startsWith(P2P_DEVICE_LOST_STR)) {
|
||||
mStateMachine.sendMessage(P2P_DEVICE_LOST_EVENT, new WifiP2pDevice(dataString));
|
||||
} else if (dataString.startsWith(P2P_FIND_STOPPED_STR)) {
|
||||
mStateMachine.sendMessage(P2P_FIND_STOPPED_EVENT);
|
||||
} else if (dataString.startsWith(P2P_GO_NEG_REQUEST_STR)) {
|
||||
mStateMachine.sendMessage(P2P_GO_NEGOTIATION_REQUEST_EVENT,
|
||||
new WifiP2pConfig(dataString));
|
||||
|
||||
@@ -181,6 +181,41 @@ public class WifiP2pManager {
|
||||
public static final String WIFI_P2P_PEERS_CHANGED_ACTION =
|
||||
"android.net.wifi.p2p.PEERS_CHANGED";
|
||||
|
||||
/**
|
||||
* Broadcast intent action indicating that peer discovery has either started or stopped.
|
||||
* One extra {@link #EXTRA_DISCOVERY_STATE} indicates whether discovery has started
|
||||
* or stopped.
|
||||
*
|
||||
* Note that discovery will be stopped during a connection setup. If the application tries
|
||||
* to re-initiate discovery during this time, it can fail.
|
||||
*/
|
||||
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
|
||||
public static final String WIFI_P2P_DISCOVERY_CHANGED_ACTION =
|
||||
"android.net.wifi.p2p.DISCOVERY_STATE_CHANGE";
|
||||
|
||||
/**
|
||||
* The lookup key for an int that indicates whether p2p discovery has started or stopped.
|
||||
* Retrieve it with {@link android.content.Intent#getIntExtra(String,int)}.
|
||||
*
|
||||
* @see #WIFI_P2P_DISCOVERY_STARTED
|
||||
* @see #WIFI_P2P_DISCOVERY_STOPPED
|
||||
*/
|
||||
public static final String EXTRA_DISCOVERY_STATE = "discoveryState";
|
||||
|
||||
/**
|
||||
* p2p discovery has stopped
|
||||
*
|
||||
* @see #WIFI_P2P_DISCOVERY_CHANGED_ACTION
|
||||
*/
|
||||
public static final int WIFI_P2P_DISCOVERY_STOPPED = 1;
|
||||
|
||||
/**
|
||||
* p2p discovery has started
|
||||
*
|
||||
* @see #WIFI_P2P_DISCOVERY_CHANGED_ACTION
|
||||
*/
|
||||
public static final int WIFI_P2P_DISCOVERY_STARTED = 2;
|
||||
|
||||
/**
|
||||
* Broadcast intent action indicating that this device details have changed.
|
||||
*/
|
||||
|
||||
@@ -140,6 +140,11 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
* is invoked */
|
||||
private boolean mPersistGroup;
|
||||
|
||||
/* Track whether we are in p2p discovery. This is used to avoid sending duplicate
|
||||
* broadcasts
|
||||
*/
|
||||
private boolean mDiscoveryStarted;
|
||||
|
||||
private NetworkInfo mNetworkInfo;
|
||||
|
||||
/* Is chosen as a unique range to avoid conflict with
|
||||
@@ -489,11 +494,15 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
case WifiP2pManager.DISCOVER_PEERS:
|
||||
if (mWifiNative.p2pFind(DISCOVER_TIMEOUT_S)) {
|
||||
replyToMessage(message, WifiP2pManager.DISCOVER_PEERS_SUCCEEDED);
|
||||
sendP2pDiscoveryChangedBroadcast(true);
|
||||
} else {
|
||||
replyToMessage(message, WifiP2pManager.DISCOVER_PEERS_FAILED,
|
||||
WifiP2pManager.ERROR);
|
||||
}
|
||||
break;
|
||||
case WifiMonitor.P2P_FIND_STOPPED_EVENT:
|
||||
sendP2pDiscoveryChangedBroadcast(false);
|
||||
break;
|
||||
case WifiP2pManager.STOP_DISCOVERY:
|
||||
if (mWifiNative.p2pStopFind()) {
|
||||
replyToMessage(message, WifiP2pManager.STOP_DISCOVERY_SUCCEEDED);
|
||||
@@ -1030,6 +1039,20 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
|
||||
mContext.sendStickyBroadcast(intent);
|
||||
}
|
||||
|
||||
private void sendP2pDiscoveryChangedBroadcast(boolean started) {
|
||||
if (mDiscoveryStarted == started) return;
|
||||
mDiscoveryStarted = started;
|
||||
|
||||
if (DBG) logd("discovery change broadcast " + started);
|
||||
|
||||
final Intent intent = new Intent(WifiP2pManager.WIFI_P2P_DISCOVERY_CHANGED_ACTION);
|
||||
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
|
||||
intent.putExtra(WifiP2pManager.EXTRA_DISCOVERY_STATE, started ?
|
||||
WifiP2pManager.WIFI_P2P_DISCOVERY_STARTED :
|
||||
WifiP2pManager.WIFI_P2P_DISCOVERY_STOPPED);
|
||||
mContext.sendStickyBroadcast(intent);
|
||||
}
|
||||
|
||||
private void sendThisDeviceChangedBroadcast() {
|
||||
final Intent intent = new Intent(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
|
||||
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
|
||||
|
||||
Reference in New Issue
Block a user