FileDocCategorySizeDatePackage
InternalMIDletSuiteImpl.javaAPI DocphoneME MR2 API (J2ME)12274Wed May 02 18:00:06 BST 2007com.sun.midp.installer

InternalMIDletSuiteImpl

public class InternalMIDletSuiteImpl extends Object implements com.sun.midp.midlet.MIDletSuite
Implements a the required MIDletSuite functionality needed by the system. The class is only needed for internal romized midlets.

Fields Summary
private String
displayName
Display name for permission dialogs.
private int
id
The ID of this suite.
private byte[]
permissions
Permissions for this suite.
private boolean
trusted
Flag for trusted suites. If true the system trust icon is displayed.
private com.sun.midp.util.Properties
properties
Suite properties for this suite.
private int
numberOfMidlets
number of midlets in this suite. For a rommized suite assume 1.
Constructors Summary
private InternalMIDletSuiteImpl(String theDisplayName, int theId)
Creates MIDletSuite for rommized MIDlet.

param
theDisplayName display name to use in permission dialogs, and in the MIDlet proxy list
param
theId unique identifier for this suite

        if (theDisplayName != null) {
            displayName = theDisplayName;
        } else {
            displayName =
                Resource.getString(ResourceConstants.AMS_SYSTEM_SUITE_NAME);
        }

        id = theId;

        trusted = true;

        permissions =
            (Permissions.forDomain(Permissions.MANUFACTURER_DOMAIN_BINDING))
                [Permissions.CUR_LEVELS];

        properties = new Properties();
    
Methods Summary
public voidcheckForPermission(int permission, java.lang.String resource, java.lang.String extraValue)
Checks for permission and throw an exception if not allowed. May block to ask the user a question.

param
permission ID of the permission to check for, the ID must be from {@link com.sun.midp.security.Permissions}
param
resource string to insert into the question, can be null if no %2 in the question
param
extraValue string to insert into the question, can be null if no %3 in the question
exception
SecurityException if the permission is not allowed by this token
exception
InterruptedException if another thread interrupts the calling thread while this method is waiting to preempt the display.

        checkIfPermissionAllowed(permission);
    
public voidcheckForPermission(int permission, java.lang.String resource)
Check for permission and throw an exception if not allowed. May block to ask the user a question.

param
permission ID of the permission to check for, the ID must be from {@link com.sun.midp.security.Permissions}
param
resource string to insert into the question, can be null if no %2 in the question
exception
SecurityException if the permission is not allowed by this token
exception
InterruptedException if another thread interrupts the calling thread while this method is waiting to preempt the display.

        checkForPermission(permission, resource, null);
    
public voidcheckIfPermissionAllowed(int permission)
Checks to see the suite has the ALLOW level for specific permission. This is used for by internal APIs that only provide access to trusted system applications.

param
permission permission ID from com.sun.midp.security.Permissions
exception
SecurityException if the suite is not allowed the permission

        if (checkPermission(permission) != 1) {
            throw new SecurityException(SecurityToken.STD_EX_MSG);
        }
    
public intcheckPermission(java.lang.String permission)
Gets the status of the specified permission. If no API on the device defines the specific permission requested then it must be reported as denied. If the status of the permission is not known because it might require a user interaction then it should be reported as unknown.

param
permission to check if denied, allowed, or unknown
return
0 if the permission is denied; 1 if the permission is allowed; -1 if the status is unknown

        for (int i = 0; i < Permissions.NUMBER_OF_PERMISSIONS; i++) {
            if (Permissions.getName(i).equals(permission)) {
                return checkPermission(i);

            }
        }

        return 0;
    
private intcheckPermission(int permission)
Check to see the suite has the ALLOW level for specific permission. This is used for by internal APIs that only provide access to trusted system applications.

param
permission permission ID from com.sun.midp.security.Permissions
param
permission to check if denied, allowed, or unknown
return
0 if the permission is denied; 1 if the permission is allowed; -1 if the status is unknown

        if (permission < 0 || permission >= permissions.length) {
            // report denied
            return 0;
        }

        switch (permissions[permission]) {
        case Permissions.ALLOW:
        case Permissions.BLANKET_GRANTED:
            // report allowed
            return 1;

        case Permissions.BLANKET:
        case Permissions.SESSION:
        case Permissions.ONESHOT:
            // report unknown
            return -1;

        default:
            break;
        }

        // report denied
        return 0;
    
public voidclose()
Close the opened MIDletSuite

    
public static com.sun.midp.midlet.MIDletSuitecreate(java.lang.String theDisplayName, int theId)
Creates MIDletSuite for rommized MIDlet.

param
theDisplayName display name to use in permission dialogs, and in the MIDlet proxy list
param
theId ID to separate this suite's resources from others
return
new MIDletSuite object


                                                  
           
        return new InternalMIDletSuiteImpl(theDisplayName, theId);
    
public intgetID()
Gets the unique ID of the suite.

return
suite ID

        return id;
    
public java.lang.StringgetMIDletName(java.lang.String className)
Get the name of a MIDlet to display to the user.

param
className class name of the MIDlet to be checked
return
name to display to the user

        /*
         * Each internal MIDlet runs in it own suite,
         * just return the suite name
         */
        return displayName;
    
public intgetNumberOfMIDlets()
Provides the number of MIDlets in this suite.

return
number of MIDlet in the suite

        return numberOfMidlets;
    
public byte[]getPermissions()
Gets list of permissions for this suite.

return
array of permissions from {@link Permissions}

        return permissions;
    
public java.lang.StringgetProperty(java.lang.String key)
Gets a property of the suite. A property is an attribute from either the application descriptor or JAR Manifest.

param
key the name of the property
return
A string with the value of the property. null is returned if no value is available for the key.

        return properties.getProperty(key);
    
public bytegetPushInterruptSetting()
Gets push setting for interrupting other MIDlets. Reuses the Permissions.

return
push setting for interrupting MIDlets the value will be permission level from {@link Permissions}

        // Rommized internal MIDlet can interrupt other MIDlets without asking.
        return Permissions.ALLOW;
    
public intgetPushOptions()
Gets push options for this suite.

return
push options are defined in {@link PushRegistryImpl}

        // There are not push options for rommized suites.
        return 0;
    
public booleanisEnabled()
Determine if the a MIDlet from this suite can be run. Note that disable suites can still have their settings changed and their install info displayed.

return
true if suite is enabled, false otherwise

        return true;
    
public booleanisRegistered(java.lang.String midletClassName)
Indicates if the named MIDlet is registered in the suite with MIDlet-<n> record in the manifest or application descriptor.

param
midletClassName class name of the MIDlet to be checked
return
true if the MIDlet is registered

        // Rommized MIDlets don't have JAD MIDlet-n entries.
        return false;
    
public booleanisTrusted()
Indicates if this suite is trusted. (not to be confused with a domain named "trusted", this is used for extra checks beyond permission checking)

return
true if the suite is trusted false if not

        return trusted;
    
public booleanisVerified()
Get state of classes preverification within the suite.

return
true because internal suite should be always preverified.

        return true;
    
public booleanpermissionToInterrupt(java.lang.String connection)
Asks the user want to interrupt the current MIDlet with a new MIDlet that has received network data.

param
connection connection to place in the permission question or null for alarm
return
true if the use wants interrupt the current MIDlet, else false

        // Rommized internal MIDlet can interrupt other MIDlets without asking.
        return true;
    
public voidsetTempProperty(com.sun.midp.security.SecurityToken token, java.lang.String key, java.lang.String value)
Replace or add a property to the suite for this run only.

param
token token with the AMS permission set to allowed, can be null to use the suite's permission
param
key the name of the property
param
value the value of the property
exception
SecurityException if the caller's token does not have internal AMS permission

        if (token != null) {
            token.checkIfPermissionAllowed(Permissions.AMS);
        } else {
            MIDletSuite current = MIDletStateHandler.
                getMidletStateHandler().getMIDletSuite();

            current.checkIfPermissionAllowed(Permissions.AMS);
        }

        properties.setProperty(key, value);