javamanager/javalauncher/src.s60/javalauncher.cpp
branchRCL_3
changeset 18 9ac0a0a7da70
parent 14 04becd199f91
child 24 6c158198356e
equal deleted inserted replaced
17:0fd27995241b 18:9ac0a0a7da70
     1 /*
     1 /*
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  The executable that enables launching OMJ Java
    14 * Description:  The executable that enables launching OMJ Java
    15 *                applications in S60
    15 *               applications in S60
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 #include <apacmdln.h>
    19 #include <apacmdln.h>
    20 #include <bacline.h>
    20 #include <bacline.h>
    40 using namespace java::captain;
    40 using namespace java::captain;
    41 using namespace java::storage;
    41 using namespace java::storage;
    42 using namespace java::util;
    42 using namespace java::util;
    43 
    43 
    44 
    44 
       
    45 _LIT(KHexValueStart, "0x");
       
    46 _LIT(KPercentage, "%");
    45 _LIT(KSemiColon, ";");
    47 _LIT(KSemiColon, ";");
       
    48 _LIT(KMidletNameArg, "midlet-name=");
       
    49 _LIT(KMidletVendorArg, "midlet-vendor=");
       
    50 _LIT(KMidletNArg, "midlet-n=");
       
    51 _LIT(KMidletUidArg, "midlet-uid=");
       
    52 
    46 
    53 
    47 const TInt KExtraLenForLoggingAndPrompting = 22;
    54 const TInt KExtraLenForLoggingAndPrompting = 22;
    48 const TInt KArgumentValueMaxLen = 1568;  // Support worst case % encoded args of 512 chars
    55 const TInt KArgumentValueMaxLen = 1568;  // Support worst case % encoded args of 512 chars
    49 
    56 
    50 // The Uid of the Web Browser process
    57 // The Uid of the Web Browser process
    56  * If aMidletName is empty, return the Uid of the first application in
    63  * If aMidletName is empty, return the Uid of the first application in
    57  * package aPackageId.
    64  * package aPackageId.
    58  *
    65  *
    59  * @param aJs           JavaStorage connection, must be open
    66  * @param aJs           JavaStorage connection, must be open
    60  * @param aPackageId    the id of the package
    67  * @param aPackageId    the id of the package
    61  * @param aMidletName   the name of the desired application in the package, can be empty
    68  * @param aMidletId     the numerical id of the desired application in the
       
    69  *                      package, can be empty
    62  * @param aUid          the Uid the found application is returned in this param
    70  * @param aUid          the Uid the found application is returned in this param
    63  * @return  KErrNone if Uid was found, otherwise one of the Symbian error codes
    71  * @return  KErrNone if Uid was found, otherwise one of the Symbian error codes
    64  * @throws  JavaStorageException if accessing Java Storage fails
    72  * @throws  JavaStorageException if accessing Java Storage fails
    65  */
    73  */
    66 static TInt getOneApplicationFromPackage(
    74 static TInt getOneApplicationFromPackage(
    67     JavaStorage& aJs,
    75     JavaStorage& aJs,
    68     const std::wstring& aPackageId,
    76     const std::wstring& aPackageId,
    69     const std::wstring& aMidletName,
    77     const std::wstring& aMidletId,
    70     TInt32 &aUid)
    78     TInt32 &aUid)
    71 {
    79 {
       
    80     std::wstring midletId = L"MIDlet-";
       
    81     if (aMidletId.length() == 0)
       
    82     {
       
    83         midletId.append(L"1");
       
    84     }
       
    85     else
       
    86     {
       
    87         midletId.append(aMidletId);
       
    88     }
       
    89 
    72     JavaStorageEntry attribute;
    90     JavaStorageEntry attribute;
    73     JavaStorageApplicationEntry_t findPattern;
    91     JavaStorageApplicationEntry_t findPattern;
    74     JavaStorageApplicationList_t  foundEntries;
    92     JavaStorageApplicationList_t  foundEntries;
    75 
    93 
    76     // Get ID from APPLICATION_TABLE based on PACKAGE_ID and NAME
    94 
       
    95     // Get MIDlet-n from APPLICATION_PACKAGE_ATTRIBUTES_TABLE based on 
       
    96     // PACKAGE_ID and NAME.
       
    97     attribute.setEntry(ID, aPackageId);
       
    98     findPattern.insert(attribute);
       
    99     attribute.setEntry(NAME, midletId);
       
   100     findPattern.insert(attribute);
       
   101     attribute.setEntry(VALUE, L"");
       
   102     findPattern.insert(attribute);
       
   103     aJs.search(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, findPattern, foundEntries);
       
   104 
       
   105     if (foundEntries.size() < 1)
       
   106     {
       
   107         return KErrNotFound;
       
   108     }
       
   109 
       
   110     // Found the MIDlet-n argument. Now getting the MIDlet name and 
       
   111     // main class. Name is the first argument and main class is the last
       
   112     // in the comma separated list.
       
   113     std::wstring value = foundEntries.front().begin()->entryValue();
       
   114     int pos = value.find_first_of(L",");
       
   115     std::wstring midletName = value.substr(0, pos);
       
   116     pos = value.find_last_of(L",");
       
   117     std::wstring className = value.substr(pos+1);
       
   118 
       
   119     // Trim white spaces.
       
   120     JavaCommonUtils::trimWstring(midletName, L' ');
       
   121     JavaCommonUtils::trimWstring(className, L' ');
       
   122     findPattern.clear();
       
   123     foundEntries.clear();
       
   124 
       
   125     // Get ID from APPLICATION_TABLE based on PACKAGE_ID and MAIN_CLASS
    77     attribute.setEntry(PACKAGE_ID, aPackageId);
   126     attribute.setEntry(PACKAGE_ID, aPackageId);
    78     findPattern.insert(attribute);
   127     findPattern.insert(attribute);
    79     if (aMidletName.length() > 0)
   128     attribute.setEntry(NAME, midletName);
    80     {
   129     findPattern.insert(attribute);
    81         attribute.setEntry(NAME, aMidletName);
   130     attribute.setEntry(MAIN_CLASS, className);
    82         findPattern.insert(attribute);
   131     findPattern.insert(attribute);
    83     }
       
    84     attribute.setEntry(ID, L"");
   132     attribute.setEntry(ID, L"");
    85     findPattern.insert(attribute);
   133     findPattern.insert(attribute);
    86 
   134 
    87     aJs.search(APPLICATION_TABLE, findPattern, foundEntries);
   135     aJs.search(APPLICATION_TABLE, findPattern, foundEntries);
    88 
   136 
   108  *
   156  *
   109  * @param aCmdLineBuf  The command line to be decoded.
   157  * @param aCmdLineBuf  The command line to be decoded.
   110  */
   158  */
   111 static void decodeCommandLineL(TPtr &aCmdLineBuf)
   159 static void decodeCommandLineL(TPtr &aCmdLineBuf)
   112 {
   160 {
   113     _LIT(KPercentage, "%");
       
   114     TInt ind = aCmdLineBuf.Find(KPercentage);
   161     TInt ind = aCmdLineBuf.Find(KPercentage);
   115     if (KErrNotFound == ind)
   162     if (KErrNotFound == ind)
   116     {
   163     {
   117         // nothing to decode
   164         // nothing to decode
   118         return;
   165         return;
   178 
   225 
   179 
   226 
   180 /**
   227 /**
   181  * Parse the names of the MIDlet suite and MIDlet vendor from aMidletCmdLine
   228  * Parse the names of the MIDlet suite and MIDlet vendor from aMidletCmdLine
   182  * parameter and use them to find the MIDlet suite from Java Storage.
   229  * parameter and use them to find the MIDlet suite from Java Storage.
   183  * Then return Uid of the named MIDlet or if 'midlet-n' argument is not given
   230  * Then return Uid of the named MIDlet or if 'midlet-app-name' argument is not given
   184  * in command line, the Uid of the first MIDlet in the suite.
   231  * in command line, the Uid of the first MIDlet in the suite.
   185  * Return the uid of the MIDlet in aUid.
   232  * Return the uid of the MIDlet in aUid.
   186  *
   233  *
   187  * @param aMidletCmdLine the command line that contains at least midlet-name
   234  * @param aMidletCmdLine the command line that contains at least midlet-name
   188  *  and midlet-vendor arguments
   235  *  and midlet-vendor arguments
   190  * @return KErrNone if MIDlet was found. KErrPathNotFound if MIDlet is not found.
   237  * @return KErrNone if MIDlet was found. KErrPathNotFound if MIDlet is not found.
   191  *  Standard Symbian error codes in other cases.
   238  *  Standard Symbian error codes in other cases.
   192  */
   239  */
   193 static TInt getUidByNames(const TPtrC &aMidletCmdLine, TInt32 &aUid)
   240 static TInt getUidByNames(const TPtrC &aMidletCmdLine, TInt32 &aUid)
   194 {
   241 {
   195     _LIT(KMidletNameArg, "midlet-name=");
       
   196     _LIT(KMidletVendorArg, "midlet-vendor=");
       
   197     _LIT(KMidletNArg, "midlet-n=");
       
   198 
       
   199     TInt err = aMidletCmdLine.FindF(KMidletNameArg);
   242     TInt err = aMidletCmdLine.FindF(KMidletNameArg);
   200     if (KErrNotFound == err)
   243     if (KErrNotFound == err)
   201     {
   244     {
   202         return KErrArgument;
   245         return KErrArgument;
   203     }
   246     }
   207         return KErrArgument;
   250         return KErrArgument;
   208     }
   251     }
   209 
   252 
   210     std::wstring suiteName = getArgValue(aMidletCmdLine, KMidletNameArg);
   253     std::wstring suiteName = getArgValue(aMidletCmdLine, KMidletNameArg);
   211     std::wstring vendorName = getArgValue(aMidletCmdLine, KMidletVendorArg);
   254     std::wstring vendorName = getArgValue(aMidletCmdLine, KMidletVendorArg);
   212     std::wstring midletName = getArgValue(aMidletCmdLine, KMidletNArg);
   255     std::wstring midletId = getArgValue(aMidletCmdLine, KMidletNArg);
   213 
   256 
   214     if (suiteName.empty() || vendorName.empty())
   257     if (suiteName.empty() || vendorName.empty())
   215     {
   258     {
   216         return KErrArgument;
   259         return KErrArgument;
   217     }
   260     }
   245             LOG1WSTR(EJavaCaptain, EInfo,
   288             LOG1WSTR(EJavaCaptain, EInfo,
   246                      "JavaLauncher: getUidByNamesL: Found suite uid by name. Uid is %s",
   289                      "JavaLauncher: getUidByNamesL: Found suite uid by name. Uid is %s",
   247                      value.c_str());
   290                      value.c_str());
   248 
   291 
   249             // Now find the Uid of the first or specified application in the package
   292             // Now find the Uid of the first or specified application in the package
   250             err = getOneApplicationFromPackage(*js, value, midletName, aUid);
   293             err = getOneApplicationFromPackage(*js, value, midletId, aUid);
   251         }
   294         }
   252         else
   295         else
   253         {
   296         {
   254             err = KErrPathNotFound;
   297             err = KErrPathNotFound;
   255         }
   298         }
   351  * command line given in aMidletCmdLine or find the midlet
   394  * command line given in aMidletCmdLine or find the midlet
   352  * based on the 'midlet-name' and 'midlet-vendor' from
   395  * based on the 'midlet-name' and 'midlet-vendor' from
   353  * Java Storage / AppArc and return the Uid of the midlet.
   396  * Java Storage / AppArc and return the Uid of the midlet.
   354  *
   397  *
   355  * @param aMidletCmdLine  command line to be parsed, the format is
   398  * @param aMidletCmdLine  command line to be parsed, the format is
   356  *  [midlet-name=XXX;midlet-vendor=XXX;|midlet-uid=YYY;]midlet-args=XXX
   399  *  [midlet-name=XXX;midlet-vendor=XXX;|midlet-uid=YYY;]<midlet_args>
   357  * @param aUid will contain the Uid parsed from command line
   400  * @param aUid will contain the Uid parsed from command line
   358  * @return KErrNone if the command line specified Uid
   401  * @return KErrNone if the command line specified Uid
   359  */
   402  */
   360 static TInt getUidFromCommandLine(const TPtrC &aMidletCmdLine, TInt32 &aUid)
   403 static TInt getUidFromCommandLine(const TPtrC &aMidletCmdLine, TInt32 &aUid)
   361 {
   404 {
   362     _LIT(KMidletUidArg, "midlet-uid=");
       
   363     _LIT(KHexValueStart, "0x");
       
   364     TInt err(KErrNone);
   405     TInt err(KErrNone);
   365     TInt argPos = aMidletCmdLine.FindF(KMidletUidArg);
   406     TInt argPos = aMidletCmdLine.FindF(KMidletUidArg);
   366     if (KErrNotFound != argPos)
   407     if (KErrNotFound != argPos)
   367     {
   408     {
   368         TPtrC uidToParse = aMidletCmdLine.Mid(argPos + KMidletUidArg.iTypeLength);
   409         TPtrC uidToParse = aMidletCmdLine.Mid(argPos + KMidletUidArg.iTypeLength);
   439     // The following feature is not supported yet.
   480     // The following feature is not supported yet.
   440     // It needs changes also to Java Installer and to
   481     // It needs changes also to Java Installer and to
   441     // Symbian Settings UI
   482     // Symbian Settings UI
   442     TInt maxExtraSpaceForDocumentArg = 0;
   483     TInt maxExtraSpaceForDocumentArg = 0;
   443 #ifdef RD_JAVA_SUPPORT_JAVA_APPS_AS_MIME_TYPE_HANDLERS
   484 #ifdef RD_JAVA_SUPPORT_JAVA_APPS_AS_MIME_TYPE_HANDLERS
   444     _LIT(KDocumentOnlyCmdLine, "midlet-args=document=");
   485     _LIT(KDocumentOnlyCmdLine, "document=");
   445     TFullName documentName;
   486     TFullName documentName;
   446     documentName = commandLine->DocumentName();
   487     documentName = commandLine->DocumentName();
   447     if (documentName.Length() > 0)
   488     if (documentName.Length() > 0)
   448     {
   489     {
   449         maxExtraSpaceForDocumentArg =
   490         maxExtraSpaceForDocumentArg =
   539                  (wchar_t *)(cmdLineBuf.PtrZ()));
   580                  (wchar_t *)(cmdLineBuf.PtrZ()));
   540     }
   581     }
   541 
   582 
   542     // Uid has already been determined, the whole command line is not needed
   583     // Uid has already been determined, the whole command line is not needed
   543     // anymore, only the arguments for the Java application
   584     // anymore, only the arguments for the Java application
   544     _LIT(KMidletArgs, "midlet-args=");
   585 
   545     TInt  argsPos = cmdLineBuf.FindF(KMidletArgs);
   586     // Find the last argument that is used to identify the MIDlet
   546     TBool cmdLineIsNotEmpty = EFalse;
   587     TBool cmdLineIsNotEmpty = EFalse;
   547     if (argsPos >= 0)
   588     TInt  lastArgPos = cmdLineBuf.FindF(KMidletUidArg);
   548     {
   589     TInt  currArgPos = cmdLineBuf.FindF(KMidletNArg);
   549         // Pass everything that follows "midlet-args="
   590     if (currArgPos > lastArgPos)
   550         cmdLineBuf.Delete(0, argsPos + KMidletArgs.iTypeLength);
   591     {
       
   592         lastArgPos = currArgPos;
       
   593     }
       
   594     currArgPos = cmdLineBuf.FindF(KMidletVendorArg);
       
   595     if (currArgPos > lastArgPos)
       
   596     {
       
   597         lastArgPos = currArgPos;
       
   598     }
       
   599     currArgPos = cmdLineBuf.FindF(KMidletNameArg);
       
   600     if (currArgPos > lastArgPos)
       
   601     {
       
   602         lastArgPos = currArgPos;
       
   603     }
       
   604 
       
   605     // Find the place where the last identity argument ends
       
   606     cmdLineBuf.Delete(0, lastArgPos);
       
   607     lastArgPos = cmdLineBuf.Find(KSemiColon);
       
   608     if (lastArgPos >= 0)
       
   609     {
       
   610         // Pass everything that follows "<last_identity_arg_name>=....;"
       
   611         cmdLineBuf.Delete(0, lastArgPos + 1);
   551         cmdLineIsNotEmpty = ETrue;
   612         cmdLineIsNotEmpty = ETrue;
   552     }
   613     }
   553     else
   614     else
   554     {
   615     {
   555         // No arguments for the Java application
   616         // No arguments for the Java application
   735  * This executable can be started also directly from other native processes
   796  * This executable can be started also directly from other native processes
   736  * to start a Java application with arguments specified in normal process
   797  * to start a Java application with arguments specified in normal process
   737  * command line.
   798  * command line.
   738  *
   799  *
   739  * The command line format is
   800  * The command line format is
   740  * [midlet-name=XXX;midlet-vendor=XXX;[midlet-n=XXX;]|midlet-uid=YYY;]midlet-args=XXX
   801  * [midlet-name=XXX;midlet-vendor=XXX;[midlet-app-name=XXX;]|midlet-uid=YYY;]<midlet_args>
   741  * for example
   802  * for example
   742  * midlet-name=Chess;midlet-vendor=Nokia;midlet-args=startMode=playChessDemo;sound=off;
   803  * midlet-name=Chess;midlet-vendor=Nokia;startMode=playChessDemo;sound=off;
   743  * 'midlet-args' specifies the arguments passed to Java application.
   804  * 'midlet-uid' or 'midlet-name'+'midlet-vendor'+ optional 'midlet-app-name' specify
   744  * 'midlet-uid' or 'midlet-name'+'midlet-vendor' specify the Java application to be started
   805  * the Java application to be started
   745  *
   806  *
   746  * Sample code for starting MIDlet from native code
   807  * Sample code for starting MIDlet from native code
   747  * @code
   808  * @code
   748     RProcess rProcess;
   809     RProcess rProcess;
   749     TInt err = rProcess.Create(_L("javalauncher.exe"),
   810     TInt err = rProcess.Create(_L("javalauncher.exe"),
   750         _L("midlet-uid=0x10137c4d;midlet-args=startMode=startFromCmdLine;sound=ON;landscapeMode=true;"));
   811         _L("midlet-uid=0x10137c4d;startMode=startFromCmdLine;sound=ON;landscapeMode=true;"));
   751     if (KErrNone == err)
   812     if (KErrNone == err)
   752     {
   813     {
   753         TRequestStatus status;
   814         TRequestStatus status;
   754         rProcess.Logon(status);
   815         rProcess.Logon(status);
   755         rProcess.Resume();
   816         rProcess.Resume();