javamanager/javacaptain/extensionplugins/preinstallerstarter/src.s60/preinstallerstarter.cpp
changeset 35 85266cc22c7f
parent 21 2a9601315dfc
child 50 023eef975703
--- a/javamanager/javacaptain/extensionplugins/preinstallerstarter/src.s60/preinstallerstarter.cpp	Thu May 27 12:49:31 2010 +0300
+++ b/javamanager/javacaptain/extensionplugins/preinstallerstarter/src.s60/preinstallerstarter.cpp	Fri Jun 11 13:33:44 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2008 - 2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -31,6 +31,7 @@
 #include "coreinterface.h"
 #include "booteventprovidermessages.h"
 #include "mmceventprovidermessages.h"
+#include "preinstallerstartermessages.h"
 
 #include "preinstallerstarter.h"
 
@@ -52,19 +53,19 @@
 using java::fileutils::DriveListenerInterface;
 
 /**
- * Empty contructor
+ * Initialize member varaibles in constructor
  */
-PreinstallerStarter::PreinstallerStarter() : mCore(0)
+PreinstallerStarter::PreinstallerStarter() :
+    CActive(EPriorityStandard), mCore(0), mPreinstaller(0)
 {
-    JELOG2(EJavaCaptain);
 }
 
 /**
- * Empty destructor
+ * Destructor
  */
 PreinstallerStarter::~PreinstallerStarter()
 {
-    JELOG2(EJavaCaptain);
+    DoCancel();
 }
 
 /**
@@ -72,8 +73,8 @@
  */
 void PreinstallerStarter::startPlugin(CoreInterface* core)
 {
-    JELOG2(EJavaCaptain);
     mCore = core;
+    CActiveScheduler::Add(this);
 }
 
 /**
@@ -81,7 +82,6 @@
  */
 void PreinstallerStarter::stopPlugin()
 {
-    JELOG2(EJavaCaptain);
     mCore = 0;
 }
 
@@ -90,7 +90,6 @@
  */
 EventConsumerInterface* PreinstallerStarter::getEventConsumer()
 {
-    JELOG2(EJavaCaptain);
     return this;
 }
 
@@ -106,7 +105,6 @@
 void PreinstallerStarter::event(const std::string& eventProvider,
                                 java::comms::CommsMessage& aMsg)
 {
-    JELOG2(EJavaCaptain);
     if (eventProvider == BOOT_EVENT_PROVIDER)
     {
         int bootType = NORMAL_BOOT_C;
@@ -133,7 +131,9 @@
         case FIRST_DEVICE_BOOT_C:
         case NORMAL_BOOT_C:
         {
+#ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
             registerMidletApplicationTypeHandler();
+#endif
 
             // Start preinstaller normally (without 'iad' option).
             startPreinstaller(EFalse);
@@ -183,8 +183,6 @@
  */
 void PreinstallerStarter::startPreinstaller(TBool aIadBoot)
 {
-    JELOG2(EJavaCaptain);
-
     // Check that the device has enough free memory (800kB) to start preinstaller process
     // and (if needed) also java installer
     TInt freeMemory = 0;
@@ -276,17 +274,21 @@
         }
 
         // start preinstaller
-        RProcess preinstaller;
+        mPreinstaller = new RProcess();
         TBuf<64> preinstallerProcess;  // Actual len of the process name is 9
         len = strlen(java::runtime::JAVA_PROCESS);
         TPtr8 ptr8Process((TUint8 *)java::runtime::JAVA_PROCESS, len, len);
         preinstallerProcess.Copy(ptr8Process);
-        TInt err = preinstaller.Create(preinstallerProcess, commandLine);
+        TInt err = mPreinstaller->Create(preinstallerProcess, commandLine);
         if (KErrNone == err)
         {
-            // process has been created, allow it to run
-            preinstaller.Resume();
-            preinstaller.Close();
+            // Process has been created.
+
+            // This active object will be activated when preinstaller process exits
+            mPreinstaller->Logon(iStatus);
+
+            // Allow the process to run
+            mPreinstaller->Resume();
             if (aIadBoot)
             {
                 LOG(
@@ -298,9 +300,14 @@
             {
                 LOG(EJavaCaptain, EInfo, "PreinstallerStarter: started preinstaller");
             }
+
+            SetActive();
         }
         else
         {
+            delete mPreinstaller;
+            mPreinstaller = 0;
+
             ELOG1(
                 EJavaCaptain,
                 "PreinstallerStarter: starting preinstaller failed, err %d",
@@ -375,5 +382,35 @@
     }
 }
 
+void PreinstallerStarter::RunL()
+{
+    LOG(EJavaCaptain, EInfo, "PreinstallerStarter::RunL started");
+
+    // Send event to AutoStarter plugin, done only once
+    CommsMessage eventMsg;
+    setPreinstallerExitedMessageParams(eventMsg, iStatus.Int());
+    mCore->getEventDispatcher()->event(PREINSTALLER_EVENT_PROVIDER, eventMsg);
+
+    // process handle is no longer needed
+    mPreinstaller->Close();
+    delete mPreinstaller;
+    mPreinstaller = 0;
+}
+
+
+void PreinstallerStarter::DoCancel()
+{
+    if (mPreinstaller)
+    {
+        mPreinstaller->LogonCancel(iStatus);
+        // Because exit notification request has been canceled,
+        // there is no reason to keep the process handle open.
+        mPreinstaller->Close();
+        delete mPreinstaller;
+        mPreinstaller = 0;
+    }
+}
+
+
 } // namespace captain
 } // namespace java