|
1 /* |
|
2 * Copyright (c) 2008-2009 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.midp2.install.steps; |
|
20 |
|
21 import com.nokia.mj.impl.installer.InstallerResultMessage; |
|
22 import com.nokia.mj.impl.installer.applicationregistrator.ApplicationRegistrator; |
|
23 import com.nokia.mj.impl.installer.applicationregistrator.SifRegistrator; |
|
24 import com.nokia.mj.impl.installer.customisationproperties.CustomisationProperties; |
|
25 import com.nokia.mj.impl.installer.downloader.Downloader; |
|
26 import com.nokia.mj.impl.installer.exetable.ExeBall; |
|
27 import com.nokia.mj.impl.installer.exetable.ExeStep; |
|
28 import com.nokia.mj.impl.installer.integrityservice.IntegrityService; |
|
29 import com.nokia.mj.impl.installer.jsrpluginnotifier.JsrPluginNotifier; |
|
30 import com.nokia.mj.impl.installer.storagehandler.StorageHandler; |
|
31 import com.nokia.mj.impl.installer.utils.Args; |
|
32 import com.nokia.mj.impl.installer.utils.FileRoots; |
|
33 import com.nokia.mj.impl.installer.utils.FileUtils; |
|
34 import com.nokia.mj.impl.installer.utils.InstallerException; |
|
35 import com.nokia.mj.impl.installer.utils.Log; |
|
36 import com.nokia.mj.impl.installer.utils.MidpAttributeValidator; |
|
37 import com.nokia.mj.impl.installer.utils.SysUtil; |
|
38 import com.nokia.mj.impl.security.midp.authentication.AuthenticationModule; |
|
39 import com.nokia.mj.impl.security.midp.authentication.OcspSettings; |
|
40 import com.nokia.mj.impl.utils.Uid; |
|
41 |
|
42 public class PrepareInstallation extends ExeStep |
|
43 { |
|
44 |
|
45 public void execute(ExeBall aBall) |
|
46 { |
|
47 InstallBall ball = (InstallBall)aBall; |
|
48 ball.log("Preparing installation..."); |
|
49 |
|
50 ball.iCustomisationProperties = new CustomisationProperties(); |
|
51 // Get default installation drive from CustomisationProperties... |
|
52 ball.iInstallationDrive = |
|
53 ((Integer)(ball.iCustomisationProperties.getIntegerProperty |
|
54 (CustomisationProperties.DefaultInstallationDrive). |
|
55 firstElement())).intValue(); |
|
56 Log.log("CustomisationProperties called"); |
|
57 // ...then check if we are making preinstallation |
|
58 // and set installation target drive accordingly... |
|
59 parseJadJarArgs(ball); |
|
60 checkForPreinstallation(ball); |
|
61 // ...and finally override installation drive with possible value |
|
62 // from command line. |
|
63 parseArgs(ball); |
|
64 FileUtils.setAppsRoot(ball.iInstallationDrive); |
|
65 Log.log("Args parsed"); |
|
66 String isRoot = FileUtils.getIntegrityServiceRoot(); |
|
67 ball.iIntegrityService = IntegrityService.getInstance(isRoot); |
|
68 Log.log("IntegrityService instantiated"); |
|
69 ball.iStorageHandler = new StorageHandler(); |
|
70 ball.iStorageHandler.startSession(); |
|
71 Log.log("StorageSession created"); |
|
72 ball.iApplicationRegistrator = new ApplicationRegistrator(); |
|
73 ball.iApplicationRegistrator.startSession(); |
|
74 Log.log("ApplicationRegistrator session created"); |
|
75 ball.iSifRegistrator = new SifRegistrator(); |
|
76 ball.iSifRegistrator.startSession(true); |
|
77 Log.log("SifRegistrator session created"); |
|
78 ball.iJsrPluginNotifier = new JsrPluginNotifier(ball.iIntegrityService); |
|
79 Log.log("JsrPluginNotifier created"); |
|
80 ball.iAttributeValidator = new MidpAttributeValidator(); |
|
81 Log.log("MidpAttributeValidator created"); |
|
82 AuthenticationModule.getInstance().setOCSPFlags(getOcspSettings(ball)); |
|
83 |
|
84 ball.iInstallationNotifier.start( |
|
85 ball.iInstallationNotifier.INSTALLING); |
|
86 } |
|
87 |
|
88 public void cancel(ExeBall aBall) |
|
89 { |
|
90 InstallBall ball = (InstallBall)aBall; |
|
91 ball.log("Installation failed."); |
|
92 if (ball.getExecuteException() != null) |
|
93 { |
|
94 ball.log(ball.getExecuteException().toString()); |
|
95 } |
|
96 |
|
97 // If posting OTA status notifications is still going on, |
|
98 // stop it now and continue when next installation is made. |
|
99 ball.getNotificationPoster().stop(); |
|
100 |
|
101 // Cleanup security components. |
|
102 ball.cleanupSecurity(); |
|
103 |
|
104 boolean result = ball.iIntegrityService.rollback(); |
|
105 if (!result) |
|
106 { |
|
107 Log.logError("IntegrityService rollback failed"); |
|
108 } |
|
109 else |
|
110 { |
|
111 Log.log("IntegrityService rolled back"); |
|
112 } |
|
113 try |
|
114 { |
|
115 ball.iStorageHandler.rollbackSession(); |
|
116 Log.log("StorageHandler rolled back"); |
|
117 } |
|
118 catch (Exception ex) |
|
119 { |
|
120 Log.logError("StorageHandler rollback failed", ex); |
|
121 } |
|
122 try |
|
123 { |
|
124 ball.iSifRegistrator.rollbackSession(); |
|
125 Log.log("SifRegistrator rolled back"); |
|
126 } |
|
127 catch (Exception ex) |
|
128 { |
|
129 Log.logError("SifRegistrator rollback failed", ex); |
|
130 } |
|
131 try |
|
132 { |
|
133 ball.iApplicationRegistrator.rollbackSession(); |
|
134 Log.log("ApplicationRegistrator rolled back"); |
|
135 } |
|
136 catch (Exception ex) |
|
137 { |
|
138 Log.logError("ApplicationRegistrator rollback failed", ex); |
|
139 } |
|
140 |
|
141 Uid uid = (ball.iSuite != null? ball.iSuite.getUid(): null); |
|
142 ball.iInstallationNotifier.finish( |
|
143 uid, ball.iInstallationNotifier.INSTALL_FAIL); |
|
144 } |
|
145 |
|
146 private static void parseJadJarArgs(InstallBall aBall) |
|
147 { |
|
148 Args args = aBall.iArgs; |
|
149 |
|
150 // Parse commsresult option first so that if parsing other |
|
151 // options fails the InstallerResultMesage will be correctly |
|
152 // sent. |
|
153 String arg = args.get("commsresult"); |
|
154 if (arg != null) |
|
155 { |
|
156 aBall.iCommsResultEndpoints = |
|
157 InstallerResultMessage.parseEndpoints(arg); |
|
158 } |
|
159 |
|
160 String jadArg = args.get("jad"); |
|
161 String jarArg = args.get("jar"); |
|
162 if (jadArg != null && jarArg != null) |
|
163 { |
|
164 InstallerException.internalError |
|
165 ("Specify either Jad or Jar as an argument, not both."); |
|
166 } |
|
167 if (jarArg != null) |
|
168 { |
|
169 if (Downloader.isDownloadUrl(jarArg)) |
|
170 { |
|
171 aBall.iJarUrl = jarArg; |
|
172 } |
|
173 else |
|
174 { |
|
175 aBall.iJarFilename = jarArg; |
|
176 } |
|
177 } |
|
178 if (jadArg != null) |
|
179 { |
|
180 if (Downloader.isDownloadUrl(jadArg)) |
|
181 { |
|
182 aBall.iJadUrl = jadArg; |
|
183 } |
|
184 else |
|
185 { |
|
186 aBall.iJadFilename = jadArg; |
|
187 } |
|
188 } |
|
189 |
|
190 aBall.iSourceUrl = args.get("sourceurl", aBall.iSourceUrl); |
|
191 } |
|
192 |
|
193 private static void parseArgs(InstallBall aBall) |
|
194 { |
|
195 Args args = aBall.iArgs; |
|
196 |
|
197 // Parse string type arguments |
|
198 aBall.iIap = args.get("iap", aBall.iIap); |
|
199 aBall.iSnap = args.get("snap", aBall.iSnap); |
|
200 aBall.iJadCharset = args.get("charset", aBall.iJadCharset); |
|
201 aBall.iDownloadUsername = args.get("username", aBall.iDownloadUsername); |
|
202 aBall.iDownloadPassword = args.get("password", aBall.iDownloadPassword); |
|
203 |
|
204 String arg = args.get("proxyhost"); |
|
205 if (arg != null) |
|
206 { |
|
207 System.setProperty("http.proxyHost", arg); |
|
208 aBall.log("HTTP proxy host set to " + arg); |
|
209 } |
|
210 |
|
211 arg = args.get("proxyport"); |
|
212 if (arg != null) |
|
213 { |
|
214 System.setProperty("http.proxyPort", arg); |
|
215 aBall.log("HTTP proxy port set to " + arg); |
|
216 } |
|
217 |
|
218 // Parse boolean type arguments |
|
219 aBall.iCaptainMsgs = args.getBoolean("captainmsgs", aBall.iCaptainMsgs); |
|
220 aBall.iAllowUpgrade = args.getBoolean("upgrade", aBall.iAllowUpgrade); |
|
221 aBall.iUpgradeData = args.getBoolean("upgrade_data", aBall.iUpgradeData); |
|
222 aBall.iAllowOverwrite = args.getBoolean("overwrite", aBall.iAllowOverwrite); |
|
223 aBall.iAllowUntrusted = args.getBoolean("untrusted", aBall.iAllowUntrusted); |
|
224 aBall.iOcsp = args.getBoolean("ocsp", aBall.iOcsp); |
|
225 aBall.iIgnoreOcspWarnings = args.getBoolean("ignore_ocsp_warnings", aBall.iIgnoreOcspWarnings); |
|
226 aBall.iAllowDownload = args.getBoolean("download", aBall.iAllowDownload); |
|
227 aBall.iConversionInstallation = args.getBoolean("convert", aBall.iConversionInstallation); |
|
228 if (aBall.iConversionInstallation) |
|
229 { |
|
230 String filename = aBall.iJadFilename; |
|
231 if (filename == null) |
|
232 { |
|
233 filename = aBall.iJarFilename; |
|
234 } |
|
235 if (filename != null) |
|
236 { |
|
237 aBall.iConversionRoot = FileUtils.getParent(filename); |
|
238 int drive = FileUtils.getDrive(filename); |
|
239 if (drive != -1) |
|
240 { |
|
241 // Make conversion installation to the same |
|
242 // drive where the application already exists. |
|
243 aBall.iInstallationDrive = drive; |
|
244 } |
|
245 } |
|
246 if (aBall.iConversionRoot == null || |
|
247 !FileUtils.exists(aBall.iConversionRoot)) |
|
248 { |
|
249 InstallerException.internalError( |
|
250 "Root dir for conversion installation does not exist: " + |
|
251 aBall.iConversionRoot); |
|
252 } |
|
253 else |
|
254 { |
|
255 Log.log("Conversion installation from " + aBall.iConversionRoot); |
|
256 } |
|
257 // Conversion installation cannot be canceled. |
|
258 aBall.setCanCancel(false); |
|
259 // Uncomment the next line to disable conversion installation support. |
|
260 //InstallerException.internalError("Conversion installation not supported"); |
|
261 } |
|
262 |
|
263 // Process "drive" argument after "convert" argument so that it can |
|
264 // be used to override the target installation drive. |
|
265 arg = args.get("drive"); |
|
266 if (arg != null) |
|
267 { |
|
268 aBall.iInstallationDrive = args.parseDrive(arg); |
|
269 } |
|
270 } |
|
271 |
|
272 private static void checkForPreinstallation(InstallBall aBall) |
|
273 { |
|
274 String preinstallDir = FileRoots.getPreinstallDir(); |
|
275 if (preinstallDir == null || preinstallDir.length() == 0) |
|
276 { |
|
277 return; |
|
278 } |
|
279 checkForPreinstallation(aBall, aBall.iJadFilename, preinstallDir); |
|
280 checkForPreinstallation(aBall, aBall.iJarFilename, preinstallDir); |
|
281 } |
|
282 |
|
283 private static void checkForPreinstallation(InstallBall aBall, |
|
284 String aFilename, |
|
285 String aPreinstallDir) |
|
286 { |
|
287 if ((aFilename != null) && |
|
288 (aFilename.indexOf(aPreinstallDir) != -1) && |
|
289 aBall.isSilent()) |
|
290 { |
|
291 aBall.iPreinstallation = true; |
|
292 int drive = FileRoots.getPreinstallDrive(aFilename); |
|
293 if (drive != -1) |
|
294 { |
|
295 aBall.iInstallationDrive = drive; |
|
296 } |
|
297 } |
|
298 } |
|
299 |
|
300 private static OcspSettings getOcspSettings(InstallBall aBall) |
|
301 { |
|
302 int ocspMode = OcspSettings.OCSP_MODE_UNDEFINED; |
|
303 if (aBall.iOcsp != null) |
|
304 { |
|
305 if (aBall.iOcsp.booleanValue()) |
|
306 { |
|
307 ocspMode = OcspSettings.OCSP_MODE_ENABLED; |
|
308 } |
|
309 else |
|
310 { |
|
311 ocspMode = OcspSettings.OCSP_MODE_DISABLED; |
|
312 } |
|
313 } |
|
314 int drive = -1; |
|
315 if (aBall.iJadFilename != null) |
|
316 { |
|
317 drive = FileUtils.getDrive(aBall.iJadFilename); |
|
318 } |
|
319 else if (aBall.iJarFilename != null) |
|
320 { |
|
321 drive = FileUtils.getDrive(aBall.iJarFilename); |
|
322 } |
|
323 if (drive != -1 && SysUtil.isDriveReadOnly(drive)) |
|
324 { |
|
325 // If installation is started from read-only drive |
|
326 // OCSP must never be made. |
|
327 ocspMode = OcspSettings.OCSP_MODE_DISABLED; |
|
328 } |
|
329 |
|
330 int ocspWarning = OcspSettings.OCSP_WARNING_UNDEFINED; |
|
331 if (aBall.iIgnoreOcspWarnings != null) |
|
332 { |
|
333 if (aBall.iIgnoreOcspWarnings.booleanValue()) |
|
334 { |
|
335 ocspWarning = OcspSettings.OCSP_WARNING_IGNORE; |
|
336 } |
|
337 else |
|
338 { |
|
339 ocspWarning = OcspSettings.OCSP_WARNING_CONFIRM; |
|
340 } |
|
341 } |
|
342 |
|
343 OcspSettings ocspSettings = |
|
344 new OcspSettings(ocspMode, ocspWarning, aBall.isSilent(), |
|
345 aBall.iIap, aBall.iSnap); |
|
346 Log.log("ocspSettings: " + ocspSettings); |
|
347 return ocspSettings; |
|
348 } |
|
349 } |