|
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: writeablejavaregistry implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include "javacommonutils.h" |
|
21 #include "driveutilities.h" |
|
22 #include "javastorageexception.h" |
|
23 #include "javastoragenames.h" |
|
24 #include "javasymbianoslayer.h" |
|
25 #include "javauid.h" |
|
26 #include "logger.h" |
|
27 #include "writeablejavaregistry.h" |
|
28 #include "writeablejavaregistryapplicationentry.h" |
|
29 #include "writeablejavaregistrypackageentry.h" |
|
30 |
|
31 using namespace Java; |
|
32 using namespace java::fileutils; |
|
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 // CWriteableJavaRegistry::NewL |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 EXPORT_C CWriteableJavaRegistry* CWriteableJavaRegistry:: |
|
45 NewL(TBool aUseIntegrity) |
|
46 { |
|
47 CWriteableJavaRegistry* self |
|
48 = CWriteableJavaRegistry::NewLC(aUseIntegrity); |
|
49 |
|
50 CleanupStack::Pop(self); |
|
51 return self; |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // CWriteableJavaRegistry::NewLC |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 EXPORT_C CWriteableJavaRegistry* CWriteableJavaRegistry:: |
|
59 NewLC(TBool aUseIntegrity) |
|
60 { |
|
61 CWriteableJavaRegistry* self = new(ELeave) CWriteableJavaRegistry(); |
|
62 CleanupStack::PushL(self); |
|
63 self->ConstructL(aUseIntegrity, EFalse); |
|
64 return self; |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // CWriteableJavaRegistry::~CWriteableJavaRegistry |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 EXPORT_C CWriteableJavaRegistry::~CWriteableJavaRegistry() |
|
72 { |
|
73 if (iStorage) |
|
74 { |
|
75 try |
|
76 { |
|
77 iStorage->close(); |
|
78 } |
|
79 catch (JavaStorageException& jse) |
|
80 { |
|
81 // No can do |
|
82 ELOG1(EJavaStorage, "Storage close failed %s ", |
|
83 jse.toString().c_str()); |
|
84 } |
|
85 delete iStorage; |
|
86 iStorage = NULL; |
|
87 } |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // CWriteableJavaRegistry::RegistryEntryExistsL |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 EXPORT_C TBool CWriteableJavaRegistry:: |
|
95 RegistryEntryExistsL(const TUid& aUid) const |
|
96 { |
|
97 JELOG2(EJavaStorage); |
|
98 |
|
99 if (aUid == TUid::Null()) |
|
100 { |
|
101 User::Leave(KErrArgument); |
|
102 } |
|
103 |
|
104 JavaStorageApplicationList_t foundApps; |
|
105 ApplicationUids(foundApps); |
|
106 |
|
107 TJavaRegistryEntryType appType; |
|
108 Uid entryUid; |
|
109 |
|
110 return MatchUid(foundApps, TUidToUid(aUid, entryUid), appType); |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // CWriteableJavaRegistry::GetRegistryEntryUidsL |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 EXPORT_C void CWriteableJavaRegistry:: |
|
118 GetRegistryEntryUidsL(RArray<TUid>& aUids) const |
|
119 { |
|
120 GetRegistryEntryUidsL(EGeneralPackage, aUids); |
|
121 GetRegistryEntryUidsL(EGeneralApplication, aUids); |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // CWriteableJavaRegistry::GetRegistryEntryUidsL |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 EXPORT_C void CWriteableJavaRegistry:: |
|
129 GetRegistryEntryUidsL(TJavaRegistryEntryType aType, |
|
130 RArray<TUid>& aUids, |
|
131 TBool /*aAllEntries*/) const |
|
132 { |
|
133 JavaStorageApplicationList_t apps; |
|
134 ApplicationUids(apps); |
|
135 |
|
136 if (apps.size() > 0) |
|
137 { |
|
138 if (EGeneralApplication == aType || EMidp2Midlet == aType) |
|
139 { |
|
140 JavaStorageEntry idQueryEntry; |
|
141 idQueryEntry.setEntry(ID, L""); |
|
142 |
|
143 AddUids(apps, idQueryEntry, aUids); |
|
144 } |
|
145 else if (EGeneralPackage == aType || EMidp2MidletSuite == aType) |
|
146 { |
|
147 JavaStorageEntry packageIdQueryEntry; |
|
148 packageIdQueryEntry.setEntry(PACKAGE_ID, L""); |
|
149 |
|
150 AddUids(apps, packageIdQueryEntry, aUids); |
|
151 } |
|
152 else |
|
153 { |
|
154 WLOG1(EJavaStorage, "Unknown entry type: %d", aType); |
|
155 } |
|
156 } |
|
157 apps.clear(); |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // CWriteableJavaRegistry::RegistryEntryL |
|
162 // It calls DecideEntryTypeAndCreateL to create the suitable subclass of |
|
163 // CWriteableJavaRegistryEntry. |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 EXPORT_C CWriteableJavaRegistryEntry* CWriteableJavaRegistry:: |
|
167 RegistryEntryL(const TUid& aUid, |
|
168 TBool /*aAllEntries*/) const |
|
169 { |
|
170 JavaStorageApplicationList_t foundApps; |
|
171 ApplicationUids(foundApps); |
|
172 |
|
173 TJavaRegistryEntryType appType; |
|
174 Uid entryUid; |
|
175 |
|
176 TBool match = MatchUid(foundApps, TUidToUid(aUid, entryUid), appType); |
|
177 foundApps.clear(); |
|
178 |
|
179 // Original implementation returns NULL if entry does not exists. |
|
180 CWriteableJavaRegistryEntry* retEntry = NULL; |
|
181 |
|
182 if (match) |
|
183 { |
|
184 JavaStorageApplicationEntry_t attributes; |
|
185 |
|
186 if ((EGeneralApplication == appType)) |
|
187 { |
|
188 StorageEntry(entryUid, APPLICATION_TABLE, attributes); |
|
189 |
|
190 if (attributes.size() > 0) |
|
191 { |
|
192 retEntry = new CWriteableJavaRegistryApplicationEntry( |
|
193 attributes, EMidp2Midlet); |
|
194 } |
|
195 } |
|
196 // Already matched so it must be suite. |
|
197 else // EGeneralPackage. |
|
198 { |
|
199 StorageEntry(entryUid, APPLICATION_PACKAGE_TABLE, attributes); |
|
200 |
|
201 if (attributes.size() > 0) |
|
202 { |
|
203 retEntry = new CWriteableJavaRegistryPackageEntry( |
|
204 attributes, EMidp2MidletSuite); |
|
205 } |
|
206 } |
|
207 } |
|
208 return retEntry; |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // CWriteableJavaRegistry::CWriteableJavaRegistry |
|
213 // --------------------------------------------------------------------------- |
|
214 // |
|
215 EXPORT_C CWriteableJavaRegistry::CWriteableJavaRegistry() |
|
216 { |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // CWriteableJavaRegistry::ConstructL |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 EXPORT_C void CWriteableJavaRegistry:: |
|
224 ConstructL(TBool /*aUseIntegrity*/, TBool /*aLegacy*/) |
|
225 { |
|
226 try |
|
227 { |
|
228 iStorage = JavaStorage::createInstance(); |
|
229 iStorage->open(); |
|
230 } |
|
231 catch (JavaStorageException& jse) |
|
232 { |
|
233 ELOG1(EJavaStorage, "Storage instance creation failed %s ", |
|
234 jse.toString().c_str()); |
|
235 User::Leave(jse.mStatus); |
|
236 } |
|
237 } |
|
238 |
|
239 // --------------------------------------------------------------------------- |
|
240 // CWriteableJavaRegistry::ApplicationUids |
|
241 // --------------------------------------------------------------------------- |
|
242 // |
|
243 void CWriteableJavaRegistry::ApplicationUids( |
|
244 JavaStorageApplicationList_t& aFoundApps) const |
|
245 { |
|
246 JavaStorageApplicationEntry_t searchQuery; |
|
247 JavaStorageEntry entry; |
|
248 entry.setEntry(ID, L""); |
|
249 searchQuery.insert(entry); |
|
250 |
|
251 entry.setEntry(PACKAGE_ID, L""); |
|
252 searchQuery.insert(entry); |
|
253 |
|
254 try |
|
255 { |
|
256 iStorage->search(APPLICATION_TABLE, searchQuery, aFoundApps); |
|
257 } |
|
258 catch (JavaStorageException& jse) |
|
259 { |
|
260 ELOG1(EJavaStorage, "Search failed: %s ", |
|
261 jse.toString().c_str()); |
|
262 } |
|
263 searchQuery.clear(); |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------------------------- |
|
267 // CWriteableJavaRegistry::MatchUid |
|
268 // --------------------------------------------------------------------------- |
|
269 // |
|
270 TBool CWriteableJavaRegistry::MatchUid( |
|
271 const JavaStorageApplicationList_t& aApps, |
|
272 const Uid& aUid, |
|
273 Java::TJavaRegistryEntryType& aType) const |
|
274 { |
|
275 JELOG2(EJavaStorage); |
|
276 |
|
277 TBool match = EFalse; |
|
278 |
|
279 // No applications nor suites to match. |
|
280 if (aApps.size()== 0) |
|
281 { |
|
282 LOG(EJavaStorage, EInfo, "No apps to match"); |
|
283 return EFalse; |
|
284 } |
|
285 |
|
286 JavaStorageEntry idQueryEntry; |
|
287 idQueryEntry.setEntry(ID, aUid.toString()); |
|
288 |
|
289 JavaStorageEntry packageIdQueryEntry; |
|
290 packageIdQueryEntry.setEntry(PACKAGE_ID, aUid.toString()); |
|
291 |
|
292 JavaStorageApplicationList_t::const_iterator appIter; |
|
293 |
|
294 for (appIter = aApps.begin(); appIter != aApps.end(); appIter++) |
|
295 { |
|
296 JavaStorageApplicationEntry_t::const_iterator findIterator |
|
297 = (*appIter).find(idQueryEntry); |
|
298 |
|
299 if (findIterator != (*appIter).end()) |
|
300 { |
|
301 aType = Java::EGeneralApplication; |
|
302 match = IsPresent((*appIter)); |
|
303 break; |
|
304 } |
|
305 |
|
306 findIterator = (*appIter).find(packageIdQueryEntry); |
|
307 if (findIterator != (*appIter).end()) |
|
308 { |
|
309 aType = Java::EGeneralPackage; |
|
310 match = IsPresent((*appIter)); |
|
311 break; |
|
312 } |
|
313 } |
|
314 return match; |
|
315 } |
|
316 |
|
317 // --------------------------------------------------------------------------- |
|
318 // CWriteableJavaRegistry::StorageEntry |
|
319 // --------------------------------------------------------------------------- |
|
320 // |
|
321 void CWriteableJavaRegistry::StorageEntry( |
|
322 const Uid& aUid, |
|
323 const string& aTableName, |
|
324 JavaStorageApplicationEntry_t& aAppEntry) const |
|
325 { |
|
326 try |
|
327 { |
|
328 iStorage->read(aTableName, aUid, aAppEntry); |
|
329 } |
|
330 catch (JavaStorageException& jse) |
|
331 { |
|
332 ELOG1(EJavaStorage, "Read failed: %s ", |
|
333 jse.toString().c_str()); |
|
334 |
|
335 } |
|
336 } |
|
337 |
|
338 // --------------------------------------------------------------------------- |
|
339 // CWriteableJavaRegistry::AddUids |
|
340 // --------------------------------------------------------------------------- |
|
341 // |
|
342 void CWriteableJavaRegistry::AddUids( |
|
343 const JavaStorageApplicationList_t& aApps, |
|
344 const JavaStorageEntry& aEntry, |
|
345 RArray<TUid>& aUids) const |
|
346 { |
|
347 JavaStorageApplicationList_t::const_iterator iter; |
|
348 |
|
349 for (iter = aApps.begin(); iter != aApps.end(); iter++) |
|
350 { |
|
351 JavaStorageApplicationEntry_t::const_iterator finder |
|
352 = (*iter).find(aEntry); |
|
353 |
|
354 if (finder != (*iter).end()) |
|
355 { |
|
356 Uid appUid((*finder).entryValue()); |
|
357 TUid uid; |
|
358 TInt err = uidToTUid(appUid, uid); |
|
359 |
|
360 if (KErrNone == err) |
|
361 { |
|
362 err = aUids.Find(uid); |
|
363 |
|
364 if (KErrNotFound == err) |
|
365 { |
|
366 if (IsPresent((*iter))) |
|
367 { |
|
368 aUids.Append(uid); |
|
369 } |
|
370 } |
|
371 } |
|
372 } |
|
373 } |
|
374 } |
|
375 |
|
376 // --------------------------------------------------------------------------- |
|
377 // CWriteableJavaRegistry::IsPresent |
|
378 // --------------------------------------------------------------------------- |
|
379 // |
|
380 TBool CWriteableJavaRegistry::IsPresent( |
|
381 const JavaStorageApplicationEntry_t& aEntry) const |
|
382 { |
|
383 wstring value = L""; |
|
384 EntryAttributeValue(aEntry, PACKAGE_ID, value); |
|
385 |
|
386 java::util::Uid uid(value); |
|
387 value.clear(); |
|
388 |
|
389 JavaStorageApplicationEntry_t appEntry; |
|
390 StorageEntry(uid, APPLICATION_PACKAGE_TABLE, appEntry); |
|
391 EntryAttributeValue(appEntry, MEDIA_ID, value); |
|
392 |
|
393 if (value == L"0") |
|
394 { |
|
395 // App is in internal c drive or internal mass memory. |
|
396 return true; |
|
397 } |
|
398 |
|
399 // App is in removable media. |
|
400 try |
|
401 { |
|
402 int sourceMediaId = JavaCommonUtils::wstringToInt(value); |
|
403 |
|
404 driveInfos drives; |
|
405 DriveUtilities::getAccesibleDrives(drives); |
|
406 |
|
407 driveInfos::const_iterator iter; |
|
408 |
|
409 for (iter = drives.begin(); iter != drives.end(); iter++) |
|
410 { |
|
411 if ((*iter).iId == sourceMediaId) |
|
412 { |
|
413 return ETrue; |
|
414 } |
|
415 } |
|
416 } |
|
417 catch (ExceptionBase) |
|
418 { |
|
419 ELOG1WSTR(EJavaStorage, "MediaId conversion failed: '%s'", value); |
|
420 } |
|
421 return EFalse; |
|
422 } |
|
423 |
|
424 // --------------------------------------------------------------------------- |
|
425 // CWriteableJavaRegistry::EntryAttributeValue |
|
426 // --------------------------------------------------------------------------- |
|
427 // |
|
428 void CWriteableJavaRegistry::EntryAttributeValue( |
|
429 const JavaStorageApplicationEntry_t& aEntry, |
|
430 const wstring& aName, |
|
431 wstring& aValue) const |
|
432 { |
|
433 JavaStorageEntry attr; |
|
434 attr.setEntry(aName, L""); |
|
435 |
|
436 JavaStorageApplicationEntry_t::const_iterator findIterator = aEntry.find(attr); |
|
437 |
|
438 if (findIterator != aEntry.end()) |
|
439 { |
|
440 aValue = (*findIterator).entryValue(); |
|
441 } |
|
442 else |
|
443 { |
|
444 LOG(EJavaStorage, EInfo, "Entry attribute value not found"); |
|
445 aValue = L""; |
|
446 } |
|
447 } |