FileDocCategorySizeDatePackage
BasicPermission.javaAPI DocAndroid 1.5 API7678Wed May 06 22:41:04 BST 2009java.security

BasicPermission

public abstract class BasicPermission extends Permission implements Serializable
{@code BasicPermission} is the common base class of all permissions which have a name but no action lists. A {@code BasicPermission} is granted or it is not.

Names of a BasicPermission follow the dot separated, hierarchical property naming convention. Asterisk '*' can be used as wildcards. Either by itself, matching anything, or at the end of the name, immediately preceded by a '.'. For example:

com.google.android.* grants all permissions under the com.google.android permission hierarchy
* grants all permissions

While this class ignores the action list in the {@link #BasicPermission(String, String)} constructor, subclasses may implement actions on top of this class.

Fields Summary
private static final long
serialVersionUID
Constructors Summary
public BasicPermission(String name)
Constructs a new instance of {@code BasicPermission} with the specified name.

param
name the name of the permission.
throws
NullPointerException if {@code name} is {@code null}.
throws
IllegalArgumentException if {@code name.length() == 0}.
since
Android 1.0


                                                         
       
        super(name);
        checkName(name);
    
public BasicPermission(String name, String action)
Constructs a new instance of {@code BasicPermission} with the specified name. The {@code action} parameter is ignored.

param
name the name of the permission.
param
action is ignored.
throws
NullPointerException if {@code name} is {@code null}.
throws
IllegalArgumentException if {@code name.length() == 0}.
since
Android 1.0

        super(name);
        checkName(name);
    
Methods Summary
private final voidcheckName(java.lang.String name)
Checks name parameter

        if (name == null) {
            throw new NullPointerException(Messages.getString("security.28")); //$NON-NLS-1$
        }
        if (name.length() == 0) {
            throw new IllegalArgumentException(Messages.getString("security.29")); //$NON-NLS-1$
        }
    
public booleanequals(java.lang.Object obj)
Compares the specified object with this {@code BasicPermission} for equality. Returns {@code true} if the specified object has the same class and the two {@code Permissions}s have the same name.

The {@link #implies(Permission)} method should be used for making access control checks.

param
obj object to be compared for equality with this {@code BasicPermission}.
return
{@code true} if the specified object is equal to this {@code BasicPermission}, otherwise {@code false}.
since
Android 1.0

        if (obj == this) {
            return true;
        }

        if (obj != null && obj.getClass() == this.getClass()) {
            return this.getName().equals(((Permission)obj).getName());
        }
        return false;
    
public java.lang.StringgetActions()
Returns the actions associated with this permission. Since {@code BasicPermission} instances have no actions, an empty string is returned.

return
an empty string.
since
Android 1.0

        return ""; //$NON-NLS-1$
    
public inthashCode()
Returns the hash code value for this {@code BasicPermission}. Returns the same hash code for {@code BasicPermission}s that are equal to each other as required by the general contract of {@link Object#hashCode}.

return
the hash code value for this {@code BasicPermission}.
see
Object#equals(Object)
see
BasicPermission#equals(Object)
since
Android 1.0

        return getName().hashCode();
    
public booleanimplies(java.security.Permission permission)
Indicates whether the specified permission is implied by this permission.

param
permission the permission to check against this permission.
return
{@code true} if the specified permission is implied by this permission, {@code false} otherwise.
since
Android 1.0

        if (permission != null && permission.getClass() == this.getClass()) {
            return nameImplies(getName(), permission.getName());
        }
        return false;
    
static booleannameImplies(java.lang.String thisName, java.lang.String thatName)
Checks if {@code thisName} implies {@code thatName}, accordingly to hierarchical property naming convention. It is assumed that names cannot be {@code null} or empty.

        if (thisName == thatName) {
            return true;
        }
        int end = thisName.length();
        if (end > thatName.length()) {
            return false;
        }
        if (thisName.charAt(--end) == '*"
            && (end == 0 || thisName.charAt(end - 1) == '.")) {
            //wildcard found
            end--;
        } else if (end != (thatName.length()-1)) {
            //names are not equal
            return false;
        }
        for (int i = end; i >= 0; i--) {
            if (thisName.charAt(i) != thatName.charAt(i)) {
                return false;
            }
        }
        return true;
    
public java.security.PermissionCollectionnewPermissionCollection()
Returns an empty {@link PermissionCollection} for holding permissions.

For {@code PermissionCollection} (and subclasses which do not override this method), the collection which is returned does not invoke the {@link #implies(Permission)} method of the permissions which are stored in it when checking if the collection implies a permission. Instead, it assumes that if the type of the permission is correct, and the name of the permission is correct, there is a match.

return
an empty {@link PermissionCollection} for holding permissions.
see
BasicPermissionCollection
since
Android 1.0

        return new BasicPermissionCollection();
    
private voidreadObject(java.io.ObjectInputStream in)
Checks name after default deserialization.

        in.defaultReadObject();
        checkName(this.getName());