javamanager/javainstaller/javasifplugin/src/javasifplugin.cpp
branchRCL_3
changeset 83 26b2b12093af
parent 60 6c158198356e
equal deleted inserted replaced
77:7cee158cb8cd 83:26b2b12093af
     1 /*
     1 /*
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009 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".
    18 */
    18 */
    19 
    19 
    20 
    20 
    21 #include <apgcli.h>
    21 #include <apgcli.h>
    22 #include <apmstd.h>
    22 #include <apmstd.h>
       
    23 #include <e32cmn.h>
       
    24 #include <e32property.h>
    23 #include <charconv.h>
    25 #include <charconv.h>
    24 #include <data_caging_path_literals.hrh>
    26 #include <data_caging_path_literals.hrh>
    25 #include <e32cmn.h>
       
    26 #include <e32property.h>
       
    27 #include <string.h>
       
    28 #include <usif/usiferror.h>
       
    29 
    27 
    30 #include "comms.h"
    28 #include "comms.h"
       
    29 #include "commsmessage.h"
    31 #include "commsclientendpoint.h"
    30 #include "commsclientendpoint.h"
    32 #include "commsmessage.h"
    31 #include "javasifplugin.h"
    33 #include "javacommonutils.h"
    32 #include "javauids.h"
       
    33 #include "logger.h"
    34 #include "javaoslayer.h"
    34 #include "javaoslayer.h"
    35 #include "javaprocessconstants.h"
    35 #include "javaprocessconstants.h"
    36 #include "javasymbianoslayer.h"
    36 #include "javasymbianoslayer.h"
    37 #include "javauids.h"
       
    38 #include "logger.h"
       
    39 #include "resultsserver.h"
       
    40 #include "runtimeexception.h"
    37 #include "runtimeexception.h"
    41 
    38 
    42 #include "javasifplugin.h"
    39 
    43 
    40 using namespace Java::Installer;
    44 
       
    45 using namespace java::installer;
       
    46 using namespace java::util;
    41 using namespace java::util;
    47 using namespace java::comms;
    42 using namespace java::comms;
    48 
    43 
    49 _LIT(KPrivateDataCage, "\\private\\");
    44 _LIT(KPrivateDataCage, "\\private\\");
    50 _LIT(KInboxDataCage, "\\private\\1000484b\\");
    45 _LIT(KInboxDataCage, "\\private\\1000484b\\");
    51 _LIT(KJavaInstallerProcess, "Installer*");
       
    52 _LIT(KJavaInstallCopierProcess, "javainstallcopier.exe");
       
    53 _LIT(KJavaInstallerDataCage, "\\private\\102033e6\\");
    46 _LIT(KJavaInstallerDataCage, "\\private\\102033e6\\");
    54 _LIT(KJavaInstallerTmp, "\\private\\102033E6\\installer\\tmp\\");
    47 _LIT(KJavaInstallerTmp, "\\private\\102033E6\\installer\\tmp\\");
    55 _LIT(KAnyExtension, ".*");
    48 _LIT(KAnyExtension, ".*");
    56 _LIT(KComponentInfo, " componentinfo");
    49 
    57 _LIT(KCommsResult, " -commsresult=");
       
    58 _LIT(KJad, " -jad=");
       
    59 _LIT(KJar, " -jar=");
       
    60 _LIT(KDoubleQuote, "\"");
       
    61 _LIT(KInstall, " install");
       
    62 _LIT(KSilent, " -silent");
       
    63 _LIT(KUninstall, " uninstall");
       
    64 _LIT(KCid, " -cid=");
       
    65 _LIT(KDrive, " -drive=");
       
    66 _LIT(KYes, "yes");
       
    67 _LIT(KNo, "no");
       
    68 _LIT(KOcsp, " -ocsp=");
       
    69 _LIT(KIgnoreOcspWarnings, " -ignore_ocsp_warnings=");
       
    70 _LIT(KUpgrade, " -upgrade=");
       
    71 _LIT(KUpgradeData, " -upgrade_data=");
       
    72 _LIT(KUntrusted, " -untrusted=");
       
    73 _LIT(KOverwrite, " -overwrite=");
       
    74 _LIT(KDownload, " -download=");
       
    75 _LIT(KIap, " -iap=");
       
    76 _LIT(KSnap, " -snap=");
       
    77 _LIT(KForceCancel, " -forcecancel");
       
    78 _LIT(KBase64, " -base64=");
       
    79 _LIT(KUsername, " -username=");
       
    80 _LIT(KPassword, " -password=");
       
    81 _LIT(KSourceUrl, " -sourceurl=");
       
    82 _LIT(KCharSet, " -charset=");
       
    83 
       
    84 _LIT(KJadMimeType, "text/vnd.sun.j2me.app-descriptor");
       
    85 _LIT8(K8JadMimeType, "text/vnd.sun.j2me.app-descriptor");
       
    86 
       
    87 // Long Java Installer command lines contain max 2 path names (512 chars max) and
       
    88 // some options -> 1536 is long enough buffer
       
    89 const TInt KLongCmdLineLen = 1536;
       
    90 
       
    91 // When starting Java Installer for uninstallation the command line is much shorter
       
    92 const TInt KShortCmdLineLen = 256;
       
    93 
       
    94 // Java Installer is executed with same Uid as Java Runtime
       
    95 _LIT_SECURE_ID(KJavaInstallerSecureID, KJavaMidpSecureId);
       
    96 
       
    97 /**
       
    98  * This function is called to hide the 'Preparing Installation' dialog.
       
    99  */
       
   100 LOCAL_C TInt HidePrepInstDialog(TAny* aPlugin)
       
   101 {
       
   102     CJavaSifPlugin *pPlugin = (CJavaSifPlugin *)aPlugin;
       
   103     if (NULL != pPlugin)
       
   104     {
       
   105         TRAP_IGNORE(pPlugin->HidePrepInstDialogL());
       
   106     }
       
   107     return KErrNone;
       
   108 }
       
   109 
    50 
   110 // ============================ MEMBER FUNCTIONS ===============================
    51 // ============================ MEMBER FUNCTIONS ===============================
   111 
    52 
   112 CJavaSifPlugin* CJavaSifPlugin::NewL()
    53 CJavaSifPlugin* CJavaSifPlugin::NewL()
   113 {
    54 {
   118     return self;
    59     return self;
   119 }
    60 }
   120 
    61 
   121 CJavaSifPlugin::~CJavaSifPlugin()
    62 CJavaSifPlugin::~CJavaSifPlugin()
   122 {
    63 {
   123     mRFs.Close();
    64     iRFs.Close();
   124 
    65 
   125     TInt nHandles = mHandlesToClose.Count();
    66     TInt nHandles = iHandlesToClose.Count();
   126     while (nHandles > 0)
    67     while (nHandles > 0)
   127     {
    68     {
   128         nHandles--;
    69         nHandles--;
   129         mHandlesToClose[nHandles].Close();
    70         iHandlesToClose[nHandles].Close();
   130     }
    71     }
   131     mHandlesToClose.Reset();
    72     iHandlesToClose.Reset();
   132 
    73 
   133     delete mResultsServer;
    74     delete iResultsServer;
   134     mResultsServer = NULL;
    75     iResultsServer = NULL;
   135 
    76 
   136     delete mDummyResults;
    77     delete iDummyResults;
   137     mDummyResults = NULL;
    78     iDummyResults = NULL;
   138 
    79 
   139     delete mDummyInfo;
    80     delete iDummyInfo;
   140     mDummyInfo = NULL;
    81     iDummyInfo = NULL;
   141 
       
   142     delete mPrepInstDialog;
       
   143     mPrepInstDialog = NULL;
       
   144 
       
   145     if (mWaitToHideDialog)
       
   146     {
       
   147         delete mWaitToHideDialog;
       
   148         mWaitToHideDialog = NULL;
       
   149     }
       
   150 }
    82 }
   151 
    83 
   152 CJavaSifPlugin::CJavaSifPlugin()
    84 CJavaSifPlugin::CJavaSifPlugin()
   153 {
    85 {
   154 }
    86 }
   155 
    87 
   156 void CJavaSifPlugin::ConstructL()
    88 void CJavaSifPlugin::ConstructL()
   157 {
    89 {
   158     User::LeaveIfError(mRFs.Connect());
    90     User::LeaveIfError(iRFs.Connect());
   159     User::LeaveIfError(mRFs.ShareProtected());
    91     User::LeaveIfError(iRFs.ShareProtected());
   160     mResultsServer = NULL;
    92     iResultsServer = NULL;
   161     mDummyResults = COpaqueNamedParams::NewL(); // codescanner::forgottoputptroncleanupstack
    93     iDummyResults = COpaqueNamedParams::NewL();
   162     mDummyInfo = CComponentInfo::NewL();
    94     iDummyInfo = CComponentInfo::NewL();
   163     mWaitToHideDialog = NULL;
       
   164 }
    95 }
   165 
    96 
   166 void CJavaSifPlugin::GetComponentInfo(
    97 void CJavaSifPlugin::GetComponentInfo(
   167     const TDesC& aFileName,
    98     const TDesC& aFileName,
   168     const TSecurityContext& aSecurityContext,
    99     const TSecurityContext& aSecurityContext,
   169     CComponentInfo& aComponentInfo,
   100     CComponentInfo& aComponentInfo,
   170     TRequestStatus& aStatus)
   101     TRequestStatus& aStatus)
   171 {
   102 {
   172     RFile fileHandle;
   103     RFile fileHandle;
   173     TInt err = fileHandle.Open(mRFs, aFileName, EFileShareReadersOnly | EFileRead);
   104     TInt err = fileHandle.Open(iRFs, aFileName, EFileShareReadersOnly | EFileRead);
   174     if (KErrNone != err)
   105     if (KErrNone != err)
   175     {
   106     {
   176         ELOG1(EJavaInstaller,
   107         ELOG1(EJavaInstaller,
   177               "CJavaSifPlugin::GetComponentInfo Opening file for reading failed with error %d",
   108               "CJavaSifPlugin::GetComponentInfo Opening file for reading failed with error %d",
   178               err);
   109               err);
   189     RFile& aFileHandle,
   120     RFile& aFileHandle,
   190     const TSecurityContext& /* aSecurityContext */,
   121     const TSecurityContext& /* aSecurityContext */,
   191     CComponentInfo& aComponentInfo,
   122     CComponentInfo& aComponentInfo,
   192     TRequestStatus& aStatus)
   123     TRequestStatus& aStatus)
   193 {
   124 {
   194     if (ExitIfJavaInstallerRunning(*mDummyResults, aStatus))
       
   195     {
       
   196         return;
       
   197     }
       
   198 
       
   199     RProcess rJavaInstaller;
   125     RProcess rJavaInstaller;
   200     TFileName fileName;
   126     TFileName fileName;
   201     HBufC* pBufCommandLine = NULL;
   127     TBuf<1536> commandLine;
   202     TRAPD(err, pBufCommandLine = HBufC::NewL(KLongCmdLineLen))
       
   203     if (KErrNone != err)
       
   204     {
       
   205         TRequestStatus *statusPtr(&aStatus);
       
   206         User::RequestComplete(statusPtr, err);
       
   207         return;
       
   208     }
       
   209     std::auto_ptr<HBufC> bufCommandLine(pBufCommandLine);
       
   210     TPtr commandLine = pBufCommandLine->Des();
       
   211 
   128 
   212     // Build command line used to pass all necessary info to Java Installer
   129     // Build command line used to pass all necessary info to Java Installer
   213     std::auto_ptr<HBufC> installerStarterDll(
   130     std::auto_ptr<HBufC> installerStarterDll(
   214         stringToDes(java::runtime::JAVA_INSTALLER_STARTER_DLL));
   131         stringToDes(java::runtime::JAVA_INSTALLER_STARTER_DLL));
   215     commandLine = installerStarterDll->Des();
   132     commandLine = installerStarterDll->Des();
   216     commandLine.Append(KComponentInfo);
   133     commandLine.Append(_L(" componentinfo"));
   217 
   134 
   218     // Ask Java Installer to send component info back
   135     // Ask Java Installer to send component info back
   219     // as Comms message. 11000 is IPC_ADDRESS_JAVA_SIF_PLUGIN_C Comms endpoint
   136     // as Comms message. 11000 is IPC_ADDRESS_JAVA_SIF_PLUGIN_C Comms endpoint
   220     // that our ResultsServer will listen to.
   137     // that our ResultsServer will listen to.
   221     commandLine.Append(KCommsResult);
   138     commandLine.Append(_L(" -commsresult=11000"));
   222     commandLine.AppendNum(IPC_ADDRESS_JAVA_SIF_PLUGIN_C);
   139 
   223 
   140     TInt err = aFileHandle.FullName(fileName);
   224     err = aFileHandle.FullName(fileName);
       
   225 
   141 
   226     // Java Installer does not have AllFiles capability.
   142     // Java Installer does not have AllFiles capability.
   227     // So if the .jad/.jar file is in the private data cage of
   143     // So if the .jad/.jar file is in the private data cage of
   228     // Remove Application Management system, it must be copied
   144     // Remove Application Management system, it must be copied
   229     // to the private data cage of Java Installer in this
   145     // to the private data cage of Java Installer in this
   236         User::RequestComplete(statusPtr, err);
   152         User::RequestComplete(statusPtr, err);
   237         return;
   153         return;
   238     }
   154     }
   239 
   155 
   240     // Check whether the file is .jad or .jar
   156     // Check whether the file is .jad or .jar
   241     TBool isJad;
   157     RApaLsSession apaSession;
   242     err = IsJadFile(aFileHandle, isJad);
   158     err = apaSession.Connect();
   243     if (KErrNone != err)
   159     if (KErrNone != err)
   244     {
   160     {
   245         TRequestStatus *statusPtr(&aStatus);
   161         ELOG1(EJavaInstaller,
   246         User::RequestComplete(statusPtr, err);
   162               "CJavaSifPlugin::GetComponentInfo RApaLsSession Connect error %d", err);
   247         return;
   163         TRequestStatus *statusPtr(&aStatus);
       
   164         User::RequestComplete(statusPtr, err);
       
   165         return;
       
   166     }
       
   167     TDataType jadFileMimeType(_L8("text/vnd.sun.j2me.app-descriptor"));
       
   168     TBool isJad = EFalse;
       
   169     err = apaSession.RecognizeSpecificData(aFileHandle, jadFileMimeType, isJad);
       
   170     apaSession.Close();
       
   171     if (KErrNone != err)
       
   172     {
       
   173         // Just log the error
       
   174         ELOG1(EJavaInstaller,
       
   175               "CJavaSifPlugin::GetComponentInfo RApaLsSession RecognizeSpecificData error %d",
       
   176               err);
   248     }
   177     }
   249     if (isJad)
   178     if (isJad)
   250     {
   179     {
   251         // Installation should be started from JAD file
   180         // Installation should be started from JAD file
   252         commandLine.Append(KJad);
   181         commandLine.Append(_L(" -jad="));
   253     }
   182     }
   254     else
   183     else
   255     {
   184     {
   256         // from JAR file
   185         // from JAR file
   257         commandLine.Append(KJar);
   186         commandLine.Append(_L(" -jar="));
   258     }
   187     }
   259 
       
   260     // Filename parameter must be surrounded in double quotes to
   188     // Filename parameter must be surrounded in double quotes to
   261     // ensure that spaces in filename are passed correctly.
   189     // ensure that spaces in filename are passed correctly.
   262     commandLine.Append(KDoubleQuote);
   190     commandLine.Append(_L("\""));
   263     commandLine.Append(fileName);
   191     commandLine.Append(fileName);
   264     commandLine.Append(KDoubleQuote);
   192     commandLine.Append(_L("\""));
   265 
   193 
   266     // Start JavaInstaller
   194     // Start JavaInstaller
   267     std::auto_ptr<HBufC> installerProcess(
   195     std::auto_ptr<HBufC> installerProcess(
   268         stringToDes(java::runtime::JAVA_PROCESS));
   196         stringToDes(java::runtime::JAVA_PROCESS));
   269     err = rJavaInstaller.Create(installerProcess->Des(), commandLine);
   197     err = rJavaInstaller.Create(installerProcess->Des(), commandLine);
   270     if (KErrNone == err)
   198     if (KErrNone == err)
   271     {
   199     {
   272         err = StartResultsServer(*mDummyResults, aComponentInfo);
   200         // Destroy old Comms server if it exists
       
   201         delete iResultsServer;
       
   202         iResultsServer = NULL;
       
   203         // Start new Comms server that receives component info and sets it to
       
   204         // to aComponentInfo.
       
   205         iResultsServer = new ResultsServer(*iDummyResults, aComponentInfo);
       
   206         if (NULL == iResultsServer)
       
   207         {
       
   208             err = KErrNoMemory;
       
   209         }
       
   210         else
       
   211         {
       
   212             // Start the server
       
   213             err = iResultsServer->start();
       
   214         }
   273         if (KErrNone != err)
   215         if (KErrNone != err)
   274         {
   216         {
   275             // server cannot be started
   217             // server cannot be started
   276             rJavaInstaller.Close();
   218             rJavaInstaller.Close();
   277             ELOG1(EJavaInstaller,
   219             ELOG1(EJavaInstaller,
   297 
   239 
   298     rJavaInstaller.Resume();
   240     rJavaInstaller.Resume();
   299 
   241 
   300     // Do NOT close rJavaInstaller now -> the caller gets notification when the
   242     // Do NOT close rJavaInstaller now -> the caller gets notification when the
   301     // process actually closes.
   243     // process actually closes.
   302     err = mHandlesToClose.Append(rJavaInstaller);
   244     iHandlesToClose.Append(rJavaInstaller);
   303     if ( err )
       
   304     {
       
   305         rJavaInstaller.Close();
       
   306         ELOG1(EJavaInstaller, "CJavaSifPlugin::GetComponentInfo  mHandles"
       
   307               "ToClose.Append failed with error %d", err);
       
   308         TRequestStatus *statusPtr(&aStatus);
       
   309         User::RequestComplete(statusPtr, err);
       
   310         return;
       
   311     }
       
   312 }
   245 }
   313 
   246 
   314 void CJavaSifPlugin::Install(
   247 void CJavaSifPlugin::Install(
   315     const TDesC& aFileName,
   248     const TDesC& aFileName,
   316     const TSecurityContext& aSecurityContext,
   249     const TSecurityContext& aSecurityContext,
   317     const COpaqueNamedParams& aArguments,
   250     const COpaqueNamedParams& aArguments,
   318     COpaqueNamedParams& aResults,
   251     COpaqueNamedParams& aResults,
   319     TRequestStatus& aStatus)
   252     TRequestStatus& aStatus)
   320 {
   253 {
   321     RFile fileHandle;
   254     RFile fileHandle;
   322     TInt err = fileHandle.Open(mRFs, aFileName, EFileShareReadersOnly | EFileRead);
   255     TInt err = fileHandle.Open(iRFs, aFileName, EFileShareReadersOnly | EFileRead);
   323     if (KErrNone != err)
   256     if (KErrNone != err)
   324     {
   257     {
   325         ELOG1(EJavaInstaller,
   258         ELOG1(EJavaInstaller,
   326               "CJavaSifPlugin::Install Opening file for reading failed with error %d", err);
   259               "CJavaSifPlugin::Install Opening file for reading failed with error %d", err);
   327         TRAP_IGNORE(aResults.AddIntL(KSifOutParam_ErrCategory, EUnexpectedError));
       
   328         TRequestStatus *statusPtr(&aStatus);
   260         TRequestStatus *statusPtr(&aStatus);
   329         User::RequestComplete(statusPtr, err);
   261         User::RequestComplete(statusPtr, err);
   330         return;
   262         return;
   331     }
   263     }
   332 
   264 
   339     const TSecurityContext& aSecurityContext,
   271     const TSecurityContext& aSecurityContext,
   340     const COpaqueNamedParams& aArguments,
   272     const COpaqueNamedParams& aArguments,
   341     COpaqueNamedParams& aResults,
   273     COpaqueNamedParams& aResults,
   342     TRequestStatus& aStatus)
   274     TRequestStatus& aStatus)
   343 {
   275 {
   344     if (ExitIfJavaInstallerRunning(aResults, aStatus))
   276     RProcess rJavaInstaller;
   345     {
   277     TFileName fileName;
   346         return;
   278     // Max two path names and some options -> 1536 is enough
   347     }
   279     TBuf<1536> commandLine;
   348 
       
   349     // Create buffer for Java Installer command line
       
   350     HBufC* pBufCommandLine = NULL;
       
   351     TRAPD(err, pBufCommandLine = HBufC::NewL(KLongCmdLineLen))
       
   352     if (KErrNone != err)
       
   353     {
       
   354         TRAP_IGNORE(aResults.AddIntL(KSifOutParam_ErrCategory, ELowMemory));
       
   355         TRequestStatus *statusPtr(&aStatus);
       
   356         User::RequestComplete(statusPtr, err);
       
   357         return;
       
   358     }
       
   359     std::auto_ptr<HBufC> bufCommandLine(pBufCommandLine);
       
   360     TPtr commandLine = pBufCommandLine->Des();
       
   361 
   280 
   362     // Build command line used to pass all necessary info to Java Installer
   281     // Build command line used to pass all necessary info to Java Installer
   363     std::auto_ptr<HBufC> installerStarterDll(
   282     std::auto_ptr<HBufC> installerStarterDll(
   364         stringToDes(java::runtime::JAVA_INSTALLER_STARTER_DLL));
   283         stringToDes(java::runtime::JAVA_INSTALLER_STARTER_DLL));
   365     commandLine = installerStarterDll->Des();
   284     commandLine = installerStarterDll->Des();
   366     commandLine.Append(KInstall);
   285     commandLine.Append(_L(" install"));
   367 
   286 
   368     // Check whether this is silent installation
   287     // Check whether this is silent installation
   369     TInt silentInstall = 0;
   288     TInt silentInstall = 0;
   370     TRAP_IGNORE(aArguments.GetIntByNameL(KSifInParam_InstallSilently, silentInstall));
   289     TRAP_IGNORE(aArguments.GetIntByNameL(KSifInParam_InstallSilently, silentInstall));
   371     if (silentInstall)
   290     if (silentInstall)
   373         // Silent installation requires TrustedUI capability
   292         // Silent installation requires TrustedUI capability
   374         if (!aSecurityContext.HasCapability(ECapabilityTrustedUI))
   293         if (!aSecurityContext.HasCapability(ECapabilityTrustedUI))
   375         {
   294         {
   376             ELOG(EJavaInstaller,
   295             ELOG(EJavaInstaller,
   377                  "CJavaSifPlugin::Install The caller did not have TrustedUI capability");
   296                  "CJavaSifPlugin::Install The caller did not have TrustedUI capability");
   378             TRAP_IGNORE(aResults.AddIntL(KSifOutParam_ErrCategory, ESecurityError));
       
   379             TRequestStatus *statusPtr(&aStatus);
   297             TRequestStatus *statusPtr(&aStatus);
   380             User::RequestComplete(statusPtr, KErrPermissionDenied);
   298             User::RequestComplete(statusPtr, KErrPermissionDenied);
   381             return;
   299             return;
   382         }
   300         }
   383 
   301 
   384         commandLine.Append(KSilent);
   302         commandLine.Append(_L(" -silent"));
   385     }
   303     }
   386     else
   304 
   387     {
   305     TBool paramFound = EFalse;
   388         // Uncomment this to enable 'preparing installation' dialog.
   306     TInt  intValue = 0;
   389         //TRAP(err, CreatePrepInstDialogL());
   307     TDesC desValue = KNullDesC;
   390         //if (KErrNone != err)
   308 
   391         //{
   309     // KSifInParam_Drive -> -drive=install_target_drive (A, B, C, ..., Z)
   392         //    WLOG1(EJavaInstaller,
   310     TRAP_IGNORE(paramFound = aArguments.GetIntByNameL(KSifInParam_Drive, intValue));
   393         //          "CJavaSifPlugin::Install Creating preparing installation dialog failed, err=%d",
   311     if (paramFound)
   394         //          err);
   312     {
   395         //}
   313         // Value 0 is 'A:' drive and  value 25 is 'Z:' drive
   396     }
   314         if ((intValue > -1) && (intValue < 26))
   397 
   315         {
   398     BuildInstallCommandLine(commandLine, aArguments);
   316             commandLine.Append(_L(" -drive="));
       
   317             TChar drive('A');
       
   318             drive += intValue;
       
   319             commandLine.Append(drive);
       
   320         }
       
   321         else
       
   322         {
       
   323             WLOG1(EJavaInstaller,
       
   324                 "CJavaSifPlugin::Install Ignoring illegal KSifInParam_Drive param (value %d)",
       
   325                 intValue);
       
   326         }
       
   327     }
       
   328 
       
   329     // KSifInParam_PerformOCSP Yes/No/AskUser -> -ocsp=yes|no
       
   330     TRAP_IGNORE(paramFound = aArguments.GetIntByNameL(KSifInParam_PerformOCSP, intValue));
       
   331     if (paramFound)
       
   332     {
       
   333         if (intValue == 0) // Yes
       
   334         {
       
   335             commandLine.Append(_L(" -ocsp=yes"));
       
   336         }
       
   337         else if (intValue == 1) // No
       
   338         {
       
   339             commandLine.Append(_L(" -ocsp=no"));
       
   340         }
       
   341         // AskUser is not supported
       
   342     }
       
   343 
       
   344     // KSifInParam_IgnoreOCSPWarnings Yes/No/AskUser -> -ignore_ocsp_warnings=yes|no
       
   345     TRAP_IGNORE(paramFound = aArguments.GetIntByNameL(KSifInParam_IgnoreOCSPWarnings, intValue));
       
   346     if (paramFound)
       
   347     {
       
   348         if (intValue == 0) // Yes
       
   349         {
       
   350             commandLine.Append(_L(" -ignore_ocsp_warnings=yes"));
       
   351         }
       
   352         else if (intValue == 1) // No
       
   353         {
       
   354             commandLine.Append(_L(" -ignore_ocsp_warnings=no"));
       
   355         }
       
   356         // AskUser is not supported
       
   357     }
       
   358 
       
   359     // KSifInParam_AllowUpgrade Yes/No/AskUser -> -upgrade=yes|no
       
   360     TRAP_IGNORE(paramFound = aArguments.GetIntByNameL(KSifInParam_AllowUpgrade, intValue));
       
   361     if (paramFound)
       
   362     {
       
   363         if (intValue == 0) // Yes
       
   364         {
       
   365             commandLine.Append(_L(" -upgrade=yes"));
       
   366         }
       
   367         else if (intValue == 1) // No
       
   368         {
       
   369             commandLine.Append(_L(" -upgrade=no"));
       
   370         }
       
   371         // AskUser is not supported
       
   372     }
       
   373 
       
   374     // KSifInParam_AllowUntrusted Yes/No/AskUser -> -untrusted=yes|no
       
   375     TRAP_IGNORE(paramFound = aArguments.GetIntByNameL(KSifInParam_AllowUntrusted, intValue));
       
   376     if (paramFound)
       
   377     {
       
   378         if (intValue == 0) // Yes
       
   379         {
       
   380             commandLine.Append(_L(" -untrusted=yes"));
       
   381         }
       
   382         else if (intValue == 1) // No
       
   383         {
       
   384             commandLine.Append(_L(" -untrusted=no"));
       
   385         }
       
   386         // AskUser is not supported
       
   387     }
       
   388 
       
   389     // KSifInParam_AllowOverwrite Yes/No/AskUser -> -overwrite=yes|no
       
   390     TRAP_IGNORE(paramFound = aArguments.GetIntByNameL(KSifInParam_AllowOverwrite, intValue));
       
   391     if (paramFound)
       
   392     {
       
   393         if (intValue == 0) // Yes
       
   394         {
       
   395             commandLine.Append(_L(" -overwrite=yes"));
       
   396         }
       
   397         else if (intValue == 1) // No
       
   398         {
       
   399             commandLine.Append(_L(" -overwrite=no"));
       
   400         }
       
   401         // AskUser is not supported
       
   402     }
       
   403 
       
   404     // KSifInParam_AllowDownload Yes/No/AskUser -> -download=yes|no
       
   405     TRAP_IGNORE(paramFound = aArguments.GetIntByNameL(KSifInParam_AllowDownload, intValue));
       
   406     if (paramFound)
       
   407     {
       
   408         if (intValue == 0) // Yes
       
   409         {
       
   410             commandLine.Append(_L(" -download=yes"));
       
   411         }
       
   412         else if (intValue == 1) // No
       
   413         {
       
   414             commandLine.Append(_L(" -download=no"));
       
   415         }
       
   416         // AskUser is not supported
       
   417     }
       
   418 
       
   419     // KSifInParam_UserName -> -username=download_username
       
   420     TRAP_IGNORE(desValue = aArguments.StringByNameL(KSifInParam_UserName));
       
   421     if (desValue.Length() > 0)
       
   422     {
       
   423         commandLine.Append(_L(" -username="));
       
   424         commandLine.Append(desValue);
       
   425     }
       
   426 
       
   427     // KSifInParam_Password -> -password=download_password
       
   428     TRAP_IGNORE(desValue = aArguments.StringByNameL(KSifInParam_Password));
       
   429     if (desValue.Length() > 0)
       
   430     {
       
   431         commandLine.Append(_L(" -password="));
       
   432         commandLine.Append(desValue);
       
   433     }
       
   434 
       
   435     // KSifInParam_SourceUrl -> -sourceurl=original (HTTP) URL of the JAD or JAR file
       
   436     TRAP_IGNORE(desValue = aArguments.StringByNameL(KSifInParam_SourceUrl));
       
   437     if (desValue.Length() > 0)
       
   438     {
       
   439         commandLine.Append(_L(" -sourceurl="));
       
   440         commandLine.Append(desValue);
       
   441     }
       
   442 
       
   443     // KSifInParam_IAP -> -iap=IAP_ID (internet access point id)
       
   444     TRAP_IGNORE(paramFound = aArguments.GetIntByNameL(KSifInParam_IAP, intValue));
       
   445     if (paramFound)
       
   446     {
       
   447         commandLine.Append(_L(" -iap="));
       
   448         commandLine.AppendNum(intValue);
       
   449     }
       
   450 
       
   451     // KSifInParam_Charset -> -charset=Internet-standard character set name
       
   452     TRAP_IGNORE(desValue = aArguments.StringByNameL(KSifInParam_Charset));
       
   453     if (desValue.Length() > 0)
       
   454     {
       
   455         commandLine.Append(_L(" -charset="));
       
   456         commandLine.Append(desValue);
       
   457     }
       
   458 
   399 
   459 
   400     // Ask Java Installer to send installation results back
   460     // Ask Java Installer to send installation results back
   401     // as Comms message. 11000 is IPC_ADDRESS_JAVA_SIF_PLUGIN_C Comms endpoint
   461     // as Comms message. 11000 is IPC_ADDRESS_JAVA_SIF_PLUGIN_C Comms endpoint
   402     // that our ResultsServer will listen to.
   462     // that our ResultsServer will listen to.
   403     commandLine.Append(KCommsResult);
   463     commandLine.Append(_L(" -commsresult=11000"));
   404     commandLine.AppendNum(IPC_ADDRESS_JAVA_SIF_PLUGIN_C);
   464 
   405 
   465     TInt err = aFileHandle.FullName(fileName);
   406     TFileName fileName;
       
   407     err = aFileHandle.FullName(fileName);
       
   408 
   466 
   409     // Java Installer does not have AllFiles capability.
   467     // Java Installer does not have AllFiles capability.
   410     // So if the .jad/.jar file is in the private data cage of
   468     // So if the .jad/.jar file is in the private data cage of
   411     // Remove Application Management system, it must be copied
   469     // Remove Application Management system, it must be copied
   412     // to the private data cage of Java Installer in this
   470     // to the private data cage of Java Installer in this
   413     // plugin which is executed in process which hopefully has
   471     // plugin which is executed in process which hopefully has
   414     // AllFiles capability.
   472     // AllFiles capability.
   415     TRAP(err, CopyFilesIfNeededL(fileName));
   473     TRAP(err, CopyFilesIfNeededL(fileName));
   416     if (KErrNone != err)
   474     if (KErrNone != err)
   417     {
   475     {
   418         TRAP_IGNORE(aResults.AddIntL(KSifOutParam_ErrCategory, EUnexpectedError));
       
   419         TRequestStatus *statusPtr(&aStatus);
   476         TRequestStatus *statusPtr(&aStatus);
   420         User::RequestComplete(statusPtr, err);
   477         User::RequestComplete(statusPtr, err);
   421         return;
   478         return;
   422     }
   479     }
   423 
   480 
   424     // Check whether the file is .jad or .jar
   481     // Check whether the file is .jad or .jar
       
   482     RApaLsSession apaSession;
       
   483     err = apaSession.Connect();
       
   484     if (KErrNone != err)
       
   485     {
       
   486         ELOG1(EJavaInstaller,
       
   487               "CJavaSifPlugin::Install RApaLsSession Connect error %d", err);
       
   488         TRequestStatus *statusPtr(&aStatus);
       
   489         User::RequestComplete(statusPtr, err);
       
   490         return;
       
   491     }
       
   492     TDataType jadFileMimeType(_L8("text/vnd.sun.j2me.app-descriptor"));
   425     TBool isJad = EFalse;
   493     TBool isJad = EFalse;
   426     err = IsJadFile(aFileHandle, aArguments, isJad);
   494     err = apaSession.RecognizeSpecificData(aFileHandle, jadFileMimeType, isJad);
       
   495     apaSession.Close();
   427     if (KErrNone != err)
   496     if (KErrNone != err)
   428     {
   497     {
   429         TRAP_IGNORE(aResults.AddIntL(KSifOutParam_ErrCategory, EUnexpectedError));
   498         ELOG1(EJavaInstaller,
   430         TRequestStatus *statusPtr(&aStatus);
   499               "CJavaSifPlugin::Install RApaLsSession RecognizeSpecificData error %d", err);
   431         User::RequestComplete(statusPtr, err);
       
   432         return;
       
   433     }
   500     }
   434     if (isJad)
   501     if (isJad)
   435     {
   502     {
   436         // Installation should be started from JAD file
   503         // Installation should be started from JAD file
   437         commandLine.Append(KJad);
   504         commandLine.Append(_L(" -jad="));
   438     }
   505     }
   439     else
   506     else
   440     {
   507     {
   441         // from JAR file
   508         // from JAR file
   442         commandLine.Append(KJar);
   509         commandLine.Append(_L(" -jar="));
   443     }
   510     }
   444     // Filename parameter must be surrounded in double quotes to
   511     // Filename parameter must be surrounded in double quotes to
   445     // ensure that spaces in filename are passed correctly.
   512     // ensure that spaces in filename are passed correctly.
   446     commandLine.Append(KDoubleQuote);
   513     commandLine.Append(_L("\""));
   447     commandLine.Append(fileName);
   514     commandLine.Append(fileName);
   448     commandLine.Append(KDoubleQuote);
   515     commandLine.Append(_L("\""));
   449 
   516 
   450     // Start JavaInstaller
   517     // Start JavaInstaller
   451     std::auto_ptr<HBufC> installerProcess(
   518     std::auto_ptr<HBufC> installerProcess(
   452         stringToDes(java::runtime::JAVA_PROCESS));
   519         stringToDes(java::runtime::JAVA_PROCESS));
   453     RProcess rJavaInstaller;
       
   454     err = rJavaInstaller.Create(installerProcess->Des(), commandLine);
   520     err = rJavaInstaller.Create(installerProcess->Des(), commandLine);
   455     if (KErrNone == err)
   521     if (KErrNone == err)
   456     {
   522     {
   457         err = StartResultsServer(aResults, *mDummyInfo);
   523         // Destroy old Comms server if it exists
       
   524         delete iResultsServer;
       
   525         iResultsServer = NULL;
       
   526         // Start new Comms server that receives component ids, sets them
       
   527         // to aResults.
       
   528         iResultsServer = new ResultsServer(aResults, *iDummyInfo);
       
   529         if (NULL == iResultsServer)
       
   530         {
       
   531             err = KErrNoMemory;
       
   532         }
       
   533         else
       
   534         {
       
   535             // Start the server
       
   536             err = iResultsServer->start();
       
   537         }
   458         if (KErrNone != err)
   538         if (KErrNone != err)
   459         {
   539         {
   460             // server cannot be started
   540             // server cannot be started
   461             rJavaInstaller.Close();
   541             rJavaInstaller.Close();
   462             ELOG1(EJavaInstaller,
   542             ELOG1(EJavaInstaller,
   463                   "CJavaSifPlugin::Install: Cannot start results server, err %d", err);
   543                   "CJavaSifPlugin::Install: Cannot start results server, err %d", err);
   464             TRAP_IGNORE(aResults.AddIntL(KSifOutParam_ErrCategory, EUnexpectedError));
       
   465             TRequestStatus *statusPtr(&aStatus);
   544             TRequestStatus *statusPtr(&aStatus);
   466             User::RequestComplete(statusPtr, err);
   545             User::RequestComplete(statusPtr, err);
   467             return;
   546             return;
   468         }
   547         }
   469 
   548 
   474     else
   553     else
   475     {
   554     {
   476         rJavaInstaller.Close();
   555         rJavaInstaller.Close();
   477         ELOG1(EJavaInstaller,
   556         ELOG1(EJavaInstaller,
   478               "CJavaSifPlugin::Install: starting JavaInstaller failed, err=%d", err);
   557               "CJavaSifPlugin::Install: starting JavaInstaller failed, err=%d", err);
   479         TRAP_IGNORE(aResults.AddIntL(KSifOutParam_ErrCategory, EUnexpectedError));
   558         TRequestStatus *statusPtr(&aStatus);
   480         TRequestStatus *statusPtr(&aStatus);
   559         User::RequestComplete(statusPtr, err);
   481         User::RequestComplete(statusPtr, err);
   560         return;
   482         return;
   561     }
   483     }
   562 
   484 
       
   485     if (!silentInstall)
       
   486     {
       
   487         TRAP(err, mWaitToHideDialog =
       
   488              CAsyncWaitCallBack::NewL(TCallBack(HidePrepInstDialog, this)));
       
   489         if (KErrNone == err)
       
   490         {
       
   491             // The active object will wait until JavaInstaller process calls Rendezvous.
       
   492             // If JavaInstaller specifies reason code EJavaInstaller, then
       
   493             // the active object will call callback function that will hide the
       
   494             // 'Preparing installation' dialog. If reason code is not EJavaInstaller,
       
   495             // the wait object will automatically wait for the next rendezvous.
       
   496             mWaitToHideDialog->Wait( rJavaInstaller, EJavaInstaller );
       
   497         }
       
   498         else
       
   499         {
       
   500             ELOG1(EJavaInstaller, "CJavaSifPlugin::Install: Creating "
       
   501                   "mWaitToHideDialog failed, err %d", err);
       
   502         }
       
   503     }
       
   504     rJavaInstaller.Resume();
   563     rJavaInstaller.Resume();
   505 
   564 
   506     // Do NOT close rJavaInstaller now -> the caller gets notification when the
   565     // Do NOT close rJavaInstaller now -> the caller gets notification when the
   507     // process actually closes.
   566     // process actually closes.
   508     err = mHandlesToClose.Append(rJavaInstaller);
   567     iHandlesToClose.Append(rJavaInstaller);
   509     if ( err )
       
   510     {
       
   511         rJavaInstaller.Close();
       
   512         ELOG1(EJavaInstaller, "CJavaSifPlugin::Install  mHandles"
       
   513               "ToClose.Append failed with error %d", err);
       
   514         TRAP_IGNORE(aResults.AddIntL(KSifOutParam_ErrCategory, ELowMemory));
       
   515         TRequestStatus *statusPtr(&aStatus);
       
   516         User::RequestComplete(statusPtr, err);
       
   517         return;
       
   518     }
       
   519 
       
   520 }
   568 }
   521 
   569 
   522 void CJavaSifPlugin::Uninstall(
   570 void CJavaSifPlugin::Uninstall(
   523     TComponentId aComponentId,
   571     TComponentId aComponentId,
   524     const TSecurityContext& aSecurityContext,
   572     const TSecurityContext& aSecurityContext,
   525     const COpaqueNamedParams& aArguments,
   573     const COpaqueNamedParams& aArguments,
   526     COpaqueNamedParams& aResults,
   574     COpaqueNamedParams& /* aResults */,
   527     TRequestStatus& aStatus)
   575     TRequestStatus& aStatus)
   528 {
   576 {
   529     if (ExitIfJavaInstallerRunning(aResults, aStatus))
   577     RProcess rJavaInstaller;
   530     {
   578     TFileName fileName;
   531         return;
   579     // Max one uid and some options -> 256 is enough
   532     }
   580     TBuf<256> commandLine;
   533 
       
   534     // Allocate buffer for Java Installer command line
       
   535     HBufC* pBufCommandLine = NULL;
       
   536     TRAPD(err, pBufCommandLine = HBufC::NewL(KShortCmdLineLen))
       
   537     if (KErrNone != err)
       
   538     {
       
   539         TRAP_IGNORE(aResults.AddIntL(KSifOutParam_ErrCategory, ELowMemory));
       
   540         TRequestStatus *statusPtr(&aStatus);
       
   541         User::RequestComplete(statusPtr, err);
       
   542         return;
       
   543     }
       
   544     std::auto_ptr<HBufC> bufCommandLine(pBufCommandLine);
       
   545     TPtr commandLine = pBufCommandLine->Des();
       
   546 
   581 
   547     // Build command line used to pass all necessary info to Java Installer
   582     // Build command line used to pass all necessary info to Java Installer
   548     std::auto_ptr<HBufC> installerStarterDll(
   583     std::auto_ptr<HBufC> installerStarterDll(
   549         stringToDes(java::runtime::JAVA_INSTALLER_STARTER_DLL));
   584         stringToDes(java::runtime::JAVA_INSTALLER_STARTER_DLL));
   550     commandLine = installerStarterDll->Des();
   585     commandLine = installerStarterDll->Des();
   551     commandLine.Append(KUninstall);
   586     commandLine.Append(_L(" uninstall"));
   552 
   587 
   553     commandLine.Append(KCid);
   588     commandLine.Append(_L(" -cid="));
   554     commandLine.AppendNum(aComponentId);
   589     commandLine.AppendNum(aComponentId);
   555 
   590 
   556     // Check whether this is silent uninstallation
   591     // Check whether this is silent uninstallation
   557     TInt silentInstall = 0;
   592     TInt silentInstall = 0;
   558     TRAP_IGNORE(aArguments.GetIntByNameL(KSifInParam_InstallSilently, silentInstall));
   593     TRAP_IGNORE(aArguments.GetIntByNameL(KSifInParam_InstallSilently, silentInstall));
   561         // Silent uninstallation requires TrustedUI capability
   596         // Silent uninstallation requires TrustedUI capability
   562         if (!aSecurityContext.HasCapability(ECapabilityTrustedUI))
   597         if (!aSecurityContext.HasCapability(ECapabilityTrustedUI))
   563         {
   598         {
   564             ELOG(EJavaInstaller,
   599             ELOG(EJavaInstaller,
   565                  "CJavaSifPlugin::Uninstall The caller did not have TrustedUI capability");
   600                  "CJavaSifPlugin::Uninstall The caller did not have TrustedUI capability");
   566             TRAP_IGNORE(aResults.AddIntL(KSifOutParam_ErrCategory, ESecurityError));
       
   567             TRequestStatus *statusPtr(&aStatus);
   601             TRequestStatus *statusPtr(&aStatus);
   568             User::RequestComplete(statusPtr, KErrPermissionDenied);
   602             User::RequestComplete(statusPtr, KErrPermissionDenied);
   569             return;
   603             return;
   570         }
   604         }
   571 
   605 
   572         commandLine.Append(KSilent);
   606         commandLine.Append(_L(" -silent"));
   573     }
   607     }
       
   608 
       
   609     // No need to start iResultsServer because Uninstall() does not
       
   610     // return anything usefull in aResults. We could return extended
       
   611     // error code there.
   574 
   612 
   575     // start JavaInstaller
   613     // start JavaInstaller
   576     std::auto_ptr<HBufC> installerProcess(
   614     std::auto_ptr<HBufC> installerProcess(
   577         stringToDes(java::runtime::JAVA_PROCESS));
   615         stringToDes(java::runtime::JAVA_PROCESS));
   578     RProcess rJavaInstaller;
   616     TInt err = rJavaInstaller.Create(installerProcess->Des(), commandLine);
   579     err = rJavaInstaller.Create(installerProcess->Des(), commandLine);
       
   580     if (KErrNone == err)
   617     if (KErrNone == err)
   581     {
   618     {
   582         err = StartResultsServer(aResults, *mDummyInfo);
       
   583         if (KErrNone != err)
       
   584         {
       
   585             // server cannot be started
       
   586             rJavaInstaller.Close();
       
   587             ELOG1(EJavaInstaller,
       
   588                   "CJavaSifPlugin::Uninstall: Cannot start results server, err %d", err);
       
   589             TRAP_IGNORE(aResults.AddIntL(KSifOutParam_ErrCategory, EUnexpectedError));
       
   590             TRequestStatus *statusPtr(&aStatus);
       
   591             User::RequestComplete(statusPtr, err);
       
   592             return;
       
   593         }
       
   594 
       
   595         // the exit status of Java Installer will be passed to
   619         // the exit status of Java Installer will be passed to
   596         // the asynch caller through aStatus
   620         // the asynch caller through aStatus
   597         rJavaInstaller.Logon(aStatus);
   621         rJavaInstaller.Logon(aStatus);
   598 
   622 
   599         rJavaInstaller.Resume();
   623         rJavaInstaller.Resume();
   601     else
   625     else
   602     {
   626     {
   603         rJavaInstaller.Close();
   627         rJavaInstaller.Close();
   604         ELOG1(EJavaInstaller,
   628         ELOG1(EJavaInstaller,
   605              "CJavaSifPlugin::Uninstall: starting JavaInstaller failed, err=%d", err);
   629              "CJavaSifPlugin::Uninstall: starting JavaInstaller failed, err=%d", err);
   606         TRAP_IGNORE(aResults.AddIntL(KSifOutParam_ErrCategory, EUnexpectedError));
       
   607         TRequestStatus *statusPtr(&aStatus);
   630         TRequestStatus *statusPtr(&aStatus);
   608         User::RequestComplete(statusPtr, err);
   631         User::RequestComplete(statusPtr, err);
   609         return;
   632         return;
   610     }
   633     }
   611 
   634 
   612     // Do NOT close rJavaInstaller now -> the caller gets notification when the
   635     // Do NOT close rJavaInstaller now -> the caller gets notification when the
   613     // process actually closes.
   636     // process actually closes.
   614     err = mHandlesToClose.Append(rJavaInstaller);
   637     iHandlesToClose.Append(rJavaInstaller);
   615     if ( err )
       
   616     {
       
   617         rJavaInstaller.Close();
       
   618         ELOG1(EJavaInstaller, "CJavaSifPlugin::Uninstall  mHandles"
       
   619               "ToClose.Append failed with error %d", err);
       
   620         TRAP_IGNORE(aResults.AddIntL(KSifOutParam_ErrCategory, ELowMemory));
       
   621         TRequestStatus *statusPtr(&aStatus);
       
   622         User::RequestComplete(statusPtr, err);
       
   623         return;
       
   624     }
       
   625 }
   638 }
   626 
   639 
   627 void CJavaSifPlugin::Activate(
   640 void CJavaSifPlugin::Activate(
   628     TComponentId /* aComponentId */,
   641     TComponentId /* aComponentId */,
   629     const TSecurityContext& /* aSecurityContext */,
   642     const TSecurityContext& /* aSecurityContext */,
   649 void CJavaSifPlugin::CancelOperation()
   662 void CJavaSifPlugin::CancelOperation()
   650 {
   663 {
   651     // Send cancel message to Java Installer
   664     // Send cancel message to Java Installer
   652 
   665 
   653     // Check whether there is anything to cancel
   666     // Check whether there is anything to cancel
   654     if (mHandlesToClose.Count() < 1)
   667     if (iHandlesToClose.Count() < 1)
   655     {
   668     {
   656         // No Java Installer process running, do nothing
   669         // No Java Installer process running, do nothing
   657         WLOG(EJavaInstaller,
   670         WLOG(EJavaInstaller,
   658             "CJavaSifPlugin::CancelOperation: Cancel called but there is no operation to cancel");
   671             "CJavaSifPlugin::CancelOperation: Cancel called but there is no operation to cancel");
   659         return;
   672         return;
   660     }
   673     }
   661 
   674 
   662     CommsMessage message;
   675     try
   663     message.setReceiver(IPC_ADDRESS_JAVA_INSTALLER_SERVER_C);
   676     {
   664     message.setSender(IPC_ADDRESS_JAVA_SIF_PLUGIN_C);
   677         CommsMessage message;
   665     message.setMessageId(INSTALLER_CANCEL_MESSAGE_ID);
   678         message.setModuleId(PLUGIN_ID_SAMPLE_C);
   666 
   679         message.setReceiver(IPC_ADDRESS_JAVA_INSTALLER_SERVER_C);
   667     CommsMessage replyMessage;
   680         message.setSender(IPC_ADDRESS_JAVA_SIF_PLUGIN_C);
   668     int timeout = 10; // 10 seconds  // codescanner::magicnumbers
   681         message.setMessageId(INSTALLER_CANCEL_MESSAGE_ID);
   669 
   682 
   670     CommsClientEndpoint comms;
   683         CommsMessage replyMessage;
   671     int err = comms.connect(IPC_ADDRESS_JAVA_INSTALLER_SERVER_C);
   684         int timeout = 10; // 10 seconds
   672     if (KErrNone == err)
   685 
   673     {
   686         CommsClientEndpoint comms;
   674         err = comms.sendReceive(message, replyMessage, timeout);
   687         int err = comms.connect(IPC_ADDRESS_JAVA_INSTALLER_SERVER_C);
   675     }
   688         if (KErrNone == err)
   676     else
   689         {
   677     {
   690             err = comms.sendReceive(message, replyMessage, timeout);
   678         // Cannot connect to Java Installer Comms end point,
   691         }
   679         // for example Java Installer is still starting up or
   692         else
   680         // already exiting
   693         {
   681         WLOG1(EJavaInstaller,
   694             // Cannot connect to Java Installer Comms end point,
   682             "CJavaSifPlugin:CancelOperation: Cannot connect to Java Installer "
   695             // for example Java Installer is still starting up or
   683             "Comms end point, err %d", err);
   696             // already exiting
   684         return;
   697             WLOG1(EJavaInstaller,
   685     }
   698                 "CJavaSifPlugin:CancelOperation: Cannot connect to Java Installer "
   686     if (err != 0)
   699                 "Comms end point, err %d", err);
   687     {
   700             return;
   688         // Sending message to Java Installer failed.
   701         }
   689         ELOG1(EJavaInstaller,
   702         if (err != 0)
   690             "CJavaSifPlugin:CancelOperation: Cannot send message to Java Installer, err %d",
   703         {
   691             err);
   704             // Sending message to Java Installer failed.
       
   705             ELOG1(EJavaInstaller,
       
   706                 "CJavaSifPlugin:CancelOperation: Cannot send message to Java Installer, err %d",
       
   707                 err);
       
   708             // Ignore possible errors in disconnect
       
   709             (void)comms.disconnect();
       
   710             return;
       
   711         }
       
   712 
       
   713         // Ignore the cancel result returned in replyMessage
       
   714         // because current SIF API does not return cancel result
       
   715 
   692         // Ignore possible errors in disconnect
   716         // Ignore possible errors in disconnect
   693         (void)comms.disconnect();  // codescanner::voidparameter
   717         (void)comms.disconnect();
   694         return;
   718     }
   695     }
   719     catch (ExceptionBase& e)
   696 
   720     {
   697     // Ignore the cancel result returned in replyMessage
   721         ELOG1(EJavaInstaller,
   698     // because current SIF API does not return cancel result
   722               "CJavaSifPlugin: Send cancel msg failed: ExceptionBase caught: %s ",
   699 
   723               e.toString().c_str());
   700     // Ignore possible errors in disconnect
   724         return;
   701     (void)comms.disconnect();  // codescanner::voidparameter
   725     }
       
   726     catch (std::exception& e)
       
   727     {
       
   728         ELOG1(EJavaInstaller,
       
   729               "CJavaSifPlugin: Send cancel msg failed: Exception %s caught", e.what());
       
   730         return;
       
   731     }
   702 
   732 
   703     // It takes some time before Java Installer had really cancelled
   733     // It takes some time before Java Installer had really cancelled
   704     // the operation and exited. Wait for it to happen because this function
   734     // the operation and exited. Wait for it to happen because this function
   705     // must return only after the original asynchronous call is completed.
   735     // must return only after the original asynchronous call is completed.
   706     TRequestStatus status;
   736     TRequestStatus status;
   707     // This array contains process handles for all Java Installer processes
   737     // This array contains process handles for all Java Installer processes
   708     // started from this sif plugin. The last handle is the active one.
   738     // started from this sif plugin. The last handle is the active one.
   709     // Check if it is still running
   739     // Check if it is still running
   710     if (mHandlesToClose[mHandlesToClose.Count()-1].ExitReason() != 0)
   740     if (iHandlesToClose[iHandlesToClose.Count()-1].ExitReason() != 0)
   711     {
   741     {
   712         // Process has already closed
   742         // Process has already closed
   713         return;
   743         return;
   714     }
   744     }
   715     // Wait until it exits
   745     // Wait until it exits
   716     mHandlesToClose[mHandlesToClose.Count()-1].Logon(status);
   746     iHandlesToClose[iHandlesToClose.Count()-1].Logon(status);
   717     User::WaitForRequest(status);  // codescanner::userWaitForRequest
   747     User::WaitForRequest(status);
   718     // Ignore the exit status of Java Installer because current SIF API
   748     // Ignore the exit status of Java Installer because current SIF API
   719     // does not return cancel result
   749     // does not return cancel result
   720 
   750 
   721     return;
   751     return;
   722 }
   752 }
   723 
   753 
   724 void CJavaSifPlugin::CopyFilesIfNeededL(TFileName &aFileName)
   754 void CJavaSifPlugin::CopyFilesIfNeededL(TFileName &aFileName)
   725 {
   755 {
   726     // Check if the file is in the private data cage of some process
   756     // Check if the file is in the private data cage of some process
   727     TInt idx = aFileName.FindF(KPrivateDataCage);
   757     TInt idx = aFileName.FindF(KPrivateDataCage);
   728     if ((idx != KErrNotFound) && (idx < 3))   // codescanner::magicnumbers
   758     if ((idx != KErrNotFound) && (idx < 3))
   729     {
   759     {
   730         // In case of device Inbox or Java Installer itself do nothing
   760         // In case of device Inbox or Java Installer itself do nothing
   731         if ((aFileName.FindF(KInboxDataCage) != KErrNotFound) ||
   761         if ((aFileName.FindF(KInboxDataCage) != KErrNotFound) ||
   732                 (aFileName.FindF(KJavaInstallerDataCage) != KErrNotFound))
   762                 (aFileName.FindF(KJavaInstallerDataCage) != KErrNotFound))
   733         {
   763         {
   738         // to Java Installer tmp dir so that both .jad file and
   768         // to Java Installer tmp dir so that both .jad file and
   739         // the corresponding .jar file are copied.
   769         // the corresponding .jar file are copied.
   740         // (aFileName is <path>\<name>.<ext>, copy <path>\<name>.*
   770         // (aFileName is <path>\<name>.<ext>, copy <path>\<name>.*
   741         // to Java Installer tmp dir.)
   771         // to Java Installer tmp dir.)
   742         TParse fp;
   772         TParse fp;
   743         mRFs.Parse(aFileName, fp);
   773         iRFs.Parse(aFileName, fp);
       
   774 
       
   775         CFileMan* fm = CFileMan::NewL(iRFs);
   744         TFileName filesToCopy = fp.DriveAndPath();
   776         TFileName filesToCopy = fp.DriveAndPath();
   745         filesToCopy.Append(fp.Name());
   777         filesToCopy.Append(fp.Name());
   746         filesToCopy.Append(KAnyExtension);
   778         filesToCopy.Append(KAnyExtension);
   747 
   779         TInt err = fm->Copy(filesToCopy, KJavaInstallerTmp, CFileMan::ERecurse);
   748         // Use JavaInstallCopier.exe to copy the files.
   780         delete fm;
   749         RProcess rJavaInstallCopier;
   781         if (KErrNone != err)
   750         TInt err = rJavaInstallCopier.Create(
   782         {
   751             KJavaInstallCopierProcess, filesToCopy);
       
   752         if (KErrNone == err)
       
   753         {
       
   754             TRequestStatus status;
       
   755             rJavaInstallCopier.Logon(status);
       
   756             rJavaInstallCopier.Resume();
       
   757             User::WaitForRequest(status); // codescanner::userWaitForRequest
       
   758             err = rJavaInstallCopier.ExitReason();
       
   759             rJavaInstallCopier.Close();
       
   760             if (KErrNone != err)
       
   761             {
       
   762                 ELOG1(EJavaInstaller,
       
   763                       "CJavaSifPlugin::CopyFilesIfNeededL: copying files "
       
   764                       "to JavaInstaller data cage failed, err=%d", err);
       
   765                 User::Leave(err);
       
   766             }
       
   767         }
       
   768         else
       
   769         {
       
   770             rJavaInstallCopier.Close();
       
   771             ELOG1(EJavaInstaller,
   783             ELOG1(EJavaInstaller,
   772                   "CJavaSifPlugin::CopyFilesIfNeededL: starting "
   784                   "CJavaSifPlugin::CopyFilesIfNeededL: copying files "
   773                   "JavaInstallCopier failed, err=%d", err);
   785                   "to Java Installer data cage failed, err=%d", err);
   774             User::Leave(err);
   786             User::Leave(err);
   775         }
   787         }
   776 
   788 
   777         // aFileName must point to the copy of the file
   789         // aFileName must point to the copy of the file
   778         aFileName = fp.Drive();
   790         aFileName = fp.Drive();
   781     }
   793     }
   782 
   794 
   783     return;
   795     return;
   784 }
   796 }
   785 
   797 
   786 
       
   787 TInt CJavaSifPlugin::IsJadFile(
       
   788     RFile& aFileHandle,
       
   789     const COpaqueNamedParams& aArguments,
       
   790     TBool& aIsJad)
       
   791 {
       
   792     TBool mimeTypeGiven = EFalse;
       
   793 
       
   794     TRAP_IGNORE(
       
   795         const TDesC &desValue = aArguments.StringByNameL(KSifInParam_MimeType);
       
   796         if (desValue.Length() > 0)
       
   797         {
       
   798             mimeTypeGiven = ETrue;
       
   799             if (!desValue.Compare(KJadMimeType))
       
   800             {
       
   801                 aIsJad = ETrue;
       
   802             }
       
   803             else
       
   804             {
       
   805                 aIsJad = EFalse;
       
   806             }
       
   807         }
       
   808     )
       
   809     if (mimeTypeGiven)
       
   810     {
       
   811         return KErrNone;
       
   812     }
       
   813 
       
   814     // Mime type was not given in the input arguments, must check the contents
       
   815     // of the file itself
       
   816     return IsJadFile(aFileHandle, aIsJad);
       
   817 }
       
   818 
       
   819 
       
   820 TInt CJavaSifPlugin::IsJadFile(
       
   821     RFile& aFileHandle,
       
   822     TBool& aIsJad)
       
   823 {
       
   824     RApaLsSession apaSession;
       
   825     TInt err = apaSession.Connect();
       
   826     if (KErrNone != err)
       
   827     {
       
   828         ELOG1(EJavaInstaller,
       
   829             "CJavaSifPlugin::IsJadFile RApaLsSession Connect error %d", err);
       
   830         return err;
       
   831     }
       
   832 
       
   833     TDataType jadFileMimeType(K8JadMimeType);
       
   834     err = apaSession.RecognizeSpecificData(aFileHandle, jadFileMimeType, aIsJad);
       
   835     apaSession.Close();
       
   836     if (KErrNone != err)
       
   837     {
       
   838         // Just log the error
       
   839         ELOG1(EJavaInstaller,
       
   840             "CJavaSifPlugin::IsJadFile RApaLsSession RecognizeSpecificData error %d",
       
   841             err);
       
   842         return err;
       
   843     }
       
   844 
       
   845     return KErrNone;
       
   846 }
       
   847 
       
   848 
       
   849 void CJavaSifPlugin::BuildInstallCommandLine(
       
   850     TPtr& aCommandLine,
       
   851     const COpaqueNamedParams& aArguments)
       
   852 {
       
   853     // KSifInParam_Drive -> -drive=install_target_drive (A, B, C, ..., Z)
       
   854     TInt intValue = GetPositiveIntParam(KSifInParam_Drive, aArguments);
       
   855     // Value 0 is 'A:' drive and  value 25 is 'Z:' drive
       
   856     if ((intValue > -1) && (intValue < 26))  // codescanner::magicnumbers
       
   857     {
       
   858         aCommandLine.Append(KDrive);
       
   859         TChar drive('A');
       
   860         drive += intValue;
       
   861         aCommandLine.Append(drive);
       
   862     }
       
   863 
       
   864     // KSifInParam_PerformOCSP Yes/No/AskUser -> -ocsp=yes|no
       
   865     intValue = GetPositiveIntParam(KSifInParam_PerformOCSP, aArguments);
       
   866     if (intValue == 0) // Yes
       
   867     {
       
   868         aCommandLine.Append(KOcsp);
       
   869         aCommandLine.Append(KYes);
       
   870     }
       
   871     else if (intValue == 1) // No
       
   872     {
       
   873         aCommandLine.Append(KOcsp);
       
   874         aCommandLine.Append(KNo);
       
   875     }
       
   876     // AskUser is not supported
       
   877 
       
   878     // KSifInParam_IgnoreOCSPWarnings Yes/No/AskUser -> -ignore_ocsp_warnings=yes|no
       
   879     intValue = GetPositiveIntParam(KSifInParam_IgnoreOCSPWarnings, aArguments);
       
   880     if (intValue == 0) // Yes
       
   881     {
       
   882         aCommandLine.Append(KIgnoreOcspWarnings);
       
   883         aCommandLine.Append(KYes);
       
   884     }
       
   885     else if (intValue == 1) // No
       
   886     {
       
   887         aCommandLine.Append(KIgnoreOcspWarnings);
       
   888         aCommandLine.Append(KNo);
       
   889     }
       
   890     // AskUser is not supported
       
   891 
       
   892     // KSifInParam_AllowUpgrade Yes/No/AskUser -> -upgrade=yes|no
       
   893     intValue = GetPositiveIntParam(KSifInParam_AllowUpgrade, aArguments);
       
   894     if (intValue == 0) // Yes
       
   895     {
       
   896         aCommandLine.Append(KUpgrade);
       
   897         aCommandLine.Append(KYes);
       
   898     }
       
   899     else if (intValue == 1) // No
       
   900     {
       
   901         aCommandLine.Append(KUpgrade);
       
   902         aCommandLine.Append(KNo);
       
   903     }
       
   904     // AskUser is not supported
       
   905 
       
   906     // KSifInParam_AllowUpgradeData Yes/No/AskUser -> -upgrade_data=yes|no
       
   907     intValue = GetPositiveIntParam(KSifInParam_AllowUpgradeData, aArguments);
       
   908     if (intValue == 0) // Yes
       
   909     {
       
   910         aCommandLine.Append(KUpgradeData);
       
   911         aCommandLine.Append(KYes);
       
   912     }
       
   913     else if (intValue == 1) // No
       
   914     {
       
   915         aCommandLine.Append(KUpgradeData);
       
   916         aCommandLine.Append(KNo);
       
   917     }
       
   918     // AskUser is not supported
       
   919 
       
   920     // KSifInParam_AllowUntrusted Yes/No/AskUser -> -untrusted=yes|no
       
   921     intValue = GetPositiveIntParam(KSifInParam_AllowUntrusted, aArguments);
       
   922     if (intValue == 0) // Yes
       
   923     {
       
   924         aCommandLine.Append(KUntrusted);
       
   925         aCommandLine.Append(KYes);
       
   926     }
       
   927     else if (intValue == 1) // No
       
   928     {
       
   929         aCommandLine.Append(KUntrusted);
       
   930         aCommandLine.Append(KNo);
       
   931     }
       
   932     // AskUser is not supported
       
   933 
       
   934     // KSifInParam_AllowOverwrite Yes/No/AskUser -> -overwrite=yes|no
       
   935     intValue = GetPositiveIntParam(KSifInParam_AllowOverwrite, aArguments);
       
   936     if (intValue == 0) // Yes
       
   937     {
       
   938         aCommandLine.Append(KOverwrite);
       
   939         aCommandLine.Append(KYes);
       
   940     }
       
   941     else if (intValue == 1) // No
       
   942     {
       
   943         aCommandLine.Append(KOverwrite);
       
   944         aCommandLine.Append(KNo);
       
   945     }
       
   946     // AskUser is not supported
       
   947 
       
   948     // KSifInParam_AllowDownload Yes/No/AskUser -> -download=yes|no
       
   949     intValue = GetPositiveIntParam(KSifInParam_AllowDownload, aArguments);
       
   950     if (intValue == 0) // Yes
       
   951     {
       
   952         aCommandLine.Append(KDownload);
       
   953         aCommandLine.Append(KYes);
       
   954     }
       
   955     else if (intValue == 1) // No
       
   956     {
       
   957         aCommandLine.Append(KDownload);
       
   958         aCommandLine.Append(KNo);
       
   959     }
       
   960     // AskUser is not supported
       
   961 
       
   962     // KSifInParam_IAP -> -iap=IAP_ID (internet access point id)
       
   963     intValue = GetPositiveIntParam(KSifInParam_IAP, aArguments);
       
   964     if (intValue > -1)
       
   965     {
       
   966         // IAP ids are always positive
       
   967         aCommandLine.Append(KIap);
       
   968         aCommandLine.AppendNum(intValue);
       
   969     }
       
   970 
       
   971     // KSifInParam_SNAP -> -snap=SNAP_ID (service network access point id)
       
   972     intValue = GetPositiveIntParam(KSifInParam_SNAP, aArguments);
       
   973     if (intValue > -1)
       
   974     {
       
   975         // SNAP ids are always positive
       
   976         aCommandLine.Append(KSnap);
       
   977         aCommandLine.AppendNum(intValue);
       
   978     }
       
   979 
       
   980     // When this param is given, Java Installer will cancel installation
       
   981     // before committing anything. This option is for debugging purposes only.
       
   982     // KForceCancel -> -forcecancel
       
   983     // The value of parameter is ignored
       
   984     TRAP_IGNORE(
       
   985         const TDesC &desValue = aArguments.StringByNameL(KForceCancel);
       
   986         if (desValue.Length() > 0)
       
   987         {
       
   988             aCommandLine.Append(KForceCancel);
       
   989         }
       
   990     )
       
   991 
       
   992     std::wstring base64EncodedArgs;
       
   993     // KSifInParam_UserName -> -username=download_username
       
   994     TRAP_IGNORE(
       
   995         const TDesC &desValue = aArguments.StringByNameL(KSifInParam_UserName);
       
   996         if (desValue.Length() > 0)
       
   997         {
       
   998             try
       
   999             {
       
  1000                 std::wstring value((wchar_t *)(desValue.Ptr()), desValue.Length());
       
  1001                 std::wstring encodedValue = JavaCommonUtils::wbase64encode(value);
       
  1002                 aCommandLine.Append(KUsername);
       
  1003                 aCommandLine.Append(
       
  1004                     (const unsigned short *)encodedValue.c_str(), (int)encodedValue.length());
       
  1005                 base64EncodedArgs.append(L"username,");
       
  1006             }
       
  1007             catch (std::exception& e)
       
  1008             {
       
  1009                 ELOG1(EJavaInstaller,
       
  1010                     "CJavaSifPlugin::BuildInstallCommandLine Base64 encoding user "
       
  1011                     "name failed, err %s", e.what());
       
  1012             }
       
  1013         }
       
  1014     )
       
  1015 
       
  1016     // KSifInParam_Password -> -password=download_password
       
  1017     TRAP_IGNORE(
       
  1018         const TDesC &desValue = aArguments.StringByNameL(KSifInParam_Password);
       
  1019         if (desValue.Length() > 0)
       
  1020         {
       
  1021             try
       
  1022             {
       
  1023                 std::wstring value((wchar_t *)(desValue.Ptr()), desValue.Length());
       
  1024                 std::wstring encodedValue = JavaCommonUtils::wbase64encode(value);
       
  1025                 aCommandLine.Append(KPassword);
       
  1026                 aCommandLine.Append(
       
  1027                     (const unsigned short *)encodedValue.c_str(), (int)encodedValue.length());
       
  1028                 base64EncodedArgs.append(L"password,");
       
  1029             }
       
  1030             catch (std::exception& e)
       
  1031             {
       
  1032                 ELOG1(EJavaInstaller,
       
  1033                     "CJavaSifPlugin::BuildInstallCommandLine Base64 encoding password "
       
  1034                     "failed, err %s", e.what());
       
  1035             }
       
  1036         }
       
  1037     )
       
  1038 
       
  1039     // KSifInParam_SourceUrl -> -sourceurl=original (HTTP) URL of the JAD or JAR file
       
  1040     TRAP_IGNORE(
       
  1041         const TDesC &desValue = aArguments.StringByNameL(KSifInParam_SourceUrl);
       
  1042         if (desValue.Length() > 0)
       
  1043         {
       
  1044             try
       
  1045             {
       
  1046                 std::wstring value((wchar_t *)(desValue.Ptr()), desValue.Length());
       
  1047                 std::wstring encodedValue = JavaCommonUtils::wbase64encode(value);
       
  1048                 aCommandLine.Append(KSourceUrl);
       
  1049                 aCommandLine.Append(
       
  1050                     (const unsigned short *)encodedValue.c_str(), (int)encodedValue.length());
       
  1051                 base64EncodedArgs.append(L"sourceurl,");
       
  1052             }
       
  1053             catch (std::exception& e)
       
  1054             {
       
  1055                 ELOG1(EJavaInstaller,
       
  1056                     "CJavaSifPlugin::BuildInstallCommandLine Base64 encoding source "
       
  1057                     "url failed, err %s", e.what());
       
  1058             }
       
  1059         }
       
  1060     )
       
  1061 
       
  1062     // KSifInParam_Charset -> -charset=Internet-standard character set name
       
  1063     TRAP_IGNORE(
       
  1064         const TDesC &desValue = aArguments.StringByNameL(KSifInParam_Charset);
       
  1065         if (desValue.Length() > 0)
       
  1066         {
       
  1067             try
       
  1068             {
       
  1069                 std::wstring value((wchar_t *)(desValue.Ptr()), desValue.Length());
       
  1070                 std::wstring encodedValue = JavaCommonUtils::wbase64encode(value);
       
  1071                 aCommandLine.Append(KCharSet);
       
  1072                 aCommandLine.Append(
       
  1073                     (const unsigned short *)encodedValue.c_str(), (int)encodedValue.length());
       
  1074                 base64EncodedArgs.append(L"charset,");
       
  1075             }
       
  1076             catch (std::exception& e)
       
  1077             {
       
  1078                 ELOG1(EJavaInstaller,
       
  1079                     "CJavaSifPlugin::BuildInstallCommandLine Base64 encoding charset "
       
  1080                     "failed, err %s", e.what());
       
  1081             }
       
  1082         }
       
  1083     )
       
  1084 
       
  1085     if (base64EncodedArgs.length() > 0)
       
  1086     {
       
  1087         // Tell Java Installer which arguments have been Base64 encoded
       
  1088         aCommandLine.Append(KBase64);
       
  1089         aCommandLine.Append(
       
  1090             (const unsigned short *)base64EncodedArgs.c_str(), (int)base64EncodedArgs.length());
       
  1091     }
       
  1092 
       
  1093     return;
       
  1094 }
       
  1095 
       
  1096 TInt CJavaSifPlugin::GetPositiveIntParam(
       
  1097         const TDesC& aName,
       
  1098         const COpaqueNamedParams& aArguments)
       
  1099 {
       
  1100     // Assume that the value will not be found
       
  1101     TInt intValue = -1;
       
  1102 
       
  1103     // If the value can be read, intValue will be set, otherwise this function
       
  1104     // returns -1
       
  1105     TRAP_IGNORE((void)aArguments.GetIntByNameL(aName, intValue));  // codescanner::voidparameter
       
  1106 
       
  1107     return intValue;
       
  1108 }
       
  1109 
       
  1110 
       
  1111 TInt CJavaSifPlugin::StartResultsServer(
       
  1112     COpaqueNamedParams& aResults,
       
  1113     CComponentInfo& aComponentInfo)
       
  1114 {
       
  1115     // Destroy old Comms server if it exists
       
  1116     delete mResultsServer;
       
  1117     mResultsServer = NULL;
       
  1118 
       
  1119     // Start new Comms server
       
  1120     mResultsServer = new ResultsServer(aResults, aComponentInfo);  // codescanner::nonleavenew
       
  1121     if (NULL == mResultsServer)
       
  1122     {
       
  1123         return KErrNoMemory;
       
  1124     }
       
  1125     else
       
  1126     {
       
  1127         // Start the server
       
  1128         return mResultsServer->start();
       
  1129     }
       
  1130 }
       
  1131 
       
  1132 
       
  1133 TBool CJavaSifPlugin::ExitIfJavaInstallerRunning(
       
  1134     COpaqueNamedParams& aResults,
       
  1135     TRequestStatus& aStatus)
       
  1136 {
       
  1137     // If Java Installer is already running, set error category EInstallerBusy etc
       
  1138     // to aResults and return
       
  1139 
       
  1140     TInt err(KErrNone);
       
  1141     RProcess proc;
       
  1142     TFindProcess finder(KJavaInstallerProcess);
       
  1143     TFullName procName;
       
  1144 
       
  1145     // Java Installer process SID is 0x102033E6 and name is "Installer"
       
  1146     while (finder.Next(procName) == KErrNone)
       
  1147     {
       
  1148         if (proc.Open(finder) != KErrNone)
       
  1149         {
       
  1150             continue;
       
  1151         }
       
  1152         if (proc.SecureId() == KJavaInstallerSecureID)
       
  1153         {
       
  1154             if (proc.ExitType() == EExitPending)
       
  1155             {
       
  1156                 // Java Installer process is already running
       
  1157                 proc.Close();
       
  1158 
       
  1159                 // return error information
       
  1160                 TRAP(err, aResults.AddIntL(KSifOutParam_ErrCategory, EInstallerBusy));
       
  1161                 if (KErrNone != err)
       
  1162                 {
       
  1163                     ELOG1(EJavaInstaller,
       
  1164                         "CJavaSifPlugin::ExitIfJavaInstallerRunning aResults.AddIntL "
       
  1165                         "ErrCategory err %d", err);
       
  1166                 }
       
  1167 
       
  1168                 TRAP(err, aResults.AddIntL(KSifOutParam_ErrCode, KErrInUse));
       
  1169                 if (KErrNone != err)
       
  1170                 {
       
  1171                     ELOG1(EJavaInstaller,
       
  1172                         "CJavaSifPlugin::ExitIfJavaInstallerRunning aResults.AddIntL "
       
  1173                         "ErrCode err %d", err);
       
  1174                 }
       
  1175 
       
  1176                 TRAP(err, aResults.AddIntL(KSifOutParam_ExtendedErrCode, 0));
       
  1177                 if (KErrNone != err)
       
  1178                 {
       
  1179                     ELOG1(EJavaInstaller,
       
  1180                         "CJavaSifPlugin::ExitIfJavaInstallerRunning aResults.AddIntL "
       
  1181                         "ExtendedErrCode err %d", err);
       
  1182                 }
       
  1183 
       
  1184                 // TODO: return also localized error message from usif
       
  1185                 // common localization file after the localized strings are available
       
  1186 
       
  1187                 TRequestStatus *statusPtr(&aStatus);
       
  1188                 User::RequestComplete(statusPtr, KErrInUse);
       
  1189                 return ETrue;
       
  1190             }
       
  1191        }
       
  1192        proc.Close();
       
  1193     }
       
  1194 
       
  1195     return EFalse;
       
  1196 }
       
  1197 
       
  1198 /**
       
  1199  * Creates 'preparing installation' dialog.
       
  1200  */
       
  1201 void CJavaSifPlugin::CreatePrepInstDialogL()
       
  1202 {
       
  1203     ILOG(EJavaInstaller, "CJavaSifPlugin::CreatePrepInstDialogL creating dialog");
       
  1204     mPrepInstDialog = CHbDeviceNotificationDialogSymbian::NewL();
       
  1205     _LIT(KPrepInstText, "Preparing installation...");
       
  1206     mPrepInstDialog->SetTitleL(KPrepInstText);
       
  1207     mPrepInstDialog->SetTimeout(20*1000); // ms
       
  1208     mPrepInstDialog->ShowL();
       
  1209     ILOG(EJavaInstaller, "CJavaSifPlugin::CreatePrepInstDialogL dialog created");
       
  1210 }
       
  1211 
       
  1212 void CJavaSifPlugin::HidePrepInstDialogL()
       
  1213 {
       
  1214     ILOG(EJavaInstaller, "CJavaSifPlugin::HidePrepInstDialogL hiding dialog");
       
  1215     // Stop further timed calls
       
  1216     if (mWaitToHideDialog)
       
  1217     {
       
  1218         mWaitToHideDialog->Cancel();
       
  1219     }
       
  1220     // Close wait dialog.
       
  1221     if (mPrepInstDialog)
       
  1222     {
       
  1223         mPrepInstDialog->Close();
       
  1224     }
       
  1225     ILOG(EJavaInstaller, "CJavaSifPlugin::HidePrepInstDialogL dialog hidden");
       
  1226 }
       
  1227 
       
  1228 //  End of File
   798 //  End of File