|
1 /* |
|
2 * Copyright (c) 2008-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 * SysUtil. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <centralrepository.h> |
|
21 #include <e32property.h> |
|
22 #include <f32file.h> |
|
23 #include <hal.h> |
|
24 #include <hal_data.h> |
|
25 #include <sysutil.h> |
|
26 #include <driveinfo.h> |
|
27 |
|
28 #include "com_nokia_mj_impl_installer_utils_SysUtil.h" |
|
29 #include "logger.h" |
|
30 |
|
31 #ifndef KPSUidJavaLatestInstallation |
|
32 #define KPSUidJavaLatestInstallation 0x10282567 |
|
33 #endif |
|
34 |
|
35 /** |
|
36 * Helper method for creating HBufC from jstring. |
|
37 */ |
|
38 HBufC* CreateHBufCFromJavaStringLC(JNIEnv* aEnv, jstring aString) |
|
39 { |
|
40 HBufC16* str = HBufC16::NewL(aEnv->GetStringLength(aString)); |
|
41 CleanupStack::PushL(str); |
|
42 const TUint16* temp = aEnv->GetStringChars(aString, 0); |
|
43 str->Des() = temp; |
|
44 aEnv->ReleaseStringChars(aString, temp); |
|
45 return str; |
|
46 } |
|
47 |
|
48 /** |
|
49 * See JNI method __1getRepositoryValue. |
|
50 * This is just internal wrapper method for handling Leaves. |
|
51 */ |
|
52 jint GetRepositoryValueL |
|
53 (JNIEnv *aEnv, jclass, jint aRepository, jlong aKey, jobject aIntValue) |
|
54 { |
|
55 TUid repositoryUid = { aRepository }; |
|
56 TUint key(aKey); |
|
57 TInt val(0); |
|
58 CRepository* repository = CRepository::NewLC(repositoryUid); |
|
59 TInt err = repository->Get(key, val); |
|
60 CleanupStack::PopAndDestroy(repository); |
|
61 if (KErrNone == err) |
|
62 { |
|
63 jclass clazz = aEnv->GetObjectClass(aIntValue); |
|
64 jmethodID methodID = aEnv->GetMethodID(clazz, "setValue", "(I)V"); |
|
65 if (0 == methodID) |
|
66 { |
|
67 ELOG(EJavaInstaller, |
|
68 "SysUtil__1getRepositoryValue: Cannot find setValue method"); |
|
69 err = KErrGeneral; |
|
70 } |
|
71 else |
|
72 { |
|
73 aEnv->CallVoidMethod(aIntValue, methodID, val); |
|
74 } |
|
75 } |
|
76 return err; |
|
77 } |
|
78 |
|
79 /** |
|
80 * See JNI method __1getRepositoryStringValue. |
|
81 * This is just internal wrapper method for handling Leaves. |
|
82 */ |
|
83 jint GetRepositoryStringValueL |
|
84 (JNIEnv *aEnv, jclass, jint aRepository, jlong aKey, jobjectArray aStringArray) |
|
85 { |
|
86 TUid repositoryUid = { aRepository }; |
|
87 CRepository* repository = CRepository::NewLC(repositoryUid); |
|
88 RBuf buf; |
|
89 buf.Create(NCentralRepositoryConstants::KMaxUnicodeStringLength); |
|
90 CleanupClosePushL(buf); |
|
91 TInt err = repository->Get(aKey, buf) ; |
|
92 if (KErrNone == err) |
|
93 { |
|
94 jstring val = aEnv->NewString((const unsigned short*)(buf.Ptr()), buf.Length()); |
|
95 if (NULL == val) |
|
96 { |
|
97 ELOG(EJavaInstaller, |
|
98 "SysUtil__1getRepositoryStringValue: String could not be constructed"); |
|
99 err = KErrGeneral; |
|
100 } |
|
101 else |
|
102 { |
|
103 aEnv->SetObjectArrayElement(aStringArray, 0, val); |
|
104 } |
|
105 } |
|
106 CleanupStack::PopAndDestroy(&buf) ; |
|
107 CleanupStack::PopAndDestroy(repository); |
|
108 return err; |
|
109 } |
|
110 |
|
111 /** |
|
112 * See JNI method __1setRepositoryValue. |
|
113 * This is just internal wrapper method for handling Leaves. |
|
114 */ |
|
115 jint SetRepositoryValueL |
|
116 (JNIEnv *, jclass, jint aRepository, jlong aKey, jint aValue) |
|
117 { |
|
118 TUid repositoryUid = { aRepository }; |
|
119 TUint key(aKey); |
|
120 TInt val(aValue); |
|
121 CRepository* repository = CRepository::NewLC(repositoryUid); |
|
122 TInt err = repository->Set(key, val); |
|
123 CleanupStack::PopAndDestroy(repository); |
|
124 return err; |
|
125 } |
|
126 |
|
127 /** |
|
128 * See JNI method __1setRepositoryStringValue. |
|
129 * This is just internal wrapper method for handling Leaves. |
|
130 */ |
|
131 jint SetRepositoryStringValueL |
|
132 (JNIEnv *aEnv, jclass, jint aRepository, jlong aKey, jstring aValue) |
|
133 { |
|
134 TUid repositoryUid = { aRepository }; |
|
135 TUint key(aKey); |
|
136 |
|
137 // Copy the characters in jstrings to Symbian descriptors so that |
|
138 // they can be used in S60 code. |
|
139 const jchar* value = aEnv->GetStringChars(aValue, 0); |
|
140 if (NULL == value) |
|
141 { |
|
142 ELOG(EJavaInstaller, |
|
143 "SysUtil__1setRepositoryStringValue: getting value failed in JNI"); |
|
144 return KErrArgument; |
|
145 } |
|
146 HBufC16* valueDes = HBufC16::New(aEnv->GetStringLength(aValue) + 1); |
|
147 if (NULL == valueDes) |
|
148 { |
|
149 ELOG(EJavaInstaller, |
|
150 "SysUtil__1setRepositoryStringValue: value allocation failed in JNI"); |
|
151 return KErrNoMemory; |
|
152 } |
|
153 CleanupStack::PushL(valueDes); |
|
154 *valueDes = value; |
|
155 aEnv->ReleaseStringChars(aValue, value); |
|
156 |
|
157 // Update repository value. |
|
158 CRepository* repository = CRepository::NewLC(repositoryUid); |
|
159 TInt err = repository->Set(key, *valueDes); |
|
160 |
|
161 CleanupStack::PopAndDestroy(repository); |
|
162 CleanupStack::PopAndDestroy(valueDes); |
|
163 |
|
164 return err; |
|
165 } |
|
166 |
|
167 /* |
|
168 * Class: com_nokia_mj_impl_installer_utils_SysUtil |
|
169 * Method: _defineProperty |
|
170 * Signature: (IJ)I |
|
171 */ |
|
172 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_utils_SysUtil__1defineProperty |
|
173 (JNIEnv *, jclass, jint aCategory, jlong aKey) |
|
174 { |
|
175 _LIT_SECURITY_POLICY_PASS(KReadPolicy); |
|
176 // update allowed by processes with write system data capability |
|
177 _LIT_SECURITY_POLICY_C1(KWritePolicy, ECapabilityWriteDeviceData); |
|
178 |
|
179 TUid categoryUid = { aCategory }; |
|
180 TInt err = RProperty::Define(categoryUid, aKey, RProperty::EInt, |
|
181 KReadPolicy, KWritePolicy); |
|
182 if (KErrAlreadyExists == err) |
|
183 { |
|
184 err = KErrNone; // Ignore KErrAlreadyExists status. |
|
185 } |
|
186 return err; |
|
187 } |
|
188 |
|
189 /* |
|
190 * Class: com_nokia_mj_impl_installer_utils_SysUtil |
|
191 * Method: _deleteProperty |
|
192 * Signature: (IJ)I |
|
193 */ |
|
194 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_utils_SysUtil__1deleteProperty |
|
195 (JNIEnv *, jclass, jint aCategory, jlong aKey) |
|
196 { |
|
197 TUid categoryUid = { aCategory }; |
|
198 TInt err = RProperty::Delete(categoryUid, aKey); |
|
199 if (KErrNotFound == err) |
|
200 { |
|
201 err = KErrNone; // Ignore KErrNotFound status. |
|
202 } |
|
203 return err; |
|
204 } |
|
205 |
|
206 /* |
|
207 * Class: com_nokia_mj_impl_installer_utils_SysUtil |
|
208 * Method: _getPropertyValue |
|
209 * Signature: (IJLcom/nokia/mj/impl/installer/utils/SysUtil/IntValue;)I |
|
210 */ |
|
211 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_utils_SysUtil__1getPropertyValue |
|
212 (JNIEnv *aEnv, jclass, jint aCategory, jlong aKey, jobject aIntValue) |
|
213 { |
|
214 TUid categoryUid = { aCategory }; |
|
215 TUint key(aKey); |
|
216 TInt val(0); |
|
217 TInt err = RProperty::Get(categoryUid, key, val); |
|
218 if (KErrNone == err) |
|
219 { |
|
220 jclass clazz = aEnv->GetObjectClass(aIntValue); |
|
221 jmethodID methodID = aEnv->GetMethodID(clazz, "setValue", "(I)V"); |
|
222 if (0 == methodID) |
|
223 { |
|
224 ELOG(EJavaInstaller, |
|
225 "SysUtil__1getPropertyValue: Cannot find setValue method"); |
|
226 return KErrGeneral; |
|
227 } |
|
228 aEnv->CallVoidMethod(aIntValue, methodID, val); |
|
229 } |
|
230 return err; |
|
231 } |
|
232 |
|
233 /* |
|
234 * Class: com_nokia_mj_impl_installer_utils_SysUtil |
|
235 * Method: _setPropertyValue |
|
236 * Signature: (IJI)I |
|
237 */ |
|
238 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_utils_SysUtil__1setPropertyValue |
|
239 (JNIEnv *, jclass, jint aCategory, jlong aKey, jint aValue) |
|
240 { |
|
241 TUid categoryUid = { aCategory }; |
|
242 TUint key(aKey); |
|
243 TInt val(aValue); |
|
244 TInt err = RProperty::Set(categoryUid, key, val); |
|
245 if ((KErrPermissionDenied == err) && (KPSUidJavaLatestInstallation == key)) |
|
246 { |
|
247 // Just log this error to allow running installer when OMJ itself is |
|
248 // installed to the device, the native installer is still running and |
|
249 // existing S60 midlets must be converted to OMJ |
|
250 WLOG(EJavaInstaller, |
|
251 "SysUtil__1setPropertyValue: Cannot set value because the old S60 " |
|
252 "installer still owns the PS key"); |
|
253 err = KErrNone; |
|
254 } |
|
255 return err; |
|
256 } |
|
257 |
|
258 /* |
|
259 * Class: com_nokia_mj_impl_installer_utils_SysUtil |
|
260 * Method: _getRepositoryValue |
|
261 * Signature: (IJLcom/nokia/mj/impl/installer/utils/SysUtil/IntValue;)I |
|
262 */ |
|
263 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_utils_SysUtil__1getRepositoryValue |
|
264 (JNIEnv *aEnv, jclass aClass, jint aRepository, jlong aKey, jobject aIntValue) |
|
265 { |
|
266 TInt result = KErrNone; |
|
267 TRAPD(err, result = GetRepositoryValueL(aEnv, aClass, aRepository, aKey, aIntValue)); |
|
268 if (KErrNone == err) |
|
269 { |
|
270 err = result; |
|
271 } |
|
272 return err; |
|
273 } |
|
274 |
|
275 /* |
|
276 * Class: com_nokia_mj_impl_installer_utils_SysUtil |
|
277 * Method: _getRepositoryStringValue |
|
278 * Signature: (IJ[Ljava/lang/String;)I |
|
279 */ |
|
280 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_utils_SysUtil__1getRepositoryStringValue |
|
281 (JNIEnv *aEnv, jclass aClass, jint aRepository, jlong aKey, jobjectArray aStringArray) |
|
282 { |
|
283 TInt result = KErrNone; |
|
284 TRAPD(err, result = GetRepositoryStringValueL(aEnv, aClass, aRepository, aKey, aStringArray)); |
|
285 if (KErrNone == err) |
|
286 { |
|
287 err = result; |
|
288 } |
|
289 return err; |
|
290 } |
|
291 |
|
292 /* |
|
293 * Class: com_nokia_mj_impl_installer_utils_SysUtil |
|
294 * Method: _setRepositoryValue |
|
295 * Signature: (IJI)I |
|
296 */ |
|
297 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_utils_SysUtil__1setRepositoryValue |
|
298 (JNIEnv *aEnv, jclass aClass, jint aRepository, jlong aKey, jint aValue) |
|
299 { |
|
300 TInt result = KErrNone; |
|
301 TRAPD(err, result = SetRepositoryValueL(aEnv, aClass, aRepository, aKey, aValue)); |
|
302 if (KErrNone == err) |
|
303 { |
|
304 err = result; |
|
305 } |
|
306 return err; |
|
307 } |
|
308 |
|
309 /* |
|
310 * Class: com_nokia_mj_impl_installer_utils_SysUtil |
|
311 * Method: _setRepositoryStringValue |
|
312 * Signature: (IJ[Ljava/lang/String;)I |
|
313 */ |
|
314 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_utils_SysUtil__1setRepositoryStringValue |
|
315 (JNIEnv *aEnv, jclass aClass, jint aRepository, jlong aKey, jstring aValue) |
|
316 { |
|
317 TInt result = KErrNone; |
|
318 TRAPD(err, result = SetRepositoryStringValueL(aEnv, aClass, aRepository, aKey, aValue)); |
|
319 if (KErrNone == err) |
|
320 { |
|
321 err = result; |
|
322 } |
|
323 return err; |
|
324 } |
|
325 |
|
326 /* |
|
327 * Class: com_nokia_mj_impl_installer_utils_SysUtil |
|
328 * Method: _getDriveUniqId |
|
329 * Signature: (ILcom/nokia/mj/impl/installer/utils/SysUtil/IntValue;)I |
|
330 */ |
|
331 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_utils_SysUtil__1getDriveUniqId |
|
332 (JNIEnv *aEnv, jclass, jint aDrive, jobject aIntValue) |
|
333 { |
|
334 RFs fs; |
|
335 TInt err = fs.Connect(); |
|
336 if (KErrNone != err) |
|
337 { |
|
338 return err; |
|
339 } |
|
340 TVolumeInfo volumeInfo; |
|
341 err = fs.Volume(volumeInfo, aDrive); |
|
342 fs.Close(); |
|
343 if (KErrNone == err) |
|
344 { |
|
345 jclass clazz = aEnv->GetObjectClass(aIntValue); |
|
346 jmethodID methodID = aEnv->GetMethodID(clazz, "setValue", "(I)V"); |
|
347 if (0 == methodID) |
|
348 { |
|
349 ELOG(EJavaInstaller, |
|
350 "SysUtil__1getDriveUniqId: Cannot find setValue method"); |
|
351 return KErrGeneral; |
|
352 } |
|
353 aEnv->CallVoidMethod(aIntValue, methodID, volumeInfo.iUniqueID); |
|
354 } |
|
355 return err; |
|
356 } |
|
357 |
|
358 /* |
|
359 * Class: com_nokia_mj_impl_installer_utils_SysUtil |
|
360 * Method: _isDrivePresent |
|
361 * Signature: (ILcom/nokia/mj/impl/installer/utils/SysUtil/BooleanValue;)I |
|
362 */ |
|
363 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_utils_SysUtil__1isDrivePresent |
|
364 (JNIEnv *aEnv, jclass, jint aDrive, jobject aBooleanValue) |
|
365 { |
|
366 RFs fs; |
|
367 TInt err = fs.Connect(); |
|
368 if (KErrNone != err) |
|
369 { |
|
370 return err; |
|
371 } |
|
372 TDriveInfo driveInfo; |
|
373 err = fs.Drive(driveInfo, aDrive); |
|
374 fs.Close(); |
|
375 |
|
376 TBool drivePresent = ETrue; |
|
377 if (KErrNone == err) |
|
378 { |
|
379 drivePresent = (driveInfo.iType != EMediaNotPresent); |
|
380 } |
|
381 else if (KErrNotReady == err || KErrBadName == err) |
|
382 { |
|
383 drivePresent = EFalse; |
|
384 err = KErrNone; |
|
385 } |
|
386 |
|
387 if (KErrNone == err) |
|
388 { |
|
389 jclass clazz = aEnv->GetObjectClass(aBooleanValue); |
|
390 jmethodID methodID = aEnv->GetMethodID(clazz, "setValue", "(Z)V"); |
|
391 if (0 == methodID) |
|
392 { |
|
393 ELOG(EJavaInstaller, |
|
394 "SysUtil__1isDrivePresent: Cannot find setValue method"); |
|
395 return KErrGeneral; |
|
396 } |
|
397 aEnv->CallVoidMethod(aBooleanValue, methodID, drivePresent); |
|
398 } |
|
399 return err; |
|
400 } |
|
401 |
|
402 /* |
|
403 * Class: com_nokia_mj_impl_installer_utils_SysUtil |
|
404 * Method: _isDriveReadOnly |
|
405 * Signature: (I)I |
|
406 */ |
|
407 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_utils_SysUtil__1isDriveReadOnly |
|
408 (JNIEnv *, jclass, jint aDrive) |
|
409 { |
|
410 RFs fs; |
|
411 TInt err = fs.Connect(); |
|
412 if (KErrNone != err) |
|
413 { |
|
414 return err; |
|
415 } |
|
416 |
|
417 TUint driveStatus = 0; |
|
418 err = DriveInfo::GetDriveStatus(fs, aDrive, driveStatus); |
|
419 fs.Close(); |
|
420 if (err < 0) |
|
421 { |
|
422 return err; |
|
423 } |
|
424 |
|
425 if (driveStatus & DriveInfo::EDriveReadOnly) |
|
426 { |
|
427 return 1; |
|
428 } |
|
429 else if (driveStatus & DriveInfo::EDriveRom) |
|
430 { |
|
431 return 1; |
|
432 } |
|
433 |
|
434 return 0; |
|
435 } |
|
436 |
|
437 /* |
|
438 * Class: com_nokia_mj_impl_installer_utils_SysUtil |
|
439 * Method: _isDiskSpaceBelowCriticalLevel |
|
440 * Signature: (ILcom/nokia/mj/impl/installer/utils/SysUtil/BooleanValue;)I |
|
441 */ |
|
442 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_utils_SysUtil__1isDiskSpaceBelowCriticalLevel |
|
443 (JNIEnv *aEnv, jclass, jint aBytesToWrite, jint aDrive, jobject aBooleanValue) |
|
444 { |
|
445 TBool result = false; |
|
446 TRAPD(err, result = SysUtil::DiskSpaceBelowCriticalLevelL(NULL, aBytesToWrite, aDrive)); |
|
447 if (KErrNone == err) |
|
448 { |
|
449 jclass clazz = aEnv->GetObjectClass(aBooleanValue); |
|
450 jmethodID methodID = aEnv->GetMethodID(clazz, "setValue", "(Z)V"); |
|
451 if (0 == methodID) |
|
452 { |
|
453 ELOG(EJavaInstaller, |
|
454 "SysUtil__1isDiskSpaceBelowCriticalLevel: Cannot find setValue method"); |
|
455 return KErrGeneral; |
|
456 } |
|
457 aEnv->CallVoidMethod(aBooleanValue, methodID, result); |
|
458 } |
|
459 return err; |
|
460 } |
|
461 |
|
462 _LIT(KProcessName, "*"); |
|
463 /* |
|
464 * Class: com_nokia_mj_impl_installer_utils_SysUtil |
|
465 * Method: _getProcessState |
|
466 * Signature: (I)I |
|
467 */ |
|
468 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_utils_SysUtil__1getProcessState |
|
469 (JNIEnv *, jclass, jint aUid) |
|
470 { |
|
471 TInt result = KErrNone; |
|
472 RProcess proc; |
|
473 TFindProcess procFinder(KProcessName); // search for "*" |
|
474 TFullName procName; |
|
475 while (procFinder.Next(procName) == KErrNone) |
|
476 { |
|
477 if (proc.Open(procFinder) != KErrNone) |
|
478 { |
|
479 continue; |
|
480 } |
|
481 if (proc.SecureId() == aUid) |
|
482 { |
|
483 if (proc.ExitType() == EExitPending) |
|
484 { |
|
485 LOG1(EJavaInstaller, EInfo, |
|
486 "SysUtil__1getProcessState: Found process [%x]", aUid); |
|
487 result = 1; // PROC_STATE_ALIVE |
|
488 proc.Close(); |
|
489 break; |
|
490 } |
|
491 } |
|
492 proc.Close(); |
|
493 } |
|
494 return result; |
|
495 } |
|
496 |
|
497 /* |
|
498 * Class: com_nokia_mj_impl_installer_utils_SysUtil |
|
499 * Method: _getDefaultPhoneMemory |
|
500 * Signature: ()I |
|
501 */ |
|
502 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_utils_SysUtil__1getDefaultPhoneMemory |
|
503 (JNIEnv *, jclass) |
|
504 { |
|
505 TInt drive; |
|
506 TInt err = DriveInfo::GetDefaultDrive(DriveInfo::EDefaultPhoneMemory, drive); |
|
507 if (err < 0) |
|
508 { |
|
509 // In case of error return Symbian error code |
|
510 return err; |
|
511 } |
|
512 else |
|
513 { |
|
514 // else return the number of the drive |
|
515 return drive; |
|
516 } |
|
517 } |
|
518 |
|
519 /* |
|
520 * Class: com_nokia_mj_impl_installer_utils_SysUtil |
|
521 * Method: _getDefaultMassStorage |
|
522 * Signature: ()I |
|
523 */ |
|
524 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_utils_SysUtil__1getDefaultMassStorage |
|
525 (JNIEnv *, jclass) |
|
526 { |
|
527 TInt drive; |
|
528 TInt err = DriveInfo::GetDefaultDrive(DriveInfo::EDefaultMassStorage, drive); |
|
529 if (err < 0) |
|
530 { |
|
531 // In case of error return Symbian error code |
|
532 return err; |
|
533 } |
|
534 else |
|
535 { |
|
536 // else return the number of the drive |
|
537 return drive; |
|
538 } |
|
539 } |
|
540 |
|
541 /* |
|
542 * Class: com_nokia_mj_impl_installer_utils_SysUtil |
|
543 * Method: _getUserVisibleDrives |
|
544 * Signature: (Ljava/util/Vector;)I |
|
545 */ |
|
546 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_utils_SysUtil__1getUserVisibleDrives |
|
547 (JNIEnv *aEnv, jclass aClass, jobject aVisibleDrives) |
|
548 { |
|
549 // Getting the list of user visible drives requires file server connection and |
|
550 // unfortunately we must create new one |
|
551 RFs fs; |
|
552 TInt err = fs.Connect(); |
|
553 if (KErrNone != err) |
|
554 { |
|
555 ELOG1(EJavaInstaller, |
|
556 "SysUtil__1getUserVisibleDrives: Cannot connect to file server, err: %d", err); |
|
557 return err; |
|
558 } |
|
559 |
|
560 // The list of user visible drives |
|
561 DriveInfo::TDriveArray drives; |
|
562 err = DriveInfo::GetUserVisibleDrives(fs, drives); |
|
563 if (KErrNone != err) |
|
564 { |
|
565 fs.Close(); |
|
566 return err; |
|
567 } |
|
568 |
|
569 TInt nCount = drives.Count(); |
|
570 if (nCount == 0) |
|
571 { |
|
572 // Strange, no user visible drives |
|
573 WLOG(EJavaInstaller, |
|
574 "SysUtil__1getUserVisibleDrives: No user visible drives in system."); |
|
575 fs.Close(); |
|
576 return KErrNone; |
|
577 } |
|
578 |
|
579 // Get status of each drive |
|
580 TUint driveStatuses[KMaxDrives]; |
|
581 TInt64 driveFreeSpaces[KMaxDrives]; |
|
582 TVolumeInfo volumeInfo; |
|
583 for (TInt nInd = 0; nInd < nCount; nInd++) |
|
584 { |
|
585 err = DriveInfo::GetDriveStatus(fs, drives[nInd], driveStatuses[nInd]); |
|
586 if (KErrNone != err) |
|
587 { |
|
588 WLOG2(EJavaInstaller, |
|
589 "SysUtil__1getUserVisibleDrives: cannot get drive %d status, err %d", |
|
590 drives[nInd], err); |
|
591 // If cannot get status of a drive, that drive will not be |
|
592 // returned to the caller |
|
593 driveStatuses[nInd] = 0; |
|
594 } |
|
595 err = fs.Volume(volumeInfo, drives[nInd]); |
|
596 if (KErrNone != err) |
|
597 { |
|
598 WLOG2(EJavaInstaller, |
|
599 "SysUtil__1getUserVisibleDrives: cannot get drive %d size, err %d", |
|
600 drives[nInd], err); |
|
601 driveFreeSpaces[nInd] = 0; |
|
602 } |
|
603 else |
|
604 { |
|
605 driveFreeSpaces[nInd] = volumeInfo.iFree; |
|
606 } |
|
607 } |
|
608 fs.Close(); |
|
609 |
|
610 // Now values in TDriveArray must be returned to Java side inside the vector |
|
611 // parameter aVisibleDrives. |
|
612 // The vector contains com.nokia.mj.impl.installer.utils.DriveInfo objects |
|
613 |
|
614 // Get class handle to Vector |
|
615 aClass = aEnv->GetObjectClass(aVisibleDrives); |
|
616 |
|
617 // Get method ID to void addElement(Object) |
|
618 jmethodID methodID = aEnv->GetMethodID( |
|
619 aClass, |
|
620 "addElement", |
|
621 "(Ljava/lang/Object;)V"); |
|
622 if (0 == methodID) |
|
623 { |
|
624 ELOG(EJavaInstaller, |
|
625 "SysUtil__1getUserVisibleDrives: JNI cannot get Vector addElement() method"); |
|
626 return KErrGeneral; |
|
627 } |
|
628 |
|
629 // Get reference to DriveInfo class |
|
630 jclass driveInfoClass = aEnv->FindClass("com/nokia/mj/impl/installer/utils/DriveInfo"); |
|
631 if (NULL == driveInfoClass) |
|
632 { |
|
633 ELOG(EJavaInstaller, |
|
634 "SysUtil__1getUserVisibleDrives: JNI cannot get DriveInfo class"); |
|
635 return KErrGeneral; |
|
636 } |
|
637 // Get reference to DriveInfo constructor (it takes two int parameters) |
|
638 jmethodID driveInfoConstructor = aEnv->GetMethodID( |
|
639 driveInfoClass, |
|
640 "<init>", |
|
641 "(IIJ)V"); |
|
642 if (0 == driveInfoConstructor) |
|
643 { |
|
644 ELOG(EJavaInstaller, |
|
645 "SysUtil__1getUserVisibleDrives: JNI cannot get DriveInfo constructor"); |
|
646 return KErrGeneral; |
|
647 } |
|
648 |
|
649 // Add drives to vector parameter |
|
650 for (TInt nInd = 0; nInd < nCount; nInd++) |
|
651 { |
|
652 // If the removable drive is not currently mounted |
|
653 // (e.g. MMC is not in the device), do NOT return the drive |
|
654 if (!(driveStatuses[nInd] & DriveInfo::EDrivePresent)) |
|
655 { |
|
656 continue; |
|
657 } |
|
658 |
|
659 // If the drive substed, remote, corrupt, in exclusive use or read only, |
|
660 // do NOT return the drive |
|
661 if (driveStatuses[nInd] & |
|
662 (DriveInfo::EDriveSubsted | DriveInfo::EDriveRemote | |
|
663 DriveInfo::EDriveCorrupt | DriveInfo::EDriveInUse | |
|
664 DriveInfo::EDriveReadOnly)) |
|
665 { |
|
666 continue; |
|
667 } |
|
668 |
|
669 // Create new DriveInfo object that contains the drive number |
|
670 // and the status of one of the user visible drives |
|
671 jobject driveInfoValue = |
|
672 aEnv->NewObject(driveInfoClass, driveInfoConstructor, |
|
673 drives[nInd], driveStatuses[nInd], |
|
674 driveFreeSpaces[nInd]); |
|
675 |
|
676 if (NULL == driveInfoValue) |
|
677 { |
|
678 ELOG(EJavaInstaller, |
|
679 "SysUtil__1getUserVisibleDrives: JNI cannot construct DriveInfo object"); |
|
680 return KErrGeneral; |
|
681 } |
|
682 |
|
683 // Append it to aVisibleDrives parameter |
|
684 aEnv->CallVoidMethod(aVisibleDrives, methodID, driveInfoValue); |
|
685 } |
|
686 |
|
687 return KErrNone; |
|
688 } |
|
689 |
|
690 /* |
|
691 * Class: com_nokia_mj_impl_installer_utils_SysUtil |
|
692 * Method: _getScreenWidth |
|
693 * Signature: ()I |
|
694 */ |
|
695 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_utils_SysUtil__1getScreenWidth |
|
696 (JNIEnv *, jclass) |
|
697 { |
|
698 TInt value = 0; |
|
699 TInt err = HAL::Get(HALData::EDisplayXPixels, value); |
|
700 if (KErrNone != err) |
|
701 { |
|
702 return err; |
|
703 } |
|
704 return value; |
|
705 } |
|
706 |
|
707 /* |
|
708 * Class: com_nokia_mj_impl_installer_utils_SysUtil |
|
709 * Method: _getScreenHeight |
|
710 * Signature: ()I |
|
711 */ |
|
712 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_installer_utils_SysUtil__1getScreenHeight |
|
713 (JNIEnv *, jclass) |
|
714 { |
|
715 TInt value = 0; |
|
716 TInt err = HAL::Get(HALData::EDisplayYPixels, value); |
|
717 if (KErrNone != err) |
|
718 { |
|
719 return err; |
|
720 } |
|
721 return value; |
|
722 } |