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

Manager

public class Manager extends MIDlet implements ApplicationManager
This is an implementation of the ApplicationManager interface for the single VM mode of the VM. In this mode the VM is shut down each time a MIDlet exits. Application manager controls midlet life cycle: - installs, updates and removes midlets/midlet suites - launches 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 DisplayError
displayError
UI to display error alerts.
private AppManagerUI
managerUI
Application Selector Screen.
Constructors Summary
public Manager()
Create and initialize a new Manager MIDlet.


                
      
        midletSuiteStorage = MIDletSuiteStorage.getMIDletSuiteStorage();

        GraphicalInstaller.initSettings();

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

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

        // Get arguments to create AppManagerUI
        String suiteIdStr = getAppProperty("arg-0");
        int suiteId = MIDletSuite.UNUSED_SUITE_ID;
        try {
            suiteId = Integer.parseInt(suiteIdStr);
        } catch (NumberFormatException e) {
            suiteId = MIDletSuite.UNUSED_SUITE_ID;
        }

        if (suiteId != MIDletSuite.UNUSED_SUITE_ID) {
            MIDletSuiteInfo sui = new MIDletSuiteInfo(suiteId);
            if (suiteId == MIDletSuite.INTERNAL_SUITE_ID) {
                // For internal suites midlet class name should be specified
                sui.midletToRun = getAppProperty("arg-1");
            }
            // AppManagerUI will be set to be current at the end of its constructor
            managerUI = new AppManagerUI(this, display, displayError, first, sui);
        } else {
            // AppManagerUI will be set to be current at the end of its constructor
            managerUI = new AppManagerUI(this, display, displayError, first, null);
        }

        if (first) {
            first = false;
        }
    
Methods Summary
public voiddestroyApp(boolean unconditional)
Destroy cleans up.

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

        GraphicalInstaller.saveSettings(null, MIDletSuite.UNUSED_SUITE_ID);

        if (MIDletSuiteUtils.getNextMIDletSuiteToRun() !=
                MIDletSuite.UNUSED_SUITE_ID) {
            /*
             * A MIDlet was pushed.
             * So make sure this MIDlet is run after the pushed one.
             *
             * Note this call only is
             * needed now because suites are not run concurrently and must
             * be queued to be run after this MIDlet is destroyed.
             */
            updateLastSuiteToRun();
        }
    
public voidexitMidlet(RunningMIDletSuiteInfo suiteInfo)
Exit the midlet with the passed in midlet suite info.

param
suiteInfo information for the midlet to be terminated

public voidinstallSuite()
Discover and install a suite.

        try {
            MIDletStateHandler.getMidletStateHandler().startMIDlet(
                DISCOVERY_APP,
                Resource.getString(ResourceConstants.INSTALL_APPLICATION));

            yieldForNextMidlet();


        } catch (Exception ex) {
            displayError.showErrorAlert(Resource.getString
				    (ResourceConstants.INSTALL_APPLICATION),
					ex, null, null);
        }
    
public voidlaunchCaManager()
Launch the CA manager.

        try {
            MIDletStateHandler.getMidletStateHandler().startMIDlet(
                CA_MANAGER,
                Resource.getString(ResourceConstants.CA_MANAGER_APP));

            yieldForNextMidlet();


        } 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,
                                      suiteInfo.displayName);

            /*
             * Give the new MIDlet the screen by destroy our self,
             * because we are running in a limited VM and must
             * restart the VM let the select suite run.
             */
            yieldForNextMidlet();



        } catch (Exception ex) {
            displayError.showErrorAlert(suiteInfo.displayName, ex, null, null);
        }
    
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

public voidpauseApp()
Pause; there are no resources that need to be released.

    
public voidshutDown()
Shut down the system

        MIDletProxyList.getMIDletProxyList().shutdown();
    
public voidstartApp()
Start puts up a List of the MIDlets found in the descriptor file.

    
private voidupdateLastSuiteToRun()
Set this MIDlet to run after the next MIDlet is run.

        MIDletSuiteInfo msi = managerUI.getSelectedMIDletSuiteInfo();
        if (msi == null) {
            MIDletSuiteUtils.setLastSuiteToRun(MIDletStateHandler.
                    getMidletStateHandler().getMIDletSuite().getID(),
                    getClass().getName(), null, null);
        } else {
            String midletToRun = null;
            if (msi.suiteId == MIDletSuite.INTERNAL_SUITE_ID) {
                midletToRun = msi.midletToRun;
            }
            MIDletSuiteUtils.setLastSuiteToRun(MIDletStateHandler.
                    getMidletStateHandler().getMIDletSuite().getID(),
                    getClass().getName(), String.valueOf(msi.suiteId), midletToRun);
        }
    
public voidupdateSuite(RunningMIDletSuiteInfo suiteInfo)
Update a suite.

param
suiteInfo information for suite to update

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

        /*
         * Setting arg 0 to "U" signals that arg 1 is a suite ID for updating.
         */
        midletSuite.setTempProperty(null, "arg-0", "U");
        midletSuite.setTempProperty(null, "arg-1",
            String.valueOf(suiteInfo.suiteId));
        try {
            midletStateHandler.startMIDlet(INSTALLER, null);
            yieldForNextMidlet();

        } catch (Exception ex) {
            displayError.showErrorAlert(suiteInfo.displayName, ex, null, null);
        }
    
private voidyieldForNextMidlet()
Yield the VM so the next MIDlet can run. To yield set this MIDlet as last MIDlet run after the next MIDlet suite is done and then destroy this MIDlet. Note: if the system is changed to allow multiple suites to run concurrently, this method will not be needed.

        // We want this MIDlet to run after the next MIDlet is run.
        updateLastSuiteToRun();
        destroyApp(false);
        notifyDestroyed();