javamanager/javainstaller/javasifplugin/src/javasifplugin.cpp
changeset 21 2a9601315dfc
child 35 85266cc22c7f
child 60 6c158198356e
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This file contains the implementation of CJavaSifPlugin
       
    15 *               class member functions. ECOM Plugin for USIF to handle
       
    16 *               install, uninstall, get component info requests.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #include <apgcli.h>
       
    22 #include <apmstd.h>
       
    23 #include <e32cmn.h>
       
    24 #include <e32property.h>
       
    25 #include <charconv.h>
       
    26 #include <data_caging_path_literals.hrh>
       
    27 
       
    28 #include "comms.h"
       
    29 #include "commsmessage.h"
       
    30 #include "commsclientendpoint.h"
       
    31 #include "javasifplugin.h"
       
    32 #include "javauids.h"
       
    33 #include "logger.h"
       
    34 #include "javaoslayer.h"
       
    35 #include "javaprocessconstants.h"
       
    36 #include "javasymbianoslayer.h"
       
    37 #include "runtimeexception.h"
       
    38 
       
    39 
       
    40 using namespace Java::Installer;
       
    41 using namespace java::util;
       
    42 using namespace java::comms;
       
    43 
       
    44 _LIT(KPrivateDataCage, "\\private\\");
       
    45 _LIT(KInboxDataCage, "\\private\\1000484b\\");
       
    46 _LIT(KJavaInstallerDataCage, "\\private\\102033e6\\");
       
    47 _LIT(KJavaInstallerTmp, "\\private\\102033E6\\installer\\tmp\\");
       
    48 _LIT(KAnyExtension, ".*");
       
    49 
       
    50 
       
    51 // ============================ MEMBER FUNCTIONS ===============================
       
    52 
       
    53 CJavaSifPlugin* CJavaSifPlugin::NewL()
       
    54 {
       
    55     CJavaSifPlugin* self = new(ELeave) CJavaSifPlugin();
       
    56     CleanupStack::PushL(self);
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop(self);
       
    59     return self;
       
    60 }
       
    61 
       
    62 CJavaSifPlugin::~CJavaSifPlugin()
       
    63 {
       
    64     iRFs.Close();
       
    65 
       
    66     TInt nHandles = iHandlesToClose.Count();
       
    67     while (nHandles > 0)
       
    68     {
       
    69         nHandles--;
       
    70         iHandlesToClose[nHandles].Close();
       
    71     }
       
    72     iHandlesToClose.Reset();
       
    73 
       
    74     delete iResultsServer;
       
    75     iResultsServer = NULL;
       
    76 
       
    77     delete iDummyResults;
       
    78     iDummyResults = NULL;
       
    79 
       
    80     delete iDummyInfo;
       
    81     iDummyInfo = NULL;
       
    82 }
       
    83 
       
    84 CJavaSifPlugin::CJavaSifPlugin()
       
    85 {
       
    86 }
       
    87 
       
    88 void CJavaSifPlugin::ConstructL()
       
    89 {
       
    90     User::LeaveIfError(iRFs.Connect());
       
    91     User::LeaveIfError(iRFs.ShareProtected());
       
    92     iResultsServer = NULL;
       
    93     iDummyResults = COpaqueNamedParams::NewL();
       
    94     iDummyInfo = CComponentInfo::NewL();
       
    95 }
       
    96 
       
    97 void CJavaSifPlugin::GetComponentInfo(
       
    98     const TDesC& aFileName,
       
    99     const TSecurityContext& aSecurityContext,
       
   100     CComponentInfo& aComponentInfo,
       
   101     TRequestStatus& aStatus)
       
   102 {
       
   103     RFile fileHandle;
       
   104     TInt err = fileHandle.Open(iRFs, aFileName, EFileShareReadersOnly | EFileRead);
       
   105     if (KErrNone != err)
       
   106     {
       
   107         ELOG1(EJavaInstaller,
       
   108               "CJavaSifPlugin::GetComponentInfo Opening file for reading failed with error %d",
       
   109               err);
       
   110         TRequestStatus *statusPtr(&aStatus);
       
   111         User::RequestComplete(statusPtr, err);
       
   112         return;
       
   113     }
       
   114 
       
   115     GetComponentInfo(fileHandle, aSecurityContext, aComponentInfo, aStatus);
       
   116     fileHandle.Close();
       
   117 }
       
   118 
       
   119 void CJavaSifPlugin::GetComponentInfo(
       
   120     RFile& aFileHandle,
       
   121     const TSecurityContext& /* aSecurityContext */,
       
   122     CComponentInfo& aComponentInfo,
       
   123     TRequestStatus& aStatus)
       
   124 {
       
   125     RProcess rJavaInstaller;
       
   126     TFileName fileName;
       
   127     TBuf<1536> commandLine;
       
   128 
       
   129     // Build command line used to pass all necessary info to Java Installer
       
   130     std::auto_ptr<HBufC> installerStarterDll(
       
   131         stringToDes(java::runtime::JAVA_INSTALLER_STARTER_DLL));
       
   132     commandLine = installerStarterDll->Des();
       
   133     commandLine.Append(_L(" componentinfo"));
       
   134 
       
   135     // Ask Java Installer to send component info back
       
   136     // as Comms message. 11000 is IPC_ADDRESS_JAVA_SIF_PLUGIN_C Comms endpoint
       
   137     // that our ResultsServer will listen to.
       
   138     commandLine.Append(_L(" -commsresult=11000"));
       
   139 
       
   140     TInt err = aFileHandle.FullName(fileName);
       
   141 
       
   142     // Java Installer does not have AllFiles capability.
       
   143     // So if the .jad/.jar file is in the private data cage of
       
   144     // Remove Application Management system, it must be copied
       
   145     // to the private data cage of Java Installer in this
       
   146     // plugin which is executed in process which hopefully has
       
   147     // AllFiles capability.
       
   148     TRAP(err, CopyFilesIfNeededL(fileName));
       
   149     if (KErrNone != err)
       
   150     {
       
   151         TRequestStatus *statusPtr(&aStatus);
       
   152         User::RequestComplete(statusPtr, err);
       
   153         return;
       
   154     }
       
   155 
       
   156     // Check whether the file is .jad or .jar
       
   157     RApaLsSession apaSession;
       
   158     err = apaSession.Connect();
       
   159     if (KErrNone != err)
       
   160     {
       
   161         ELOG1(EJavaInstaller,
       
   162               "CJavaSifPlugin::GetComponentInfo RApaLsSession Connect error %d", err);
       
   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);
       
   177     }
       
   178     if (isJad)
       
   179     {
       
   180         // Installation should be started from JAD file
       
   181         commandLine.Append(_L(" -jad="));
       
   182     }
       
   183     else
       
   184     {
       
   185         // from JAR file
       
   186         commandLine.Append(_L(" -jar="));
       
   187     }
       
   188     // Filename parameter must be surrounded in double quotes to
       
   189     // ensure that spaces in filename are passed correctly.
       
   190     commandLine.Append(_L("\""));
       
   191     commandLine.Append(fileName);
       
   192     commandLine.Append(_L("\""));
       
   193 
       
   194     // Start JavaInstaller
       
   195     std::auto_ptr<HBufC> installerProcess(
       
   196         stringToDes(java::runtime::JAVA_PROCESS));
       
   197     err = rJavaInstaller.Create(installerProcess->Des(), commandLine);
       
   198     if (KErrNone == err)
       
   199     {
       
   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         }
       
   215         if (KErrNone != err)
       
   216         {
       
   217             // server cannot be started
       
   218             rJavaInstaller.Close();
       
   219             ELOG1(EJavaInstaller,
       
   220                   "CJavaSifPlugin::GetComponentInfo: Cannot start results server, err %d", err);
       
   221             TRequestStatus *statusPtr(&aStatus);
       
   222             User::RequestComplete(statusPtr, err);
       
   223             return;
       
   224         }
       
   225 
       
   226         // The status of the component info operation == the exit status of Java Installer
       
   227         // It will be passed to the asynch caller through aStatus
       
   228         rJavaInstaller.Logon(aStatus);
       
   229     }
       
   230     else
       
   231     {
       
   232         rJavaInstaller.Close();
       
   233         ELOG1(EJavaInstaller,
       
   234               "CJavaSifPlugin::GetComponentInfo: starting JavaInstaller failed, err=%d", err);
       
   235         TRequestStatus *statusPtr(&aStatus);
       
   236         User::RequestComplete(statusPtr, err);
       
   237         return;
       
   238     }
       
   239 
       
   240     rJavaInstaller.Resume();
       
   241 
       
   242     // Do NOT close rJavaInstaller now -> the caller gets notification when the
       
   243     // process actually closes.
       
   244     iHandlesToClose.Append(rJavaInstaller);
       
   245 }
       
   246 
       
   247 void CJavaSifPlugin::Install(
       
   248     const TDesC& aFileName,
       
   249     const TSecurityContext& aSecurityContext,
       
   250     const COpaqueNamedParams& aArguments,
       
   251     COpaqueNamedParams& aResults,
       
   252     TRequestStatus& aStatus)
       
   253 {
       
   254     RFile fileHandle;
       
   255     TInt err = fileHandle.Open(iRFs, aFileName, EFileShareReadersOnly | EFileRead);
       
   256     if (KErrNone != err)
       
   257     {
       
   258         ELOG1(EJavaInstaller,
       
   259               "CJavaSifPlugin::Install Opening file for reading failed with error %d", err);
       
   260         TRequestStatus *statusPtr(&aStatus);
       
   261         User::RequestComplete(statusPtr, err);
       
   262         return;
       
   263     }
       
   264 
       
   265     Install(fileHandle, aSecurityContext, aArguments, aResults, aStatus);
       
   266     fileHandle.Close();
       
   267 }
       
   268 
       
   269 void CJavaSifPlugin::Install(
       
   270     RFile& aFileHandle,
       
   271     const TSecurityContext& aSecurityContext,
       
   272     const COpaqueNamedParams& aArguments,
       
   273     COpaqueNamedParams& aResults,
       
   274     TRequestStatus& aStatus)
       
   275 {
       
   276     RProcess rJavaInstaller;
       
   277     TFileName fileName;
       
   278     // Max two path names and some options -> 1536 is enough
       
   279     TBuf<1536> commandLine;
       
   280 
       
   281     // Build command line used to pass all necessary info to Java Installer
       
   282     std::auto_ptr<HBufC> installerStarterDll(
       
   283         stringToDes(java::runtime::JAVA_INSTALLER_STARTER_DLL));
       
   284     commandLine = installerStarterDll->Des();
       
   285     commandLine.Append(_L(" install"));
       
   286 
       
   287     // Check whether this is silent installation
       
   288     TInt silentInstall = 0;
       
   289     TRAP_IGNORE(aArguments.GetIntByNameL(KSifInParam_InstallSilently, silentInstall));
       
   290     if (silentInstall)
       
   291     {
       
   292         // Silent installation requires TrustedUI capability
       
   293         if (!aSecurityContext.HasCapability(ECapabilityTrustedUI))
       
   294         {
       
   295             ELOG(EJavaInstaller,
       
   296                  "CJavaSifPlugin::Install The caller did not have TrustedUI capability");
       
   297             TRequestStatus *statusPtr(&aStatus);
       
   298             User::RequestComplete(statusPtr, KErrPermissionDenied);
       
   299             return;
       
   300         }
       
   301 
       
   302         commandLine.Append(_L(" -silent"));
       
   303     }
       
   304 
       
   305     TBool paramFound = EFalse;
       
   306     TInt  intValue = 0;
       
   307     TDesC desValue = KNullDesC;
       
   308 
       
   309     // KSifInParam_Drive -> -drive=install_target_drive (A, B, C, ..., Z)
       
   310     TRAP_IGNORE(paramFound = aArguments.GetIntByNameL(KSifInParam_Drive, intValue));
       
   311     if (paramFound)
       
   312     {
       
   313         // Value 0 is 'A:' drive and  value 25 is 'Z:' drive
       
   314         if ((intValue > -1) && (intValue < 26))
       
   315         {
       
   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 
       
   459 
       
   460     // Ask Java Installer to send installation results back
       
   461     // as Comms message. 11000 is IPC_ADDRESS_JAVA_SIF_PLUGIN_C Comms endpoint
       
   462     // that our ResultsServer will listen to.
       
   463     commandLine.Append(_L(" -commsresult=11000"));
       
   464 
       
   465     TInt err = aFileHandle.FullName(fileName);
       
   466 
       
   467     // Java Installer does not have AllFiles capability.
       
   468     // So if the .jad/.jar file is in the private data cage of
       
   469     // Remove Application Management system, it must be copied
       
   470     // to the private data cage of Java Installer in this
       
   471     // plugin which is executed in process which hopefully has
       
   472     // AllFiles capability.
       
   473     TRAP(err, CopyFilesIfNeededL(fileName));
       
   474     if (KErrNone != err)
       
   475     {
       
   476         TRequestStatus *statusPtr(&aStatus);
       
   477         User::RequestComplete(statusPtr, err);
       
   478         return;
       
   479     }
       
   480 
       
   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"));
       
   493     TBool isJad = EFalse;
       
   494     err = apaSession.RecognizeSpecificData(aFileHandle, jadFileMimeType, isJad);
       
   495     apaSession.Close();
       
   496     if (KErrNone != err)
       
   497     {
       
   498         ELOG1(EJavaInstaller,
       
   499               "CJavaSifPlugin::Install RApaLsSession RecognizeSpecificData error %d", err);
       
   500     }
       
   501     if (isJad)
       
   502     {
       
   503         // Installation should be started from JAD file
       
   504         commandLine.Append(_L(" -jad="));
       
   505     }
       
   506     else
       
   507     {
       
   508         // from JAR file
       
   509         commandLine.Append(_L(" -jar="));
       
   510     }
       
   511     // Filename parameter must be surrounded in double quotes to
       
   512     // ensure that spaces in filename are passed correctly.
       
   513     commandLine.Append(_L("\""));
       
   514     commandLine.Append(fileName);
       
   515     commandLine.Append(_L("\""));
       
   516 
       
   517     // Start JavaInstaller
       
   518     std::auto_ptr<HBufC> installerProcess(
       
   519         stringToDes(java::runtime::JAVA_PROCESS));
       
   520     err = rJavaInstaller.Create(installerProcess->Des(), commandLine);
       
   521     if (KErrNone == err)
       
   522     {
       
   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         }
       
   538         if (KErrNone != err)
       
   539         {
       
   540             // server cannot be started
       
   541             rJavaInstaller.Close();
       
   542             ELOG1(EJavaInstaller,
       
   543                   "CJavaSifPlugin::Install: Cannot start results server, err %d", err);
       
   544             TRequestStatus *statusPtr(&aStatus);
       
   545             User::RequestComplete(statusPtr, err);
       
   546             return;
       
   547         }
       
   548 
       
   549         // The status of the install operation == the exit status of Java Installer
       
   550         // It will be passed to the asynch caller through aStatus
       
   551         rJavaInstaller.Logon(aStatus);
       
   552     }
       
   553     else
       
   554     {
       
   555         rJavaInstaller.Close();
       
   556         ELOG1(EJavaInstaller,
       
   557               "CJavaSifPlugin::Install: starting JavaInstaller failed, err=%d", err);
       
   558         TRequestStatus *statusPtr(&aStatus);
       
   559         User::RequestComplete(statusPtr, err);
       
   560         return;
       
   561     }
       
   562 
       
   563     rJavaInstaller.Resume();
       
   564 
       
   565     // Do NOT close rJavaInstaller now -> the caller gets notification when the
       
   566     // process actually closes.
       
   567     iHandlesToClose.Append(rJavaInstaller);
       
   568 }
       
   569 
       
   570 void CJavaSifPlugin::Uninstall(
       
   571     TComponentId aComponentId,
       
   572     const TSecurityContext& aSecurityContext,
       
   573     const COpaqueNamedParams& aArguments,
       
   574     COpaqueNamedParams& /* aResults */,
       
   575     TRequestStatus& aStatus)
       
   576 {
       
   577     RProcess rJavaInstaller;
       
   578     TFileName fileName;
       
   579     // Max one uid and some options -> 256 is enough
       
   580     TBuf<256> commandLine;
       
   581 
       
   582     // Build command line used to pass all necessary info to Java Installer
       
   583     std::auto_ptr<HBufC> installerStarterDll(
       
   584         stringToDes(java::runtime::JAVA_INSTALLER_STARTER_DLL));
       
   585     commandLine = installerStarterDll->Des();
       
   586     commandLine.Append(_L(" uninstall"));
       
   587 
       
   588     commandLine.Append(_L(" -cid="));
       
   589     commandLine.AppendNum(aComponentId);
       
   590 
       
   591     // Check whether this is silent uninstallation
       
   592     TInt silentInstall = 0;
       
   593     TRAP_IGNORE(aArguments.GetIntByNameL(KSifInParam_InstallSilently, silentInstall));
       
   594     if (silentInstall)
       
   595     {
       
   596         // Silent uninstallation requires TrustedUI capability
       
   597         if (!aSecurityContext.HasCapability(ECapabilityTrustedUI))
       
   598         {
       
   599             ELOG(EJavaInstaller,
       
   600                  "CJavaSifPlugin::Uninstall The caller did not have TrustedUI capability");
       
   601             TRequestStatus *statusPtr(&aStatus);
       
   602             User::RequestComplete(statusPtr, KErrPermissionDenied);
       
   603             return;
       
   604         }
       
   605 
       
   606         commandLine.Append(_L(" -silent"));
       
   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.
       
   612 
       
   613     // start JavaInstaller
       
   614     std::auto_ptr<HBufC> installerProcess(
       
   615         stringToDes(java::runtime::JAVA_PROCESS));
       
   616     TInt err = rJavaInstaller.Create(installerProcess->Des(), commandLine);
       
   617     if (KErrNone == err)
       
   618     {
       
   619         // the exit status of Java Installer will be passed to
       
   620         // the asynch caller through aStatus
       
   621         rJavaInstaller.Logon(aStatus);
       
   622 
       
   623         rJavaInstaller.Resume();
       
   624     }
       
   625     else
       
   626     {
       
   627         rJavaInstaller.Close();
       
   628         ELOG1(EJavaInstaller,
       
   629              "CJavaSifPlugin::Uninstall: starting JavaInstaller failed, err=%d", err);
       
   630         TRequestStatus *statusPtr(&aStatus);
       
   631         User::RequestComplete(statusPtr, err);
       
   632         return;
       
   633     }
       
   634 
       
   635     // Do NOT close rJavaInstaller now -> the caller gets notification when the
       
   636     // process actually closes.
       
   637     iHandlesToClose.Append(rJavaInstaller);
       
   638 }
       
   639 
       
   640 void CJavaSifPlugin::Activate(
       
   641     TComponentId /* aComponentId */,
       
   642     const TSecurityContext& /* aSecurityContext */,
       
   643     TRequestStatus& aStatus)
       
   644 {
       
   645     // java applications are always active
       
   646     TRequestStatus *statusPtr(&aStatus);
       
   647     User::RequestComplete(statusPtr, KErrNone);
       
   648     return;
       
   649 }
       
   650 
       
   651 void CJavaSifPlugin::Deactivate(
       
   652     TComponentId /* aComponentId */,
       
   653     const TSecurityContext& /* aSecurityContext */,
       
   654     TRequestStatus& aStatus)
       
   655 {
       
   656     // java applications are always active
       
   657     TRequestStatus *statusPtr(&aStatus);
       
   658     User::RequestComplete(statusPtr, KErrNotSupported);
       
   659     return;
       
   660 }
       
   661 
       
   662 void CJavaSifPlugin::CancelOperation()
       
   663 {
       
   664     // Send cancel message to Java Installer
       
   665 
       
   666     // Check whether there is anything to cancel
       
   667     if (iHandlesToClose.Count() < 1)
       
   668     {
       
   669         // No Java Installer process running, do nothing
       
   670         WLOG(EJavaInstaller,
       
   671             "CJavaSifPlugin::CancelOperation: Cancel called but there is no operation to cancel");
       
   672         return;
       
   673     }
       
   674 
       
   675     try
       
   676     {
       
   677         CommsMessage message;
       
   678         message.setModuleId(PLUGIN_ID_SAMPLE_C);
       
   679         message.setReceiver(IPC_ADDRESS_JAVA_INSTALLER_SERVER_C);
       
   680         message.setSender(IPC_ADDRESS_JAVA_SIF_PLUGIN_C);
       
   681         message.setMessageId(INSTALLER_CANCEL_MESSAGE_ID);
       
   682 
       
   683         CommsMessage replyMessage;
       
   684         int timeout = 10; // 10 seconds
       
   685 
       
   686         CommsClientEndpoint comms;
       
   687         int err = comms.connect(IPC_ADDRESS_JAVA_INSTALLER_SERVER_C);
       
   688         if (KErrNone == err)
       
   689         {
       
   690             err = comms.sendReceive(message, replyMessage, timeout);
       
   691         }
       
   692         else
       
   693         {
       
   694             // Cannot connect to Java Installer Comms end point,
       
   695             // for example Java Installer is still starting up or
       
   696             // already exiting
       
   697             WLOG1(EJavaInstaller,
       
   698                 "CJavaSifPlugin:CancelOperation: Cannot connect to Java Installer "
       
   699                 "Comms end point, err %d", err);
       
   700             return;
       
   701         }
       
   702         if (err != 0)
       
   703         {
       
   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 
       
   716         // Ignore possible errors in disconnect
       
   717         (void)comms.disconnect();
       
   718     }
       
   719     catch (ExceptionBase& e)
       
   720     {
       
   721         ELOG1(EJavaInstaller,
       
   722               "CJavaSifPlugin: Send cancel msg failed: ExceptionBase caught: %s ",
       
   723               e.toString().c_str());
       
   724         return;
       
   725     }
       
   726     catch (std::exception& e)
       
   727     {
       
   728         ELOG1(EJavaInstaller,
       
   729               "CJavaSifPlugin: Send cancel msg failed: Exception %s caught", e.what());
       
   730         return;
       
   731     }
       
   732 
       
   733     // It takes some time before Java Installer had really cancelled
       
   734     // the operation and exited. Wait for it to happen because this function
       
   735     // must return only after the original asynchronous call is completed.
       
   736     TRequestStatus status;
       
   737     // This array contains process handles for all Java Installer processes
       
   738     // started from this sif plugin. The last handle is the active one.
       
   739     // Check if it is still running
       
   740     if (iHandlesToClose[iHandlesToClose.Count()-1].ExitReason() != 0)
       
   741     {
       
   742         // Process has already closed
       
   743         return;
       
   744     }
       
   745     // Wait until it exits
       
   746     iHandlesToClose[iHandlesToClose.Count()-1].Logon(status);
       
   747     User::WaitForRequest(status);
       
   748     // Ignore the exit status of Java Installer because current SIF API
       
   749     // does not return cancel result
       
   750 
       
   751     return;
       
   752 }
       
   753 
       
   754 void CJavaSifPlugin::CopyFilesIfNeededL(TFileName &aFileName)
       
   755 {
       
   756     // Check if the file is in the private data cage of some process
       
   757     TInt idx = aFileName.FindF(KPrivateDataCage);
       
   758     if ((idx != KErrNotFound) && (idx < 3))
       
   759     {
       
   760         // In case of device Inbox or Java Installer itself do nothing
       
   761         if ((aFileName.FindF(KInboxDataCage) != KErrNotFound) ||
       
   762                 (aFileName.FindF(KJavaInstallerDataCage) != KErrNotFound))
       
   763         {
       
   764             return;
       
   765         }
       
   766 
       
   767         // Copy ALL files with the same base filename as aFileName
       
   768         // to Java Installer tmp dir so that both .jad file and
       
   769         // the corresponding .jar file are copied.
       
   770         // (aFileName is <path>\<name>.<ext>, copy <path>\<name>.*
       
   771         // to Java Installer tmp dir.)
       
   772         TParse fp;
       
   773         iRFs.Parse(aFileName, fp);
       
   774 
       
   775         CFileMan* fm = CFileMan::NewL(iRFs);
       
   776         TFileName filesToCopy = fp.DriveAndPath();
       
   777         filesToCopy.Append(fp.Name());
       
   778         filesToCopy.Append(KAnyExtension);
       
   779         TInt err = fm->Copy(filesToCopy, KJavaInstallerTmp, CFileMan::ERecurse);
       
   780         delete fm;
       
   781         if (KErrNone != err)
       
   782         {
       
   783             ELOG1(EJavaInstaller,
       
   784                   "CJavaSifPlugin::CopyFilesIfNeededL: copying files "
       
   785                   "to Java Installer data cage failed, err=%d", err);
       
   786             User::Leave(err);
       
   787         }
       
   788 
       
   789         // aFileName must point to the copy of the file
       
   790         aFileName = fp.Drive();
       
   791         aFileName.Append(KJavaInstallerTmp);
       
   792         aFileName.Append(fp.NameAndExt());
       
   793     }
       
   794 
       
   795     return;
       
   796 }
       
   797 
       
   798 //  End of File