midletsuiteimpl.jpp
来自「This is a resource based on j2me embedde」· JPP 代码 · 共 741 行 · 第 1/2 页
JPP
741 行
/* * * * 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.midletsuite;import java.io.*;import java.util.*;import javax.microedition.io.*;import javax.microedition.lcdui.*;import javax.microedition.midlet.*;import com.sun.j2me.security.AccessController;import com.sun.midp.io.*;import com.sun.midp.i18n.Resource;import com.sun.midp.i18n.ResourceConstants;import com.sun.midp.security.*;import com.sun.midp.midlet.*;import com.sun.midp.midletsuite.SuiteProperties;import com.sun.midp.io.j2me.storage.*;import com.sun.midp.log.Logging;import com.sun.midp.log.LogChannels;import com.sun.midp.main.MIDletSuiteVerifier;import com.sun.midp.util.Properties;import com.sun.midp.configurator.Constants;/** * Implements the required MIDletSuite functionality needed by the * system. */public final class MIDletSuiteImpl implements MIDletSuite { /** This class has a different security domain than the application. */ private static SecurityToken classSecurityToken; /** MIDlet Suite Storage. */ private MIDletSuiteStorage midletSuiteStorage; /** Security token for this suite. */ private SecurityHandler securityHandler; /** Suite properties of the application descriptor and manifest. */ private SuiteProperties suiteProperties; /** Suite settings for this suite. */ private SuiteSettings suiteSettings; /** Installation information for this suite. */ private InstallInfo installInfo; /** The ID of this suite. */ private int id; /** Cache of MIDlet-1 name. */ private String midlet_1_name; /** Cache of MIDlet-1 class. */ private String midlet_1_class; /** * Number of midlets in this suite. less than 0 mean they need to * counted. */ private int numberOfMidlets = -1; /** * Indicator to check if the suite has already been locked */ private boolean locked = false; /** * 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 */ static void initSecurityToken(SecurityToken token) { if (classSecurityToken != null) { return; } classSecurityToken = token; } /** * Constructs MIDletSuiteImpl from an installed MIDlet Suite. * * @param theID unique identifier for this suite */ MIDletSuiteImpl(int theID) throws MIDletSuiteCorruptedException { id = theID; locked = true; suiteProperties = new SuiteProperties(id); suiteSettings = new SuiteSettings(id); suiteSettings.load(); installInfo = new InstallInfo(id); try { installInfo.load(); } catch (IOException ioe) { throw new MIDletSuiteCorruptedException( "installInfo.load IOException"); } } /** * Gets a property of the suite. A property is an attribute from * either the application descriptor or JAR Manifest. * * @param key the name of the property * @return A string with the value of the property. * <code>null</code> is returned if no value is available for * the key. */ public String getProperty(String key) { guaranteeMIDletSuiteLocked("getProperty"); return suiteProperties.getProperty(key); } /** * Replace or add a property to the suite for this run only. * * @param token token with the AMS permission set to allowed, * can be null to use the suite's permission * @param key the name of the property * @param value the value of the property * * @exception SecurityException if the caller's token does not have * internal AMS permission */ public void setTempProperty(SecurityToken token, String key, String value) { guaranteeMIDletSuiteLocked("setTempProperty"); if (token != null) { token.checkIfPermissionAllowed(Permissions.AMS); } else { AccessController.checkPermission(Permissions.AMS_PERMISSION_NAME); } suiteProperties.setTempProperty(key, value); } /** * Checks to see the suite has the ALLOW level for specific permission. * This is used for by internal APIs that only provide access to * trusted system applications. * * @param permission permission ID from com.sun.midp.security.Permissions * * @exception SecurityException if the suite is not allowed the permission */ public void checkIfPermissionAllowed(String permission) { if (checkPermission(permission) != 1) { throw new SecurityException(SecurityToken.STD_EX_MSG); } } /** * Checks for permission and throw an exception if not allowed. * May block to ask the user a question. * * @param permission ID of the permission to check for, * the ID must be from * {@link com.sun.midp.security.Permissions} * @param resource string to insert into the question, can be null if * no %2 in the question * * @exception SecurityException if the permission is not * allowed by this token * @exception InterruptedException if another thread interrupts the * calling thread while this method is waiting to preempt the * display. */ public void checkForPermission(String permission, String resource) throws InterruptedException { guaranteeMIDletSuiteLocked("checkForPermission"); checkForPermission(permission, getProperty(SUITE_NAME_PROP), resource, null); } /** * Checks for permission and throw an exception if not allowed. * May block to ask the user a question. * * @param permission ID of the permission to check for, * the ID must be from * {@link com.sun.midp.security.Permissions} * @param resource string to insert into the question, can be null if * no %2 in the question * @param extraValue string to insert into the question, * can be null if no %3 in the question * * @exception SecurityException if the permission is not * allowed by this token * @exception InterruptedException if another thread interrupts the * calling thread while this method is waiting to preempt the * display. */ public void checkForPermission(String permission, String resource, String extraValue) throws InterruptedException { guaranteeMIDletSuiteLocked("checkForPermission"); checkForPermission(permission, getProperty(SUITE_NAME_PROP), resource, extraValue); } /** * Checks for permission and throw an exception if not allowed. * May block to ask the user a question. * * @param permissionStr ID of the permission to check for, * the ID must be from * {@link com.sun.midp.security.Permissions} * @param name name of the suite, %1 in the question * @param resource string to insert into the question, can be null if * no %2 in the question * @param extraValue string to insert into the question, * can be null if no %3 in the question * * @exception SecurityException if the permission is not * allowed by this token * @exception InterruptedException if another thread interrupts the * calling thread while this method is waiting to preempt the * display. */ private void checkForPermission(String permissionStr, String name, String resource, String extraValue) throws InterruptedException { boolean settingsChanged = true; // assume they changed suiteSettings.load(); try { int permission = Permissions.getId(permissionStr); settingsChanged = getSecurityHandler().checkForPermission( permissionStr, Permissions.getTitle(permission), Permissions.getQuestion(permission), Permissions.getOneshotQuestion(permission), name, resource, extraValue); } finally { if (settingsChanged) { suiteSettings.save(); } } } /** * Gets the status of the specified permission. * If no API on the device defines the specific permission * requested then it must be reported as denied. * If the status of the permission is not known because it might * require a user interaction then it should be reported as unknown. * * @param permission to check if denied, allowed, or unknown * @return 0 if the permission is denied; 1 if the permission is allowed; * -1 if the status is unknown */ public int checkPermission(String permission) { guaranteeMIDletSuiteLocked("checkPermission"); suiteSettings.load(); return getSecurityHandler().checkPermission(permission); } /** * Gets the unique ID of the suite. * * @return suite ID */ public int getID() { guaranteeMIDletSuiteLocked("getID"); return id; } /** * Asks the user want to interrupt the current MIDlet with * a new MIDlet that has received network data. * * @param connection connection to place in the permission question or * null for alarm * * @return true if the use wants interrupt the current MIDlet, else false */ public boolean permissionToInterrupt(String connection) { String name; MIDletSuite current; int question; String currentName; boolean interruptOk; boolean settingsChanged = false; guaranteeMIDletSuiteLocked("permissionToInterrupt"); suiteSettings.load(); switch (suiteSettings.getPushInterruptSetting()) { case Permissions.ALLOW: case Permissions.BLANKET_GRANTED: return true; case Permissions.BLANKET_DENIED: case Permissions.NEVER: return false; } /* Any other cases require prompting the user. */ name = getSuiteNameForInterrupt(); // The currently running suite controls what question to ask. current = MIDletStateHandler.getMidletStateHandler().getMIDletSuite(); if (current instanceof MIDletSuiteImpl) { MIDletSuiteImpl temp = (MIDletSuiteImpl)current; if (connection == null) { question = temp.getAlarmInterruptQuestion(); } else { question = temp.getPushInterruptQuestion(); } currentName = temp.getSuiteNameForInterrupt(); } else { // Use the internal MIDlet question question = ResourceConstants. AMS_MIDLETSUITELDR_PUSH_INTERRUPT_QUESTION; currentName = Resource.getString (ResourceConstants.AMS_MIDLETSUITEIMPL_CURR_APP); } try { interruptOk = SecurityHandler.askUserForPermission( classSecurityToken, isTrusted(), Resource.getString(ResourceConstants.AMS_MIDLETSUITEIMPL_INTRPT_QUE), Resource.getString(question), name, currentName, null); switch (suiteSettings.getPushInterruptSetting()) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?