/*
*
*
* Copyright 1990-2009 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.util.Vector;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.ByteArrayInputStream;
import javax.microedition.io.ConnectionNotFoundException;
import com.sun.j2me.security.*;
import com.sun.midp.security.*;
import com.sun.midp.main.MIDletSuiteVerifier;
import com.sun.midp.main.MIDletAppImageGenerator;
import com.sun.midp.midlet.MIDletSuite;
import com.sun.midp.midletsuite.*;
import com.sun.midp.jarutil.JarReader;
import com.sun.midp.io.HttpUrl;
import com.sun.midp.io.Util;
import com.sun.midp.io.j2me.push.PushRegistryInternal;
import com.sun.midp.io.j2me.storage.RandomAccessStream;
import com.sun.midp.io.j2me.storage.File;
import com.sun.midp.rms.RecordStoreFactory;
import com.sun.midp.content.CHManager;
import com.sun.midp.log.Logging;
import com.sun.midp.log.LogChannels;
import com.sun.midp.configurator.Constants;
import com.sun.midp.jsr075.FileConnectionCleanup;
/**
* 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 abstract 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 to signal that application image is being generating.
*/
public static final int GENERATING_APP_IMAGE = 6;
/**
* Status code to signal that suite classes are being verified.
*/
public static final int VERIFYING_SUITE_CLASSES = 7;
/**
* 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 = 8;
/** Status code for corrupted suite */
public static final int CORRUPTED_SUITE = 9;
/** System property containing the supported microedition profiles */
protected static final String MICROEDITION_PROFILES =
"microedition.profiles";
/** System property containing the microedition configuration */
protected static final String MICROEDITION_CONFIG =
"microedition.configuration";
/** System property containing the microedition locale */
protected static final String MICROEDITION_LOCALE = "microedition.locale";
/** 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";
/**
* Filename to save the JAR of the suite temporarily. This is used
* to avoid overwriting an existing JAR prior to verification.
*/
protected static final String TMP_FILENAME = "installer.tmp";
/** Midlet suite signature verifier. */
protected Verifier verifier;
/** Holds the install state. */
protected InstallStateImpl state;
/** Holds the access control context. */
protected AccessControlContext accessControlContext;
/** An alias for more state.installInfo to get more compact record. */
protected InstallInfo info;
/** An alias for more state.suiteSettings to get more compact record. */
protected SuiteSettings settings;
/** Holds the CLDC configuration string. */
protected String cldcConfig;
/** Holds the device's Runtime Execution Environment string. */
protected final String cldcRuntimeEnv = "MIDP.CLDC";
/** Holds the MIDP supported profiles. */
private Vector supportedProfiles;
/** Use this to be the security domain for unsigned suites. */
protected String unsignedSecurityDomain =
Permissions.getUnsignedDomain();
/**
* Include this permissions into the list of permissions
* given in MIDlet-Permissions jad attribute for unsigned
* suites.
*/
protected String additionalPermissions;
/**
* Constructor of the Installer.
*/
Installer() {
state = getInstallState();
verifier = new VerifierImpl(state);
// This setting has no effect until OCSP is enabled at the build-time.
verifier.enableOCSPCheck(true);
// Aliases for more compact record.
info = state.installInfo;
settings = state.suiteSettings;
}
/**
* Creates an instance of InstallState of the appropriate type
* depending on the installer type. Should be overloaded in the
* inherited classes.
*
* @return an instance of class containing the installation state
*/
protected InstallStateImpl getInstallState() {
if (state == null) {
state = new InstallStateImpl();
// IMPL_NOTE: "info" and "settings" aliases must be updated
// after calling getInstallState().
}
return state;
}
/**
* Creates an AccessControlContext for the suite being installed.
*
* @return an instance of class containing the installation state
*/
protected AccessControlContext getAccessControlContext() {
if (accessControlContext == null) {
accessControlContext = new AccessControl(getInstallState());
}
return accessControlContext;
}
/**
* Installs a software package from the given URL. The URL is assumed
* refer to an application descriptor.
* <p>
* If the component to be installed is the same as an existing
* component (by comparin