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

WifiP2pGroupList

public class WifiP2pGroupList extends Object implements android.os.Parcelable
A class representing a Wi-Fi P2p group list {@see WifiP2pManager}
hide

Fields Summary
private static final int
CREDENTIAL_MAX_NUM
private final android.util.LruCache
mGroups
private final GroupDeleteListener
mListener
private boolean
isClearCalled
public static final Creator
CREATOR
Implement the Parcelable interface
Constructors Summary
public WifiP2pGroupList()

hide


       
           
    

      
      
        this(null, null);
    
public WifiP2pGroupList(WifiP2pGroupList source, GroupDeleteListener listener)

hide

        mListener = listener;
        mGroups = new LruCache<Integer, WifiP2pGroup>(CREDENTIAL_MAX_NUM) {
            @Override
            protected void entryRemoved(boolean evicted, Integer netId,
                    WifiP2pGroup oldValue, WifiP2pGroup newValue) {
                if (mListener != null && !isClearCalled) {
                    mListener.onDeleteGroup(oldValue.getNetworkId());
                }
            }
        };

        if (source != null) {
            for (Map.Entry<Integer, WifiP2pGroup> item : source.mGroups.snapshot().entrySet()) {
                mGroups.put(item.getKey(), item.getValue());
            }
        }
    
Methods Summary
public voidadd(WifiP2pGroup group)
Add the specified group to this group list.

param
group
hide

        mGroups.put(group.getNetworkId(), group);
    
public booleanclear()
Clear the group.

hide

        if (mGroups.size() == 0) return false;
        isClearCalled = true;
        mGroups.evictAll();
        isClearCalled = false;
        return true;
    
public booleancontains(int netId)
Return true if this group list contains the specified network id. This function does NOT update LRU information. It means the internal queue is NOT reordered.

param
netId network id.
return
true if the specified network id is present in this group list.
hide

        final Collection<WifiP2pGroup> groups = mGroups.snapshot().values();
        for (WifiP2pGroup grp: groups) {
            if (netId == grp.getNetworkId()) {
                return true;
            }
        }
        return false;
    
public intdescribeContents()
Implement the Parcelable interface

        return 0;
    
public java.util.CollectiongetGroupList()
Return the list of p2p group.

return
the list of p2p group.

        return mGroups.snapshot().values();
    
public intgetNetworkId(java.lang.String deviceAddress)
Return the network id of the group owner profile with the specified p2p device address. If more than one persistent group of the same address is present in the list, return the first one.

param
deviceAddress p2p device address.
return
the network id. if not found, return -1.
hide

        if (deviceAddress == null) return -1;

        final Collection<WifiP2pGroup> groups = mGroups.snapshot().values();
        for (WifiP2pGroup grp: groups) {
            if (deviceAddress.equalsIgnoreCase(grp.getOwner().deviceAddress)) {
                // update cache ordered.
                mGroups.get(grp.getNetworkId());
                return grp.getNetworkId();
            }
        }
        return -1;
    
public intgetNetworkId(java.lang.String deviceAddress, java.lang.String ssid)
Return the network id of the group with the specified p2p device address and the ssid.

param
deviceAddress p2p device address.
param
ssid ssid.
return
the network id. if not found, return -1.
hide

        if (deviceAddress == null || ssid == null) {
            return -1;
        }

        final Collection<WifiP2pGroup> groups = mGroups.snapshot().values();
        for (WifiP2pGroup grp: groups) {
            if (deviceAddress.equalsIgnoreCase(grp.getOwner().deviceAddress) &&
                    ssid.equals(grp.getNetworkName())) {
                // update cache ordered.
                mGroups.get(grp.getNetworkId());
                return grp.getNetworkId();
            }
        }

        return -1;
    
public java.lang.StringgetOwnerAddr(int netId)
Return the group owner address of the group with the specified network id

param
netId network id.
return
the address. if not found, return null.
hide

        WifiP2pGroup grp = mGroups.get(netId);
        if (grp != null) {
            return grp.getOwner().deviceAddress;
        }
        return null;
    
public voidremove(int netId)
Remove the group with the specified network id from this group list.

param
netId
hide

        mGroups.remove(netId);
    
voidremove(java.lang.String deviceAddress)
Remove the group with the specified device address from this group list.

param
deviceAddress

        remove(getNetworkId(deviceAddress));
    
public java.lang.StringtoString()

        StringBuffer sbuf = new StringBuffer();

        final Collection<WifiP2pGroup> groups = mGroups.snapshot().values();
        for (WifiP2pGroup grp: groups) {
            sbuf.append(grp).append("\n");
        }
        return sbuf.toString();
    
public voidwriteToParcel(android.os.Parcel dest, int flags)
Implement the Parcelable interface

        final Collection<WifiP2pGroup> groups = mGroups.snapshot().values();
        dest.writeInt(groups.size());
        for(WifiP2pGroup group : groups) {
            dest.writeParcelable(group, flags);
        }