FileDocCategorySizeDatePackage
WifiP2pServiceImpl.javaAPI DocAndroid 5.1 API135777Thu Mar 12 22:22:52 GMT 2015com.android.server.wifi.p2p

WifiP2pServiceImpl

public final class WifiP2pServiceImpl extends IWifiP2pManager.Stub
WifiP2pService includes a state machine to perform Wi-Fi p2p operations. Applications communicate with this service to issue device discovery and connectivity requests through the WifiP2pManager interface. The state machine communicates with the wifi driver through wpa_supplicant and handles the event responses through WifiMonitor. Note that the term Wifi when used without a p2p suffix refers to the client mode of Wifi operation
hide

Fields Summary
private static final String
TAG
private static final boolean
DBG
private static final String
NETWORKTYPE
private android.content.Context
mContext
private String
mInterface
private android.app.Notification
mNotification
android.os.INetworkManagementService
mNwService
private android.net.DhcpStateMachine
mDhcpStateMachine
private P2pStateMachine
mP2pStateMachine
private com.android.internal.util.AsyncChannel
mReplyChannel
private com.android.internal.util.AsyncChannel
mWifiChannel
private static final Boolean
JOIN_GROUP
private static final Boolean
FORM_GROUP
private static final Boolean
RELOAD
private static final Boolean
NO_RELOAD
private static final int
GROUP_CREATING_WAIT_TIME_MS
private static int
mGroupCreatingTimeoutIndex
private static final int
DISABLE_P2P_WAIT_TIME_MS
private static int
mDisableP2pTimeoutIndex
private static final int
DISCOVER_TIMEOUT_S
private static final int
GROUP_IDLE_TIME_S
private static final int
BASE
public static final int
GROUP_CREATING_TIMED_OUT
private static final int
PEER_CONNECTION_USER_ACCEPT
private static final int
PEER_CONNECTION_USER_REJECT
private static final int
DROP_WIFI_USER_ACCEPT
private static final int
DROP_WIFI_USER_REJECT
public static final int
DISABLE_P2P_TIMED_OUT
public static final int
P2P_CONNECTION_CHANGED
public static final int
DISCONNECT_WIFI_REQUEST
public static final int
DISCONNECT_WIFI_RESPONSE
public static final int
SET_MIRACAST_MODE
public static final int
BLOCK_DISCOVERY
public static final int
SET_COUNTRY_CODE
public static final int
ENABLED
public static final int
DISABLED
private final boolean
mP2pSupported
private android.net.wifi.p2p.WifiP2pDevice
mThisDevice
private boolean
mAutonomousGroup
private boolean
mJoinExistingGroup
private boolean
mDiscoveryStarted
private boolean
mDiscoveryBlocked
private String
mLastSetCountryCode
private boolean
mDiscoveryPostponed
private android.net.NetworkInfo
mNetworkInfo
private boolean
mTemporarilyDisconnectedWifi
private byte
mServiceTransactionId
private String
mServiceDiscReqId
private HashMap
mClientInfoList
private static final String
SERVER_ADDRESS
private ClientHandler
mClientHandler
Constructors Summary
public WifiP2pServiceImpl(android.content.Context context)

        mContext = context;

        //STOPSHIP: get this from native side
        mInterface = "p2p0";
        mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_WIFI_P2P, 0, NETWORKTYPE, "");

        mP2pSupported = mContext.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_WIFI_DIRECT);

        mThisDevice.primaryDeviceType = mContext.getResources().getString(
                com.android.internal.R.string.config_wifi_p2p_device_type);

        HandlerThread wifiP2pThread = new HandlerThread("WifiP2pService");
        wifiP2pThread.start();
        mClientHandler = new ClientHandler(wifiP2pThread.getLooper());

        mP2pStateMachine = new P2pStateMachine(TAG, wifiP2pThread.getLooper(), mP2pSupported);
        mP2pStateMachine.start();
    
Methods Summary
private intcheckConnectivityInternalPermission()

        return mContext.checkCallingOrSelfPermission(
                android.Manifest.permission.CONNECTIVITY_INTERNAL);
    
private intcheckLocationHardwarePermission()

        return mContext.checkCallingOrSelfPermission(
                android.Manifest.permission.LOCATION_HARDWARE);
    
public voidconnectivityServiceReady()

        IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
        mNwService = INetworkManagementService.Stub.asInterface(b);
    
protected voiddump(java.io.FileDescriptor fd, java.io.PrintWriter pw, java.lang.String[] args)

        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
                != PackageManager.PERMISSION_GRANTED) {
            pw.println("Permission Denial: can't dump WifiP2pService from from pid="
                    + Binder.getCallingPid()
                    + ", uid=" + Binder.getCallingUid());
            return;
        }
        mP2pStateMachine.dump(fd, pw, args);
        pw.println("mAutonomousGroup " + mAutonomousGroup);
        pw.println("mJoinExistingGroup " + mJoinExistingGroup);
        pw.println("mDiscoveryStarted " + mDiscoveryStarted);
        pw.println("mNetworkInfo " + mNetworkInfo);
        pw.println("mTemporarilyDisconnectedWifi " + mTemporarilyDisconnectedWifi);
        pw.println("mServiceDiscReqId " + mServiceDiscReqId);
        pw.println();
    
private voidenforceAccessPermission()

        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_WIFI_STATE,
                "WifiP2pService");
    
private voidenforceChangePermission()

        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.CHANGE_WIFI_STATE,
                "WifiP2pService");
    
private voidenforceConnectivityInternalOrLocationHardwarePermission()

        if (checkConnectivityInternalPermission() != PackageManager.PERMISSION_GRANTED
                && checkLocationHardwarePermission() != PackageManager.PERMISSION_GRANTED) {
            enforceConnectivityInternalPermission();
        }
    
private voidenforceConnectivityInternalPermission()

        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.CONNECTIVITY_INTERNAL,
                "WifiP2pService");
    
public android.os.MessengergetMessenger()
Get a reference to handler. This is used by a client to establish an AsyncChannel communication with WifiP2pService

        enforceAccessPermission();
        enforceChangePermission();
        return new Messenger(mClientHandler);
    
public android.os.MessengergetP2pStateMachineMessenger()
Get a reference to handler. This is used by a WifiStateMachine to establish an AsyncChannel communication with P2pStateMachine

hide

        enforceConnectivityInternalOrLocationHardwarePermission();
        enforceAccessPermission();
        enforceChangePermission();
        return new Messenger(mP2pStateMachine.getHandler());
    
public voidsetMiracastMode(int mode)
This is used to provide information to drivers to optimize performance depending on the current mode of operation. 0 - disabled 1 - source operation 2 - sink operation As an example, the driver could reduce the channel dwell time during scanning when acting as a source or sink to minimize impact on miracast.

        enforceConnectivityInternalPermission();
        mP2pStateMachine.sendMessage(SET_MIRACAST_MODE, mode);