equal
deleted
inserted
replaced
78 * shut down procedure, it is a responsibility of the Java Captain to terminate |
78 * shut down procedure, it is a responsibility of the Java Captain to terminate |
79 * the MIDP process. The MIDP runtime tries to close gracefully the JVM, but |
79 * the MIDP process. The MIDP runtime tries to close gracefully the JVM, but |
80 * that will fail if any of the started Java threads dont stop as a result of |
80 * that will fail if any of the started Java threads dont stop as a result of |
81 * shut down notifications. That is considered a failure in the shut down phase |
81 * shut down notifications. That is considered a failure in the shut down phase |
82 * and the Java Captain will terminate forcefully the process. |
82 * and the Java Captain will terminate forcefully the process. |
83 * |
|
84 * @author Nokia Corporation |
|
85 * @version $Rev$ |
|
86 */ |
83 */ |
87 final class MidletLifeCycle |
84 final class MidletLifeCycle |
88 { |
85 { |
89 /** |
86 /** |
90 * Possible states of the state machine |
87 * Possible states of the state machine |
98 private static final int STOPPING_MIDLET = 0x40; |
95 private static final int STOPPING_MIDLET = 0x40; |
99 private static final int CLOSED = 0x80; |
96 private static final int CLOSED = 0x80; |
100 private static final int RESUMING = 0x100; |
97 private static final int RESUMING = 0x100; |
101 |
98 |
102 /** |
99 /** |
103 * A singleton instance of the life cycle. It is singleton for provoding |
100 * A singleton instance of the life cycle. |
104 * easy access to all other classes of the MIDP runtime. |
|
105 */ |
101 */ |
106 private static MidletLifeCycle mInstance = new MidletLifeCycle(); |
102 private static MidletLifeCycle mInstance = new MidletLifeCycle(); |
107 |
103 |
108 /** |
104 /** |
109 * Timers for ensuring that correct actions are done if MIDlet doesn't |
105 * Timers for ensuring that correct actions are done if MIDlet doesn't |
249 |
245 |
250 if (mRuntimeErrDialog != null) |
246 if (mRuntimeErrDialog != null) |
251 { |
247 { |
252 mRuntimeErrDialog.showDialog(); |
248 mRuntimeErrDialog.showDialog(); |
253 } |
249 } |
254 if (Log.mOn) Log.logI("Sending close indication to runtime starter."); |
|
255 _closeInd(mNativeRuntimeStarterHandle); |
|
256 |
|
257 if (Log.mOn) Log.logI("Sending shutdown notifications to listeners."); |
|
258 ApplicationUtilsImpl.doShutdownImpl(); |
|
259 |
250 |
260 if (!mStandAlone) |
251 if (!mStandAlone) |
261 { |
252 { |
262 if (Log.mOn) Log.logI("Sending termination indication to Captain."); |
253 if (Log.mOn) Log.logI("Sending termination indication to Captain."); |
263 mMidpcomms.sendTerminatedIndication(0); |
254 mMidpcomms.sendTerminatedIndication(0); |
265 if (Log.mOn) Log.logI("Closing COMMS."); |
256 if (Log.mOn) Log.logI("Closing COMMS."); |
266 mMidpcomms.close(); |
257 mMidpcomms.close(); |
267 mMidpcomms = null; |
258 mMidpcomms = null; |
268 } |
259 } |
269 |
260 |
270 if (Log.mOn) Log.logI("Short pause before closing dispatchers."); |
261 if (Log.mOn) Log.logI("Sending shutdown notifications to listeners."); |
|
262 ApplicationUtilsImpl.doShutdownImpl(); |
|
263 |
|
264 if (Log.mOn) Log.logI("Sending close indication to runtime starter."); |
|
265 _closeInd(mNativeRuntimeStarterHandle); |
|
266 |
|
267 |
|
268 if (Log.mOn) Log.logI("Short pause before closing LegacySupport."); |
271 try |
269 try |
272 { |
270 { |
273 Thread.sleep(200); |
271 Thread.sleep(200); |
274 } |
272 } |
275 catch (Exception e) |
273 catch (Exception e) |
276 { |
274 { |
277 } |
275 } |
278 |
276 |
279 if (Log.mOn) Log.logI("Closing dispatchers."); |
277 if (Log.mOn) Log.logI("Closing LegacySupport."); |
280 LegacySupport.close(); |
278 LegacySupport.close(); |
281 |
279 |
282 // Setting state to closed. |
280 // Setting state to closed. |
283 mState = CLOSED; |
281 mState = CLOSED; |
284 } |
282 } |
600 } |
598 } |
601 |
599 |
602 /** |
600 /** |
603 * Handles the start request task. Allowed to be called only from |
601 * Handles the start request task. Allowed to be called only from |
604 * startStateMachine() method. The only intention of this method is |
602 * startStateMachine() method. The only intention of this method is |
605 * to diminish the switch case clause in the diminish startStateMachine() |
603 * to diminish the switch case clause in the startStateMachine() |
606 * method. |
604 * method. |
607 * @param subTask The sub task provided by the task setter. |
605 * @param subTask The sub task provided by the task setter. |
608 */ |
606 */ |
609 private void handleStartRequest(int subTask) |
607 private void handleStartRequest(int subTask) |
610 { |
608 { |
611 if (Log.mOn) Log.logI("MidletLifeCycle.handleStartRequest(), subTask: " |
609 if (Log.mOn) Log.logI("MidletLifeCycle.handleStartRequest(), subTask: " |
612 + subTask); |
610 + subTask); |
613 if (mState == POST_INIT_DONE || (mState == PRE_INIT_DONE && |
611 if ((mState == POST_INIT_DONE && subTask != LifeCycleTask.PRE_WARM_START) || |
614 subTask == LifeCycleTask.PRE_WARM_START)) |
612 (mState == PRE_INIT_DONE && subTask == LifeCycleTask.PRE_WARM_START)) |
615 { |
613 { |
616 if (subTask == LifeCycleTask.NORMAL_START) |
614 if (subTask == LifeCycleTask.NORMAL_START) |
617 { |
615 { |
618 if (Log.mOn) Log.logI(" Normal start"); |
616 if (Log.mOn) Log.logI(" Normal start"); |
619 mState = STARTING_MIDLET; |
617 mState = STARTING_MIDLET; |
778 // Set protected and restricted packages. |
776 // Set protected and restricted packages. |
779 setClassProtection(); |
777 setClassProtection(); |
780 |
778 |
781 // Check if there are add-on JSRs. |
779 // Check if there are add-on JSRs. |
782 ExtensionUtil.handleExtensions(); |
780 ExtensionUtil.handleExtensions(); |
|
781 } |
|
782 else |
|
783 { |
|
784 ApplicationUtilsImpl.setStandAloneMode(); |
783 } |
785 } |
784 |
786 |
785 mTaskQueue = new TaskQueue(); |
787 mTaskQueue = new TaskQueue(); |
786 |
788 |
787 // If system property com.nokia.mid.cmdline has value, it contains |
789 // If system property com.nokia.mid.cmdline has value, it contains |
917 // The native peer doesn't know the UID of the started MIDlet. |
919 // The native peer doesn't know the UID of the started MIDlet. |
918 // Informing native. |
920 // Informing native. |
919 _setUids(mMidletUid.toString(), |
921 _setUids(mMidletUid.toString(), |
920 ApplicationInfoImpl.getMidletInfo().getSuiteUid().toString(), |
922 ApplicationInfoImpl.getMidletInfo().getSuiteUid().toString(), |
921 mNativeRuntimeStarterHandle); |
923 mNativeRuntimeStarterHandle); |
922 // The Jvm doesn't know about MIDlet class path - need to set it. |
|
923 String classPath = ApplicationInfoImpl.getMidletInfo().getClassPath(); |
|
924 if (Log.mOn) Log.logI(" Adding to classpath: "+classPath); |
|
925 JvmInternal.appendToClassPath(classPath); |
|
926 } |
924 } |
927 |
925 |
928 private void doPostInit() |
926 private void doPostInit() |
929 { |
927 { |
930 if (Log.mOn) Log.logI("Doing post init."); |
928 if (Log.mOn) Log.logI("Doing post init."); |
944 // In case of pre-warm start we need to create the core ui |
942 // In case of pre-warm start we need to create the core ui |
945 // from Java side. In order to ensure that Runtime Support |
943 // from Java side. In order to ensure that Runtime Support |
946 // API works ok, the setMidletInfo must be called before |
944 // API works ok, the setMidletInfo must be called before |
947 // starting the UI. |
945 // starting the UI. |
948 CoreUi.createUi(mMidletUid, mBackGroundStart); |
946 CoreUi.createUi(mMidletUid, mBackGroundStart); |
|
947 |
|
948 // The Jvm doesn't know about MIDlet class path - need to set it. |
|
949 String classPath = ApplicationInfoImpl.getMidletInfo().getClassPath(); |
|
950 if (Log.mOn) Log.logI(" Adding to classpath: "+classPath); |
|
951 JvmInternal.appendToClassPath(classPath); |
949 } |
952 } |
950 if (!mStandAlone) |
953 if (!mStandAlone) |
951 { |
954 { |
952 |
955 |
953 // Do the MIDlet suite authentication. |
956 // Do the MIDlet suite authentication. |