39 public static final int SUB_OP_NO = 1; |
39 public static final int SUB_OP_NO = 1; |
40 /** OCSP phase during installation. */ |
40 /** OCSP phase during installation. */ |
41 public static final int SUB_OP_OCSP = 2; |
41 public static final int SUB_OP_OCSP = 2; |
42 /** Download phase during installation. */ |
42 /** Download phase during installation. */ |
43 public static final int SUB_OP_DOWNLOAD = 3; |
43 public static final int SUB_OP_DOWNLOAD = 3; |
|
44 /** Maximum progress notification value. */ |
|
45 private static final int MAX_PROGRESS = 100; |
44 |
46 |
45 /** Operation being notified. */ |
47 /** Operation being notified. */ |
46 private int iOperation = 0; |
48 private int iOperation = 0; |
47 /** Global component id for the application. */ |
49 /** Global component id for the application. */ |
48 private String iGlobalComponentId = null; |
50 private String iGlobalComponentId = null; |
60 private String iComponentIcon = null; |
62 private String iComponentIcon = null; |
61 |
63 |
62 /** Sending progress notifications is only allowed between start |
64 /** Sending progress notifications is only allowed between start |
63 * and end notifications. */ |
65 * and end notifications. */ |
64 private boolean iNotifyProgressAllowed = false; |
66 private boolean iNotifyProgressAllowed = false; |
|
67 /** Value of the last progress notification that has been sent. */ |
|
68 private int iLastProgressSent = 0; |
65 |
69 |
66 /** Native object handle. */ |
70 /** Native object handle. */ |
67 private int iHandle = 0; |
71 private int iHandle = 0; |
68 |
72 |
69 /*** ----------------------------- PUBLIC ------------------------------ */ |
73 /*** ----------------------------- PUBLIC ------------------------------ */ |
101 iApplicationIcons = aApplicationIcons; |
105 iApplicationIcons = aApplicationIcons; |
102 iComponentSize = aComponentSize; |
106 iComponentSize = aComponentSize; |
103 iIconDir = aIconDir; |
107 iIconDir = aIconDir; |
104 iComponentIcon = aComponentIcon; |
108 iComponentIcon = aComponentIcon; |
105 |
109 |
106 if (iHandle == 0) |
110 checkHandle(); |
107 { |
|
108 InstallerException.internalError( |
|
109 "SifNotifier.notifyStart: notifier has not been initialized"); |
|
110 } |
|
111 int ret = _notifyStart( |
111 int ret = _notifyStart( |
112 iHandle, aGlobalComponentId, aComponentName, |
112 iHandle, aGlobalComponentId, aComponentName, |
113 aApplicationNames, aApplicationIcons, |
113 aApplicationNames, aApplicationIcons, |
114 aComponentSize, aIconDir, aComponentIcon); |
114 aComponentSize, aIconDir, aComponentIcon); |
115 if (ret < 0) |
115 if (ret < 0) |
116 { |
116 { |
117 Log.logError("Notifying SIF start failed with code " + ret + |
117 Log.log("Notifying SIF start failed with code " + ret + |
118 ", " + getInfoString()); |
118 ", " + getInfoString()); |
119 InstallerException.internalError( |
119 InstallerException.internalError( |
120 "Notifying SIF start failed with code " + ret); |
120 "Notifying SIF start failed with code " + ret); |
|
121 } |
|
122 else |
|
123 { |
|
124 Log.log("SifNotifier.notifyStart: " + getInfoString()); |
121 } |
125 } |
122 iNotifyProgressAllowed = true; |
126 iNotifyProgressAllowed = true; |
123 } |
127 } |
124 |
128 |
125 /** |
129 /** |
128 * @throws InstallerException in case an error occurs |
132 * @throws InstallerException in case an error occurs |
129 */ |
133 */ |
130 public void notifyEnd( |
134 public void notifyEnd( |
131 int aErrCategory, int aErrCode, String aErrMsg, String aErrMsgDetails) |
135 int aErrCategory, int aErrCode, String aErrMsg, String aErrMsgDetails) |
132 { |
136 { |
133 if (iHandle == 0) |
137 checkHandle(); |
134 { |
138 if (aErrCategory == 0 && iLastProgressSent < MAX_PROGRESS) |
135 InstallerException.internalError( |
139 { |
136 "SifNotifier.notifyEnd: notifier has not been initialized"); |
140 // Before sending end notification, update progress to max if |
137 } |
141 // operation was successful and max progress notification has |
|
142 // not yet been sent. |
|
143 notifyProgress(SUB_OP_NO, MAX_PROGRESS, MAX_PROGRESS); |
|
144 } |
|
145 // No more progress notifications allowed. |
138 iNotifyProgressAllowed = false; |
146 iNotifyProgressAllowed = false; |
139 int ret = _notifyEnd( |
147 int ret = _notifyEnd( |
140 iHandle, iGlobalComponentId, aErrCategory, aErrCode, |
148 iHandle, iGlobalComponentId, aErrCategory, aErrCode, |
141 aErrMsg, aErrMsgDetails); |
149 aErrMsg, aErrMsgDetails); |
142 if (ret < 0) |
150 String logMsg = |
143 { |
151 "ErrCategory: " + aErrCategory + |
144 Log.logError("Notifying SIF end failed with code " + ret + |
152 ", ErrCode: " + aErrCode + |
145 ", " + getInfoString() + |
153 ", ErrMsg: " + aErrMsg + |
146 ", ErrCategory: " + aErrCategory + |
154 ", ErrMsgDetails: " + aErrMsgDetails; |
147 ", ErrCode: " + aErrCode + |
155 if (ret < 0) |
148 ", ErrMsg: " + aErrMsg + |
156 { |
149 ", ErrMsgDetails: " + aErrMsgDetails); |
157 Log.log("Notifying SIF end failed with code " + ret + |
|
158 ", " + getInfoString() + ", " + logMsg); |
150 InstallerException.internalError( |
159 InstallerException.internalError( |
151 "Notifying SIF end failed with code " + ret); |
160 "Notifying SIF end failed with code " + ret); |
152 } |
161 } |
|
162 else |
|
163 { |
|
164 Log.log("SifNotifier.notifyEnd: " + logMsg); |
|
165 } |
153 } |
166 } |
154 |
167 |
155 /** |
168 /** |
156 * Notifies SIF about installation or uninstallation progress. |
169 * Notifies SIF about installation or uninstallation progress. |
157 * |
170 * |
161 { |
174 { |
162 if (!iNotifyProgressAllowed) |
175 if (!iNotifyProgressAllowed) |
163 { |
176 { |
164 return; |
177 return; |
165 } |
178 } |
166 if (iHandle == 0) |
179 checkHandle(); |
167 { |
180 if (aSubOperation == SUB_OP_NO) |
168 InstallerException.internalError( |
181 { |
169 "SifNotifier.notifyProgress: notifier has not been initialized"); |
182 iLastProgressSent = aCurrent; |
170 } |
183 } |
171 int ret = _notifyProgress( |
184 int ret = _notifyProgress( |
172 iHandle, iGlobalComponentId, iOperation, aSubOperation, |
185 iHandle, iGlobalComponentId, iOperation, aSubOperation, |
173 aCurrent, aTotal); |
186 aCurrent, aTotal); |
174 if (ret < 0) |
187 String logMsg = |
175 { |
188 "SubOp: " + aSubOperation + |
176 Log.logError("Notifying SIF progress failed with code " + ret + |
189 ", Current: " + aCurrent + |
177 ", " + getInfoString() + |
190 ", Total: " + aTotal; |
178 ", SubOp: " + aSubOperation + |
191 if (ret < 0) |
179 ", Current: " + aCurrent + |
192 { |
180 ", Total: " + aTotal); |
193 Log.log("Notifying SIF progress failed with code " + ret + |
|
194 ", " + getInfoString() + ", " + logMsg); |
181 InstallerException.internalError( |
195 InstallerException.internalError( |
182 "Notifying SIF progress failed with code " + ret); |
196 "Notifying SIF progress failed with code " + ret); |
|
197 } |
|
198 else |
|
199 { |
|
200 Log.log("SifNotifier.notifyProgress: " + logMsg); |
183 } |
201 } |
184 } |
202 } |
185 |
203 |
186 /** |
204 /** |
187 * Destroys SifNotifier. This method releawse native resources and |
205 * Destroys SifNotifier. This method releawse native resources and |
189 * |
207 * |
190 * @throws InstallerException in case an error occurs |
208 * @throws InstallerException in case an error occurs |
191 */ |
209 */ |
192 public void destroy() |
210 public void destroy() |
193 { |
211 { |
194 if (iHandle == 0) |
212 checkHandle(); |
195 { |
|
196 InstallerException.internalError( |
|
197 "SifNotifier.destroy: notifier has not been initialized"); |
|
198 } |
|
199 int ret = _destroy(iHandle); |
213 int ret = _destroy(iHandle); |
200 if (ret < 0) |
214 if (ret < 0) |
201 { |
215 { |
202 InstallerException.internalError( |
216 InstallerException.internalError( |
203 "Destroying SIF notifier failed with code " + ret); |
217 "Destroying SIF notifier failed with code " + ret); |
|
218 } |
|
219 else |
|
220 { |
|
221 Log.log("SifNotifier destroyed"); |
204 } |
222 } |
205 iHandle = 0; |
223 iHandle = 0; |
206 } |
224 } |
207 |
225 |
208 /*** ----------------------------- PACKAGE ---------------------------- */ |
226 /*** ----------------------------- PACKAGE ---------------------------- */ |
219 if (ret < 0) |
237 if (ret < 0) |
220 { |
238 { |
221 InstallerException.internalError( |
239 InstallerException.internalError( |
222 "Initializing SifNotifier failed with code " + ret); |
240 "Initializing SifNotifier failed with code " + ret); |
223 } |
241 } |
|
242 else |
|
243 { |
|
244 Log.log("SifNotifier created"); |
|
245 } |
224 iHandle = ret; |
246 iHandle = ret; |
225 } |
247 } |
226 |
248 |
227 /*** ----------------------------- PRIVATE ---------------------------- */ |
249 /*** ----------------------------- PRIVATE ---------------------------- */ |
|
250 |
|
251 /** |
|
252 * Checks if notifier instance has been initialized. |
|
253 * @throws InstallerException if notifier has not been initialized |
|
254 */ |
|
255 private void checkHandle() |
|
256 { |
|
257 if (iHandle == 0) |
|
258 { |
|
259 InstallerException.internalError( |
|
260 "SifNotifier.destroy: notifier has not been initialized"); |
|
261 } |
|
262 } |
228 |
263 |
229 /** |
264 /** |
230 * Returns notification info string used in logging. |
265 * Returns notification info string used in logging. |
231 */ |
266 */ |
232 private String getInfoString() |
267 private String getInfoString() |
233 { |
268 { |
234 StringBuffer buf = new StringBuffer(); |
269 StringBuffer buf = new StringBuffer(); |
235 buf.append("Operation: ").append(iOperation); |
270 buf.append("Operation: ").append(iOperation); |
236 buf.append(", GlobalComponentId: ").append(iGlobalComponentId); |
271 buf.append(", GlobalComponentId: ").append(iGlobalComponentId); |
237 buf.append(", ComponentName: ").append(iComponentName); |
272 buf.append(", ComponentName: ").append(iComponentName); |
238 for (int i = 0; i < iApplicationNames.length; i++) |
273 if (iApplicationNames != null) |
239 { |
274 { |
240 buf.append(", ApplicationName: ").append(iApplicationNames[i]); |
275 for (int i = 0; i < iApplicationNames.length; i++) |
|
276 { |
|
277 buf.append(", ApplicationName[").append(i).append("]: ") |
|
278 .append(iApplicationNames[i]); |
|
279 } |
|
280 } |
|
281 if (iApplicationIcons != null) |
|
282 { |
|
283 for (int i = 0; i < iApplicationIcons.length; i++) |
|
284 { |
|
285 buf.append(", ApplicationIcon[").append(i).append("]: ") |
|
286 .append(iApplicationIcons[i]); |
|
287 } |
241 } |
288 } |
242 buf.append(", ComponentSize: ").append(iComponentSize); |
289 buf.append(", ComponentSize: ").append(iComponentSize); |
|
290 if (iIconDir != null) |
|
291 { |
|
292 buf.append(", IconDir: ").append(iIconDir); |
|
293 } |
|
294 if (iComponentIcon != null) |
|
295 { |
|
296 buf.append(", ComponentIcon: ").append(iComponentIcon); |
|
297 } |
243 return buf.toString(); |
298 return buf.toString(); |
244 } |
299 } |
245 |
300 |
246 /*** ----------------------------- NATIVE ----------------------------- */ |
301 /*** ----------------------------- NATIVE ----------------------------- */ |
247 |
302 |