FileDocCategorySizeDatePackage
Manager.javaAPI DocJ2ME MIDP 2.048117Thu Nov 07 12:02:24 GMT 2002com.sun.midp.dev

Manager

public class Manager extends MIDlet implements CommandListener
The Graphical MIDlet suite manager.

Starts with a selector that provides a list of MIDlet suites and a set of commands to perform. It displays the MIDlet names for a suite under the MIDlet suite name, except if there is only one suite then instead of display the suite name, MIDlet-1 name and icon are used.

The commands are:

  • Install: Let the user install a suite from a list suites obtained using an HTML URL given by the user. This list is derived by extracting the links with hrefs that are in quotes and end with ".jad" from the HTML page. An href in an extracted link is assumed to be an absolute URL for a MIDP application descriptor.
  • Launch: Launch the suite the user selected.
  • Remove: Remove the suite (with confirmation) the user selected.
  • Update: Update the suite the user selected.
  • Info: Show the user general information of the selected suite.
  • Settings: Let the user change the manager's settings.

Fields Summary
private static final String
SMALL_COPYRIGHT
Translated small copyright string.
private static final String
COPYRIGHT
Translated long copyright string.
private static Image
suiteIcon
Cache of the suite icon.
private static Image
emptyIcon
Cache of the empty icon.
private static Image
singleSuiteIcon
Cache of the single suite icon.
private static Image
javaLogo
Cache of the Java logo.
private static Image
homeScreenGraphic
Cache of the home screen graphic.
static boolean
colorDisplay
So the static method can know if there is a color display.
private static boolean
first
True until constructed for the first time.
private Installer
installer
The installer that is being used to install or update a suite.
private List
mlist
List of all the MIDlet suites.
private Display
display
Display for this MIDlet.
private long
lastDisplayChange
Keeps track of when the display last changed, in millseconds.
private int
mcount
Number of midlets in minfo.
private MIDletSuiteInfo[]
minfo
MIDlet suite information, class, name, icon; one per MIDlet suite.
private int
selectedSuite
Currently selected suite.
private ChoiceGroup
pushChoice
The application push permission setting.
private ChoiceGroup
netChoice
The application network permission setting.
private ChoiceGroup
serverChoice
The application network server permission setting.
private ChoiceGroup
commChoice
The application comm port permission setting.
private Command
appsCmd
Command object for "Apps" command for home screen.
private Command
launchCmd
Command object for "Launch".
private Command
infoCmd
Command object for "Info".
private Command
removeCmd
Command object for "Remove".
private Command
updateCmd
Command object for "Update".
private Command
appSettingsCmd
Command object for "Application settings".
private Command
aboutCmd
Command object for "About".
private Command
saveAppSettingsCmd
Command object for "OK" command for application settings form.
private Command
backCmd
Command object for "Back" command for back to list.
private Command
cancelCmd
Command object for "Cancel" command for the remove form.
private Command
removeOkCmd
Command object for "Remove" command for the remove form.
Constructors Summary
public Manager()
Create and initialize a new Manager MIDlet.

        installer = Installer.getInstaller();
        display = Display.getDisplay(this);
        colorDisplay = display.isColor();
        mcount = 0;
        minfo = new MIDletSuiteInfo[20];
        readMIDletSuiteInfo();
        first = getAppProperty("logo-displayed").equals("F");
        String runMessage;

        GraphicalInstaller.initSettings();

        setupList();

        if (mcount > 0) {
            mlist.addCommand(infoCmd);
            mlist.addCommand(removeCmd);
            mlist.addCommand(updateCmd);
            mlist.addCommand(appSettingsCmd);
        }

        mlist.addCommand(launchCmd);
        mlist.addCommand(backCmd);
        mlist.addCommand(aboutCmd);
        mlist.setCommandListener(this); // Listen for the selection

        runMessage = getAppProperty("run-message");
        if (runMessage != null) {
            Alert error = new Alert(null);

            error.setString(runMessage);
            display.setCurrent(error, mlist);
        } else if (first) {
            first = false;
            displayHomeScreen();
        } else {
            display.setCurrent(mlist);
        }
    
Methods Summary
private voidaddMIDletSuite(com.sun.midp.dev.Manager$MIDletSuiteInfo info)
Add a MIDlet suite to the list.

param
info MIDlet suite information to add to MIDlet

        if (mcount >= minfo.length) {
            MIDletSuiteInfo[] n = new MIDletSuiteInfo[mcount+4];
            System.arraycopy(minfo, 0, n, 0, mcount);
            minfo = n;
        }

        minfo[mcount++] = info;
    
private voidappendMIDletsToForm(MIDletSuite midletSuite, Form form)
Appends a names of all the MIDlets in a suite to a Form, one per line.

param
midletSuite suite of MIDlets
param
form form to append to

        int numberOfMidlets;
        MIDletInfo midletInfo;
        StringItem item;

        numberOfMidlets = midletSuite.getNumberOfMIDlets();
        for (int i = 1; i <= numberOfMidlets; i++) {
            midletInfo = new MIDletInfo(
                             midletSuite.getProperty("MIDlet-" + i));

            item = new StringItem(null, midletInfo.name);
            item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
            form.append(item);
        }
    
public voidcommandAction(Command c, Displayable s)
Respond to a command issued on any Screen.

param
c command activiated by the user
param
s the Displayable the command was on.

        if (c == aboutCmd) {
            Alert a = new Alert(null);
                
            a.setImage(getJavaLogo());
            a.setString(COPYRIGHT);
            a.setTimeout(Alert.FOREVER);

            display.setCurrent(a, mlist);
            return;
        }

        if (s == mlist) {
            if (c == backCmd) {
                displayHomeScreen();
                return;
            }

            // save the selected suite for the removeOk command
            selectedSuite = mlist.getSelectedIndex();

            // The first suite is built-in suite
            selectedSuite--;

            if (c == List.SELECT_COMMAND || c == launchCmd) {


                if (selectedSuite == -1) {
                    // The built-in Install Application MIDlet was selected.
                    installSuite();
                    return;
                }

                launchSuite(minfo[selectedSuite]);
                return;
            }

            if (selectedSuite == -1) {
                // The built-in Install Application MIDlet was selected.
                displayInstallAppWarning();
                return;
            }

            if (c == infoCmd) {
                displaySuiteInfo(minfo[selectedSuite]);
                return;
            }

            if (c == removeCmd) {
                confirmRemove(minfo[selectedSuite]);
                return;
            }

            if (c == updateCmd) {
                updateSuite(minfo[selectedSuite]);
                return;
            }

            if (c == appSettingsCmd) {
                getApplicationSettings(minfo[selectedSuite]);
                return;
            }
        }

        if (c == removeOkCmd) {
            removeSuite(minfo[selectedSuite]);
            return;
        }

        if (c == saveAppSettingsCmd) {
            saveApplicationSettings(minfo[selectedSuite]);
            return;
        }

        if (c == appsCmd || c == backCmd || c == cancelCmd) {
            // goto back to the main list of suites
            display.setCurrent(mlist);
            return;
        }
    
private voidconfirmRemove(com.sun.midp.dev.Manager$MIDletSuiteInfo suiteInfo)
Confirm the removal of a suite.

param
suiteInfo information for suite to remove

        Form confirmForm;
        StringBuffer temp = new StringBuffer(40);
        Item item;
        String extraConfirmMsg;
        String[] values = new String[1];

        try {
            confirmForm = new Form(null);

            confirmForm.setTitle(Resource.getString("Confirmation"));

            if (suiteInfo.singleMidlet) {
                values[0] = suiteInfo.displayName;
            } else {
                values[0] =
                    suiteInfo.midletSuite.getProperty(
                        Installer.SUITE_NAME_PROP);
            }

            item = new StringItem(null, Resource.getString(
                      "Are you sure you want to remove %1?", values));
            item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
            confirmForm.append(item);


            extraConfirmMsg = 
                suiteInfo.midletSuite.getProperty("MIDlet-delete-confirm");
            if (extraConfirmMsg != null) {
                temp.setLength(0);
                temp.append(" \n");
                temp.append(extraConfirmMsg);
                item = new StringItem(null, temp.toString());
                item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
                confirmForm.append(item);
            }

            if (!suiteInfo.singleMidlet) {
                temp.setLength(0);
                temp.append(Resource.getString("This suite contains"));
                temp.append(": ");
                item = new StringItem(temp.toString(), "");
                item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
                confirmForm.append(item);
                appendMIDletsToForm(suiteInfo.midletSuite, confirmForm);
            }

            temp.setLength(0);
            temp.append(" \n");
            temp.append(Resource.getString(
                "Once removed, %1 will have to be reinstalled.", values));
            item = new StringItem("", temp.toString());
            confirmForm.append(item);
        } catch (Exception ex) {
            temp.setLength(0);
            temp.append(suiteInfo.displayName);
            temp.append("\n");
            temp.append(Resource.getString("Exception"));
            temp.append(": ");
            temp.append(ex.toString());

            Alert a = new Alert(Resource.getString("Cannot access: "), 
                                temp.toString(), null, AlertType.ERROR);
            a.setTimeout(Alert.FOREVER);
            display.setCurrent(a, mlist);
            return;
        }

        confirmForm.addCommand(cancelCmd);
        confirmForm.addCommand(removeOkCmd);
        confirmForm.setCommandListener(this);
        display.setCurrent(confirmForm);
    
public voiddestroyApp(boolean unconditional)
Destroy cleans up.

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

        resetSettings();
    
private voiddisplayHomeScreen()
Display the home screen.

        Form home = new Form("");

        mlist.setSelectedIndex(0, true);

        home.append(
            new ImageItem(null, getJavaLogo(),
                          ImageItem.LAYOUT_NEWLINE_BEFORE +
                          ImageItem.LAYOUT_CENTER +
                          ImageItem.LAYOUT_NEWLINE_AFTER, null));
        home.append(
            new ImageItem(null, getHomeScreenGraphic(),
                          ImageItem.LAYOUT_NEWLINE_BEFORE +
                          ImageItem.LAYOUT_CENTER +
                          ImageItem.LAYOUT_NEWLINE_AFTER, null));
        home.addCommand(appsCmd);
        home.setCommandListener(this);

        display.setCurrent(home);
    
private voiddisplayInstallAppWarning()
Display the standard warning for Install Application when any command but launch is selected.

        Alert a = new Alert(null, Resource.getString(
                  "This operation does not apply to Install Application " +
                  "because Install Application is part of the system on " +
                  "this device. Use Install Application to find and " +
                  "install applications."), null, AlertType.INFO);

        a.setTimeout(4000);
        display.setCurrent(a, mlist);
        return;
    
private voiddisplaySuccessMessage(java.lang.String successMessage)
Alert the user that an action was successful.

param
successMessage message to display to user

        Image icon;
        Alert successAlert;

        icon = GraphicalInstaller.getIconFromStorage(
                       (colorDisplay ? "_dukeok8.png" : "_dukeok2.png"));

        successAlert = new Alert(null, successMessage, icon, null);

        successAlert.setTimeout(GraphicalInstaller.ALERT_TIMEOUT);

        // We need to prevent "flashing" on fast development platforms.
        while (System.currentTimeMillis() - lastDisplayChange <
               GraphicalInstaller.ALERT_TIMEOUT);

        display.setCurrent(successAlert, mlist);
        lastDisplayChange = System.currentTimeMillis();
    
private voiddisplaySuiteInfo(com.sun.midp.dev.Manager$MIDletSuiteInfo suiteInfo)
Display the information for a suite.

param
suiteInfo information for suite to display

        Form infoForm;
        String name;
        Image icon;
        StringBuffer label = new StringBuffer(40);
        StringBuffer value = new StringBuffer(40);
        Item item;
        String temp;

        try {
            infoForm = new Form(null);

            if (suiteInfo.singleMidlet) {
                name = suiteInfo.displayName;
                icon = suiteInfo.icon;
            } else {
                name = suiteInfo.midletSuite.getProperty(
                          Installer.SUITE_NAME_PROP);
                icon = getSuiteIcon();
            }

            label.append(Resource.getString("Info"));
            label.append(": ");
            label.append(name);
            infoForm.setTitle(label.toString());

            infoForm.append(
                new ImageItem(null, icon, ImageItem.LAYOUT_NEWLINE_BEFORE +
                              ImageItem.LAYOUT_CENTER +
                              ImageItem.LAYOUT_NEWLINE_AFTER, null));

            // round up the size to a Kilobyte
            label.setLength(0);
            label.append(Resource.getString("Size"));
            label.append(": ");
            value.append(
                Integer.toString((suiteInfo.midletSuite.getStorageUsed() +
                    1023) / 1024));
            value.append(" K");
            item = new StringItem(label.toString(), value.toString());
            item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
            infoForm.append(item);

            label.setLength(0);
            label.append(Resource.getString("Version"));
            label.append(": ");
            item = new StringItem(label.toString(),
                suiteInfo.midletSuite.getProperty(Installer.VERSION_PROP));
            item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
            infoForm.append(item);

            label.setLength(0);

            if (suiteInfo.midletSuite.isTrusted()) {
                temp = "Authorized Vendor";
            } else {
                temp = "Vendor";
            }

            label.append(Resource.getString(temp));
            label.append(": ");
            item = new StringItem(label.toString(),
                suiteInfo.midletSuite.getProperty(Installer.VENDOR_PROP));
            item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
            infoForm.append(item);

            temp = suiteInfo.midletSuite.getProperty(Installer.DESC_PROP);
            if (temp != null) {
                label.setLength(0);
                label.append(Resource.getString("Description"));
                label.append(": ");
                item = new StringItem(label.toString(), temp);
                item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
                infoForm.append(item);
            }

            if (!suiteInfo.singleMidlet) {
                label.setLength(0);
                label.append(Resource.getString("Contents"));
                label.append(":");
                item = new StringItem(label.toString(), "");
                item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
                infoForm.append(item);
                appendMIDletsToForm(suiteInfo.midletSuite, infoForm);
            }

            label.setLength(0);
            label.append(Resource.getString("Website"));
            label.append(": ");
            item = new StringItem(label.toString(),
                                  suiteInfo.midletSuite.getDownloadUrl());
            item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
            infoForm.append(item);


            label.setLength(0);
            label.append(Resource.getString("Advanced"));
            label.append(": ");
            item = new StringItem(label.toString(), "");
            item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
            infoForm.append(item);

            if (suiteInfo.midletSuite.isTrusted()) {
                infoForm.append(new ImageItem(null,
                    DisplayManagerFactory.getDisplayManager().
                        getTrustedMIDletIcon(), ImageItem.LAYOUT_DEFAULT,
                        null));
                temp = "Trusted";
            } else {
                temp = "Untrusted";
            }

            item = new StringItem(null, Resource.getString(temp));
            item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
            infoForm.append(item);

            temp = suiteInfo.midletSuite.getCA();
            if (temp != null) {
                label.setLength(0);
                label.append(Resource.getString("Authorized by"));
                label.append(": ");
                item = new StringItem(label.toString(), temp);
                item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
                infoForm.append(item);
            }

            temp = PushRegistryImpl.listConnections(
                       suiteInfo.midletSuite.getStorageName(), false);
            if (temp != null) {
                label.setLength(0);
                label.append(Resource.getString("Auto start connections"));
                label.append(": ");
                item = new StringItem(label.toString(), temp);
                item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
                infoForm.append(item);
            }
        } catch (Exception ex) {
            value.setLength(0);
            value.append(suiteInfo.displayName);
            value.append("\n");
            value.append(Resource.getString("Exception"));
            value.append(": ");
            value.append(ex.toString());

            Alert a = new Alert(Resource.getString("Cannot access: "), 
                                value.toString(), null, AlertType.ERROR);
            a.setTimeout(Alert.FOREVER);
            display.setCurrent(a, mlist);
            return;
        }

        infoForm.addCommand(backCmd);
        infoForm.setCommandListener(this);
        display.setCurrent(infoForm);
    
private voidgetApplicationSettings(com.sun.midp.dev.Manager$MIDletSuiteInfo suiteInfo)
Get the settings for an application.

param
suiteInfo information for suite to display

        MIDletSuite midletSuite = suiteInfo.midletSuite;
        Form form;
        String name;
        byte[][] ApiPermissions = suiteInfo.getPermissions();
        byte[] maxLevels = ApiPermissions[Permissions.MAX_LEVELS];
        byte[] curLevels = ApiPermissions[Permissions.CUR_LEVELS];
        int maxLevel;
        int permission;
        String[] values = new String[1];

        try {
            form = new Form(null);

            // A push interrupt may have changed the settings.
            suiteInfo.reloadSuite(installer);

            if (suiteInfo.singleMidlet) {
                name = suiteInfo.displayName;
            } else {
                name = suiteInfo.midletSuite.getProperty(
                          Installer.SUITE_NAME_PROP);
            }

            values[0] = name;
            form.setTitle(Resource.getString("Settings for %1:", values));

            pushChoice = newSettingChoice(form,
                             "Can %1 interrupt another application to " +
                             "receive information? The interrupted " +
                             "application will exit.",
                             Permissions.BLANKET,
                             suiteInfo.getPushInterruptSetting(), name);

            /*
             * Get the best user permission level for the group,
             * so when the user saves all of the permissions will
             * have that level.
             */
            maxLevel = maxLevels[Permissions.HTTP];
            permission = curLevels[Permissions.HTTP];
            maxLevel = selectBestUserPermissionLevel(maxLevel,
                       maxLevels[Permissions.HTTPS]);
            permission = selectBestUserPermissionLevel(permission,
                         curLevels[Permissions.HTTPS]);
            maxLevel = selectBestUserPermissionLevel(maxLevel,
                       maxLevels[Permissions.SSL]);
            permission = selectBestUserPermissionLevel(permission,
                         curLevels[Permissions.SSL]);
            maxLevel = selectBestUserPermissionLevel(maxLevel,
                       maxLevels[Permissions.TCP]);
            permission = selectBestUserPermissionLevel(permission,
                         curLevels[Permissions.TCP]);
            maxLevel = selectBestUserPermissionLevel(maxLevel,
                       maxLevels[Permissions.UDP]);
            permission = selectBestUserPermissionLevel(permission,
                         curLevels[Permissions.UDP]);

            netChoice = newSettingChoice(form,
                            "Can %1 use airtime to SEND information? " +
                            "This may cost you money.", maxLevel,
                            permission, name);

            /*
             * Get the best user permission level for the group,
             * so when the user saves all of the permissions will
             * have that level.
             */
            maxLevel = maxLevels[Permissions.TCP_SERVER];
            permission = curLevels[Permissions.TCP_SERVER];
            maxLevel = selectBestUserPermissionLevel(maxLevel,
                       maxLevels[Permissions.UDP_SERVER]);
            permission = selectBestUserPermissionLevel(permission,
                         curLevels[Permissions.UDP_SERVER]);

            serverChoice = newSettingChoice(form,
                            "Can %1 use airtime to RECEIVE information? " +
                            "This may cost you money.", maxLevel,
                            permission, name);
            
            commChoice = newSettingChoice(form,
                         "Can %1 directly connect to a computer to " +
                         "exchange information? This may require a " +
                         "special cable.", maxLevels[Permissions.COMM],
                         curLevels[Permissions.COMM], name);
        } catch (Exception ex) {
            StringBuffer sb = new StringBuffer();

            sb.append(suiteInfo.displayName);
            sb.append("\n");
            sb.append(Resource.getString("Exception"));
            sb.append(": ");
            sb.append(ex.toString());

            Alert a = new Alert(Resource.getString("Cannot access: "), 
                                sb.toString(), null, AlertType.ERROR);
            a.setTimeout(Alert.FOREVER);
            display.setCurrent(a, mlist);
            return;
        }

        form.addCommand(saveAppSettingsCmd);
        form.addCommand(backCmd);
        form.setCommandListener(this);
        display.setCurrent(form);
    
private static ImagegetEmptyIcon()
Gets the empty icon from storage.

return
icon image

        if (emptyIcon != null) {
            return emptyIcon;
        }

        emptyIcon = GraphicalInstaller.getIconFromStorage("_empty.png");
        return emptyIcon;
    
private static ImagegetHomeScreenGraphic()
Gets the home screen graphic from storage.

return
icon image

        if (homeScreenGraphic != null) {
            return homeScreenGraphic;
        }

        homeScreenGraphic = GraphicalInstaller.getIconFromStorage(
                       (colorDisplay ? "_home_8.png" : "_home_4.png"));
        return homeScreenGraphic;
    
private static ImagegetJavaLogo()
Gets the Java logo image from storage.

return
icon image

        if (javaLogo != null) {
            return javaLogo;
        }

        javaLogo = GraphicalInstaller.getIconFromStorage(
                       (colorDisplay ? "_logo_8.png" : "_logo_2.png"));
        return javaLogo;
    
bytegetNewPermissionLevel(ChoiceGroup choice, int maxLevel, int current)
Get the choice group index if any and convert it to a new permission. To make this method re-usable, return the current value if the max level is not a user level or if the choice group is null. Also do not return a user level higher than max level.

param
choice choice group with the new permission level
param
maxLevel maximum level the permission can have
param
current current level the permission has
return
new level

        int selected;

        if (maxLevel == Permissions.NEVER ||
                maxLevel == Permissions.ALLOW ||
                choice == null) {
            return (byte)current;
        }

        selected = choice.getSelectedIndex();
        if (choice.size() == 2) {
            // we did not put in the blanket choice, so adjust selected index
            selected++;
        }
        
        switch (choice.getSelectedIndex()) {
        case 0:
            if (maxLevel == Permissions.SESSION) {
                return Permissions.ONE_SHOT;
            }

            if (maxLevel == Permissions.ONE_SHOT) {
                return Permissions.ONE_SHOT;
            }

            return Permissions.BLANKET_GRANTED;

        case 1:
            if (maxLevel == Permissions.ONE_SHOT) {
                return Permissions.ONE_SHOT;
            }

            return Permissions.SESSION;
        }

        return Permissions.USER_DENIED;
    
private java.lang.StringgetSelectedMIDlet()
Open the settings database and retreive the currently selected midlet

return
the storagename of the midlet that shoul be hilighted. this may be null.

        ByteArrayInputStream bas;
        DataInputStream dis;
        byte[] data;
        RecordStore settings = null;
        String ret = null;
	
        try {

            settings = RecordStore.
                       openRecordStore(GraphicalInstaller.SETTINGS_STORE, 
                                       false);

            /** we should be guaranteed that this is always the case! */
            if (settings.getNumRecords() > 0) {

                data = settings.getRecord(
                           GraphicalInstaller.SELECTED_MIDLET_RECORD_ID);

                if (data != null) {
                    bas = new ByteArrayInputStream(data);
                    dis = new DataInputStream(bas);
                    ret = dis.readUTF();
                }
            }

        } catch (RecordStoreException e) {
            // ignore
        } catch (IOException e) {
            // ignore
        } finally {
            if (settings != null) {
                try {
                    settings.closeRecordStore();
                } catch (RecordStoreException e) {
                    // ignore
                }
            }
        }

        return ret;
    
private static ImagegetSingleSuiteIcon()
Gets the single MIDlet suite icon from storage.

return
icon image

        if (singleSuiteIcon != null) {
            return singleSuiteIcon;
        }

        singleSuiteIcon = GraphicalInstaller.getIconFromStorage(
                        (colorDisplay ? "_single8.png" : "_single2.png"));
        return singleSuiteIcon;
    
private static ImagegetSuiteIcon()
Gets the MIDlet suite icon from storage.

return
icon image


                   
        
        if (suiteIcon != null) {
            return suiteIcon;
        }

        suiteIcon = GraphicalInstaller.getIconFromStorage(
                        (colorDisplay ? "_suite_8.png" : "_suite_2.png"));
        return suiteIcon;
    
private voidinstallSuite()
Discover and install a suite.

        Scheduler.getScheduler().scheduleMIDlet(new GraphicalInstaller());
        destroyApp(false);
        notifyDestroyed();
    
private voidlaunchSuite(com.sun.midp.dev.Manager$MIDletSuiteInfo suiteInfo)
Lauches a suite.

param
suiteInfo information for suite to launch

        try {
            // Create an instance of the MIDlet class
            // All other initialization happens in MIDlet constructor
            if (installer.execute(suiteInfo.storageName, null)) {
                /*
                 * 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.
                 */
                destroyApp(false);
                notifyDestroyed();
            } else {
                // Give the new MIDlet the screen by pausing and
                // asking to be resumed.
                notifyPaused();
                resumeRequest();
            }
        } catch (Exception ex) {
            StringBuffer sb = new StringBuffer();

            sb.append(suiteInfo.displayName);
            sb.append("\n");
            sb.append(Resource.getString("Error"));
            sb.append(ex.toString());

            Alert a = new Alert(Resource.getString("Cannot start: "), 
                                sb.toString(), null, AlertType.ERROR);
            a.setTimeout(Alert.FOREVER);
            display.setCurrent(a, mlist);
        }
    
private ChoiceGroupnewSettingChoice(Form form, java.lang.String question, int maxLevel, int level, java.lang.String name)
Creates a new choice group in a form if it is user settable, with the 3 preset choices and a initial one set.

param
form Form to put the choice in
param
question label for the choice, will be translated
param
maxLevel maximum permission level
param
level current permission level
param
name name of suite
return
choice to put in the application settings form, or null if initValue is -1

        String[] values = {name};
        int initValue;
        ChoiceGroup choice;
        
        switch (level) {
        case Permissions.BLANKET_GRANTED:
        case Permissions.BLANKET:
            initValue = 0;
            break;

        case Permissions.ONE_SHOT:
        case Permissions.SESSION:
        case Permissions.DENY_SESSION:
            initValue = 1;
            break;

        case Permissions.DENY:
        case Permissions.USER_DENIED:
            initValue = 2;
            break;

        default:
            return null;
        }

        choice = new ChoiceGroup(Resource.getString(question, values),
                     Choice.EXCLUSIVE);

        if (maxLevel == Permissions.SESSION ||
                maxLevel == Permissions.ONE_SHOT) {
            initValue--;
        } else {
            choice.append(Resource.getString("Yes, always. Don't ask again."),
                          null);
        }

        choice.append(Resource.getString("Maybe. Ask me each time."), null);
        choice.append(Resource.getString("No. Shutoff %1.", values), null);

        choice.setSelectedIndex(initValue, true);

        choice.setPreferredSize(form.getWidth(), -1);

        form.append(choice);

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

    
private voidreadMIDletSuiteInfo()
Read in and create a MIDletInfo for each MIDlet suite.

        String[] suiteNames;
        MIDletSuite midletSuite;
        int numberOfMidlets;
        String attr;

        suiteNames = installer.list();

        for (int i = 0; i < suiteNames.length; i++) {

            int lowest = i;

            for (int k = i + 1; k < suiteNames.length; k++) {
                if (suiteNames[k].compareTo(suiteNames[lowest]) < 0) {
                    lowest = k;
                }
            }

            try {
                midletSuite = installer.getMIDletSuite(suiteNames[lowest]);
                numberOfMidlets = midletSuite.getNumberOfMIDlets();

                if (numberOfMidlets == 1) {
                    attr = midletSuite.getProperty("MIDlet-1");
                    addMIDletSuite(new MIDletSuiteInfo(suiteNames[lowest],
                                               midletSuite, attr));
                    minfo[mcount - 1].singleMidlet = true;
                    minfo[mcount - 1].icon = getSingleSuiteIcon();
                } else {
                    addMIDletSuite(new MIDletSuiteInfo(suiteNames[lowest],
                                                       midletSuite));
                } 

            } catch (Exception e) {
                // move on to the next suite
            }

            suiteNames[lowest] = suiteNames[i];
        }
    
private voidremoveSuite(com.sun.midp.dev.Manager$MIDletSuiteInfo suiteInfo)
Remove a suite.

param
suiteInfo information for suite to remove

        installer.remove(suiteInfo.storageName);
        destroyApp(false);
        notifyDestroyed();
    
private voidresetSettings()
Save user settings such as currently selected midlet

        GraphicalInstaller.saveSettings(null, "");
    
private voidsaveApplicationSettings(com.sun.midp.dev.Manager$MIDletSuiteInfo suiteInfo)
Save the application settings the user entered.

param
suiteInfo information for suite to save the settings for

        MIDletSuite midletSuite = suiteInfo.midletSuite;
        byte[][] ApiPermissions = suiteInfo.getPermissions();
        byte[] maxLevels = ApiPermissions[Permissions.MAX_LEVELS];
        byte[] curLevels = ApiPermissions[Permissions.CUR_LEVELS];
        byte interruptSetting = (byte)getNewPermissionLevel(
                                pushChoice, Permissions.BLANKET,
                                suiteInfo.getPushInterruptSetting());

        suiteInfo.setPushInterruptSetting(interruptSetting);

        curLevels[Permissions.PUSH] = getNewPermissionLevel(pushChoice,
                                      maxLevels[Permissions.PUSH],
                                      curLevels[Permissions.PUSH]);

        curLevels[Permissions.HTTP] = getNewPermissionLevel(netChoice,
                                      maxLevels[Permissions.HTTP],
                                      curLevels[Permissions.HTTP]);
        curLevels[Permissions.HTTPS] = getNewPermissionLevel(netChoice,
                                       maxLevels[Permissions.HTTPS],
                                       curLevels[Permissions.HTTPS]);
        curLevels[Permissions.TCP] = getNewPermissionLevel(netChoice,
                                     maxLevels[Permissions.TCP],
                                     curLevels[Permissions.TCP]);
        curLevels[Permissions.SSL] = getNewPermissionLevel(netChoice,
                                     maxLevels[Permissions.SSL],
                                     curLevels[Permissions.SSL]);
        curLevels[Permissions.UDP] = getNewPermissionLevel(netChoice,
                                     maxLevels[Permissions.UDP],
                                     curLevels[Permissions.UDP]);

        curLevels[Permissions.TCP_SERVER] = getNewPermissionLevel(serverChoice,
                                            maxLevels[Permissions.TCP_SERVER],
                                            curLevels[Permissions.TCP_SERVER]);
        curLevels[Permissions.UDP_SERVER] = getNewPermissionLevel(serverChoice,
                                            maxLevels[Permissions.UDP_SERVER],
                                            curLevels[Permissions.UDP_SERVER]);

        curLevels[Permissions.COMM] = getNewPermissionLevel(commChoice,
                                      maxLevels[Permissions.COMM],
                                      curLevels[Permissions.COMM]);

        try {
            Installer.saveSuiteSettings(
                suiteInfo.midletSuite.getStorageRoot(),
                suiteInfo.getPushInterruptSetting(), ApiPermissions,
                suiteInfo.midletSuite.isTrusted());
            displaySuccessMessage(Resource.getString("Saved!"));
        } catch (Exception ex) {
            Alert a = new Alert(Resource.getString("Exception"), 
                                ex.toString(), null, AlertType.ERROR);
            a.setTimeout(Alert.FOREVER);
            display.setCurrent(a, mlist);
        }
    
private intselectBestUserPermissionLevel(int current, int next)
Select the best user permission level of either the current permission or the next permission. Return current if neither permission is a user level.

param
current current permission level
param
next next permission level
return
best user level or the current level

        if (current == Permissions.BLANKET_GRANTED ||
                current == Permissions.BLANKET) {
            return current;
        }

        if (next == Permissions.BLANKET_GRANTED ||
                next == Permissions.BLANKET) {
            return next;
        }

        if (current == Permissions.SESSION ||
                current == Permissions.DENY_SESSION) {
            return current;
        }

        if (next == Permissions.SESSION ||
                next == Permissions.DENY_SESSION) {
            return next;
        }

        if (current == Permissions.DENY ||
                current == Permissions.USER_DENIED) {
            return current;
        }

        if (next == Permissions.DENY ||
                next == Permissions.USER_DENIED) {
            return next;
        }

        return current;
    
private voidsetupList()
Read the set of MIDlet names, icons and classes Fill in the list.

        if (mlist == null) {
            mlist = new List(Resource.getString("Applications"), 
                             Choice.IMPLICIT);

            // Add the installer midlet first
            mlist.append(" " + Resource.getString("Install Application"),
                      getSingleSuiteIcon());
            
            String curMIDlet = getSelectedMIDlet();

            // Add each midlet
            for (int i = 0; i < mcount; i++) {
                mlist.append(" " + minfo[i].displayName, minfo[i].icon);

                if (minfo[i].storageName.equals(curMIDlet)) {
                    // plus one because of the "Install App" option
                    mlist.setSelectedIndex(i + 1, true);
                }
            }
        }
    
public voidstartApp()
Start puts up a List of the MIDlets found in the descriptor file.

    
private voidupdateSuite(com.sun.midp.dev.Manager$MIDletSuiteInfo suiteInfo)
Update a suite.

param
suiteInfo information for suite to update

        Scheduler.getScheduler().getMIDletSuite().addProperty("storageName",
            suiteInfo.midletSuite.getStorageName());
        installSuite();