WifiP2pDevice.java revision 55bc5f3e0408bcb5a39a6732de0b2d1aa99a55be
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.os.Parcelable; 2055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncimport android.os.Parcel; 2155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncimport android.util.Log; 2255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 2355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncimport java.util.regex.Pattern; 2455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 2555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync/** 2655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * A class representing a Wi-Fi p2p device 2755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * @hide 2855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 2955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncpublic class WifiP2pDevice implements Parcelable { 3055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 3155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final String TAG = "WifiP2pDevice"; 3255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 3355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Device name 3455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 3555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public String deviceName; 3655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 3755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 3855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Device MAC address 3955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 4055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public String deviceAddress; 4155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 4255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 4355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * interfaceAddress 4455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * 4555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * This address is used during group owner negotiation as the Intended 4655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * P2P Interface Address and the group interface will be created with 4755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * address as the local address in case of successfully completed 4855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * negotiation. 4955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 5055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public String interfaceAddress; 5155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 5255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 5355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Primary device type 5455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 5555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public String primaryDeviceType; 5655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 5755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 5855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Secondary device type 5955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 6055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public String secondaryDeviceType; 6155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 6255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 6355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync // These definitions match the ones in wpa_supplicant 6455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /* WPS config methods supported */ 6555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int WPS_CONFIG_USBA = 0x0001; 6655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int WPS_CONFIG_ETHERNET = 0x0002; 6755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int WPS_CONFIG_LABEL = 0x0004; 6855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int WPS_CONFIG_DISPLAY = 0x0008; 6955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int WPS_CONFIG_EXT_NFC_TOKEN = 0x0010; 7055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int WPS_CONFIG_INT_NFC_TOKEN = 0x0020; 7155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int WPS_CONFIG_NFC_INTERFACE = 0x0040; 7255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int WPS_CONFIG_PUSHBUTTON = 0x0080; 7355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int WPS_CONFIG_KEYPAD = 0x0100; 7455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int WPS_CONFIG_VIRT_PUSHBUTTON = 0x0280; 7555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int WPS_CONFIG_PHY_PUSHBUTTON = 0x0480; 7655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int WPS_CONFIG_VIRT_DISPLAY = 0x2008; 7755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int WPS_CONFIG_PHY_DISPLAY = 0x4008; 7855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 7955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /* Device Capability bitmap */ 8055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int DEVICE_CAPAB_SERVICE_DISCOVERY = 1; 8155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int DEVICE_CAPAB_CLIENT_DISCOVERABILITY = 1<<1; 8255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int DEVICE_CAPAB_CONCURRENT_OPER = 1<<2; 8355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int DEVICE_CAPAB_INFRA_MANAGED = 1<<3; 8455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int DEVICE_CAPAB_DEVICE_LIMIT = 1<<4; 8555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int DEVICE_CAPAB_INVITATION_PROCEDURE = 1<<5; 8655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 8755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /* Group Capability bitmap */ 8855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int GROUP_CAPAB_GROUP_OWNER = 1; 8955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int GROUP_CAPAB_PERSISTENT_GROUP = 1<<1; 9055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int GROUP_CAPAB_GROUP_LIMIT = 1<<2; 9155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int GROUP_CAPAB_INTRA_BSS_DIST = 1<<3; 9255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int GROUP_CAPAB_CROSS_CONN = 1<<4; 9355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int GROUP_CAPAB_PERSISTENT_RECONN = 1<<5; 9455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private static final int GROUP_CAPAB_GROUP_FORMATION = 1<<6; 9555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 9655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 9755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * WPS config methods supported 9855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 9955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public int wpsConfigMethodsSupported; 10055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 10155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 10255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Device capability 10355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 10455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public int deviceCapability; 10555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 10655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 10755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Group capability 10855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 10955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public int groupCapability; 11055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 11155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public enum Status { 11255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync CONNECTED, 11355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync INVITED, 11455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync FAILED, 11555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync AVAILABLE, 11655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync UNAVAILABLE, 11755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 11855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 11955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public Status status = Status.UNAVAILABLE; 12055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 12155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public WifiP2pDevice() { 12255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 12355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 12455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 12555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * @param string formats supported include 12655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * P2P-DEVICE-FOUND fa:7b:7a:42:02:13 p2p_dev_addr=fa:7b:7a:42:02:13 12755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * pri_dev_type=1-0050F204-1 name='p2p-TEST1' config_methods=0x188 dev_capab=0x27 12855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * group_capab=0x0 12955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * 13055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * P2P-DEVICE-LOST p2p_dev_addr=fa:7b:7a:42:02:13 13155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * 13255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * fa:7b:7a:42:02:13 13355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * 13455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * P2P-PROV-DISC-PBC-REQ 42:fc:89:e1:e2:27 p2p_dev_addr=42:fc:89:e1:e2:27 13555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27 13655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * group_capab=0x0 13755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * 13855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * P2P-PROV-DISC-ENTER-PIN 42:fc:89:e1:e2:27 p2p_dev_addr=42:fc:89:e1:e2:27 13955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27 14055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * group_capab=0x0 14155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * 14255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * P2P-PROV-DISC-SHOW-PIN 42:fc:89:e1:e2:27 44490607 p2p_dev_addr=42:fc:89:e1:e2:27 14355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27 14455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * group_capab=0x0 14555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * 14655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Note: The events formats can be looked up in the wpa_supplicant code 14755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 14855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public WifiP2pDevice(String string) throws IllegalArgumentException { 14955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync String[] tokens = string.split(" "); 15055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 15155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (tokens.length < 1) { 15255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync throw new IllegalArgumentException("Malformed supplicant event"); 15355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 15455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 15555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /* Just a device address */ 15655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (tokens.length == 1) { 15755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync deviceAddress = string; 15855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync return; 15955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 16055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 16155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync Pattern p = Pattern.compile("(?:[0-9a-f]{2}:){5}[0-9a-f]{2}", Pattern.CASE_INSENSITIVE); 16255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (p.matcher(tokens[1]).matches()) interfaceAddress = tokens[1]; 16355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 16455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync for (String token : tokens) { 16555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync String[] nameValue = token.split("="); 16655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (nameValue.length != 2) continue; 16755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 16855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (nameValue[0].equals("p2p_dev_addr")) { 16955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync deviceAddress = nameValue[1]; 17055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync continue; 17155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 17255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 17355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (nameValue[0].equals("pri_dev_type")) { 17455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync primaryDeviceType = nameValue[1]; 17555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync continue; 17655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 17755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 17855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (nameValue[0].equals("name")) { 17955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync deviceName = trimQuotes(nameValue[1]); 18055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 18155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 18255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (nameValue[0].equals("config_methods")) { 18355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync wpsConfigMethodsSupported = parseHex(nameValue[1]); 18455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync continue; 18555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 18655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 18755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (nameValue[0].equals("dev_capab")) { 18855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync deviceCapability = parseHex(nameValue[1]); 18955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync continue; 19055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 19155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 19255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (nameValue[0].equals("group_capab")) { 19355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync groupCapability = parseHex(nameValue[1]); 19455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync continue; 19555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 19655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 19755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 19855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (tokens[0].startsWith("P2P-DEVICE-FOUND")) { 19955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync status = Status.AVAILABLE; 20055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 20155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 20255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 20355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public boolean isGroupOwner() { 20455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync return (groupCapability & GROUP_CAPAB_GROUP_OWNER) != 0; 20555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 20655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 20755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync @Override 20855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public boolean equals(Object obj) { 20955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (this == obj) return true; 21055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (!(obj instanceof WifiP2pDevice)) return false; 21155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 21255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync WifiP2pDevice other = (WifiP2pDevice) obj; 21355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (other == null || other.deviceAddress == null) { 21455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync return (deviceAddress == null); 21555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 21655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync //STOPSHIP: fix later 21755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync //return other.deviceAddress.equals(deviceAddress); 21855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync return other.deviceAddress.startsWith(deviceAddress.substring(0,8)); 21955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 22055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 22155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public String toString() { 22255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync StringBuffer sbuf = new StringBuffer(); 22355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync sbuf.append("Device: ").append(deviceName); 22455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync sbuf.append("\n deviceAddress: ").append(deviceAddress); 22555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync sbuf.append("\n interfaceAddress: ").append(interfaceAddress); 22655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync sbuf.append("\n primary type: ").append(primaryDeviceType); 22755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync sbuf.append("\n secondary type: ").append(secondaryDeviceType); 22855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync sbuf.append("\n wps: ").append(wpsConfigMethodsSupported); 22955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync sbuf.append("\n grpcapab: ").append(groupCapability); 23055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync sbuf.append("\n devcapab: ").append(deviceCapability); 23155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync sbuf.append("\n status: ").append(status); 23255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync return sbuf.toString(); 23355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 23455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 23555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** Implement the Parcelable interface {@hide} */ 23655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public int describeContents() { 23755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync return 0; 23855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 23955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 24055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** copy constructor {@hide} */ 24155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public WifiP2pDevice(WifiP2pDevice source) { 24255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (source != null) { 24355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync deviceName = source.deviceName; 24455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync deviceAddress = source.deviceAddress; 24555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync interfaceAddress = source.interfaceAddress; 24655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync primaryDeviceType = source.primaryDeviceType; 24755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync secondaryDeviceType = source.secondaryDeviceType; 24855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync wpsConfigMethodsSupported = source.wpsConfigMethodsSupported; 24955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync deviceCapability = source.deviceCapability; 25055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync groupCapability = source.groupCapability; 25155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync status = source.status; 25255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 25355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 25455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 25555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** Implement the Parcelable interface {@hide} */ 25655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public void writeToParcel(Parcel dest, int flags) { 25755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync dest.writeString(deviceName); 25855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync dest.writeString(deviceAddress); 25955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync dest.writeString(interfaceAddress); 26055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync dest.writeString(primaryDeviceType); 26155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync dest.writeString(secondaryDeviceType); 26255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync dest.writeInt(wpsConfigMethodsSupported); 26355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync dest.writeInt(deviceCapability); 26455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync dest.writeInt(groupCapability); 26555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync dest.writeString(status.name()); 26655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 26755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 26855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** Implement the Parcelable interface {@hide} */ 26955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public static final Creator<WifiP2pDevice> CREATOR = 27055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync new Creator<WifiP2pDevice>() { 27155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public WifiP2pDevice createFromParcel(Parcel in) { 27255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync WifiP2pDevice device = new WifiP2pDevice(); 27355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync device.deviceName = in.readString(); 27455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync device.deviceAddress = in.readString(); 27555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync device.interfaceAddress = in.readString(); 27655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync device.primaryDeviceType = in.readString(); 27755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync device.secondaryDeviceType = in.readString(); 27855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync device.wpsConfigMethodsSupported = in.readInt(); 27955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync device.deviceCapability = in.readInt(); 28055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync device.groupCapability = in.readInt(); 28155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync device.status = Status.valueOf(in.readString()); 28255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync return device; 28355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 28455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 28555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public WifiP2pDevice[] newArray(int size) { 28655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync return new WifiP2pDevice[size]; 28755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 28855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync }; 28955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 29055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private String trimQuotes(String str) { 29155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync str = str.trim(); 29255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (str.startsWith("'") && str.endsWith("'")) { 29355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync return str.substring(1, str.length()-1); 29455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 29555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync return str; 29655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 29755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 29855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync //supported formats: 0x1abc, 0X1abc, 1abc 29955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync private int parseHex(String hexString) { 30055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync int num = 0; 30155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (hexString.startsWith("0x") || hexString.startsWith("0X")) { 30255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync hexString = hexString.substring(2); 30355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 30455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 30555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync try { 30655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync num = Integer.parseInt(hexString, 16); 30755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } catch(NumberFormatException e) { 30855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync Log.e(TAG, "Failed to parse hex string " + hexString); 30955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 31055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync return num; 31155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 31255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync} 313