installerpeermidlet.java

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

JAVA
696
字号
     *     * @param state current state of the install.     *     * @return true if the user wants to continue, false to stop the install     */    public boolean confirmJarDownload(InstallState state) {        int err = sendNativeRequest0(RQ_CONFIRM_JAR_DOWNLOAD,                                     convertInstallState(state),                                     -1, null);        if (err != 0) {            return false; /* stop the installation */        }        /*         * This Java thread is blocked here until the answer arrives         * in native, then it is woken up also from the native code.         */        return getAnswer0();    }    /**     * Called with the current status of the install. See     * {@link Installer} for the status codes.     *     * @param status current status of the install.     * @param state current state of the install.     */    public void updateStatus(int status, InstallState state) {        sendNativeRequest0(RQ_UPDATE_STATUS, convertInstallState(state),                           status, null);    }    /**     * Called with the current state of the install so the user can be     * asked to confirm if the RMS data should be kept for new version of     * an updated suite.     * If false is returned, the an I/O exception thrown and     * {@link Installer#wasStopped()} will return true if called.     *     * @param state current state of the install.     *     * @return true if the user wants to keep the RMS data for the next suite     */    public boolean keepRMS(InstallState state) {        int err = sendNativeRequest0(RQ_ASK_KEEP_RMS,                                     convertInstallState(state),                                     -1, null);        if (err != 0) {            return true; /* keep the RMS */        }        /*         * This Java thread is blocked here until the answer arrives         * in native, then it is woken up also from the native code.         */        return getAnswer0();    }    /**     * Called with the current state of the install so the user can be     * asked to confirm the authentication path.     * If false is returned, the an I/O exception thrown and     * {@link Installer#wasStopped()} will return true if called.     *     * @param state current state of the install.     *     * @return true if the user wants to continue, false to stop the install     */    public boolean confirmAuthPath(InstallState state) {        int err = sendNativeRequest0(RQ_CONFIRM_AUTH_PATH,                                     convertInstallState(state),                                     -1, null);        if (err != 0) {            return false; /* stop the installation */        }        /*         * This Java thread is blocked here until the answer arrives         * in native, then it is woken up also from the native code.         */        return getAnswer0();    }    /**     * Called with the current state of the install and the URL where the     * request is attempted to be redirected so the user can be asked     * to confirm if he really wants to install from the new location.     * If false is returned, the an I/O exception thrown and     * {@link com.sun.midp.installer.Installer#wasStopped()}     * will return true if called.     *     * @param state       current state of the install.     * @param newLocation new url of the resource to install.     *      * @return true if the user wants to continue, false to stop the install     */    public boolean confirmRedirect(InstallState state, String newLocation) {        int err = sendNativeRequest0(RQ_CONFIRM_REDIRECT,                                     convertInstallState(state),                                     -1, newLocation);        if (err != 0) {            return false; /* stop the installation */        }        /*         * This Java thread is blocked here until the answer arrives         * in native, then it is woken up also from the native code.         */        return getAnswer0();    }    /**     * Converts the given InstallState object into NativeInstallState     * to facilitate access to it from the native code.      *     * @param state the state object to convert     *     * @return NativeInstallState object corresponding to the given     *         InstallState object     */    private NativeInstallState convertInstallState(InstallState state) {        NativeInstallState nis = new NativeInstallState();        nis.appId = appId;        nis.suiteId = state.getID();        nis.jarUrl = state.getJarUrl();        nis.suiteName = state.getSuiteName();        nis.jarSize = state.getJarSize();        nis.authPath = state.getAuthPath();        InvalidJadException ije = state.getLastException();        if (ije == null) {            nis.exceptionCode = NativeInstallState.NO_EXCEPTIONS;        } else {            nis.exceptionCode = ije.getReason();        }        /*         * IMPL_NOTE: only well-known attributes are supported         *            for the installation purposes.         */        final String[] propNames = {            MIDletSuite.JAR_MANIFEST,       MIDletSuite.DATA_SIZE_PROP,            MIDletSuite.JAR_SIZE_PROP,      MIDletSuite.JAR_URL_PROP,            MIDletSuite.SUITE_NAME_PROP,    MIDletSuite.VENDOR_PROP,            MIDletSuite.VERSION_PROP,       MIDletSuite.DESC_PROP,            MIDletSuite.CONFIGURATION_PROP, MIDletSuite.PROFILE_PROP,            MIDletSuite.RUNTIME_EXEC_ENV_PROP,            MIDletSuite.RUNTIME_EXEC_ENV_DEFAULT,            MIDletSuite.PERMISSIONS_PROP,   MIDletSuite.PERMISSIONS_OPT_PROP        };        Vector v = new Vector(propNames.length * 2);        for (int i = 0; i < propNames.length; i++) {            String propValue = state.getAppProperty(propNames[i]);            if (propValue != null) {                v.addElement(propNames[i]);                v.addElement(propValue);            }        }        int arraySize = v.size();        if (arraySize > 0) {            nis.suiteProperties = new String[arraySize];            for (int j = 0; j < arraySize; j++, j++) {                nis.suiteProperties[j] = (String)v.elementAt(j);                nis.suiteProperties[j + 1] = (String)v.elementAt(j + 1);            }        } else {            nis.suiteProperties = null;        }        return nis;    }    // ==============================================================    // ------ Implementation of the EventListener interface    /**     * Preprocess an event that is being posted to the event queue.     * This method will get called in the thread that posted the event.     *     * @param event event being posted     *     * @param waitingEvent previous event of this type waiting in the     *     queue to be processed     *     * @return true to allow the post to continue, false to not post the     *     event to the queue     */    public boolean preprocess(Event event, Event waitingEvent) {        return true;    }    /**     * Process an event.     * This method will get called in the event queue processing thread.     *     * @param event event to process     */    public void process(Event event) {        NativeEvent nativeEvent = (NativeEvent)event;        // appId of the running installer which the event is intended for        int installerAppId = nativeEvent.intParam1;        // -1 - broadcast        if ((installerAppId != appId) && (installerAppId != -1)) {            // this event was sent to another installer, ignoring            return;        }        switch (nativeEvent.getType()) {            case EventTypes.NATIVE_UNBLOCK_INSTALLER: {                unblockInstaller0();                break;            }            case EventTypes.NATIVE_ENABLE_OCSP_REQUEST: {                /*                 * intParam1 - appId of the running installer,                 * intParam2 - 0/1 to enable / disable OCSP                 */                boolean enable = (nativeEvent.intParam2 != 0);                int result;                if (installer != null) {                    installer.enableOCSPCheck(enable);                    result = 0;                } else {                    result = -1;                }                notifyRequestHandled0(appId,                        EventTypes.NATIVE_ENABLE_OCSP_REQUEST,                                result, enable);                break;            }            case EventTypes.NATIVE_CHECK_OCSP_ENABLED_REQUEST: {                boolean ocspEnabled;                int result;                if (installer != null) {                    ocspEnabled = installer.isOCSPCheckEnabled();                    result = 0;                } else {                    result = -1;                    ocspEnabled = false;                }                                notifyRequestHandled0(appId,                        EventTypes.NATIVE_CHECK_OCSP_ENABLED_REQUEST,                                result, ocspEnabled);                break;            }        }    }    // ==============================================================    // Native methods.    /**     * Sends a request of type defined by the given request code to     * the party that uses this installer via the native callback.     *     * Note: only some of parameters are used, depending on the request code     *     * IMPL_NOTE: the request code passed to this method as an argument must     *            be the same as the corresponding JAVACALL_INSTALL_REQUEST_*     *            value defined in javacall_ams_installer.h.     *      * @param requestCode code of the request to the native callback     * @param state       current installation state     * @param status      current status of the installation, -1 if not used     * @param newLocation new url of the resource to install; null if not used     *     * @return 0 if no errors, a platform-specific error code otherwise     */    private static native int sendNativeRequest0(            int requestCode,            NativeInstallState state,            int status,            String newLocation);    /**     * Returns yes/no answer from the native callback.     *     * @return yes/no answer from the native callback     */    private static native boolean getAnswer0();    /**     * Reports to the party using this installer that     * the installation has been completed.     *     * @param appId this application ID     * @param suiteId ID of the newly installed midlet suite, or     *                MIDletSuite.UNUSED_SUITE_ID if the installation     *                failed     * @param resultCode result of the installation (0 if succeeded or -1 in     *                   case of unknown error, or one of the values defined     *                   in InvalidJadException)     * @param errMsg error message if the installation failed, null otherwise     */    private static native void reportFinished0(            int appId, int suiteId, int resultCode, String errMsg);    /**     * Reports to the party using this installer that the requested     * operation has been completed and the result (if any) is available.     *     * @param appId this application ID     * @param requestCode code of the request that was handled     * @param resultCode completion code (0 if succeeded or -1 in case     *                   of error)     * @param result operation-dependent result (for OCSP operations it contains     *               the current state (enabled/disabled) of OCSP checks)     */    private static native void notifyRequestHandled0(        int appId, int requestCode, int resultCode, boolean result);    /**     * Unblocks the installer thread.     */    private static native void unblockInstaller0();}/** * Storage for InstallState fields that should be passed to native. */class NativeInstallState {    /**     * exceptionCode value indicating that there are no exceptions.     */    public static final int NO_EXCEPTIONS = -1;    public int appId;    public int exceptionCode;    public int suiteId;    public String[] suiteProperties;    public String jarUrl;    public String suiteName;    public int    jarSize;    public String[] authPath;}

⌨️ 快捷键说明

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