javamanager/javainstaller/installer/javasrc/com/nokia/mj/impl/installer/GetComponentInfo.java
branchRCL_3
changeset 14 04becd199f91
child 24 6c158198356e
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 package com.nokia.mj.impl.installer;
       
    20 
       
    21 import com.nokia.mj.impl.installer.applicationregistrator.SifRegistrator;
       
    22 import com.nokia.mj.impl.installer.storagehandler.ApplicationInfo;
       
    23 import com.nokia.mj.impl.installer.storagehandler.SuiteInfo;
       
    24 import com.nokia.mj.impl.installer.storagehandler.StorageHandler;
       
    25 import com.nokia.mj.impl.installer.integrityservice.IntegrityService;
       
    26 import com.nokia.mj.impl.installer.jadjarmatcher.JadJarFile;
       
    27 import com.nokia.mj.impl.installer.jadjarmatcher.JadJarMatcher;
       
    28 import com.nokia.mj.impl.installer.jadjarmatcher.MidletMessageHandler;
       
    29 import com.nokia.mj.impl.installer.utils.Args;
       
    30 import com.nokia.mj.impl.installer.utils.ComponentId;
       
    31 import com.nokia.mj.impl.installer.utils.FileUtils;
       
    32 import com.nokia.mj.impl.installer.utils.InstallerException;
       
    33 import com.nokia.mj.impl.installer.utils.JadReader;
       
    34 import com.nokia.mj.impl.installer.utils.Log;
       
    35 import com.nokia.mj.impl.installer.utils.MidpAttributeValidator;
       
    36 import com.nokia.mj.impl.installer.utils.PlatformUid;
       
    37 import com.nokia.mj.impl.security.midp.authentication.AuthenticationModule;
       
    38 import com.nokia.mj.impl.security.midp.common.AuthenticationCredentials;
       
    39 import com.nokia.mj.impl.security.midp.common.SecurityAttributes;
       
    40 import com.nokia.mj.impl.utils.Attribute;
       
    41 import com.nokia.mj.impl.utils.JarManifestReader;
       
    42 import com.nokia.mj.impl.utils.Tokenizer;
       
    43 import com.nokia.mj.impl.utils.Uid;
       
    44 import com.nokia.mj.impl.utils.Version;
       
    45 
       
    46 import java.io.IOException;
       
    47 import java.util.Hashtable;
       
    48 import java.util.Vector;
       
    49 
       
    50 /**
       
    51  * This class implements functionlity for getting information of
       
    52  * an installed or not installed application.
       
    53  */
       
    54 public class GetComponentInfo
       
    55 {
       
    56     // Constants for install status.
       
    57     static final int NEW_COMPONENT = 0;
       
    58     static final int UPGRADE = 1;
       
    59     static final int ALREADY_INSTALLED = 2;
       
    60     static final int NEWER_VERSION_ALREADY_INSTALLED = 3;
       
    61     static final int INVALID_PACKAGE = 4;
       
    62 
       
    63     // There can be only one instance of IntegrityService at a time
       
    64     // so concurrent execution of getComponentInfo must be limited.
       
    65     private static final Object iSync = new Object();
       
    66     private IntegrityService iIntegrityService = null;
       
    67 
       
    68     // Command line arguments
       
    69     private Args iArgs = null;
       
    70     private String iJarFilename = null;
       
    71     private String iJadFilename = null;
       
    72     private String iJadCharset = null;
       
    73     private Uid iUid = null;
       
    74     private int[] iCommsResultEndpoints = null;
       
    75     private int iTmpDrive = -1;
       
    76 
       
    77     // Jad/Manifest attributes
       
    78     private Hashtable iJarAttributes = null;
       
    79     private Hashtable iJadAttributes = null;
       
    80     private Hashtable iCombinedAttributes = null;
       
    81 
       
    82     // Suite info from JavaStorage
       
    83     private SuiteInfo iSuite = null;
       
    84 
       
    85     // Security information
       
    86     private SecurityAttributes iSecurityAttributes = null;
       
    87     private boolean iIsTrusted = false;
       
    88 
       
    89     // Install status.
       
    90     private int iInstallStatus = NEW_COMPONENT;
       
    91     private Exception iException = null;
       
    92 
       
    93     /**
       
    94      * Default constructor.
       
    95      */
       
    96     public GetComponentInfo()
       
    97     {
       
    98     }
       
    99 
       
   100     /**
       
   101      * Main method for getting component info. This method sends
       
   102      * information of the requested component using InstallerResultMessage
       
   103      * to the Comms endpoint given as an argument. Component can be
       
   104      * identifed using either -jad, -jar or -uid argument.
       
   105      */
       
   106     public int getComponentInfo(Args aArgs)
       
   107     {
       
   108         int result = Installer.ERR_NONE;
       
   109         synchronized (iSync)
       
   110         {
       
   111             Log.log("getComponentInfo begins");
       
   112 
       
   113             // Reset member variables.
       
   114             iJarAttributes = null;
       
   115             iJadAttributes = null;
       
   116             iCombinedAttributes = null;
       
   117             iSuite = null;
       
   118 
       
   119             // Get IntegrityService instance.
       
   120             iIntegrityService = IntegrityService.getInstance(
       
   121                                     FileUtils.getIntegrityServiceRoot());
       
   122 
       
   123             // Get component info.
       
   124             try
       
   125             {
       
   126                 result = parseArgs(aArgs);
       
   127                 if (result == Installer.ERR_NONE)
       
   128                 {
       
   129                     findJadJar();
       
   130                     getAttributes();
       
   131                     result = getFromStorage();
       
   132                 }
       
   133                 if (result == Installer.ERR_NONE)
       
   134                 {
       
   135                     authenticate();
       
   136                     getFromSif();
       
   137                 }
       
   138             }
       
   139             catch (Exception e)
       
   140             {
       
   141                 result = Installer.ERR_GENERAL;
       
   142                 iException = e;
       
   143                 Log.logError("Getting component info failed", e);
       
   144             }
       
   145 
       
   146             // Close IntegrityService by making rollback.
       
   147             if (iIntegrityService.rollback())
       
   148             {
       
   149                 Log.log("IntegrityService rolled back");
       
   150             }
       
   151             else
       
   152             {
       
   153                 Log.logError("IntegrityService rollback failed");
       
   154             }
       
   155 
       
   156             // Send InstallerResultMessage.
       
   157             try
       
   158             {
       
   159                 sendResult(result);
       
   160             }
       
   161             catch (Throwable t)
       
   162             {
       
   163                 Log.logError("Sending component info failed", t);
       
   164                 result = Installer.ERR_GENERAL;
       
   165             }
       
   166             Log.log("getComponentInfo returns " + result);
       
   167         }
       
   168         return result;
       
   169     }
       
   170 
       
   171     /**
       
   172      * Parses command line arguments.
       
   173      */
       
   174     private int parseArgs(Args aArgs)
       
   175     {
       
   176         Log.log("parseArgs begins");
       
   177         int result = Installer.ERR_NONE;
       
   178         iArgs = aArgs;
       
   179         iJadFilename = iArgs.get("jad");
       
   180         iJarFilename = iArgs.get("jar");
       
   181         if (iJadFilename != null && iJarFilename != null)
       
   182         {
       
   183             InstallerException.internalError(
       
   184                 "Specify either jad or jar as an argument, not both.");
       
   185         }
       
   186         iJadCharset = iArgs.get("charset");
       
   187 
       
   188         String arg = iArgs.get("uid");
       
   189         if (arg != null)
       
   190         {
       
   191             if (iJadFilename != null || iJarFilename != null)
       
   192             {
       
   193                 InstallerException.internalError(
       
   194                     "Specify either jad, jar or uid as an argument.");
       
   195             }
       
   196             Uid uid = PlatformUid.createUid(arg);
       
   197             if (uid == null)
       
   198             {
       
   199                 InstallerException.internalError("Invalid uid " + arg);
       
   200             }
       
   201             iUid = uid;
       
   202         }
       
   203 
       
   204         arg = iArgs.get("commsresult");
       
   205         if (arg != null)
       
   206         {
       
   207             iCommsResultEndpoints = InstallerResultMessage.parseEndpoints(arg);
       
   208         }
       
   209 
       
   210         // Check that file exists and store temporary files to the
       
   211         // same drive where the component is located.
       
   212         if (iJadFilename != null)
       
   213         {
       
   214             iTmpDrive = FileUtils.getDrive(iJadFilename);
       
   215             if (!FileUtils.exists(iJadFilename) &&
       
   216                     !FileUtils.isInboxFile(iJadFilename))
       
   217             {
       
   218                 result = Installer.ERR_NOT_FOUND;
       
   219                 Log.log("File not found: " + iJadFilename);
       
   220             }
       
   221         }
       
   222         if (iJarFilename != null)
       
   223         {
       
   224             iTmpDrive = FileUtils.getDrive(iJarFilename);
       
   225             if (!FileUtils.exists(iJarFilename) &&
       
   226                     !FileUtils.isInboxFile(iJarFilename))
       
   227             {
       
   228                 result = Installer.ERR_NOT_FOUND;
       
   229                 Log.log("File not found: " + iJarFilename);
       
   230             }
       
   231         }
       
   232         Log.log("parseArgs returns " + result);
       
   233         return result;
       
   234     }
       
   235 
       
   236     /**
       
   237      * Finds matching Jad and Jar.
       
   238      */
       
   239     private void findJadJar()
       
   240     {
       
   241         Log.log("findJadJar begins");
       
   242 
       
   243         // Initialise JadJarMatcher classes.
       
   244         JadJarMatcher.setIntegrityService(iIntegrityService);
       
   245         MidletMessageHandler.setInstallationDrive(iTmpDrive);
       
   246 
       
   247         // Try to find jar basing on local jad file.
       
   248         if (iJadFilename != null)
       
   249         {
       
   250             JadJarFile jadJarFile =
       
   251                 JadJarMatcher.findJar(iJadFilename, iJadCharset);
       
   252             iJadFilename = jadJarFile.iJadFilename;
       
   253             iJarFilename = jadJarFile.iJarFilename;
       
   254             iJadAttributes = jadJarFile.iJadAttributes;
       
   255             iJarAttributes = jadJarFile.iJarAttributes;
       
   256             if (iJarFilename != null)
       
   257             {
       
   258                 Log.log("Found matching Jar: " + iJarFilename);
       
   259             }
       
   260             else
       
   261             {
       
   262                 Log.log("Matching Jar not found locally");
       
   263             }
       
   264         }
       
   265         // Try to find jad basing on local jar file.
       
   266         else if (iJarFilename != null)
       
   267         {
       
   268             JadJarFile jadJarFile =
       
   269                 JadJarMatcher.findJad(iJarFilename);
       
   270             iJadFilename = jadJarFile.iJadFilename;
       
   271             iJarFilename = jadJarFile.iJarFilename;
       
   272             iJadAttributes = jadJarFile.iJadAttributes;
       
   273             iJarAttributes = jadJarFile.iJarAttributes;
       
   274             if (iJadFilename != null)
       
   275             {
       
   276                 Log.log("Found matching Jad: " + iJadFilename);
       
   277             }
       
   278             else
       
   279             {
       
   280                 Log.log("Matching Jad not found locally");
       
   281             }
       
   282         }
       
   283 
       
   284         Log.log("findJadJar returns");
       
   285     }
       
   286 
       
   287     /**
       
   288      * Gets and validates jad and manifest attributes.
       
   289      */
       
   290     private void getAttributes() throws IOException
       
   291     {
       
   292         Log.log("getAttributes begins");
       
   293         if (iJadFilename != null && iJadAttributes == null)
       
   294         {
       
   295             Log.log("Reading Jad...");
       
   296             iJadAttributes =
       
   297                 JadReader.getAttributes(iJadFilename, iJadCharset);
       
   298             if (iJadAttributes == null)
       
   299             {
       
   300                 throw new IOException(
       
   301                     "No Jad attributes found from " + iJadFilename);
       
   302             }
       
   303         }
       
   304 
       
   305         if (iJarFilename != null && iJarAttributes == null)
       
   306         {
       
   307             Log.log("Reading Jar...");
       
   308             iJarAttributes =
       
   309                 JarManifestReader.getAttributes(iJarFilename);
       
   310             if (iJarAttributes == null)
       
   311             {
       
   312                 throw new IOException(
       
   313                     "No Jar attributes found from " + iJarFilename);
       
   314             }
       
   315         }
       
   316 
       
   317         try
       
   318         {
       
   319             // Validate and combine the attributes.
       
   320             MidpAttributeValidator attributeValidator =
       
   321                 new MidpAttributeValidator();
       
   322             if (iJadAttributes != null)
       
   323             {
       
   324                 attributeValidator.validate(
       
   325                     iJadAttributes, attributeValidator.JAD);
       
   326                 // Get security attributes.
       
   327                 iSecurityAttributes = new SecurityAttributes();
       
   328                 iSecurityAttributes.addDescriptorAttributes(iJadAttributes);
       
   329                 iIsTrusted = iSecurityAttributes.isTrusted();
       
   330             }
       
   331             if (iJarAttributes != null)
       
   332             {
       
   333                 attributeValidator.validate(
       
   334                     iJarAttributes, attributeValidator.JAR);
       
   335             }
       
   336             iCombinedAttributes = attributeValidator.combine(
       
   337                                       iJadAttributes, iJarAttributes, iIsTrusted);
       
   338         }
       
   339         catch (Exception e)
       
   340         {
       
   341             // Attribute validation failure means that
       
   342             // application cannot be installed.
       
   343             iInstallStatus = INVALID_PACKAGE;
       
   344             iException = e;
       
   345             Log.log("Attribute validation failed", e);
       
   346         }
       
   347         Log.log("getAttributes returns");
       
   348     }
       
   349 
       
   350     /**
       
   351      * Gets application suite information from JavaStorage.
       
   352      */
       
   353     private int getFromStorage()
       
   354     {
       
   355         Log.log("getFromStorage begins");
       
   356         int result = Installer.ERR_NONE;
       
   357         StorageHandler storageHandler = null;
       
   358         try
       
   359         {
       
   360             storageHandler = new StorageHandler();
       
   361             if (iUid != null)
       
   362             {
       
   363                 // Read from JavaStorage by uid.
       
   364                 Uid uid = storageHandler.getSuiteUid(iUid);
       
   365                 if (uid != null)
       
   366                 {
       
   367                     iSuite = new SuiteInfo(uid);
       
   368                 }
       
   369             }
       
   370             else
       
   371             {
       
   372                 // Read from JavaStorage by name and vendor.
       
   373                 iSuite = new SuiteInfo(
       
   374                     getAttributeValue("MIDlet-Name"),
       
   375                     getAttributeValue("MIDlet-Vendor"));
       
   376             }
       
   377             if (iSuite != null && storageHandler.readSuiteInfo(iSuite))
       
   378             {
       
   379                 Log.log("Suite found from JavaStorage: " + iSuite.toString());
       
   380                 iInstallStatus = ALREADY_INSTALLED;
       
   381                 Version version = Version.getVersion(
       
   382                                       getAttributeValue("MIDlet-Version"));
       
   383                 if (version != null)
       
   384                 {
       
   385                     int versionComparison =
       
   386                         version.compareTo(iSuite.getVersion());
       
   387                     if (versionComparison > 0)
       
   388                     {
       
   389                         iInstallStatus = UPGRADE;
       
   390                     }
       
   391                     else if (versionComparison == 0)
       
   392                     {
       
   393                         iInstallStatus = ALREADY_INSTALLED;
       
   394                     }
       
   395                     else if (versionComparison < 0)
       
   396                     {
       
   397                         iInstallStatus = NEWER_VERSION_ALREADY_INSTALLED;
       
   398                     }
       
   399                 }
       
   400             }
       
   401             else
       
   402             {
       
   403                 Log.log("Suite not found from JavaStorage");
       
   404                 iSuite = null;
       
   405                 if (iUid != null)
       
   406                 {
       
   407                     // If component info is requested by uid
       
   408                     // and not found from JavaStorage, return
       
   409                     // "not found" error code.
       
   410                     result = Installer.ERR_NOT_FOUND;
       
   411                 }
       
   412             }
       
   413         }
       
   414         finally
       
   415         {
       
   416             if (storageHandler != null)
       
   417             {
       
   418                 storageHandler.close();
       
   419             }
       
   420         }
       
   421         Log.log("getFromStorage returns " + result);
       
   422         return result;
       
   423     }
       
   424 
       
   425     /**
       
   426      * Gets component ids from SIF if application is already installed.
       
   427      */
       
   428     private void getFromSif()
       
   429     {
       
   430         if (iSuite != null)
       
   431         {
       
   432             Log.log("getFromSif begins");
       
   433             // Suite exists, now get component ids from SIF.
       
   434             SifRegistrator sr = new SifRegistrator();
       
   435             sr.startSession(false);
       
   436             try
       
   437             {
       
   438                 iSuite.setComponentId(sr.getComponentId(iSuite.getGlobalId()));
       
   439                 Log.log("getFromSif " + iSuite.getGlobalId() +
       
   440                         ", cid: " + iSuite.getComponentId());
       
   441                 Vector apps = iSuite.getApplications();
       
   442                 for (int i = 0; i < apps.size(); i++)
       
   443                 {
       
   444                     ApplicationInfo appInfo =
       
   445                         (ApplicationInfo)apps.elementAt(i);
       
   446                     appInfo.setComponentId(
       
   447                         sr.getComponentId(iSuite.getGlobalId(i)));
       
   448                     Log.log("getFromSif " + iSuite.getGlobalId(i) +
       
   449                             ", cid: " + appInfo.getComponentId());
       
   450                 }
       
   451             }
       
   452             finally
       
   453             {
       
   454                 sr.closeSession();
       
   455             }
       
   456             Log.log("getFromSif returns");
       
   457         }
       
   458     }
       
   459 
       
   460     /**
       
   461      * Authenticates Jad and Jar.
       
   462      */
       
   463     private void authenticate()
       
   464     {
       
   465         Log.log("authenticate begins");
       
   466         if (iSecurityAttributes != null)
       
   467         {
       
   468             try
       
   469             {
       
   470                 // Use dummy uid in case suite has not been installed yet.
       
   471                 Uid suiteUid = PlatformUid.createUid(0);
       
   472                 if (iSuite != null)
       
   473                 {
       
   474                     suiteUid = iSuite.getUid();
       
   475                 }
       
   476 
       
   477                 // Authenticate jad.
       
   478                 AuthenticationCredentials[] authenticationCredentials =
       
   479                     AuthenticationModule.getInstance().authenticateJad(
       
   480                         suiteUid, null,
       
   481                         iSecurityAttributes.getAuthenticationAttributes());
       
   482 
       
   483                 if (iJarFilename != null)
       
   484                 {
       
   485                     // Authenticate jar.
       
   486                     AuthenticationModule.getInstance().authenticateJar(
       
   487                         null, suiteUid, null, iJarFilename,
       
   488                         FileUtils.isDrmProtected(iJarFilename));
       
   489                 }
       
   490             }
       
   491             catch (Exception e)
       
   492             {
       
   493                 // If authentication fails it means that
       
   494                 // application cannot be installed.
       
   495                 iInstallStatus = INVALID_PACKAGE;
       
   496                 iException = e;
       
   497                 Log.log("Authentication failed", e);
       
   498             }
       
   499         }
       
   500         Log.log("authenticate returns");
       
   501     }
       
   502 
       
   503     /**
       
   504      * Sends InstallerResultMessage.
       
   505      */
       
   506     private void sendResult(int aResult)
       
   507     {
       
   508         if (iCommsResultEndpoints == null ||
       
   509                 iCommsResultEndpoints.length == 0)
       
   510         {
       
   511             return;
       
   512         }
       
   513         InstallerResultMessage msg = new InstallerResultMessage();
       
   514         msg.addValue(msg.NAME_OPERATION, 2);
       
   515         msg.addResult(iException);
       
   516         msg.addValue(msg.NAME_RESULT, aResult);
       
   517         if (aResult == Installer.ERR_NONE)
       
   518         {
       
   519             // Init msg either using iSuite, iCombinedAttributes or both.
       
   520             if (iSuite != null && iCombinedAttributes == null)
       
   521             {
       
   522                 // Init msg from iSuite only.
       
   523                 msg.init(iSuite);
       
   524             }
       
   525             else if (iCombinedAttributes != null)
       
   526             {
       
   527                 String[][] midletNAttributes = getMidletNAttributeValues();
       
   528                 if (iSuite != null)
       
   529                 {
       
   530                     // Init available suite and application uids from iSuite.
       
   531                     msg.addValue(msg.NAME_SUITE_UID,
       
   532                                  PlatformUid.getIntValue(iSuite.getUid()));
       
   533                     if (iSuite.getComponentId() != null)
       
   534                     {
       
   535                         msg.addValue(msg.NAME_SUITE_CID,
       
   536                                      iSuite.getComponentId().getId());
       
   537                     }
       
   538                     Vector apps = iSuite.getApplications();
       
   539                     for (int i = 0; i < midletNAttributes.length; i++)
       
   540                     {
       
   541                         int index = i+1;
       
   542                         if (i < apps.size())
       
   543                         {
       
   544                             ApplicationInfo app = (ApplicationInfo)apps.elementAt(i);
       
   545                             msg.addValue(msg.NAME_MIDLET_UID+index,
       
   546                                          PlatformUid.getIntValue(app.getUid()));
       
   547                             if (app.getComponentId() != null)
       
   548                             {
       
   549                                 msg.addValue(msg.NAME_MIDLET_CID+index,
       
   550                                              app.getComponentId().getId());
       
   551                             }
       
   552                         }
       
   553                     }
       
   554                 }
       
   555 
       
   556                 // Init message from attributes read from jad/jar.
       
   557                 // Note that uids for not installed applications
       
   558                 // are not returned, unless they are defined with
       
   559                 // Nokia-MIDlet-UID-n attribute.
       
   560                 msg.addValue(msg.NAME_SUITE_GID,
       
   561                              SuiteInfo.getGlobalId(
       
   562                                  getAttributeValue("MIDlet-Vendor"),
       
   563                                  getAttributeValue("MIDlet-Name"), null));
       
   564                 addAttributeValue(msg, msg.NAME_SUITE_NAME, "MIDlet-Name");
       
   565                 addAttributeValue(msg, msg.NAME_VENDOR, "MIDlet-Vendor");
       
   566                 addAttributeValue(msg, msg.NAME_VERSION, "MIDlet-Version");
       
   567                 for (int i = 0; i < midletNAttributes.length; i++)
       
   568                 {
       
   569                     int index = i+1;
       
   570                     String midletName = midletNAttributes[i][0].trim();
       
   571                     msg.addValue(msg.NAME_MIDLET_NAME+index, midletName);
       
   572                     msg.addValue(msg.NAME_MIDLET_GID+index,
       
   573                                  SuiteInfo.getGlobalId(
       
   574                                      getAttributeValue("MIDlet-Vendor"),
       
   575                                      getAttributeValue("MIDlet-Name"),
       
   576                                      midletName));
       
   577                     String midletUid =
       
   578                         getAttributeValue("Nokia-MIDlet-UID-" + index);
       
   579                     if (midletUid != null)
       
   580                     {
       
   581                         msg.addValue(
       
   582                             msg.NAME_MIDLET_UID+index,
       
   583                             PlatformUid.getIntValue(
       
   584                                 PlatformUid.createUid(midletUid)));
       
   585                     }
       
   586                 }
       
   587 
       
   588                 // Calculate size of the installation package.
       
   589                 int initialSize = 0;
       
   590                 String dataSize = getAttributeValue("MIDlet-Data-Size");
       
   591                 String jarSize = getAttributeValue("MIDlet-Jar-Size");
       
   592                 try
       
   593                 {
       
   594                     if (dataSize != null)
       
   595                     {
       
   596                         initialSize += Integer.parseInt(dataSize);
       
   597                     }
       
   598                     if (jarSize != null)
       
   599                     {
       
   600                         initialSize += Integer.parseInt(jarSize);
       
   601                     }
       
   602                 }
       
   603                 catch (NumberFormatException nfe)
       
   604                 {
       
   605                     // ignore
       
   606                 }
       
   607                 if (initialSize == 0 && iJarFilename != null)
       
   608                 {
       
   609                     // Get initialSize from jar file size.
       
   610                     initialSize = (int)FileUtils.getSize(iJarFilename);
       
   611                 }
       
   612                 msg.addValue(msg.NAME_COMPONENT_SIZE, initialSize);
       
   613             }
       
   614             msg.addValue(msg.NAME_INSTALL_STATUS, iInstallStatus);
       
   615             if (iInstallStatus != INVALID_PACKAGE)
       
   616             {
       
   617                 // Add authenticity value only when the package is found
       
   618                 // to be valid.
       
   619                 msg.addValue(msg.NAME_AUTHENTICITY, (iIsTrusted? 1: 0));
       
   620             }
       
   621         }
       
   622         Log.log("Sending " + msg.toString());
       
   623         msg.send(iCommsResultEndpoints);
       
   624     }
       
   625 
       
   626     /**
       
   627      * Adds specified value to given message if the value exists
       
   628      * in iCombinedAttributes member. If value does not exist in
       
   629      * iCombinedAttributes then value is removed from the message.
       
   630      */
       
   631     private void addAttributeValue(
       
   632         InstallerResultMessage aMsg, String aValueName, String aAttrName)
       
   633     {
       
   634         String value = getAttributeValue(aAttrName);
       
   635         if (value == null)
       
   636         {
       
   637             aMsg.removeValue(aValueName);
       
   638         }
       
   639         else
       
   640         {
       
   641             aMsg.addValue(aValueName, value);
       
   642         }
       
   643     }
       
   644 
       
   645     /**
       
   646      * Returns an array of MIDlet-n attribute values from iCombinedAttaributes.
       
   647      */
       
   648     private String[][] getMidletNAttributeValues()
       
   649     {
       
   650         String attrName = "MIDlet-";
       
   651         String attrValue = "";
       
   652         Vector attrs = new Vector();
       
   653         int i = 1;
       
   654         while (attrValue != null)
       
   655         {
       
   656             attrValue = getAttributeValue(attrName + i);
       
   657             if (attrValue != null)
       
   658             {
       
   659                 String[] attrTokens = Tokenizer.split(attrValue, ",");
       
   660                 // attrTokens has midlet name, icon, and class.
       
   661                 attrs.addElement(attrTokens);
       
   662             }
       
   663             i++;
       
   664         }
       
   665         String[][] result = new String[attrs.size()][];
       
   666         attrs.copyInto(result);
       
   667         return result;
       
   668     }
       
   669 
       
   670     /**
       
   671      * Returns a string type attribute value from iCombinedAttributes.
       
   672      */
       
   673     private String getAttributeValue(String aName)
       
   674     {
       
   675         if (iCombinedAttributes == null)
       
   676         {
       
   677             return null;
       
   678         }
       
   679         Attribute attr = (Attribute)iCombinedAttributes.get(aName);
       
   680         if (attr != null)
       
   681         {
       
   682             return attr.getValue();
       
   683         }
       
   684         return null;
       
   685     }
       
   686 }