graphicalinstaller.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 1,787 行 · 第 1/5 页
JAVA
1,787 行
/* * * * 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.installer;import java.io.*;import javax.microedition.lcdui.*;import javax.microedition.midlet.*;import javax.microedition.rms.*;import com.sun.j2me.security.AccessController;import com.sun.midp.security.*;import com.sun.midp.i18n.Resource;import com.sun.midp.i18n.ResourceConstants;import com.sun.midp.configurator.Constants;import com.sun.midp.main.TrustedMIDletIcon;import com.sun.midp.midlet.MIDletSuite;import com.sun.midp.midletsuite.*;import com.sun.midp.content.CHManager;import com.sun.midp.log.Logging;import com.sun.midp.log.LogChannels;import com.sun.midp.util.ResourceHandler;import com.sun.midp.events.Event;import com.sun.midp.events.NativeEvent;import com.sun.midp.events.EventTypes;import com.sun.midp.events.EventQueue;import com.sun.midp.events.EventListener;import com.sun.midp.ams.VMUtils;/** * The Graphical MIDlet suite installer. * <p> * The graphical installer is implements the installer requirements of the * MIDP OTA specification.</p> * <p> * If the Content Handler API (CHAPI) is present the GraphicalInstaller will * dequeue a single Invocation and install from the URL contained * in the request. If there is no Invocation present then the arguments below * will be used. * <p> * The MIDlet uses certain application properties as arguments: </p> * <ol> * <li>arg-0: "U" for update, "I" for install, "FI" for forced install, * "FU" for forced update, "PR" for install or update * initiated by platformRequest</li> * <li>arg-1: Suite ID for updating, URL for installing * <li>arg-2: For installing a name to put in the title bar when installing * </ol> * @see CHManager */public class GraphicalInstaller extends MIDlet implements CommandListener { /** Standard timeout for alerts. */ public static final int ALERT_TIMEOUT = 1250; /** settings database */ public static final String SETTINGS_STORE = "settings"; /** record id of selected midlet */ public static final int URL_RECORD_ID = 1; /** record id of filepath in external storage */ public static final int FILE_PATH_RECORD_ID = 3; /** record is of the last installed midlet */ public static final int SELECTED_MIDLET_RECORD_ID = 2; /** type of last installation: from web or storage source */ public static final int LAST_INSTALLATION_SOURCE_RECORD_ID = 4; /** The installer that is being used to install or update a suite. */ private Installer installer; /** Display for this MIDlet. */ private Display display; /** Form obtain a password and a username. */ private Form passwordForm; /** Contains the username for installing. */ private TextField usernameField; /** Contains the password for installing. */ private TextField passwordField; /** Background installer that holds state for the current install. */ private BackgroundInstaller backgroundInstaller; /** Displays the progress of the install. */ private Form progressForm; /** Gauge for progress form index. */ private int progressGaugeIndex; /** URL for progress form index. */ private int progressUrlIndex; /** Keeps track of when the display last changed, in milliseconds. */ private long lastDisplayChange; /** What to display to the user when the current action is cancelled. */ private String cancelledMessage; /** What to display to the user when the current action is finishing. */ private String finishingMessage; /** Displays a list of storages to install to. */ private List storageListBox; /** ID of the storage where the new midlet suite will be installed. */ private int storageId = Constants.INTERNAL_STORAGE_ID; /** Content handler specific install functions. */ CHManager chmanager; /** Command object for "Stop" command for progress form. */ private Command stopCmd = new Command(Resource.getString (ResourceConstants.STOP), Command.STOP, 1); /** Command object for "Cancel" command for the confirm form. */ private Command cancelCmd = new Command(Resource.getString(ResourceConstants.CANCEL), Command.CANCEL, 1); /** Command object for "Install" command for the confirm download form. */ private Command continueCmd = new Command(Resource.getString(ResourceConstants.INSTALL), Command.OK, 1); /** Command object for "Next" command for storage select list. */ private Command storeSelectCmd = new Command(Resource.getString(ResourceConstants.NEXT), Command.OK, 1); /** Command object for "Next" command for password form. */ private Command nextCmd = new Command(Resource.getString(ResourceConstants.NEXT), Command.OK, 1); /** Command object for "continue" command for warning form. */ private Command okCmd = new Command(Resource.getString(ResourceConstants.CONTINUE), Command.OK, 1); /** Command object for "Yes" command for keep RMS form. */ private Command keepRMSCmd = new Command(Resource.getString(ResourceConstants.YES), Command.OK, 1); /** Command object for "No" command for keep RMS form. */ private Command removeRMSCmd = new Command(Resource.getString(ResourceConstants.NO), Command.CANCEL, 1); /** Suite name */ private String label; /** Url to install from */ private String url; /** true if update should be forced without user confirmation */ private boolean forceUpdate = false; /** true if user confirmation should be presented */ private boolean noConfirmation = false; /** true if runnning midlets from the suite being updated must be killed */ private boolean killRunningMIDletIfUpdate = false; /** * Gets an image from the internal storage. * <p> * Method requires com.sun.midp.ams permission. * * IMPL_NOTE: this method should be moved somewhere. * * @param imageName image file name without a path and extension * @return Image loaded from storage, or null if not found */ public static Image getImageFromInternalStorage(String imageName) { byte[] imageBytes = ResourceHandler.getSystemImageResource(null, imageName); if (imageBytes != null) { return Image.createImage(imageBytes, 0, imageBytes.length); } return null; } /** * Translate an InvalidJadException into a message for the user. * * @param exception exception to translate * @param name name of the MIDlet suite to insert into the message * @param vendor vendor of the MIDlet suite to insert into the message, * can be null * @param version version of the MIDlet suite to insert into the message, * can be null * @param jadUrl URL of a JAD, can be null * * @return message to display to the user */ private static String translateJadException( InvalidJadException exception, String name, String vendor, String version, String jadUrl) { String[] values = {name, vendor, version, jadUrl, exception.getExtraData()}; int key; switch (exception.getReason()) { case InvalidJadException.OLD_VERSION: key =ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_OLD_VERSION; break; case InvalidJadException.ALREADY_INSTALLED: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_ALREADY_INSTALLED; break; case InvalidJadException.NEW_VERSION: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_NEW_VERSION; break; case InvalidJadException.JAD_SERVER_NOT_FOUND: case InvalidJadException.JAD_NOT_FOUND: case InvalidJadException.INVALID_JAD_URL: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_INVALID_JAD_URL; break; case InvalidJadException.INVALID_JAD_TYPE: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_INVALID_JAD_TYPE; break; case InvalidJadException.MISSING_PROVIDER_CERT: case InvalidJadException.MISSING_SUITE_NAME: case InvalidJadException.MISSING_VENDOR: case InvalidJadException.MISSING_VERSION: case InvalidJadException.MISSING_JAR_URL: case InvalidJadException.MISSING_JAR_SIZE: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_MISSING_JAD_INFO; break; case InvalidJadException.MISSING_CONFIGURATION: case InvalidJadException.MISSING_PROFILE: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_MISSING_JAR_INFO; break; case InvalidJadException.INVALID_KEY: case InvalidJadException.INVALID_VALUE: case InvalidJadException.INVALID_VERSION: case InvalidJadException.PUSH_FORMAT_FAILURE: case InvalidJadException.PUSH_CLASS_FAILURE: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_INVALID_FORMAT; break; case InvalidJadException.DEVICE_INCOMPATIBLE: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_DEVICE_INCOMPATIBLE; break; case InvalidJadException.JAD_MOVED: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_JAD_MOVED; break; case InvalidJadException.INSUFFICIENT_STORAGE: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_INSUFFICIENT_STORAGE; break; case InvalidJadException.JAR_SERVER_NOT_FOUND: case InvalidJadException.JAR_NOT_FOUND: case InvalidJadException.INVALID_JAR_URL: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_JAR_NOT_FOUND; break; case InvalidJadException.INVALID_JAR_TYPE: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_INVALID_JAR_TYPE; break; case InvalidJadException.SUITE_NAME_MISMATCH: case InvalidJadException.VERSION_MISMATCH: case InvalidJadException.VENDOR_MISMATCH: case InvalidJadException.JAR_SIZE_MISMATCH: case InvalidJadException.ATTRIBUTE_MISMATCH: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_ATTRIBUTE_MISMATCH; break; case InvalidJadException.CORRUPT_JAR: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_CORRUPT_JAR; break; case InvalidJadException.CANNOT_AUTH: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_CANNOT_AUTH; break; case InvalidJadException.CORRUPT_PROVIDER_CERT: case InvalidJadException.INVALID_PROVIDER_CERT: case InvalidJadException.CORRUPT_SIGNATURE: case InvalidJadException.INVALID_SIGNATURE: case InvalidJadException.UNSUPPORTED_CERT: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_INVALID_SIGNATURE; break; case InvalidJadException.UNKNOWN_CA: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_UNKNOWN_CA; break; case InvalidJadException.EXPIRED_PROVIDER_CERT: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_EXPIRED_PROVIDER_CERT; break; case InvalidJadException.EXPIRED_CA_KEY: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_EXPIRED_CA_KEY; break; case InvalidJadException.AUTHORIZATION_FAILURE: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_AUTHORIZATION_FAILURE; break; case InvalidJadException.CA_DISABLED: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_CA_DISABLED; break; case InvalidJadException.PUSH_DUP_FAILURE: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_PUSH_DUP_FAILURE; break; case InvalidJadException.PUSH_PROTO_FAILURE: key = ResourceConstants. AMS_GRA_INTLR_INVALIDJADEXCEPTION_PUSH_PROTO_FAILURE;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?