javamanager/javainstaller/installer/javasrc/com/nokia/mj/impl/installer/InstallerResultMessage.java
branchRCL_3
changeset 83 26b2b12093af
parent 60 6c158198356e
equal deleted inserted replaced
77:7cee158cb8cd 83:26b2b12093af
    19 package com.nokia.mj.impl.installer;
    19 package com.nokia.mj.impl.installer;
    20 
    20 
    21 import com.nokia.mj.impl.comms.CommsEndpoint;
    21 import com.nokia.mj.impl.comms.CommsEndpoint;
    22 import com.nokia.mj.impl.comms.CommsMessage;
    22 import com.nokia.mj.impl.comms.CommsMessage;
    23 import com.nokia.mj.impl.installer.applicationregistrator.SifNotifier;
    23 import com.nokia.mj.impl.installer.applicationregistrator.SifNotifier;
    24 import com.nokia.mj.impl.installer.applicationregistrator.SifRegistrator;
       
    25 import com.nokia.mj.impl.installer.storagehandler.ApplicationInfo;
    24 import com.nokia.mj.impl.installer.storagehandler.ApplicationInfo;
    26 import com.nokia.mj.impl.installer.storagehandler.SuiteInfo;
    25 import com.nokia.mj.impl.installer.storagehandler.SuiteInfo;
    27 import com.nokia.mj.impl.installer.utils.InstallerException;
    26 import com.nokia.mj.impl.installer.utils.InstallerException;
    28 import com.nokia.mj.impl.installer.utils.Log;
    27 import com.nokia.mj.impl.installer.utils.Log;
    29 import com.nokia.mj.impl.installer.utils.PlatformUid;
    28 import com.nokia.mj.impl.installer.utils.PlatformUid;
    30 import com.nokia.mj.impl.utils.exception.ExceptionBase;
    29 import com.nokia.mj.impl.utils.exception.ExceptionBase;
    31 import com.nokia.mj.impl.utils.ErrorMessageBase;
       
    32 import com.nokia.mj.impl.utils.InstallerErrorMessage;
    30 import com.nokia.mj.impl.utils.InstallerErrorMessage;
    33 import com.nokia.mj.impl.utils.Tokenizer;
    31 import com.nokia.mj.impl.utils.Tokenizer;
    34 import com.nokia.mj.impl.utils.Uid;
    32 import com.nokia.mj.impl.utils.Uid;
    35 
    33 
    36 import java.util.Enumeration;
    34 import java.util.Enumeration;
    37 import java.util.Hashtable;
    35 import java.util.Hashtable;
    38 import java.util.Vector;
    36 import java.util.Vector;
    39 
    37 
    40 /**
    38 /**
    41  * InstallerResultMessage contains information about install, uninstall
    39  * InstallerResultMessage contains information about install, uninstall
    42  * and componentinfo operation results. JavaInstaller sends it at the end
    40  * and componentinfo operations. It is sent to Comms endpoint specified
    43  * of operation to Comms endpoint specified at JavaInstaller startup with
    41  * at JavaInstaller startup.
    44  * -commsresult option.
       
    45  * <p>
       
    46  * InstallerResultMessage contains name-value pairs: name is a string,
       
    47  * value can be either a string or an int. Message syntax:
       
    48  * <p>
       
    49  * <pre>
       
    50  * message := length named_int_value* length named_string_value*
       
    51  * named_int_value := name int_value
       
    52  * named_string_value := name string_value
       
    53  * name := &lt;string&gt;
       
    54  * int_value := &lt;int&gt;
       
    55  * string_value := &lt;string&gt;
       
    56  * length := &lt;int telling the length of the table that follows&gt;
       
    57  * </pre>
       
    58  * <p>
       
    59  */
    42  */
    60 public class InstallerResultMessage
    43 public class InstallerResultMessage
    61 {
    44 {
    62     /** Operation type. Value type: int.
       
    63         Possible values: 0: install, 1: uninstall, 2: componentinfo. */
       
    64     public static final String NAME_OPERATION = "operation";
    45     public static final String NAME_OPERATION = "operation";
    65     /** Status code indicating operation result. Value type: int. */
       
    66     public static final String NAME_RESULT = "result";
    46     public static final String NAME_RESULT = "result";
    67     /** SIF error category. Value type: int. */
       
    68     public static final String NAME_ERROR_CATEGORY = "error-category";
    47     public static final String NAME_ERROR_CATEGORY = "error-category";
    69     /** Java runtime specific error code. Value type: int. */
       
    70     public static final String NAME_ERROR_CODE = "error-code";
       
    71     /** Localized error message. Value type: string. */
       
    72     public static final String NAME_ERROR_MSG = "error-message";
    48     public static final String NAME_ERROR_MSG = "error-message";
    73     /** Localized message with more details of the error reason. Value type: string. */
       
    74     public static final String NAME_ERROR_DETAILS = "error-details";
    49     public static final String NAME_ERROR_DETAILS = "error-details";
    75     /** Suite UID. Value type: int. */
       
    76     public static final String NAME_SUITE_UID = "suite-uid";
    50     public static final String NAME_SUITE_UID = "suite-uid";
    77     /** Midlet-n UID. Value type: int. */
       
    78     public static final String NAME_MIDLET_UID = "midlet-uid-";
    51     public static final String NAME_MIDLET_UID = "midlet-uid-";
    79     /** Suite component id. Value type: int. */
       
    80     public static final String NAME_SUITE_CID = "suite-cid";
    52     public static final String NAME_SUITE_CID = "suite-cid";
    81     /** Midlet-n component id. Value type: int. */
       
    82     public static final String NAME_MIDLET_CID = "midlet-cid-";
    53     public static final String NAME_MIDLET_CID = "midlet-cid-";
    83     /** Suite global id. Value type: string. */
       
    84     public static final String NAME_SUITE_GID = "suite-gid";
    54     public static final String NAME_SUITE_GID = "suite-gid";
    85     /** Midlet-n global id. Value type: string. */
       
    86     public static final String NAME_MIDLET_GID = "midlet-gid-";
    55     public static final String NAME_MIDLET_GID = "midlet-gid-";
    87     /** Suite name. Value type: string. */
       
    88     public static final String NAME_SUITE_NAME = "suite-name";
    56     public static final String NAME_SUITE_NAME = "suite-name";
    89     /** Midlet-n name. Value type: string. */
       
    90     public static final String NAME_MIDLET_NAME=  "midlet-name-";
    57     public static final String NAME_MIDLET_NAME=  "midlet-name-";
    91     /** Suite vendor. Value type: string. */
       
    92     public static final String NAME_VENDOR = "vendor";
    58     public static final String NAME_VENDOR = "vendor";
    93     /** Suite version. Value type: string. */
       
    94     public static final String NAME_VERSION = "version";
    59     public static final String NAME_VERSION = "version";
    95     /** Component installation status. Value type: int. Possible values:
       
    96         0: new component,
       
    97         1: upgrade,
       
    98         2: already installed,
       
    99         3: newer version already installed,
       
   100         4: invalid package, cannot be installed. */
       
   101     public static final String NAME_INSTALL_STATUS = "install-status";
    60     public static final String NAME_INSTALL_STATUS = "install-status";
   102     /** Component authenticity. Value type: int. Possible values:
       
   103         0: component is not authenticated, 1: component is authenticated. */
       
   104     public static final String NAME_AUTHENTICITY = "authenticity";
    61     public static final String NAME_AUTHENTICITY = "authenticity";
   105     /** Size of the files owned by the component at the time of the
       
   106         installation. Calculated from MIDlet-Data-Size and
       
   107         MIDlet-Jar-Size attributes. Value type: int. */
       
   108     public static final String NAME_COMPONENT_SIZE = "component-size";
    62     public static final String NAME_COMPONENT_SIZE = "component-size";
   109 
       
   110     /** Id for installer result Comms message. */
       
   111     private static final int INSTALLER_RESULT_MESSAGE_ID = 601;
       
   112 
    63 
   113     private Hashtable iNamedIntValues = null;
    64     private Hashtable iNamedIntValues = null;
   114     private Hashtable iNamedStringValues = null;
    65     private Hashtable iNamedStringValues = null;
   115 
    66 
   116     private SifNotifier iSifNotifier = null;
    67     private SifNotifier iSifNotifier = null;
   212             msg = eb.getDetailedMessage();
   163             msg = eb.getDetailedMessage();
   213             if (msg != null)
   164             if (msg != null)
   214             {
   165             {
   215                 addValue(NAME_ERROR_DETAILS, msg);
   166                 addValue(NAME_ERROR_DETAILS, msg);
   216             }
   167             }
   217             addErrorCodes(eb);
   168             addErrorCategory(eb);
   218         }
   169         }
   219         if (aException instanceof InstallerException)
   170         if (aException instanceof InstallerException)
   220         {
   171         {
   221             InstallerException ie =
   172             InstallerException ie =
   222                 (InstallerException)aException;
   173                 (InstallerException)aException;
   240     {
   191     {
   241         iNamedIntValues.put(aName, new Integer(aValue));
   192         iNamedIntValues.put(aName, new Integer(aValue));
   242     }
   193     }
   243 
   194 
   244     /**
   195     /**
   245      * Returns a string value from this message, or null
   196      * Get a string value from this message.
   246      * if string value is not present.
   197      * @throws IllegalArgumentException if value with given name is not found
   247      */
   198      */
   248     String getStringValue(String aName)
   199     public String getStringValue(String aName)
   249     {
   200     {
   250         Object value = iNamedStringValues.get(aName);
   201         Object value = iNamedStringValues.get(aName);
   251         if (value instanceof String)
   202         if (value instanceof String)
   252         {
   203         {
   253             return (String)value;
   204             return (String)value;
   254         }
   205         }
   255         return null;
   206         throw new IllegalArgumentException(
       
   207             "InstallerResultMessage: string value " + aName + " not found");
   256     }
   208     }
   257 
   209 
   258     /**
   210     /**
   259      * Get an int value from this message.
   211      * Get an int value from this message.
   260      * @throws IllegalArgumentException if value with given name is not found
   212      * @throws IllegalArgumentException if value with given name is not found
   261      */
   213      */
   262     int getIntValue(String aName)
   214     public int getIntValue(String aName)
   263     {
   215     {
   264         Object value = iNamedIntValues.get(aName);
   216         Object value = iNamedIntValues.get(aName);
   265         if (value instanceof Integer)
   217         if (value instanceof Integer)
   266         {
   218         {
   267             return ((Integer)value).intValue();
   219             return ((Integer)value).intValue();
   271     }
   223     }
   272 
   224 
   273     /**
   225     /**
   274      * Removes a value from this message.
   226      * Removes a value from this message.
   275      */
   227      */
   276     void removeValue(String aName)
   228     public void removeValue(String aName)
   277     {
   229     {
   278         iNamedStringValues.remove(aName);
   230         iNamedStringValues.remove(aName);
   279         iNamedIntValues.remove(aName);
   231         iNamedIntValues.remove(aName);
   280     }
   232     }
   281 
   233 
   301                 installerException = ie;
   253                 installerException = ie;
   302             }
   254             }
   303         }
   255         }
   304         if (iSifNotifier != null)
   256         if (iSifNotifier != null)
   305         {
   257         {
       
   258             int errCategory = 0;
       
   259             int errCode = 0;
       
   260             String errMsg = null;
       
   261             String errDetails = null;
       
   262             if (getIntValue(NAME_RESULT) != Installer.ERR_NONE)
       
   263             {
       
   264                 errCategory = getIntValue(NAME_ERROR_CATEGORY);
       
   265                 errCode = Installer.ERR_GENERAL;
       
   266                 errMsg = getStringValue(NAME_ERROR_MSG);
       
   267                 errDetails = getStringValue(NAME_ERROR_DETAILS);
       
   268             }
   306             try
   269             try
   307             {
   270             {
   308                 int result = getIntValue(NAME_RESULT);
       
   309                 int errCategory = 0;
       
   310                 int errCode = 0;
       
   311                 String errMsg = null;
       
   312                 String errDetails = null;
       
   313                 if (result != Installer.ERR_NONE)
       
   314                 {
       
   315                     errCategory = getIntValue(NAME_ERROR_CATEGORY);
       
   316                     errCode = getIntValue(NAME_ERROR_CODE);
       
   317                     errMsg = getStringValue(NAME_ERROR_MSG);
       
   318                     errDetails = getStringValue(NAME_ERROR_DETAILS);
       
   319                 }
       
   320                 iSifNotifier.notifyEnd(errCategory, errCode, errMsg, errDetails);
   271                 iSifNotifier.notifyEnd(errCategory, errCode, errMsg, errDetails);
   321             }
   272             }
   322             catch (Throwable t)
   273             catch (Throwable t)
   323             {
   274             {
   324                 Log.logError("InstallerResultMessage: SifNotifier.notifyEnd failed", t);
   275                 Log.logError("InstallerResultMessage: SifNotifier.notifyEnd failed", t);
   345         }
   296         }
   346         try
   297         try
   347         {
   298         {
   348             comms.connect(aEndpoint);
   299             comms.connect(aEndpoint);
   349             CommsMessage msg = new CommsMessage();
   300             CommsMessage msg = new CommsMessage();
   350             msg.setMessageId(INSTALLER_RESULT_MESSAGE_ID);
   301             msg.setMessageId(601);
   351             // Initialise the message data.
   302             // Initialise the message data.
   352             msg.write(iNamedIntValues.size());
   303             msg.write(iNamedIntValues.size());
   353             Enumeration e = iNamedIntValues.keys();
   304             Enumeration e = iNamedIntValues.keys();
   354             while (e.hasMoreElements())
   305             while (e.hasMoreElements())
   355             {
   306             {
   365                 msg.write(name);
   316                 msg.write(name);
   366                 msg.write((String)iNamedStringValues.get(name));
   317                 msg.write((String)iNamedStringValues.get(name));
   367             }
   318             }
   368             // Send the message.
   319             // Send the message.
   369             Log.log("Sending InstallerResultMessage to " + aEndpoint);
   320             Log.log("Sending InstallerResultMessage to " + aEndpoint);
   370             comms.sendReceive(msg, 5);
   321             CommsMessage installerResultResponse = comms.sendReceive(msg, 5);
   371             comms.disconnect();
   322             comms.disconnect();
   372             Log.log("Received InstallerResultResponse from " + aEndpoint);
   323             Log.log("Received InstallerResultResponse from " + aEndpoint);
   373         }
   324         }
   374         catch (Throwable t)
   325         catch (Throwable t)
   375         {
   326         {
   432         }
   383         }
   433         return buf.toString();
   384         return buf.toString();
   434     }
   385     }
   435 
   386 
   436     /**
   387     /**
   437      * Adds error codes to the result message.
   388      * Adds error category to the result message.
   438      */
   389      */
   439     private void addErrorCodes(ExceptionBase aEb)
   390     private void addErrorCategory(ExceptionBase aEb)
   440     {
   391     {
   441         if (aEb.getShortMessageId() >= ErrorMessageBase.INSTALLER_RANGE_START &&
   392         switch (aEb.getShortMessageId())
   442             aEb.getShortMessageId() <= ErrorMessageBase.INSTALLER_RANGE_END)
   393         {
   443         {
   394         case InstallerErrorMessage.INST_NO_MEM:
   444             addValue(NAME_ERROR_CATEGORY,
   395             addValue(NAME_ERROR_CATEGORY, 2); // ELowDiskSpace
   445                      SifRegistrator.getErrorCategory(aEb.getShortMessageId()));
   396             break;
   446             addValue(NAME_ERROR_CODE,
   397         case InstallerErrorMessage.INST_NO_NET:
   447                      aEb.getShortMessageId()*1000 + aEb.getDetailedMessageId());
   398             addValue(NAME_ERROR_CATEGORY, 3); // ENetworkUnavailable
   448         }
   399             break;
   449         else if (aEb.getShortMessageId() >= ErrorMessageBase.SECURITY_RANGE_START &&
   400         case InstallerErrorMessage.INST_CORRUPT_PKG:
   450                  aEb.getShortMessageId() <= ErrorMessageBase.SECURITY_RANGE_END)
   401             addValue(NAME_ERROR_CATEGORY, 5); // ECorruptedPackage
   451         {
   402             break;
   452             addValue(NAME_ERROR_CATEGORY,
   403         case InstallerErrorMessage.INST_COMPAT_ERR:
   453                      SifRegistrator.getErrorCategory(
   404             addValue(NAME_ERROR_CATEGORY, 6); // EApplicationNotCompatible
   454                          InstallerErrorMessage.INST_AUTHORIZATION_ERR));
   405             break;
   455             addValue(NAME_ERROR_CODE,
   406         case InstallerErrorMessage.INST_AUTHORIZATION_ERR:
   456                      aEb.getShortMessageId()*1000 + aEb.getDetailedMessageId());
   407             // fall through
   457         }
   408         case InstallerErrorMessage.INST_AUTHENTICATION_ERR:
   458         else
   409             addValue(NAME_ERROR_CATEGORY, 7); // ESecurityError
   459         {
   410             break;
   460             addValue(NAME_ERROR_CATEGORY,
   411         case InstallerErrorMessage.INST_PUSH_REG_ERR:
   461                      SifRegistrator.getErrorCategory(
   412             // fall through
   462                          InstallerErrorMessage.INST_UNEXPECTED_ERR));
   413         case InstallerErrorMessage.INST_UNEXPECTED_ERR:
   463             addValue(NAME_ERROR_CODE,
   414             // fall through
   464                      aEb.getShortMessageId()*1000 + aEb.getDetailedMessageId());
   415         case InstallerErrorMessage.UNINST_UNEXPECTED_ERR:
       
   416             // fall through
       
   417         case InstallerErrorMessage.OTHER_UNEXPECTED_ERR:
       
   418             addValue(NAME_ERROR_CATEGORY, 8); // EUnexpectedError
       
   419             break;
       
   420         case InstallerErrorMessage.INST_CANCEL:
       
   421             // fall through
       
   422         case InstallerErrorMessage.UNINST_CANCEL:
       
   423             addValue(NAME_ERROR_CATEGORY, 9); // EUserCancelled
       
   424             break;
       
   425         case InstallerErrorMessage.UNINST_NOT_ALLOWED:
       
   426             addValue(NAME_ERROR_CATEGORY, 10); // EUninstallationBlocked
       
   427             break;
       
   428         default:
       
   429             addValue(NAME_ERROR_CATEGORY, 8); // EUnexpectedError
   465         }
   430         }
   466     }
   431     }
   467 }
   432 }