FileDocCategorySizeDatePackage
SocketPermissionCollection.javaAPI DocAndroid 1.5 API3835Wed May 06 22:41:04 BST 2009java.net

SocketPermissionCollection

public final class SocketPermissionCollection extends PermissionCollection
This class represents a list of {@code SocketPermission} objects and provides a method to check whether or not a specific permission is implied by this {@code SocketPermissionCollection}.
since
Android 1.0

Fields Summary
private static final long
serialVersionUID
private Vector
permissions
Constructors Summary
public SocketPermissionCollection()


    // Constructs a new instance of this class.
      
        super();
    
Methods Summary
public voidadd(java.security.Permission permission)

        if (isReadOnly()) {
            throw new IllegalStateException();
        }
        if (!(permission instanceof SocketPermission)) {
            throw new IllegalArgumentException(permission.toString());
        }
        permissions.addElement(permission);
    
public java.util.Enumerationelements()

        return permissions.elements();
    
public booleanimplies(java.security.Permission permission)
Returns whether this permission collection implies {@code permission}. Basically it tests whether {@code permission} is the subset of this collection.

since
Android 1.0

        if (!(permission instanceof SocketPermission)) {
            return false;
        }
        SocketPermission sp, argPerm = (SocketPermission) permission;
        int pmask = argPerm.actionsMask;
        int allMask = 0;
        int i = 0, count = permissions.size();
        while ((i < count) && ((allMask & pmask) != pmask)) {
            sp = (SocketPermission) permissions.elementAt(i);
            if (sp.checkHost(argPerm)) {
                if ((sp.actionsMask & SocketPermission.SP_RESOLVE) == SocketPermission.SP_RESOLVE) {
                    allMask |= SocketPermission.SP_RESOLVE;
                }
                // Only set flags if the port range and host can be implied
                if ((argPerm.portMin >= sp.portMin)
                        && (argPerm.portMax <= sp.portMax)) {
                    if ((sp.actionsMask & SocketPermission.SP_CONNECT) == SocketPermission.SP_CONNECT) {
                        allMask |= SocketPermission.SP_CONNECT;
                    }
                    if ((sp.actionsMask & SocketPermission.SP_ACCEPT) == SocketPermission.SP_ACCEPT) {
                        allMask |= SocketPermission.SP_ACCEPT;
                    }
                    if ((sp.actionsMask & SocketPermission.SP_LISTEN) == SocketPermission.SP_LISTEN) {
                        allMask |= SocketPermission.SP_LISTEN;
                    }
                }
            }
            ++i;
        }

        return (allMask & pmask) == pmask;