FileDocCategorySizeDatePackage
WifiP2pDevice.javaAPI DocAndroid 5.1 API14551Thu Mar 12 22:22:44 GMT 2015android.net.wifi.p2p

WifiP2pDevice

public class WifiP2pDevice extends Object implements android.os.Parcelable
A class representing a Wi-Fi p2p device Note that the operations are not thread safe {@see WifiP2pManager}

Fields Summary
private static final String
TAG
public String
deviceName
The device name is a user friendly string to identify a Wi-Fi p2p device
public String
deviceAddress
The device MAC address uniquely identifies a Wi-Fi p2p device
public String
primaryDeviceType
Primary device type identifies the type of device. For example, an application could filter the devices discovered to only display printers if the purpose is to enable a printing action from the user. See the Wi-Fi Direct technical specification for the full list of standard device types supported.
public String
secondaryDeviceType
Secondary device type is an optional attribute that can be provided by a device in addition to the primary device type.
private static final int
WPS_CONFIG_DISPLAY
private static final int
WPS_CONFIG_PUSHBUTTON
private static final int
WPS_CONFIG_KEYPAD
private static final int
DEVICE_CAPAB_SERVICE_DISCOVERY
private static final int
DEVICE_CAPAB_CLIENT_DISCOVERABILITY
private static final int
DEVICE_CAPAB_CONCURRENT_OPER
private static final int
DEVICE_CAPAB_INFRA_MANAGED
private static final int
DEVICE_CAPAB_DEVICE_LIMIT
private static final int
DEVICE_CAPAB_INVITATION_PROCEDURE
private static final int
GROUP_CAPAB_GROUP_OWNER
private static final int
GROUP_CAPAB_PERSISTENT_GROUP
private static final int
GROUP_CAPAB_GROUP_LIMIT
private static final int
GROUP_CAPAB_INTRA_BSS_DIST
private static final int
GROUP_CAPAB_CROSS_CONN
private static final int
GROUP_CAPAB_PERSISTENT_RECONN
private static final int
GROUP_CAPAB_GROUP_FORMATION
public int
wpsConfigMethodsSupported
WPS config methods supported
public int
deviceCapability
Device capability
public int
groupCapability
Group capability
public static final int
CONNECTED
public static final int
INVITED
public static final int
FAILED
public static final int
AVAILABLE
public static final int
UNAVAILABLE
public int
status
Device connection status
public WifiP2pWfdInfo
wfdInfo
private static final Pattern
detailedDevicePattern
Detailed device string pattern with WFD info Example: P2P-DEVICE-FOUND 00:18:6b:de:a3:6e p2p_dev_addr=00:18:6b:de:a3:6e pri_dev_type=1-0050F204-1 name='DWD-300-DEA36E' config_methods=0x188 dev_capab=0x21 group_capab=0x9
private static final Pattern
twoTokenPattern
2 token device address pattern Example: P2P-DEVICE-LOST p2p_dev_addr=fa:7b:7a:42:02:13 AP-STA-DISCONNECTED 42:fc:89:a8:96:09
private static final Pattern
threeTokenPattern
3 token device address pattern Example: AP-STA-CONNECTED 42:fc:89:a8:96:09 p2p_dev_addr=fa:7b:7a:42:02:13 AP-STA-DISCONNECTED 42:fc:89:a8:96:09 p2p_dev_addr=fa:7b:7a:42:02:13
public static final Creator
CREATOR
Implement the Parcelable interface
Constructors Summary
public WifiP2pDevice()



      
    
public WifiP2pDevice(WifiP2pDevice source)
copy constructor

        if (source != null) {
            deviceName = source.deviceName;
            deviceAddress = source.deviceAddress;
            primaryDeviceType = source.primaryDeviceType;
            secondaryDeviceType = source.secondaryDeviceType;
            wpsConfigMethodsSupported = source.wpsConfigMethodsSupported;
            deviceCapability = source.deviceCapability;
            groupCapability = source.groupCapability;
            status = source.status;
            wfdInfo = new WifiP2pWfdInfo(source.wfdInfo);
        }
    
public WifiP2pDevice(String string)

param
string formats supported include P2P-DEVICE-FOUND fa:7b:7a:42:02:13 p2p_dev_addr=fa:7b:7a:42:02:13 pri_dev_type=1-0050F204-1 name='p2p-TEST1' config_methods=0x188 dev_capab=0x27 group_capab=0x0 wfd_dev_info=000006015d022a0032 P2P-DEVICE-LOST p2p_dev_addr=fa:7b:7a:42:02:13 AP-STA-CONNECTED 42:fc:89:a8:96:09 [p2p_dev_addr=02:90:4c:a0:92:54] AP-STA-DISCONNECTED 42:fc:89:a8:96:09 [p2p_dev_addr=02:90:4c:a0:92:54] fa:7b:7a:42:02:13 Note: The events formats can be looked up in the wpa_supplicant code
hide

        String[] tokens = string.split("[ \n]");
        Matcher match;

        if (tokens.length < 1) {
            throw new IllegalArgumentException("Malformed supplicant event");
        }

        switch (tokens.length) {
            case 1:
                /* Just a device address */
                deviceAddress = string;
                return;
            case 2:
                match = twoTokenPattern.matcher(string);
                if (!match.find()) {
                    throw new IllegalArgumentException("Malformed supplicant event");
                }
                deviceAddress = match.group(2);
                return;
            case 3:
                match = threeTokenPattern.matcher(string);
                if (!match.find()) {
                    throw new IllegalArgumentException("Malformed supplicant event");
                }
                deviceAddress = match.group(1);
                return;
            default:
                match = detailedDevicePattern.matcher(string);
                if (!match.find()) {
                    throw new IllegalArgumentException("Malformed supplicant event");
                }

                deviceAddress = match.group(3);
                primaryDeviceType = match.group(4);
                deviceName = match.group(5);
                wpsConfigMethodsSupported = parseHex(match.group(6));
                deviceCapability = parseHex(match.group(7));
                groupCapability = parseHex(match.group(8));
                if (match.group(9) != null) {
                    String str = match.group(10);
                    wfdInfo = new WifiP2pWfdInfo(parseHex(str.substring(0,4)),
                            parseHex(str.substring(4,8)),
                            parseHex(str.substring(8,12)));
                }
                break;
        }

        if (tokens[0].startsWith("P2P-DEVICE-FOUND")) {
            status = AVAILABLE;
        }
    
Methods Summary
public intdescribeContents()
Implement the Parcelable interface

        return 0;
    
public booleanequals(java.lang.Object obj)

        if (this == obj) return true;
        if (!(obj instanceof WifiP2pDevice)) return false;

        WifiP2pDevice other = (WifiP2pDevice) obj;
        if (other == null || other.deviceAddress == null) {
            return (deviceAddress == null);
        }
        return other.deviceAddress.equals(deviceAddress);
    
public booleanisDeviceLimit()
Returns true if the device reaches the limit. {@hide}

        return (deviceCapability & DEVICE_CAPAB_DEVICE_LIMIT) != 0;
    
public booleanisGroupLimit()
Returns true if the group reaches the limit. {@hide}

        return (groupCapability & GROUP_CAPAB_GROUP_LIMIT) != 0;
    
public booleanisGroupOwner()
Returns true if the device is a group owner

        return (groupCapability & GROUP_CAPAB_GROUP_OWNER) != 0;
    
public booleanisInvitationCapable()
Returns true if the device is capable of invitation {@hide}

        return (deviceCapability & DEVICE_CAPAB_INVITATION_PROCEDURE) != 0;
    
public booleanisServiceDiscoveryCapable()
Returns true if the device is capable of service discovery

        return (deviceCapability & DEVICE_CAPAB_SERVICE_DISCOVERY) != 0;
    
private intparseHex(java.lang.String hexString)


    //supported formats: 0x1abc, 0X1abc, 1abc
        
        int num = 0;
        if (hexString.startsWith("0x") || hexString.startsWith("0X")) {
            hexString = hexString.substring(2);
        }

        try {
            num = Integer.parseInt(hexString, 16);
        } catch(NumberFormatException e) {
            Log.e(TAG, "Failed to parse hex string " + hexString);
        }
        return num;
    
public java.lang.StringtoString()

        StringBuffer sbuf = new StringBuffer();
        sbuf.append("Device: ").append(deviceName);
        sbuf.append("\n deviceAddress: ").append(deviceAddress);
        sbuf.append("\n primary type: ").append(primaryDeviceType);
        sbuf.append("\n secondary type: ").append(secondaryDeviceType);
        sbuf.append("\n wps: ").append(wpsConfigMethodsSupported);
        sbuf.append("\n grpcapab: ").append(groupCapability);
        sbuf.append("\n devcapab: ").append(deviceCapability);
        sbuf.append("\n status: ").append(status);
        sbuf.append("\n wfdInfo: ").append(wfdInfo);
        return sbuf.toString();
    
public voidupdate(android.net.wifi.p2p.WifiP2pDevice device)
Update device details. This will be throw an exception if the device address does not match.

param
device to be updated
throws
IllegalArgumentException if the device is null or device address does not match
hide

        updateSupplicantDetails(device);
        status = device.status;
    
public voidupdateSupplicantDetails(android.net.wifi.p2p.WifiP2pDevice device)
Updates details obtained from supplicant @hide

        if (device == null) {
            throw new IllegalArgumentException("device is null");
        }
        if (device.deviceAddress == null) {
            throw new IllegalArgumentException("deviceAddress is null");
        }
        if (!deviceAddress.equals(device.deviceAddress)) {
            throw new IllegalArgumentException("deviceAddress does not match");
        }
        deviceName = device.deviceName;
        primaryDeviceType = device.primaryDeviceType;
        secondaryDeviceType = device.secondaryDeviceType;
        wpsConfigMethodsSupported = device.wpsConfigMethodsSupported;
        deviceCapability = device.deviceCapability;
        groupCapability = device.groupCapability;
        wfdInfo = device.wfdInfo;
    
public booleanwpsDisplaySupported()
Returns true if WPS display configuration is supported

        return (wpsConfigMethodsSupported & WPS_CONFIG_DISPLAY) != 0;
    
public booleanwpsKeypadSupported()
Returns true if WPS keypad configuration is supported

        return (wpsConfigMethodsSupported & WPS_CONFIG_KEYPAD) != 0;
    
public booleanwpsPbcSupported()
Returns true if WPS push button configuration is supported

        return (wpsConfigMethodsSupported & WPS_CONFIG_PUSHBUTTON) != 0;
    
public voidwriteToParcel(android.os.Parcel dest, int flags)
Implement the Parcelable interface

        dest.writeString(deviceName);
        dest.writeString(deviceAddress);
        dest.writeString(primaryDeviceType);
        dest.writeString(secondaryDeviceType);
        dest.writeInt(wpsConfigMethodsSupported);
        dest.writeInt(deviceCapability);
        dest.writeInt(groupCapability);
        dest.writeInt(status);
        if (wfdInfo != null) {
            dest.writeInt(1);
            wfdInfo.writeToParcel(dest, flags);
        } else {
            dest.writeInt(0);
        }