⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 installer.java

📁 用于移动设备上的java虚拟机源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * @(#)Installer.java	1.113 02/10/14 @(#) * * Copyright (c) 2001-2002 Sun Microsystems, Inc.  All rights reserved. * PROPRIETARY/CONFIDENTIAL * Use is subject to license terms. */package com.sun.midp.midletsuite;import java.util.Vector;import java.util.Enumeration;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.io.ByteArrayOutputStream;import java.io.ByteArrayInputStream;import java.io.DataOutputStream;import java.io.DataInputStream;import java.lang.String;import java.lang.IllegalArgumentException;import javax.microedition.io.Connector;import javax.microedition.io.Connection;import javax.microedition.io.HttpConnection;import javax.microedition.io.ConnectionNotFoundException;import com.sun.midp.security.SecurityToken;import com.sun.midp.security.Permissions;import com.sun.midp.main.Configuration;import com.sun.midp.midlet.Scheduler;import com.sun.midp.midlet.MIDletSuite;import com.sun.midp.midlet.MIDletInfo;import com.sun.midp.io.Base64;import com.sun.midp.io.Properties;import com.sun.midp.io.HttpUrl;import com.sun.midp.io.Util;import com.sun.midp.io.j2me.push.PushRegistryImpl;import com.sun.midp.io.j2me.storage.RandomAccessStream;import com.sun.midp.io.j2me.storage.File;import com.sun.midp.lcdui.Resource;import com.sun.midp.rms.RecordStoreFile;/** * An Installer manages MIDlet suites and libraries * present in a Java application environment.  An MIDlet suite * distributed as a descriptor and JAR pair. * The descriptor identifies the configuration and contains security * information and the manifest of the JAR describes the contents. * The implementation of an Installer is * specific to the platform and provides access to  * procedures that make an MIDlet suite visible to users.  * <P> * Each installed package is uniquely identified by a storage name * constructed from the combination * of the values of the <code>MIDlet-Name</code> and * <code>MIDlet-Vendor</code> attributes. * The syntax and content of the strings used to identify * installed packages are implementation dependent. * Only packages installed or upgraded using this API appear  * in the list of known packages. * */public class Installer {    /** Status code to signal connection to the JAD server was successful. */    public static final int DOWNLOADING_JAD = 1;    /** Status code to signal that another 1K of the JAD has been download. */    public static final int DOWNLOADED_1K_OF_JAD = 2;    /** Status code to signal connection to the JAR server was successful. */    public static final int DOWNLOADING_JAR = 3;    /** Status code to signal that another 1K of the JAR has been download. */    public static final int DOWNLOADED_1K_OF_JAR = 4;    /**     * Status code to signal that download is done and the suite is being     * verified.     */    public static final int VERIFYING_SUITE = 5;    /**     * Status code for local writing of the verified MIDlet suite.     * Stopping the install at this point has no effect, so there user     * should not be given a chance to stop the install.     */    public static final int STORING_SUITE = 6;    /** Filename of Manifest inside the application archive. */    public static final String JAR_MANIFEST       = "META-INF/MANIFEST.MF";    /** MIDlet property for the size of the application data. */    public static final String DATA_SIZE_PROP     = "MIDlet-Data-Size";    /** MIDlet property for the size of the application archive. */    public static final String JAR_SIZE_PROP      = "MIDlet-Jar-Size";    /** MIDlet property for the application archive URL. */    public static final String JAR_URL_PROP       = "MIDlet-Jar-URL";    /** MIDlet property for the suite name. */    public static final String SUITE_NAME_PROP    = "MIDlet-Name";    /** MIDlet property for the suite vendor. */    public static final String VENDOR_PROP        = "MIDlet-Vendor";    /** MIDlet property for the suite version. */    public static final String VERSION_PROP       = "MIDlet-Version";    /** MIDlet property for the suite description. */    public static final String DESC_PROP        = "MIDlet-Description";    /** MIDlet property for the install notify URL. */    public static final String NOTIFY_PROP        = "MIDlet-Install-Notify";    /** MIDlet property for the delete notify URL. */    public static final String DELETE_PROP        = "MIDlet-Delete-Notify";    /** MIDlet property for the microedition configuration. */    public static final String CONFIGURATION_PROP =        "MicroEdition-Configuration";    /** MIDlet property for the profile. */    public static final String PROFILE_PROP       = "MicroEdition-Profile";    /** MIDlet property for the required permissions. */    public static final String PERMISSIONS_PROP     = "MIDlet-Permissions";    /** MIDlet property for the optional permissions. */    public static final String PERMISSIONS_OPT_PROP = "MIDlet-Permissions-Opt";    /** Media-Type for valid application descriptor files. */    public static final String JAD_MT = "text/vnd.sun.j2me.app-descriptor";    /** Media-Type for valid Jar file. */    public static final String JAR_MT_1 = "application/java";    /** Media-Type for valid Jar file. */    public static final String JAR_MT_2 = "application/java-archive";    /** Max number of bytes to download at one time (1K). */    private static final int MAX_DL_SIZE = 1024;    /** Tag that signals that the HTTP server supports basic auth. */    private static final String BASIC_TAG = "basic";    /** Filename to save the domain owner of the suite. */    static final String CA_FILENAME = "CA.utf";    /** Filename to save the URL of the JAD. */    static final String JAD_URL_FILENAME = "jadUrl.utf";    /** Filename to save the URL of the JAR. */    static final String JAR_URL_FILENAME = "jarUrl.utf";    /** Filename to save the encoding of the JAD. */    static final String JAD_ENCODING_FILENAME = "jadEncoding.utf";    /** Filename to save the encoding of the JAD. */    static final String SETTINGS_FILENAME = "settings.bin";    /** Filename to suite JAR. */    static final String JAR_FILENAME = "suite.jar";    /** Filename to save the suite application descriptor. */    static final String JAD_FILENAME = "suite.jad";    /** Filename to save the delete notification URLs. */    static final String DELETE_NOTIFY_FILENAME = "_delete_notify.utf";    /**     * Filename to save the JAR of the suite temporarily. This is used     * to avoid overwriting an existing JAR prior to     * verification.     */    static final String TMP_FILENAME      = "installer.tmp";    /** Filename to save the application manifest. */    static final String MANIFEST_FILENAME = "suite.mf";    /** Filename of the list of installed suites. */    static final String SUITE_LIST_FILENAME = "suites.utf";    /** Success message for the suite provider. */    static final String SUCCESS_MSG = "900 Success";    /** Error message for the suite provider. */    static final String INSUFFICIENT_MEM_MSG = "901 Insufficient Memory";    /** Error message for the suite provider. */    static final String USER_CANCELLED_MSG = "902 User Cancelled";    /** Error message for the suite provider. */    static final String JAR_SIZE_MISMATCH_MSG = "904 JAR Size Mismatch";    /** Error message for the suite provider. */    static final String ATTRIBUTE_MISMATCH_MSG = "905 Attribute Mismatch";    /** Error message for the suite provider. */    static final String INVALID_JAD_MSG = "906 Invalid Descriptor";    /** Error message for the suite provider. */    static final String INVALID_JAR_MSG = "907 Invalid JAR";    /** Error message for the suite provider. */    static final String INCOMPATIBLE_MSG =        "908 Incompatible Configuration or Profile";    /** Error message for authentication failure. */    static final String AUTHENTICATION_FAILURE_MSG =        "909 Application authentication failure";    /** Error message for authorization failure. */    static final String AUTHORIZATION_FAILURE_MSG =        "910 Application authorization failure";    /** Error message for push registration failure. */    static final String PUSH_REG_FAILURE_MSG =         "911 Push registration failure";    /** Error message for push registration failure. */    static final String DELETE_NOTIFICATION_MSG =         "912 Deletion notification";    /** Private reference to the singleton Installer class. */    private static Installer myInstaller;    /** This class has a different security domain than the MIDlet suite. */    private static SecurityToken classSecurityToken;    /** The unique storage name of the next MIDlet suite to run. */    private String nextMidletSuiteToRun;    /** The of the next MIDlet to run. */    private String nextMidletToRun;     /** Cache of installed MIDlet suites. */    private Vector midletSuiteList;    /** Cache of delete notification URL list. */    private Vector deleteNotifyURLList;    /** HTTP connection to close when we stop the installation. */    private HttpConnection httpConnection;    /** HTTP stream to close when we stop the installation. */    private InputStream httpInputStream;    /** Holds the install state. */    protected InstallStateImpl state;    /** Holds the CLDC configuration string. */    private String cldcConfig;    /** Holds the MIDP supported profiles. */    private Vector supportedProfiles;    /** Use this to be the security domain for unsigned suites. */    private String unsignedSecurityDomain = Permissions.UNTRUSTED_DOMAIN_NAME;    /**     * Initializes the security token for this class, so it can     * perform actions that a normal MIDlet Suite cannot.     *     * @param token security token for this class.     */    public static void initSecurityToken(SecurityToken token) {        if (classSecurityToken != null) {            return;        }        classSecurityToken = token;        MIDletSuiteImpl.initSecurityToken(classSecurityToken);    }    /**     * Saves any of the settings (security or others) that the user may have     * changed.     *     * @param token security token with internal MIDP permission     * @param suiteStorageRoot storage root of the suite     * @param pushInterruptSetting push interrupt setting     * @param permissions security permissions for the suite     * @param trusted true if the suite is trusted     *     * @exception IOException if an error happens while writing     */    public static void saveSuiteSettings(SecurityToken token,            String suiteStorageRoot, byte pushInterruptSetting,            byte[][] permissions, boolean trusted) throws IOException {        saveSuiteSettings(new RandomAccessStream(token),            suiteStorageRoot, pushInterruptSetting, permissions, trusted);    }    /**     * Saves any of the settings (security or others) that the user may have     * changed.     *     * @param suiteStorageRoot storage root of the suite     * @param pushInterruptSetting push interrupt setting     * @param permissions security permissions for the suite     * @param trusted true if the suite is trusted     *     * @exception IOException if an error happens while writing     */    public static void saveSuiteSettings(String suiteStorageRoot,            byte pushInterruptSetting, byte[][] permissions, boolean trusted)            throws IOException {        saveSuiteSettings(new RandomAccessStream(), suiteStorageRoot,            pushInterruptSetting, permissions, trusted);    }    /**     * Saves any of the settings (security or others) that the user may have     * changed.     *     * @param storage pre-allocated storage object, but not connected     * @param suiteStorageRoot storage root of the suite     * @param pushInterruptSetting push interrupt setting     * @param permissions security permissions for the suite     * @param trusted true if the suite is trusted     *     * @exception IOException if an error happens while writing     */    private static void saveSuiteSettings(RandomAccessStream storage,            String suiteStorageRoot, byte pushInterruptSetting,            byte[][] permissions, boolean trusted) throws IOException {        DataOutputStream storageStream;        byte[] maximums = permissions[Permissions.MAX_LEVELS];        byte[] currentLevels = permissions[Permissions.CUR_LEVELS];        storage.connect(suiteStorageRoot + SETTINGS_FILENAME,                        RandomAccessStream.READ_WRITE_TRUNCATE);        try {            storageStream = storage.openDataOutputStream();            /*             * write the version of the file

⌨️ 快捷键说明

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