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 := <string> |
|
54 * int_value := <int> |
|
55 * string_value := <string> |
|
56 * length := <int telling the length of the table that follows> |
|
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; |
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(); |
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 } |