diff options
author | Irfan Sheriff <isheriff@google.com> | 2012-03-28 15:59:30 -0700 |
---|---|---|
committer | Irfan Sheriff <isheriff@google.com> | 2012-03-28 17:37:04 -0700 |
commit | c111d1caa8d4cc5d2139b5abd4d2db1f78560eff (patch) | |
tree | 10b3872501db6b0970b4a1340a780c4be23fc7f0 /wifi/java/android/net | |
parent | 61472a8314e6716f231ec1c0aba73e005935829b (diff) | |
download | frameworks_base-c111d1caa8d4cc5d2139b5abd4d2db1f78560eff.zip frameworks_base-c111d1caa8d4cc5d2139b5abd4d2db1f78560eff.tar.gz frameworks_base-c111d1caa8d4cc5d2139b5abd4d2db1f78560eff.tar.bz2 |
Add discovery broadcasts for p2p
This will allow apps to figure out if discovery is active or not
and based on that initiate a new discovery for fresh connections
Change-Id: I4778f135fdd88773e4f0d50c384f9b6ebf561e6d
Diffstat (limited to 'wifi/java/android/net')
-rw-r--r-- | wifi/java/android/net/wifi/WifiMonitor.java | 6 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/p2p/WifiP2pManager.java | 35 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/p2p/WifiP2pService.java | 23 |
3 files changed, 64 insertions, 0 deletions
diff --git a/wifi/java/android/net/wifi/WifiMonitor.java b/wifi/java/android/net/wifi/WifiMonitor.java index f07e0de..03d5134 100644 --- a/wifi/java/android/net/wifi/WifiMonitor.java +++ b/wifi/java/android/net/wifi/WifiMonitor.java @@ -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)); diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java index 4fd0a57..2fc6c20 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java @@ -182,6 +182,41 @@ public class WifiP2pManager { "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. */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pService.java b/wifi/java/android/net/wifi/p2p/WifiP2pService.java index 02ca926..3d3a746 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pService.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pService.java @@ -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); |