javamanager/javainstaller/installer/src.s60/applicationregistrator/applicationregistrator.cpp
branchRCL_3
changeset 83 26b2b12093af
parent 60 6c158198356e
equal deleted inserted replaced
77:7cee158cb8cd 83:26b2b12093af
    28 #include <apacmdln.h>
    28 #include <apacmdln.h>
    29 #include <centralrepository.h>
    29 #include <centralrepository.h>
    30 #include <AknUtils.h>
    30 #include <AknUtils.h>
    31 #include <hal.h>
    31 #include <hal.h>
    32 
    32 
    33 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
    34 #include <SWInstLogTaskParam.h>
       
    35 #include <SWInstTask.h>
       
    36 #include <SWInstTaskManager.h>
       
    37 #endif // !SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
    38 
       
    39 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
    33 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
    40 #include <apgicnfl.h>
    34 #include <apgicnfl.h>
    41 #else
    35 #else
    42 #include <apgicnflpartner.h>
    36 #include <apgicnflpartner.h>
    43 #endif
    37 #endif
    54 #include "javacommonutils.h"
    48 #include "javacommonutils.h"
    55 #include "logger.h"
    49 #include "logger.h"
    56 
    50 
    57 // NAMESPACE DECLARATION
    51 // NAMESPACE DECLARATION
    58 using namespace java;
    52 using namespace java;
    59 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    53 
    60 using namespace SwiUI;
       
    61 #endif // !SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
    62 
       
    63 IMPORT_C HBufC* CreateHBufCFromJavaStringLC(JNIEnv* aEnv, jstring aString);
       
    64 
       
    65 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
    66 /**
    54 /**
    67  * MIDP Stub SIS file UID. The application type Uid for MIDlets in S60
    55  * MIDP Stub SIS file UID. The application type Uid for MIDlets in S60
    68  */
    56  */
    69 const TUid KMidletApplicationTypeUid = { 0x10210E26 };
    57 const TUid KMidletApplicationTypeUid = { 0x10210E26 };
    70 
    58 
    97                           jint aUid, HBufC16 *aGroupName, HBufC16 *aMIDletName, HBufC16 *aTargetDrive,
    85                           jint aUid, HBufC16 *aGroupName, HBufC16 *aMIDletName, HBufC16 *aTargetDrive,
    98                           HBufC16 *aIconFileName, HBufC16 *aJarFileName, jboolean aHidden,
    86                           HBufC16 *aIconFileName, HBufC16 *aJarFileName, jboolean aHidden,
    99                           jboolean aBackground);
    87                           jboolean aBackground);
   100 
    88 
   101 /**
    89 /**
       
    90  * Internal helper method for checking whether Application Shell is already running
       
    91  * Used JNI method ...1startAppShellUi
       
    92  *
       
    93  * @return ETrue if AppShell is running
       
    94  */
       
    95 TBool isAppShellUiRunning();
       
    96 
       
    97 /**
   102  * Internal helper method for checking whether this code is executing in
    98  * Internal helper method for checking whether this code is executing in
   103  * a device that has correctly working version of
    99  * a device that has correctly working version of
   104  * RApaLsSession::ForceCommitNonNativeApplicationsUpdatesL()
   100  * RApaLsSession::ForceCommitNonNativeApplicationsUpdatesL()
   105  *
   101  *
   106  * @return ETrue if force commit works well
   102  * @return ETrue if force commit works well
   107  */
   103  */
   108 TBool isForceCommitSupported();
   104 TBool isForceCommitSupported();
   109 #endif // !SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   110 
       
   111 /**
       
   112  * Internal helper method for checking whether Application Shell is already running
       
   113  * Used JNI method ...1startAppShellUi
       
   114  *
       
   115  * @return ETrue if AppShell is running
       
   116  */
       
   117 TBool isAppShellUiRunning();
       
   118 
   105 
   119 /**
   106 /**
   120  * Internal helper method for starting menu application
   107  * Internal helper method for starting menu application
   121  *
   108  *
   122  * @return KErrNone or Symbian error code
   109  * @return KErrNone or Symbian error code
   147     {
   134     {
   148         // Cannot connect to AppArc server
   135         // Cannot connect to AppArc server
   149         return err;
   136         return err;
   150     }
   137     }
   151 
   138 
   152 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   139 #if 1
       
   140 //#ifndef RD_JAVA_USIF_APP_REG
   153     // Delete any pending (un)registrations (possible if
   141     // Delete any pending (un)registrations (possible if
   154     // e.g. device rebooted before commit).
   142     // e.g. device rebooted before commit).
   155     // This call does nothing if there is no pending registrations.
   143     // This call does nothing if there is no pending registrations.
   156     // Ignore errors.
   144     // Ignore errors.
   157     (void)pApaSession->RollbackNonNativeApplicationsUpdates();
   145     (void)pApaSession->RollbackNonNativeApplicationsUpdates();
   162     {
   150     {
   163         // Close session and return error
   151         // Close session and return error
   164         pApaSession->Close();
   152         pApaSession->Close();
   165         return err;
   153         return err;
   166     }
   154     }
   167 #endif // !SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   155 #endif // RD_JAVA_USIF_APP_REG
   168 
   156 
   169     // Return handle to session. Utilize the fact that in Symbian
   157     // Return handle to session. Utilize the fact that in Symbian
   170     // all pointer addresses are MOD 4 so the last 2 bits are 0
   158     // all pointer addresses are MOD 4 so the last 2 bits are 0
   171     // and can be shifted out. This way the returned handle is
   159     // and can be shifted out. This way the returned handle is
   172     // always positive whereas Symbian error codes are always negative.
   160     // always positive whereas Symbian error codes are always negative.
   186  * @param[in] aJarFileName The full path name of the jar file
   174  * @param[in] aJarFileName The full path name of the jar file
   187  * @param[in] aHidden
   175  * @param[in] aHidden
   188  * @param[in] aBackground
   176  * @param[in] aBackground
   189  * @return 0 if registration succeeded or Symbian error code
   177  * @return 0 if registration succeeded or Symbian error code
   190  */
   178  */
   191 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   179 #if 0
       
   180 //#ifdef RD_JAVA_USIF_APP_REG
   192 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_ApplicationRegistrator__1registerApplication
   181 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_ApplicationRegistrator__1registerApplication
   193 (JNIEnv */*aEnv*/, jclass /*aClass*/, jint /*aSessionHandle*/, jint /*aUid*/, jstring /*aGroupName*/,
   182 (JNIEnv */*aEnv*/, jclass /*aClass*/, jint /*aSessionHandle*/, jint /*aUid*/, jstring /*aGroupName*/,
   194  jstring /*aMIDletName*/, jstring /*aTargetDrive*/, jstring /*aIconFileName*/,
   183  jstring /*aMIDletName*/, jstring /*aTargetDrive*/, jstring /*aIconFileName*/,
   195  jstring /*aJarFileName*/, jboolean /*aHidden*/, jboolean /*aBackground*/)
   184  jstring /*aJarFileName*/, jboolean /*aHidden*/, jboolean /*aBackground*/)
   196 {
   185 {
   197     return KErrNone;
   186     return KErrNone;
   198 }
   187 }
   199 #else // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   188 #else
   200 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_ApplicationRegistrator__1registerApplication
   189 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_ApplicationRegistrator__1registerApplication
   201 (JNIEnv *aEnv, jclass aClass, jint aSessionHandle, jint aUid, jstring aGroupName,
   190 (JNIEnv *aEnv, jclass aClass, jint aSessionHandle, jint aUid, jstring aGroupName,
   202  jstring aMIDletName, jstring aTargetDrive, jstring aIconFileName,
   191  jstring aMIDletName, jstring aTargetDrive, jstring aIconFileName,
   203  jstring aJarFileName, jboolean aHidden, jboolean aBackground)
   192  jstring aJarFileName, jboolean aHidden, jboolean aBackground)
   204 {
   193 {
   361     delete unicodeTargetDrive;
   350     delete unicodeTargetDrive;
   362     delete unicodeJarFileName;
   351     delete unicodeJarFileName;
   363 
   352 
   364     return err;
   353     return err;
   365 }
   354 }
       
   355 #endif // RD_JAVA_USIF_APP_REG
   366 
   356 
   367 
   357 
   368 /**
   358 /**
   369  * See JNI method __1registerApplication.
   359  * See JNI method __1registerApplication.
   370  * This method makes all calls that may leave (the actual registering)
   360  * This method makes all calls that may leave (the actual registering)
   492     // close file server connection
   482     // close file server connection
   493     CleanupStack::PopAndDestroy(&fileServ);
   483     CleanupStack::PopAndDestroy(&fileServ);
   494 
   484 
   495     return err;
   485     return err;
   496 }
   486 }
   497 #endif // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   498 
   487 
   499 
   488 
   500 /**
   489 /**
   501  * Unregisters Java Application from S60 AppArc
   490  * Unregisters Java Application from S60 AppArc
   502  *
   491  *
   503  * @param[in] aSessionHandle
   492  * @param[in] aSessionHandle
   504  * @param[in] aUid The Uid of the application to be unregistered..
   493  * @param[in] aUid The Uid of the application to be unregistered..
   505  * @return 0 if unregistration succeeded or Symbian error code
   494  * @return 0 if unregistration succeeded or Symbian error code
   506  */
   495  */
   507 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   496 #if 0
       
   497 //#ifdef RD_JAVA_USIF_APP_REG
   508 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_ApplicationRegistrator__1unregisterApplication
   498 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_ApplicationRegistrator__1unregisterApplication
   509 (JNIEnv *, jclass, jint /*aSessionHandle*/, jint /*aUid*/)
   499 (JNIEnv *, jclass, jint /*aSessionHandle*/, jint /*aUid*/)
   510 {
   500 {
   511     return KErrNone;
   501     return KErrNone;
   512 }
   502 }
   513 #else // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   503 #else
   514 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_ApplicationRegistrator__1unregisterApplication
   504 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_ApplicationRegistrator__1unregisterApplication
   515 (JNIEnv *, jclass, jint aSessionHandle, jint aUid)
   505 (JNIEnv *, jclass, jint aSessionHandle, jint aUid)
   516 {
   506 {
   517     // Convert session handle to pointer.
   507     // Convert session handle to pointer.
   518     RApaLsSession *pApaSession =
   508     RApaLsSession *pApaSession =
   521     TUid appUid;
   511     TUid appUid;
   522     appUid.iUid = aUid;
   512     appUid.iUid = aUid;
   523     TRAPD(err, pApaSession->DeregisterNonNativeApplicationL(appUid));
   513     TRAPD(err, pApaSession->DeregisterNonNativeApplicationL(appUid));
   524     return err;
   514     return err;
   525 }
   515 }
   526 #endif // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   516 #endif // RD_JAVA_USIF_APP_REG
   527 
   517 
   528 
   518 
   529 /**
   519 /**
   530  * Commits native application registration session.
   520  * Commits native application registration session.
   531  * If commit succeeds the native session is closed.
   521  * If commit succeeds the native session is closed.
   542     RApaLsSession *pApaSession =
   532     RApaLsSession *pApaSession =
   543         reinterpret_cast<RApaLsSession*>(aSessionHandle<<2);
   533         reinterpret_cast<RApaLsSession*>(aSessionHandle<<2);
   544 
   534 
   545     TInt err = KErrNone;
   535     TInt err = KErrNone;
   546 
   536 
   547 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   537 #if 1
       
   538 //#ifndef RD_JAVA_USIF_APP_REG
   548     if (aSynchronous)
   539     if (aSynchronous)
   549     {
   540     {
   550         // Make synchronous commit
   541         // Make synchronous commit
   551         TRAP(err, pApaSession->CommitNonNativeApplicationsUpdatesL());
   542         TRAP(err, pApaSession->CommitNonNativeApplicationsUpdatesL());
   552         if (KErrNone == err)
   543         if (KErrNone == err)
   570     {
   561     {
   571 #ifdef __WINS__
   562 #ifdef __WINS__
   572         // Use always this synchronous commit when running in emulator
   563         // Use always this synchronous commit when running in emulator
   573         // to make writing autotest cases easier.
   564         // to make writing autotest cases easier.
   574         TRAP(err, pApaSession->CommitNonNativeApplicationsUpdatesL());
   565         TRAP(err, pApaSession->CommitNonNativeApplicationsUpdatesL());
   575 #else // __WINS__
   566 #else
   576         // asynchronous commit
   567         // asynchronous commit
   577         TRAP(err, pApaSession->ForceCommitNonNativeApplicationsUpdatesL());
   568         TRAP(err, pApaSession->ForceCommitNonNativeApplicationsUpdatesL());
   578 #endif // __WINS__
   569 #endif // __WINS__
   579     }
   570     }
   580 #endif // !SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   571 #endif // RD_JAVA_USIF_APP_REG
   581 
   572 
   582     if (KErrNone == err)
   573     if (KErrNone == err)
   583     {
   574     {
   584         pApaSession->Close();
   575         pApaSession->Close();
   585         delete pApaSession;
   576         delete pApaSession;
   600     // Convert session handle to pointer.
   591     // Convert session handle to pointer.
   601     RApaLsSession *pApaSession =
   592     RApaLsSession *pApaSession =
   602         reinterpret_cast<RApaLsSession*>(aSessionHandle<<2);
   593         reinterpret_cast<RApaLsSession*>(aSessionHandle<<2);
   603 
   594 
   604     TInt err = KErrNone;
   595     TInt err = KErrNone;
   605 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   596 #if 1
       
   597 //#ifndef RD_JAVA_USIF_APP_REG
   606     err = pApaSession->RollbackNonNativeApplicationsUpdates();
   598     err = pApaSession->RollbackNonNativeApplicationsUpdates();
   607 #endif // !SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   599 #endif // RD_JAVA_USIF_APP_REG
   608     pApaSession->Close();
   600     pApaSession->Close();
   609     delete pApaSession;
   601     delete pApaSession;
   610 
   602 
   611     return err;
   603     return err;
   612 }
   604 }
   943     return JNI_FALSE;
   935     return JNI_FALSE;
   944 #endif
   936 #endif
   945 }
   937 }
   946 
   938 
   947 
   939 
   948 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   949 /**
   940 /**
   950  * Internal helper method for checking whether this code is executing in
   941  * Internal helper method for checking whether this code is executing in
   951  * a device that has correctly working version of
   942  * a device that has correctly working version of
   952  * RApaLsSession::ForceCommitNonNativeApplicationsUpdatesL()
   943  * RApaLsSession::ForceCommitNonNativeApplicationsUpdatesL()
   953  *
   944  *
   988     else
   979     else
   989     {
   980     {
   990         return EFalse;
   981         return EFalse;
   991     }
   982     }
   992 }
   983 }
   993 #endif // !SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   994 
       
   995 /**
       
   996  * See JNI method __1logComponent.
       
   997  * This method makes calls that may leave.
       
   998  */
       
   999 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
  1000 void AddInstallLogEntryL(
       
  1001     JNIEnv */*aEnv*/, jint /*aAction*/, jint /*aUid*/,
       
  1002     jstring /*aName*/, jstring /*aVendor*/,
       
  1003     jint /*aMajorVersion*/, jint /*aMinorVersion*/, jint /*aMicroVersion*/)
       
  1004 {
       
  1005 }
       
  1006 #else
       
  1007 void AddInstallLogEntryL(
       
  1008     JNIEnv *aEnv, jint aAction, jint aUid, jstring aName, jstring aVendor,
       
  1009     jint aMajorVersion, jint aMinorVersion, jint aMicroVersion)
       
  1010 {
       
  1011     TUid uid = TUid::Uid(aUid);
       
  1012     HBufC *name = CreateHBufCFromJavaStringLC(aEnv, aName);
       
  1013     HBufC *vendor = CreateHBufCFromJavaStringLC(aEnv, aVendor);
       
  1014     TVersion version(aMajorVersion, aMinorVersion, aMicroVersion);
       
  1015 
       
  1016     // Create log task object.
       
  1017     CTask* task = CTask::NewL(KLogTaskImplUid, EFalse);
       
  1018     CleanupStack::PushL(task);
       
  1019 
       
  1020     // Initalize log task parameters.
       
  1021     TLogTaskParam params;
       
  1022     params.iName.Copy(name->Left(KMaxLogNameLength));
       
  1023     params.iVendor.Copy(vendor->Left(KMaxLogVendorLength));
       
  1024     params.iVersion = version;
       
  1025     params.iUid = uid;
       
  1026     // Time must be universal time.
       
  1027     TTime time;
       
  1028     time.UniversalTime();
       
  1029     params.iTime = time;
       
  1030     params.iAction = (TLogTaskAction)aAction;
       
  1031     params.iIsStartup = EFalse; // Startup list was not modified.
       
  1032 
       
  1033     TLogTaskParamPckg pckg(params);
       
  1034     task->SetParameterL(pckg, 0);
       
  1035 
       
  1036     // Create log task manager.
       
  1037     CTaskManager* taskManager = CTaskManager::NewL();
       
  1038     CleanupStack::PushL(taskManager);
       
  1039 
       
  1040     // Add the log task to the task list.
       
  1041     taskManager->AddTaskL(task);
       
  1042     taskManager->ExecutePendingTasksL();
       
  1043 
       
  1044     // Cleanup.
       
  1045     CleanupStack::PopAndDestroy(taskManager);
       
  1046     CleanupStack::Pop(task);
       
  1047 
       
  1048     CleanupStack::PopAndDestroy(vendor);
       
  1049     CleanupStack::PopAndDestroy(name);
       
  1050 }
       
  1051 #endif // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
  1052 
       
  1053 /**
       
  1054  * Adds an entry to platform installation log.
       
  1055  */
       
  1056 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_ApplicationRegistrator__1addInstallLogEntry
       
  1057 (JNIEnv *aEnv, jclass, jint aAction, jint aUid, jstring aName, jstring aVendor,
       
  1058  jint aMajorVersion, jint aMinorVersion, jint aMicroVersion)
       
  1059 {
       
  1060     TRAPD(err, AddInstallLogEntryL(
       
  1061               aEnv, aAction, aUid, aName, aVendor,
       
  1062               aMajorVersion, aMinorVersion, aMicroVersion));
       
  1063     return err;
       
  1064 }