javamanager/javacaptain/extensionplugins/preinstallerstarter/src.s60/preinstallerstarter.cpp
branchRCL_3
changeset 60 6c158198356e
parent 19 04becd199f91
child 83 26b2b12093af
equal deleted inserted replaced
59:e5618cc85d74 60:6c158198356e
     1 /*
     1 /*
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008 - 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    17 *
    17 *
    18 */
    18 */
    19 
    19 
    20 
    20 
    21 #include <e32base.h>
    21 #include <e32base.h>
       
    22 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    22 #include <apgcli.h> // for RApaLsSession
    23 #include <apgcli.h> // for RApaLsSession
       
    24 #endif
    23 #include <hal_data.h>
    25 #include <hal_data.h>
    24 #include <hal.h>
    26 #include <hal.h>
    25 #include <sysutil.h>
    27 #include <sysutil.h>
    26 
    28 
    27 #include "javaprocessconstants.h"
    29 #include "javaprocessconstants.h"
    29 #include "javauids.h"
    31 #include "javauids.h"
    30 #include "logger.h"
    32 #include "logger.h"
    31 #include "coreinterface.h"
    33 #include "coreinterface.h"
    32 #include "booteventprovidermessages.h"
    34 #include "booteventprovidermessages.h"
    33 #include "mmceventprovidermessages.h"
    35 #include "mmceventprovidermessages.h"
       
    36 #include "preinstallerstartermessages.h"
    34 
    37 
    35 #include "preinstallerstarter.h"
    38 #include "preinstallerstarter.h"
    36 
    39 
    37 /**
    40 /**
    38  * Return pointer to ExtensionPluginInterface implementation for this
    41  * Return pointer to ExtensionPluginInterface implementation for this
    50 
    53 
    51 using java::fileutils::driveInfo;
    54 using java::fileutils::driveInfo;
    52 using java::fileutils::DriveListenerInterface;
    55 using java::fileutils::DriveListenerInterface;
    53 
    56 
    54 /**
    57 /**
    55  * Empty contructor
    58  * Initialize member varaibles in constructor
    56  */
    59  */
    57 PreinstallerStarter::PreinstallerStarter() : mCore(0)
    60 PreinstallerStarter::PreinstallerStarter() :
    58 {
    61     CActive(EPriorityStandard), mCore(0), mPreinstaller(0)
    59     JELOG2(EJavaCaptain);
    62 {
    60 }
    63 }
    61 
    64 
    62 /**
    65 /**
    63  * Empty destructor
    66  * Destructor
    64  */
    67  */
    65 PreinstallerStarter::~PreinstallerStarter()
    68 PreinstallerStarter::~PreinstallerStarter()
    66 {
    69 {
    67     JELOG2(EJavaCaptain);
    70     DoCancel();
    68 }
    71 }
    69 
    72 
    70 /**
    73 /**
    71  * Implement PluginInterface method
    74  * Implement PluginInterface method
    72  */
    75  */
    73 void PreinstallerStarter::startPlugin(CoreInterface* core)
    76 void PreinstallerStarter::startPlugin(CoreInterface* core)
    74 {
    77 {
    75     JELOG2(EJavaCaptain);
       
    76     mCore = core;
    78     mCore = core;
       
    79     CActiveScheduler::Add(this);
    77 }
    80 }
    78 
    81 
    79 /**
    82 /**
    80  * Implement PluginInterface method
    83  * Implement PluginInterface method
    81  */
    84  */
    82 void PreinstallerStarter::stopPlugin()
    85 void PreinstallerStarter::stopPlugin()
    83 {
    86 {
    84     JELOG2(EJavaCaptain);
       
    85     mCore = 0;
    87     mCore = 0;
    86 }
    88 }
    87 
    89 
    88 /**
    90 /**
    89  * Implement ExtensionPluginInterface method
    91  * Implement ExtensionPluginInterface method
    90  */
    92  */
    91 EventConsumerInterface* PreinstallerStarter::getEventConsumer()
    93 EventConsumerInterface* PreinstallerStarter::getEventConsumer()
    92 {
    94 {
    93     JELOG2(EJavaCaptain);
       
    94     return this;
    95     return this;
    95 }
    96 }
    96 
    97 
    97 /**
    98 /**
    98  * Handle Java Captain events sent by Boot event provider or
    99  * Handle Java Captain events sent by Boot event provider or
   104  * Implement EventConsumerInterface method
   105  * Implement EventConsumerInterface method
   105  */
   106  */
   106 void PreinstallerStarter::event(const std::string& eventProvider,
   107 void PreinstallerStarter::event(const std::string& eventProvider,
   107                                 java::comms::CommsMessage& aMsg)
   108                                 java::comms::CommsMessage& aMsg)
   108 {
   109 {
   109     JELOG2(EJavaCaptain);
       
   110     if (eventProvider == BOOT_EVENT_PROVIDER)
   110     if (eventProvider == BOOT_EVENT_PROVIDER)
   111     {
   111     {
   112         int bootType = NORMAL_BOOT_C;
   112         int bootType = NORMAL_BOOT_C;
   113         getBootMessageParams(aMsg, bootType);
   113         getBootMessageParams(aMsg, bootType);
   114         LOG1(
   114         LOG1(
   131         break;
   131         break;
   132 
   132 
   133         case FIRST_DEVICE_BOOT_C:
   133         case FIRST_DEVICE_BOOT_C:
   134         case NORMAL_BOOT_C:
   134         case NORMAL_BOOT_C:
   135         {
   135         {
       
   136 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   136             registerMidletApplicationTypeHandler();
   137             registerMidletApplicationTypeHandler();
       
   138 #endif
   137 
   139 
   138             // Start preinstaller normally (without 'iad' option).
   140             // Start preinstaller normally (without 'iad' option).
   139             startPreinstaller(EFalse);
   141             startPreinstaller(EFalse);
   140         }
   142         }
   141         break;
   143         break;
   181  *
   183  *
   182  * @param aIadBoot when true, starts preinstaller with 'iad' parameter
   184  * @param aIadBoot when true, starts preinstaller with 'iad' parameter
   183  */
   185  */
   184 void PreinstallerStarter::startPreinstaller(TBool aIadBoot)
   186 void PreinstallerStarter::startPreinstaller(TBool aIadBoot)
   185 {
   187 {
   186     JELOG2(EJavaCaptain);
       
   187 
       
   188     // Check that the device has enough free memory (800kB) to start preinstaller process
   188     // Check that the device has enough free memory (800kB) to start preinstaller process
   189     // and (if needed) also java installer
   189     // and (if needed) also java installer
   190     TInt freeMemory = 0;
   190     TInt freeMemory = 0;
   191     TInt err = HAL::Get(HALData::EMemoryRAMFree, freeMemory);
   191     TInt err = HAL::Get(HALData::EMemoryRAMFree, freeMemory);
   192     if (KErrNone == err)
   192     if (KErrNone == err)
   274         {
   274         {
   275             commandLine.Append(_L(" iad"));
   275             commandLine.Append(_L(" iad"));
   276         }
   276         }
   277 
   277 
   278         // start preinstaller
   278         // start preinstaller
   279         RProcess preinstaller;
   279         mPreinstaller = new RProcess();
   280         TBuf<64> preinstallerProcess;  // Actual len of the process name is 9
   280         TBuf<64> preinstallerProcess;  // Actual len of the process name is 9
   281         len = strlen(java::runtime::JAVA_PROCESS);
   281         len = strlen(java::runtime::JAVA_PROCESS);
   282         TPtr8 ptr8Process((TUint8 *)java::runtime::JAVA_PROCESS, len, len);
   282         TPtr8 ptr8Process((TUint8 *)java::runtime::JAVA_PROCESS, len, len);
   283         preinstallerProcess.Copy(ptr8Process);
   283         preinstallerProcess.Copy(ptr8Process);
   284         TInt err = preinstaller.Create(preinstallerProcess, commandLine);
   284         TInt err = mPreinstaller->Create(preinstallerProcess, commandLine);
   285         if (KErrNone == err)
   285         if (KErrNone == err)
   286         {
   286         {
   287             // process has been created, allow it to run
   287             // Process has been created.
   288             preinstaller.Resume();
   288 
   289             preinstaller.Close();
   289             // This active object will be activated when preinstaller process exits
       
   290             mPreinstaller->Logon(iStatus);
       
   291 
       
   292             // Allow the process to run
       
   293             mPreinstaller->Resume();
   290             if (aIadBoot)
   294             if (aIadBoot)
   291             {
   295             {
   292                 LOG(
   296                 LOG(
   293                     EJavaCaptain,
   297                     EJavaCaptain,
   294                     EInfo,
   298                     EInfo,
   296             }
   300             }
   297             else
   301             else
   298             {
   302             {
   299                 LOG(EJavaCaptain, EInfo, "PreinstallerStarter: started preinstaller");
   303                 LOG(EJavaCaptain, EInfo, "PreinstallerStarter: started preinstaller");
   300             }
   304             }
       
   305 
       
   306             SetActive();
   301         }
   307         }
   302         else
   308         else
   303         {
   309         {
       
   310             delete mPreinstaller;
       
   311             mPreinstaller = 0;
       
   312 
   304             ELOG1(
   313             ELOG1(
   305                 EJavaCaptain,
   314                 EJavaCaptain,
   306                 "PreinstallerStarter: starting preinstaller failed, err %d",
   315                 "PreinstallerStarter: starting preinstaller failed, err %d",
   307                 err);
   316                 err);
   308         }
   317         }
   311 
   320 
   312 /**
   321 /**
   313  * Register 'javalauncher.exe' as the midlet application type handler
   322  * Register 'javalauncher.exe' as the midlet application type handler
   314  * in AppArc. If necessary unregister old handler first.
   323  * in AppArc. If necessary unregister old handler first.
   315  */
   324  */
       
   325 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   316 void PreinstallerStarter::registerMidletApplicationTypeHandler()
   326 void PreinstallerStarter::registerMidletApplicationTypeHandler()
   317 {
   327 {
   318     _LIT(KMidpAppArcPlugin, "javalauncher.exe");
   328     _LIT(KMidpAppArcPlugin, "javalauncher.exe");
   319 
   329 
   320     RApaLsSession appLstSession;
   330     RApaLsSession appLstSession;
   372               "PreinstallerStarter: registerMidletApplicationTypeHandler: "
   382               "PreinstallerStarter: registerMidletApplicationTypeHandler: "
   373               "Connecting to AppArc failed with error %d",
   383               "Connecting to AppArc failed with error %d",
   374               err);
   384               err);
   375     }
   385     }
   376 }
   386 }
       
   387 #endif
       
   388 
       
   389 void PreinstallerStarter::RunL()
       
   390 {
       
   391     LOG(EJavaCaptain, EInfo, "PreinstallerStarter::RunL started");
       
   392 
       
   393     // Send event to AutoStarter plugin, done only once
       
   394     CommsMessage eventMsg;
       
   395     setPreinstallerExitedMessageParams(eventMsg, iStatus.Int());
       
   396     mCore->getEventDispatcher()->event(PREINSTALLER_EVENT_PROVIDER, eventMsg);
       
   397 
       
   398     // process handle is no longer needed
       
   399     mPreinstaller->Close();
       
   400     delete mPreinstaller;
       
   401     mPreinstaller = 0;
       
   402 }
       
   403 
       
   404 
       
   405 void PreinstallerStarter::DoCancel()
       
   406 {
       
   407     if (mPreinstaller)
       
   408     {
       
   409         mPreinstaller->LogonCancel(iStatus);
       
   410         // Because exit notification request has been canceled,
       
   411         // there is no reason to keep the process handle open.
       
   412         mPreinstaller->Close();
       
   413         delete mPreinstaller;
       
   414         mPreinstaller = 0;
       
   415     }
       
   416 }
       
   417 
   377 
   418 
   378 } // namespace captain
   419 } // namespace captain
   379 } // namespace java
   420 } // namespace java