1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.mj.impl.rt.legacy; |
|
19 |
|
20 import javax.microedition.midlet.MIDlet; |
|
21 |
|
22 import com.nokia.mj.impl.rt.support.ApplicationInfo; |
|
23 |
|
24 /** |
|
25 * A class for porting legacy JSRs to new runtime. |
|
26 */ |
|
27 public class LegacyRtPort |
|
28 { |
|
29 |
|
30 /** |
|
31 * A singleton instance. |
|
32 */ |
|
33 private static LegacyRtPort mInstance = new LegacyRtPort(); |
|
34 |
|
35 /** |
|
36 * The running MIDlet instance. |
|
37 */ |
|
38 private MIDlet mMidlet; |
|
39 |
|
40 /** |
|
41 * The registered UI toolkit. |
|
42 */ |
|
43 private String mRegisteredToolkit; |
|
44 |
|
45 /** |
|
46 * Contructor, allowed only for this class. |
|
47 */ |
|
48 private LegacyRtPort() |
|
49 { |
|
50 } |
|
51 |
|
52 /** |
|
53 * Sets the running MIDlet. |
|
54 */ |
|
55 static void setMidlet(MIDlet midlet) |
|
56 { |
|
57 mInstance.mMidlet = midlet; |
|
58 } |
|
59 |
|
60 /** |
|
61 * Gets the running MIDlet instance. |
|
62 */ |
|
63 public static MIDlet getMidlet() |
|
64 { |
|
65 return mInstance.mMidlet; |
|
66 } |
|
67 |
|
68 /** |
|
69 * Gets the UID of the running MIDlet in int format. |
|
70 */ |
|
71 public static int getMidletUid() |
|
72 { |
|
73 int midletUid = -1; |
|
74 try |
|
75 { |
|
76 String uidS = ApplicationInfo.getInstance().getUid().getStringValue(); |
|
77 // In Symbian the UID is in format '[<uid>]' where <uid> is in hex |
|
78 // format. So wee need to take the brackets away. |
|
79 // Long is needed in conversion because UIDs greater than 0x80000000 |
|
80 // would fail if Integer would be used. However typecast from long |
|
81 // to int is safe since UID in Symbian is 32 bit. |
|
82 long uidL = Long.parseLong(uidS.substring(1,uidS.length()-1), 16); |
|
83 return (int)uidL; |
|
84 } |
|
85 catch (Throwable t) |
|
86 { |
|
87 } |
|
88 return midletUid; |
|
89 } |
|
90 |
|
91 |
|
92 /** |
|
93 * Registers active UI toolkit. There can be only one active UI toolkit at the |
|
94 * same time. |
|
95 */ |
|
96 public static void registerToolkit(String toolkitId) |
|
97 { |
|
98 if (mInstance.mRegisteredToolkit != null) |
|
99 { |
|
100 throw new RuntimeException("Could not register toolkit: " + |
|
101 toolkitId); |
|
102 } |
|
103 mInstance.mRegisteredToolkit = toolkitId; |
|
104 } |
|
105 |
|
106 /** |
|
107 * Unregisters the given UI toolkit. |
|
108 */ |
|
109 public static void unRegisterToolkit(String toolkitId) |
|
110 { |
|
111 if (mInstance.mRegisteredToolkit != null && |
|
112 mInstance.mRegisteredToolkit.equals(toolkitId)) |
|
113 { |
|
114 mInstance.mRegisteredToolkit = null; |
|
115 } |
|
116 } |
|
117 |
|
118 /** |
|
119 * Gets the active UI toolkit. |
|
120 */ |
|
121 public static String getRegisteredToolkit() |
|
122 { |
|
123 return mInstance.mRegisteredToolkit; |
|
124 } |
|
125 |
|
126 /** |
|
127 * Gets the ApplicationId. |
|
128 */ |
|
129 public static Object getApplicationId() |
|
130 { |
|
131 return mInstance; |
|
132 } |
|
133 |
|
134 } |
|