4 Software Management

This chapter introduces the Software Management (SWM) APIs of the Java ME Embedded Profile (MEEP) version 8. These APIs provided extended software management features for Oracle Java ME Embedded applications, as given in the javax.microedition.swm package. There are five interfaces and six classes in this package that can be used by applications to enhance software management. In addition, there are a number of enumerations that are present in the package; these are documented near the classes and methods that use them throughout this chapter.

SuiteInstallListener Interface

SuiteInstallListener is a sub-interface that provides progress data for an installer that is downloading an app or a link.

The interface consists of two methods, both of which are called at certain times during installation. One is the installationDone() method, which provides only a single code, the definitions of which can be found in the InstallerErrorCode interface. The other is the updateStatus() method, which identifies the current task as one of the SuiteInstallStage constants that are shown in Table 4-1, and provides an integer percentage of completeness.


Table 4-1 SuiteInstallState

Name Description

DONE

Installation has completed

DOWNLOADING_BODY

Install stage: downloading application body.

DOWNLOADING_DATA

Install stage: downloading additional application data.

DOWNLOADING_DESCRIPTOR

Install stage: downloading application descriptor.

STORING

Install stage: storing application.

VERIFYING

Install stage: verifying downloaded content.


Here are the two method defined in the SuiteInstallListener interface:

  • void installationDone(int errorCode)

    This method is called by the installer to report that the installation has completed. The resulting integer code is contained in the InstallerErrorCode class. See "InstallerErrorCode" for more information about installation error codes.

  • void updateStatus(SuiteManagementTracker tracker, SuiteInstallStage status, int percent)

    This method is called by the installer to inform the listener of the current status of the install. The stage is given by an integer constant as shown in Table 4-1. The percent is an integer between 0 and 100.

SuiteListener Interface

SuiteListener is an interface that provides a notification that the current state of a suite has changed.

There is only one method defined in the SuiteListener interface:

  • void notifySuiteStateChanged(SuiteManagementTracker tracker, SuiteState newState)

    This method is called to notify a listener that the current state of a suite has changed. A reference to the current SuiteManagementTracker is included, as well as an instance of SuiteState, which indicates the new state.

SuiteManager Interface

The SuiteManager interface consists of only seven methods that add or remove suites, add or remove suite listeners, retrieve a list of the currently installed suites, or retrieve the current SuiteInstaller.

  • void addSuiteListener(SuiteListener theListener)

    This method adds a SuiteListener object to the current SuiteManager.

  • Suite getSuite(java.lang.String vendor, java.lang.String name)

    This method returns an instance of the currently installed Suite.

  • SuiteInstaller getSuiteInstaller(byte[] instData, int offset, int length, boolean ignoreUpdateLock)

    This method returns the current SuiteInstaller.

  • SuiteInstaller getSuiteInstaller(java.lang.String locationUrl, boolean ignoreUpdateLock)

    This method returns the current SuiteInstaller

  • java.util.List<Suite> getSuites(SuiteType type)

    This method requests a list of installed suites of specified type.

  • void removeSuite(Suite suite, boolean ignoreRemoveLock)

    This method removes a Suite.

  • void removeSuiteListener(SuiteListener theListener)

    This method removes a SuiteListener.

TaskListener Interface

The TaskListener interface is an interface used to receive updates about a task that is currently running.

  • void notifyStatusUpdate(Task task, TaskStatus newStatus)

    This method is called when the current task has a new status update to report. The method passes a reference to the Task in question, as well as a TaskStatus object reporting the new status.

TaskManager Interface

The TaskManager interface is an interface used to manage the tasks.

  • void addTaskListener(TaskListener) throws SecurityException

    This method adds a TaskListener.

  • Task getCurrentTask() throws SecurityException

    This method returns the current task that is running.

  • java.util.List<Task> getTaskList(boolean includeSystem)

    This method obtains a list of Task objects. If system tasks are to be included, that can be specified with the boolean parameter.

  • void removeTaskListener(TaskListener listener)

    This method removes a TaskListener.

  • boolean setForegroundTask(Task task) throws java.lang.IllegalArgumentException

    This method assigns the specified task to be the currently running foreground task. A task is said to be in the foreground if the LUI API or another UI API is supported and the task is visible on the display, or if the Key API is supported and input device events will be delivered to it. If none of those packages is supported by the implementation, a call to this method has no effect.

  • boolean setPriority(Task task, TaskPriority priority) throws java.lang.IllegalArgumentException

    Changes the priority for the given task. The method returns true if the change was successful, or false otherwise.

  • Task startTask(Suite suite, String className) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException

    Starts a Task from the given class name in the given Suite. This method throws an exception if suite is a library and can therefore not be started. Calling this method schedules a new application execution. The new task is created with TaskStatus.STARTING on success or TaskStatus.START_FAILED on failure.

    More than one call to this method can be performed with the same arguments. In this case subsequent calls lead to attempts to re-start the task. In case of unsuccessful attempt to re-start the task, an appropriate exception is thrown or the corresponding state TaskStatus.START_FAILED is set to the returned task object.

  • boolean stopTask(Task task) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException

    This method cancels an installation that is in progress. It returns true if the cancellation was successful, or false otherwise.

ManagerFactory Class

The ManagerFactory class is a global factory that is used to obtain a SuiteManager or a TaskManager implementation.

  • static SuiteManager getSuiteManager()

    This method returns an implementation of a SuiteManager.

  • static TaskManager getTaskManager()

    This method returns an implementation of a TaskManager.

The Suite Class

All IMlet suites maintain a basic set of identification and state information that acts as a descriptor. This descriptor is represented by the Suite class.

Suites can be one of four types, presented in the SuiteType enumeration, and shown in Table 4-2:


Table 4-2 SuiteType Enumeration

Suite Type Description

ST_APPLICATION

The suite contains one or more MIDlets with an entry point that can be executed.

ST_LIBRARY

The suite is a library that can be used by one or more applications.

ST_SYSTEM

The suite is a system-level application.

ST_INVALID

The suite is invalid and cannot be found or executed.


In addition, suites contain binary flags that describe their state, presented in the SuiteStateFlag enumeration, and shown in Table 4-3:


Table 4-3 SuiteStageFlag Enumeration

State Description

AVAILABLE

The suite is available for use.

ENABLED

The suite is enabled. When a suite is disabled, any attempt to run application or use a library from this suite should fail.

SYSTEM

The suite is a system-level suite.

PREINSTALLED

The suite is a system-level suite that cannot be updated.

REMOVE_DENIED

The suite should not be removed.

UPDATE_DENIED

The suite should not be updated.


The following are method present in the Suite class.

  • java.lang.String getName()

    This method returns the name for the given suite.

  • java.lang.String getVendor()

    This method returns the vendor for the given suite.

  • java.lang.String getVersion()

    This method returns the version of the given suite.

  • java.lang.String getDownloadUrl()

    This method returns the URL that the JAD or JAR was downloaded from.

  • java.util.Iteration<String> getAttributes()

    This method returns a String array that provides the names of the available properties. The properties returned are those from the JAD file and the manifest combined into a single array.

  • java.lang.String getAttributeValue(String name)

    This method retrieves the value for the respective attribute name.

  • SuiteType getSuiteType()

    This method returns the suite type. See Table 4-2 for more information.

  • public boolean isSuiteState(SuiteStateFlag state)

    This method checks the current state boolean to see if it is true.

  • public void setSuiteStateFlag(SuiteStateFlag state, boolean value) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.SecurityException

    This method sets the specified flag to the specified value. If a Suite has been created, SuiteStateFlag.ENABLED and SuiteStateFlag.AVAILABLE are always set to true, while SuiteStateFlag.REMOVE_DENIED and SuiteStateFlag.UPDATE_DENIED are set to false. These states can be changed by calling this method. The SuiteStateFlag.SYSTEM and SuiteStateFlag.PREINSTALLED flags are only set for system suites or pre-installed suites, respectively, and cannot be unset or set by this method. To be able to set suite flags, caller application should request javax.microedition.swm.SWMPermission("client", "manageSuite") or javax.microedition.swm.SWMPermission ("crossClient", "manageSuite") permission. See SWMPermission for more details.

  • public java.util.Iterator<java.lang.String> getMIDlets()

    This method returns a list of the applications (application class names) in this suite. The first application in the enumeration is the default application as specified in the MIDlet-1 field of the descriptor.

  • public java.util.Iterator<Suite> getDependencies()

    This method returns a list of the shared libraries this Suite depends on

  • public boolean isTrusted()

    Checks if this Suite is trusted or not. The return value is always true if it is a SYSTEM_SUITE.

  • public boolean isInstalled()

    Checks if this Suite is still installed or has been removed.

SuiteInstaller Class

The ManagerFactory class is a global factory that is used to obtain a SuiteManager or a TaskManager implementation.

  • void addInstallationListener(SuiteInstallListener listener)

    This method adds a SuiteInstallListener to this suite installer

  • void removeInstallationListener(SuiteInstallationListener listener)

    This method removes a SuiteInstallListener to this suite installer.

  • SuiteManagementTracker start()

    This method starts installation of the suite. The installation can be the first installation of this suite, or a re-installation (update) of a suite that had been installed before. A SuiteInstallListener must be added in order to handle callback requests.This method returns an instance of SuiteManagementTracker; the caller can observe the progress of the installation via the SuiteInstallListener added. Please note that the method may not return quickly. Depending on the provisioning mechanism used in the implementation of MEEP 8, it may be necessary to download the entire JAR data first in order to inspect the manifest of the application suite in order to find out whether this is a new installation or an update of an existing application suite. Depending on the network connection, this may take some time.In case the previous attempt to install this suite (initiated by a previous call of the start() method) has not been finished at the time the new call takes place, the call is queued and the new attempt to install (in case the first one failed) or the re-installation (in case the first call was successful), respectively, starts as soon as the first installation attempt or installation has been finished.A new instance of SuiteManagementTracker will be created for every call to this method and assigned to the Suite to be installed as soon as the installation has been completed successfully. In case of an update of an existing Suite, the SuiteManagementTracker instance is assigned to the existing Suite object from the beginning.If the initiating application does not have the right SWMPermission, the installation will fail with InstallErrorCodes.UNAUTHORIZED_INSTALL.

  • void cancel()

    Begins installation of the suite.

SuiteManagementTracker Class

An instance of this class is generated as soon as an installation or update of a Suite is started using SuiteInstaller.start(). Invoking that method creates a new tracker instance. Whether two trackers refer to the same Suite can be found out by calling getSuite() for both and compare the returned Suite instances. The tracker instance created for a management operation is passed to any call of SuiteListener.notifySuiteStateChanged() in order to inform about the progress of this operation.

For the installation of a new Suite, as long as the installation hasn't been successfully completed, an instance of SuiteManagementTracker is not assigned to any Suite instance yet, as it does not exit yet. In these cases, a call to getSuite() returns null. In case of an update, the tracker is assigned to the existing Suite from the beginning, though.

This class has one method.

  • Suite getSuite()

    This method returns the Suite that this tracker is assigned to, if the installation has completed successfully

SWMPermission Class

The SWMPermission provides permission handling for SWM API permissions. An SWMPermission object contains a scope and actions. The scope is the scope of the permission. Valid scopes are "client" stands for permission to perform the listed actions only for applications assigned to the same Client. "crossClient" stands for permission to perform the listed actions also for applications assigned to other Clients. Usually this is a permission reserved for the Root Client. Granting this permissions to other Clients should be figured out well in order to avoid security breaches.The actions to be granted are passed to the constructor in a non-empty string, containing a list of comma-separated keywords. Trailing and leading white spaces as well as those between the keywords and commas in the list are not allowed and lead to an IllegalArgumentException. The possible values can be seen in this table in the Security Policy Provider chapter of the spec. The actions string is converted to lowercase before processing.

This class has one constructor and several methods.

  • SWMPermission(java.lang.String scope, java.lang.String actions)

    This method creates a new SWMPermission object with the specified name and actions.

  • public boolean implies(java.security.Permission p)

    This method checks if the specified permission is "implied" by this object.

  • String getActions()

    This method returns the permitted actions of this Permission as a comma separated list in alphabetical order.

  • java.security.PermissionCollection newPermissionCollection()

    This method creates a new SWMPermissionCollection.

Task Class

The Task class is, in effect, a simple task descriptor. A Task is the abstraction of the execution of an application (see javax.microedition.midlet.MIDlet). Tasks are started using the TaskManager.startTask() method, where the arguments specify the application suite and the class within the suite being the starting point of the application. Starting a new task attempts to execute corresponding application. A task has a status, as described in the TaskStatus enumeration, that describes corresponding application lifecycle state. A task has a priority with possible values as described in TaskPriority. Depending on whether the implementation supports multiple VMs, several tasks can run in parallel.There are special tasks called system tasks. Those tasks cannot be started or stopped via this API, but are started by the system. The isSystemTask() method can be used to find out whether a task is a considered a system task.

The Task class contains the following methods.

  • String getName()

    This is a convenience method for returning the name of the task. The returned string is the name of the application running in this task.

  • TaskPriority getPriority()

    This method returns the priority of given task.

  • public int getHeapUse()

    This method returns the heap use of given task.

  • public TaskStatus getStatus()

    This method returns the task's status.

  • public Suite getSuite()

    This method returns the suite information this task executed from.

  • public boolean isSystemTask()

    This method returns a boolean indicating whether a task is a system task.

InstallerErrorCode

The InstallerErrorCode provides several constants used by the installation routines. These constants are shown in Table 4-4.


Table 4-4 Installer Error Codes

Constant Description

ALREADY_INSTALLED

The JAD matches a version of a suite already installed.

APP_INTEGRITY_FAILURE_DEPENDENCY_CONFLICT

Application Integrity Failure: two or more dependencies exist on the component with the same name and vendor, but have different versions or hashs.

APP_INTEGRITY_FAILURE_DEPENDENCY_MISMATCH

Application Integrity Failure: there is a component name or vendor mismatch between the component JAD and IMlet or component JAD that depends on it.

APP_INTEGRITY_FAILURE_HASH_MISMATCH

Application Integrity Failure: hash mismatch.

ATTRIBUTE_MISMATCH

A attribute in both the JAD and JAR manifest does not match.

AUTHORIZATION_FAILURE

Application authorization failure, possibly indicating that the application was not digitally signed.

CA_DISABLED

Indicates that the trusted certificate authority (CA) for this suite has been disabled for software authorization.

CANCELED

Canceled by user.

CANNOT_AUTH

The server does not support basic authentication.

CIRCULAR_COMPONENT_DEPENDENCY

Circular dynamic component dependency.

COMPONENT_DEPS_LIMIT_EXCEEDED

Dynamic component dependencies limit exceeded.

CONTENT_HANDLER_CONFLICT

The installation of a content handler would conflict with an already installed handler.

CORRUPT_DEPENDENCY_HASH

A dependency has a corrupt hash code.

CORRUPT_JAR

An entry could not be read from the JAR.

CORRUPT_PROVIDER_CERT

The content provider certificate cannot be decoded.

CORRUPT_SIGNATURE

The JAR signature cannot be decoded.

DEVICE_INCOMPATIBLE

The device does not support either the configuration or profile in the JAD.

DUPLICATED_KEY

Duplicated JAD/manifest key attribute

EXPIRED_CA_KEY

The certificate authority's public key has expired.

EXPIRED_PROVIDER_CERT

The content provider certificate has expired.

INSUFFICIENT_STORAGE

Not enough storage for this suite to be installed.

INVALID_CONTENT_HANDLER

The MicroEdition-Handler-<n> JAD attribute has invalid values.

INVALID_JAD_TYPE

The server did not have a resource with the correct type or the JAD downloaded has the wrong media type.

INVALID_JAD_URL

The JAD URL is invalid.

INVALID_JAR_TYPE

The server did not have a resource with the correct type or the JAR downloaded has the wrong media type.

INVALID_JAR_URL

The JAR URL is invalid.

INVALID_KEY

A key for an attribute is not formatted correctly.

INVALID_NATIVE_LIBRARY

A native library contained within the JAR cannot be loaded.

INVALID_PAYMENT_INFO

Indicates that the payment information provided with the IMlet suite is incomplete or incorrect.

INVALID_PROVIDER_CERT

The signature of the content provider certificate is invalid.

INVALID_SIGNATURE

The signature of the JAR is invalid.

INVALID_VALUE

A value for an attribute is not formatted correctly.

INVALID_VERSION

The format of the version is invalid.

JAD_MOVED

The JAD URL for an installed suite is different than the original JAD URL.

JAD_NOT_FOUND

The JAD was not found.

JAD_SERVER_NOT_FOUND

The server for the JAD was not found.

JAR_CLASSES_VERIFICATION_FAILED

Not all classes within JAR package can be successfully verified with class verifier.

JAR_IS_LOCKED

Component or MIDlet or IMlet suite is locked by the system.

JAR_NOT_FOUND

The JAR was not found at the URL given in the JAD.

JAR_SERVER_NOT_FOUND

The server for the JAR was not found at the URL given in the JAD.

JAR_SIZE_MISMATCH

The JAR downloaded was not the same size as given in the JAD.

MISSING_CONFIGURATION

The configuration is missing from the manifest.

MISSING_DEPENDENCY_HASH

A dependency hash code is missing.

MISSING_DEPENDENCY_JAD_URL

A dependency JAD URL is missing.

MISSING_JAR_SIZE

The JAR size is missing.

MISSING_JAR_URL

The URL for the JAR is missing.

MISSING_PROFILE

The profile is missing from the manifest.

MISSING_PROVIDER_CERT

The content provider certificate is missing.

MISSING_SUITE_NAME

The name of MIDlet or IMlet suite is missing.

MISSING_VENDOR

The vendor is missing.

MISSING_VERSION

The version is missing.

NEW_VERSION

This suite is newer that the one currently installed.

NO_ERROR

No error.

OLD_VERSION

This suite is older that the one currently installed.

OTHER_ERROR

Other errors.

PROXY_AUTH

Indicates that the user must first authenticate with the proxy.

PUSH_CLASS_FAILURE

The class in a push attribute is not in MIDlet-<n> attribute.

PUSH_DUP_FAILURE

The connection in a push entry is already taken.

PUSH_FORMAT_FAILURE

The format of a push attribute has an invalid format.

PUSH_PROTO_FAILURE

The connection in a push attribute is not supported.

REVOKED_CERT

The certificate has been revoked.

RMS_INITIALIZATION_FAILURE

Failure to import RMS data.

SUITE_NAME_MISMATCH

The MIDlet or IMlet suite name does not match the one in the JAR manifest.

TOO_MANY_PROPS

Indicates that either the JAD or manifest has too many properties to fit into memory.

TRUSTED_OVERWRITE_FAILURE

Indicates that the user tried to overwrite a trusted suite with an untrusted suite during an update.

UNAUTHORIZED

Web server authentication failed or is required.

UNKNOWN_CA

The certificate authority (CA) that issued the content provider certificate is unknown.

UNKNOWN_CERT_STATUS

The certificate is unknown to OCSP server.

UNSUPPORTED_CERT

The content provider certificate has an unsupported version.

UNSUPPORTED_CHAR_ENCODING

Indicates that the character encoding specified in the MIME type is not supported.

UNSUPPORTED_PAYMENT_INFO

Indicates that the payment information provided with the MIDlet or IMlet suite is incompatible with the current implementation.

UNTRUSTED_PAYMENT_SUITE

Indicates that the MIDlet or IMlet suite has payment provisioning information but it is not trusted.

VENDOR_MISMATCH

The vendor does not match the one in the JAR manifest.

VERSION_MISMATCH

The version does not match the one in the JAR manifest.