Loading core/java/android/net/nsd/DnsSdTxtRecord.java +21 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,8 @@ package android.net.nsd; import android.os.Parcelable; import android.os.Parcel; import java.util.Arrays; /** * This class handles TXT record data for DNS based service discovery as specified at * http://tools.ietf.org/html/draft-cheshire-dnsext-dns-sd-11 Loading Loading @@ -160,7 +162,7 @@ public class DnsSdTxtRecord implements Parcelable { /* Gets the raw data in bytes */ public byte[] getRawData() { return mData; return (byte[]) mData.clone(); } private void insert(byte[] keyBytes, byte[] value, int index) { Loading Loading @@ -279,6 +281,24 @@ public class DnsSdTxtRecord implements Parcelable { return result != null ? result : ""; } @Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof DnsSdTxtRecord)) { return false; } DnsSdTxtRecord record = (DnsSdTxtRecord)o; return Arrays.equals(record.mData, mData); } @Override public int hashCode() { return Arrays.hashCode(mData); } /** Implement the Parcelable interface */ public int describeContents() { return 0; Loading core/jni/android_net_wifi_Wifi.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ #define WIFI_PKG_NAME "android/net/wifi/WifiNative" #define BUF_SIZE 256 #define EVENT_BUF_SIZE 2048 namespace android { Loading Loading @@ -140,7 +141,7 @@ static void android_net_wifi_closeSupplicantConnection(JNIEnv* env, jobject, jst static jstring android_net_wifi_waitForEvent(JNIEnv* env, jobject, jstring jIface) { char buf[BUF_SIZE]; char buf[EVENT_BUF_SIZE]; ScopedUtfChars ifname(env, jIface); int nread = ::wifi_wait_for_event(ifname.c_str(), buf, sizeof buf); if (nread > 0) { Loading wifi/java/android/net/wifi/WifiMonitor.java +56 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.net.wifi.p2p.WifiP2pConfig; import android.net.wifi.p2p.WifiP2pDevice; import android.net.wifi.p2p.WifiP2pGroup; import android.net.wifi.p2p.WifiP2pProvDiscEvent; import android.net.wifi.p2p.nsd.WifiP2pServiceResponse; import android.net.wifi.StateChangeResult; import android.os.Message; import android.util.Log; Loading @@ -29,6 +30,7 @@ import android.util.Log; import com.android.internal.util.Protocol; import com.android.internal.util.StateMachine; import java.util.List; import java.util.regex.Pattern; import java.util.regex.Matcher; Loading Loading @@ -214,6 +216,52 @@ public class WifiMonitor { group_capab=0x0 */ private static final String P2P_PROV_DISC_SHOW_PIN_STR = "P2P-PROV-DISC-SHOW-PIN"; /* * Protocol format is as follows.<br> * See the Table.62 in the WiFi Direct specification for the detail. * ______________________________________________________________ * | Length(2byte) | Type(1byte) | TransId(1byte)}| * ______________________________________________________________ * | status(1byte) | vendor specific(variable) | * * P2P-SERV-DISC-RESP 42:fc:89:e1:e2:27 1 0300000101 * length=3, service type=0(ALL Service), transaction id=1, * status=1(service protocol type not available)<br> * * P2P-SERV-DISC-RESP 42:fc:89:e1:e2:27 1 0300020201 * length=3, service type=2(UPnP), transaction id=2, * status=1(service protocol type not available) * * P2P-SERV-DISC-RESP 42:fc:89:e1:e2:27 1 990002030010757569643a3131323 * 2646534652d383537342d353961622d393332322d3333333435363738393034343a3 * a75726e3a736368656d61732d75706e702d6f72673a736572766963653a436f6e746 * 56e744469726563746f72793a322c757569643a36383539646564652d383537342d3 * 53961622d393333322d3132333435363738393031323a3a75706e703a726f6f74646 * 576696365 * length=153,type=2(UPnP),transaction id=3,status=0 * * UPnP Protocol format is as follows. * ______________________________________________________ * | Version (1) | USN (Variable) | * * version=0x10(UPnP1.0) data=usn:uuid:1122de4e-8574-59ab-9322-33345678 * 9044::urn:schemas-upnp-org:service:ContentDirectory:2,usn:uuid:6859d * ede-8574-59ab-9332-123456789012::upnp:rootdevice * * P2P-SERV-DISC-RESP 58:17:0c:bc:dd:ca 21 1900010200045f6970 * 70c00c000c01094d795072696e746572c027 * length=25, type=1(Bonjour),transaction id=2,status=0 * * Bonjour Protocol format is as follows. * __________________________________________________________ * |DNS Name(Variable)|DNS Type(1)|Version(1)|RDATA(Variable)| * * DNS Name=_ipp._tcp.local.,DNS type=12(PTR), Version=1, * RDATA=MyPrinter._ipp._tcp.local. * */ private static final String P2P_SERV_DISC_RESP_STR = "P2P-SERV-DISC-RESP"; private static final String HOST_AP_EVENT_PREFIX_STR = "AP"; /* AP-STA-CONNECTED 42:fc:89:a8:96:09 dev_addr=02:90:4c:a0:92:54 */ private static final String AP_STA_CONNECTED_STR = "AP-STA-CONNECTED"; Loading Loading @@ -268,6 +316,7 @@ public class WifiMonitor { public static final int P2P_PROV_DISC_ENTER_PIN_EVENT = BASE + 35; public static final int P2P_PROV_DISC_SHOW_PIN_EVENT = BASE + 36; public static final int P2P_FIND_STOPPED_EVENT = BASE + 37; public static final int P2P_SERV_DISC_RESP_EVENT = BASE + 38; /* hostap events */ public static final int AP_STA_DISCONNECTED_EVENT = BASE + 41; Loading Loading @@ -558,6 +607,13 @@ public class WifiMonitor { } else if (dataString.startsWith(P2P_PROV_DISC_SHOW_PIN_STR)) { mStateMachine.sendMessage(P2P_PROV_DISC_SHOW_PIN_EVENT, new WifiP2pProvDiscEvent(dataString)); } else if (dataString.startsWith(P2P_SERV_DISC_RESP_STR)) { List<WifiP2pServiceResponse> list = WifiP2pServiceResponse.newInstance(dataString); if (list != null) { mStateMachine.sendMessage(P2P_SERV_DISC_RESP_EVENT, list); } else { Log.e(TAG, "Null service resp " + dataString); } } } Loading wifi/java/android/net/wifi/WifiNative.java +76 −1 Original line number Diff line number Diff line Loading @@ -19,8 +19,9 @@ package android.net.wifi; import android.net.wifi.p2p.WifiP2pConfig; import android.net.wifi.p2p.WifiP2pGroup; import android.net.wifi.p2p.WifiP2pDevice; import android.os.SystemProperties; import android.text.TextUtils; import android.net.wifi.p2p.nsd.WifiP2pServiceInfo; import android.net.wifi.p2p.nsd.WifiP2pServiceRequest; import android.util.Log; import java.io.InputStream; Loading Loading @@ -644,4 +645,78 @@ public class WifiNative { public String p2pPeer(String deviceAddress) { return doStringCommand("P2P_PEER " + deviceAddress); } public boolean p2pServiceAdd(WifiP2pServiceInfo servInfo) { /* * P2P_SERVICE_ADD bonjour <query hexdump> <RDATA hexdump> * P2P_SERVICE_ADD upnp <version hex> <service> * * e.g) * [Bonjour] * # IP Printing over TCP (PTR) (RDATA=MyPrinter._ipp._tcp.local.) * P2P_SERVICE_ADD bonjour 045f697070c00c000c01 094d795072696e746572c027 * # IP Printing over TCP (TXT) (RDATA=txtvers=1,pdl=application/postscript) * P2P_SERVICE_ADD bonjour 096d797072696e746572045f697070c00c001001 * 09747874766572733d311a70646c3d6170706c69636174696f6e2f706f7374736372797074 * * [UPnP] * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012 * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012::upnp:rootdevice * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012::urn:schemas-upnp * -org:device:InternetGatewayDevice:1 * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9322-123456789012::urn:schemas-upnp * -org:service:ContentDirectory:2 */ for (String s : servInfo.getSupplicantQueryList()) { String command = "P2P_SERVICE_ADD"; command += (" " + s); if (!doBooleanCommand(command)) { return false; } } return true; } public boolean p2pServiceDel(WifiP2pServiceInfo servInfo) { /* * P2P_SERVICE_DEL bonjour <query hexdump> * P2P_SERVICE_DEL upnp <version hex> <service> */ for (String s : servInfo.getSupplicantQueryList()) { String command = "P2P_SERVICE_DEL "; String[] data = s.split(" "); if (data.length < 2) { return false; } if ("upnp".equals(data[0])) { command += s; } else if ("bonjour".equals(data[0])) { command += data[0]; command += (" " + data[1]); } else { return false; } if (!doBooleanCommand(command)) { return false; } } return true; } public boolean p2pServiceFlush() { return doBooleanCommand("P2P_SERVICE_FLUSH"); } public String p2pServDiscReq(String addr, String query) { String command = "P2P_SERV_DISC_REQ"; command += (" " + addr); command += (" " + query); return doStringCommand(command); } public boolean p2pServDiscCancelReq(String id) { return doBooleanCommand("P2P_SERV_DISC_CANCEL_REQ " + id); } } wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java +33 −23 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.util.Log; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; /** * A class representing a Wi-Fi P2p device list Loading @@ -32,24 +33,28 @@ import java.util.Collections; */ public class WifiP2pDeviceList implements Parcelable { private Collection<WifiP2pDevice> mDevices; private HashMap<String, WifiP2pDevice> mDevices; public WifiP2pDeviceList() { mDevices = new ArrayList<WifiP2pDevice>(); mDevices = new HashMap<String, WifiP2pDevice>(); } /** copy constructor */ public WifiP2pDeviceList(WifiP2pDeviceList source) { if (source != null) { mDevices = source.getDeviceList(); for (WifiP2pDevice d : source.getDeviceList()) { mDevices.put(d.deviceAddress, d); } } } /** @hide */ public WifiP2pDeviceList(ArrayList<WifiP2pDevice> devices) { mDevices = new ArrayList<WifiP2pDevice>(); mDevices = new HashMap<String, WifiP2pDevice>(); for (WifiP2pDevice device : devices) { mDevices.add(device); if (device.deviceAddress != null) { mDevices.put(device.deviceAddress, device); } } } Loading @@ -62,10 +67,9 @@ public class WifiP2pDeviceList implements Parcelable { /** @hide */ public void update(WifiP2pDevice device) { if (device == null) return; for (WifiP2pDevice d : mDevices) { //Found, update fields that can change if (d.equals(device)) { if (device == null || device.deviceAddress == null) return; WifiP2pDevice d = mDevices.get(device.deviceAddress); if (d != null) { d.deviceName = device.deviceName; d.primaryDeviceType = device.primaryDeviceType; d.secondaryDeviceType = device.secondaryDeviceType; Loading @@ -74,25 +78,31 @@ public class WifiP2pDeviceList implements Parcelable { d.groupCapability = device.groupCapability; return; } } //Not found, add a new one mDevices.add(device); mDevices.put(device.deviceAddress, device); } /** @hide */ public WifiP2pDevice get(String deviceAddress) { if (deviceAddress == null) return null; return mDevices.get(deviceAddress); } /** @hide */ public boolean remove(WifiP2pDevice device) { if (device == null) return false; return mDevices.remove(device); if (device == null || device.deviceAddress == null) return false; return mDevices.remove(device.deviceAddress) != null; } /** Get the list of devices */ public Collection<WifiP2pDevice> getDeviceList() { return Collections.unmodifiableCollection(mDevices); return Collections.unmodifiableCollection(mDevices.values()); } public String toString() { StringBuffer sbuf = new StringBuffer(); for (WifiP2pDevice device : mDevices) { for (WifiP2pDevice device : mDevices.values()) { sbuf.append("\n").append(device); } return sbuf.toString(); Loading @@ -106,7 +116,7 @@ public class WifiP2pDeviceList implements Parcelable { /** Implement the Parcelable interface */ public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mDevices.size()); for(WifiP2pDevice device : mDevices) { for(WifiP2pDevice device : mDevices.values()) { dest.writeParcelable(device, flags); } } Loading Loading
core/java/android/net/nsd/DnsSdTxtRecord.java +21 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,8 @@ package android.net.nsd; import android.os.Parcelable; import android.os.Parcel; import java.util.Arrays; /** * This class handles TXT record data for DNS based service discovery as specified at * http://tools.ietf.org/html/draft-cheshire-dnsext-dns-sd-11 Loading Loading @@ -160,7 +162,7 @@ public class DnsSdTxtRecord implements Parcelable { /* Gets the raw data in bytes */ public byte[] getRawData() { return mData; return (byte[]) mData.clone(); } private void insert(byte[] keyBytes, byte[] value, int index) { Loading Loading @@ -279,6 +281,24 @@ public class DnsSdTxtRecord implements Parcelable { return result != null ? result : ""; } @Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof DnsSdTxtRecord)) { return false; } DnsSdTxtRecord record = (DnsSdTxtRecord)o; return Arrays.equals(record.mData, mData); } @Override public int hashCode() { return Arrays.hashCode(mData); } /** Implement the Parcelable interface */ public int describeContents() { return 0; Loading
core/jni/android_net_wifi_Wifi.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ #define WIFI_PKG_NAME "android/net/wifi/WifiNative" #define BUF_SIZE 256 #define EVENT_BUF_SIZE 2048 namespace android { Loading Loading @@ -140,7 +141,7 @@ static void android_net_wifi_closeSupplicantConnection(JNIEnv* env, jobject, jst static jstring android_net_wifi_waitForEvent(JNIEnv* env, jobject, jstring jIface) { char buf[BUF_SIZE]; char buf[EVENT_BUF_SIZE]; ScopedUtfChars ifname(env, jIface); int nread = ::wifi_wait_for_event(ifname.c_str(), buf, sizeof buf); if (nread > 0) { Loading
wifi/java/android/net/wifi/WifiMonitor.java +56 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.net.wifi.p2p.WifiP2pConfig; import android.net.wifi.p2p.WifiP2pDevice; import android.net.wifi.p2p.WifiP2pGroup; import android.net.wifi.p2p.WifiP2pProvDiscEvent; import android.net.wifi.p2p.nsd.WifiP2pServiceResponse; import android.net.wifi.StateChangeResult; import android.os.Message; import android.util.Log; Loading @@ -29,6 +30,7 @@ import android.util.Log; import com.android.internal.util.Protocol; import com.android.internal.util.StateMachine; import java.util.List; import java.util.regex.Pattern; import java.util.regex.Matcher; Loading Loading @@ -214,6 +216,52 @@ public class WifiMonitor { group_capab=0x0 */ private static final String P2P_PROV_DISC_SHOW_PIN_STR = "P2P-PROV-DISC-SHOW-PIN"; /* * Protocol format is as follows.<br> * See the Table.62 in the WiFi Direct specification for the detail. * ______________________________________________________________ * | Length(2byte) | Type(1byte) | TransId(1byte)}| * ______________________________________________________________ * | status(1byte) | vendor specific(variable) | * * P2P-SERV-DISC-RESP 42:fc:89:e1:e2:27 1 0300000101 * length=3, service type=0(ALL Service), transaction id=1, * status=1(service protocol type not available)<br> * * P2P-SERV-DISC-RESP 42:fc:89:e1:e2:27 1 0300020201 * length=3, service type=2(UPnP), transaction id=2, * status=1(service protocol type not available) * * P2P-SERV-DISC-RESP 42:fc:89:e1:e2:27 1 990002030010757569643a3131323 * 2646534652d383537342d353961622d393332322d3333333435363738393034343a3 * a75726e3a736368656d61732d75706e702d6f72673a736572766963653a436f6e746 * 56e744469726563746f72793a322c757569643a36383539646564652d383537342d3 * 53961622d393333322d3132333435363738393031323a3a75706e703a726f6f74646 * 576696365 * length=153,type=2(UPnP),transaction id=3,status=0 * * UPnP Protocol format is as follows. * ______________________________________________________ * | Version (1) | USN (Variable) | * * version=0x10(UPnP1.0) data=usn:uuid:1122de4e-8574-59ab-9322-33345678 * 9044::urn:schemas-upnp-org:service:ContentDirectory:2,usn:uuid:6859d * ede-8574-59ab-9332-123456789012::upnp:rootdevice * * P2P-SERV-DISC-RESP 58:17:0c:bc:dd:ca 21 1900010200045f6970 * 70c00c000c01094d795072696e746572c027 * length=25, type=1(Bonjour),transaction id=2,status=0 * * Bonjour Protocol format is as follows. * __________________________________________________________ * |DNS Name(Variable)|DNS Type(1)|Version(1)|RDATA(Variable)| * * DNS Name=_ipp._tcp.local.,DNS type=12(PTR), Version=1, * RDATA=MyPrinter._ipp._tcp.local. * */ private static final String P2P_SERV_DISC_RESP_STR = "P2P-SERV-DISC-RESP"; private static final String HOST_AP_EVENT_PREFIX_STR = "AP"; /* AP-STA-CONNECTED 42:fc:89:a8:96:09 dev_addr=02:90:4c:a0:92:54 */ private static final String AP_STA_CONNECTED_STR = "AP-STA-CONNECTED"; Loading Loading @@ -268,6 +316,7 @@ public class WifiMonitor { public static final int P2P_PROV_DISC_ENTER_PIN_EVENT = BASE + 35; public static final int P2P_PROV_DISC_SHOW_PIN_EVENT = BASE + 36; public static final int P2P_FIND_STOPPED_EVENT = BASE + 37; public static final int P2P_SERV_DISC_RESP_EVENT = BASE + 38; /* hostap events */ public static final int AP_STA_DISCONNECTED_EVENT = BASE + 41; Loading Loading @@ -558,6 +607,13 @@ public class WifiMonitor { } else if (dataString.startsWith(P2P_PROV_DISC_SHOW_PIN_STR)) { mStateMachine.sendMessage(P2P_PROV_DISC_SHOW_PIN_EVENT, new WifiP2pProvDiscEvent(dataString)); } else if (dataString.startsWith(P2P_SERV_DISC_RESP_STR)) { List<WifiP2pServiceResponse> list = WifiP2pServiceResponse.newInstance(dataString); if (list != null) { mStateMachine.sendMessage(P2P_SERV_DISC_RESP_EVENT, list); } else { Log.e(TAG, "Null service resp " + dataString); } } } Loading
wifi/java/android/net/wifi/WifiNative.java +76 −1 Original line number Diff line number Diff line Loading @@ -19,8 +19,9 @@ package android.net.wifi; import android.net.wifi.p2p.WifiP2pConfig; import android.net.wifi.p2p.WifiP2pGroup; import android.net.wifi.p2p.WifiP2pDevice; import android.os.SystemProperties; import android.text.TextUtils; import android.net.wifi.p2p.nsd.WifiP2pServiceInfo; import android.net.wifi.p2p.nsd.WifiP2pServiceRequest; import android.util.Log; import java.io.InputStream; Loading Loading @@ -644,4 +645,78 @@ public class WifiNative { public String p2pPeer(String deviceAddress) { return doStringCommand("P2P_PEER " + deviceAddress); } public boolean p2pServiceAdd(WifiP2pServiceInfo servInfo) { /* * P2P_SERVICE_ADD bonjour <query hexdump> <RDATA hexdump> * P2P_SERVICE_ADD upnp <version hex> <service> * * e.g) * [Bonjour] * # IP Printing over TCP (PTR) (RDATA=MyPrinter._ipp._tcp.local.) * P2P_SERVICE_ADD bonjour 045f697070c00c000c01 094d795072696e746572c027 * # IP Printing over TCP (TXT) (RDATA=txtvers=1,pdl=application/postscript) * P2P_SERVICE_ADD bonjour 096d797072696e746572045f697070c00c001001 * 09747874766572733d311a70646c3d6170706c69636174696f6e2f706f7374736372797074 * * [UPnP] * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012 * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012::upnp:rootdevice * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012::urn:schemas-upnp * -org:device:InternetGatewayDevice:1 * P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9322-123456789012::urn:schemas-upnp * -org:service:ContentDirectory:2 */ for (String s : servInfo.getSupplicantQueryList()) { String command = "P2P_SERVICE_ADD"; command += (" " + s); if (!doBooleanCommand(command)) { return false; } } return true; } public boolean p2pServiceDel(WifiP2pServiceInfo servInfo) { /* * P2P_SERVICE_DEL bonjour <query hexdump> * P2P_SERVICE_DEL upnp <version hex> <service> */ for (String s : servInfo.getSupplicantQueryList()) { String command = "P2P_SERVICE_DEL "; String[] data = s.split(" "); if (data.length < 2) { return false; } if ("upnp".equals(data[0])) { command += s; } else if ("bonjour".equals(data[0])) { command += data[0]; command += (" " + data[1]); } else { return false; } if (!doBooleanCommand(command)) { return false; } } return true; } public boolean p2pServiceFlush() { return doBooleanCommand("P2P_SERVICE_FLUSH"); } public String p2pServDiscReq(String addr, String query) { String command = "P2P_SERV_DISC_REQ"; command += (" " + addr); command += (" " + query); return doStringCommand(command); } public boolean p2pServDiscCancelReq(String id) { return doBooleanCommand("P2P_SERV_DISC_CANCEL_REQ " + id); } }
wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java +33 −23 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.util.Log; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; /** * A class representing a Wi-Fi P2p device list Loading @@ -32,24 +33,28 @@ import java.util.Collections; */ public class WifiP2pDeviceList implements Parcelable { private Collection<WifiP2pDevice> mDevices; private HashMap<String, WifiP2pDevice> mDevices; public WifiP2pDeviceList() { mDevices = new ArrayList<WifiP2pDevice>(); mDevices = new HashMap<String, WifiP2pDevice>(); } /** copy constructor */ public WifiP2pDeviceList(WifiP2pDeviceList source) { if (source != null) { mDevices = source.getDeviceList(); for (WifiP2pDevice d : source.getDeviceList()) { mDevices.put(d.deviceAddress, d); } } } /** @hide */ public WifiP2pDeviceList(ArrayList<WifiP2pDevice> devices) { mDevices = new ArrayList<WifiP2pDevice>(); mDevices = new HashMap<String, WifiP2pDevice>(); for (WifiP2pDevice device : devices) { mDevices.add(device); if (device.deviceAddress != null) { mDevices.put(device.deviceAddress, device); } } } Loading @@ -62,10 +67,9 @@ public class WifiP2pDeviceList implements Parcelable { /** @hide */ public void update(WifiP2pDevice device) { if (device == null) return; for (WifiP2pDevice d : mDevices) { //Found, update fields that can change if (d.equals(device)) { if (device == null || device.deviceAddress == null) return; WifiP2pDevice d = mDevices.get(device.deviceAddress); if (d != null) { d.deviceName = device.deviceName; d.primaryDeviceType = device.primaryDeviceType; d.secondaryDeviceType = device.secondaryDeviceType; Loading @@ -74,25 +78,31 @@ public class WifiP2pDeviceList implements Parcelable { d.groupCapability = device.groupCapability; return; } } //Not found, add a new one mDevices.add(device); mDevices.put(device.deviceAddress, device); } /** @hide */ public WifiP2pDevice get(String deviceAddress) { if (deviceAddress == null) return null; return mDevices.get(deviceAddress); } /** @hide */ public boolean remove(WifiP2pDevice device) { if (device == null) return false; return mDevices.remove(device); if (device == null || device.deviceAddress == null) return false; return mDevices.remove(device.deviceAddress) != null; } /** Get the list of devices */ public Collection<WifiP2pDevice> getDeviceList() { return Collections.unmodifiableCollection(mDevices); return Collections.unmodifiableCollection(mDevices.values()); } public String toString() { StringBuffer sbuf = new StringBuffer(); for (WifiP2pDevice device : mDevices) { for (WifiP2pDevice device : mDevices.values()) { sbuf.append("\n").append(device); } return sbuf.toString(); Loading @@ -106,7 +116,7 @@ public class WifiP2pDeviceList implements Parcelable { /** Implement the Parcelable interface */ public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mDevices.size()); for(WifiP2pDevice device : mDevices) { for(WifiP2pDevice device : mDevices.values()) { dest.writeParcelable(device, flags); } } Loading