javamanager/javainstaller/installer/src.s60/applicationregistrator/sifregistrator.cpp
changeset 21 2a9601315dfc
child 23 98ccebc37403
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2008-2010 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:  The JNI code for Java Installer component
       
    15 *                SifRegistrator.
       
    16 *
       
    17 */
       
    18 
       
    19 #include <apacmdln.h>
       
    20 #include <apaid.h>
       
    21 #include <apgcli.h>
       
    22 #include <apgtask.h>
       
    23 #include <s32mem.h>
       
    24 #include <w32std.h>
       
    25 
       
    26 #include "com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator.h"
       
    27 #include "javacommonutils.h"
       
    28 #include "javasymbianoslayer.h" // for CleanupResetAndDestroyPushL
       
    29 #include "logger.h"
       
    30 
       
    31 // SCR usage is enabled if this macro has been defined.
       
    32 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
    33 
       
    34 #include <qservicemanager.h>
       
    35 #include <usif/scr/scr.h>
       
    36 #include <usif/scr/screntries.h>
       
    37 #ifdef RD_JAVA_USIF_APP_REG
       
    38 #include <usif/scr/appreginfo.h>
       
    39 #endif // RD_JAVA_USIF_APP_REG
       
    40 
       
    41 // Helper macro for logging a TDesC.
       
    42 #define LOG_TDESC_L(compIdParam, logLevelParam, msgParam, tdescParam) \
       
    43     {                                                               \
       
    44         HBufC8* tdescBuf = HBufC8::NewLC(tdescParam.Length() + 1);  \
       
    45         TPtr8 tdescPtr(tdescBuf->Des());                            \
       
    46         tdescPtr.Append(tdescParam);                                \
       
    47         LOG1(compIdParam, logLevelParam, msgParam, tdescPtr.PtrZ());\
       
    48         CleanupStack::PopAndDestroy(tdescBuf);                      \
       
    49     }
       
    50 
       
    51 // NAMESPACE DECLARATION
       
    52 QTM_USE_NAMESPACE
       
    53 using namespace java;
       
    54 using namespace Usif;
       
    55 
       
    56 IMPORT_C HBufC* CreateHBufCFromJavaStringLC(JNIEnv* aEnv, jstring aString);
       
    57 
       
    58 // Java MIME types.
       
    59 _LIT(KMimeTypeAppDescriptor, "text/vnd.sun.j2me.app-descriptor");
       
    60 _LIT(KMimeTypeJava, "application/java");
       
    61 _LIT(KMimeTypeJavaArchive, "application/java-archive");
       
    62 _LIT(KMimeTypeXJavaArchive, "application/x-java-archive");
       
    63 
       
    64 // Properties registered to SCR.
       
    65 _LIT(KMIDletName, "MIDlet-Name");
       
    66 _LIT(KUid, "Uid");
       
    67 _LIT(KMediaId, "Media-Id");
       
    68 _LIT(KMIDletInfoURL, "MIDlet-Info-URL");
       
    69 _LIT(KMIDletDescription, "MIDlet-Description");
       
    70 _LIT(KDownloadURL, "Download-URL");
       
    71 _LIT(KSettingsPlugin, "SettingsName");
       
    72 _LIT(KSettingsPluginValue, "javaapplicationsettingsview");
       
    73 
       
    74 #ifdef RD_JAVA_USIF_APP_REG
       
    75 // Symbian file path separator.
       
    76 _LIT(KPathSeperator, "\\");
       
    77 // Postfix for the fake application name generated for AppArc.
       
    78 _LIT(KAppPostfix, ".fakeapp");
       
    79 #endif // RD_JAVA_USIF_APP_REG
       
    80 
       
    81 /**
       
    82  * Internal helper method for checking if specified application
       
    83  * is already running.
       
    84  *
       
    85  * @param aUid application uid
       
    86  * @param aBringToForeground if application is running and this
       
    87  *   flag is true the application is brought to foreground.
       
    88  * @return ETrue if application is running
       
    89  */
       
    90 TBool IsAppRunningL(TUid aUid, TBool aBringToForeground)
       
    91 {
       
    92     TBool result = EFalse;
       
    93     // Getting list of current processes requires window
       
    94     // server session, create it now.
       
    95     RWsSession wsSession;
       
    96     TInt err = wsSession.Connect();
       
    97     if (KErrNone != err)
       
    98     {
       
    99         ELOG1(EJavaInstaller,
       
   100               "IsAppRunning: Cannot connect to window server, error %d",
       
   101               err);
       
   102         return result;
       
   103     }
       
   104     CleanupClosePushL(wsSession);
       
   105     // Get list of all processes in the device.
       
   106     TApaTaskList taskList(wsSession);
       
   107     TApaTask task = taskList.FindApp(aUid);
       
   108     if (task.Exists())
       
   109     {
       
   110         // Application is already running.
       
   111         result = ETrue;
       
   112         if (aBringToForeground)
       
   113         {
       
   114             // Bring the application to foreground.
       
   115             task.BringToForeground();
       
   116         }
       
   117     }
       
   118     CleanupStack::PopAndDestroy(&wsSession);
       
   119     return result;
       
   120 }
       
   121 
       
   122 /**
       
   123  * Internal helper method for starting specified application.
       
   124  *
       
   125  * @param aUid application uid
       
   126  * @return 1 if application was already running,
       
   127  *   0 if application was started,
       
   128  *   negative number (Symbian error code) in case of error.
       
   129  */
       
   130 TInt StartAppL(TUid aUid)
       
   131 {
       
   132     if (IsAppRunningL(aUid, ETrue))
       
   133     {
       
   134         // Application is already running, do nothing.
       
   135         LOG1(EJavaInstaller, EInfo,
       
   136              "StartAppL: Application 0x%x already running", aUid.iUid);
       
   137         return 1;
       
   138     }
       
   139     TInt err = KErrNone;
       
   140     LOG1(EJavaInstaller, EInfo,
       
   141          "StartAppL: Starting application 0x%x", aUid.iUid);
       
   142     TApaAppInfo appInfo;
       
   143     RApaLsSession lsSession;
       
   144     err = lsSession.Connect();
       
   145     CleanupClosePushL(lsSession);
       
   146     if (KErrNone == lsSession.GetAppInfo(appInfo, aUid))
       
   147     {
       
   148         CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
       
   149         cmdLine->SetExecutableNameL(appInfo.iFullName);
       
   150         //cmdLine->SetCommandL(EApaCommandBackground);
       
   151         //cmdLine->SetTailEndL(_L8(""));
       
   152         err = lsSession.StartApp(*cmdLine);
       
   153         CleanupStack::PopAndDestroy(cmdLine);
       
   154     }
       
   155     CleanupStack::PopAndDestroy(&lsSession);
       
   156     LOG1(EJavaInstaller, EInfo,
       
   157          "StartAppL: Result of starting application is %d", err);
       
   158     return err;
       
   159 }
       
   160 
       
   161 /**
       
   162  * Creates an instance of RSoftwareComponentRegistry and connects to it.
       
   163  */
       
   164 RSoftwareComponentRegistry *CreateScrL()
       
   165 {
       
   166     RSoftwareComponentRegistry *pScr = new RSoftwareComponentRegistry;
       
   167     if (NULL == pScr)
       
   168     {
       
   169         ELOG(EJavaInstaller,
       
   170              "CreateScrL: Creating RSoftwareComponentRegistry failed");
       
   171         User::Leave(KErrGeneral);
       
   172     }
       
   173     TInt err = pScr->Connect();
       
   174     if (KErrNone != err)
       
   175     {
       
   176         ELOG1(EJavaInstaller,
       
   177               "CreateScrL: Connecting to RSoftwareComponentRegistry failed, error %d",
       
   178               err);
       
   179         delete pScr;
       
   180         User::Leave(err);
       
   181     }
       
   182     return pScr;
       
   183 }
       
   184 
       
   185 /**
       
   186  * See JNI method __1notifyAppChange.
       
   187  * This method makes calls that may leave (the actual registering).
       
   188  */
       
   189 #ifdef RD_JAVA_USIF_NOTIFY_APP_ARC
       
   190 void NotifyAppChangeL(JNIEnv *aEnv, jintArray aAppUids, jint aAppChange)
       
   191 {
       
   192     RApaLsSession apaSession;
       
   193     TInt err = apaSession.Connect();
       
   194     if (KErrNone != err)
       
   195     {
       
   196         ELOG1(EJavaInstaller,
       
   197               "NotifyAppChangeL: Error %d when connecting AppArc", err);
       
   198         User::Leave(err);
       
   199     }
       
   200     CleanupClosePushL(apaSession);
       
   201 
       
   202     RArray<TApaAppUpdateInfo> appUpdateInfos;
       
   203     CleanupClosePushL(appUpdateInfos);
       
   204     TInt appUidCount = aEnv->GetArrayLength(aAppUids);
       
   205     jint* appUids = aEnv->GetIntArrayElements(aAppUids, NULL);
       
   206     for (TInt i = 0; i < appUidCount; i++)
       
   207     {
       
   208         TApaAppUpdateInfo appUpdateInfo;
       
   209         appUpdateInfo.iAppUid = TUid::Uid(appUids[i]);
       
   210         appUpdateInfo.iAction = (TApaAppUpdateInfo::TApaAppAction)aAppChange;
       
   211         appUpdateInfos.AppendL(appUpdateInfo);
       
   212         LOG2(EJavaInstaller, EInfo, "NotifyAppChangeL uid: 0x%x, action: %d",
       
   213              appUpdateInfo.iAppUid, appUpdateInfo.iAction);
       
   214     }
       
   215     aEnv->ReleaseIntArrayElements(aAppUids, appUids, 0);
       
   216     User::LeaveIfError(apaSession.UpdateAppListL(appUpdateInfos));
       
   217     CleanupStack::PopAndDestroy(&appUpdateInfos);
       
   218 
       
   219     CleanupStack::PopAndDestroy(&apaSession);
       
   220     LOG(EJavaInstaller, EInfo, "NotifyAppChangeL completed");
       
   221 }
       
   222 #else
       
   223 void NotifyAppChangeL(JNIEnv *, jintArray, jint)
       
   224 {
       
   225 }
       
   226 #endif // RD_JAVA_USIF_NOTIFY_APP_ARC
       
   227 
       
   228 /*
       
   229  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
   230  * Method:    _notifyAppChange
       
   231  * Signature: ([II)I
       
   232  */
       
   233 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1notifyAppChange
       
   234 (JNIEnv *aEnv, jclass, jintArray aAppUids, jint aAppChange)
       
   235 {
       
   236     TRAPD(err, NotifyAppChangeL(aEnv, aAppUids, aAppChange));
       
   237     if (KErrNone != err)
       
   238     {
       
   239         ELOG1(EJavaInstaller,
       
   240               "notifyAppChange: notifying AppArc failed, error %d",
       
   241               err);
       
   242     }
       
   243     return err;
       
   244 }
       
   245 
       
   246 /*
       
   247  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
   248  * Method:    _launchAppView
       
   249  * Signature: ()I
       
   250  */
       
   251 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1launchAppView
       
   252 (JNIEnv *, jclass)
       
   253 {
       
   254     TInt err = KErrNone;
       
   255     /*
       
   256     //Application Library UID.
       
   257     const TUid KAppLibUid = { 0x20022F35 };
       
   258 
       
   259     QServiceManager serviceManager;
       
   260     QObject* activityManager =
       
   261         serviceManager.loadInterface("com.nokia.qt.activities.ActivityManager");
       
   262     if (!activityManager)
       
   263     {
       
   264         err = serviceManager.error();
       
   265         ELOG1(EJavaInstaller,
       
   266               "launchAppView: loading ActivityManager failed, error %d", err);
       
   267         return KErrCouldNotConnect;
       
   268     }
       
   269     QMetaObject::invokeMethod(activityManager, "launchActivity",
       
   270                               Q_ARG(int, KAppLibUid.iUid), // AppLib uid
       
   271                               Q_ARG(QString, "showInstalledApps"));
       
   272     err = serviceManager.error();
       
   273     delete activityManager;
       
   274     if (QServiceManager::NoError != err)
       
   275     {
       
   276         ELOG1(EJavaInstaller,
       
   277               "launchAppView: launching AppLib activity failed, error %d",
       
   278               err);
       
   279         return KErrCouldNotConnect;
       
   280     }
       
   281 
       
   282     // Start AppLib and bring it to foreground.
       
   283     TRAP(err, StartAppL(KAppLibUid));
       
   284     */
       
   285     return err;
       
   286 }
       
   287 
       
   288 /**
       
   289  * See JNI method __1registerJavaSoftwareType.
       
   290  * This method makes calls that may leave (the actual registering).
       
   291  */
       
   292 void RegisterJavaSoftwareTypeL(RSoftwareComponentRegistry *aScr, TBool aRegister = ETrue)
       
   293 {
       
   294     RPointerArray<HBufC> javaMimeTypes;
       
   295     CleanupResetAndDestroyPushL(javaMimeTypes);
       
   296     javaMimeTypes.AppendL(KMimeTypeAppDescriptor().AllocL());
       
   297     javaMimeTypes.AppendL(KMimeTypeJava().AllocL());
       
   298     javaMimeTypes.AppendL(KMimeTypeJavaArchive().AllocL());
       
   299     javaMimeTypes.AppendL(KMimeTypeXJavaArchive().AllocL());
       
   300     if (aRegister)
       
   301     {
       
   302         TUid javaSifPluginUid = TUid::Uid(0x2002bc70);
       
   303         _LIT_SECURE_ID(KJavaInstallerSid, 0x102033E6);
       
   304         aScr->AddSoftwareTypeL(
       
   305             Usif::KSoftwareTypeJava, javaSifPluginUid,
       
   306             KJavaInstallerSid, KJavaInstallerSid, javaMimeTypes);
       
   307     }
       
   308     else
       
   309     {
       
   310         aScr->DeleteSoftwareTypeL(Usif::KSoftwareTypeJava, javaMimeTypes);
       
   311     }
       
   312     CleanupStack::PopAndDestroy(&javaMimeTypes);
       
   313 }
       
   314 
       
   315 /*
       
   316  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
   317  * Method:    _registerJavaSoftwareType
       
   318  * Signature: (Z)I
       
   319  */
       
   320 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1registerJavaSoftwareType
       
   321 (JNIEnv *, jclass, jboolean aRegister)
       
   322 {
       
   323     RSoftwareComponentRegistry *pScr = NULL;
       
   324     TRAPD(err, pScr = CreateScrL());
       
   325     if (KErrNone != err)
       
   326     {
       
   327         return err;
       
   328     }
       
   329     TRAP(err, RegisterJavaSoftwareTypeL(pScr, aRegister));
       
   330     if (KErrNone != err)
       
   331     {
       
   332         ELOG1(EJavaInstaller,
       
   333               "registerJavaSoftwareType: registration failed, error %d",
       
   334               err);
       
   335     }
       
   336     pScr->Close();
       
   337     delete pScr;
       
   338     return err;
       
   339 }
       
   340 
       
   341 /*
       
   342  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
   343  * Method:    _startSession
       
   344  * Signature: ()I
       
   345  */
       
   346 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1startSession
       
   347 (JNIEnv *, jclass, jboolean aTransaction)
       
   348 {
       
   349     RSoftwareComponentRegistry *pScr = NULL;
       
   350     TRAPD(err, pScr = CreateScrL());
       
   351     if (KErrNone != err)
       
   352     {
       
   353         return err;
       
   354     }
       
   355     if (aTransaction)
       
   356     {
       
   357         // Prepare for Java application registrations / unregistrations.
       
   358         TRAP(err, pScr->CreateTransactionL());
       
   359         if (KErrNone != err)
       
   360         {
       
   361             // Close session and return error
       
   362             ELOG1(EJavaInstaller,
       
   363                   "startSession: Creating transaction failed, error %d", err);
       
   364             pScr->Close();
       
   365             return err;
       
   366         }
       
   367     }
       
   368     // Return handle to session. Utilize the fact that in Symbian
       
   369     // all pointer addresses are MOD 4 so the last 2 bits are 0
       
   370     // and can be shifted out. This way the returned handle is
       
   371     // always positive whereas Symbian error codes are always negative.
       
   372     return reinterpret_cast<TUint>(pScr)>>2;
       
   373 }
       
   374 
       
   375 /*
       
   376  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
   377  * Method:    _commitSession
       
   378  * Signature: (I)I
       
   379  */
       
   380 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1commitSession
       
   381 (JNIEnv *, jclass, jint aSessionHandle)
       
   382 {
       
   383     RSoftwareComponentRegistry *pScr =
       
   384         reinterpret_cast<RSoftwareComponentRegistry*>(aSessionHandle<<2);
       
   385     TRAPD(err, pScr->CommitTransactionL());
       
   386     if (KErrNone == err)
       
   387     {
       
   388         pScr->Close();
       
   389         delete pScr;
       
   390     }
       
   391     else
       
   392     {
       
   393         ELOG1(EJavaInstaller,
       
   394               "commitSession: Commiting transaction failed, error %d", err);
       
   395     }
       
   396     return err;
       
   397 }
       
   398 
       
   399 /*
       
   400  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
   401  * Method:    _rollbackSession
       
   402  * Signature: (I)I
       
   403  */
       
   404 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1rollbackSession
       
   405 (JNIEnv *, jclass, jint aSessionHandle)
       
   406 {
       
   407     RSoftwareComponentRegistry *pScr =
       
   408         reinterpret_cast<RSoftwareComponentRegistry*>(aSessionHandle<<2);
       
   409     TRAPD(err, pScr->RollbackTransactionL());
       
   410     pScr->Close();
       
   411     delete pScr;
       
   412     if (KErrNone != err)
       
   413     {
       
   414         ELOG1(EJavaInstaller,
       
   415               "rollbackSession: Rolling back transaction failed, error %d",
       
   416               err);
       
   417     }
       
   418     return err;
       
   419 }
       
   420 
       
   421 /*
       
   422  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
   423  * Method:    _closeSession
       
   424  * Signature: (I)V
       
   425  */
       
   426 JNIEXPORT void JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1closeSession
       
   427 (JNIEnv *, jclass, jint aSessionHandle)
       
   428 {
       
   429     RSoftwareComponentRegistry *pScr =
       
   430         reinterpret_cast<RSoftwareComponentRegistry*>(aSessionHandle<<2);
       
   431     pScr->Close();
       
   432     delete pScr;
       
   433 }
       
   434 
       
   435 /**
       
   436  * Sets component property if given property value is not NULL.
       
   437  */
       
   438 void SetComponentPropertyL(
       
   439     JNIEnv *aEnv, RSoftwareComponentRegistry *aScr,
       
   440     TComponentId aComponentId, const TDesC &aName, jstring aValue)
       
   441 {
       
   442     if (NULL != aValue)
       
   443     {
       
   444         HBufC *valueBuf = CreateHBufCFromJavaStringLC(aEnv, aValue);
       
   445         aScr->SetComponentPropertyL(aComponentId, aName, *valueBuf);
       
   446         //LOG_TDESC_L(EJavaInstaller, EInfo,
       
   447         //            "SetComponentPropertyL: name %s", aName);
       
   448         //LOG_TDESC_L(EJavaInstaller, EInfo,
       
   449         //            "SetComponentPropertyL: value %s", valueBuf->Des());
       
   450         CleanupStack::PopAndDestroy(valueBuf);
       
   451     }
       
   452 }
       
   453 
       
   454 /**
       
   455  * See JNI method __1registerComponent.
       
   456  * This method makes calls that may leave (the actual registering).
       
   457  */
       
   458 TComponentId RegisterComponentL(
       
   459     JNIEnv *aEnv, RSoftwareComponentRegistry *aScr, jint aUid,
       
   460     jstring aSuiteName, jstring aVendor, jstring aVersion,
       
   461     jstring aName, jstring aGlobalId,
       
   462     jobjectArray aComponentFiles, TInt64 aComponentSize,
       
   463     TBool aIsRemovable, TBool aIsDrmProtected,
       
   464     TBool aIsOriginVerified, TBool aIsUpdate, jint aMediaId,
       
   465     jstring aMidletInfoUrl, jstring aMidletDescription, jstring aDownloadUrl)
       
   466 {
       
   467     HBufC *name = NULL;
       
   468     if (NULL == aName)
       
   469     {
       
   470         // If name is not specified, use suite name.
       
   471         name = CreateHBufCFromJavaStringLC(aEnv, aSuiteName);
       
   472     }
       
   473     else
       
   474     {
       
   475         name = CreateHBufCFromJavaStringLC(aEnv, aName);
       
   476     }
       
   477     HBufC *vendor = CreateHBufCFromJavaStringLC(aEnv, aVendor);
       
   478     HBufC *version = CreateHBufCFromJavaStringLC(aEnv, aVersion);
       
   479     HBufC *globalId = CreateHBufCFromJavaStringLC(aEnv, aGlobalId);
       
   480 
       
   481     TComponentId componentId = aScr->AddComponentL(
       
   482                                    *name, *vendor, Usif::KSoftwareTypeJava, globalId,
       
   483                                    (aIsUpdate? EScrCompUpgrade: EScrCompInstall));
       
   484     //LOG1(EJavaInstaller, EInfo,
       
   485     //     "RegisterComponentL: added component %d", componentId);
       
   486     aScr->SetComponentVersionL(componentId, *version);
       
   487     //LOG(EJavaInstaller, EInfo, "RegisterComponentL: version set");
       
   488     aScr->SetComponentSizeL(componentId, aComponentSize);
       
   489     //LOG(EJavaInstaller, EInfo, "RegisterComponentL: size set");
       
   490     aScr->SetIsComponentRemovableL(componentId, aIsRemovable);
       
   491     //LOG(EJavaInstaller, EInfo, "RegisterComponentL: isRemovable set");
       
   492     aScr->SetIsComponentDrmProtectedL(componentId, aIsDrmProtected);
       
   493     //LOG(EJavaInstaller, EInfo, "RegisterComponentL: DrmProtected set");
       
   494     aScr->SetIsComponentOriginVerifiedL(componentId, aIsOriginVerified);
       
   495     //LOG(EJavaInstaller, EInfo, "RegisterComponentL: isOriginVerified set");
       
   496     aScr->SetComponentPropertyL(componentId, KUid(), aUid);
       
   497     //LOG(EJavaInstaller, EInfo, "RegisterComponentL: Uid property set");
       
   498     aScr->SetComponentPropertyL(componentId, KMediaId(), aMediaId);
       
   499     //LOG(EJavaInstaller, EInfo, "RegisterComponentL: Media-Id property set");
       
   500     aScr->SetComponentPropertyL(componentId, KSettingsPlugin(), KSettingsPluginValue());
       
   501     //LOG(EJavaInstaller, EInfo, "RegisterComponentL: Settings plugin property set");
       
   502 
       
   503     if (NULL != aName)
       
   504     {
       
   505         // If name is specified, store suite name as property.
       
   506         SetComponentPropertyL(aEnv, aScr, componentId, KMIDletName(), aSuiteName);
       
   507     }
       
   508     SetComponentPropertyL(aEnv, aScr, componentId, KMIDletInfoURL(), aMidletInfoUrl);
       
   509     SetComponentPropertyL(aEnv, aScr, componentId, KMIDletDescription(), aMidletDescription);
       
   510     SetComponentPropertyL(aEnv, aScr, componentId, KDownloadURL(), aDownloadUrl);
       
   511 
       
   512     CleanupStack::PopAndDestroy(globalId);
       
   513     CleanupStack::PopAndDestroy(version);
       
   514     CleanupStack::PopAndDestroy(vendor);
       
   515     CleanupStack::PopAndDestroy(name);
       
   516 
       
   517     TInt fileCount = aEnv->GetArrayLength(aComponentFiles);
       
   518     for (TInt i = 0; i < fileCount; i++)
       
   519     {
       
   520         HBufC *componentFile = CreateHBufCFromJavaStringLC(
       
   521                                    aEnv, (jstring)aEnv->GetObjectArrayElement(aComponentFiles, i));
       
   522         aScr->RegisterComponentFileL(componentId, *componentFile);
       
   523         CleanupStack::PopAndDestroy(componentFile);
       
   524     }
       
   525 
       
   526     return componentId;
       
   527 }
       
   528 
       
   529 /*
       
   530  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
   531  * Method:    _registerComponent
       
   532  * Signature: (ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;JZZZZLcom/nokia/mj/impl/installer/applicationregistrator/ComponentId;)I
       
   533  */
       
   534 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1registerComponent
       
   535 (JNIEnv *aEnv, jclass, jint aSessionHandle, jint aUid, jstring aSuiteName,
       
   536  jstring aVendor, jstring aVersion, jstring aName, jstring aGlobalId,
       
   537  jobjectArray aComponentFiles, jlong aComponentSize, jboolean aIsRemovable,
       
   538  jboolean aIsDrmProtected, jboolean aIsOriginVerified, jboolean aIsUpdate,
       
   539  jint aMediaId, jstring aMidletInfoUrl, jstring aMidletDescription,
       
   540  jstring aDownloadUrl, jobject aComponentId)
       
   541 {
       
   542     __UHEAP_MARK;
       
   543     RSoftwareComponentRegistry *pScr =
       
   544         reinterpret_cast<RSoftwareComponentRegistry*>(aSessionHandle<<2);
       
   545     TComponentId componentId = -1;
       
   546     TRAPD(err, componentId = RegisterComponentL(
       
   547                                  aEnv, pScr, aUid, aSuiteName, aVendor, aVersion, aName, aGlobalId,
       
   548                                  aComponentFiles, aComponentSize, aIsRemovable,
       
   549                                  aIsDrmProtected, aIsOriginVerified, aIsUpdate, aMediaId,
       
   550                                  aMidletInfoUrl, aMidletDescription, aDownloadUrl));
       
   551     __UHEAP_MARKEND;
       
   552     if (KErrNone == err)
       
   553     {
       
   554         jclass clazz = aEnv->GetObjectClass(aComponentId);
       
   555         jmethodID methodSetId = aEnv->GetMethodID(clazz, "setId", "(I)V");
       
   556         aEnv->CallVoidMethod(aComponentId, methodSetId, componentId);
       
   557     }
       
   558     return err;
       
   559 }
       
   560 
       
   561 /*
       
   562  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
   563  * Method:    _unregisterComponent
       
   564  * Signature: (II)I
       
   565  */
       
   566 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1unregisterComponent
       
   567 (JNIEnv *, jclass, jint aSessionHandle, jint aComponentId)
       
   568 {
       
   569     __UHEAP_MARK;
       
   570     RSoftwareComponentRegistry *pScr =
       
   571         reinterpret_cast<RSoftwareComponentRegistry*>(aSessionHandle<<2);
       
   572     TInt err = KErrNone;
       
   573 #ifdef RD_JAVA_USIF_APP_REG
       
   574     TRAP(err, pScr->DeleteApplicationEntriesL(aComponentId));
       
   575 #endif // RD_JAVA_USIF_APP_REG
       
   576     if (KErrNone == err)
       
   577     {
       
   578         TRAP(err, pScr->DeleteComponentL(aComponentId));
       
   579     }
       
   580     __UHEAP_MARKEND;
       
   581     return err;
       
   582 }
       
   583 
       
   584 /**
       
   585  * See JNI method __1registerApplication.
       
   586  * This method makes calls that may leave.
       
   587  */
       
   588 #ifdef RD_JAVA_USIF_APP_REG
       
   589 void RegisterApplicationL(
       
   590     JNIEnv *aEnv, RSoftwareComponentRegistry *aScr,
       
   591     jint aComponentId, jint aAppUid,
       
   592     jstring aAppName, jstring aAppFilename, jstring aGroupName,
       
   593     jstring aIconFilename, jint aNumberOfIcons,
       
   594     jintArray aLanguages, jobjectArray aAppNames)
       
   595 {
       
   596     __UHEAP_MARK;
       
   597     // Application Uid.
       
   598     TUid appUid = TUid::Uid(aAppUid);
       
   599 
       
   600     // Generate the executable name using the same algorithm as used
       
   601     // earlier in S60 platform in case some external S60 application
       
   602     // needs to parse the Uid from the executable name.
       
   603     TFileName appName;
       
   604     appName.Copy(KPathSeperator);
       
   605     appName.AppendNum(appUid.iUid);
       
   606     appName.Append(KAppPostfix);
       
   607 
       
   608     HBufC *caption = CreateHBufCFromJavaStringLC(aEnv, aAppName);
       
   609     HBufC *appFilename = CreateHBufCFromJavaStringLC(aEnv, aAppFilename);
       
   610     HBufC *groupName = CreateHBufCFromJavaStringLC(aEnv, aGroupName);
       
   611     HBufC *iconFilename = NULL;
       
   612     TInt numberOfAppIcons = 0;
       
   613     if (NULL != aIconFilename)
       
   614     {
       
   615         iconFilename = CreateHBufCFromJavaStringLC(aEnv, aIconFilename);
       
   616         numberOfAppIcons = aNumberOfIcons;
       
   617     }
       
   618 
       
   619     RPointerArray<HBufC> ownedFileArray; // codescanner::resourcenotoncleanupstack
       
   620     RPointerArray<Usif::CServiceInfo> serviceArray; // codescanner::resourcenotoncleanupstack
       
   621     RPointerArray<Usif::CPropertyEntry> appPropertiesArray; // codescanner::resourcenotoncleanupstack
       
   622     RPointerArray<Usif::CAppViewData> viewDataList; // codescanner::resourcenotoncleanupstack
       
   623 
       
   624     RPointerArray<Usif::COpaqueData> opaqueDataArray;
       
   625     CleanupResetAndDestroyPushL(opaqueDataArray);
       
   626     // Write application Uid to opaque data (needed by MIDlet launcher).
       
   627     TBuf8<4> opaqueDataBuf; // Opaque data will contain one signed 32-bit int.
       
   628     RDesWriteStream writeStream(opaqueDataBuf);
       
   629     writeStream.WriteInt32L(aAppUid);
       
   630     writeStream.CommitL();
       
   631     COpaqueData *opaqueData =
       
   632         COpaqueData::NewLC(opaqueDataBuf, KUnspecifiedLocale);
       
   633     opaqueDataArray.AppendL(opaqueData);
       
   634     CleanupStack::Pop(opaqueData);
       
   635 
       
   636     RPointerArray<Usif::CLocalizableAppInfo> localizableAppInfoList;
       
   637     CleanupResetAndDestroyPushL(localizableAppInfoList);
       
   638     // Add non-localized application name (caption) and icon.
       
   639     CCaptionAndIconInfo *captionAndIconInfo = CCaptionAndIconInfo::NewLC(
       
   640                 /*aCaption=*/ *caption,
       
   641                 /*aIconFileName=*/ *iconFilename,
       
   642                 /*aNumOfAppIcons=*/ numberOfAppIcons);
       
   643     CLocalizableAppInfo *locAppInfo = CLocalizableAppInfo::NewLC(
       
   644                                           /*aShortCaption=*/ KNullDesC, /*aApplicationLanguage=*/ KNonLocalized,
       
   645                                           /*aGroupName=*/ KNullDesC, /*aCaptionAndIconInfo=*/ captionAndIconInfo,
       
   646                                           /*aViewDataList=*/ viewDataList);
       
   647     localizableAppInfoList.AppendL(locAppInfo);
       
   648     CleanupStack::Pop(locAppInfo);
       
   649     CleanupStack::Pop(captionAndIconInfo);
       
   650 
       
   651     // Add localized application names (captions).
       
   652     RPointerArray<HBufC> captionsArray;
       
   653     CleanupResetAndDestroyPushL(captionsArray);
       
   654     TInt langCount = aEnv->GetArrayLength(aLanguages);
       
   655     TInt captionCount = aEnv->GetArrayLength(aAppNames);
       
   656     if (langCount == captionCount)
       
   657     {
       
   658         jint* languages = aEnv->GetIntArrayElements(aLanguages, NULL);
       
   659         for (TInt i = 0; i < langCount; i++)
       
   660         {
       
   661             TLanguage tmpLanguage = (TLanguage)languages[i];
       
   662             HBufC *tmpCaption = CreateHBufCFromJavaStringLC(
       
   663                                     aEnv, (jstring)aEnv->GetObjectArrayElement(aAppNames, i));
       
   664             captionsArray.AppendL(tmpCaption);
       
   665             CleanupStack::Pop(tmpCaption);
       
   666             //LOG1(EJavaInstaller, EInfo,
       
   667             //     "RegisterApplicationL: language %d", tmpLanguage);
       
   668             //LOG_TDESC_L(EJavaInstaller, EInfo,
       
   669             //            "RegisterApplicationL: caption %s", tmpCaption->Des());
       
   670             CCaptionAndIconInfo *tmpCaptionAndIconInfo =
       
   671                 CCaptionAndIconInfo::NewLC(
       
   672                     /*aCaption=*/ *tmpCaption,
       
   673                     /*aIconFileName=*/ KNullDesC,
       
   674                     /*aNumOfAppIcons=*/ 0);
       
   675             CLocalizableAppInfo *tmpLocAppInfo =
       
   676                 CLocalizableAppInfo::NewLC(
       
   677                     /*aShortCaption=*/ KNullDesC,
       
   678                     /*aApplicationLanguage=*/ tmpLanguage,
       
   679                     /*aGroupName=*/ KNullDesC,
       
   680                     /*aCaptionAndIconInfo=*/ tmpCaptionAndIconInfo,
       
   681                     /*aViewDataList=*/ viewDataList);
       
   682             localizableAppInfoList.AppendL(tmpLocAppInfo);
       
   683             CleanupStack::Pop(tmpLocAppInfo);
       
   684             CleanupStack::Pop(tmpCaptionAndIconInfo);
       
   685         }
       
   686         aEnv->ReleaseIntArrayElements(aLanguages, languages, 0);
       
   687     }
       
   688     else
       
   689     {
       
   690         WLOG2(EJavaInstaller,
       
   691               "RegisterApplicationL: localisation not made because language " \
       
   692               "count does not match to caption count (%d != %d)",
       
   693               langCount, captionCount);
       
   694     }
       
   695 
       
   696     // Create application registration data objects.
       
   697     TApplicationCharacteristics appCharacteristics;
       
   698     appCharacteristics.iAttributes = TApaAppCapability::ENonNative;
       
   699     appCharacteristics.iEmbeddability = TApplicationCharacteristics::ENotEmbeddable;
       
   700     appCharacteristics.iSupportsNewFile = EFalse;
       
   701     appCharacteristics.iAppIsHidden = EFalse;
       
   702     appCharacteristics.iLaunchInBackground = EFalse;
       
   703     appCharacteristics.iGroupName = *groupName;
       
   704     CApplicationRegistrationData *appRegData =
       
   705         CApplicationRegistrationData::NewLC(
       
   706             /*aOwnedFileArray=*/ ownedFileArray,
       
   707             /*aServiceArray=*/ serviceArray,
       
   708             /*aLocalizableAppInfoList=*/ localizableAppInfoList,
       
   709             /*aAppPropertiesArray=*/ appPropertiesArray,
       
   710             /*aOpaqueDataArray=*/ opaqueDataArray,
       
   711             /*aAppUid=*/ appUid, /*aAppFile=*/ appName,
       
   712             /*aCharacteristics=*/ appCharacteristics,
       
   713             /*aDefaultScreenNumber=*/ 0);
       
   714     aScr->AddApplicationEntryL(aComponentId, *appRegData);
       
   715     CleanupStack::PopAndDestroy(appRegData);
       
   716 
       
   717     CleanupStack::PopAndDestroy(&captionsArray);
       
   718     CleanupStack::Pop(&localizableAppInfoList); // deleted in appRegData destructor
       
   719     CleanupStack::Pop(&opaqueDataArray); // deleted in appRegData destructor
       
   720 
       
   721     if (NULL != aIconFilename)
       
   722     {
       
   723         CleanupStack::PopAndDestroy(iconFilename);
       
   724     }
       
   725     CleanupStack::PopAndDestroy(groupName);
       
   726     CleanupStack::PopAndDestroy(appFilename);
       
   727     CleanupStack::PopAndDestroy(caption);
       
   728     __UHEAP_MARKEND;
       
   729 }
       
   730 #else
       
   731 void RegisterApplicationL(
       
   732     JNIEnv *, RSoftwareComponentRegistry *, jint, jint, jstring,
       
   733     jstring, jstring, jstring, jint, jintArray, jobjectArray)
       
   734 {
       
   735 }
       
   736 #endif // RD_JAVA_USIF_APP_REG
       
   737 
       
   738 /*
       
   739  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
   740  * Method:    _registerApplication
       
   741  * Signature: (IIILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I[I[Ljava/lang/String;)I
       
   742  */
       
   743 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1registerApplication
       
   744 (JNIEnv *aEnv, jclass, jint aSessionHandle, jint aComponentId, jint aAppUid,
       
   745  jstring aAppName, jstring aAppFilename, jstring aGroupName,
       
   746  jstring aIconFilename, jint aNumberOfIcons,
       
   747  jintArray aLanguages, jobjectArray aAppNames)
       
   748 {
       
   749     RSoftwareComponentRegistry *pScr =
       
   750         reinterpret_cast<RSoftwareComponentRegistry*>(aSessionHandle<<2);
       
   751     TRAPD(err, RegisterApplicationL(
       
   752               aEnv, pScr, aComponentId, aAppUid, aAppName, aAppFilename,
       
   753               aGroupName, aIconFilename, aNumberOfIcons,
       
   754               aLanguages, aAppNames));
       
   755     return err;
       
   756 }
       
   757 
       
   758 /**
       
   759  * See JNI method __1registerLocalizedComponentName.
       
   760  * This method makes calls that may leave.
       
   761  */
       
   762 void RegisterLocalizedComponentNameL(
       
   763     JNIEnv *aEnv, RSoftwareComponentRegistry *aScr, jint aComponentId,
       
   764     jstring aName, jstring aVendor, jint aLanguage)
       
   765 {
       
   766     if (NULL != aName)
       
   767     {
       
   768         HBufC *name = CreateHBufCFromJavaStringLC(aEnv, aName);
       
   769         aScr->SetComponentNameL(aComponentId, *name, (TLanguage)aLanguage);
       
   770         CleanupStack::PopAndDestroy(name);
       
   771     }
       
   772 
       
   773     if (NULL != aVendor)
       
   774     {
       
   775         HBufC *vendor = CreateHBufCFromJavaStringLC(aEnv, aVendor);
       
   776         aScr->SetVendorNameL(aComponentId, *vendor, (TLanguage)aLanguage);
       
   777         CleanupStack::PopAndDestroy(vendor);
       
   778     }
       
   779 }
       
   780 
       
   781 /*
       
   782  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
   783  * Method:    _registerLocalizedComponentName
       
   784  * Signature: (IILjava/lang/String;I)I
       
   785  */
       
   786 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1registerLocalizedComponentName
       
   787 (JNIEnv *aEnv, jclass, jint aSessionHandle, jint aComponentId, jstring aName, jstring aVendor, jint aLanguage)
       
   788 {
       
   789     __UHEAP_MARK;
       
   790     RSoftwareComponentRegistry *pScr =
       
   791         reinterpret_cast<RSoftwareComponentRegistry*>(aSessionHandle<<2);
       
   792     TRAPD(err, RegisterLocalizedComponentNameL(
       
   793               aEnv, pScr, aComponentId, aName, aVendor, aLanguage));
       
   794     __UHEAP_MARKEND;
       
   795     return err;
       
   796 }
       
   797 
       
   798 /**
       
   799  * See JNI method __1setLocalizedComponentProperty.
       
   800  * This method makes calls that may leave.
       
   801  */
       
   802 void SetLocalizedComponentPropertyL(
       
   803     JNIEnv *aEnv, RSoftwareComponentRegistry *aScr, jint aComponentId,
       
   804     jstring aName, jstring aValue, jint aLanguage)
       
   805 {
       
   806     if (NULL != aName && NULL != aValue)
       
   807     {
       
   808         HBufC *name = CreateHBufCFromJavaStringLC(aEnv, aName);
       
   809         HBufC *value = CreateHBufCFromJavaStringLC(aEnv, aValue);
       
   810         if (KUnspecifiedLocale == aLanguage)
       
   811         {
       
   812             aScr->SetComponentPropertyL(aComponentId, *name, *value);
       
   813         }
       
   814         else
       
   815         {
       
   816             aScr->SetComponentPropertyL(
       
   817                 aComponentId, *name, *value, (TLanguage)aLanguage);
       
   818         }
       
   819         CleanupStack::PopAndDestroy(value);
       
   820         CleanupStack::PopAndDestroy(name);
       
   821     }
       
   822 }
       
   823 
       
   824 /*
       
   825  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
   826  * Method:    _setLocalizedComponentProperty
       
   827  * Signature: (IILjava/lang/String;Ljava/lang/String;I)I
       
   828  */
       
   829 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1setLocalizedComponentProperty
       
   830 (JNIEnv *aEnv, jclass, jint aSessionHandle, jint aComponentId, jstring aName, jstring aValue, jint aLanguage)
       
   831 {
       
   832     __UHEAP_MARK;
       
   833     RSoftwareComponentRegistry *pScr =
       
   834         reinterpret_cast<RSoftwareComponentRegistry*>(aSessionHandle<<2);
       
   835     TRAPD(err, SetLocalizedComponentPropertyL(
       
   836               aEnv, pScr, aComponentId, aName, aValue, aLanguage));
       
   837     __UHEAP_MARKEND;
       
   838     return err;
       
   839 }
       
   840 
       
   841 /**
       
   842  * See JNI method __1getComponentId.
       
   843  * This method makes calls that may leave.
       
   844  */
       
   845 TComponentId GetComponentIdL(
       
   846     JNIEnv *aEnv, RSoftwareComponentRegistry *aScr, jstring aGlobalId)
       
   847 {
       
   848     HBufC *globalId = CreateHBufCFromJavaStringLC(aEnv, aGlobalId);
       
   849     TComponentId componentId =
       
   850         aScr->GetComponentIdL(*globalId, Usif::KSoftwareTypeJava);
       
   851     CleanupStack::PopAndDestroy(globalId);
       
   852     return componentId;
       
   853 }
       
   854 
       
   855 /*
       
   856  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
   857  * Method:    _getComponentId
       
   858  * Signature: (ILjava/lang/String;Lcom/nokia/mj/impl/installer/applicationregistrator/ComponentId;)I
       
   859  */
       
   860 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1getComponentId
       
   861 (JNIEnv *aEnv, jclass, jint aSessionHandle, jstring aGlobalId, jobject aComponentId)
       
   862 {
       
   863     __UHEAP_MARK;
       
   864     RSoftwareComponentRegistry *pScr =
       
   865         reinterpret_cast<RSoftwareComponentRegistry*>(aSessionHandle<<2);
       
   866     TComponentId componentId = -1;
       
   867     TRAPD(err, componentId = GetComponentIdL(aEnv, pScr, aGlobalId));
       
   868     __UHEAP_MARKEND;
       
   869     if (KErrNone == err)
       
   870     {
       
   871         jclass clazz = aEnv->GetObjectClass(aComponentId);
       
   872         jmethodID methodSetId = aEnv->GetMethodID(clazz, "setId", "(I)V");
       
   873         aEnv->CallVoidMethod(aComponentId, methodSetId, componentId);
       
   874     }
       
   875     return err;
       
   876 }
       
   877 
       
   878 /*
       
   879  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
   880  * Method:    _getComponentIdForApp
       
   881  * Signature: (IILcom/nokia/mj/impl/installer/applicationregistrator/ComponentId;)I
       
   882  */
       
   883 #ifdef RD_JAVA_USIF_APP_REG
       
   884 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1getComponentIdForApp
       
   885 (JNIEnv *aEnv, jclass, jint aSessionHandle, jint aAppUid, jobject aComponentId)
       
   886 {
       
   887     TInt err = KErrNone;
       
   888     __UHEAP_MARK;
       
   889     RSoftwareComponentRegistry *pScr =
       
   890         reinterpret_cast<RSoftwareComponentRegistry*>(aSessionHandle<<2);
       
   891     TUid appUid = TUid::Uid(aAppUid);
       
   892     TComponentId componentId = -1;
       
   893     TRAP(err, componentId = pScr->GetComponentIdForAppL(appUid));
       
   894     __UHEAP_MARKEND;
       
   895     if (KErrNone == err)
       
   896     {
       
   897         jclass clazz = aEnv->GetObjectClass(aComponentId);
       
   898         jmethodID methodSetId = aEnv->GetMethodID(clazz, "setId", "(I)V");
       
   899         aEnv->CallVoidMethod(aComponentId, methodSetId, componentId);
       
   900     }
       
   901     return err;
       
   902 }
       
   903 #else
       
   904 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1getComponentIdForApp
       
   905 (JNIEnv *, jclass, jint, jint, jobject)
       
   906 {
       
   907     return KErrNone;
       
   908 }
       
   909 #endif // RD_JAVA_USIF_APP_REG
       
   910 
       
   911 /**
       
   912  * See JNI method __1getuid.
       
   913  * This method makes calls that may leave.
       
   914  */
       
   915 TInt GetUidL(jint aCid)
       
   916 {
       
   917     // Create a new tmporary instance of RSoftwareComponentRegistry.
       
   918     RSoftwareComponentRegistry *pScr = CreateScrL();
       
   919     CleanupClosePushL(*pScr);
       
   920     TInt uid = 0;
       
   921     CPropertyEntry *property = pScr->GetComponentPropertyL(aCid, KUid());
       
   922     if (NULL != property)
       
   923     {
       
   924         if (property->PropertyType() == CPropertyEntry::EIntProperty)
       
   925         {
       
   926             uid = ((CIntPropertyEntry*)property)->IntValue();
       
   927         }
       
   928         else
       
   929         {
       
   930             ELOG2(EJavaInstaller,
       
   931                   "GetUidL: Incorrect property type %d for cid %d",
       
   932                   property->PropertyType(), aCid);
       
   933         }
       
   934         delete property;
       
   935     }
       
   936     // Close and delete the temporary RSoftwareComponentRegistry.
       
   937     CleanupStack::PopAndDestroy(pScr);
       
   938     delete pScr; // For some reason PopAndDestroy does not delete this.
       
   939     return uid;
       
   940 }
       
   941 
       
   942 /*
       
   943  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
   944  * Method:    _getUid
       
   945  * Signature: (IILcom/nokia/mj/impl/installer/applicationregistrator/ComponentId;)I
       
   946  */
       
   947 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1getUid
       
   948 (JNIEnv *aEnv, jclass, jint aCid, jobject aComponentId)
       
   949 {
       
   950     __UHEAP_MARK;
       
   951     TInt uid = 0;
       
   952     TRAPD(err, uid = GetUidL(aCid));
       
   953     __UHEAP_MARKEND;
       
   954     if (KErrNone == err)
       
   955     {
       
   956         jclass clazz = aEnv->GetObjectClass(aComponentId);
       
   957         jmethodID methodSetId = aEnv->GetMethodID(clazz, "setId", "(I)V");
       
   958         aEnv->CallVoidMethod(aComponentId, methodSetId, uid);
       
   959     }
       
   960     return err;
       
   961 }
       
   962 
       
   963 /**
       
   964  * See JNI method __1logComponent.
       
   965  * This method makes calls that may leave.
       
   966  */
       
   967 void LogComponentL(JNIEnv *aEnv, RSoftwareComponentRegistry *aScr, jstring aGlobalId, TLanguage aLanguage)
       
   968 {
       
   969     HBufC *globalId = CreateHBufCFromJavaStringLC(aEnv, aGlobalId);
       
   970     CComponentEntry *componentEntry =
       
   971         aScr->GetComponentL(*globalId, Usif::KSoftwareTypeJava, aLanguage);
       
   972     if (NULL == componentEntry)
       
   973     {
       
   974         //LOG_TDESC_L(EJavaInstaller, EInfo,
       
   975         //            "Component not found for GlobalId %s", globalId->Des());
       
   976         CleanupStack::PopAndDestroy(globalId);
       
   977         return;
       
   978     }
       
   979     CleanupStack::PopAndDestroy(globalId);
       
   980 
       
   981     // Log component entry.
       
   982     TComponentId componentId = componentEntry->ComponentId();
       
   983     LOG_TDESC_L(EJavaInstaller, EInfo, "GlobalId: %s", componentEntry->GlobalId());
       
   984     LOG1(EJavaInstaller, EInfo, "ComponentId: %d", componentId);
       
   985     LOG_TDESC_L(EJavaInstaller, EInfo, "SoftwareType: %s", componentEntry->SoftwareType());
       
   986     LOG_TDESC_L(EJavaInstaller, EInfo, "Name: %s", componentEntry->Name());
       
   987     LOG_TDESC_L(EJavaInstaller, EInfo, "Vendor: %s", componentEntry->Vendor());
       
   988     LOG_TDESC_L(EJavaInstaller, EInfo, "Version: %s", componentEntry->Version());
       
   989     LOG1(EJavaInstaller, EInfo, "ComponentSize: %d", componentEntry->ComponentSize());
       
   990     LOG1(EJavaInstaller, EInfo, "ScomoState: %d", componentEntry->ScomoState());
       
   991     LOG1(EJavaInstaller, EInfo, "IsDrmProtected: %d", componentEntry->IsDrmProtected());
       
   992     LOG1(EJavaInstaller, EInfo, "IsHidden: %d", componentEntry->IsHidden());
       
   993     LOG1(EJavaInstaller, EInfo, "IsKnownRevoked: %d", componentEntry->IsKnownRevoked());
       
   994     LOG1(EJavaInstaller, EInfo, "IsOriginVerified: %d", componentEntry->IsOriginVerified());
       
   995     LOG1(EJavaInstaller, EInfo, "IsRemovable: %d", componentEntry->IsRemovable());
       
   996     TDriveList driveList = componentEntry->InstalledDrives();
       
   997     for (TInt i = EDriveA; i < driveList.Length(); i++)
       
   998     {
       
   999         if (driveList[i])
       
  1000         {
       
  1001             LOG1(EJavaInstaller, EInfo, "InstalledDrive: %d", i);
       
  1002         }
       
  1003     }
       
  1004     delete componentEntry;
       
  1005 
       
  1006     // Log component properties.
       
  1007     RPointerArray<CPropertyEntry> properties;
       
  1008     aScr->GetComponentPropertiesL(componentId, properties, aLanguage);
       
  1009     CleanupResetAndDestroyPushL(properties);
       
  1010     for (TInt i = 0; i < properties.Count(); i++)
       
  1011     {
       
  1012         CPropertyEntry *propertyEntry = properties[i];
       
  1013         switch (propertyEntry->PropertyType())
       
  1014         {
       
  1015         case CPropertyEntry::EBinaryProperty:
       
  1016             LOG_TDESC_L(EJavaInstaller, EInfo, "BinaryProperty: %s",
       
  1017                         propertyEntry->PropertyName());
       
  1018             break;
       
  1019         case CPropertyEntry::EIntProperty:
       
  1020             LOG_TDESC_L(EJavaInstaller, EInfo, "IntProperty: %s",
       
  1021                         propertyEntry->PropertyName());
       
  1022             LOG2(EJavaInstaller, EInfo, "  = 0x%x (%d)",
       
  1023                  ((CIntPropertyEntry*)propertyEntry)->IntValue(),
       
  1024                  ((CIntPropertyEntry*)propertyEntry)->IntValue());
       
  1025             break;
       
  1026         case CPropertyEntry::ELocalizedProperty:
       
  1027             LOG_TDESC_L(EJavaInstaller, EInfo, "LocalizedProperty: %s",
       
  1028                         propertyEntry->PropertyName());
       
  1029             LOG_TDESC_L(EJavaInstaller, EInfo, " = %s",
       
  1030                         ((CLocalizablePropertyEntry*)propertyEntry)->StrValue());
       
  1031             break;
       
  1032         }
       
  1033     }
       
  1034     CleanupStack::PopAndDestroy(&properties);
       
  1035 
       
  1036 #ifdef RD_JAVA_USIF_APP_REG
       
  1037     // Log uids of applications associated to component.
       
  1038     RArray<TUid> appUids;
       
  1039     CleanupClosePushL(appUids);
       
  1040     aScr->GetAppUidsForComponentL(componentId, appUids);
       
  1041     if (appUids.Count() == 0)
       
  1042     {
       
  1043         LOG(EJavaInstaller, EInfo, "No component appUids found from SCR");
       
  1044     }
       
  1045     for (TInt i = 0; i < appUids.Count(); i++)
       
  1046     {
       
  1047         LOG2(EJavaInstaller, EInfo, "AppUid [%x] (%d)",
       
  1048              appUids[i].iUid, appUids[i].iUid);
       
  1049     }
       
  1050     CleanupStack::PopAndDestroy(&appUids);
       
  1051 #endif // RD_JAVA_USIF_APP_REG
       
  1052 }
       
  1053 
       
  1054 /**
       
  1055  * See JNI method __1logComponent.
       
  1056  * This method makes calls that may leave.
       
  1057  */
       
  1058 void LogComponentL(JNIEnv *aEnv, RSoftwareComponentRegistry *aScr, jstring aGlobalId)
       
  1059 {
       
  1060     // Log the component with all supported languages.
       
  1061     TComponentId componentId = GetComponentIdL(aEnv, aScr, aGlobalId);
       
  1062     RArray<TLanguage> languages;
       
  1063     CleanupClosePushL(languages);
       
  1064     aScr->GetComponentSupportedLocalesListL(componentId, languages);
       
  1065     LogComponentL(aEnv, aScr, aGlobalId, KNonLocalized);
       
  1066     for (TInt i = 0; i < languages.Count(); i++)
       
  1067     {
       
  1068         if (KNonLocalized == i)
       
  1069         {
       
  1070             continue;
       
  1071         }
       
  1072         TLanguage language = languages[i];
       
  1073         LOG1(EJavaInstaller, EInfo, "Component supports language %d", language);
       
  1074         LogComponentL(aEnv, aScr, aGlobalId, language);
       
  1075     }
       
  1076     CleanupStack::PopAndDestroy(&languages);
       
  1077 }
       
  1078 
       
  1079 /*
       
  1080  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
  1081  * Method:    _logComponent
       
  1082  * Signature: (ILjava/lang/String;)I
       
  1083  */
       
  1084 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1logComponent
       
  1085 (JNIEnv *aEnv, jclass, jint aSessionHandle, jstring aGlobalId)
       
  1086 {
       
  1087     __UHEAP_MARK;
       
  1088     RSoftwareComponentRegistry *pScr =
       
  1089         reinterpret_cast<RSoftwareComponentRegistry*>(aSessionHandle<<2);
       
  1090     TRAPD(err, LogComponentL(aEnv, pScr, aGlobalId));
       
  1091     __UHEAP_MARKEND;
       
  1092     return err;
       
  1093 }
       
  1094 
       
  1095 /*
       
  1096  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
  1097  * Method:    _getUsifMode
       
  1098  * Signature: ()I
       
  1099  */
       
  1100 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1getUsifMode
       
  1101 (JNIEnv *, jclass)
       
  1102 {
       
  1103 #ifdef RD_JAVA_USIF_APP_REG
       
  1104     return 1;
       
  1105 #else
       
  1106     return 0;
       
  1107 #endif // RD_JAVA_USIF_APP_REG
       
  1108 }
       
  1109 
       
  1110 #else // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
  1111 
       
  1112 /*
       
  1113  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
  1114  * Method:    _notifyAppChange
       
  1115  * Signature: ([II)I
       
  1116  */
       
  1117 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1notifyAppChange
       
  1118 (JNIEnv *, jclass, jintArray, jint)
       
  1119 {
       
  1120     return KErrNone;
       
  1121 }
       
  1122 
       
  1123 /*
       
  1124  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
  1125  * Method:    _launchAppView
       
  1126  * Signature: ()I
       
  1127  */
       
  1128 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1launchAppView
       
  1129 (JNIEnv *, jclass)
       
  1130 {
       
  1131     return KErrNone;
       
  1132 }
       
  1133 
       
  1134 /*
       
  1135  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
  1136  * Method:    _registerJavaSoftwareType
       
  1137  * Signature: (Z)I
       
  1138  */
       
  1139 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1registerJavaSoftwareType
       
  1140 (JNIEnv *, jclass, jboolean)
       
  1141 {
       
  1142     return KErrNone;
       
  1143 }
       
  1144 
       
  1145 /*
       
  1146  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
  1147  * Method:    _startSession
       
  1148  * Signature: ()I
       
  1149  */
       
  1150 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1startSession
       
  1151 (JNIEnv *, jclass, jboolean)
       
  1152 {
       
  1153     return 1; // dummy session handle
       
  1154 }
       
  1155 
       
  1156 /*
       
  1157  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
  1158  * Method:    _commitSession
       
  1159  * Signature: (I)I
       
  1160  */
       
  1161 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1commitSession
       
  1162 (JNIEnv *, jclass, jint)
       
  1163 {
       
  1164     return KErrNone;
       
  1165 }
       
  1166 
       
  1167 /*
       
  1168  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
  1169  * Method:    _rollbackSession
       
  1170  * Signature: (I)I
       
  1171  */
       
  1172 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1rollbackSession
       
  1173 (JNIEnv *, jclass, jint)
       
  1174 {
       
  1175     return KErrNone;
       
  1176 }
       
  1177 
       
  1178 /*
       
  1179  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
  1180  * Method:    _closeSession
       
  1181  * Signature: (I)V
       
  1182  */
       
  1183 JNIEXPORT void JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1closeSession
       
  1184 (JNIEnv *, jclass, jint)
       
  1185 {
       
  1186 }
       
  1187 
       
  1188 /*
       
  1189  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
  1190  * Method:    _registerComponent
       
  1191  * Signature: (ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;JZZZZLcom/nokia/mj/impl/installer/applicationregistrator/ComponentId;)I
       
  1192  */
       
  1193 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1registerComponent
       
  1194 (JNIEnv *, jclass, jint, jint, jstring, jstring, jstring, jstring, jstring,
       
  1195  jobjectArray, jlong, jboolean, jboolean, jboolean, jboolean, jint, jstring,
       
  1196  jstring, jstring, jobject)
       
  1197 {
       
  1198     return KErrNone;
       
  1199 }
       
  1200 
       
  1201 /*
       
  1202  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
  1203  * Method:    _unregisterComponent
       
  1204  * Signature: (II)I
       
  1205  */
       
  1206 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1unregisterComponent
       
  1207 (JNIEnv *, jclass, jint, jint)
       
  1208 {
       
  1209     return KErrNone;
       
  1210 }
       
  1211 
       
  1212 /*
       
  1213  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
  1214  * Method:    _registerApplication
       
  1215  * Signature: (IIILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I[I[Ljava/lang/String;)I
       
  1216  */
       
  1217 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1registerApplication
       
  1218 (JNIEnv *, jclass, jint, jint, jint, jstring, jstring, jstring, jstring, jint, jintArray, jobjectArray)
       
  1219 {
       
  1220     return KErrNone;
       
  1221 }
       
  1222 
       
  1223 /*
       
  1224  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
  1225  * Method:    _registerLocalizedComponentName
       
  1226  * Signature: (IILjava/lang/String;Ljava/lang/String;I)I
       
  1227  */
       
  1228 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1registerLocalizedComponentName
       
  1229 (JNIEnv *, jclass, jint, jint, jstring, jstring, jint)
       
  1230 {
       
  1231     return KErrNone;
       
  1232 }
       
  1233 
       
  1234 /*
       
  1235  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
  1236  * Method:    _setLocalizedComponentProperty
       
  1237  * Signature: (IILjava/lang/String;Ljava/lang/String;I)I
       
  1238  */
       
  1239 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1setLocalizedComponentProperty
       
  1240 (JNIEnv *, jclass, jint, jint, jstring, jstring, jint)
       
  1241 {
       
  1242     return KErrNone;
       
  1243 }
       
  1244 
       
  1245 /*
       
  1246  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
  1247  * Method:    _getComponentId
       
  1248  * Signature: (ILjava/lang/String;Lcom/nokia/mj/impl/installer/applicationregistrator/ComponentId;)I
       
  1249  */
       
  1250 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1getComponentId
       
  1251 (JNIEnv *, jclass, jint, jstring, jobject)
       
  1252 {
       
  1253     return KErrNone;
       
  1254 }
       
  1255 
       
  1256 /*
       
  1257  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
  1258  * Method:    _getComponentIdForApp
       
  1259  * Signature: (IILcom/nokia/mj/impl/installer/applicationregistrator/ComponentId;)I
       
  1260  */
       
  1261 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1getComponentIdForApp
       
  1262 (JNIEnv *, jclass, jint, jint, jobject)
       
  1263 {
       
  1264     return KErrNone;
       
  1265 }
       
  1266 
       
  1267 /*
       
  1268  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
  1269  * Method:    _getUid
       
  1270  * Signature: (IILcom/nokia/mj/impl/installer/applicationregistrator/ComponentId;)I
       
  1271  */
       
  1272 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1getUid
       
  1273 (JNIEnv *, jclass, jint, jobject)
       
  1274 {
       
  1275     return KErrNone;
       
  1276 }
       
  1277 
       
  1278 /*
       
  1279  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
  1280  * Method:    _logComponent
       
  1281  * Signature: (ILjava/lang/String;)I
       
  1282  */
       
  1283 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1logComponent
       
  1284 (JNIEnv *, jclass, jint, jstring)
       
  1285 {
       
  1286     return KErrNone;
       
  1287 }
       
  1288 
       
  1289 /*
       
  1290  * Class:     com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator
       
  1291  * Method:    _getUsifMode
       
  1292  * Signature: ()I
       
  1293  */
       
  1294 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifRegistrator__1getUsifMode
       
  1295 (JNIEnv *, jclass)
       
  1296 {
       
  1297     return 0;
       
  1298 }
       
  1299 
       
  1300 #endif // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK