16 */ |
16 */ |
17 |
17 |
18 |
18 |
19 package com.nokia.mj.impl.installer.applicationregistrator; |
19 package com.nokia.mj.impl.installer.applicationregistrator; |
20 |
20 |
|
21 import com.nokia.mj.impl.installer.ui.InstallerUi; |
21 import com.nokia.mj.impl.installer.utils.InstallerException; |
22 import com.nokia.mj.impl.installer.utils.InstallerException; |
22 import com.nokia.mj.impl.installer.utils.Log; |
23 import com.nokia.mj.impl.installer.utils.Log; |
|
24 import com.nokia.mj.impl.installer.utils.PropertyListener; |
|
25 import com.nokia.mj.impl.installer.utils.PropertyProvider; |
23 |
26 |
24 /** |
27 /** |
25 * Sends installation and uninstallation progress notifications |
28 * Sends installation and uninstallation progress notifications |
26 * to platform's software installation framework. |
29 * to platform's software installation framework. |
27 */ |
30 */ |
28 public final class SifNotifier |
31 public final class SifNotifier |
29 { |
32 { |
30 /** Install operation. */ |
33 /** Install operation. */ |
31 public static final int OP_INSTALL = 1; |
34 public static final int OP_INSTALL = 1; // TSifOperationPhase::EInstalling |
32 /** Uninstall operation. */ |
35 /** Uninstall operation. */ |
33 public static final int OP_UNINSTALL = 2; |
36 public static final int OP_UNINSTALL = 2; // TSifOperationPhase::EUninstalling |
34 /** Update operation. */ |
37 /** Update operation. */ |
35 public static final int OP_UPDATE = 3; |
38 public static final int OP_UPDATE = 3; // TSifOperationPhase::EUpgrading |
36 |
39 |
37 /** Indicates installaion or uninstallation without |
40 /** Indicates installation or uninstallation without |
38 specific suboperation. */ |
41 specific suboperation. */ |
39 public static final int SUB_OP_NO = 1; |
42 public static final int SUB_OP_NO = 1; // TSifOperationSubPhase::ENoSubPhase |
40 /** OCSP phase during installation. */ |
43 /** OCSP phase during installation. */ |
41 public static final int SUB_OP_OCSP = 2; |
44 public static final int SUB_OP_OCSP = 2; // TSifOperationSubPhase::EOCSPCheck |
42 /** Download phase during installation. */ |
45 /** Download phase during installation. */ |
43 public static final int SUB_OP_DOWNLOAD = 3; |
46 public static final int SUB_OP_DOWNLOAD = 3; // TSifOperationSubPhase::EDownload |
44 /** Maximum progress notification value. */ |
47 /** Maximum progress notification value. */ |
45 private static final int MAX_PROGRESS = 100; |
48 private static final int MAX_PROGRESS = 100; |
46 |
49 |
47 /** Operation being notified. */ |
50 /** Operation being notified. */ |
48 private int iOperation = 0; |
51 private int iOperation = 0; |
|
52 /** Suboperation during installation. */ |
|
53 private int iSubOperation = 0; |
49 /** Global component id for the application. */ |
54 /** Global component id for the application. */ |
50 private String iGlobalComponentId = null; |
55 private String iGlobalComponentId = null; |
51 /** Component name (i.e. suite name). */ |
56 /** Component name (i.e. suite name). */ |
52 private String iComponentName = null; |
57 private String iComponentName = null; |
53 /** Application names. */ |
58 /** Application names. */ |
62 private String iComponentIcon = null; |
67 private String iComponentIcon = null; |
63 |
68 |
64 /** Sending progress notifications is only allowed between start |
69 /** Sending progress notifications is only allowed between start |
65 * and end notifications. */ |
70 * and end notifications. */ |
66 private boolean iNotifyProgressAllowed = false; |
71 private boolean iNotifyProgressAllowed = false; |
67 /** Value of the last progress notification that has been sent. */ |
72 /** |
|
73 * Value of the last progress notification that has been sent with |
|
74 * SUB_OP_NO suboperation. |
|
75 */ |
68 private int iLastProgressSent = 0; |
76 private int iLastProgressSent = 0; |
69 |
77 /** Current value of the last progress notification that has been sent. */ |
70 /** Native object handle. */ |
78 private int iCurrentValue = 0; |
|
79 /** total value of the last progress notification that has been sent. */ |
|
80 private int iTotalValue = 0; |
|
81 |
|
82 /** Native notifier object handle. */ |
71 private int iHandle = 0; |
83 private int iHandle = 0; |
|
84 /** Native indicator object handle. */ |
|
85 private int iIndicatorHandle = 0; |
|
86 /** InstallerUi handle. */ |
|
87 private InstallerUi iInstallerUi = null; |
|
88 /** Provider for indicator status events. */ |
|
89 private PropertyProvider iIndicatorStatusProvider = null; |
|
90 /** Indicator state. */ |
|
91 private int iIndicatorState = -1; |
72 |
92 |
73 /*** ----------------------------- PUBLIC ------------------------------ */ |
93 /*** ----------------------------- PUBLIC ------------------------------ */ |
74 |
94 |
75 /** |
95 /** |
76 * Constructor. |
96 * Constructor. |
77 */ |
97 */ |
78 public SifNotifier() |
98 public SifNotifier() |
79 { |
99 { |
80 init(); |
100 init(); |
|
101 } |
|
102 |
|
103 /** |
|
104 * Set InstallerUi used when handling indicator. |
|
105 */ |
|
106 public void setInstallerUi(InstallerUi aInstallerUi) |
|
107 { |
|
108 iInstallerUi = aInstallerUi; |
|
109 } |
|
110 |
|
111 /** |
|
112 * Activates and updates indicator which displays installation |
|
113 * progress to user while installer UI is hidden. The notifyStart |
|
114 * and notifyProgress methods must be called at least once before |
|
115 * calling this method. |
|
116 */ |
|
117 public void activateIndicator() |
|
118 { |
|
119 if (iInstallerUi == null) |
|
120 { |
|
121 return; |
|
122 } |
|
123 |
|
124 if (iIndicatorHandle == 0) |
|
125 { |
|
126 int ret = _initIndicator(); |
|
127 if (ret < 0) |
|
128 { |
|
129 Log.logError( |
|
130 "Initializing SifNotifier indicator failed with code " + |
|
131 ret); |
|
132 } |
|
133 else |
|
134 { |
|
135 Log.log("SifNotifier indicator created"); |
|
136 } |
|
137 iIndicatorHandle = ret; |
|
138 } |
|
139 |
|
140 if (iIndicatorHandle == 0) |
|
141 { |
|
142 return; |
|
143 } |
|
144 |
|
145 int phase = 0; |
|
146 switch (iSubOperation) |
|
147 { |
|
148 case SUB_OP_OCSP: phase = 2; break; // TInstallingPhase::ECheckingCerts |
|
149 case SUB_OP_DOWNLOAD: phase = 1; break; // TInstallingPhase::EDownloading |
|
150 default: phase = 0; // TInstallingPhase::EInstalling |
|
151 } |
|
152 int progress = (iTotalValue == 0? 0: iCurrentValue*100/iTotalValue); |
|
153 updateIndicator(iComponentName, phase, progress); |
|
154 |
|
155 if (iIndicatorStatusProvider == null) |
|
156 { |
|
157 // Create PropertyListener which listens indicator status events |
|
158 // and unhides UI when necessary. |
|
159 final int indicatorCategory = 0x20022FC5; // sifuiinstallindicatorplugin |
|
160 final int indicatorKey = 0x2002E690; // /SifUiInstallIndicator/Status |
|
161 iIndicatorStatusProvider = new PropertyProvider(); |
|
162 iIndicatorStatusProvider.subscribe( |
|
163 indicatorCategory, indicatorKey, new PropertyListener() |
|
164 { |
|
165 public void valueChanged(int aCategory, int aKey, int aValue) |
|
166 { |
|
167 Log.log("SifNotifier indicator status " + aValue + |
|
168 " (category=" + aCategory + ", key=" + aKey + ")"); |
|
169 iIndicatorState = aValue; |
|
170 if (iIndicatorState == 0) |
|
171 { |
|
172 // Indicator has been closed, unhide the UI. |
|
173 iInstallerUi.hide(false); |
|
174 } |
|
175 } |
|
176 }); |
|
177 Log.log("SifNotifier indicator status provider subscribed"); |
|
178 } |
|
179 } |
|
180 |
|
181 /** |
|
182 * Updates indicator which displays installation progress to user |
|
183 * while installer UI is hidden. The activateindicator method must |
|
184 * be called before calling this method. |
|
185 */ |
|
186 public void updateIndicator(String aName, int aPhase, int aProgress) |
|
187 { |
|
188 if (iInstallerUi == null || iIndicatorHandle == 0) |
|
189 { |
|
190 return; |
|
191 } |
|
192 |
|
193 final String name = aName; |
|
194 final int phase = aPhase; |
|
195 final int progress = aProgress; |
|
196 iInstallerUi.syncExec(new Runnable() |
|
197 { |
|
198 // Indicator must be updated from UI thread. |
|
199 public void run() |
|
200 { |
|
201 int ret = _updateIndicator( |
|
202 iIndicatorHandle, name, phase, progress); |
|
203 if (ret < 0) |
|
204 { |
|
205 Log.logError( |
|
206 "Updating SifNotifier indicator failed with code " + |
|
207 ret); |
|
208 } |
|
209 else |
|
210 { |
|
211 Log.log("SifNotifier indicator updated: " + name + |
|
212 ", " + phase + ", " + progress + "%"); |
|
213 } |
|
214 } |
|
215 }); |
|
216 } |
|
217 |
|
218 /** |
|
219 * Deactivates indicator which displays installation |
|
220 * progress to user while installer UI is hidden. |
|
221 */ |
|
222 public void deactivateIndicator() |
|
223 { |
|
224 if (iIndicatorStatusProvider != null) |
|
225 { |
|
226 iIndicatorStatusProvider.unsubscribe(); |
|
227 iIndicatorStatusProvider = null; |
|
228 Log.log("SifNotifier indicator status provider unsubscribed"); |
|
229 } |
|
230 |
|
231 if (iInstallerUi == null) |
|
232 { |
|
233 return; |
|
234 } |
|
235 |
|
236 iInstallerUi.syncExec(new Runnable() |
|
237 { |
|
238 // Indicator must be deactivated from UI thread. |
|
239 public void run() |
|
240 { |
|
241 if (iIndicatorHandle == 0) |
|
242 { |
|
243 return; |
|
244 } |
|
245 int ret = _destroyIndicator(iIndicatorHandle, iIndicatorState); |
|
246 if (ret < 0) |
|
247 { |
|
248 Log.logError( |
|
249 "Destroying SifNotifier indicator failed with code " + |
|
250 ret); |
|
251 } |
|
252 else |
|
253 { |
|
254 Log.log("SifNotifier indicator destroyed"); |
|
255 } |
|
256 iIndicatorHandle = 0; |
|
257 } |
|
258 }); |
81 } |
259 } |
82 |
260 |
83 /** |
261 /** |
84 * Returns true if SIF progress notifications are enabled, false otherwise. |
262 * Returns true if SIF progress notifications are enabled, false otherwise. |
85 */ |
263 */ |
318 * @param aComponentIcon |
508 * @param aComponentIcon |
319 * @return Symbian error code (negative number) if operation fails, |
509 * @return Symbian error code (negative number) if operation fails, |
320 * otherwise 0 |
510 * otherwise 0 |
321 */ |
511 */ |
322 private static native int _notifyStart( |
512 private static native int _notifyStart( |
323 int aHandle, String aGlobalComponentId, String aComponentName, |
513 int aHandle, int aOperation, String aGlobalComponentId, |
324 String[] aApplicationNames, String[] aApplicationIcons, |
514 String aComponentName, String[] aApplicationNames, |
325 int aComponentSize, String aIconDir, String aComponentIcon); |
515 String[] aApplicationIcons, int aComponentSize, |
|
516 String aIconDir, String aComponentIcon); |
326 |
517 |
327 /** |
518 /** |
328 * Notifies SIF about installation/uinstallation completion. |
519 * Notifies SIF about installation/uinstallation completion. |
329 * |
520 * |
330 * @param aHandle |
521 * @param aHandle |
374 * @return Symbian error code (negative number) if operation fails, |
565 * @return Symbian error code (negative number) if operation fails, |
375 * otherwise 0 |
566 * otherwise 0 |
376 */ |
567 */ |
377 private static native int _destroy(int aHandle); |
568 private static native int _destroy(int aHandle); |
378 |
569 |
|
570 /** |
|
571 * Initializes SifNotifier indicator. |
|
572 * |
|
573 * @return Symbian error code (negative number) if operation fails, |
|
574 * otherwise handle to the native side object |
|
575 */ |
|
576 private static native int _initIndicator(); |
|
577 |
|
578 /** |
|
579 * Updates SifNotifier indicator. |
|
580 * |
|
581 * @param aHandle handle to indicator object |
|
582 * @param aName application name |
|
583 * @param aPhase operation phase |
|
584 * @param aProgress progress in percentage |
|
585 * @return Symbian error code (negative number) if operation fails, |
|
586 * otherwise handle to the native side object |
|
587 */ |
|
588 private static native int _updateIndicator( |
|
589 int aHandle, String aName, int aPhase, int aProgress); |
|
590 |
|
591 /** |
|
592 * Destroys SifNotifier indicator. |
|
593 * |
|
594 * @param aHandle handle to indicator object |
|
595 * @param aState indicator state |
|
596 * @return Symbian error code (negative number) if operation fails, |
|
597 * otherwise 0 |
|
598 */ |
|
599 private static native int _destroyIndicator(int aHandle, int aState); |
|
600 |
379 } |
601 } |