javamanager/javainstaller/installer/javasrc.s60/com/nokia/mj/impl/installer/applicationregistrator/SifRegistrator.java
branchRCL_3
changeset 24 6c158198356e
parent 17 0fd27995241b
equal deleted inserted replaced
23:e5618cc85d74 24:6c158198356e
     1 /*
     1 /*
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    23 import com.nokia.mj.impl.installer.utils.ComponentId;
    23 import com.nokia.mj.impl.installer.utils.ComponentId;
    24 import com.nokia.mj.impl.installer.utils.InstallerException;
    24 import com.nokia.mj.impl.installer.utils.InstallerException;
    25 import com.nokia.mj.impl.installer.utils.FileUtils;
    25 import com.nokia.mj.impl.installer.utils.FileUtils;
    26 import com.nokia.mj.impl.installer.utils.Log;
    26 import com.nokia.mj.impl.installer.utils.Log;
    27 import com.nokia.mj.impl.installer.utils.PlatformUid;
    27 import com.nokia.mj.impl.installer.utils.PlatformUid;
    28 import com.nokia.mj.impl.rt.installer.ApplicationInfoImpl;
       
    29 import com.nokia.mj.impl.utils.Attribute;
    28 import com.nokia.mj.impl.utils.Attribute;
    30 import com.nokia.mj.impl.utils.Uid;
    29 import com.nokia.mj.impl.utils.Uid;
    31 
    30 
    32 import java.util.Enumeration;
    31 import java.util.Enumeration;
    33 import java.util.Hashtable;
    32 import java.util.Hashtable;
    59     {
    58     {
    60         return _getUsifMode();
    59         return _getUsifMode();
    61     }
    60     }
    62 
    61 
    63     /**
    62     /**
       
    63      * Returns SIF specific error category from given error id.
       
    64      */
       
    65     public static int getErrorCategory(int aErrorId)
       
    66     {
       
    67         return _getErrorCategory(aErrorId);
       
    68     }
       
    69 
       
    70     /**
    64      * Launches the application view. If launching application view
    71      * Launches the application view. If launching application view
    65      * fails this method does not throw exception but produces an
    72      * fails this method does not throw exception but produces an
    66      * error log entry.
    73      * error log entry.
    67      */
    74      */
    68     public static void launchAppView()
    75     public static void launchAppView()
   124         if (id.getId() != 0)
   131         if (id.getId() != 0)
   125         {
   132         {
   126             uid = PlatformUid.createUid(id.getId());
   133             uid = PlatformUid.createUid(id.getId());
   127         }
   134         }
   128         return uid;
   135         return uid;
   129     }
       
   130 
       
   131     /**
       
   132      * Registers or unregisters Java software type to software
       
   133      * installation framework.
       
   134      *
       
   135      * @param aRegister true for registration, false for unregistration
       
   136      */
       
   137     public static void registerJavaSoftwareType(boolean aRegister)
       
   138     {
       
   139         String op = (aRegister? "Register": "Unregister");
       
   140         int err = _registerJavaSoftwareType(aRegister);
       
   141         if (err < 0)
       
   142         {
       
   143             InstallerException.internalError(
       
   144                 op + " Java software type failed with code " + err);
       
   145         }
       
   146         else
       
   147         {
       
   148             Log.log("SifRegistrator " + op + "ed Java software type");
       
   149         }
       
   150     }
   136     }
   151 
   137 
   152     /**
   138     /**
   153      * Starts application registration session.
   139      * Starts application registration session.
   154      * The registrations and unregistrations are done only
   140      * The registrations and unregistrations are done only
   177         // negative Symbian error code if it fails.
   163         // negative Symbian error code if it fails.
   178         int ret = _startSession(aTransaction);
   164         int ret = _startSession(aTransaction);
   179         if (ret < 0)
   165         if (ret < 0)
   180         {
   166         {
   181             InstallerException.internalError(
   167             InstallerException.internalError(
   182                 "Creating session failed with code " + ret);
   168                 "Creating SIF session failed with code " + ret);
   183         }
   169         }
   184         //Log.log("SifRegistrator session started");
   170         //Log.log("SifRegistrator session started");
   185         iSessionHandle = ret;
   171         iSessionHandle = ret;
   186     }
   172     }
   187 
   173 
   196      * @see startSession
   182      * @see startSession
   197      * @see SuiteInfo
   183      * @see SuiteInfo
   198      */
   184      */
   199     public void registerSuite(SuiteInfo aSuiteInfo, boolean aIsUpdate)
   185     public void registerSuite(SuiteInfo aSuiteInfo, boolean aIsUpdate)
   200     {
   186     {
   201         if (0 == iSessionHandle)
   187         checkSession();
   202         {
       
   203             InstallerException.internalError("No valid SIF session.");
       
   204         }
       
   205         Log.log("SifRegistrator registering application suite " +
   188         Log.log("SifRegistrator registering application suite " +
   206                 aSuiteInfo.getGlobalId());
   189                 aSuiteInfo.getGlobalId());
   207 
   190 
   208         if (_getUsifMode() > 0)
   191         // Register suite as a component.
   209         {
   192         registerComponent(aSuiteInfo, aIsUpdate);
   210             // USIF Phase 2 registration.
   193         registerLocalizedComponentName(aSuiteInfo, -1);
   211             // Register suite as a component.
   194         // Register applications within the component.
   212             registerComponent(aSuiteInfo, aIsUpdate);
   195         Vector apps = aSuiteInfo.getApplications();
   213             registerLocalizedComponentName(aSuiteInfo, -1);
   196         for (int i = 0; i < apps.size(); i++)
   214             // Register applications within the component.
   197         {
   215             Vector apps = aSuiteInfo.getApplications();
   198             registerApplication(aSuiteInfo, i);
   216             for (int i = 0; i < apps.size(); i++)
       
   217             {
       
   218                 registerApplication(aSuiteInfo, i);
       
   219             }
       
   220         }
       
   221         else
       
   222         {
       
   223             // USIF Phase 1 registration.
       
   224             // Register each application in the suite.
       
   225             Vector apps = aSuiteInfo.getApplications();
       
   226             for (int i = 0; i < apps.size(); i++)
       
   227             {
       
   228                 registerComponent(aSuiteInfo, i, aIsUpdate);
       
   229                 registerLocalizedComponentName(aSuiteInfo, i);
       
   230             }
       
   231         }
   199         }
   232         registerLocalizedProperties(aSuiteInfo);
   200         registerLocalizedProperties(aSuiteInfo);
   233     }
   201     }
   234 
   202 
   235     /**
   203     /**
   241      * @see startSession
   209      * @see startSession
   242      * @see SuiteInfo
   210      * @see SuiteInfo
   243      */
   211      */
   244     public void unregisterSuite(SuiteInfo aSuiteInfo)
   212     public void unregisterSuite(SuiteInfo aSuiteInfo)
   245     {
   213     {
   246         if (0 == iSessionHandle)
   214         checkSession();
   247         {
       
   248             InstallerException.internalError("No valid SIF session.");
       
   249         }
       
   250         Log.log("SifRegistrator unregistering application suite " +
   215         Log.log("SifRegistrator unregistering application suite " +
   251                 aSuiteInfo.getGlobalId());
   216                 aSuiteInfo.getGlobalId());
   252 
   217 
   253         if (_getUsifMode() > 0)
   218         // Unregister suite as a component.
   254         {
   219         unregisterComponent(aSuiteInfo);
   255             // USIF Phase 2 unregistration.
       
   256             // Unregister suite as a component.
       
   257             unregisterComponent(aSuiteInfo);
       
   258         }
       
   259         else
       
   260         {
       
   261             // USIF Phase 1 unregistration.
       
   262             // Unregister each application in the suite.
       
   263             Vector apps = aSuiteInfo.getApplications();
       
   264             for (int i = 0; i < apps.size(); i++)
       
   265             {
       
   266                 unregisterComponent(aSuiteInfo, i);
       
   267             }
       
   268         }
       
   269     }
   220     }
   270 
   221 
   271     /**
   222     /**
   272      * Commits the registrations and unregistrations.
   223      * Commits the registrations and unregistrations.
   273      * Ends the current session if commit is successfull.
   224      * Ends the current session if commit is successfull.
   276      *
   227      *
   277      * @throws InstallerException if session cannot be committed
   228      * @throws InstallerException if session cannot be committed
   278      */
   229      */
   279     public void commitSession()
   230     public void commitSession()
   280     {
   231     {
   281         if (0 == iSessionHandle)
   232         checkSession();
   282         {
       
   283             InstallerException.internalError("No valid SIF session.");
       
   284         }
       
   285 
       
   286         int err = _commitSession(iSessionHandle);
   233         int err = _commitSession(iSessionHandle);
   287         if (err < 0)
   234         if (err < 0)
   288         {
   235         {
   289             InstallerException.internalError("Commiting session failed with code " + err);
   236             InstallerException.internalError("Commiting SIF session failed with code " + err);
   290         }
   237         }
   291         // Current session has been closed
   238         // Current session has been closed
   292         iSessionHandle = 0;
   239         iSessionHandle = 0;
   293         //Log.log("SifRegistrator session committed");
   240         //Log.log("SifRegistrator session committed");
   294     }
   241     }
   299      *
   246      *
   300      * @throws InstallerException if session cannot be rolled back.
   247      * @throws InstallerException if session cannot be rolled back.
   301      */
   248      */
   302     public void rollbackSession()
   249     public void rollbackSession()
   303     {
   250     {
   304         if (0 == iSessionHandle)
   251         checkSession();
   305         {
       
   306             InstallerException.internalError("No valid SIF session.");
       
   307         }
       
   308 
       
   309         int err = _rollbackSession(iSessionHandle);
   252         int err = _rollbackSession(iSessionHandle);
   310         // Session is closed always when rollback is called
   253         // Session is closed always when rollback is called
   311         iSessionHandle = 0;
   254         iSessionHandle = 0;
   312         if (err < 0)
   255         if (err < 0)
   313         {
   256         {
   314             InstallerException.internalError("Rolling back the session failed with code " + err);
   257             InstallerException.internalError("Rolling back SIF session failed with code " + err);
   315         }
   258         }
   316         //Log.log("SifRegistrator session rolled back");
   259         //Log.log("SifRegistrator session rolled back");
   317     }
   260     }
   318 
   261 
   319     /**
   262     /**
   325     {
   268     {
   326         if (0 == iSessionHandle)
   269         if (0 == iSessionHandle)
   327         {
   270         {
   328             return;
   271             return;
   329         }
   272         }
   330 
       
   331         _closeSession(iSessionHandle);
   273         _closeSession(iSessionHandle);
   332         // Current session has been closed
   274         // Current session has been closed
   333         iSessionHandle = 0;
   275         iSessionHandle = 0;
   334         //Log.log("SifRegistrator session closed");
   276         //Log.log("SifRegistrator session closed");
   335     }
   277     }
   342      * application with given global id cannot be found.
   284      * application with given global id cannot be found.
   343      * @throws InstallerException if an error occurs
   285      * @throws InstallerException if an error occurs
   344      */
   286      */
   345     public ComponentId getComponentId(String aGlobalId)
   287     public ComponentId getComponentId(String aGlobalId)
   346     {
   288     {
   347         if (0 == iSessionHandle)
   289         checkSession();
   348         {
       
   349             InstallerException.internalError("No valid SIF session.");
       
   350         }
       
   351 
       
   352         ComponentId result = new ComponentId();
   290         ComponentId result = new ComponentId();
   353         int ret = _getComponentId(iSessionHandle, aGlobalId, result);
   291         int ret = _getComponentId(iSessionHandle, aGlobalId, result);
   354         if (-1 == ret)
   292         if (-1 == ret)
   355         {
   293         {
   356             // Symbian error code KErrNotFound means that the
   294             // Symbian error code KErrNotFound means that the
   374      * application with given uid cannot be found.
   312      * application with given uid cannot be found.
   375      * @throws InstallerException if an error occurs
   313      * @throws InstallerException if an error occurs
   376      */
   314      */
   377     public ComponentId getComponentId(Uid aAppUid)
   315     public ComponentId getComponentId(Uid aAppUid)
   378     {
   316     {
   379         if (0 == iSessionHandle)
   317         checkSession();
   380         {
       
   381             InstallerException.internalError("No valid SIF session.");
       
   382         }
       
   383 
       
   384         ComponentId result = new ComponentId();
   318         ComponentId result = new ComponentId();
   385         int ret = _getComponentIdForApp(
   319         int ret = _getComponentIdForApp(
   386                       iSessionHandle, ((PlatformUid)aAppUid).getIntValue(), result);
   320                       iSessionHandle, ((PlatformUid)aAppUid).getIntValue(), result);
   387         if (-1 == ret)
   321         if (-1 == ret)
   388         {
   322         {
   404      *
   338      *
   405      * @param aGlobalId the global id for the application.
   339      * @param aGlobalId the global id for the application.
   406      */
   340      */
   407     public void logComponent(String aGlobalId)
   341     public void logComponent(String aGlobalId)
   408     {
   342     {
   409         if (0 == iSessionHandle)
   343         checkSession();
   410         {
       
   411             InstallerException.internalError("No valid SIF session.");
       
   412         }
       
   413 
       
   414         int ret = _logComponent(iSessionHandle, aGlobalId);
   344         int ret = _logComponent(iSessionHandle, aGlobalId);
   415         if (ret < -1)
   345         if (ret < -1)
   416         {
   346         {
   417             Log.logError("SifRegistrator logComponent failed with code " + ret);
   347             Log.logError("SifRegistrator logComponent for " + aGlobalId +
       
   348                          " failed with code " + ret);
   418         }
   349         }
   419     }
   350     }
   420 
   351 
   421     /*** ----------------------------- PACKAGE ---------------------------- */
   352     /*** ----------------------------- PACKAGE ---------------------------- */
   422     /*** ----------------------------- PRIVATE ---------------------------- */
   353     /*** ----------------------------- PRIVATE ---------------------------- */
   423 
   354 
   424     /**
   355     /**
   425      * Registers one Java application to S60 USIF as a component.
   356      * Checks if SifRegistrator session has been started.
   426      * Used with USIF Phase 1.
   357      * @throws InstallerException if SifRegistrator session has not been started
   427      *
   358      */
   428      * @param aSuiteInfo Information needed to register the application
   359     private void checkSession()
   429      * @param aIndex index of the application in the suite
   360     {
   430      * @param aIsUpdate true in case of an update, false in case of a new
   361         if (iSessionHandle == 0)
   431      * installation
   362         {
   432      * @throws InstallerException if registration cannot done or
   363             InstallerException.internalError("No valid SIF session.");
   433      *  startSession has not been called successfully
       
   434      * @see startSession
       
   435      * @see SuiteInfo
       
   436      */
       
   437     private void registerComponent(
       
   438         SuiteInfo aSuiteInfo, int aIndex, boolean aIsUpdate)
       
   439     {
       
   440         String globalId = aSuiteInfo.getGlobalId(aIndex);
       
   441         if (globalId == null)
       
   442         {
       
   443             Log.logWarning("SifRegistrator: Application with index " + aIndex +
       
   444                            " not found from " + aSuiteInfo.getGlobalId());
       
   445             return;
       
   446         }
       
   447         ApplicationInfo appInfo =
       
   448             (ApplicationInfo)aSuiteInfo.getApplications().elementAt(aIndex);
       
   449         String suiteName = aSuiteInfo.getName();
       
   450         String vendor = aSuiteInfo.getVendor();
       
   451         String version = aSuiteInfo.getVersion().toString();
       
   452         String name = appInfo.getName();
       
   453         int uid = ((PlatformUid)appInfo.getUid()).getIntValue();
       
   454         String[] componentFiles = getComponentFiles(aSuiteInfo);
       
   455         long componentSize = aSuiteInfo.getInitialSize();
       
   456         String attrValue = aSuiteInfo.getAttributeValue("Nokia-MIDlet-Block-Uninstall");
       
   457         boolean isRemovable = !(attrValue != null && attrValue.equalsIgnoreCase("true"));
       
   458         boolean isDrmProtected = (aSuiteInfo.getContentInfo() == aSuiteInfo.CONTENT_INFO_DRM);
       
   459         boolean isOriginVerified = aSuiteInfo.isTrusted();
       
   460         String midletInfoUrl = aSuiteInfo.getAttributeValue("MIDlet-Info-URL");
       
   461         String midletDescription = aSuiteInfo.getAttributeValue("MIDlet-Description");
       
   462         String downloadUrl = aSuiteInfo.getAttributeValue("Nokia-MIDlet-Download-URL");
       
   463         ComponentId componentId = new ComponentId();
       
   464         int err = _registerComponent(
       
   465                       iSessionHandle, uid,
       
   466                       getScrString(suiteName), getScrString(vendor),
       
   467                       getScrString(version), getScrString(name),
       
   468                       getScrString(globalId), componentFiles,
       
   469                       componentSize, isRemovable, isDrmProtected,
       
   470                       isOriginVerified, aIsUpdate, aSuiteInfo.getMediaId(),
       
   471                       getScrString(midletInfoUrl),
       
   472                       getScrString(midletDescription),
       
   473                       getScrString(downloadUrl),
       
   474                       componentId);
       
   475         if (err < 0)
       
   476         {
       
   477             InstallerException.internalError(
       
   478                 "Registering component " + globalId +
       
   479                 " failed with code " + err);
       
   480         }
       
   481         else
       
   482         {
       
   483             appInfo.setComponentId(componentId);
       
   484             Log.log("SifRegistrator registered component " + globalId +
       
   485                     " with id " + componentId.getId());
       
   486         }
       
   487     }
       
   488 
       
   489     /**
       
   490      * Unregisters one Java application from being S60 USIF component.
       
   491      * Used with USIF Phase 1.
       
   492      *
       
   493      * @param aSuiteInfo Information needed to unregister the application,
       
   494      * @param aIndex index of the application in the suite
       
   495      * @throws InstallerException if unregistration cannot done or
       
   496      *  startSession has not been called successfully
       
   497      * @see startSession
       
   498      * @see SuiteInfo
       
   499      */
       
   500     private void unregisterComponent(SuiteInfo aSuiteInfo, int aIndex)
       
   501     {
       
   502         String globalId = aSuiteInfo.getGlobalId(aIndex);
       
   503         if (globalId == null)
       
   504         {
       
   505             Log.logWarning("SifRegistrator: Application with index " + aIndex +
       
   506                            " not found from " + aSuiteInfo.getGlobalId());
       
   507             return;
       
   508         }
       
   509         ComponentId componentId = getComponentId(globalId);
       
   510         if (componentId == null)
       
   511         {
       
   512             Log.logWarning(
       
   513                 "SifRegistrator unregistration failed, application " +
       
   514                 globalId + " does not exist");
       
   515             return;
       
   516         }
       
   517         // Save component id to ApplicationInfo.
       
   518         ApplicationInfo appInfo =
       
   519             (ApplicationInfo)aSuiteInfo.getApplications().elementAt(aIndex);
       
   520         appInfo.setComponentId(componentId);
       
   521         // Unregister application.
       
   522         int err = _unregisterComponent(iSessionHandle, componentId.getId());
       
   523         if (err < 0)
       
   524         {
       
   525             InstallerException.internalError(
       
   526                 "Unregistering component " + globalId +
       
   527                 " failed with code " + err);
       
   528         }
       
   529         else
       
   530         {
       
   531             Log.log("SifRegistrator unregistered component " + globalId +
       
   532                     " with id " + componentId.getId());
       
   533         }
   364         }
   534     }
   365     }
   535 
   366 
   536     /**
   367     /**
   537      * Registers Java application suite to S60 USIF as a component.
   368      * Registers Java application suite to S60 USIF as a component.
   538      * Used with USIF Phase 2.
       
   539      *
   369      *
   540      * @param aSuiteInfo Suite information
   370      * @param aSuiteInfo Suite information
   541      * @param aIsUpdate true in case of an update, false in case of a new
   371      * @param aIsUpdate true in case of an update, false in case of a new
   542      * installation
   372      * installation
   543      * @throws InstallerException if registration cannot done or
   373      * @throws InstallerException if registration cannot done or
   549     {
   379     {
   550         String globalId = aSuiteInfo.getGlobalId();
   380         String globalId = aSuiteInfo.getGlobalId();
   551         String suiteName = aSuiteInfo.getName();
   381         String suiteName = aSuiteInfo.getName();
   552         String vendor = aSuiteInfo.getVendor();
   382         String vendor = aSuiteInfo.getVendor();
   553         String version = aSuiteInfo.getVersion().toString();
   383         String version = aSuiteInfo.getVersion().toString();
   554         String name = null; // Set name to null so that suite name will be used.
       
   555         int uid = ((PlatformUid)aSuiteInfo.getUid()).getIntValue();
   384         int uid = ((PlatformUid)aSuiteInfo.getUid()).getIntValue();
   556         String[] componentFiles = getComponentFiles(aSuiteInfo);
   385         String[] componentFiles = getComponentFiles(aSuiteInfo);
   557         long componentSize = aSuiteInfo.getInitialSize();
   386         long componentSize = aSuiteInfo.getInitialSize();
   558         String attrValue = aSuiteInfo.getAttributeValue("Nokia-MIDlet-Block-Uninstall");
   387         String attrValue = aSuiteInfo.getAttributeValue("Nokia-MIDlet-Block-Uninstall");
   559         boolean isRemovable = !(attrValue != null && attrValue.equalsIgnoreCase("true"));
   388         boolean isRemovable = !(attrValue != null && attrValue.equalsIgnoreCase("true"));
   560         boolean isDrmProtected = (aSuiteInfo.getContentInfo() == aSuiteInfo.CONTENT_INFO_DRM);
   389         boolean isDrmProtected = (aSuiteInfo.getContentInfo() == aSuiteInfo.CONTENT_INFO_DRM);
   561         boolean isOriginVerified = aSuiteInfo.isTrusted();
   390         boolean isOriginVerified = aSuiteInfo.isTrusted();
   562         String midletInfoUrl = aSuiteInfo.getAttributeValue("MIDlet-Info-URL");
   391         String midletInfoUrl = aSuiteInfo.getAttributeValue("MIDlet-Info-URL");
   563         String midletDescription = aSuiteInfo.getAttributeValue("MIDlet-Description");
   392         String midletDescription = aSuiteInfo.getAttributeValue("MIDlet-Description");
   564         String downloadUrl = aSuiteInfo.getAttributeValue("Nokia-MIDlet-Download-URL");
   393         String downloadUrl = aSuiteInfo.getAttributeValue("Nokia-MIDlet-Download-URL");
       
   394         String updateUrl = aSuiteInfo.getAttributeValue("Nokia-Update");
   565         ComponentId componentId = new ComponentId();
   395         ComponentId componentId = new ComponentId();
   566         int err = _registerComponent(
   396         int err = _registerComponent(
   567                       iSessionHandle, uid,
   397                       iSessionHandle, uid,
   568                       getScrString(suiteName), getScrString(vendor),
   398                       getScrString(suiteName), getScrString(vendor),
   569                       getScrString(version), getScrString(name),
   399                       getScrString(version), getScrString(globalId),
   570                       getScrString(globalId), componentFiles,
   400                       componentFiles, componentSize,
   571                       componentSize, isRemovable, isDrmProtected,
   401                       isRemovable, isDrmProtected,
   572                       isOriginVerified, aIsUpdate, aSuiteInfo.getMediaId(),
   402                       isOriginVerified, aIsUpdate,
       
   403                       aSuiteInfo.getMediaId(),
   573                       getScrString(midletInfoUrl),
   404                       getScrString(midletInfoUrl),
   574                       getScrString(midletDescription),
   405                       getScrString(midletDescription),
   575                       getScrString(downloadUrl),
   406                       getScrString(downloadUrl),
       
   407                       getScrString(updateUrl),
   576                       componentId);
   408                       componentId);
   577         if (err < 0)
   409         if (err < 0)
   578         {
   410         {
   579             InstallerException.internalError(
   411             InstallerException.internalError(
   580                 "Registering component " + globalId +
   412                 "Registering component " + globalId +
   588         }
   420         }
   589     }
   421     }
   590 
   422 
   591     /**
   423     /**
   592      * Unregisters Java application suite from being S60 USIF component.
   424      * Unregisters Java application suite from being S60 USIF component.
   593      * Used with USIF Phase 2.
       
   594      *
   425      *
   595      * @param aSuiteInfo suite information
   426      * @param aSuiteInfo suite information
   596      * @throws InstallerException if unregistration cannot done or
   427      * @throws InstallerException if unregistration cannot done or
   597      *  startSession has not been called successfully
   428      *  startSession has not been called successfully
   598      * @see startSession
   429      * @see startSession
   630      * Registers one Java application to S60 USIF as an S60 application.
   461      * Registers one Java application to S60 USIF as an S60 application.
   631      * The application is registered to component whose id is taken
   462      * The application is registered to component whose id is taken
   632      * from given SuiteInfo object. The SuiteInfo must already have
   463      * from given SuiteInfo object. The SuiteInfo must already have
   633      * been registered to USIF as a component with registerComponent()
   464      * been registered to USIF as a component with registerComponent()
   634      * method before this method is called.
   465      * method before this method is called.
   635      * Used with USIF Phase 2.
       
   636      *
   466      *
   637      * @param aSuiteInfo information needed to register the application
   467      * @param aSuiteInfo information needed to register the application
   638      * @param aIndex index of the application in the suite
   468      * @param aIndex index of the application in the suite
   639      * @throws InstallerException if registration cannot done or
   469      * @throws InstallerException if registration cannot done or
   640      *  startSession has not been called successfully
   470      *  startSession has not been called successfully
   688     }
   518     }
   689 
   519 
   690     private static String[] getComponentFiles(SuiteInfo aSuite)
   520     private static String[] getComponentFiles(SuiteInfo aSuite)
   691     {
   521     {
   692         Vector componentFiles = new Vector();
   522         Vector componentFiles = new Vector();
   693         String path = aSuite.getJadPath();
   523         if (!aSuite.isPreinstalled())
   694         if (path != null)
   524         {
   695         {
   525             // Add component jad and jar files only when the
   696             componentFiles.addElement(getScrString(path));
   526             // application is not preinstalled.
   697         }
   527             String path = aSuite.getJadPath();
   698         path = aSuite.getJarPath();
   528             if (path != null)
   699         if (path != null)
   529             {
   700         {
   530                 componentFiles.addElement(getScrString(path));
   701             componentFiles.addElement(getScrString(path));
   531             }
       
   532             path = aSuite.getJarPath();
       
   533             if (path != null)
       
   534             {
       
   535                 componentFiles.addElement(getScrString(path));
       
   536             }
   702         }
   537         }
   703         boolean addRootPath = true;
   538         boolean addRootPath = true;
   704         int rootDrive = FileUtils.getDrive(aSuite.getRootDir());
   539         int rootDrive = FileUtils.getDrive(aSuite.getRootDir());
   705         for (int i = 0; i < componentFiles.size(); i++)
   540         for (int i = 0; i < componentFiles.size(); i++)
   706         {
   541         {
   714                 break;
   549                 break;
   715             }
   550             }
   716         }
   551         }
   717         if (addRootPath)
   552         if (addRootPath)
   718         {
   553         {
   719             componentFiles.addElement(getScrString(aSuite.getRootDir()));
   554             componentFiles.addElement(
       
   555                 getScrString(aSuite.getRootDir() + "nofile.txt"));
   720         }
   556         }
   721         String[] result = new String[componentFiles.size()];
   557         String[] result = new String[componentFiles.size()];
   722         componentFiles.copyInto(result);
   558         componentFiles.copyInto(result);
       
   559         for (int i = 0; i < result.length; i++)
       
   560         {
       
   561             Log.log("SifRegistrator componentFiles[" + i + "]: " + result[i]);
       
   562         }
   723         return result;
   563         return result;
   724     }
   564     }
   725 
   565 
   726     /**
   566     /**
   727      * Registers localized names for given application from given suite.
   567      * Registers localized names for given application from given suite.
   807             InstallerException.internalError(
   647             InstallerException.internalError(
   808                 "Adding property " + attrName + " for component " + cid +
   648                 "Adding property " + attrName + " for component " + cid +
   809                 " failed with code " + err + " (" + nonlocalizedAttrValue + ")");
   649                 " failed with code " + err + " (" + nonlocalizedAttrValue + ")");
   810         }
   650         }
   811         LocalizedName[] localizedAttrValues =
   651         LocalizedName[] localizedAttrValues =
   812             getLocalizedNames(aSuite, attrName + "-");
   652             getLocalizedNames(aSuite, "Nokia-" + attrName + "-");
   813         for (int i = 0; i < localizedAttrValues.length; i++)
   653         for (int i = 0; i < localizedAttrValues.length; i++)
   814         {
   654         {
   815             err = _setLocalizedComponentProperty(
   655             err = _setLocalizedComponentProperty(
   816                       iSessionHandle, cid, getScrString(attrName),
   656                       iSessionHandle, cid, getScrString(attrName),
   817                       getScrString(localizedAttrValues[i].getName()),
   657                       getScrString(localizedAttrValues[i].getName()),
   824                     " (" + localizedAttrValues[i] + ")");
   664                     " (" + localizedAttrValues[i] + ")");
   825             }
   665             }
   826         }
   666         }
   827 
   667 
   828         // Register Domain-Category property.
   668         // Register Domain-Category property.
   829         ApplicationInfoImpl appInfoImpl = (ApplicationInfoImpl)
   669         String protectionDomainProperty = "Domain-Category";
   830                                           com.nokia.mj.impl.rt.support.ApplicationInfo.getInstance();
   670         String protectionDomainName = aSuite.getProtectionDomainName();
   831         String domainCategory = appInfoImpl.getProtectionDomain();
       
   832         err = _setLocalizedComponentProperty(
   671         err = _setLocalizedComponentProperty(
   833                   iSessionHandle, cid, "Domain-Category",
   672             iSessionHandle, cid, protectionDomainProperty,
   834                   domainCategory, UNSPECIFIED_LOCALE);
   673             getProtectionDomainPropertyValue(protectionDomainName),
       
   674             UNSPECIFIED_LOCALE);
   835         if (err < 0)
   675         if (err < 0)
   836         {
   676         {
   837             InstallerException.internalError(
   677             InstallerException.internalError(
   838                 "Adding property Domain-Category value " + domainCategory +
   678                 "Adding property " + protectionDomainProperty +
   839                 " for component " + cid + " failed with code " + err);
   679                 " value " + protectionDomainName + " for component " +
   840         }
   680                 cid + " failed with code " + err);
       
   681         }
       
   682     }
       
   683 
       
   684     /**
       
   685      * Returns the "Domain-Category" property value which contains
       
   686      * the text id and text file name for the localized domain category
       
   687      * text. This method must never return null.
       
   688      */
       
   689     private String getProtectionDomainPropertyValue(String aProtectionDomain)
       
   690     {
       
   691         String textId = "txt_java_inst_setlabel_cert_domain_val_untrusted_third_party";
       
   692         if (aProtectionDomain != null)
       
   693         {
       
   694             if (aProtectionDomain.equals("Manufacturer"))
       
   695             {
       
   696                 textId = "txt_java_inst_setlabel_cert_domain_val_manufacturer";
       
   697             }
       
   698             else if (aProtectionDomain.equals("Operator"))
       
   699             {
       
   700                 textId = "txt_java_inst_setlabel_cert_domain_val_operator";
       
   701             }
       
   702             else if (aProtectionDomain.equals("IdentifiedThirdParty"))
       
   703             {
       
   704                 textId = "txt_java_inst_setlabel_cert_domain_val_trusted_third_party";
       
   705             }
       
   706         }
       
   707         return textId + ",javaapplicationinstaller";
   841     }
   708     }
   842 
   709 
   843     /**
   710     /**
   844      * Returns array of localized names from the specified
   711      * Returns array of localized names from the specified
   845      * attributes of given suite. Assumes that aAttrPrefix
   712      * attributes of given suite. Assumes that aAttrPrefix
   867                     {
   734                     {
   868                         Log.logWarning(
   735                         Log.logWarning(
   869                             "SifRegistrator ignored unknown locale: " +
   736                             "SifRegistrator ignored unknown locale: " +
   870                             name + ": " + localizedName);
   737                             name + ": " + localizedName);
   871                     }
   738                     }
       
   739                     else if (localizedName.getName() == null ||
       
   740                              localizedName.getName().length() == 0)
       
   741                     {
       
   742                         Log.logWarning(
       
   743                             "SifRegistrator ignored empty localized text: " +
       
   744                             name + ": " + localizedName);
       
   745                     }
   872                     else
   746                     else
   873                     {
   747                     {
   874                         Log.log("SifRegistrator found localized text " +
   748                         Log.log("SifRegistrator found localized text " +
   875                                 name + ": " + localizedName);
   749                                 name + ": " + localizedName);
   876                         localizedNames.put(
   750                         localizedNames.put(
   947      * @return 0 or Symbian error code (negative number)
   821      * @return 0 or Symbian error code (negative number)
   948      */
   822      */
   949     private static native int _launchAppView();
   823     private static native int _launchAppView();
   950 
   824 
   951     /**
   825     /**
   952      * Registers Java software type to software installation framework.
       
   953      *
       
   954      * @param aRegister true for registration, false for unregistration
       
   955      * @return 0 or Symbian error code (negative number)
       
   956      */
       
   957     private static native int _registerJavaSoftwareType(boolean aRegister);
       
   958 
       
   959     /**
       
   960      * Starts native application registration session.
   826      * Starts native application registration session.
   961      *
   827      *
   962      * @param aTransaction true if also transaction for this session should
   828      * @param aTransaction true if also transaction for this session should
   963      * be opened, false otherwise
   829      * be opened, false otherwise
   964      * @return native session handle or Symbian error code (negative number)
   830      * @return native session handle or Symbian error code (negative number)
   996      * @param aSessionHandle
   862      * @param aSessionHandle
   997      * @param aUid
   863      * @param aUid
   998      * @param aSuiteName
   864      * @param aSuiteName
   999      * @param aVendor
   865      * @param aVendor
  1000      * @param aVersion
   866      * @param aVersion
  1001      * @param aName
       
  1002      * @param aGlobalId
   867      * @param aGlobalId
  1003      * @param aComponentFiles
   868      * @param aComponentFiles
  1004      * @param aComponentSize
   869      * @param aComponentSize
  1005      * @param aIsRemovable
   870      * @param aIsRemovable
  1006      * @param aIsDrmProtected
   871      * @param aIsDrmProtected
  1008      * @param aIsUpdate
   873      * @param aIsUpdate
  1009      * @param aMediaId
   874      * @param aMediaId
  1010      * @param aMidletInfoUrl
   875      * @param aMidletInfoUrl
  1011      * @param aMidletDescription
   876      * @param aMidletDescription
  1012      * @param aDownloadUrl
   877      * @param aDownloadUrl
       
   878      * @param aUpdateUrl
  1013      * @param aComponentId upon successful execution contains the
   879      * @param aComponentId upon successful execution contains the
  1014      * component id for the registered component
   880      * component id for the registered component
  1015      * @return 0 if registration succeeded or Symbian error code
   881      * @return 0 if registration succeeded or Symbian error code
  1016      */
   882      */
  1017     private static native int _registerComponent(
   883     private static native int _registerComponent(
  1018         int aSessionHandle, int aUid, String aSuiteName, String aVendor,
   884         int aSessionHandle, int aUid, String aSuiteName, String aVendor,
  1019         String aVersion, String aName, String aGlobalId,
   885         String aVersion, String aGlobalId,
  1020         String[] aComponentFiles, long aComponentSize,
   886         String[] aComponentFiles, long aComponentSize,
  1021         boolean aIsRemovable, boolean aIsDrmProtected,
   887         boolean aIsRemovable, boolean aIsDrmProtected,
  1022         boolean aIsOriginVerified, boolean aIsUpdate, int aMediaId,
   888         boolean aIsOriginVerified, boolean aIsUpdate, int aMediaId,
  1023         String aMidletInfoUrl, String aMidletDescription, String aDownloadUrl,
   889         String aMidletInfoUrl, String aMidletDescription,
       
   890         String aDownloadUrl, String aUpdateUrl,
  1024         ComponentId aComponentId);
   891         ComponentId aComponentId);
  1025 
   892 
  1026     /**
   893     /**
  1027      * Unregisters Java application from S60 USIF.
   894      * Unregisters Java application from S60 USIF.
  1028      *
   895      *
  1126      * Checks if USIF is enabled.
   993      * Checks if USIF is enabled.
  1127      *
   994      *
  1128      * @return 1 if application data should be registered to USIF, 0 otherwise
   995      * @return 1 if application data should be registered to USIF, 0 otherwise
  1129      */
   996      */
  1130     private static native int _getUsifMode();
   997     private static native int _getUsifMode();
       
   998 
       
   999     /**
       
  1000      * Returns SIF specific error category from given error id.
       
  1001      */
       
  1002     private static native int _getErrorCategory(int aErrorId);
  1131 }
  1003 }