44 public static final int UNINSTALL_OK = 0x201; |
44 public static final int UNINSTALL_OK = 0x201; |
45 public static final int UNINSTALL_FAIL = 0x202; |
45 public static final int UNINSTALL_FAIL = 0x202; |
46 |
46 |
47 // Maximum number of progress updates to SysUtil.setProperty(). |
47 // Maximum number of progress updates to SysUtil.setProperty(). |
48 private static final int MAX_PROPERTY_PROGRESS_UPDATES = 5; |
48 private static final int MAX_PROPERTY_PROGRESS_UPDATES = 5; |
|
49 // Maximum number of progress updates to SIF. |
|
50 private static final int MAX_SIF_PROGRESS_UPDATES = 5; |
49 // Maximum number of progress updates to UI. |
51 // Maximum number of progress updates to UI. |
50 private static final int MAX_UI_PROGRESS_UPDATES = 20; |
52 private static final int MAX_UI_PROGRESS_UPDATES = 20; |
51 |
53 |
52 // Flag telling if the properties are already defined. |
54 // Flag telling if the properties are already defined. |
53 private static boolean iPropertiesDefined = false; |
55 private static boolean iPropertiesDefined = false; |
59 |
61 |
60 // Maximum progress value. |
62 // Maximum progress value. |
61 private int iMaxValue = 1; |
63 private int iMaxValue = 1; |
62 // Tells how often property progress should be updated. |
64 // Tells how often property progress should be updated. |
63 private int iPropertyProgressStep = 1; |
65 private int iPropertyProgressStep = 1; |
|
66 // Tells how often SIF progress should be updated. |
|
67 private int iSifProgressStep = 1; |
64 // Tells how often UI progress should be updated. |
68 // Tells how often UI progress should be updated. |
65 private int iUiProgressStep = 1; |
69 private int iUiProgressStep = 1; |
66 // Point between 0 and iMaxValue where the last property |
70 // Point between 0 and iMaxValue where the last property |
67 // update has been made. |
71 // update has been made. |
68 private int iLastPropertyUpdate = 0; |
72 private int iLastPropertyUpdate = 0; |
|
73 // Point between 0 and iMaxValue where the last SIF update |
|
74 // has been made. |
|
75 private int iLastSifUpdate = 0; |
69 // Point between 0 and iMaxValue where the last UI update |
76 // Point between 0 and iMaxValue where the last UI update |
70 // has been made. |
77 // has been made. |
71 private int iLastUiUpdate = 0; |
78 private int iLastUiUpdate = 0; |
72 // Flag telling if the started() method has been called. |
79 // Flag telling if the started() method has been called. |
73 private boolean iStarted = false; |
80 private boolean iStarted = false; |
201 iPropertyProgressStep = iMaxValue / MAX_PROPERTY_PROGRESS_UPDATES; |
208 iPropertyProgressStep = iMaxValue / MAX_PROPERTY_PROGRESS_UPDATES; |
202 if (iPropertyProgressStep == 0) |
209 if (iPropertyProgressStep == 0) |
203 { |
210 { |
204 iPropertyProgressStep = 1; |
211 iPropertyProgressStep = 1; |
205 } |
212 } |
|
213 iSifProgressStep = iMaxValue / MAX_SIF_PROGRESS_UPDATES; |
|
214 if (iSifProgressStep == 0) |
|
215 { |
|
216 iSifProgressStep = 1; |
|
217 } |
206 iUiProgressStep = iMaxValue / MAX_UI_PROGRESS_UPDATES; |
218 iUiProgressStep = iMaxValue / MAX_UI_PROGRESS_UPDATES; |
207 if (iUiProgressStep == 0) |
219 if (iUiProgressStep == 0) |
208 { |
220 { |
209 iUiProgressStep = 1; |
221 iUiProgressStep = 1; |
210 } |
222 } |
239 } |
251 } |
240 int currentPercentage = (aCurrentValue * 100) / iMaxValue; |
252 int currentPercentage = (aCurrentValue * 100) / iMaxValue; |
241 Log.log("InstallationNotifier.set: progress " + currentPercentage); |
253 Log.log("InstallationNotifier.set: progress " + currentPercentage); |
242 defineProperties(); |
254 defineProperties(); |
243 |
255 |
244 if (aCurrentValue == 0 || |
256 if (isUpdateNeeded(aCurrentValue, iMaxValue, |
245 aCurrentValue == iMaxValue || |
257 iLastPropertyUpdate, iPropertyProgressStep)) |
246 aCurrentValue >= iLastPropertyUpdate + iPropertyProgressStep || |
|
247 aCurrentValue <= iLastPropertyUpdate - iPropertyProgressStep) |
|
248 { |
258 { |
249 iLastPropertyUpdate = aCurrentValue; |
259 iLastPropertyUpdate = aCurrentValue; |
250 Log.log("InstallationNotifier.set: update property to " + |
260 Log.log("InstallationNotifier.set: update property to " + |
251 currentPercentage); |
261 currentPercentage); |
252 // Update property values: progress. |
262 // Update property values: progress. |
253 SysUtil.setPropertyValue |
263 SysUtil.setPropertyValue( |
254 (SysUtil.PROP_CATEGORY_SYSTEM, |
264 SysUtil.PROP_CATEGORY_SYSTEM, |
255 SysUtil.PROP_KEY_JAVA_LATEST_INSTALLATION_PROGRESS, |
265 SysUtil.PROP_KEY_JAVA_LATEST_INSTALLATION_PROGRESS, |
256 currentPercentage); |
266 currentPercentage); |
257 } |
267 } |
258 |
268 |
259 if (aCurrentValue == 0 || |
269 if (isUpdateNeeded(aCurrentValue, iMaxValue, |
260 aCurrentValue == iMaxValue || |
270 iLastSifUpdate, iSifProgressStep)) |
261 aCurrentValue >= iLastUiUpdate + iUiProgressStep || |
271 { |
262 aCurrentValue <= iLastUiUpdate - iUiProgressStep) |
272 if (iSifNotifier != null) |
263 { |
273 { |
264 iLastUiUpdate = aCurrentValue; |
274 iLastSifUpdate = aCurrentValue; |
|
275 try |
|
276 { |
|
277 iSifNotifier.notifyProgress( |
|
278 iSifNotifier.SUB_OP_NO, currentPercentage, 100); |
|
279 } |
|
280 catch (Throwable t) |
|
281 { |
|
282 Log.logError( |
|
283 "InstallationNotifier: SifNotifier.notifyProgress threw exception", t); |
|
284 } |
|
285 } |
|
286 } |
|
287 |
|
288 if (isUpdateNeeded(aCurrentValue, iMaxValue, |
|
289 iLastUiUpdate, iUiProgressStep)) |
|
290 { |
265 if (iInstallerUi != null) |
291 if (iInstallerUi != null) |
266 { |
292 { |
|
293 iLastUiUpdate = aCurrentValue; |
267 Log.log("InstallationNotifier.set: update ui to " + |
294 Log.log("InstallationNotifier.set: update ui to " + |
268 currentPercentage); |
295 currentPercentage); |
269 try |
296 try |
270 { |
297 { |
271 iInstallerUi.updateProgress(currentPercentage); |
298 iInstallerUi.updateProgress(currentPercentage); |
274 { |
301 { |
275 Log.logError( |
302 Log.logError( |
276 "InstallationNotifier: InstallerUi.updateProgress threw exception", t); |
303 "InstallationNotifier: InstallerUi.updateProgress threw exception", t); |
277 } |
304 } |
278 } |
305 } |
279 if (iSifNotifier != null) |
|
280 { |
|
281 Log.log("InstallationNotifier.set: update SifNotifier to " + |
|
282 currentPercentage); |
|
283 try |
|
284 { |
|
285 iSifNotifier.notifyProgress( |
|
286 iSifNotifier.SUB_OP_NO, currentPercentage, 100); |
|
287 } |
|
288 catch (Throwable t) |
|
289 { |
|
290 Log.logError( |
|
291 "InstallationNotifier: SifNotifier.notifyProgress threw exception", t); |
|
292 } |
|
293 } |
|
294 } |
306 } |
295 } |
307 } |
296 |
308 |
297 /** |
309 /** |
298 * This method is called from execution steps to notify |
310 * This method is called from execution steps to notify |
380 { |
392 { |
381 Log.logError( |
393 Log.logError( |
382 "InstallationNotifier: Deleting property failed", ex); |
394 "InstallationNotifier: Deleting property failed", ex); |
383 } |
395 } |
384 } |
396 } |
|
397 |
|
398 /** |
|
399 * Returns true if progress update is needed, false otherwise. |
|
400 * |
|
401 * @param aCurrent current progress value |
|
402 * @param aMax maximum progress value |
|
403 * @param aPrevious previously updated progress value |
|
404 * @param aStep step between progress updates |
|
405 */ |
|
406 private static boolean isUpdateNeeded( |
|
407 int aCurrent, int aMax, int aPrevious, int aStep) |
|
408 { |
|
409 if (aCurrent == 0 || aCurrent == aMax || |
|
410 aCurrent >= aPrevious + aStep || |
|
411 aCurrent <= aPrevious - aStep) |
|
412 { |
|
413 return true; |
|
414 } |
|
415 return false; |
|
416 } |
385 } |
417 } |