amsutil.java

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

JAVA
491
字号
/* * * * Copyright  1990-2008 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.main;import com.sun.cldc.isolate.*;import com.sun.midp.midlet.MIDletSuite;import com.sun.midp.midletsuite.MIDletSuiteStorage;import com.sun.midp.midletsuite.DynamicComponentStorage;import com.sun.midp.configurator.Constants;import com.sun.midp.links.Link;import com.sun.midp.links.LinkPortal;import com.sun.midp.log.Logging;import com.sun.midp.security.ImplicitlyTrustedClass;import com.sun.midp.security.SecurityInitializer;import com.sun.midp.security.SecurityToken;import com.sun.midp.services.ComponentInfo;import com.sun.midp.services.SystemServiceLinkPortal;import com.sun.midp.services.SystemServiceManager;/** * Implements utilities that are different for SVM and MVM modes. * Utilities to start a MIDlet in a suite. If not the called from the * AMS Isolate the request is forwarded to the AMS Isolate. * See {@link #executeWithArgs}. * <p> * In the AMS Isolate, a check is make that the MIDlet is * not already running and is not in the process of starting. * If the MIDlet is already running or is starting the request * returns immediately. See {@link #startMidletCommon} * <p> */public class AmsUtil {    /** Cached reference to the MIDletExecuteEventProducer. */    private static MIDletExecuteEventProducer midletExecuteEventProducer;    /** Cached reference to the MIDletControllerEventProducer. */    private static MIDletControllerEventProducer midletControllerEventProducer;    /** Cached reference to the MIDletProxyList. */    private static MIDletProxyList midletProxyList;        /** Own trusted class to be able to request SecurityToken for priviledged operations */    private static class SecurityTrusted implements ImplicitlyTrustedClass {};    /** The instance of SecurityToken for priviledged operations */    private static SecurityToken trustedToken;        /**     * Initializes AmsUtil class. shall only be called from     * MIDletSuiteLoader's main() in MVM AMS isolate     * or in SVM main isolate.     * No need in security checks since it is package private method.     *     * @param theMIDletProxyList MIDletController's container     * @param theMidletControllerEventProducer utility to send events     */    static void initClass(MIDletProxyList theMIDletProxyList,            MIDletControllerEventProducer theMidletControllerEventProducer) {        midletProxyList = theMIDletProxyList;        midletControllerEventProducer = theMidletControllerEventProducer;        IsolateMonitor.initClass(theMIDletProxyList);        StartMIDletMonitor.initClass(theMIDletProxyList);    }    /**     * Initializes AmsUtil class. shall only be called from     * AppIsolateMIDletSuiteLoader's main() in     * non-AMS isolates.     * No need in security checks since it is package private method.     *     * @param theMIDletExecuteEventProducer event producer     *        to be used by this class to send events     */    static void initClassInAppIsolate(            MIDletExecuteEventProducer theMIDletExecuteEventProducer) {        midletExecuteEventProducer = theMIDletExecuteEventProducer;    }    /**     * Starts a MIDlet in a new Isolate.     *     * @param midletSuiteStorage reference to a MIDletStorage object     * @param externalAppId ID of MIDlet to invoke, given by an external     *                      application manager     * @param id ID of an installed suite     * @param midlet class name of MIDlet to invoke     * @param displayName name to display to the user     * @param arg0 if not null, this parameter will be available to the     *             MIDlet as application property arg-0     * @param arg1 if not null, this parameter will be available to the     *             MIDlet as application property arg-1     * @param arg2 if not null, this parameter will be available to the     *             MIDlet as application property arg-2     * @param memoryReserved the minimum amount of memory guaranteed to be     *             available to the isolate at any time; &lt; 0 if not used     * @param memoryTotal the total amount of memory that the isolate can                   reserve; &lt; 0 if not used     * @param priority priority to set for the new isolate;     *                 &lt;= 0 if not used     * @param profileName name of the profile to set for the new isolate;     *                    null if not used     * @param isDebugMode true if the new midlet must be started in debug     *                    mode, false otherwise     *     * @return false to signal that the MIDlet suite does not have to exit     * before the MIDlet is run     */    static boolean executeWithArgs(MIDletSuiteStorage midletSuiteStorage,            int externalAppId, int id, String midlet,            String displayName, String arg0, String arg1, String arg2,            int memoryReserved, int memoryTotal, int priority,            String profileName, boolean isDebugMode) {        if (id == MIDletSuite.UNUSED_SUITE_ID) {            // this was just a cancel request meant for SVM mode            return false;        }        if (midlet == null) {            throw new IllegalArgumentException("MIDlet class cannot be null");        }        if (!MIDletSuiteUtils.isAmsIsolate()) {            /*             * This is not the AMS isolate so send the request to the             * AMS isolate.             */            midletExecuteEventProducer.sendMIDletExecuteEvent(                externalAppId, id,                midlet, displayName,                arg0, arg1, arg2,                memoryReserved, memoryTotal, priority,                profileName, isDebugMode            );            return false;        }        // Don't start the MIDlet if it is already running.        if (midletProxyList.isMidletInList(id, midlet)) {            return false;        }        try {            startMidletCommon(midletSuiteStorage, externalAppId, id, midlet,                              displayName, arg0, arg1, arg2,                              memoryReserved, memoryTotal, priority,                              profileName, isDebugMode);        } catch (Throwable t) {            /*             * This method does not throw exceptions for start errors,             * (just like the SVM case), for errors, MVM callers rely on             * start error events.             */        }        return false;    }    /**     * Starts a MIDlet in a new Isolate. Called from the AMS MIDlet suite.     *     * @param id ID of an installed suite     * @param midlet class name of MIDlet to invoke     * @param displayName name to display to the user     * @param arg0 if not null, this parameter will be available to the     *             MIDlet as application property arg-0     * @param arg1 if not null, this parameter will be available to the     *             MIDlet as application property arg-1     * @param arg2 if not null, this parameter will be available to the     *             MIDlet as application property arg-2     *     * @return Isolate that the MIDlet suite was started in     */    public static Isolate startMidletInNewIsolate(int id, String midlet,            String displayName, String arg0, String arg1, String arg2) {        // Note: getMIDletSuiteStorage performs an AMS permission check        return startMidletCommon(MIDletSuiteStorage.getMIDletSuiteStorage(),            0, id, midlet, displayName, arg0, arg1, arg2,            -1, -1, Isolate.MIN_PRIORITY - 1, null, false);    }    /**     * Starts a MIDlet in a new Isolate.     * Check that the MIDlet is is not realy running and is not already     * being started. If so, return immediately.     *     * @param midletSuiteStorage midletSuiteStorage for obtaining a     *      classpath     * @param externalAppId ID of MIDlet to invoke, given by an external     *                      application manager     * @param id ID of an installed suite     * @param midlet class name of MIDlet to invoke     * @param displayName name to display to the user     * @param arg0 if not null, this parameter will be available to the     *             MIDlet as application property arg-0     * @param arg1 if not null, this parameter will be available to the     *             MIDlet as application property arg-1     * @param arg2 if not null, this parameter will be available to the     *             MIDlet as application property arg-2     * @param memoryReserved the minimum amount of memory guaranteed to be     *             available to the isolate at any time; &lt; 0 if not used     * @param memoryTotal the total amount of memory that the isolate can                   reserve; &lt; 0 if not used     * @param priority priority to set for the new isolate;     *                 &lt;= 0 if not used     * @param profileName name of the profile to set for the new isolate;     *                    null if not used     * @param isDebugMode true if the new isolate must be started in debug     *                    mode, false otherwise     *     * @return Isolate that the MIDlet suite was started in;     *             <code>null</code> if the MIDlet is already running     */    private static Isolate startMidletCommon(MIDletSuiteStorage            midletSuiteStorage, int externalAppId, int id, String midlet,            String displayName, String arg0, String arg1, String arg2,            int memoryReserved, int memoryTotal,

⌨️ 快捷键说明

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