javamanager/javainstaller/installer/javasrc.s60/com/nokia/mj/impl/installer/applicationregistrator/SifRegistrator.java
branchRCL_3
changeset 83 26b2b12093af
parent 60 6c158198356e
equal deleted inserted replaced
77:7cee158cb8cd 83:26b2b12093af
     1 /*
     1 /*
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008-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;
    28 import com.nokia.mj.impl.utils.Attribute;
    29 import com.nokia.mj.impl.utils.Attribute;
    29 import com.nokia.mj.impl.utils.Uid;
    30 import com.nokia.mj.impl.utils.Uid;
    30 
    31 
    31 import java.util.Enumeration;
    32 import java.util.Enumeration;
    32 import java.util.Hashtable;
    33 import java.util.Hashtable;
    58     {
    59     {
    59         return _getUsifMode();
    60         return _getUsifMode();
    60     }
    61     }
    61 
    62 
    62     /**
    63     /**
    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     /**
       
    71      * Launches the application view. If launching application view
    64      * Launches the application view. If launching application view
    72      * fails this method does not throw exception but produces an
    65      * fails this method does not throw exception but produces an
    73      * error log entry.
    66      * error log entry.
    74      */
    67      */
    75     public static void launchAppView()
    68     public static void launchAppView()
   131         if (id.getId() != 0)
   124         if (id.getId() != 0)
   132         {
   125         {
   133             uid = PlatformUid.createUid(id.getId());
   126             uid = PlatformUid.createUid(id.getId());
   134         }
   127         }
   135         return uid;
   128         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         }
   136     }
   150     }
   137 
   151 
   138     /**
   152     /**
   139      * Starts application registration session.
   153      * Starts application registration session.
   140      * The registrations and unregistrations are done only
   154      * The registrations and unregistrations are done only
   163         // negative Symbian error code if it fails.
   177         // negative Symbian error code if it fails.
   164         int ret = _startSession(aTransaction);
   178         int ret = _startSession(aTransaction);
   165         if (ret < 0)
   179         if (ret < 0)
   166         {
   180         {
   167             InstallerException.internalError(
   181             InstallerException.internalError(
   168                 "Creating SIF session failed with code " + ret);
   182                 "Creating session failed with code " + ret);
   169         }
   183         }
   170         //Log.log("SifRegistrator session started");
   184         //Log.log("SifRegistrator session started");
   171         iSessionHandle = ret;
   185         iSessionHandle = ret;
   172     }
   186     }
   173 
   187 
   182      * @see startSession
   196      * @see startSession
   183      * @see SuiteInfo
   197      * @see SuiteInfo
   184      */
   198      */
   185     public void registerSuite(SuiteInfo aSuiteInfo, boolean aIsUpdate)
   199     public void registerSuite(SuiteInfo aSuiteInfo, boolean aIsUpdate)
   186     {
   200     {
   187         checkSession();
   201         if (0 == iSessionHandle)
       
   202         {
       
   203             InstallerException.internalError("No valid SIF session.");
       
   204         }
   188         Log.log("SifRegistrator registering application suite " +
   205         Log.log("SifRegistrator registering application suite " +
   189                 aSuiteInfo.getGlobalId());
   206                 aSuiteInfo.getGlobalId());
   190 
   207 
   191         // Register suite as a component.
   208         if (_getUsifMode() > 0)
   192         registerComponent(aSuiteInfo, aIsUpdate);
   209         {
   193         registerLocalizedComponentName(aSuiteInfo, -1);
   210             // USIF Phase 2 registration.
   194         // Register applications within the component.
   211             // Register suite as a component.
   195         Vector apps = aSuiteInfo.getApplications();
   212             registerComponent(aSuiteInfo, aIsUpdate);
   196         for (int i = 0; i < apps.size(); i++)
   213             registerLocalizedComponentName(aSuiteInfo, -1);
   197         {
   214             // Register applications within the component.
   198             registerApplication(aSuiteInfo, i);
   215             Vector apps = aSuiteInfo.getApplications();
       
   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             }
   199         }
   231         }
   200         registerLocalizedProperties(aSuiteInfo);
   232         registerLocalizedProperties(aSuiteInfo);
   201     }
   233     }
   202 
   234 
   203     /**
   235     /**
   209      * @see startSession
   241      * @see startSession
   210      * @see SuiteInfo
   242      * @see SuiteInfo
   211      */
   243      */
   212     public void unregisterSuite(SuiteInfo aSuiteInfo)
   244     public void unregisterSuite(SuiteInfo aSuiteInfo)
   213     {
   245     {
   214         checkSession();
   246         if (0 == iSessionHandle)
       
   247         {
       
   248             InstallerException.internalError("No valid SIF session.");
       
   249         }
   215         Log.log("SifRegistrator unregistering application suite " +
   250         Log.log("SifRegistrator unregistering application suite " +
   216                 aSuiteInfo.getGlobalId());
   251                 aSuiteInfo.getGlobalId());
   217 
   252 
   218         // Unregister suite as a component.
   253         if (_getUsifMode() > 0)
   219         unregisterComponent(aSuiteInfo);
   254         {
       
   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         }
   220     }
   269     }
   221 
   270 
   222     /**
   271     /**
   223      * Commits the registrations and unregistrations.
   272      * Commits the registrations and unregistrations.
   224      * Ends the current session if commit is successfull.
   273      * Ends the current session if commit is successfull.
   227      *
   276      *
   228      * @throws InstallerException if session cannot be committed
   277      * @throws InstallerException if session cannot be committed
   229      */
   278      */
   230     public void commitSession()
   279     public void commitSession()
   231     {
   280     {
   232         checkSession();
   281         if (0 == iSessionHandle)
       
   282         {
       
   283             InstallerException.internalError("No valid SIF session.");
       
   284         }
       
   285 
   233         int err = _commitSession(iSessionHandle);
   286         int err = _commitSession(iSessionHandle);
   234         if (err < 0)
   287         if (err < 0)
   235         {
   288         {
   236             InstallerException.internalError("Commiting SIF session failed with code " + err);
   289             InstallerException.internalError("Commiting session failed with code " + err);
   237         }
   290         }
   238         // Current session has been closed
   291         // Current session has been closed
   239         iSessionHandle = 0;
   292         iSessionHandle = 0;
   240         //Log.log("SifRegistrator session committed");
   293         //Log.log("SifRegistrator session committed");
   241     }
   294     }
   246      *
   299      *
   247      * @throws InstallerException if session cannot be rolled back.
   300      * @throws InstallerException if session cannot be rolled back.
   248      */
   301      */
   249     public void rollbackSession()
   302     public void rollbackSession()
   250     {
   303     {
   251         checkSession();
   304         if (0 == iSessionHandle)
       
   305         {
       
   306             InstallerException.internalError("No valid SIF session.");
       
   307         }
       
   308 
   252         int err = _rollbackSession(iSessionHandle);
   309         int err = _rollbackSession(iSessionHandle);
   253         // Session is closed always when rollback is called
   310         // Session is closed always when rollback is called
   254         iSessionHandle = 0;
   311         iSessionHandle = 0;
   255         if (err < 0)
   312         if (err < 0)
   256         {
   313         {
   257             InstallerException.internalError("Rolling back SIF session failed with code " + err);
   314             InstallerException.internalError("Rolling back the session failed with code " + err);
   258         }
   315         }
   259         //Log.log("SifRegistrator session rolled back");
   316         //Log.log("SifRegistrator session rolled back");
   260     }
   317     }
   261 
   318 
   262     /**
   319     /**
   268     {
   325     {
   269         if (0 == iSessionHandle)
   326         if (0 == iSessionHandle)
   270         {
   327         {
   271             return;
   328             return;
   272         }
   329         }
       
   330 
   273         _closeSession(iSessionHandle);
   331         _closeSession(iSessionHandle);
   274         // Current session has been closed
   332         // Current session has been closed
   275         iSessionHandle = 0;
   333         iSessionHandle = 0;
   276         //Log.log("SifRegistrator session closed");
   334         //Log.log("SifRegistrator session closed");
   277     }
   335     }
   284      * application with given global id cannot be found.
   342      * application with given global id cannot be found.
   285      * @throws InstallerException if an error occurs
   343      * @throws InstallerException if an error occurs
   286      */
   344      */
   287     public ComponentId getComponentId(String aGlobalId)
   345     public ComponentId getComponentId(String aGlobalId)
   288     {
   346     {
   289         checkSession();
   347         if (0 == iSessionHandle)
       
   348         {
       
   349             InstallerException.internalError("No valid SIF session.");
       
   350         }
       
   351 
   290         ComponentId result = new ComponentId();
   352         ComponentId result = new ComponentId();
   291         int ret = _getComponentId(iSessionHandle, aGlobalId, result);
   353         int ret = _getComponentId(iSessionHandle, aGlobalId, result);
   292         if (-1 == ret)
   354         if (-1 == ret)
   293         {
   355         {
   294             // Symbian error code KErrNotFound means that the
   356             // Symbian error code KErrNotFound means that the
   312      * application with given uid cannot be found.
   374      * application with given uid cannot be found.
   313      * @throws InstallerException if an error occurs
   375      * @throws InstallerException if an error occurs
   314      */
   376      */
   315     public ComponentId getComponentId(Uid aAppUid)
   377     public ComponentId getComponentId(Uid aAppUid)
   316     {
   378     {
   317         checkSession();
   379         if (0 == iSessionHandle)
       
   380         {
       
   381             InstallerException.internalError("No valid SIF session.");
       
   382         }
       
   383 
   318         ComponentId result = new ComponentId();
   384         ComponentId result = new ComponentId();
   319         int ret = _getComponentIdForApp(
   385         int ret = _getComponentIdForApp(
   320                       iSessionHandle, ((PlatformUid)aAppUid).getIntValue(), result);
   386                       iSessionHandle, ((PlatformUid)aAppUid).getIntValue(), result);
   321         if (-1 == ret)
   387         if (-1 == ret)
   322         {
   388         {
   338      *
   404      *
   339      * @param aGlobalId the global id for the application.
   405      * @param aGlobalId the global id for the application.
   340      */
   406      */
   341     public void logComponent(String aGlobalId)
   407     public void logComponent(String aGlobalId)
   342     {
   408     {
   343         checkSession();
   409         if (0 == iSessionHandle)
       
   410         {
       
   411             InstallerException.internalError("No valid SIF session.");
       
   412         }
       
   413 
   344         int ret = _logComponent(iSessionHandle, aGlobalId);
   414         int ret = _logComponent(iSessionHandle, aGlobalId);
   345         if (ret < -1)
   415         if (ret < -1)
   346         {
   416         {
   347             Log.logError("SifRegistrator logComponent for " + aGlobalId +
   417             Log.logError("SifRegistrator logComponent failed with code " + ret);
   348                          " failed with code " + ret);
       
   349         }
   418         }
   350     }
   419     }
   351 
   420 
   352     /*** ----------------------------- PACKAGE ---------------------------- */
   421     /*** ----------------------------- PACKAGE ---------------------------- */
   353     /*** ----------------------------- PRIVATE ---------------------------- */
   422     /*** ----------------------------- PRIVATE ---------------------------- */
   354 
   423 
   355     /**
   424     /**
   356      * Checks if SifRegistrator session has been started.
   425      * Registers one Java application to S60 USIF as a component.
   357      * @throws InstallerException if SifRegistrator session has not been started
   426      * Used with USIF Phase 1.
   358      */
   427      *
   359     private void checkSession()
   428      * @param aSuiteInfo Information needed to register the application
   360     {
   429      * @param aIndex index of the application in the suite
   361         if (iSessionHandle == 0)
   430      * @param aIsUpdate true in case of an update, false in case of a new
   362         {
   431      * installation
   363             InstallerException.internalError("No valid SIF session.");
   432      * @throws InstallerException if registration cannot done or
       
   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());
   364         }
   533         }
   365     }
   534     }
   366 
   535 
   367     /**
   536     /**
   368      * Registers Java application suite to S60 USIF as a component.
   537      * Registers Java application suite to S60 USIF as a component.
       
   538      * Used with USIF Phase 2.
   369      *
   539      *
   370      * @param aSuiteInfo Suite information
   540      * @param aSuiteInfo Suite information
   371      * @param aIsUpdate true in case of an update, false in case of a new
   541      * @param aIsUpdate true in case of an update, false in case of a new
   372      * installation
   542      * installation
   373      * @throws InstallerException if registration cannot done or
   543      * @throws InstallerException if registration cannot done or
   379     {
   549     {
   380         String globalId = aSuiteInfo.getGlobalId();
   550         String globalId = aSuiteInfo.getGlobalId();
   381         String suiteName = aSuiteInfo.getName();
   551         String suiteName = aSuiteInfo.getName();
   382         String vendor = aSuiteInfo.getVendor();
   552         String vendor = aSuiteInfo.getVendor();
   383         String version = aSuiteInfo.getVersion().toString();
   553         String version = aSuiteInfo.getVersion().toString();
       
   554         String name = null; // Set name to null so that suite name will be used.
   384         int uid = ((PlatformUid)aSuiteInfo.getUid()).getIntValue();
   555         int uid = ((PlatformUid)aSuiteInfo.getUid()).getIntValue();
   385         String[] componentFiles = getComponentFiles(aSuiteInfo);
   556         String[] componentFiles = getComponentFiles(aSuiteInfo);
   386         long componentSize = aSuiteInfo.getInitialSize();
   557         long componentSize = aSuiteInfo.getInitialSize();
   387         String attrValue = aSuiteInfo.getAttributeValue("Nokia-MIDlet-Block-Uninstall");
   558         String attrValue = aSuiteInfo.getAttributeValue("Nokia-MIDlet-Block-Uninstall");
   388         boolean isRemovable = !(attrValue != null && attrValue.equalsIgnoreCase("true"));
   559         boolean isRemovable = !(attrValue != null && attrValue.equalsIgnoreCase("true"));
   389         boolean isDrmProtected = (aSuiteInfo.getContentInfo() == aSuiteInfo.CONTENT_INFO_DRM);
   560         boolean isDrmProtected = (aSuiteInfo.getContentInfo() == aSuiteInfo.CONTENT_INFO_DRM);
   390         boolean isOriginVerified = aSuiteInfo.isTrusted();
   561         boolean isOriginVerified = aSuiteInfo.isTrusted();
   391         String midletInfoUrl = aSuiteInfo.getAttributeValue("MIDlet-Info-URL");
   562         String midletInfoUrl = aSuiteInfo.getAttributeValue("MIDlet-Info-URL");
   392         String midletDescription = aSuiteInfo.getAttributeValue("MIDlet-Description");
   563         String midletDescription = aSuiteInfo.getAttributeValue("MIDlet-Description");
   393         String downloadUrl = aSuiteInfo.getAttributeValue("Nokia-MIDlet-Download-URL");
   564         String downloadUrl = aSuiteInfo.getAttributeValue("Nokia-MIDlet-Download-URL");
   394         String updateUrl = aSuiteInfo.getAttributeValue("Nokia-Update");
       
   395         ComponentId componentId = new ComponentId();
   565         ComponentId componentId = new ComponentId();
   396         int err = _registerComponent(
   566         int err = _registerComponent(
   397                       iSessionHandle, uid,
   567                       iSessionHandle, uid,
   398                       getScrString(suiteName), getScrString(vendor),
   568                       getScrString(suiteName), getScrString(vendor),
   399                       getScrString(version), getScrString(globalId),
   569                       getScrString(version), getScrString(name),
   400                       componentFiles, componentSize,
   570                       getScrString(globalId), componentFiles,
   401                       isRemovable, isDrmProtected,
   571                       componentSize, isRemovable, isDrmProtected,
   402                       isOriginVerified, aIsUpdate,
   572                       isOriginVerified, aIsUpdate, aSuiteInfo.getMediaId(),
   403                       aSuiteInfo.getMediaId(),
       
   404                       getScrString(midletInfoUrl),
   573                       getScrString(midletInfoUrl),
   405                       getScrString(midletDescription),
   574                       getScrString(midletDescription),
   406                       getScrString(downloadUrl),
   575                       getScrString(downloadUrl),
   407                       getScrString(updateUrl),
       
   408                       componentId);
   576                       componentId);
   409         if (err < 0)
   577         if (err < 0)
   410         {
   578         {
   411             InstallerException.internalError(
   579             InstallerException.internalError(
   412                 "Registering component " + globalId +
   580                 "Registering component " + globalId +
   420         }
   588         }
   421     }
   589     }
   422 
   590 
   423     /**
   591     /**
   424      * Unregisters Java application suite from being S60 USIF component.
   592      * Unregisters Java application suite from being S60 USIF component.
       
   593      * Used with USIF Phase 2.
   425      *
   594      *
   426      * @param aSuiteInfo suite information
   595      * @param aSuiteInfo suite information
   427      * @throws InstallerException if unregistration cannot done or
   596      * @throws InstallerException if unregistration cannot done or
   428      *  startSession has not been called successfully
   597      *  startSession has not been called successfully
   429      * @see startSession
   598      * @see startSession
   461      * Registers one Java application to S60 USIF as an S60 application.
   630      * Registers one Java application to S60 USIF as an S60 application.
   462      * The application is registered to component whose id is taken
   631      * The application is registered to component whose id is taken
   463      * from given SuiteInfo object. The SuiteInfo must already have
   632      * from given SuiteInfo object. The SuiteInfo must already have
   464      * been registered to USIF as a component with registerComponent()
   633      * been registered to USIF as a component with registerComponent()
   465      * method before this method is called.
   634      * method before this method is called.
       
   635      * Used with USIF Phase 2.
   466      *
   636      *
   467      * @param aSuiteInfo information needed to register the application
   637      * @param aSuiteInfo information needed to register the application
   468      * @param aIndex index of the application in the suite
   638      * @param aIndex index of the application in the suite
   469      * @throws InstallerException if registration cannot done or
   639      * @throws InstallerException if registration cannot done or
   470      *  startSession has not been called successfully
   640      *  startSession has not been called successfully
   518     }
   688     }
   519 
   689 
   520     private static String[] getComponentFiles(SuiteInfo aSuite)
   690     private static String[] getComponentFiles(SuiteInfo aSuite)
   521     {
   691     {
   522         Vector componentFiles = new Vector();
   692         Vector componentFiles = new Vector();
   523         if (!aSuite.isPreinstalled())
   693         String path = aSuite.getJadPath();
   524         {
   694         if (path != null)
   525             // Add component jad and jar files only when the
   695         {
   526             // application is not preinstalled.
   696             componentFiles.addElement(getScrString(path));
   527             String path = aSuite.getJadPath();
   697         }
   528             if (path != null)
   698         path = aSuite.getJarPath();
   529             {
   699         if (path != null)
   530                 componentFiles.addElement(getScrString(path));
   700         {
   531             }
   701             componentFiles.addElement(getScrString(path));
   532             path = aSuite.getJarPath();
       
   533             if (path != null)
       
   534             {
       
   535                 componentFiles.addElement(getScrString(path));
       
   536             }
       
   537         }
   702         }
   538         boolean addRootPath = true;
   703         boolean addRootPath = true;
   539         int rootDrive = FileUtils.getDrive(aSuite.getRootDir());
   704         int rootDrive = FileUtils.getDrive(aSuite.getRootDir());
   540         for (int i = 0; i < componentFiles.size(); i++)
   705         for (int i = 0; i < componentFiles.size(); i++)
   541         {
   706         {
   549                 break;
   714                 break;
   550             }
   715             }
   551         }
   716         }
   552         if (addRootPath)
   717         if (addRootPath)
   553         {
   718         {
   554             componentFiles.addElement(
   719             componentFiles.addElement(getScrString(aSuite.getRootDir()));
   555                 getScrString(aSuite.getRootDir() + "nofile.txt"));
       
   556         }
   720         }
   557         String[] result = new String[componentFiles.size()];
   721         String[] result = new String[componentFiles.size()];
   558         componentFiles.copyInto(result);
   722         componentFiles.copyInto(result);
   559         for (int i = 0; i < result.length; i++)
       
   560         {
       
   561             Log.log("SifRegistrator componentFiles[" + i + "]: " + result[i]);
       
   562         }
       
   563         return result;
   723         return result;
   564     }
   724     }
   565 
   725 
   566     /**
   726     /**
   567      * Registers localized names for given application from given suite.
   727      * Registers localized names for given application from given suite.
   664                     " (" + localizedAttrValues[i] + ")");
   824                     " (" + localizedAttrValues[i] + ")");
   665             }
   825             }
   666         }
   826         }
   667 
   827 
   668         // Register Domain-Category property.
   828         // Register Domain-Category property.
   669         String protectionDomainProperty = "Domain-Category";
   829         ApplicationInfoImpl appInfoImpl = (ApplicationInfoImpl)
   670         String protectionDomainName = aSuite.getProtectionDomainName();
   830                                           com.nokia.mj.impl.rt.support.ApplicationInfo.getInstance();
       
   831         String domainCategory = appInfoImpl.getProtectionDomain();
   671         err = _setLocalizedComponentProperty(
   832         err = _setLocalizedComponentProperty(
   672             iSessionHandle, cid, protectionDomainProperty,
   833                   iSessionHandle, cid, "Domain-Category",
   673             getProtectionDomainPropertyValue(protectionDomainName),
   834                   domainCategory, UNSPECIFIED_LOCALE);
   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";
       
   708     }
   841     }
   709 
   842 
   710     /**
   843     /**
   711      * Returns array of localized names from the specified
   844      * Returns array of localized names from the specified
   712      * attributes of given suite. Assumes that aAttrPrefix
   845      * attributes of given suite. Assumes that aAttrPrefix
   734                     {
   867                     {
   735                         Log.logWarning(
   868                         Log.logWarning(
   736                             "SifRegistrator ignored unknown locale: " +
   869                             "SifRegistrator ignored unknown locale: " +
   737                             name + ": " + localizedName);
   870                             name + ": " + localizedName);
   738                     }
   871                     }
   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                     }
       
   746                     else
   872                     else
   747                     {
   873                     {
   748                         Log.log("SifRegistrator found localized text " +
   874                         Log.log("SifRegistrator found localized text " +
   749                                 name + ": " + localizedName);
   875                                 name + ": " + localizedName);
   750                         localizedNames.put(
   876                         localizedNames.put(
   821      * @return 0 or Symbian error code (negative number)
   947      * @return 0 or Symbian error code (negative number)
   822      */
   948      */
   823     private static native int _launchAppView();
   949     private static native int _launchAppView();
   824 
   950 
   825     /**
   951     /**
       
   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     /**
   826      * Starts native application registration session.
   960      * Starts native application registration session.
   827      *
   961      *
   828      * @param aTransaction true if also transaction for this session should
   962      * @param aTransaction true if also transaction for this session should
   829      * be opened, false otherwise
   963      * be opened, false otherwise
   830      * @return native session handle or Symbian error code (negative number)
   964      * @return native session handle or Symbian error code (negative number)
   862      * @param aSessionHandle
   996      * @param aSessionHandle
   863      * @param aUid
   997      * @param aUid
   864      * @param aSuiteName
   998      * @param aSuiteName
   865      * @param aVendor
   999      * @param aVendor
   866      * @param aVersion
  1000      * @param aVersion
       
  1001      * @param aName
   867      * @param aGlobalId
  1002      * @param aGlobalId
   868      * @param aComponentFiles
  1003      * @param aComponentFiles
   869      * @param aComponentSize
  1004      * @param aComponentSize
   870      * @param aIsRemovable
  1005      * @param aIsRemovable
   871      * @param aIsDrmProtected
  1006      * @param aIsDrmProtected
   873      * @param aIsUpdate
  1008      * @param aIsUpdate
   874      * @param aMediaId
  1009      * @param aMediaId
   875      * @param aMidletInfoUrl
  1010      * @param aMidletInfoUrl
   876      * @param aMidletDescription
  1011      * @param aMidletDescription
   877      * @param aDownloadUrl
  1012      * @param aDownloadUrl
   878      * @param aUpdateUrl
       
   879      * @param aComponentId upon successful execution contains the
  1013      * @param aComponentId upon successful execution contains the
   880      * component id for the registered component
  1014      * component id for the registered component
   881      * @return 0 if registration succeeded or Symbian error code
  1015      * @return 0 if registration succeeded or Symbian error code
   882      */
  1016      */
   883     private static native int _registerComponent(
  1017     private static native int _registerComponent(
   884         int aSessionHandle, int aUid, String aSuiteName, String aVendor,
  1018         int aSessionHandle, int aUid, String aSuiteName, String aVendor,
   885         String aVersion, String aGlobalId,
  1019         String aVersion, String aName, String aGlobalId,
   886         String[] aComponentFiles, long aComponentSize,
  1020         String[] aComponentFiles, long aComponentSize,
   887         boolean aIsRemovable, boolean aIsDrmProtected,
  1021         boolean aIsRemovable, boolean aIsDrmProtected,
   888         boolean aIsOriginVerified, boolean aIsUpdate, int aMediaId,
  1022         boolean aIsOriginVerified, boolean aIsUpdate, int aMediaId,
   889         String aMidletInfoUrl, String aMidletDescription,
  1023         String aMidletInfoUrl, String aMidletDescription, String aDownloadUrl,
   890         String aDownloadUrl, String aUpdateUrl,
       
   891         ComponentId aComponentId);
  1024         ComponentId aComponentId);
   892 
  1025 
   893     /**
  1026     /**
   894      * Unregisters Java application from S60 USIF.
  1027      * Unregisters Java application from S60 USIF.
   895      *
  1028      *
   993      * Checks if USIF is enabled.
  1126      * Checks if USIF is enabled.
   994      *
  1127      *
   995      * @return 1 if application data should be registered to USIF, 0 otherwise
  1128      * @return 1 if application data should be registered to USIF, 0 otherwise
   996      */
  1129      */
   997     private static native int _getUsifMode();
  1130     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);
       
  1003 }
  1131 }