|
1 /* |
|
2 * Copyright (c) 2010 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: The JNI code for Java Installer component |
|
15 * SifNotifier. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "com_nokia_mj_impl_installer_applicationregistrator_SifNotifier.h" |
|
20 #include "javacommonutils.h" |
|
21 #include "javasymbianoslayer.h" // for CleanupResetAndDestroyPushL |
|
22 #include "logger.h" |
|
23 |
|
24 #if defined(SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK) && defined(RD_JAVA_USIF_NOTIFY_PROGRESS) |
|
25 |
|
26 #include <usif/sifnotification.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 } |
|
38 |
|
39 // NAMESPACE DECLARATION |
|
40 using namespace java; |
|
41 using namespace Usif; |
|
42 |
|
43 IMPORT_C HBufC* CreateHBufCFromJavaStringLC(JNIEnv* aEnv, jstring aString); |
|
44 |
|
45 |
|
46 /* |
|
47 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
|
48 * Method: _sifNotifierEnabled |
|
49 * Signature: ()Z |
|
50 */ |
|
51 JNIEXPORT jboolean JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1sifNotifierEnabled |
|
52 (JNIEnv *, jclass) |
|
53 { |
|
54 return ETrue; |
|
55 } |
|
56 |
|
57 /** |
|
58 * See JNI method __1notifyStart. |
|
59 * This method makes calls that may leave (the actual notifying). |
|
60 */ |
|
61 void NotifyStartL( |
|
62 JNIEnv *aEnv, CPublishSifOperationInfo *aNotifier, |
|
63 jstring aGlobalComponentId, jstring aComponentName, |
|
64 jobjectArray aApplicationNames, jint aComponentSize, |
|
65 jstring aComponentIconPath) |
|
66 { |
|
67 __UHEAP_MARK; |
|
68 HBufC *globalComponentId = CreateHBufCFromJavaStringLC(aEnv, aGlobalComponentId); |
|
69 HBufC *componentName = CreateHBufCFromJavaStringLC(aEnv, aComponentName); |
|
70 HBufC *componentIconPath = CreateHBufCFromJavaStringLC(aEnv, aComponentIconPath); |
|
71 |
|
72 RPointerArray<HBufC> applicationNames; |
|
73 CleanupResetAndDestroyPushL(applicationNames); |
|
74 RPointerArray<HBufC> applicationIcons; |
|
75 CleanupResetAndDestroyPushL(applicationIcons); |
|
76 |
|
77 TInt appsCount = aEnv->GetArrayLength(aApplicationNames); |
|
78 for (TInt i = 0; i < appsCount; i++) |
|
79 { |
|
80 HBufC *appName = CreateHBufCFromJavaStringLC( |
|
81 aEnv, (jstring)aEnv->GetObjectArrayElement(aApplicationNames, i)); |
|
82 applicationNames.AppendL(appName); |
|
83 CleanupStack::Pop(appName); |
|
84 } |
|
85 |
|
86 CSifOperationStartData *startData = CSifOperationStartData::NewLC( |
|
87 *globalComponentId, *componentName, applicationNames, applicationIcons, |
|
88 aComponentSize, /*aIconPath=*/ *componentIconPath, |
|
89 /*aComponentIcon=*/ KNullDesC(), Usif::KSoftwareTypeJava); |
|
90 |
|
91 User::LeaveIfError(aNotifier->PublishStart(*startData)); |
|
92 |
|
93 CleanupStack::PopAndDestroy(startData); |
|
94 |
|
95 CleanupStack::PopAndDestroy(&applicationIcons); |
|
96 CleanupStack::PopAndDestroy(&applicationNames); |
|
97 |
|
98 CleanupStack::PopAndDestroy(componentIconPath); |
|
99 CleanupStack::PopAndDestroy(componentName); |
|
100 CleanupStack::PopAndDestroy(globalComponentId); |
|
101 __UHEAP_MARKEND; |
|
102 } |
|
103 |
|
104 /* |
|
105 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
|
106 * Method: _notifyStart |
|
107 * Signature: (IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;I)I |
|
108 */ |
|
109 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1notifyStart |
|
110 (JNIEnv *aEnv, jclass, jint aHandle, jstring aGlobalComponentId, |
|
111 jstring aComponentName, jobjectArray aApplicationNames, jint aComponentSize, |
|
112 jstring aComponentIconPath) |
|
113 { |
|
114 CPublishSifOperationInfo *pNotifier = |
|
115 reinterpret_cast<CPublishSifOperationInfo*>(aHandle<<2); |
|
116 TRAPD(err, NotifyStartL(aEnv, pNotifier, aGlobalComponentId, aComponentName, |
|
117 aApplicationNames, aComponentSize, |
|
118 aComponentIconPath)); |
|
119 return err; |
|
120 } |
|
121 |
|
122 /** |
|
123 * See JNI method __1notifyEnd. |
|
124 * This method makes calls that may leave (the actual notifying). |
|
125 */ |
|
126 void NotifyEndL( |
|
127 JNIEnv *aEnv, CPublishSifOperationInfo *aNotifier, |
|
128 jstring aGlobalComponentId, jint aErrCategory, jint aErrCode, |
|
129 jstring aErrMsg, jstring aErrMsgDetails) |
|
130 { |
|
131 __UHEAP_MARK; |
|
132 HBufC *globalComponentId = CreateHBufCFromJavaStringLC(aEnv, aGlobalComponentId); |
|
133 HBufC *errMsg = NULL; |
|
134 if (NULL != aErrMsg) |
|
135 { |
|
136 errMsg = CreateHBufCFromJavaStringLC(aEnv, aErrMsg); |
|
137 } |
|
138 HBufC *errMsgDetails = NULL; |
|
139 if (NULL != aErrMsgDetails) |
|
140 { |
|
141 errMsgDetails = CreateHBufCFromJavaStringLC(aEnv, aErrMsgDetails); |
|
142 } |
|
143 |
|
144 CSifOperationEndData *endData = CSifOperationEndData::NewLC( |
|
145 *globalComponentId, (TErrorCategory)aErrCategory, aErrCode, |
|
146 *errMsg, *errMsgDetails); |
|
147 |
|
148 User::LeaveIfError(aNotifier->PublishCompletion(*endData)); |
|
149 |
|
150 CleanupStack::PopAndDestroy(endData); |
|
151 |
|
152 if (NULL != aErrMsg) |
|
153 { |
|
154 CleanupStack::PopAndDestroy(errMsg); |
|
155 } |
|
156 if (NULL != aErrMsgDetails) |
|
157 { |
|
158 CleanupStack::PopAndDestroy(errMsgDetails); |
|
159 } |
|
160 CleanupStack::PopAndDestroy(globalComponentId); |
|
161 __UHEAP_MARKEND; |
|
162 } |
|
163 |
|
164 /* |
|
165 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
|
166 * Method: _notifyEnd |
|
167 * Signature: (ILjava/lang/String;IILjava/lang/String;Ljava/lang/String;)I |
|
168 */ |
|
169 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1notifyEnd |
|
170 (JNIEnv *aEnv, jclass, jint aHandle, jstring aGlobalComponentId, |
|
171 jint aErrCategory, jint aErrCode, jstring aErrMsg, jstring aErrMsgDetails) |
|
172 { |
|
173 CPublishSifOperationInfo *pNotifier = |
|
174 reinterpret_cast<CPublishSifOperationInfo*>(aHandle<<2); |
|
175 TRAPD(err, NotifyEndL(aEnv, pNotifier, aGlobalComponentId, |
|
176 aErrCategory, aErrCode, aErrMsg, aErrMsgDetails)); |
|
177 return err; |
|
178 } |
|
179 |
|
180 /** |
|
181 * See JNI method __1notifyProgress. |
|
182 * This method makes calls that may leave (the actual notifying). |
|
183 */ |
|
184 void NotifyProgressL( |
|
185 JNIEnv *aEnv, CPublishSifOperationInfo *aNotifier, |
|
186 jstring aGlobalComponentId, jint aOperation, jint aSubOperation, |
|
187 jint aCurrent, jint aTotal) |
|
188 { |
|
189 __UHEAP_MARK; |
|
190 HBufC *globalComponentId = CreateHBufCFromJavaStringLC(aEnv, aGlobalComponentId); |
|
191 CSifOperationProgressData *progressData = CSifOperationProgressData::NewLC( |
|
192 *globalComponentId, (TSifOperationPhase)aOperation, |
|
193 (TSifOperationSubPhase)aSubOperation, aCurrent, aTotal); |
|
194 |
|
195 User::LeaveIfError(aNotifier->PublishProgress(*progressData)); |
|
196 |
|
197 CleanupStack::PopAndDestroy(progressData); |
|
198 CleanupStack::PopAndDestroy(globalComponentId); |
|
199 __UHEAP_MARKEND; |
|
200 } |
|
201 |
|
202 /* |
|
203 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
|
204 * Method: _notifyProgress |
|
205 * Signature: (ILjava/lang/String;IIII)I |
|
206 */ |
|
207 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1notifyProgress |
|
208 (JNIEnv *aEnv, jclass, jint aHandle, jstring aGlobalComponentId, |
|
209 jint aOperation, jint aSubOperation, jint aCurrent, jint aTotal) |
|
210 { |
|
211 CPublishSifOperationInfo *pNotifier = |
|
212 reinterpret_cast<CPublishSifOperationInfo*>(aHandle<<2); |
|
213 TRAPD(err, NotifyProgressL(aEnv, pNotifier, aGlobalComponentId, |
|
214 aOperation, aSubOperation, aCurrent, aTotal)); |
|
215 return err; |
|
216 } |
|
217 |
|
218 /* |
|
219 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
|
220 * Method: _init |
|
221 * Signature: ()I |
|
222 */ |
|
223 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1init |
|
224 (JNIEnv *, jclass) |
|
225 { |
|
226 CPublishSifOperationInfo *pNotifier = NULL; |
|
227 TRAPD(err, pNotifier = CPublishSifOperationInfo::NewL()); |
|
228 if (KErrNone != err) |
|
229 { |
|
230 ELOG1(EJavaInstaller, |
|
231 "SifNotifier.init: Creating CPublishSifOperationInfo failed, error %d", |
|
232 err); |
|
233 return err; |
|
234 } |
|
235 // Return handle to the object. Utilize the fact that in Symbian |
|
236 // all pointer addresses are MOD 4 so the last 2 bits are 0 |
|
237 // and can be shifted out. This way the returned handle is |
|
238 // always positive whereas Symbian error codes are always negative. |
|
239 return reinterpret_cast<TUint>(pNotifier)>>2; |
|
240 } |
|
241 |
|
242 /* |
|
243 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
|
244 * Method: _destroy |
|
245 * Signature: (I)I |
|
246 */ |
|
247 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1destroy |
|
248 (JNIEnv *, jclass, jint aHandle) |
|
249 { |
|
250 CPublishSifOperationInfo *pNotifier = |
|
251 reinterpret_cast<CPublishSifOperationInfo*>(aHandle<<2); |
|
252 delete pNotifier; |
|
253 return KErrNone; |
|
254 } |
|
255 |
|
256 #else // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK && RD_JAVA_USIF_NOTIFY_PROGRESS |
|
257 |
|
258 /* |
|
259 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
|
260 * Method: _sifNotifierEnabled |
|
261 * Signature: ()Z |
|
262 */ |
|
263 JNIEXPORT jboolean JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1sifNotifierEnabled |
|
264 (JNIEnv *, jclass) |
|
265 { |
|
266 return EFalse; |
|
267 } |
|
268 |
|
269 /* |
|
270 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
|
271 * Method: _notifyStart |
|
272 * Signature: (IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;I)I |
|
273 */ |
|
274 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1notifyStart |
|
275 (JNIEnv *, jclass, jint, jstring, jstring, jobjectArray, jint, jstring) |
|
276 { |
|
277 LOG(EJavaInstaller, EInfo, "SifNotifier.notifyStart"); |
|
278 return KErrNone; |
|
279 } |
|
280 |
|
281 /* |
|
282 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
|
283 * Method: _notifyEnd |
|
284 * Signature: (ILjava/lang/String;IILjava/lang/String;Ljava/lang/String;)I |
|
285 */ |
|
286 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1notifyEnd |
|
287 (JNIEnv *, jclass, jint, jstring, jint aErrCategory, jint aErrCode, jstring, jstring) |
|
288 { |
|
289 LOG2(EJavaInstaller, EInfo, |
|
290 "SifNotifier.notifyEnd: errCategory=%d, errCode=%d", |
|
291 aErrCategory, aErrCode); |
|
292 return KErrNone; |
|
293 } |
|
294 |
|
295 /* |
|
296 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
|
297 * Method: _notifyProgress |
|
298 * Signature: (ILjava/lang/String;IIII)I |
|
299 */ |
|
300 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1notifyProgress |
|
301 (JNIEnv *, jclass, jint, jstring, |
|
302 jint aOperation, jint aSubOperation, jint aCurrent, jint aTotal) |
|
303 { |
|
304 LOG4(EJavaInstaller, EInfo, |
|
305 "SifNotifier.notifyProgress: op=%d, subop=%d, current=%d, total=%d", |
|
306 aOperation, aSubOperation, aCurrent, aTotal); |
|
307 return KErrNone; |
|
308 } |
|
309 |
|
310 /* |
|
311 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
|
312 * Method: _init |
|
313 * Signature: ()I |
|
314 */ |
|
315 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1init |
|
316 (JNIEnv *, jclass) |
|
317 { |
|
318 LOG(EJavaInstaller, EInfo, "SifNotifier.init"); |
|
319 return 1; // return dummy object handle |
|
320 } |
|
321 |
|
322 /* |
|
323 * Class: com_nokia_mj_impl_installer_applicationregistrator_SifNotifier |
|
324 * Method: _destroy |
|
325 * Signature: (I)I |
|
326 */ |
|
327 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_applicationregistrator_SifNotifier__1destroy |
|
328 (JNIEnv *, jclass, jint) |
|
329 { |
|
330 LOG(EJavaInstaller, EInfo, "SifNotifier.destroy"); |
|
331 return KErrNone; |
|
332 } |
|
333 |
|
334 #endif // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK && RD_JAVA_USIF_NOTIFY_PROGRESS |