javamanager/javaupgradeapp/src.s60/javaupgradeapp.cpp
branchGCC_SURGE
changeset 55 d93ef1df440d
parent 35 85266cc22c7f
parent 48 e0d6e9bd3ca7
equal deleted inserted replaced
43:6d7ae91094e7 55:d93ef1df440d
    24 #include <s32mem.h>
    24 #include <s32mem.h>
    25 #include <unistd.h>
    25 #include <unistd.h>
    26 
    26 
    27 #include "exceptionbase.h"
    27 #include "exceptionbase.h"
    28 #include "javaoslayer.h"
    28 #include "javaoslayer.h"
       
    29 #include "javacommonutils.h"
    29 #include "javaprocessconstants.h"
    30 #include "javaprocessconstants.h"
    30 #include "javasymbianoslayer.h"
    31 #include "javasymbianoslayer.h"
    31 #include "javauids.h"
    32 #include "javauids.h"
    32 #include "logger.h"
    33 #include "logger.h"
    33 
    34 
    34 
    35 
    35 using namespace java::util;
    36 using namespace java::util;
    36 
    37 
    37 
    38 
    38 _LIT(KHexValueStart, "0x");
    39 _LIT8(KHexValueStart, "0x");
    39 _LIT(KSemiColon, ";");
    40 _LIT8(KSemiColon, ";");
    40 _LIT(KUidArg, "uid=");
    41 _LIT8(KUidArg, "uid=");
    41 _LIT(KFileArg, "file=");
    42 _LIT8(KFileArg, "file=");
    42 
    43 
    43 const TInt KExtraLenForLogging = 2;
    44 const TInt KExtraLenForLogging = 2;
    44 const TInt KArgumentValueMaxLen = 1568;
    45 const TInt KArgumentValueMaxLen = 1568;
    45 // Wait for 0.5 sec if ArcApp has not yet initialized
    46 // Wait for 0.5 sec if ArcApp has not yet initialized
    46 const TInt KDelayWhenWaitingAppArc = 500000;
    47 const TInt KDelayWhenWaitingAppArc = 500000;
    51  *
    52  *
    52  * @param aCmdLine command line to be parsed
    53  * @param aCmdLine command line to be parsed
    53  * @param aArgName the name of the argument
    54  * @param aArgName the name of the argument
    54  * @param aArgValue the value parsed from command line will be returned here
    55  * @param aArgValue the value parsed from command line will be returned here
    55  */
    56  */
    56 static void getArgValueL(const TPtrC &aCmdLine, const TDesC &aArgName, HBufC **aArgValue)
    57 static void getArgValueL(const TPtrC8 &aCmdLine, const TDesC8 &aArgName, HBufC **aArgValue)
    57 {
    58 {
    58     TBuf<KArgumentValueMaxLen> valueBuf;
    59     TBuf8<KArgumentValueMaxLen> valueBuf;
    59     TInt argPos = aCmdLine.FindF(aArgName);
    60     TInt argPos = aCmdLine.FindF(aArgName);
    60     if (argPos >= 0)
    61     if (argPos >= 0)
    61     {
    62     {
    62         TInt semicolonPos = aCmdLine.Mid(argPos).Find(KSemiColon);
    63         TInt semicolonPos = aCmdLine.Mid(argPos).Find(KSemiColon);
    63         if (KErrNotFound == semicolonPos)
    64         if (KErrNotFound == semicolonPos)
    79         }
    80         }
    80 
    81 
    81         valueBuf = aCmdLine.Mid(argPos + aArgName.Length(),  argLen);
    82         valueBuf = aCmdLine.Mid(argPos + aArgName.Length(),  argLen);
    82     }
    83     }
    83 
    84 
    84     // Allocate new HBufC and return it
    85     // Allocate new HBufC
    85     HBufC *pBufValue = HBufC::NewL(valueBuf.Length() + 2);
    86     HBufC *pBufValue = HBufC::NewL(valueBuf.Length() + 2);
    86     *pBufValue = valueBuf;
    87 
       
    88     // Convert argument from UTF8 to UCS-2 (UTF16)
       
    89     std::wstring tmp = JavaCommonUtils::utf8ToWstring((const char *)valueBuf.PtrZ());
       
    90 
       
    91     // Return the argument inside the new HBufC
       
    92     *pBufValue = (const TUint16 *)(tmp.c_str());
    87     *aArgValue = pBufValue;
    93     *aArgValue = pBufValue;
    88 }
    94 }
    89 
    95 
    90 
    96 
    91 /**
    97 /**
    94  *
   100  *
    95  * @param aCmdLine  command line to be parsed, the format is
   101  * @param aCmdLine  command line to be parsed, the format is
    96  *  <other_args>;file=YYY;<other_args>
   102  *  <other_args>;file=YYY;<other_args>
    97  * @param aFileName will contain the name parsed from command line
   103  * @param aFileName will contain the name parsed from command line
    98  */
   104  */
    99 static void getNameFromCommandLineL(const TPtrC &aCmdLine, HBufC **aFileName)
   105 static void getNameFromCommandLineL(const TPtrC8 &aCmdLine, HBufC **aFileName)
   100 {
   106 {
   101     TInt err = aCmdLine.FindF(KFileArg);
   107     TInt err = aCmdLine.FindF(KFileArg);
   102     User::LeaveIfError(err);
   108     User::LeaveIfError(err);
   103 
   109 
   104     getArgValueL(aCmdLine, KFileArg, aFileName);
   110     getArgValueL(aCmdLine, KFileArg, aFileName);
   111  *
   117  *
   112  * @param aCmdLine  command line to be parsed, the format is
   118  * @param aCmdLine  command line to be parsed, the format is
   113  *  uid=YYY;<other_args>
   119  *  uid=YYY;<other_args>
   114  * @param aUid will contain the Uid parsed from command line
   120  * @param aUid will contain the Uid parsed from command line
   115  */
   121  */
   116 static void getUidFromCommandLineL(const TPtrC &aCmdLine, TInt32 &aUid)
   122 static void getUidFromCommandLineL(const TPtrC8 &aCmdLine, TInt32 &aUid)
   117 {
   123 {
   118     TInt err(KErrNone);
   124     TInt err(KErrNone);
   119     TInt argPos = aCmdLine.FindF(KUidArg);
   125     TInt argPos = aCmdLine.FindF(KUidArg);
   120     if (KErrNotFound != argPos)
   126     if (KErrNotFound != argPos)
   121     {
   127     {
   122         TPtrC uidToParse = aCmdLine.Mid(argPos + KUidArg.iTypeLength);
   128         TPtrC8 uidToParse = aCmdLine.Mid(argPos + KUidArg.iTypeLength);
   123         TLex parseUid(uidToParse);
   129         TLex8 parseUid(uidToParse);
   124         if (uidToParse.FindF(KHexValueStart) == 0)
   130         if (uidToParse.FindF(KHexValueStart) == 0)
   125         {
   131         {
   126             parseUid.Inc(2); // skip hex prefix
   132             parseUid.Inc(2); // skip hex prefix
   127             TUint32 tmpValue;
   133             TUint32 tmpValue;
   128             err = parseUid.Val(tmpValue, EHex);
   134             err = parseUid.Val(tmpValue, EHex);
   161  * @param aFileName returns value of argument 'file'
   167  * @param aFileName returns value of argument 'file'
   162  * @param aUid returns Uid of the Java application to be uninstalled
   168  * @param aUid returns Uid of the Java application to be uninstalled
   163  */
   169  */
   164 void getFileAndUidL(HBufC **aFileName, TInt32 *aUid)
   170 void getFileAndUidL(HBufC **aFileName, TInt32 *aUid)
   165 {
   171 {
   166     HBufC *pBufCmdLine =
   172     CApaCommandLine* commandLine;
   167         HBufC::NewLC(User::CommandLineLength() + KExtraLenForLogging);
   173 
   168     TPtr cmdLineBuf = pBufCmdLine->Des();
   174     // CApaCommandLine command line is used when this application has been
   169     User::CommandLine(cmdLineBuf);
   175     // launched using AppArc APIs.
   170 
   176     TInt err = CApaCommandLine::GetCommandLineFromProcessEnvironment(commandLine);
   171     if (cmdLineBuf.Length() > 0)
   177     if (KErrNone != err)
   172     {
   178     {
   173         LOG1WSTR(EUtils, EInfo,
   179         ELOG1(EUtils, "javaupgradeapp: Getting CApaCommandLine failed, err %d", err);
   174                  "javaupgradeapp: full java application cmd line is : %s",
   180         User::Leave(err);
   175                  (wchar_t *)(cmdLineBuf.PtrZ()));
   181     }
       
   182     CleanupStack::PushL(commandLine);
       
   183 
       
   184     // Get the value of _application-args_
       
   185     TPtrC8 args = commandLine->TailEnd();
       
   186     HBufC8 *pBufCmdLine =
       
   187         HBufC8::NewLC(args.Length() + KExtraLenForLogging);
       
   188     if (args.Length() > 0)
       
   189     {
       
   190         // Copy the arguments to the new HBufC8
       
   191         TPtr8 cmdLineBuf = pBufCmdLine->Des();
       
   192         cmdLineBuf = args;
       
   193 
       
   194         LOG1(EUtils, EInfo,
       
   195             "javaupgradeapp: full cmd line is : %s",
       
   196             cmdLineBuf.PtrZ());
   176 
   197 
   177         // Get the midlet uid from the commandline
   198         // Get the midlet uid from the commandline
   178         TRAPD(err, getUidFromCommandLineL(cmdLineBuf, *aUid));
   199         TRAPD(err, getUidFromCommandLineL(cmdLineBuf, *aUid));
   179         // It is enough that either midlet uid OR installation package name
   200         // It is enough that either midlet uid OR installation package name
   180         // have been given in commandline
   201         // have been given in commandline
   206         ELOG(EUtils, "javaupgradeapp: empty command line");
   227         ELOG(EUtils, "javaupgradeapp: empty command line");
   207         User::Leave(KErrArgument);
   228         User::Leave(KErrArgument);
   208     }
   229     }
   209 
   230 
   210     CleanupStack::PopAndDestroy(pBufCmdLine);
   231     CleanupStack::PopAndDestroy(pBufCmdLine);
       
   232     CleanupStack::PopAndDestroy(commandLine);
   211 }
   233 }
   212 
   234 
   213 
   235 
   214 /**
   236 /**
   215  * Uninstall the java application specified by aUid parameter.
   237  * Uninstall the java application specified by aUid parameter.
   231     // Use command line options that make sure that uninstallation is done
   253     // Use command line options that make sure that uninstallation is done
   232     // always, silently and so that the uninstalled java application will
   254     // always, silently and so that the uninstalled java application will
   233     // be preinstalled again if the user uninstalls it
   255     // be preinstalled again if the user uninstalls it
   234     commandLine.Append(_L(" uninstall -uid="));
   256     commandLine.Append(_L(" uninstall -uid="));
   235     commandLine.AppendNum(aUid);
   257     commandLine.AppendNum(aUid);
   236     commandLine.Append(_L(" -forceuninstall -silent -preinstall_always"));
   258     commandLine.Append(_L(" -forceuninstall -silent -resetpreinstall"));
   237 
   259 
   238     LOG1WSTR(EUtils, EInfo,
   260     LOG1WSTR(EUtils, EInfo,
   239         "javaupgradeapp:uninstallJavaAppL Java Installer command line is %s",
   261         "javaupgradeapp:uninstallJavaAppL Java Installer command line is %s",
   240         (wchar_t *)(commandLine.PtrZ()));
   262         (wchar_t *)(commandLine.PtrZ()));
   241 
   263 
   302             // Application list has not yet been populated,
   324             // Application list has not yet been populated,
   303             // try again after a short delay
   325             // try again after a short delay
   304             retryCounter--;
   326             retryCounter--;
   305             if (retryCounter > 0)
   327             if (retryCounter > 0)
   306             {
   328             {
   307                 User::After(KDelayWhenWaitingAppArc);
   329                 User::After(KDelayWhenWaitingAppArc); // codescanner::userafter
   308                 continue;
   330                 continue;
   309             }
   331             }
   310             else
   332             else
   311             {
   333             {
   312                 ELOG(EUtils,
   334                 ELOG(EUtils,
   342 
   364 
   343     getFileAndUidL(&pBufFileName, &uid);
   365     getFileAndUidL(&pBufFileName, &uid);
   344 
   366 
   345     if (uid != 0)
   367     if (uid != 0)
   346     {
   368     {
   347         LOG1(
   369         PLOG1(EUtils, "javaupgradeapp uninstalling app uid %x", uid);
   348             EUtils,
       
   349             EInfo,
       
   350             "javaupgradeapp uninstalling app uid %d", uid);
       
   351         uninstallJavaAppL(uid);
   370         uninstallJavaAppL(uid);
   352     }
   371     }
       
   372     else
       
   373     {
       
   374         WLOG(EUtils, "javaupgradeapp: uid argument was not given");
       
   375     }
   353 
   376 
   354     if (pBufFileName != NULL)
   377     if (pBufFileName != NULL)
   355     {
   378     {
   356         LOG1WSTR(EUtils, EInfo,
   379         PLOG1WSTR(EUtils,
   357             "javaupgradeapp: installing new app package %s",
   380             "javaupgradeapp: installing new app package %s",
   358             (wchar_t *)(pBufFileName->Des().PtrZ()));
   381             (wchar_t *)(pBufFileName->Des().PtrZ()));
   359         installAppPackageL(pBufFileName);
   382         installAppPackageL(pBufFileName);
   360 
   383 
   361         delete pBufFileName;
   384         delete pBufFileName;
       
   385     }
       
   386     else
       
   387     {
       
   388         WLOG(EUtils, "javaupgradeapp: file argument was not given");
   362     }
   389     }
   363 }
   390 }
   364 
   391 
   365 
   392 
   366 /**
   393 /**