WifiP2pManager.java revision 651cdfcbac6245f570475991588ddc2d30265e8d
155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync/* 255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Copyright (C) 2011 The Android Open Source Project 355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * 455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Licensed under the Apache License, Version 2.0 (the "License"); 555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * you may not use this file except in compliance with the License. 655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * You may obtain a copy of the License at 755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * 855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * http://www.apache.org/licenses/LICENSE-2.0 955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * 1055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Unless required by applicable law or agreed to in writing, software 1155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * distributed under the License is distributed on an "AS IS" BASIS, 1255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * See the License for the specific language governing permissions and 1455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * limitations under the License. 1555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 1655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 1755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncpackage android.net.wifi.p2p; 1855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 1955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncimport android.annotation.SdkConstant; 2055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncimport android.annotation.SdkConstant.SdkConstantType; 2155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncimport android.content.Context; 22aea743aaa43a833fd8ff3dc56205197583152d5frepo syncimport android.net.ConnectivityManager; 23aea743aaa43a833fd8ff3dc56205197583152d5frepo syncimport android.net.IConnectivityManager; 2455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncimport android.os.Binder; 2555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncimport android.os.IBinder; 2655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncimport android.os.Handler; 27651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriffimport android.os.Looper; 2855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncimport android.os.Message; 2955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncimport android.os.RemoteException; 30aea743aaa43a833fd8ff3dc56205197583152d5frepo syncimport android.os.ServiceManager; 3155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncimport android.os.WorkSource; 3255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncimport android.os.Messenger; 33aea743aaa43a833fd8ff3dc56205197583152d5frepo syncimport android.util.Log; 3455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 3555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncimport com.android.internal.util.AsyncChannel; 3655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncimport com.android.internal.util.Protocol; 3755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 38651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriffimport java.util.HashMap; 39651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff 4055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync/** 419cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * This class provides the API for managing Wi-Fi peer-to-peer connectivity. This lets an 429cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * application discover available peers, setup connection to peers and query for the list of peers. 439cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * When a p2p connection is formed over wifi, the device continues to maintain the uplink 449cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * connection over mobile or any other available network for internet connectivity on the device. 459cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 46651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * <p> The API is asynchronous and responses to requests from an application are on listener 47651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * callbacks provided by the application. The application needs to do an initialization with 48651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * {@link #initialize} before doing any p2p operation. 49651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * 50651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * <p> Application actions {@link #discoverPeers}, {@link #connect}, {@link #cancelConnect}, 51651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * {@link #createGroup} and {@link #removeGroup} need a {@link ActionListener} instance for 52651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * receiving callbacks {@link ActionListener#onSuccess} or {@link ActionListener#onFailure}. 53651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * Action callbacks indicate whether the initiation of the action was a success or a failure. 54651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * Upon failure, the reason of failure can be one of {@link #ERROR}, {@link #P2P_UNSUPPORTED} 55651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * or {@link #BUSY}. 569cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 57651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * <p> An application can initiate discovery of peers with {@link #discoverPeers}. An initiated 58651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * discovery request from an application stays active until the device starts connecting to a peer 59651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * or forms a p2p group. The {@link ActionListener} callbacks provide feedback on whether the 60651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * discovery initiation was successful or failure. Additionally, applications can listen 61651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * to {@link #WIFI_P2P_PEERS_CHANGED_ACTION} intent action to know when the peer list changes. 629cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 63651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * <p> When the peer list change intent {@link #WIFI_P2P_PEERS_CHANGED_ACTION} is received 64651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * or when an application needs to fetch the current list of peers, it can request the list 65651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * of peers with {@link #requestPeers}. When the peer list is available 66651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * {@link PeerListListener#onPeersAvailable} is called with the device list. 679cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 689cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * <p> An application can initiate a connection request to a peer through {@link #connect}. See 699cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * {@link WifiP2pConfig} for details on setting up the configuration. For communication with legacy 709cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * Wi-Fi devices that do not support p2p, an app can create a group using {@link #createGroup} 719cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * which creates an access point whose details can be fetched with {@link #requestGroupInfo}. 72651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff* 739cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * <p> After a successful group formation through {@link #createGroup} or through {@link #connect}, 74651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * use {@link #requestConnectionInfo} to fetch the connection details. The connection info 75651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * {@link WifiP2pInfo} contains the address of the group owner 766f7d385d964949e507dcc9c88012372f48d0bce7Irfan Sheriff * {@link WifiP2pInfo#groupOwnerAddress} and a flag {@link WifiP2pInfo#isGroupOwner} to indicate 779cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * if the current device is a p2p group owner. A p2p client can thus communicate with 789cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * the p2p group owner through a socket connection. 799cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 809cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * <p> Android has no platform support for service discovery yet, so applications could 819cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * run a service discovery protocol to discover services on the peer-to-peer netework. 829cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 839cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * <p class="note"><strong>Note:</strong> 849cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * Registering an application handler with {@link #initialize} requires the permissions 859cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * {@link android.Manifest.permission#ACCESS_WIFI_STATE} and 869cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * {@link android.Manifest.permission#CHANGE_WIFI_STATE} to perform any further peer-to-peer 879cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * operations. 889cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 899cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * Get an instance of this class by calling {@link android.content.Context#getSystemService(String) 9055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Context.getSystemService(Context.WIFI_P2P_SERVICE)}. 9155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * 929cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * {@see WifiP2pConfig} 939cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * {@see WifiP2pInfo} 949cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * {@see WifiP2pGroup} 959cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * {@see WifiP2pDevice} 969cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * {@see WifiP2pDeviceList} 97651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * {@see android.net.wifi.WpsInfo} 9855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 9955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncpublic class WifiP2pManager { 100651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff private static final String TAG = "WifiP2pManager"; 10155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 1029cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * Broadcast intent action to indicate whether Wi-Fi p2p is enabled or disabled. An 1039cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * extra {@link #EXTRA_WIFI_STATE} provides the state information as int. 1049cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 1059cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * @see #EXTRA_WIFI_STATE 10655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 10755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 10855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public static final String WIFI_P2P_STATE_CHANGED_ACTION = 109651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff "android.net.wifi.p2p.STATE_CHANGED"; 11055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 11155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 11255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * The lookup key for an int that indicates whether Wi-Fi p2p is enabled or disabled. 11355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Retrieve it with {@link android.content.Intent#getIntExtra(String,int)}. 11455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * 11555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * @see #WIFI_P2P_STATE_DISABLED 11655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * @see #WIFI_P2P_STATE_ENABLED 11755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 11855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public static final String EXTRA_WIFI_STATE = "wifi_p2p_state"; 11955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 12055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 12155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Wi-Fi p2p is disabled. 12255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * 12355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * @see #WIFI_P2P_STATE_CHANGED_ACTION 12455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 12555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public static final int WIFI_P2P_STATE_DISABLED = 1; 12655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 12755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 12855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Wi-Fi p2p is enabled. 12955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * 13055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * @see #WIFI_P2P_STATE_CHANGED_ACTION 13155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 13255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public static final int WIFI_P2P_STATE_ENABLED = 2; 13355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 13455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 13555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Broadcast intent action indicating that the state of Wi-Fi p2p connectivity 1369cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * has changed. One extra {@link #EXTRA_WIFI_P2P_INFO} provides the p2p connection info in 1379cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * the form of a {@link WifiP2pInfo} object. Another extra {@link #EXTRA_NETWORK_INFO} provides 1389cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * the network info in the form of a {@link android.net.NetworkInfo}. 1399cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 1409cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * @see #EXTRA_WIFI_P2P_INFO 14155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * @see #EXTRA_NETWORK_INFO 14255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 14355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 14455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public static final String WIFI_P2P_CONNECTION_CHANGED_ACTION = 145651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff "android.net.wifi.p2p.CONNECTION_STATE_CHANGE"; 14655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 14755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 148ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff * The lookup key for a {@link android.net.wifi.p2p.WifiP2pInfo} object 149ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}. 150ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff */ 151ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff public static final String EXTRA_WIFI_P2P_INFO = "wifiP2pInfo"; 152ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff 153ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff /** 15455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * The lookup key for a {@link android.net.NetworkInfo} object associated with the 15555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Wi-Fi network. Retrieve with 15655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * {@link android.content.Intent#getParcelableExtra(String)}. 15755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 15855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public static final String EXTRA_NETWORK_INFO = "networkInfo"; 15955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 16055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 161aea743aaa43a833fd8ff3dc56205197583152d5frepo sync * The lookup key for a {@link android.net.LinkProperties} object associated with the 162aea743aaa43a833fd8ff3dc56205197583152d5frepo sync * network. Retrieve with 163aea743aaa43a833fd8ff3dc56205197583152d5frepo sync * {@link android.content.Intent#getParcelableExtra(String)}. 164aea743aaa43a833fd8ff3dc56205197583152d5frepo sync * @hide 165aea743aaa43a833fd8ff3dc56205197583152d5frepo sync */ 166aea743aaa43a833fd8ff3dc56205197583152d5frepo sync public static final String EXTRA_LINK_PROPERTIES = "linkProperties"; 167aea743aaa43a833fd8ff3dc56205197583152d5frepo sync 168aea743aaa43a833fd8ff3dc56205197583152d5frepo sync /** 169aea743aaa43a833fd8ff3dc56205197583152d5frepo sync * The lookup key for a {@link android.net.LinkCapabilities} object associated with the 170aea743aaa43a833fd8ff3dc56205197583152d5frepo sync * network. Retrieve with 171aea743aaa43a833fd8ff3dc56205197583152d5frepo sync * {@link android.content.Intent#getParcelableExtra(String)}. 172aea743aaa43a833fd8ff3dc56205197583152d5frepo sync * @hide 173aea743aaa43a833fd8ff3dc56205197583152d5frepo sync */ 174aea743aaa43a833fd8ff3dc56205197583152d5frepo sync public static final String EXTRA_LINK_CAPABILITIES = "linkCapabilities"; 175aea743aaa43a833fd8ff3dc56205197583152d5frepo sync 176aea743aaa43a833fd8ff3dc56205197583152d5frepo sync /** 1779cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * Broadcast intent action indicating that the available peer list has changed. Fetch 1789cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * the changed list of peers with {@link #requestPeers} 17955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 18055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 18155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public static final String WIFI_P2P_PEERS_CHANGED_ACTION = 182651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff "android.net.wifi.p2p.PEERS_CHANGED"; 18355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 18455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 185651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * Broadcast intent action indicating that this device details have changed. 18655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 187651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 188651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public static final String WIFI_P2P_THIS_DEVICE_CHANGED_ACTION = 189651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff "android.net.wifi.p2p.THIS_DEVICE_CHANGED"; 19055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 1919cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff /** 192651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * The lookup key for a {@link android.net.wifi.p2p.WifiP2pDevice} object 193651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}. 1949cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff */ 195651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public static final String EXTRA_WIFI_P2P_DEVICE = "wifiP2pDevice"; 196651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff 197651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff IWifiP2pManager mService; 19855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 19955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int BASE = Protocol.BASE_WIFI_P2P_MANAGER; 20055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 2019cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff /** @hide */ 20255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public static final int ENABLE_P2P = BASE + 1; 2039cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff /** @hide */ 20455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public static final int ENABLE_P2P_FAILED = BASE + 2; 2059cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff /** @hide */ 20655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public static final int ENABLE_P2P_SUCCEEDED = BASE + 3; 20755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 2089cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff /** @hide */ 209ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff public static final int DISABLE_P2P = BASE + 4; 2109cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff /** @hide */ 211ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff public static final int DISABLE_P2P_FAILED = BASE + 5; 2129cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff /** @hide */ 213ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff public static final int DISABLE_P2P_SUCCEEDED = BASE + 6; 21455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 2159cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff /** @hide */ 216ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff public static final int DISCOVER_PEERS = BASE + 7; 217651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** @hide */ 218ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff public static final int DISCOVER_PEERS_FAILED = BASE + 8; 219651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** @hide */ 220ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff public static final int DISCOVER_PEERS_SUCCEEDED = BASE + 9; 22155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 2229cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff /** @hide */ 223ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff public static final int CONNECT = BASE + 10; 224651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** @hide */ 225ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff public static final int CONNECT_FAILED = BASE + 11; 226651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** @hide */ 227ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff public static final int CONNECT_SUCCEEDED = BASE + 12; 22855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 2299cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff /** @hide */ 230651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public static final int CANCEL_CONNECT = BASE + 13; 231651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** @hide */ 232651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public static final int CANCEL_CONNECT_FAILED = BASE + 14; 233651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** @hide */ 234651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public static final int CANCEL_CONNECT_SUCCEEDED = BASE + 15; 2359cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff 236651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** @hide */ 237651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public static final int CREATE_GROUP = BASE + 16; 238651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** @hide */ 239651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public static final int CREATE_GROUP_FAILED = BASE + 17; 240651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** @hide */ 241651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public static final int CREATE_GROUP_SUCCEEDED = BASE + 18; 24255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 2439cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff /** @hide */ 244651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public static final int REMOVE_GROUP = BASE + 19; 245651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** @hide */ 246651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public static final int REMOVE_GROUP_FAILED = BASE + 20; 247651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** @hide */ 248651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public static final int REMOVE_GROUP_SUCCEEDED = BASE + 21; 249651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff 250651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** @hide */ 251651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public static final int REQUEST_PEERS = BASE + 22; 252651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** @hide */ 253651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public static final int RESPONSE_PEERS = BASE + 23; 254651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff 255651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** @hide */ 256651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public static final int REQUEST_CONNECTION_INFO = BASE + 24; 257651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** @hide */ 258651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public static final int RESPONSE_CONNECTION_INFO = BASE + 25; 259651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff 260651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** @hide */ 261651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public static final int REQUEST_GROUP_INFO = BASE + 26; 262651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** @hide */ 263651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public static final int RESPONSE_GROUP_INFO = BASE + 27; 264651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff 2659cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff /** 266651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * Create a new WifiP2pManager instance. Applications use 267651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * {@link android.content.Context#getSystemService Context.getSystemService()} to retrieve 268651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * the standard {@link android.content.Context#WIFI_P2P_SERVICE Context.WIFI_P2P_SERVICE}. 269651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param service the Binder interface 270651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @hide - hide this because it takes in a parameter of type IWifiP2pManager, which 271651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * is a system private class. 2729cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff */ 273651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public WifiP2pManager(IWifiP2pManager service) { 274651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff mService = service; 275651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 27655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 2779cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff /** 278651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * Passed with {@link ActionListener#onFailure}. 279651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * Indicates that the operation failed due to an internal error. 2809cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff */ 2814be4d31f34a0fd0e23de1cbda311c07412f8d0b8Irfan Sheriff public static final int ERROR = 0; 2829cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff 2839cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff /** 284651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * Passed with {@link ActionListener#onFailure}. 285651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * Indicates that the operation failed because p2p is unsupported on the device. 2869cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff */ 2874be4d31f34a0fd0e23de1cbda311c07412f8d0b8Irfan Sheriff public static final int P2P_UNSUPPORTED = 1; 2889cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff 2899cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff /** 290651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * Passed with {@link ActionListener#onFailure}. 291651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * Indicates that the operation failed because the framework is busy and 2924be4d31f34a0fd0e23de1cbda311c07412f8d0b8Irfan Sheriff * unable to service the request 2939cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff */ 2944be4d31f34a0fd0e23de1cbda311c07412f8d0b8Irfan Sheriff public static final int BUSY = 2; 2959cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff 296651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** Interface for callback invocation when framework channel is lost */ 297651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public interface ChannelListener { 298651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** 299651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * The channel to the framework has been disconnected. 300651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * Application could try re-initializing using {@link #initialize} 301651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff */ 302651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public void onChannelDisconnected(); 303651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 3049cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff 305651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** Interface for callback invocation on an application action */ 306651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public interface ActionListener { 307651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** The operation succeeded */ 308651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public void onSuccess(); 309651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** 310651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * The operation failed 311651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param reason The reason for failure could be one of {@link #P2P_UNSUPPORTED}, 312651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * {@link #ERROR} or {@link #BUSY} 313651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff */ 314651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public void onFailure(int reason); 315651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 3169cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff 317651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** Interface for callback invocation when peer list is available */ 318651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public interface PeerListListener { 319651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** 320651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * The requested peer list is available 321651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param peers List of available peers 322651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff */ 323651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public void onPeersAvailable(WifiP2pDeviceList peers); 324651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 32555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 326651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** Interface for callback invocation when connection info is available */ 327651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public interface ConnectionInfoListener { 328651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** 329651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * The requested connection info is available 330651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param info Wi-Fi p2p connection info 331651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff */ 332651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public void onConnectionInfoAvailable(WifiP2pInfo info); 333651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 33455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 335651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** Interface for callback invocation when group info is available */ 336651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public interface GroupInfoListener { 337651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** 338651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * The requested p2p group info is available 339651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param group Wi-Fi p2p group info 340651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff */ 341651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public void onGroupInfoAvailable(WifiP2pGroup group); 34255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 34355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 34455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 345651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * A channel that connects the application to the Wifi p2p framework. 3469cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * Most p2p operations require a Channel as an argument. An instance of Channel is obtained 3479cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * by doing a call on {@link #initialize} 348aea743aaa43a833fd8ff3dc56205197583152d5frepo sync */ 349651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public static class Channel { 350651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff Channel(Looper looper, ChannelListener l) { 351651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff mAsyncChannel = new AsyncChannel(); 352651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff mHandler = new P2pHandler(looper); 353651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff mChannelListener = l; 354aea743aaa43a833fd8ff3dc56205197583152d5frepo sync } 355651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff private ChannelListener mChannelListener; 356651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff private HashMap<Integer, Object> mListenerMap = new HashMap<Integer, Object>(); 357651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff private Object mListenerMapLock = new Object(); 358651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff private int mListenerKey = 0; 359651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff 360aea743aaa43a833fd8ff3dc56205197583152d5frepo sync AsyncChannel mAsyncChannel; 361651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff P2pHandler mHandler; 362651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff class P2pHandler extends Handler { 363651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff P2pHandler(Looper looper) { 364651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff super(looper); 365651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 366651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff 367651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff @Override 368651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public void handleMessage(Message message) { 369651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff Object listener = getListener(message.arg2); 370651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff switch (message.what) { 371651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff case AsyncChannel.CMD_CHANNEL_DISCONNECTED: 372651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff if (mChannelListener != null) { 373651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff mChannelListener.onChannelDisconnected(); 374651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff mChannelListener = null; 375651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 376651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff break; 377651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /* ActionListeners grouped together */ 378651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff case WifiP2pManager.DISCOVER_PEERS_FAILED: 379651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff case WifiP2pManager.CONNECT_FAILED: 380651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff case WifiP2pManager.CANCEL_CONNECT_FAILED: 381651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff case WifiP2pManager.CREATE_GROUP_FAILED: 382651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff case WifiP2pManager.REMOVE_GROUP_FAILED: 383651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff if (listener != null) { 384651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff ((ActionListener) listener).onFailure(message.arg1); 385651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 386651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff break; 387651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /* ActionListeners grouped together */ 388651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff case WifiP2pManager.DISCOVER_PEERS_SUCCEEDED: 389651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff case WifiP2pManager.CONNECT_SUCCEEDED: 390651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff case WifiP2pManager.CANCEL_CONNECT_SUCCEEDED: 391651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff case WifiP2pManager.CREATE_GROUP_SUCCEEDED: 392651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff case WifiP2pManager.REMOVE_GROUP_SUCCEEDED: 393651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff if (listener != null) { 394651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff ((ActionListener) listener).onSuccess(); 395651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 396651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff break; 397651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff case WifiP2pManager.RESPONSE_PEERS: 398651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff WifiP2pDeviceList peers = (WifiP2pDeviceList) message.obj; 399651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff if (listener != null) { 400651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff ((PeerListListener) listener).onPeersAvailable(peers); 401651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 402651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff break; 403651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff case WifiP2pManager.RESPONSE_CONNECTION_INFO: 404651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff WifiP2pInfo wifiP2pInfo = (WifiP2pInfo) message.obj; 405651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff if (listener != null) { 406651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff ((ConnectionInfoListener) listener).onConnectionInfoAvailable(wifiP2pInfo); 407651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 408651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff break; 409651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff case WifiP2pManager.RESPONSE_GROUP_INFO: 410651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff WifiP2pGroup group = (WifiP2pGroup) message.obj; 411651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff if (listener != null) { 412651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff ((GroupInfoListener) listener).onGroupInfoAvailable(group); 413651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 414651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff break; 415651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff default: 416651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff Log.d(TAG, "Ignored " + message); 417651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff break; 418651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 419651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 420651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 421651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff 422651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff int putListener(Object listener) { 423651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff if (listener == null) return 0; 424651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff int key; 425651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff synchronized (mListenerMapLock) { 426651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff key = mListenerKey++; 427651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff mListenerMap.put(key, listener); 428651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 429651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff return key; 430651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 431651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff 432651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff Object getListener(int key) { 433651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff synchronized (mListenerMapLock) { 434651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff return mListenerMap.remove(key); 435651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 436651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 437aea743aaa43a833fd8ff3dc56205197583152d5frepo sync } 438aea743aaa43a833fd8ff3dc56205197583152d5frepo sync 439aea743aaa43a833fd8ff3dc56205197583152d5frepo sync /** 440651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * Registers the application with the Wi-Fi framework. This function 4419cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * must be the first to be called before any p2p operations are performed. 4429cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 44355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * @param srcContext is the context of the source 444651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param srcLooper is the Looper on which the callbacks are receivied 445651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param listener for callback at loss of framework communication. Can be null. 4469cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * @return Channel instance that is necessary for performing any further p2p operations 44755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 448651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public Channel initialize(Context srcContext, Looper srcLooper, ChannelListener listener) { 44955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync Messenger messenger = getMessenger(); 450aea743aaa43a833fd8ff3dc56205197583152d5frepo sync if (messenger == null) return null; 451aea743aaa43a833fd8ff3dc56205197583152d5frepo sync 452651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff Channel c = new Channel(srcLooper, listener); 453651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff if (c.mAsyncChannel.connectSync(srcContext, c.mHandler, messenger) 454aea743aaa43a833fd8ff3dc56205197583152d5frepo sync == AsyncChannel.STATUS_SUCCESSFUL) { 455aea743aaa43a833fd8ff3dc56205197583152d5frepo sync return c; 456aea743aaa43a833fd8ff3dc56205197583152d5frepo sync } else { 457aea743aaa43a833fd8ff3dc56205197583152d5frepo sync return null; 458aea743aaa43a833fd8ff3dc56205197583152d5frepo sync } 45955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 46055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 46155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 46255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Sends in a request to the system to enable p2p. This will pop up a dialog 46355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * to the user and upon authorization will enable p2p. 4649cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * @hide 46555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 466aea743aaa43a833fd8ff3dc56205197583152d5frepo sync public void enableP2p(Channel c) { 467aea743aaa43a833fd8ff3dc56205197583152d5frepo sync if (c == null) return; 468aea743aaa43a833fd8ff3dc56205197583152d5frepo sync c.mAsyncChannel.sendMessage(ENABLE_P2P); 46955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 47055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 47155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 47255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Sends in a request to the system to disable p2p. This will pop up a dialog 47355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * to the user and upon authorization will enable p2p. 4749cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * @hide 47555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 476aea743aaa43a833fd8ff3dc56205197583152d5frepo sync public void disableP2p(Channel c) { 477aea743aaa43a833fd8ff3dc56205197583152d5frepo sync if (c == null) return; 478aea743aaa43a833fd8ff3dc56205197583152d5frepo sync c.mAsyncChannel.sendMessage(DISABLE_P2P); 47955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 48055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 48155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 4829cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * Initiate peer discovery. A discovery process involves scanning for available Wi-Fi peers 4839cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * for the purpose of establishing a connection. 4849cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 4859cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * <p> The function call immediately returns after sending a discovery request 486651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * to the framework. The application is notified of a success or failure to initiate 487651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * discovery through listener callbacks {@link ActionListener#onSuccess} or 488651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * {@link ActionListener#onFailure}. 4899cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 4909cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * <p> The discovery remains active until a connection is initiated or 4919cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * a p2p group is formed. Register for {@link #WIFI_P2P_PEERS_CHANGED_ACTION} intent to 4929cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * determine when the framework notifies of a change as peers are discovered. 4939cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 4949cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * <p> Upon receiving a {@link #WIFI_P2P_PEERS_CHANGED_ACTION} intent, an application 495651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * can request for the list of peers using {@link #requestPeers}. 496651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * 497651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param c is the channel created at {@link #initialize} 498651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param listener for callbacks on success or failure. Can be null. 49955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 500651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public void discoverPeers(Channel c, ActionListener listener) { 501aea743aaa43a833fd8ff3dc56205197583152d5frepo sync if (c == null) return; 502651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff c.mAsyncChannel.sendMessage(DISCOVER_PEERS, 0, c.putListener(listener)); 50355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 50455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 50555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 5069cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * Start a p2p connection to a device with the specified configuration. 5079cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 5089cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * <p> The function call immediately returns after sending a connection request 509651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * to the framework. The application is notified of a success or failure to initiate 510651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * connect through listener callbacks {@link ActionListener#onSuccess} or 511651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * {@link ActionListener#onFailure}. 51255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * 5139cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * <p> Register for {@link #WIFI_P2P_CONNECTION_CHANGED_ACTION} intent to 5149cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * determine when the framework notifies of a change in connectivity. 5159cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 5169cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * <p> If the current device is not part of a p2p group, a connect request initiates 5179cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * a group negotiation with the peer. 5189cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 5199cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * <p> If the current device is part of an existing p2p group or has created 5209cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * a p2p group with {@link #createGroup}, an invitation to join the group is sent to 5219cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * the peer device. 5229cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 523651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param c is the channel created at {@link #initialize} 524651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param config options as described in {@link WifiP2pConfig} class 525651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param listener for callbacks on success or failure. Can be null. 52655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 527651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public void connect(Channel c, WifiP2pConfig config, ActionListener listener) { 528aea743aaa43a833fd8ff3dc56205197583152d5frepo sync if (c == null) return; 529651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff c.mAsyncChannel.sendMessage(CONNECT, 0, c.putListener(listener), config); 530651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff } 531651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff 532651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff /** 533651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * Cancel any ongoing p2p group negotiation 534651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * 535651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * <p> The function call immediately returns after sending a connection cancellation request 536651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * to the framework. The application is notified of a success or failure to initiate 537651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * cancellation through listener callbacks {@link ActionListener#onSuccess} or 538651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * {@link ActionListener#onFailure}. 539651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * 540651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param c is the channel created at {@link #initialize} 541651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param listener for callbacks on success or failure. Can be null. 542651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff */ 543651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public void cancelConnect(Channel c, ActionListener listener) { 544651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff if (c == null) return; 545651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff c.mAsyncChannel.sendMessage(CANCEL_CONNECT, 0, c.putListener(listener)); 54655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 54755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 54855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 5499cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * Create a p2p group with the current device as the group owner. This essentially creates 5509cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * an access point that can accept connections from legacy clients as well as other p2p 5519cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * devices. 552651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * 553651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * <p class="note"><strong>Note:</strong> 554651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * This function would normally not be used unless the current device needs 5559cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * to form a p2p connection with a legacy client 5569cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 5579cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * <p> The function call immediately returns after sending a group creation request 558651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * to the framework. The application is notified of a success or failure to initiate 559651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * group creation through listener callbacks {@link ActionListener#onSuccess} or 560651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * {@link ActionListener#onFailure}. 561651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * 562651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * <p> Application can request for the group details with {@link #requestGroupInfo}. 5639cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 564651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param c is the channel created at {@link #initialize} 565651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param listener for callbacks on success or failure. Can be null. 56655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 567651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public void createGroup(Channel c, ActionListener listener) { 568aea743aaa43a833fd8ff3dc56205197583152d5frepo sync if (c == null) return; 569651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff c.mAsyncChannel.sendMessage(CREATE_GROUP, 0, c.putListener(listener)); 57055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 57155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 57255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 5739cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * Remove the current p2p group. 5749cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * 5759cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * <p> The function call immediately returns after sending a group removal request 576651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * to the framework. The application is notified of a success or failure to initiate 577651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * group removal through listener callbacks {@link ActionListener#onSuccess} or 578651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * {@link ActionListener#onFailure}. 579651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * 580651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param c is the channel created at {@link #initialize} 581651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param listener for callbacks on success or failure. Can be null. 58255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 583651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public void removeGroup(Channel c, ActionListener listener) { 584aea743aaa43a833fd8ff3dc56205197583152d5frepo sync if (c == null) return; 585651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff c.mAsyncChannel.sendMessage(REMOVE_GROUP, 0, c.putListener(listener)); 58655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 58755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 58855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 589651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * Request the current list of peers. 590651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * 591651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param c is the channel created at {@link #initialize} 592651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param listener for callback when peer list is available. Can be null. 59355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 594651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public void requestPeers(Channel c, PeerListListener listener) { 595aea743aaa43a833fd8ff3dc56205197583152d5frepo sync if (c == null) return; 596651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff c.mAsyncChannel.sendMessage(REQUEST_PEERS, 0, c.putListener(listener)); 59755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 59855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 59955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 600651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * Request device connection info. 601651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * 602651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param c is the channel created at {@link #initialize} 603651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param listener for callback when connection info is available. Can be null. 60455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 605651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public void requestConnectionInfo(Channel c, ConnectionInfoListener listener) { 606aea743aaa43a833fd8ff3dc56205197583152d5frepo sync if (c == null) return; 607651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff c.mAsyncChannel.sendMessage(REQUEST_CONNECTION_INFO, 0, c.putListener(listener)); 608ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff } 609ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff 610ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff /** 611651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * Request p2p group info. 612651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * 613651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param c is the channel created at {@link #initialize} 614651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff * @param listener for callback when group info is available. Can be null. 6159cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff */ 616651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff public void requestGroupInfo(Channel c, GroupInfoListener listener) { 6179cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff if (c == null) return; 618651cdfcbac6245f570475991588ddc2d30265e8dIrfan Sheriff c.mAsyncChannel.sendMessage(REQUEST_GROUP_INFO, 0, c.putListener(listener)); 6199cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff } 62055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 62155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 62255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Get a reference to WifiP2pService handler. This is used to establish 62355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * an AsyncChannel communication with WifiService 62455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * 62555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * @return Messenger pointing to the WifiP2pService handler 62655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * @hide 62755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 62855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public Messenger getMessenger() { 62955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync try { 63055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync return mService.getMessenger(); 63155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } catch (RemoteException e) { 63255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync return null; 63355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 63455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 635aea743aaa43a833fd8ff3dc56205197583152d5frepo sync 63655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync} 637