javamanager/javainstaller/installer/src.s60/applicationregistrator/applicationregistrator.cpp
changeset 50 023eef975703
parent 35 85266cc22c7f
child 56 abc41079b313
equal deleted inserted replaced
49:35baca0e7a2e 50:023eef975703
    49 #include "logger.h"
    49 #include "logger.h"
    50 
    50 
    51 // NAMESPACE DECLARATION
    51 // NAMESPACE DECLARATION
    52 using namespace java;
    52 using namespace java;
    53 
    53 
       
    54 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    54 /**
    55 /**
    55  * MIDP Stub SIS file UID. The application type Uid for MIDlets in S60
    56  * MIDP Stub SIS file UID. The application type Uid for MIDlets in S60
    56  */
    57  */
    57 const TUid KMidletApplicationTypeUid = { 0x10210E26 };
    58 const TUid KMidletApplicationTypeUid = { 0x10210E26 };
    58 
    59 
    63 
    64 
    64 /**
    65 /**
    65  * Postfix for the fake application name generated only to make AppArc happy
    66  * Postfix for the fake application name generated only to make AppArc happy
    66  */
    67  */
    67 _LIT(KAppPostfix, ".fakeapp");
    68 _LIT(KAppPostfix, ".fakeapp");
       
    69 
       
    70 
       
    71 #ifdef RD_JAVA_S60_RELEASE_9_2
       
    72 const TInt KAppIconCount = 2;
       
    73 #else
       
    74 const TInt KAppIconCount = 1;
       
    75 #endif
    68 
    76 
    69 // ------------------------
    77 // ------------------------
    70 
    78 
    71 /**
    79 /**
    72  * Internal wrapper method that is used to make TRAPping the leaves in the
    80  * Internal wrapper method that is used to make TRAPping the leaves in the
    78                           jint aUid, HBufC16 *aGroupName, HBufC16 *aMIDletName, HBufC16 *aTargetDrive,
    86                           jint aUid, HBufC16 *aGroupName, HBufC16 *aMIDletName, HBufC16 *aTargetDrive,
    79                           HBufC16 *aIconFileName, HBufC16 *aJarFileName, jboolean aHidden,
    87                           HBufC16 *aIconFileName, HBufC16 *aJarFileName, jboolean aHidden,
    80                           jboolean aBackground);
    88                           jboolean aBackground);
    81 
    89 
    82 /**
    90 /**
    83  * Internal helper method for checking whether Application Shell is already running
       
    84  * Used JNI method ...1startAppShellUi
       
    85  *
       
    86  * @return ETrue if AppShell is running
       
    87  */
       
    88 TBool isAppShellUiRunning();
       
    89 
       
    90 /**
       
    91  * Internal helper method for checking whether this code is executing in
    91  * Internal helper method for checking whether this code is executing in
    92  * a device that has correctly working version of
    92  * a device that has correctly working version of
    93  * RApaLsSession::ForceCommitNonNativeApplicationsUpdatesL()
    93  * RApaLsSession::ForceCommitNonNativeApplicationsUpdatesL()
    94  *
    94  *
    95  * @return ETrue if force commit works well
    95  * @return ETrue if force commit works well
    96  */
    96  */
    97 TBool isForceCommitSupported();
    97 TBool isForceCommitSupported();
       
    98 #endif // !SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
    99 
       
   100 /**
       
   101  * Internal helper method for checking whether Application Shell is already running
       
   102  * Used JNI method ...1startAppShellUi
       
   103  *
       
   104  * @return ETrue if AppShell is running
       
   105  */
       
   106 TBool isAppShellUiRunning();
    98 
   107 
    99 /**
   108 /**
   100  * Internal helper method for starting menu application
   109  * Internal helper method for starting menu application
   101  *
   110  *
   102  * @return KErrNone or Symbian error code
   111  * @return KErrNone or Symbian error code
   127     {
   136     {
   128         // Cannot connect to AppArc server
   137         // Cannot connect to AppArc server
   129         return err;
   138         return err;
   130     }
   139     }
   131 
   140 
   132 #ifndef RD_JAVA_USIF_APP_REG
   141 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   133     // Delete any pending (un)registrations (possible if
   142     // Delete any pending (un)registrations (possible if
   134     // e.g. device rebooted before commit).
   143     // e.g. device rebooted before commit).
   135     // This call does nothing if there is no pending registrations.
   144     // This call does nothing if there is no pending registrations.
   136     // Ignore errors.
   145     // Ignore errors.
   137     (void)pApaSession->RollbackNonNativeApplicationsUpdates();
   146     (void)pApaSession->RollbackNonNativeApplicationsUpdates();
   142     {
   151     {
   143         // Close session and return error
   152         // Close session and return error
   144         pApaSession->Close();
   153         pApaSession->Close();
   145         return err;
   154         return err;
   146     }
   155     }
   147 #endif // RD_JAVA_USIF_APP_REG
   156 #endif // !SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   148 
   157 
   149     // Return handle to session. Utilize the fact that in Symbian
   158     // Return handle to session. Utilize the fact that in Symbian
   150     // all pointer addresses are MOD 4 so the last 2 bits are 0
   159     // all pointer addresses are MOD 4 so the last 2 bits are 0
   151     // and can be shifted out. This way the returned handle is
   160     // and can be shifted out. This way the returned handle is
   152     // always positive whereas Symbian error codes are always negative.
   161     // always positive whereas Symbian error codes are always negative.
   166  * @param[in] aJarFileName The full path name of the jar file
   175  * @param[in] aJarFileName The full path name of the jar file
   167  * @param[in] aHidden
   176  * @param[in] aHidden
   168  * @param[in] aBackground
   177  * @param[in] aBackground
   169  * @return 0 if registration succeeded or Symbian error code
   178  * @return 0 if registration succeeded or Symbian error code
   170  */
   179  */
   171 #ifdef RD_JAVA_USIF_APP_REG
   180 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   172 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
   173 (JNIEnv */*aEnv*/, jclass /*aClass*/, jint /*aSessionHandle*/, jint /*aUid*/, jstring /*aGroupName*/,
   182 (JNIEnv */*aEnv*/, jclass /*aClass*/, jint /*aSessionHandle*/, jint /*aUid*/, jstring /*aGroupName*/,
   174  jstring /*aMIDletName*/, jstring /*aTargetDrive*/, jstring /*aIconFileName*/,
   183  jstring /*aMIDletName*/, jstring /*aTargetDrive*/, jstring /*aIconFileName*/,
   175  jstring /*aJarFileName*/, jboolean /*aHidden*/, jboolean /*aBackground*/)
   184  jstring /*aJarFileName*/, jboolean /*aHidden*/, jboolean /*aBackground*/)
   176 {
   185 {
   177     return KErrNone;
   186     return KErrNone;
   178 }
   187 }
   179 #else
   188 #else // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   180 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
   181 (JNIEnv *aEnv, jclass aClass, jint aSessionHandle, jint aUid, jstring aGroupName,
   190 (JNIEnv *aEnv, jclass aClass, jint aSessionHandle, jint aUid, jstring aGroupName,
   182  jstring aMIDletName, jstring aTargetDrive, jstring aIconFileName,
   191  jstring aMIDletName, jstring aTargetDrive, jstring aIconFileName,
   183  jstring aJarFileName, jboolean aHidden, jboolean aBackground)
   192  jstring aJarFileName, jboolean aHidden, jboolean aBackground)
   184 {
   193 {
   341     delete unicodeTargetDrive;
   350     delete unicodeTargetDrive;
   342     delete unicodeJarFileName;
   351     delete unicodeJarFileName;
   343 
   352 
   344     return err;
   353     return err;
   345 }
   354 }
   346 #endif // RD_JAVA_USIF_APP_REG
       
   347 
   355 
   348 
   356 
   349 /**
   357 /**
   350  * See JNI method __1registerApplication.
   358  * See JNI method __1registerApplication.
   351  * This method makes all calls that may leave (the actual registering)
   359  * This method makes all calls that may leave (the actual registering)
   357 {
   365 {
   358     RFs         fileServ;
   366     RFs         fileServ;
   359     RFile       appArcIcon;
   367     RFile       appArcIcon;
   360     TUid        midletUid;
   368     TUid        midletUid;
   361     TInt        err;
   369     TInt        err;
   362     TInt        numberOfIcons = 1; // Conversion results always one icon in mbm.
   370     TInt        numberOfIcons = KAppIconCount; // number of icons stored in MBM
   363     // Also default mbm has one icon.
   371     // Also default mbm has one icon.
   364 
   372 
   365     midletUid.iUid = aUid;
   373     midletUid.iUid = aUid;
   366 
   374 
   367     // AppArc requires open RFile handle
   375     // AppArc requires open RFile handle
   473     // close file server connection
   481     // close file server connection
   474     CleanupStack::PopAndDestroy(&fileServ);
   482     CleanupStack::PopAndDestroy(&fileServ);
   475 
   483 
   476     return err;
   484     return err;
   477 }
   485 }
       
   486 #endif // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   478 
   487 
   479 
   488 
   480 /**
   489 /**
   481  * Unregisters Java Application from S60 AppArc
   490  * Unregisters Java Application from S60 AppArc
   482  *
   491  *
   483  * @param[in] aSessionHandle
   492  * @param[in] aSessionHandle
   484  * @param[in] aUid The Uid of the application to be unregistered..
   493  * @param[in] aUid The Uid of the application to be unregistered..
   485  * @return 0 if unregistration succeeded or Symbian error code
   494  * @return 0 if unregistration succeeded or Symbian error code
   486  */
   495  */
   487 #ifdef RD_JAVA_USIF_APP_REG
   496 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   488 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_ApplicationRegistrator__1unregisterApplication
   497 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_ApplicationRegistrator__1unregisterApplication
   489 (JNIEnv *, jclass, jint /*aSessionHandle*/, jint /*aUid*/)
   498 (JNIEnv *, jclass, jint /*aSessionHandle*/, jint /*aUid*/)
   490 {
   499 {
   491     return KErrNone;
   500     return KErrNone;
   492 }
   501 }
   493 #else
   502 #else // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   494 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_ApplicationRegistrator__1unregisterApplication
   503 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_ApplicationRegistrator__1unregisterApplication
   495 (JNIEnv *, jclass, jint aSessionHandle, jint aUid)
   504 (JNIEnv *, jclass, jint aSessionHandle, jint aUid)
   496 {
   505 {
   497     // Convert session handle to pointer.
   506     // Convert session handle to pointer.
   498     RApaLsSession *pApaSession =
   507     RApaLsSession *pApaSession =
   501     TUid appUid;
   510     TUid appUid;
   502     appUid.iUid = aUid;
   511     appUid.iUid = aUid;
   503     TRAPD(err, pApaSession->DeregisterNonNativeApplicationL(appUid));
   512     TRAPD(err, pApaSession->DeregisterNonNativeApplicationL(appUid));
   504     return err;
   513     return err;
   505 }
   514 }
   506 #endif // RD_JAVA_USIF_APP_REG
   515 #endif // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   507 
   516 
   508 
   517 
   509 /**
   518 /**
   510  * Commits native application registration session.
   519  * Commits native application registration session.
   511  * If commit succeeds the native session is closed.
   520  * If commit succeeds the native session is closed.
   522     RApaLsSession *pApaSession =
   531     RApaLsSession *pApaSession =
   523         reinterpret_cast<RApaLsSession*>(aSessionHandle<<2);
   532         reinterpret_cast<RApaLsSession*>(aSessionHandle<<2);
   524 
   533 
   525     TInt err = KErrNone;
   534     TInt err = KErrNone;
   526 
   535 
   527 #ifndef RD_JAVA_USIF_APP_REG
   536 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   528     if (aSynchronous)
   537     if (aSynchronous)
   529     {
   538     {
   530         // Make synchronous commit
   539         // Make synchronous commit
   531         TRAP(err, pApaSession->CommitNonNativeApplicationsUpdatesL());
   540         TRAP(err, pApaSession->CommitNonNativeApplicationsUpdatesL());
   532         if (KErrNone == err)
   541         if (KErrNone == err)
   550     {
   559     {
   551 #ifdef __WINS__
   560 #ifdef __WINS__
   552         // Use always this synchronous commit when running in emulator
   561         // Use always this synchronous commit when running in emulator
   553         // to make writing autotest cases easier.
   562         // to make writing autotest cases easier.
   554         TRAP(err, pApaSession->CommitNonNativeApplicationsUpdatesL());
   563         TRAP(err, pApaSession->CommitNonNativeApplicationsUpdatesL());
   555 #else
   564 #else // __WINS__
   556         // asynchronous commit
   565         // asynchronous commit
   557         TRAP(err, pApaSession->ForceCommitNonNativeApplicationsUpdatesL());
   566         TRAP(err, pApaSession->ForceCommitNonNativeApplicationsUpdatesL());
   558 #endif // __WINS__
   567 #endif // __WINS__
   559     }
   568     }
   560 #endif // RD_JAVA_USIF_APP_REG
   569 #endif // !SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   561 
   570 
   562     if (KErrNone == err)
   571     if (KErrNone == err)
   563     {
   572     {
   564         pApaSession->Close();
   573         pApaSession->Close();
   565         delete pApaSession;
   574         delete pApaSession;
   580     // Convert session handle to pointer.
   589     // Convert session handle to pointer.
   581     RApaLsSession *pApaSession =
   590     RApaLsSession *pApaSession =
   582         reinterpret_cast<RApaLsSession*>(aSessionHandle<<2);
   591         reinterpret_cast<RApaLsSession*>(aSessionHandle<<2);
   583 
   592 
   584     TInt err = KErrNone;
   593     TInt err = KErrNone;
   585 #ifndef RD_JAVA_USIF_APP_REG
   594 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   586     err = pApaSession->RollbackNonNativeApplicationsUpdates();
   595     err = pApaSession->RollbackNonNativeApplicationsUpdates();
   587 #endif // RD_JAVA_USIF_APP_REG
   596 #endif // !SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   588     pApaSession->Close();
   597     pApaSession->Close();
   589     delete pApaSession;
   598     delete pApaSession;
   590 
   599 
   591     return err;
   600     return err;
   592 }
   601 }
   923     return JNI_FALSE;
   932     return JNI_FALSE;
   924 #endif
   933 #endif
   925 }
   934 }
   926 
   935 
   927 
   936 
       
   937 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   928 /**
   938 /**
   929  * Internal helper method for checking whether this code is executing in
   939  * Internal helper method for checking whether this code is executing in
   930  * a device that has correctly working version of
   940  * a device that has correctly working version of
   931  * RApaLsSession::ForceCommitNonNativeApplicationsUpdatesL()
   941  * RApaLsSession::ForceCommitNonNativeApplicationsUpdatesL()
   932  *
   942  *
   967     else
   977     else
   968     {
   978     {
   969         return EFalse;
   979         return EFalse;
   970     }
   980     }
   971 }
   981 }
       
   982 #endif // !SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK