01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package com.sun.midp.main;
28:
29: import javax.microedition.lcdui.Image;
30:
31: import com.sun.midp.midlet.MIDletStateHandler;
32: import com.sun.midp.midlet.MIDletSuite;
33:
34: import com.sun.midp.security.Permissions;
35:
36: import com.sun.midp.util.ResourceHandler;
37:
38: import com.sun.midp.security.SecurityToken;
39: import com.sun.midp.security.SecurityInitializer;
40: import com.sun.midp.security.ImplicitlyTrustedClass;
41:
42: /**
43: * This holds the trusted MIDlet icon.
44: */
45: public class TrustedMIDletIcon {
46: /** The trusted icon. */
47: private static Image trustedIcon;
48:
49: /**
50: * Inner class to request security token from SecurityInitializer.
51: * SecurityInitializer should be able to check this inner class name.
52: */
53: static private class SecurityTrusted implements
54: ImplicitlyTrustedClass {
55: };
56:
57: /** Security token to allow access to implementation APIs */
58: private static SecurityToken classSecurityToken = SecurityInitializer
59: .requestToken(new SecurityTrusted());
60:
61: /**
62: * Get the Image of the trusted icon for this Display.
63: * Only callers with the internal AMS permission can use this method.
64: *
65: * @return an Image of the trusted icon.
66: *
67: * @exception SecurityException if the suite calling does not have the
68: * the AMS permission
69: */
70: public static Image getIcon() {
71: MIDletStateHandler midletStateHandler = MIDletStateHandler
72: .getMidletStateHandler();
73:
74: MIDletSuite suite = midletStateHandler.getMIDletSuite();
75: suite.checkIfPermissionAllowed(Permissions.AMS);
76:
77: if (trustedIcon == null) {
78: byte[] imageData = ResourceHandler.getSystemImageResource(
79: classSecurityToken, "trustedmidlet_icon");
80: if (imageData != null) {
81: trustedIcon = Image.createImage(imageData, 0,
82: imageData.length);
83: } else {
84: // Use a empty immutable image as placeholder
85: trustedIcon = Image.createImage(Image.createImage(16,
86: 16));
87: }
88: }
89:
90: return trustedIcon;
91: }
92: }
|