|
1 /* |
|
2 * Copyright (c) 2005-2009 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: writeablejavaregistrypackageentry implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 |
|
21 #include <memory> |
|
22 #include <e32base.h> |
|
23 #include <appversion.h> |
|
24 |
|
25 #include "writeablejavaregistrypackageentry.h" |
|
26 #include "securitystoragedatadefs.h" |
|
27 #include "javacommonutils.h" |
|
28 #include "javastoragenames.h" |
|
29 #include "javasizehelpclient.h" |
|
30 #include "javasymbianoslayer.h" |
|
31 #include "logger.h" |
|
32 |
|
33 using namespace Java::Manager::Registry; |
|
34 using namespace java::storage; |
|
35 using namespace java::util; |
|
36 using namespace std; |
|
37 |
|
38 // ============================ MEMBER FUNCTIONS ============================== |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // CJavaRegistryPackageEntry::CJavaRegistryPackageEntry |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 CWriteableJavaRegistryPackageEntry::CWriteableJavaRegistryPackageEntry |
|
45 (JavaStorageApplicationEntry_t& aEntry, TJavaRegistryEntryType aType) : |
|
46 CWriteableJavaRegistryEntry(aEntry , aType) |
|
47 { |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // CWriteableJavaRegistryPackageEntry::~CWriteableJavaRegistryPackageEntry |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 EXPORT_C CWriteableJavaRegistryPackageEntry:: |
|
55 ~CWriteableJavaRegistryPackageEntry() |
|
56 { |
|
57 if (iVendor) |
|
58 { |
|
59 delete iVendor; |
|
60 iVendor = NULL; |
|
61 } |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // CWriteableJavaRegistryPackageEntry::Version |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 EXPORT_C TAppVersion CWriteableJavaRegistryPackageEntry::Version() const |
|
69 { |
|
70 JELOG2(EJavaStorage); |
|
71 |
|
72 wstring value = L""; |
|
73 EntryAttributeValue(iEntry, VERSION, value); |
|
74 return wstringToAppVersion(value); |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // CWriteableJavaRegistryPackageEntry::Vendor |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 EXPORT_C const TDesC& CWriteableJavaRegistryPackageEntry::Vendor() const |
|
82 { |
|
83 JELOG2(EJavaStorage); |
|
84 |
|
85 if (!iVendor) |
|
86 { |
|
87 wstring value = L""; |
|
88 EntryAttributeValue(iEntry, VENDOR, value); |
|
89 |
|
90 if (value == L"") |
|
91 { |
|
92 return KNullDesC; |
|
93 } |
|
94 else |
|
95 { |
|
96 iVendor = wstringToBuf(value); |
|
97 } |
|
98 } |
|
99 return *iVendor; |
|
100 } |
|
101 |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // CWriteableJavaRegistryPackageEntry::IsUninstallable |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 EXPORT_C TBool CWriteableJavaRegistryPackageEntry::IsUninstallable() const |
|
108 { |
|
109 JELOG2(EJavaStorage); |
|
110 |
|
111 TBool result = ETrue; |
|
112 |
|
113 _LIT(KBlockUninstall, "Nokia-MIDlet-Block-Uninstall"); |
|
114 const MJavaAttribute* blockUninstall = NULL; |
|
115 TRAPD(err, blockUninstall = AttributeL(KBlockUninstall)); |
|
116 |
|
117 if (KErrNone != err) |
|
118 { |
|
119 ELOG1(EJavaStorage, "Cannot read Block uninstall attribute: %d", err); |
|
120 return ETrue; |
|
121 } |
|
122 |
|
123 _LIT(KValueTrue, "true"); |
|
124 |
|
125 // If attribute is present and value is set to true. |
|
126 if (blockUninstall && blockUninstall->Value().CompareF(KValueTrue) == 0) |
|
127 { |
|
128 // Check it is authorized i.e. belongs to manufacturer or operator |
|
129 // domain |
|
130 wstring value = L""; |
|
131 EntryAttributeValue(iEntry, ID, value); |
|
132 |
|
133 java::util::Uid suiteUid(value); |
|
134 JavaStorageApplicationEntry_t suiteEntry; |
|
135 |
|
136 StorageEntry(suiteUid, MIDP_PACKAGE_TABLE, suiteEntry); |
|
137 value.clear(); |
|
138 |
|
139 EntryAttributeValue(suiteEntry, SECURITY_DOMAIN_CATEGORY, value); |
|
140 |
|
141 if (value.size() > 0) |
|
142 { |
|
143 try |
|
144 { |
|
145 if (value == OPERATOR_DOMAIN_CATEGORY |
|
146 || value == MANUFACTURER_DOMAIN_CATEGORY) |
|
147 |
|
148 { |
|
149 result = EFalse; |
|
150 } |
|
151 } |
|
152 catch (ExceptionBase& e) |
|
153 { |
|
154 ELOG1WSTR(EJavaStorage, |
|
155 "Security domain UTF-8 conversion failed: %s", value); |
|
156 } |
|
157 } |
|
158 } |
|
159 |
|
160 if (blockUninstall) |
|
161 { |
|
162 delete blockUninstall; |
|
163 blockUninstall = NULL; |
|
164 } |
|
165 |
|
166 return result; |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // CWriteableJavaRegistryPackageEntry::GetEmbeddedEntries |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 EXPORT_C void CWriteableJavaRegistryPackageEntry:: |
|
174 GetEmbeddedEntries(RArray<TUid>& aUids) const |
|
175 { |
|
176 JELOG2(EJavaStorage); |
|
177 |
|
178 wstring value = L""; |
|
179 EntryAttributeValue(iEntry, ID, value); |
|
180 |
|
181 JavaStorageApplicationList_t apps; |
|
182 java::util::Uid uid(value); |
|
183 SuiteEntries(uid, apps); |
|
184 |
|
185 if (apps.size() != 0) |
|
186 { |
|
187 JavaStorageEntry attr; |
|
188 attr.setEntry(ID, L""); |
|
189 JavaStorageApplicationList_t::const_iterator appsIter; |
|
190 |
|
191 for (appsIter = apps.begin(); appsIter != apps.end(); ++appsIter) |
|
192 { |
|
193 JavaStorageApplicationEntry_t::const_iterator entryIter |
|
194 = (*appsIter).find(attr); |
|
195 |
|
196 if (entryIter != (*appsIter).end()) |
|
197 { |
|
198 wstring attrValue = L""; |
|
199 EntryAttributeValue((*appsIter), ID, attrValue); |
|
200 |
|
201 if (attrValue.size() > 0) |
|
202 { |
|
203 java::util::Uid appUid(attrValue); |
|
204 TUid converted; |
|
205 TInt err = uidToTUid(appUid, converted); |
|
206 if (KErrNone == err) |
|
207 { |
|
208 aUids.Append(converted); |
|
209 } |
|
210 else |
|
211 { |
|
212 ELOG1(EJavaStorage, "Uid TUid conversion err: %d", |
|
213 err); |
|
214 } |
|
215 } |
|
216 } |
|
217 } |
|
218 } |
|
219 apps.clear(); |
|
220 } |
|
221 |
|
222 // --------------------------------------------------------------------------- |
|
223 // CWriteableJavaRegistryPackageEntry::NumberOfEmbeddedEntries |
|
224 // --------------------------------------------------------------------------- |
|
225 // |
|
226 EXPORT_C TInt CWriteableJavaRegistryPackageEntry:: |
|
227 NumberOfEmbeddedEntries() const |
|
228 { |
|
229 JELOG2(EJavaStorage); |
|
230 |
|
231 wstring value = L""; |
|
232 EntryAttributeValue(iEntry, ID, value); |
|
233 |
|
234 JavaStorageApplicationList_t apps; |
|
235 java::util::Uid uid(value); |
|
236 SuiteEntries(uid, apps); |
|
237 |
|
238 return apps.size(); |
|
239 } |
|
240 |
|
241 // --------------------------------------------------------------------------- |
|
242 // CWriteableJavaRegistryPackageEntry::EmbeddedEntryByUidL |
|
243 // --------------------------------------------------------------------------- |
|
244 // |
|
245 EXPORT_C CWriteableJavaRegistryEntry* |
|
246 CWriteableJavaRegistryPackageEntry:: |
|
247 EmbeddedEntryByUidL(const TUid& aEntryUid) const |
|
248 { |
|
249 JELOG2(EJavaStorage); |
|
250 |
|
251 JavaStorageApplicationEntry_t attributes; |
|
252 java::util::Uid entryUid; |
|
253 |
|
254 StorageEntry( |
|
255 TUidToUid(aEntryUid, entryUid), APPLICATION_TABLE, attributes); |
|
256 |
|
257 if (0 == attributes.size()) |
|
258 { |
|
259 WLOG(EJavaStorage, "Entry does not exists"); |
|
260 return NULL; |
|
261 } |
|
262 |
|
263 return new CWriteableJavaRegistryEntry(attributes, EMidp2Midlet); |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------------------------- |
|
267 // CWriteableJavaRegistryPackageEntry::EmbeddedEntryByNumberL |
|
268 // --------------------------------------------------------------------------- |
|
269 // |
|
270 EXPORT_C CWriteableJavaRegistryEntry* |
|
271 CWriteableJavaRegistryPackageEntry:: |
|
272 EmbeddedEntryByNumberL(TInt aEntryNum) const |
|
273 { |
|
274 JELOG2(EJavaStorage); |
|
275 |
|
276 if (aEntryNum < 0) |
|
277 { |
|
278 User::Leave(KErrArgument); |
|
279 } |
|
280 |
|
281 wstring value = L""; |
|
282 EntryAttributeValue(iEntry, ID, value); |
|
283 |
|
284 JavaStorageApplicationList_t apps; |
|
285 java::util::Uid uid(value); |
|
286 SuiteEntries(uid, apps); |
|
287 |
|
288 // aEntryNum is zero based whereas apps is one based. |
|
289 if (aEntryNum >= apps.size()) |
|
290 { |
|
291 return NULL; |
|
292 } |
|
293 |
|
294 JavaStorageApplicationList_t::const_iterator iter = apps.begin(); |
|
295 |
|
296 for (int i = 0; i < aEntryNum; i++) |
|
297 { |
|
298 ++iter; |
|
299 } |
|
300 |
|
301 value.clear(); |
|
302 |
|
303 EntryAttributeValue((*iter), ID, value); |
|
304 |
|
305 java::util::Uid appUid(value); |
|
306 JavaStorageApplicationEntry_t attributes; |
|
307 |
|
308 StorageEntry(appUid, APPLICATION_TABLE, attributes); |
|
309 |
|
310 if (attributes.size() == 0) |
|
311 { |
|
312 ELOG1WSTR(EJavaStorage, |
|
313 "No attributes for embedded entry: %s", |
|
314 appUid.toString()); |
|
315 return NULL; |
|
316 } |
|
317 else |
|
318 { |
|
319 return new CWriteableJavaRegistryEntry(attributes, EMidp2Midlet); |
|
320 } |
|
321 } |
|
322 |
|
323 // --------------------------------------------------------------------------- |
|
324 // CWriteableJavaRegistryPackageEntry::AttributeL |
|
325 // --------------------------------------------------------------------------- |
|
326 // |
|
327 EXPORT_C const MJavaAttribute* CWriteableJavaRegistryPackageEntry:: |
|
328 AttributeL(const TDesC& aName) const |
|
329 { |
|
330 JELOG2(EJavaStorage); |
|
331 return CWriteableJavaRegistryEntry::AttributeL(aName); |
|
332 } |
|
333 |
|
334 // --------------------------------------------------------------------------- |
|
335 // CWriteableJavaRegistryPackageEntry::AttributesL |
|
336 // --------------------------------------------------------------------------- |
|
337 // |
|
338 EXPORT_C const RPointerArray<MJavaAttribute>& |
|
339 CWriteableJavaRegistryPackageEntry::AttributesL() const |
|
340 { |
|
341 JELOG2(EJavaStorage); |
|
342 return CWriteableJavaRegistryEntry::AttributesL(); |
|
343 } |
|
344 |
|
345 // --------------------------------------------------------------------------- |
|
346 // CWriteableJavaRegistryPackageEntry::UsedUserDiskSpace |
|
347 // --------------------------------------------------------------------------- |
|
348 EXPORT_C TInt64 CWriteableJavaRegistryPackageEntry::UsedUserDiskSpace() const |
|
349 { |
|
350 JELOG(EJavaStorage, "CJavaRegistryPackageEntry::UsedUserDiskSpace()"); |
|
351 |
|
352 wstring rootPath = L""; |
|
353 EntryAttributeValue(iEntry, ROOT_PATH, rootPath); |
|
354 |
|
355 auto_ptr<HBufC> suitePath(HBufC16::New(rootPath.size() + 1)); |
|
356 |
|
357 if (!suitePath.get()) |
|
358 { |
|
359 ELOG(EJavaStorage, "Cannot allocate suite path."); |
|
360 return 0; |
|
361 } |
|
362 |
|
363 TPtr16 suitePathPtr(suitePath->Des()); |
|
364 suitePathPtr = (const TUint16*)rootPath.c_str(); |
|
365 |
|
366 RJavaSizeHelpClient session; |
|
367 TInt err = session.Connect(); |
|
368 |
|
369 TInt r = 0; |
|
370 |
|
371 if (KErrNone == err) |
|
372 { |
|
373 r = session.GetUserUsedDiskSpace(suitePathPtr); |
|
374 session.Close(); |
|
375 } |
|
376 wstring jarPath = L""; |
|
377 EntryAttributeValue(iEntry, JAR_PATH, jarPath); |
|
378 |
|
379 wstring::size_type startIdx = 0; |
|
380 |
|
381 if (jarPath.find(rootPath, startIdx) == string::npos) |
|
382 { |
|
383 // As ROOT_PATH is not parth of the JAR_PATH this application suite |
|
384 // is preinstalled and its JAR size is added to ROOT_PATH count. |
|
385 wstring value = L""; |
|
386 EntryAttributeValue(iEntry, INITIAL_SIZE, value); |
|
387 r += JavaCommonUtils::wstringToInt(value); |
|
388 } |
|
389 return r; |
|
390 } |
|
391 |
|
392 // --------------------------------------------------------------------------- |
|
393 // CWriteableJavaRegistryPackageEntry::IsPreinstalled |
|
394 // --------------------------------------------------------------------------- |
|
395 EXPORT_C TBool CWriteableJavaRegistryPackageEntry::IsPreinstalled() const |
|
396 { |
|
397 JELOG2(EJavaStorage); |
|
398 TBool isPreinstalled = EFalse; |
|
399 wstring name = L""; |
|
400 wstring vendor = L""; |
|
401 |
|
402 EntryAttributeValue(iEntry, PACKAGE_NAME, name); |
|
403 EntryAttributeValue(iEntry, VENDOR, vendor); |
|
404 |
|
405 JavaStorageApplicationList_t apps; |
|
406 JavaStorageApplicationEntry_t searchQuery; |
|
407 JavaStorageEntry attr; |
|
408 attr.setEntry(NAME, name); |
|
409 searchQuery.insert(attr); |
|
410 attr.setEntry(VENDOR, vendor); |
|
411 searchQuery.insert(attr); |
|
412 |
|
413 try |
|
414 { |
|
415 auto_ptr<JavaStorage> js(JavaStorage::createInstance()); |
|
416 js->open(); |
|
417 js->search(PREINSTALL_TABLE, searchQuery, apps); |
|
418 js->close(); |
|
419 js.reset(0); |
|
420 } |
|
421 catch (JavaStorageException& jse) |
|
422 { |
|
423 ELOG1(EJavaStorage, "IsPreinstalled: Search failed: %s ", |
|
424 jse.toString().c_str()); |
|
425 } |
|
426 searchQuery.clear(); |
|
427 |
|
428 if (apps.size() > 0) |
|
429 { |
|
430 wstring installState = L""; |
|
431 EntryAttributeValue(apps.front(), INSTALL_STATE, installState); |
|
432 |
|
433 // INSTALL_STATE 1 indicates preinstallation. |
|
434 if (installState == L"1") |
|
435 { |
|
436 isPreinstalled = ETrue; |
|
437 } |
|
438 } |
|
439 |
|
440 return isPreinstalled; |
|
441 } |
|
442 |
|
443 // --------------------------------------------------------------------------- |
|
444 // CWriteableJavaRegistryPackageEntry::SuiteEntries |
|
445 // --------------------------------------------------------------------------- |
|
446 // |
|
447 void CWriteableJavaRegistryPackageEntry::SuiteEntries( |
|
448 const java::util::Uid& aUid, |
|
449 JavaStorageApplicationList_t& aApps) const |
|
450 { |
|
451 JavaStorageApplicationEntry_t searchQuery; |
|
452 JavaStorageEntry attr; |
|
453 attr.setEntry(PACKAGE_ID, aUid.toString()); |
|
454 searchQuery.insert(attr); |
|
455 attr.setEntry(ID, L""); |
|
456 searchQuery.insert(attr); |
|
457 |
|
458 try |
|
459 { |
|
460 auto_ptr<JavaStorage> js(JavaStorage::createInstance()); |
|
461 js->open(); |
|
462 js->search(APPLICATION_TABLE, searchQuery, aApps); |
|
463 js->close(); |
|
464 js.reset(0); |
|
465 } |
|
466 catch (JavaStorageException& jse) |
|
467 { |
|
468 ELOG1(EJavaStorage, "Search failed: %s ", |
|
469 jse.toString().c_str()); |
|
470 } |
|
471 searchQuery.clear(); |
|
472 } |