appmanagerpeer.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 1,154 行 · 第 1/3 页

JAVA
1,154
字号
/* * * * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER *  * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. *  * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). *  * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA *  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */                         package com.sun.midp.appmanager;import javax.microedition.lcdui.*;import com.sun.midp.installer.*;import com.sun.midp.main.*;import com.sun.midp.midletsuite.*;import com.sun.midp.midlet.MIDletSuite;import com.sun.midp.io.j2me.push.PushRegistryInternal;import com.sun.midp.i18n.Resource;import com.sun.midp.i18n.ResourceConstants;import com.sun.midp.configurator.Constants;import com.sun.midp.payment.PAPICleanUp;import java.io.*;import javax.microedition.rms.*;import java.util.*;/** * The Graphical MIDlet selector Screen. * <p> * It displays a list (or grid to be exact) of currently installed * MIDlets/MIDlet suites (including the Installer MIDlet). Each MIDlet or * MIDlet suite is represented by an icon with a name under it. * An icon from a jad file for the MIDlet/MIDlet suite representation * is used if possible, otherwise a default icon is used. * * There is a a set of commands per MIDlet/MIDlet suite. Note that * the set of commands can change depending on the corresponding MIDlet state. * For MIDlets/MIDlet suites that are not running the following commands are * available: * <ul> * <li><b>Launch</b>: Launch the MIDlet or the MIDlet Selector *      if it is a suite. * <li><b>Remove</b>: Remove the MIDlet/MIDlet suite teh user selected *      (with confirmation). </li> * <li><b>Update</b>: Update the MIDlet/MIDlet suite the user selected.</li> * <li><b>Info</b>: Show the user general information *    of the selected MIDlet/MIdlet suite. </li> * <li><b>Settings</b>: Let the user change the manager's settings. * </ul> * * For MIDlets/MIDlet suites that are running the following commands are * available: * <ul> * <li><b>Bring to foreground</b>: Bring the running MIDlet to foreground * <li><b>End</b>: Terminate the running MIDlet * <li><b>Remove</b>: Remove the MIDlet/MIDlet suite teh user selected *      (with confirmation). </li> * <li><b>Update</b>: Update the MIDlet/MIDlet suite the user selected.</li> * <li><b>Info</b>: Show the user general information *    of the selected MIDlet/MIdlet suite. </li> * <li><b>Settings</b>: Let the user change the manager's settings. * </ul> * * Exactly one MIDlet from a MIDlet suite could be run at the same time. * Each MIDlet/MIDlet suite representation corresponds to an instance of * MidletCustomItem which in turn maintains a reference to a MIDletSuiteInfo * object (that contains info about this MIDlet/MIDlet suite). * When a MIDlet is launched or a MIDlet form a MIDlet suite is launched * the proxy instance in the corresponding MidletCustomItem is set to * a running MIDletProxy value. It is set back to null when MIDlet exits. * * Running midlets can be distinguished from non-running MIdlets/MIDlet suites * by the color of their name. */class AppManagerPeer implements CommandListener {    private AppManagerUI appManagerUI;    /** Constant for the discovery application class name. */    public static final String DISCOVERY_APP =        "com.sun.midp.installer.DiscoveryApp";    /** Constant for the certificate manager class name */    public static final String CA_MANAGER =        "com.sun.midp.appmanager.CaManager";    /** Constant for the component manager class name */    public static final String COMP_MANAGER =        "com.sun.midp.appmanager.ComponentManager";    /** Constant for the graphical installer class name. */    public static final String INSTALLER =        "com.sun.midp.installer.GraphicalInstaller";    /** Constant for the ODT Agent class name. */    public static final String ODT_AGENT =        "com.sun.midp.odd.ODTAgentMIDlet";    /** True if On Device Debug is enabled. */    private static boolean oddEnabled = false;    /** MIDlet Suite storage object. */    private MIDletSuiteStorage midletSuiteStorage;    /** Display for the Manager MIDlet. */    Display display; // = null    /** MIDlet to be removed after confirmation screen was accepted */    private RunningMIDletSuiteInfo removeMsi;   /** vector of existing RunningMIDletSuiteInfo */    private Vector msiVector;    /** UI used to display error messages. */    private DisplayError displayError;           /** Display for the Manager MIDlet. */    ApplicationManager manager;    /**     * There are several Application Manager     * midlets from the same "internal" midlet suite     * that should not be running in the background.     * appManagerMidlet helps to destroy them     * (see MidletCustomItem.showNotify).     */    private MIDletProxy appManagerMidlet;    /** True, if the CA manager is included. */    private boolean caManagerIncluded;    /** True, if the CA manager is included. */    private boolean compManagerIncluded;        /** If there are folders */    private boolean foldersOn;    /** Command object for "Yes, enable on device debug" command. */    private Command enableOddYesCmd = new Command(Resource.getString                                            (ResourceConstants.YES),                                            Command.OK, 1);    /** Command object for "No, don't enable on device debug" command. */    private Command enableOddNoCmd = new Command(Resource.getString                                           (ResourceConstants.NO),                                           Command.BACK, 1);    /**     * Creates and populates the Application Selector Screen.     * @param manager - The application manager that invoked it     * @param displayError - The UI used to display error messages     * @param display - The display instance associated with the manager     * @param first - true if this is the first time AppSelector is being     *                shown     * @param ms - MidletSuiteInfo that should be selected. For the internal     *             suites midletToRun should be set, for the other suites     *             suiteId is enough to find the corresponding item.     */    AppManagerPeer(ApplicationManager manager, Display display,               DisplayError displayError, boolean first, MIDletSuiteInfo ms) {        msiVector = new Vector();        this.displayError = displayError;        this.manager = manager;                this.display = display;        Vector folders = FolderManager.getFolders();        foldersOn = (folders != null) ? folders.size() > 0 : false;        try {            caManagerIncluded = Class.forName(CA_MANAGER) != null;        } catch (ClassNotFoundException e) {            // keep caManagerIncluded false        }        try {            compManagerIncluded = Class.forName(COMP_MANAGER) != null;        } catch (ClassNotFoundException e) {            // keep compManagerIncluded false        }        midletSuiteStorage = MIDletSuiteStorage.getMIDletSuiteStorage();        RunningMIDletSuiteInfo currentItem = null;        if (first) {            appManagerUI = new AppManagerUIImpl(manager, this, display, displayError, foldersOn);             // cleanup the storage from the previous execution            midletSuiteStorage.removeTemporarySuites();       } else {            // if a MIDlet was just installed            // getLastInstalledMidletItem() will return RunningMIDletSuiteInfo            // corresponding to this suite, then we have to prompt            // the user if he wantto launch a midlet from the suite.            RunningMIDletSuiteInfo msi = getLastInstalledMidletItem();            if (msi != null) {                if (foldersOn) {                    // move it to default folder                    try {                        midletSuiteStorage.moveSuiteToFolder(msi.suiteId,                                FolderManager.getDefaultFolderId());                        msi.folderId = FolderManager.getDefaultFolderId();                    } catch (Throwable t) {                        displayError.showErrorAlert(msi.displayName, t, null, null);                    }                }                appManagerUI = new AppManagerUIImpl(manager, this, display,                        displayError, foldersOn, true);                currentItem = msi;            } else {                appManagerUI = new AppManagerUIImpl(manager, this, display,                        displayError, foldersOn, false);            }        }        // appManagerUI will be populated with items during        // updateContent() method execution.        updateContent();        if (null != currentItem) {            appManagerUI.setCurrentItem(currentItem);        } else {            if (ms != null) {                // Find item to select                if (ms.isInternal()) {                    for (int i = 0; i < msiVector.size(); i++) {                        RunningMIDletSuiteInfo mi =                                (RunningMIDletSuiteInfo)msiVector.elementAt(i);                        if ((mi.isInternal()) &&                                mi.midletToRun.equals(ms.midletToRun)) {                            currentItem = mi;                            break;                        }                    }                } else {                    for (int i = 0; i < msiVector.size(); i++) {                        RunningMIDletSuiteInfo mi =                                (RunningMIDletSuiteInfo)msiVector.elementAt(i);                        if (mi.suiteId == ms.suiteId) {                            currentItem = mi;                            break;                        }                    }                }                appManagerUI.setCurrentItem(currentItem);            } // ms != null        }    }    /**     * Returns True if On Device Debug is enabled.     * @return     */    public boolean oddEnabled() {        return oddEnabled;    }    /**     * Returns true, if the CA manager is included.     * @return     */    public boolean caManagerIncluded() {        return caManagerIncluded;    }    /**     * Returns true, if the CA manager is included.     * @return     */    public boolean compManagerIncluded() {        return compManagerIncluded;    }    /**     * Shows requested application settings.     * @param suiteId suite ID     * @param nextScreen displayable that is to be shown     *  after settings dialog is dismissed     */    public void showAppSettings(int suiteId,                       Displayable nextScreen)            throws MIDletSuiteLockedException, MIDletSuiteCorruptedException {        AppSettings appSettings = new AppSettingsImpl(suiteId, display,                                                  displayError, nextScreen);    }    /**     * Shows ODT Agent midlet in the midlet list.     */    public void showODTAgent() {        try {            // check if the ODTAgent midlet is included into the build            Class.forName(ODT_AGENT);        } catch (ClassNotFoundException e) {            // return if the agent is not included            return;        }        // return if ODD is already enabled        if (oddEnabled) {            return;        }        // warn the user that he enables a potentially dangerous feature        String title = Resource.getString(            ResourceConstants.AMS_MGR_ENABLE_ON_DEVICE_DEBUG_TITLE, null);        String msg = Resource.getString(            ResourceConstants.AMS_MGR_ENABLE_ON_DEVICE_DEBUG, null);        Alert alert = new Alert(title, msg, null, AlertType.WARNING);        alert.addCommand(enableOddNoCmd);        alert.addCommand(enableOddYesCmd);        alert.setCommandListener(this);        alert.setTimeout(Alert.FOREVER);        display.setCurrent(alert);    }    /**     * Respond to a command issued on any Screen.     *     * @param c command activated by the user     * @param s the Displayable the command was on.     */    public void commandAction(Command c, Displayable s) {        if (c == enableOddYesCmd) {            // user has confirmed that he wants to enable on device debug            oddEnabled = true;            updateContent();        } else if (c == enableOddNoCmd) {            // user doesn't want to enable on device debug, do nothing        }        display.setCurrent(appManagerUI.getMainDisplayable());    }    /**     * Called when a new midlet was launched.     *     * @param midlet proxy of a newly added MIDlet     */    void notifyMidletStarted(MIDletProxy midlet) {        String midletClassName = midlet.getClassName();        if (midletClassName.equals(manager.getClass().getName())) {            return;        }        if (midlet.getSuiteId() == MIDletSuite.INTERNAL_SUITE_ID &&                !midletClassName.equals(DISCOVERY_APP) &&                !midletClassName.equals(INSTALLER) &&                !midletClassName.equals(CA_MANAGER) &&                !midletClassName.equals(COMP_MANAGER) &&                !midletClassName.equals(ODT_AGENT)) {            appManagerMidlet = midlet;            appManagerUI.notifyInternalMidletStarted(midlet);        } else {            RunningMIDletSuiteInfo si;            for (int i = 0; i < msiVector.size(); i++) {                si = (RunningMIDletSuiteInfo)msiVector.elementAt(i);                if (si.sameSuite(midlet)) {                    si.addProxy(midlet);                    appManagerUI.notifyMidletStarted(si, midletClassName);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?