FileDocCategorySizeDatePackage
MIDletSuiteStorage.javaAPI DocphoneME MR2 API (J2ME)23798Wed May 02 18:00:06 BST 2007com.sun.midp.midletsuite

MIDletSuiteStorage

public class MIDletSuiteStorage extends Object
This class manages the persistent data for MIDlet suites.

Each installed package is uniquely identified by a unique ID. Only suites installed or updated using this API appear in the list of known suites.

Fields Summary
private static com.sun.midp.security.SecurityToken
classSecurityToken
This class has a different security domain than the MIDlet suite.
private static MIDletSuiteStorage
masterStorage
This is the master storage object to synchronize all accesses
Constructors Summary
private MIDletSuiteStorage()
Private constructor to prevent outside instantiation.

    
Methods Summary
public native intcreateSuiteID()
Returns a unique identifier of MIDlet suite. Constructed from the combination of the values of the MIDlet-Name and MIDlet-Vendor attributes.

return
the platform-specific storage name of the application given by vendorName and appName

public native voiddisable(int id)
Disables a suite given its suite ID.

The method does not stop the suite if is in use. However any future attepts to run a MIDlet from this suite while disabled should fail.

param
id suite ID for the installed package
exception
IllegalArgumentException if the suite cannot be found
exception
MIDletSuiteLockedException is thrown, if the MIDletSuite is locked for updating

public native voidenable(int id)
Enables a suite given its suite ID.

The method does update an suites that are currently loaded for settings or of application management purposes.

param
id suite ID for the installed package
exception
IllegalArgumentException if the suite cannot be found
exception
MIDletSuiteLockedException is thrown, if the MIDletSuite is locked for updating

InstallInfogetInstallInfo(MIDletSuiteImpl midletSuite)
Get the installation information of a suite.

param
midletSuite Suite object
return
installation information
exception
IOException if an the information cannot be read

        return midletSuite.getInstallInfo();
    
public synchronized int[]getListOfSuites()
List all installed software packages by storage name.

return
an array of ints of the storage names for the installed packages
exception
SecurityException if the caller does not have permission to see what software is installed

        int n = getNumberOfSuites();
        if (n < 0) {
            if (Logging.REPORT_LEVEL <= Logging.ERROR) {
                Logging.report(Logging.ERROR, LogChannels.LC_AMS,
                    "Error in getNumberOfSuites0(): returned -1!");
            }
            n = 0;
        }

        int[] array = new int[n];

        if (n > 0) {
            getSuiteList(array);
        }

        return array;
    
public synchronized MIDletSuiteImplgetMIDletSuite(int id, boolean update)
Gets the MIDlet Suite from storage, and selects one midlet to be run.

param
id the unique ID of the suite given by the installer when it was downloaded
param
update true is this MIDletSuite need to be updated
exception
MIDletSuiteLockedException is thrown, if the MIDletSuite is locked; MIDletSuiteCorruptedException is thrown if the MIDletSuite is corrupted
return
MIDlet Suite reference

        if (!suiteExists(id)) {
            return null;
        }

        MIDletSuiteImpl.lockMIDletSuite(id, update);

        /*
         * save on startup time, get the properties at first getProperty call
         * and fill permissions on getPermission
         */
        return new MIDletSuiteImpl(id);
    
public synchronized byte[]getMIDletSuiteIcon(int suiteId, java.lang.String iconName)

param
suiteId unique identifier of the suite
param
iconName the name of the icon to retrieve
return

        byte[] iconBytes = null;

        if (iconName == null) {
            return null;
        }

        try {
            iconBytes = getMIDletSuiteIcon0(suiteId, iconName);

            if (iconBytes == null) {
                /* Search for icon in the image cache */
                iconBytes = loadCachedIcon0(suiteId, iconName);
            }

            if (iconBytes == null) {
                /* Search for icon in the suite JAR */
                iconBytes = JarReader.readJarEntry(
                    getMidletSuiteJarPath(suiteId), iconName);
            }
        } catch (Exception e) {
            iconBytes = null;
        }

        return iconBytes;
    
private static native byte[]getMIDletSuiteIcon0(int suiteId, java.lang.String iconName)
Retrieves the cached icon from the icon cache.

param
suiteId unique identifier of the suite
param
iconName the name of the icon to retrieve
return
cached image data if available, otherwise null

public synchronized MIDletSuiteInfogetMIDletSuiteInfo(int id)
Reads the basic information about the midlet suite from the storage.

param
id unique ID of the suite
exception
IOException if an the information cannot be read
exception
IllegalArgumentException if suiteId is invalid
return
MIDletSuiteInfo object with the suite's attributes


        MIDletSuiteInfo msi = new MIDletSuiteInfo(id);
        getMIDletSuiteInfoImpl0(id, msi);

        return msi;
    
public native voidgetMIDletSuiteInfoImpl0(int id, MIDletSuiteInfo msi)
Reads the basic information about the midlet suite from the storage.

param
id unique ID of the suite
param
msi object to fill
exception
IOException if an the information cannot be read
exception
IllegalArgumentException if suiteId is invalid

public static com.sun.midp.midletsuite.MIDletSuiteStoragegetMIDletSuiteStorage()
Returns a reference to the singleton MIDlet suite storage object.

return
the storage reference
exception
SecurityException if the caller does not have permission to install software

        MIDletSuite midletSuite =
            MIDletStateHandler.getMidletStateHandler().getMIDletSuite();

        if (midletSuite == null) {
            throw new
                IllegalStateException("This method can't be called before " +
                                      "a suite is started.");
        }

        midletSuite.checkIfPermissionAllowed(Permissions.AMS);

        return getMasterStorage();
    
public static com.sun.midp.midletsuite.MIDletSuiteStoragegetMIDletSuiteStorage(com.sun.midp.security.SecurityToken securityToken)
Returns a reference to the singleton MIDlet suite storage object.

param
securityToken security token of the calling class
return
the storage reference
exception
SecurityException if the caller does not have permission to manage midlets

        securityToken.checkIfPermissionAllowed(Permissions.AMS);

        return getMasterStorage();
    
private static com.sun.midp.midletsuite.MIDletSuiteStoragegetMasterStorage()
Returns a reference to the singleton storage object.

return
the storage reference

        if (masterStorage == null) {
            masterStorage = new MIDletSuiteStorage();

            int status = loadSuitesIcons0();
            if (Logging.REPORT_LEVEL <= Logging.ERROR) {
                if (status != 0) {
                    Logging.report(Logging.ERROR, LogChannels.LC_AMS,
                        "Can't load the cached icons, error code" + status);
                }
            }
        }

        return masterStorage;
    
public native synchronized java.lang.StringgetMidletSuiteAppImagePath(int id)
Get the path for the MONET image of the specified suite.

param
id unique ID of the suite
return
image path or null if the suite does not exist

public synchronized java.lang.String[]getMidletSuiteClassPath(int id)
Get the midlet suite's class path including a path to the MONET image of the specified suite and a path to the suite's jar file.

param
id unique ID of the suite
return
class path or null if the suite does not exist

        String jarFile = getMidletSuiteJarPath(id);

        if (Constants.MONET_ENABLED && id != MIDletSuite.INTERNAL_SUITE_ID) {
            String bunFile = getMidletSuiteAppImagePath(id);
            return new String[]{bunFile, jarFile};
        }
        return new String[]{jarFile};
    
public native synchronized java.lang.StringgetMidletSuiteJarPath(int id)
Get the class path for a suite.

param
id unique ID of the suite
return
class path or null if the suite does not exist

private native intgetNumberOfSuites()
Get the number of installed of MIDlet suites.

return
the number of installed suites or -1 in case of error

static java.lang.String[]getPropertiesStrings(com.sun.midp.util.Properties props)
Fill plain array with properties key/value String pairs. It's needed to simplify properties using in a native code.

param
props properties to get Strings from
return
array of Strings filled with property key/value pairs

        if (props != null) {
            int size = props.size();
            String[] res = new String[size * 2];
            for (int i = 0, j = 0; i < size; i++) {
                res[j++] = props.getKeyAt(i);
                res[j++] = props.getValueAt(i);
            }
            return res;
        } else return null;
    
public native intgetStorageUsed(int id)
Gets the amount of storage on the device that this suite is using. This includes the JAD, JAR, management data, and RMS.

param
id ID of a MIDlet suite
return
number of bytes of storage the suite is using

public static native intgetSuiteID(java.lang.String vendor, java.lang.String name)
Gets the unique identifier of MIDlet suite.

param
vendor name of the vendor that created the application, as given in a JAD file
param
name name of the suite, as given in a JAD file
return
suite ID of the midlet suite given by vendor and name or MIDletSuite.UNUSED_SUITE_ID if the suite does not exist

private native voidgetSuiteList(int[] suites)
Retrieves the list of MIDlet suites and store them into a Vector object. Each element in the Vector is the storage name of an installed application.

param
suites an empty array of suite IDs to fill, call getNumberOfSuites to know how big to make the array

public static voidinitSecurityToken(com.sun.midp.security.SecurityToken token)
Initializes the security token for this class, so it can perform actions that a normal MIDlet Suite cannot.

param
token security token for this class.

        if (classSecurityToken != null) {
            return;
        }

        classSecurityToken = token;
        MIDletSuiteImpl.initSecurityToken(classSecurityToken);
    
public java.lang.String[]listRecordStores(int suiteId)
Returns an array of the names of record stores owned by the MIDlet suite. The order of RecordStore names returned is implementation dependent.

param
suiteId ID of the MIDlet suite that owns the record store
return
array of the names of record stores owned by the MIDlet suite or null if the MIDlet suite does not have any record stores

        return RecordStoreImpl.listRecordStores(classSecurityToken, suiteId);
    
private static native byte[]loadCachedIcon0(int suiteId, java.lang.String iconName)
Loads suite icon data from image cache.

param
suiteId the ID of suite the icon belongs to
param
iconName the name of the icon to be loaded
return
cached image data if available, otherwise null

public static native intloadSuitesIcons0()
Loads the cached icons from the permanent storage into memory.

return
status code (0 if no errors)

private native voidnativeStoreSuite(InstallInfo installInfo, SuiteSettings suiteSettings, MIDletSuiteInfo msi, java.lang.String[] jadProps, java.lang.String[] jarProps)
Stores or updates a midlet suite.

param
installInfo structure containing the following information:
id - unique ID of the suite;
jadUrl - where the JAD came from, can be null;
jarUrl - where the JAR came from;
jarFilename - name of the downloaded MIDlet suite jar file;
suiteName - name of the suite;
suiteVendor - vendor of the suite;
authPath - authPath if signed, the authorization path starting
with the most trusted authority;
domain - security domain of the suite;
trusted - true if suite is trusted;
verifyHash - may contain hash value of the suite with
preverified classes or may be NULL;
param
suiteSettings structure containing the following information:
permissions - permissions for the suite;
pushInterruptSetting - defines if this MIDlet suite interrupt
other suites;
pushOptions - user options for push interrupts;
suiteId - unique ID of the suite, must be equal to the one given
in installInfo;
boolean enabled - if true, MIDlet from this suite can be run;
param
msi structure containing the following information:
suiteId - unique ID of the suite, must be equal to the value given
in installInfo and suiteSettings parameters;
storageId - ID of the storage where the MIDlet should be installed;
numberOfMidlets - number of midlets in the suite;
displayName - the suite's name to display to the user;
midletToRunClassName - the midlet's class name if the suite contains
only one midlet, ignored otherwise;
iconName - name of the icon for this suite.
param
jadProps properties the JAD as an array of strings in key/value pair order, can be null if jadUrl is null
param
jarProps properties of the manifest as an array of strings in key/value pair order
exception
IOException is thrown, if an I/O error occurs during storing the suite
exception
MIDletSuiteLockedException is thrown, if the MIDletSuite is locked

public voidremove(int id)
Removes a software package given its suite ID. The content handler manager is called to remove any registrations, if any.

If the component is in use it must continue to be available to the other components that are using it. The resources it consumes must not be released until it is not in use.

param
id suite ID for the installed package
exception
IllegalArgumentException if the suite cannot be found
exception
MIDletSuiteLockedException is thrown, if the MIDletSuite is locked

        remove0(id);

        /*
         * If no exception occurs,
         * remove the content handler registrations, if any.
         */
        CHManager.getManager(classSecurityToken).uninstall(id);
    
private native voidremove0(int id)
Native remove of a software package given its suite ID.

If the component is in use it must continue to be available to the other components that are using it. The resources it consumes must not be released until it is not in use.

param
id suite ID for the installed package
exception
IllegalArgumentException if the suite cannot be found
exception
MIDletSuiteLockedException is thrown, if the MIDletSuite is locked

public voidsaveSuiteSettings(int id, byte pushInterruptSetting, int pushOptions, byte[] permissions)
Saves any of the settings (security or others) that the user may have changed.

param
id ID of the suite
param
pushInterruptSetting push interrupt setting
param
pushOptions push options
param
permissions security permissions for the suite
exception
IOException if an error happens while writing

        SuiteSettings settings = new SuiteSettings(id);
        settings.setPushInterruptSetting(pushInterruptSetting);
        settings.setPushOptions(pushOptions);
        settings.setPermissions(permissions);
        settings.save();
    
public synchronized voidstoreSuite(InstallInfo installInfo, SuiteSettings suiteSettings, MIDletSuiteInfo msi, com.sun.midp.util.Properties jadProps, com.sun.midp.util.Properties jarProps)
Stores or updates a midlet suite.

param
installInfo structure containing the following information:
id - unique ID of the suite;
jadUrl - where the JAD came from, can be null;
jarUrl - where the JAR came from;
jarFilename - name of the downloaded MIDlet suite jar file;
suiteName - name of the suite;
suiteVendor - vendor of the suite;
authPath - authPath if signed, the authorization path starting
with the most trusted authority;
domain - security domain of the suite;
trusted - true if suite is trusted;
verifyHash - may contain hash value of the suite with
preverified classes or may be NULL;
param
suiteSettings structure containing the following information:
permissions - permissions for the suite;
pushInterruptSetting - defines if this MIDlet suite interrupt
other suites;
pushOptions - user options for push interrupts;
suiteId - unique ID of the suite, must be equal to the one given
in installInfo;
boolean enabled - if true, MIDlet from this suite can be run;
param
msi structure containing the following information:
suiteId - unique ID of the suite, must be equal to the value given
in installInfo and suiteSettings parameters;
storageId - ID of the storage where the MIDlet should be installed;
numberOfMidlets - number of midlets in the suite;
displayName - the suite's name to display to the user;
midletToRunClassName - the midlet's class name if the suite contains
only one midlet, ignored otherwise;
iconName - name of the icon for this suite.
param
jadProps properties defined in the application descriptor
param
jarProps properties of the manifest
exception
IOException is thrown, if an I/O error occurs during storing the suite
exception
MIDletSuiteLockedException is thrown, if the MIDletSuite is locked

        /*
         * Convert the property args to String arrays to save
         * creating the native KNI code to access the object.
         */
        String[] strJadProperties = getPropertiesStrings(jadProps);
        String[] strJarProperties = getPropertiesStrings(jarProps);

        nativeStoreSuite(installInfo, suiteSettings, msi,
            strJadProperties, strJarProperties);
    
public native voidstoreSuiteVerifyHash(int id, byte[] verifyHash)
Stores hash value of the suite with preverified classes

param
id unique ID of the suite
param
verifyHash hash value of the suite with preverified classes

public native booleansuiteExists(int id)
Tells if a suite exists.

param
id ID of a suite
return
true if a suite of the given storage name already exists on the system
exception
MIDletSuiteCorruptedException is thrown if the MIDletSuite is corrupted

public static native java.lang.StringsuiteIdToString(int suiteId)
Java interface for midp_suiteid2pcsl_string().

param
suiteId unique ID of the suite
return
string representation of the given suiteId