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