19 #include "com_nokia_mj_impl_installer_applicationregistrator_SifNotifier.h" |
19 #include "com_nokia_mj_impl_installer_applicationregistrator_SifNotifier.h" |
20 #include "javacommonutils.h" |
20 #include "javacommonutils.h" |
21 #include "javasymbianoslayer.h" // for CleanupResetAndDestroyPushL |
21 #include "javasymbianoslayer.h" // for CleanupResetAndDestroyPushL |
22 #include "logger.h" |
22 #include "logger.h" |
23 |
23 |
24 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK |
24 #if defined(SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK) && defined(RD_JAVA_USIF_NOTIFY_PROGRESS) |
25 |
25 |
26 #include <hb/hbcore/hbindicatorsymbian.h> |
|
27 #include <hb/hbcore/hbsymbianvariant.h> |
|
28 #include <sifuiinstallindicatordefinitions.h> |
|
29 #include <usif/sif/sifnotification.h> |
26 #include <usif/sif/sifnotification.h> |
30 #include <usif/usifcommon.h> |
27 #include <usif/usifcommon.h> |
|
28 |
|
29 // Helper macro for logging a TDesC. |
|
30 #define LOG_TDESC_L(compIdParam, logLevelParam, msgParam, tdescParam) \ |
|
31 { \ |
|
32 HBufC8* tdescBuf = HBufC8::NewLC(tdescParam.Length() + 1); \ |
|
33 TPtr8 tdescPtr(tdescBuf->Des()); \ |
|
34 tdescPtr.Append(tdescParam); \ |
|
35 LOG1(compIdParam, logLevelParam, msgParam, tdescPtr.PtrZ());\ |
|
36 CleanupStack::PopAndDestroy(tdescBuf); \ |
|
37 } |
31 |
38 |
32 // NAMESPACE DECLARATION |
39 // NAMESPACE DECLARATION |
33 using namespace java; |
40 using namespace java; |
34 using namespace Usif; |
41 using namespace Usif; |
35 |
42 |
52 /** |
59 /** |
53 * See JNI method __1notifyStart. |
60 * See JNI method __1notifyStart. |
54 * This method makes calls that may leave (the actual notifying). |
61 * This method makes calls that may leave (the actual notifying). |
55 */ |
62 */ |
56 void NotifyStartL( |
63 void NotifyStartL( |
57 JNIEnv *aEnv, CPublishSifOperationInfo *aNotifier, jint aOperation, |
64 JNIEnv *aEnv, CPublishSifOperationInfo *aNotifier, |
58 jstring aGlobalComponentId, jstring aComponentName, |
65 jstring aGlobalComponentId, jstring aComponentName, |
59 jobjectArray aApplicationNames, jobjectArray aApplicationIcons, |
66 jobjectArray aApplicationNames, jobjectArray aApplicationIcons, |
60 jint aComponentSize, jstring aIconDir, jstring /*aComponentIcon*/) |
67 jint aComponentSize, jstring aIconDir, jstring /*aComponentIcon*/) |
61 { |
68 { |
62 __UHEAP_MARK; |
69 __UHEAP_MARK; |
107 |
113 |
108 CSifOperationStartData *startData = |
114 CSifOperationStartData *startData = |
109 CSifOperationStartData::NewLC( |
115 CSifOperationStartData::NewLC( |
110 *globalComponentId, *componentName, applicationNames, applicationIcons, |
116 *globalComponentId, *componentName, applicationNames, applicationIcons, |
111 aComponentSize, /*aIconPath=*/ (NULL != aIconDir? *iconDir: KNullDesC()), |
117 aComponentSize, /*aIconPath=*/ (NULL != aIconDir? *iconDir: KNullDesC()), |
112 /*aComponentIcon=*/ KNullDesC(), Usif::KSoftwareTypeJava, |
118 /*aComponentIcon=*/ KNullDesC(), Usif::KSoftwareTypeJava); |
113 (TSifOperationPhase)aOperation); |
|
114 |
119 |
115 aNotifier->PublishStartL(*startData); |
120 aNotifier->PublishStartL(*startData); |
116 |
121 |
117 CleanupStack::PopAndDestroy(startData); |
122 CleanupStack::PopAndDestroy(startData); |
118 |
123 |
132 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
137 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
133 * Method: _notifyStart |
138 * Method: _notifyStart |
134 * Signature: (IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;I)I |
139 * Signature: (IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;I)I |
135 */ |
140 */ |
136 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1notifyStart |
141 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1notifyStart |
137 (JNIEnv *aEnv, jclass, jint aHandle, jint aOperation, |
142 (JNIEnv *aEnv, jclass, jint aHandle, jstring aGlobalComponentId, |
138 jstring aGlobalComponentId, jstring aComponentName, |
143 jstring aComponentName, jobjectArray aApplicationNames, |
139 jobjectArray aApplicationNames, jobjectArray aApplicationIcons, |
144 jobjectArray aApplicationIcons, jint aComponentSize, |
140 jint aComponentSize, jstring aIconDir, jstring aComponentIcon) |
145 jstring aIconDir, jstring aComponentIcon) |
141 { |
146 { |
142 CPublishSifOperationInfo *pNotifier = |
147 CPublishSifOperationInfo *pNotifier = |
143 reinterpret_cast<CPublishSifOperationInfo*>(aHandle<<2); |
148 reinterpret_cast<CPublishSifOperationInfo*>(aHandle<<2); |
144 TRAPD(err, NotifyStartL(aEnv, pNotifier, aOperation, aGlobalComponentId, |
149 TRAPD(err, NotifyStartL(aEnv, pNotifier, aGlobalComponentId, aComponentName, |
145 aComponentName, aApplicationNames, |
150 aApplicationNames, aApplicationIcons, |
146 aApplicationIcons, aComponentSize, |
151 aComponentSize, aIconDir, aComponentIcon)); |
147 aIconDir, aComponentIcon)); |
|
148 return err; |
152 return err; |
149 } |
153 } |
150 |
154 |
151 /** |
155 /** |
152 * See JNI method __1notifyEnd. |
156 * See JNI method __1notifyEnd. |
155 void NotifyEndL( |
159 void NotifyEndL( |
156 JNIEnv *aEnv, CPublishSifOperationInfo *aNotifier, |
160 JNIEnv *aEnv, CPublishSifOperationInfo *aNotifier, |
157 jstring aGlobalComponentId, jint aErrCategory, jint aErrCode, |
161 jstring aGlobalComponentId, jint aErrCategory, jint aErrCode, |
158 jstring aErrMsg, jstring aErrMsgDetails) |
162 jstring aErrMsg, jstring aErrMsgDetails) |
159 { |
163 { |
160 //__UHEAP_MARK; |
164 __UHEAP_MARK; |
161 HBufC *globalComponentId = CreateHBufCFromJavaStringLC(aEnv, aGlobalComponentId); |
165 HBufC *globalComponentId = CreateHBufCFromJavaStringLC(aEnv, aGlobalComponentId); |
162 HBufC *errMsg = NULL; |
166 HBufC *errMsg = NULL; |
163 if (NULL != aErrMsg) |
167 if (NULL != aErrMsg) |
164 { |
168 { |
165 errMsg = CreateHBufCFromJavaStringLC(aEnv, aErrMsg); |
169 errMsg = CreateHBufCFromJavaStringLC(aEnv, aErrMsg); |
168 if (NULL != aErrMsgDetails) |
172 if (NULL != aErrMsgDetails) |
169 { |
173 { |
170 errMsgDetails = CreateHBufCFromJavaStringLC(aEnv, aErrMsgDetails); |
174 errMsgDetails = CreateHBufCFromJavaStringLC(aEnv, aErrMsgDetails); |
171 } |
175 } |
172 |
176 |
173 CSifOperationEndData *endData = |
177 CSifOperationEndData *endData = CSifOperationEndData::NewLC( |
174 CSifOperationEndData::NewLC( |
178 *globalComponentId, (TErrorCategory)aErrCategory, aErrCode, |
175 *globalComponentId, (TErrorCategory)aErrCategory, aErrCode, |
179 *errMsg, *errMsgDetails); |
176 (NULL != errMsg? *errMsg: KNullDesC()), |
180 |
177 (NULL != errMsgDetails? *errMsgDetails: KNullDesC())); |
|
178 |
|
179 // Do not use UHEAP macros around PublishCompletionL() because it |
|
180 // creates a timer object which gets deleted only when the notifier |
|
181 // object is deleted. |
|
182 aNotifier->PublishCompletionL(*endData); |
181 aNotifier->PublishCompletionL(*endData); |
183 |
182 |
184 CleanupStack::PopAndDestroy(endData); |
183 CleanupStack::PopAndDestroy(endData); |
185 |
184 |
186 if (NULL != errMsgDetails) |
185 if (NULL != aErrMsg) |
|
186 { |
|
187 CleanupStack::PopAndDestroy(errMsg); |
|
188 } |
|
189 if (NULL != aErrMsgDetails) |
187 { |
190 { |
188 CleanupStack::PopAndDestroy(errMsgDetails); |
191 CleanupStack::PopAndDestroy(errMsgDetails); |
189 } |
192 } |
190 if (NULL != errMsg) |
|
191 { |
|
192 CleanupStack::PopAndDestroy(errMsg); |
|
193 } |
|
194 CleanupStack::PopAndDestroy(globalComponentId); |
193 CleanupStack::PopAndDestroy(globalComponentId); |
195 //__UHEAP_MARKEND; |
194 __UHEAP_MARKEND; |
196 } |
195 } |
197 |
196 |
198 /* |
197 /* |
199 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
198 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
200 * Method: _notifyEnd |
199 * Method: _notifyEnd |
202 */ |
201 */ |
203 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1notifyEnd |
202 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1notifyEnd |
204 (JNIEnv *aEnv, jclass, jint aHandle, jstring aGlobalComponentId, |
203 (JNIEnv *aEnv, jclass, jint aHandle, jstring aGlobalComponentId, |
205 jint aErrCategory, jint aErrCode, jstring aErrMsg, jstring aErrMsgDetails) |
204 jint aErrCategory, jint aErrCode, jstring aErrMsg, jstring aErrMsgDetails) |
206 { |
205 { |
207 CActiveScheduler* newScheduler = 0; |
|
208 if (0 == CActiveScheduler::Current()) |
|
209 { |
|
210 // Create ActiveScheduler as it does not yet exist. |
|
211 newScheduler = new CActiveScheduler; |
|
212 CActiveScheduler::Install(newScheduler); |
|
213 } |
|
214 |
|
215 CPublishSifOperationInfo *pNotifier = |
206 CPublishSifOperationInfo *pNotifier = |
216 reinterpret_cast<CPublishSifOperationInfo*>(aHandle<<2); |
207 reinterpret_cast<CPublishSifOperationInfo*>(aHandle<<2); |
217 TRAPD(err, NotifyEndL(aEnv, pNotifier, aGlobalComponentId, |
208 TRAPD(err, NotifyEndL(aEnv, pNotifier, aGlobalComponentId, |
218 aErrCategory, aErrCode, aErrMsg, aErrMsgDetails)); |
209 aErrCategory, aErrCode, aErrMsg, aErrMsgDetails)); |
219 |
|
220 if (newScheduler) |
|
221 { |
|
222 delete newScheduler; |
|
223 newScheduler = 0; |
|
224 } |
|
225 |
|
226 return err; |
210 return err; |
227 } |
211 } |
228 |
212 |
229 /** |
213 /** |
230 * See JNI method __1notifyProgress. |
214 * See JNI method __1notifyProgress. |
300 reinterpret_cast<CPublishSifOperationInfo*>(aHandle<<2); |
284 reinterpret_cast<CPublishSifOperationInfo*>(aHandle<<2); |
301 delete pNotifier; |
285 delete pNotifier; |
302 return KErrNone; |
286 return KErrNone; |
303 } |
287 } |
304 |
288 |
305 /* |
289 #else // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK && RD_JAVA_USIF_NOTIFY_PROGRESS |
306 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
|
307 * Method: _initIndicator |
|
308 * Signature: ()I |
|
309 */ |
|
310 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1initIndicator |
|
311 (JNIEnv *, jclass) |
|
312 { |
|
313 CHbIndicatorSymbian *pIndicator = NULL; |
|
314 TRAPD(err, pIndicator = CHbIndicatorSymbian::NewL()); |
|
315 if (KErrNone != err) |
|
316 { |
|
317 ELOG1(EJavaInstaller, |
|
318 "SifNotifier.initIndicator: Creating indicator failed, error %d", |
|
319 err); |
|
320 return err; |
|
321 } |
|
322 // Return handle to the object. Utilize the fact that in Symbian |
|
323 // all pointer addresses are MOD 4 so the last 2 bits are 0 |
|
324 // and can be shifted out. This way the returned handle is |
|
325 // always positive whereas Symbian error codes are always negative. |
|
326 return reinterpret_cast<TUint>(pIndicator)>>2; |
|
327 } |
|
328 |
|
329 /** |
|
330 * See JNI method __1updateIndicator. |
|
331 * This method makes calls that may leave (the actual notifying). |
|
332 */ |
|
333 void UpdateIndicatorL( |
|
334 JNIEnv *aEnv, CHbIndicatorSymbian *pIndicator, jstring aName, jint aPhase, jint aProgress) |
|
335 { |
|
336 HBufC *name = CreateHBufCFromJavaStringLC(aEnv, aName); |
|
337 |
|
338 CHbSymbianVariantMap *variantMap = CHbSymbianVariantMap::NewL(); |
|
339 CleanupStack::PushL(variantMap); |
|
340 CHbSymbianVariant *variantName = CHbSymbianVariant::NewL(name, CHbSymbianVariant::EDes); |
|
341 variantMap->Add(KSifUiInstallIndicatorAppName, variantName); |
|
342 CHbSymbianVariant *variantPhase = CHbSymbianVariant::NewL(&aPhase, CHbSymbianVariant::EInt); |
|
343 variantMap->Add(KSifUiInstallIndicatorPhase, variantPhase); |
|
344 CHbSymbianVariant *variantProgress = CHbSymbianVariant::NewL(&aProgress, CHbSymbianVariant::EInt); |
|
345 variantMap->Add(KSifUiInstallIndicatorProgress, variantProgress); |
|
346 |
|
347 CHbSymbianVariant *variant = CHbSymbianVariant::NewL(variantMap, CHbSymbianVariant::EVariantMap); |
|
348 CleanupStack::PushL(variant); |
|
349 |
|
350 TInt err = KErrNone; |
|
351 if (!pIndicator->Activate(KSifUiInstallIndicatorType, variant)) |
|
352 { |
|
353 err = pIndicator->Error(); |
|
354 ELOG1(EJavaInstaller, |
|
355 "SifNotifier.updateIndicator: activating indicator failed, error %d", |
|
356 err); |
|
357 err = KErrGeneral; |
|
358 } |
|
359 |
|
360 CleanupStack::PopAndDestroy(variant); |
|
361 CleanupStack::PopAndDestroy(variantMap); |
|
362 CleanupStack::PopAndDestroy(name); |
|
363 } |
|
364 |
|
365 /* |
|
366 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
|
367 * Method: _updateIndicator |
|
368 * Signature: ()I |
|
369 */ |
|
370 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1updateIndicator |
|
371 (JNIEnv *aEnv, jclass, jint aHandle, jstring aName, jint aPhase, jint aProgress) |
|
372 { |
|
373 CHbIndicatorSymbian *pIndicator = |
|
374 reinterpret_cast<CHbIndicatorSymbian*>(aHandle<<2); |
|
375 TRAPD(err, UpdateIndicatorL(aEnv, pIndicator, aName, aPhase, aProgress)); |
|
376 return err; |
|
377 } |
|
378 |
|
379 /* |
|
380 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
|
381 * Method: _destroyIndicator |
|
382 * Signature: (II)I |
|
383 */ |
|
384 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1destroyIndicator |
|
385 (JNIEnv *, jclass, jint aHandle, jint aState) |
|
386 { |
|
387 CHbIndicatorSymbian *pIndicator = |
|
388 reinterpret_cast<CHbIndicatorSymbian*>(aHandle<<2); |
|
389 TInt err = KErrNone; |
|
390 if (aState && !pIndicator->Deactivate(KSifUiInstallIndicatorType)) |
|
391 { |
|
392 err = pIndicator->Error(); |
|
393 ELOG1(EJavaInstaller, |
|
394 "SifNotifier.destroyIndicator: Deactivating indicator failed, error %d", |
|
395 err); |
|
396 err = KErrGeneral; |
|
397 } |
|
398 delete pIndicator; |
|
399 return err; |
|
400 } |
|
401 |
|
402 #else // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK |
|
403 |
290 |
404 /* |
291 /* |
405 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
292 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
406 * Method: _sifNotifierEnabled |
293 * Method: _sifNotifierEnabled |
407 * Signature: ()Z |
294 * Signature: ()Z |
416 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
303 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
417 * Method: _notifyStart |
304 * Method: _notifyStart |
418 * Signature: (IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;I)I |
305 * Signature: (IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;I)I |
419 */ |
306 */ |
420 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1notifyStart |
307 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1notifyStart |
421 (JNIEnv *, jclass, jint, jint, jstring, jstring, jobjectArray, jobjectArray, jint, jstring, jstring) |
308 (JNIEnv *, jclass, jint, jstring, jstring, jobjectArray, jobjectArray, jint, jstring, jstring) |
422 { |
309 { |
423 LOG(EJavaInstaller, EInfo, "SifNotifier.notifyStart"); |
310 LOG(EJavaInstaller, EInfo, "SifNotifier.notifyStart"); |
424 return KErrNone; |
311 return KErrNone; |
425 } |
312 } |
426 |
313 |
481 { |
368 { |
482 LOG(EJavaInstaller, EInfo, "SifNotifier.destroy"); |
369 LOG(EJavaInstaller, EInfo, "SifNotifier.destroy"); |
483 return KErrNone; |
370 return KErrNone; |
484 } |
371 } |
485 |
372 |
486 /* |
373 #endif // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK && RD_JAVA_USIF_NOTIFY_PROGRESS |
487 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
|
488 * Method: _initIndicator |
|
489 * Signature: ()I |
|
490 */ |
|
491 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1initIndicator |
|
492 (JNIEnv *, jclass) |
|
493 { |
|
494 LOG(EJavaInstaller, EInfo, "SifNotifier.initIndicator"); |
|
495 return 1; // return dummy object handle |
|
496 } |
|
497 |
|
498 /* |
|
499 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
|
500 * Method: _updateIndicator |
|
501 * Signature: ()I |
|
502 */ |
|
503 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1updateIndicator |
|
504 (JNIEnv *, jclass, jint, jstring, jint, jint) |
|
505 { |
|
506 LOG(EJavaInstaller, EInfo, "SifNotifier.updateIndicator"); |
|
507 return KErrNone; |
|
508 } |
|
509 |
|
510 /* |
|
511 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
|
512 * Method: _destroyIndicator |
|
513 * Signature: (II)I |
|
514 */ |
|
515 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1destroyIndicator |
|
516 (JNIEnv *, jclass, jint, jint) |
|
517 { |
|
518 LOG(EJavaInstaller, EInfo, "SifNotifier.destroyIndicator"); |
|
519 return KErrNone; |
|
520 } |
|
521 |
|
522 #endif // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK |
|