FileDocCategorySizeDatePackage
MVMManager.javaAPI DocphoneME MR2 API (J2ME)11456Wed May 02 18:00:02 BST 2007com.sun.midp.appmanager

MVMManager

public class MVMManager extends MIDlet implements ApplicationManager, MIDletProxyListListener, DisplayControllerListener
This is an implementation of the ApplicationManager interface for the MVM mode of the VM capable of running with more than 1 midlet concurrently. Application manager controls midlet life cycle: - installs, updates and removes midlets/midlet suites - launches, moves to foreground and terminates midlets - displays info about a midlet/midlet suite - shuts down the AMS system

Fields Summary
private static final String
DISCOVERY_APP
Constant for the discovery application class name.
private static final String
INSTALLER
Constant for the graphical installer class name.
private static final String
CA_MANAGER
Constant for the CA manager class name.
private static boolean
first
True until constructed for the first time.
private MIDletSuiteStorage
midletSuiteStorage
MIDlet Suite storage object.
private AppManagerUI
appManagerUI
Screen that displays all installed midlets and installer
private MIDletProxyList
midletProxyList
MIDlet proxy list reference.
private DisplayError
displayError
UI to display error alerts.
Constructors Summary
public MVMManager()
Create and initialize a new MVMManager MIDlet.


                
      
        MIDletProxy thisMidlet;

        midletSuiteStorage = MIDletSuiteStorage.getMIDletSuiteStorage();

        /*
         * Listen to the MIDlet proxy list.
         * this allows us to notify the Application Selector
         * of any changes whenever switch back to the AMS.
         */
        midletProxyList = MIDletProxyList.getMIDletProxyList();
        midletProxyList.addListener(this);

        // The proxy for this MIDlet may not have been create yet.
        for (; ; ) {
            thisMidlet = midletProxyList.findMIDletProxy(
                MIDletSuite.INTERNAL_SUITE_ID, this.getClass().getName());

            if (thisMidlet != null) {
                break;
            }

            try {
                Thread.sleep(10);
            } catch (InterruptedException ie) {
                // ignore
            }
        }

        MVMDisplayController dc = new MVMDisplayController(
            midletProxyList, thisMidlet); 
        midletProxyList.setDisplayController(dc);
        dc.addListener(this);

        IndicatorManager.init(midletProxyList);

        GraphicalInstaller.initSettings();

        first = (getAppProperty("logo-displayed") == null);

        Display display = Display.getDisplay(this);
        displayError = new DisplayError(display);

        // AppManagerUI will be set to be current at the end of its constructor
        appManagerUI = new AppManagerUI(this, display, displayError, first,
                                        null);

        if (first) {
            first = false;
        }
    
Methods Summary
public voiddestroyApp(boolean unconditional)
Destroy midlet. Cleans up the resources used.

param
unconditional is ignored; this object always destroys itself when requested.

        /*
         * Save user settings such as currently selected MIDlet
         * This may not be needed since we are always running
         * IMPL_NOTE: remove this
         */
        GraphicalInstaller.saveSettings(null, MIDletSuite.UNUSED_SUITE_ID);

        // Ending the MIDlet ends all others.
        midletProxyList.shutdown();
    
public voidexitMidlet(RunningMIDletSuiteInfo suiteInfo)
Exit the midlet with the passed in midlet suite info.

param
suiteInfo information for the midlet to be terminated

        try {
            if (suiteInfo != null) {
                suiteInfo.proxy.destroyMidlet();
            }

        } catch (Exception ex) {
            displayError.showErrorAlert(suiteInfo.displayName, ex, null, null);
        }
    
public voidinstallSuite()
Discover and install a suite.

        try {
            MIDletSuiteUtils.execute(MIDletSuite.INTERNAL_SUITE_ID,
                DISCOVERY_APP,
                Resource.getString(ResourceConstants.INSTALL_APPLICATION));
        } catch (Exception ex) {
            displayError.showErrorAlert(Resource.getString(
                                  ResourceConstants.INSTALL_APPLICATION),
                              ex, null, null);
        }
    
public voidlaunchCaManager()
Launch the CA manager.

        try {
            MIDletSuiteUtils.execute(MIDletSuite.INTERNAL_SUITE_ID,
                CA_MANAGER,
                Resource.getString(ResourceConstants.CA_MANAGER_APP));
        } catch (Exception ex) {
            displayError.showErrorAlert(Resource.getString(
                ResourceConstants.CA_MANAGER_APP), ex, null, null);
        }
    
public voidlaunchSuite(RunningMIDletSuiteInfo suiteInfo, java.lang.String midletToRun)
Launches a suite.

param
suiteInfo information for suite to launch
param
midletToRun class name of the MIDlet to launch


        if (Constants.MEASURE_STARTUP) {
            System.err.println("Application Startup Time: Begin at "
                                +System.currentTimeMillis());
        }

        try {
            // Create an instance of the MIDlet class
            // All other initialization happens in MIDlet constructor
            MIDletSuiteUtils.execute(suiteInfo.suiteId, midletToRun, null);
        } catch (Exception ex) {
            displayError.showErrorAlert(suiteInfo.displayName, ex, null, null);
        }
    
public voidmidletAdded(MIDletProxy midlet)
Called when a MIDlet is added to the list.

param
midlet The proxy of the MIDlet being added

        appManagerUI.notifyMidletStarted(midlet);
    
public voidmidletRemoved(MIDletProxy midlet)
Called when a MIDlet is removed from the list.

param
midlet The proxy of the removed MIDlet

        appManagerUI.notifyMidletExited(midlet);
    
public voidmidletStartError(int externalAppId, int suiteId, java.lang.String className, int errorCode, java.lang.String errorDetails)
Called when error occurred while starting a MIDlet object.

param
externalAppId ID assigned by the external application manager
param
suiteId Suite ID of the MIDlet
param
className Class name of the MIDlet
param
errorCode start error code
param
errorDetails start error details

        appManagerUI.notifyMidletStartError(suiteId, className,
            errorCode, errorDetails);
    
public voidmidletUpdated(MIDletProxy midlet, int fieldId)
Called when the state of a MIDlet in the list is updated.

param
midlet The proxy of the MIDlet that was updated
param
fieldId code for which field of the proxy was updated

        appManagerUI.notifyMidletStateChanged(midlet);
    
public voidmoveToForeground(RunningMIDletSuiteInfo suiteInfo)
Bring the midlet with the passed in midlet suite info to the foreground.

param
suiteInfo information for the midlet to be put to foreground

        try {

            if (Constants.MEASURE_STARTUP) {
                System.err.println("Switch To Foreground Time: Begin at " +
                    System.currentTimeMillis());
            }

            if (suiteInfo != null) {
                midletProxyList.setForegroundMIDlet(suiteInfo.proxy);
            }

        } catch (Exception ex) {
            displayError.showErrorAlert(suiteInfo.displayName, ex, null, null);
        }
    
public voidpauseApp()
Pause; there are no resources that need to be released.

    
public voidselectForeground(boolean onlyFromLaunchedList)
Called when going to select midlet to bring it to foreground.

param
onlyFromLaunched true if midlet should be selected from the list of already launched midlets, if false then possibility to launch midlet is needed.

        appManagerUI.showMidletSwitcher(onlyFromLaunchedList);
    
public voidshutDown()
Shut down the system

        midletProxyList.shutdown();
    
public voidstartApp()
Start app; there is nothing that needs to be done at start up.

    
public voidupdateSuite(RunningMIDletSuiteInfo suiteInfo)
Update a suite.

param
suiteInfo information for suite to update

        /*
         * Setting arg 0 to "U" signals that arg 1 is a suite ID for updating.
         */
        try {
            MIDletSuiteUtils.executeWithArgs(MIDletSuite.INTERNAL_SUITE_ID,
                                      INSTALLER,
                                      suiteInfo.displayName,
                                      "U", String.valueOf(suiteInfo.suiteId),
                                      null);
        } catch (Exception ex) {
            displayError.showErrorAlert(suiteInfo.displayName, ex, null, null);
        }