diff options
author | Irfan Sheriff <isheriff@google.com> | 2012-03-29 08:41:15 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-03-29 08:41:15 -0700 |
commit | 8901de0af68f952ed092ed61ebe652cd907f2ada (patch) | |
tree | 0da945c8e8b206043a6d53646dfc6e0148740c21 | |
parent | b5caab633afcb0e6a333bbea4df97b6bf1000f2f (diff) | |
parent | c111d1caa8d4cc5d2139b5abd4d2db1f78560eff (diff) | |
download | frameworks_base-8901de0af68f952ed092ed61ebe652cd907f2ada.zip frameworks_base-8901de0af68f952ed092ed61ebe652cd907f2ada.tar.gz frameworks_base-8901de0af68f952ed092ed61ebe652cd907f2ada.tar.bz2 |
Merge "Add discovery broadcasts for p2p"
-rw-r--r-- | api/current.txt | 4 | ||||
-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 |
4 files changed, 68 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt index 8273d23..233938b5 100644 --- a/api/current.txt +++ b/api/current.txt @@ -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 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); |