1 /* |
|
2 * Copyright (c) 2008 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: File containing application list classes |
|
15 * |
|
16 */ |
|
17 |
|
18 //INCLUDES: |
|
19 |
|
20 #include "tsfswdatalist.h" |
|
21 #include "tsentrykeygenerator.h" |
|
22 #include <mmf/common/mmfcontrollerpluginresolver.h> // for CleanupResetAndDestroyPushL |
|
23 #include <apgwgnam.h> |
|
24 #include <bitstd.h> |
|
25 #include <AknIconUtils.h> // avkon |
|
26 #include <apgicnfl.h> // fbsbitmap |
|
27 #include <AknIconSrvClient.h> |
|
28 #include <fbs.h> |
|
29 #include <apgwgnam.h> |
|
30 |
|
31 |
|
32 // size for the created app icons |
|
33 const TInt KAppIconWidth = 128; |
|
34 const TInt KAppIconHeight = 128; |
|
35 |
|
36 //uids to be hidden |
|
37 const TUid KHsApplicationUid = { 0x20022F35 }; |
|
38 |
|
39 const TInt KMaxLookupSize(75); |
|
40 |
|
41 // ================= MEMBER FUNCTIONS ======================= |
|
42 |
|
43 // -------------------------------------------------------------------------- |
|
44 // CTsFswDataList::NewL |
|
45 // -------------------------------------------------------------------------- |
|
46 // |
|
47 CTsFswDataList* CTsFswDataList::NewL(MTsResourceManager& resources, |
|
48 MTsWindowGroupsMonitor &monitor, |
|
49 MHsDataObserver& observer) |
|
50 { |
|
51 CTsFswDataList* self = new (ELeave) CTsFswDataList(resources, monitor, observer); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(); |
|
54 CleanupStack::Pop(self); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // -------------------------------------------------------------------------- |
|
59 // CTsFswDataList::CTsFswDataList |
|
60 // -------------------------------------------------------------------------- |
|
61 // |
|
62 CTsFswDataList::CTsFswDataList(MTsResourceManager& resources, |
|
63 MTsWindowGroupsMonitor &monitor, |
|
64 MHsDataObserver& observer) |
|
65 : |
|
66 CTsWindowGroupsObserver(monitor), |
|
67 mResources(resources), |
|
68 mObserver(observer) |
|
69 { |
|
70 } |
|
71 |
|
72 // -------------------------------------------------------------------------- |
|
73 // CTsFswDataList::~CTsFswDataList |
|
74 // -------------------------------------------------------------------------- |
|
75 // |
|
76 CTsFswDataList::~CTsFswDataList() |
|
77 { |
|
78 mData.ResetAndDestroy(); |
|
79 mHiddenUids.Close(); |
|
80 mAllowedUids.Close(); |
|
81 RFbsSession::Disconnect(); |
|
82 RAknIconSrvClient::Disconnect(); |
|
83 } |
|
84 |
|
85 // -------------------------------------------------------------------------- |
|
86 // CTsFswDataList::ConstructL |
|
87 // -------------------------------------------------------------------------- |
|
88 // |
|
89 void CTsFswDataList::ConstructL() |
|
90 { |
|
91 BaseConstructL(); |
|
92 mHiddenUids.AppendL(KHsApplicationUid); |
|
93 User::LeaveIfError(RFbsSession::Connect()); |
|
94 RAknIconSrvClient::Connect(); |
|
95 } |
|
96 |
|
97 // -------------------------------------------------------------------------- |
|
98 // CTsFswDataList::FswDataL |
|
99 // -------------------------------------------------------------------------- |
|
100 // |
|
101 const RTsFswArray& CTsFswDataList::FswDataL() |
|
102 { |
|
103 return mData; |
|
104 } |
|
105 |
|
106 // -------------------------------------------------------------------------- |
|
107 // CTsFswDataList::CollectTasksL |
|
108 // -------------------------------------------------------------------------- |
|
109 // |
|
110 void CTsFswDataList::HandleWindowGroupChanged(MTsResourceManager &, |
|
111 const TArray<RWsSession::TWindowGroupChainInfo> &wgList) |
|
112 { |
|
113 TRAP_IGNORE(RTsFswArray newAppsList; |
|
114 CleanupResetAndDestroyPushL(newAppsList); |
|
115 CollectAppsL(newAppsList, wgList); |
|
116 FitDataToList(newAppsList); |
|
117 CleanupStack::PopAndDestroy(&newAppsList)); |
|
118 |
|
119 } |
|
120 |
|
121 // -------------------------------------------------------------------------- |
|
122 // CTsFswDataList:: |
|
123 // -------------------------------------------------------------------------- |
|
124 // |
|
125 void CTsFswDataList::CollectAppsL(RTsFswArray& appsList, |
|
126 const TArray<RWsSession::TWindowGroupChainInfo> &wgList) |
|
127 { |
|
128 TInt offset(KErrNotFound); |
|
129 for (TInt i = 0; i < wgList.Count(); ++i) { |
|
130 TTsEntryKey key = TsEntryKeyGeneraror::GenerateL(wgList[i].iId, wgList); |
|
131 //skip this entry if it is already on list |
|
132 if (FindEntry(appsList, key) >= 0) { |
|
133 continue; |
|
134 } |
|
135 |
|
136 // get window group name |
|
137 TInt wgId = key.mParentId; |
|
138 CApaWindowGroupName* windowName = CApaWindowGroupName::NewLC(mResources.WsSession(), wgId); |
|
139 TUid appUid = windowName->AppUid(); |
|
140 |
|
141 //Check hidden applications |
|
142 if (KErrNotFound != (offset = mHiddenUids.Find(appUid))) { |
|
143 UpdateLookupTableL(mHiddenUids, offset); |
|
144 } else if (KErrNotFound != (offset = mAllowedUids.Find(appUid))) { |
|
145 UpdateLookupTableL(mAllowedUids, offset); |
|
146 AddEntryL(key, appUid, windowName, appsList); |
|
147 } else if(VerifyApplicationL(appUid)) { |
|
148 AddEntryL(key, appUid, windowName, appsList); |
|
149 } |
|
150 CleanupStack::PopAndDestroy(windowName); |
|
151 } |
|
152 CompressLookupTable(mHiddenUids); |
|
153 CompressLookupTable(mAllowedUids); |
|
154 } |
|
155 |
|
156 // -------------------------------------------------------------------------- |
|
157 // CTsFswDataList::AddEntryL |
|
158 // -------------------------------------------------------------------------- |
|
159 // |
|
160 void CTsFswDataList::AddEntryL(const TTsEntryKey& key, const TUid& appUid, |
|
161 CApaWindowGroupName* wgName, RTsFswArray& newList) |
|
162 { |
|
163 CTsFswEntry* entry = CTsFswEntry::NewLC(key, &mObserver); |
|
164 |
|
165 // check if present in old list and if yes then take some of the old data |
|
166 TBool found = ConsiderOldDataL(key); |
|
167 |
|
168 // if not present previously then find out app name |
|
169 // and check if screenshot is already available |
|
170 if (!found) { |
|
171 entry->SetAppUid(appUid); |
|
172 HBufC* name = FindAppNameLC(wgName, appUid, key.mParentId); |
|
173 if (name) { |
|
174 entry->SetAppNameL(*name); |
|
175 } |
|
176 CleanupStack::PopAndDestroy(name); |
|
177 |
|
178 if (wgName) { |
|
179 entry->SetCloseableApp(!wgName->IsSystem()); |
|
180 } |
|
181 CFbsBitmap* iconBitmap = NULL; |
|
182 CFbsBitmap* iconMask = NULL; |
|
183 GetAppIconL(appUid, iconBitmap, iconMask); |
|
184 //transfer ownership to entry |
|
185 entry->SetAppIcon(iconBitmap, iconMask); |
|
186 } |
|
187 |
|
188 // add to new list, ownership is transferred |
|
189 newList.AppendL(entry); |
|
190 CleanupStack::Pop(entry); |
|
191 } |
|
192 |
|
193 // -------------------------------------------------------------------------- |
|
194 // CTsFswDataList::ConsiderOldDataL |
|
195 // -------------------------------------------------------------------------- |
|
196 // |
|
197 TBool CTsFswDataList::ConsiderOldDataL(const TTsEntryKey& key) |
|
198 { |
|
199 for (TInt entryIdx = 0, oldCount = mData.Count(); entryIdx < oldCount; ++entryIdx) { |
|
200 if (mData[entryIdx]->Key() == key) { |
|
201 return ETrue; |
|
202 } |
|
203 } |
|
204 return EFalse; |
|
205 } |
|
206 |
|
207 // -------------------------------------------------------------------------- |
|
208 // CTsFswDataList::FindAppNameLC |
|
209 // -------------------------------------------------------------------------- |
|
210 // |
|
211 HBufC* CTsFswDataList::FindAppNameLC(CApaWindowGroupName* windowName, const TUid& appUid, TInt wgId) |
|
212 { |
|
213 //Retrieve the app name |
|
214 TApaAppInfo info; |
|
215 mResources.ApaSession().GetAppInfo(info, appUid); |
|
216 TPtrC caption = info.iShortCaption; |
|
217 |
|
218 HBufC* tempName = 0; |
|
219 if (!caption.Length() && windowName) // if not set - use thread name instead |
|
220 { |
|
221 if (windowName->Caption().Length()) { |
|
222 tempName = windowName->Caption().AllocL(); |
|
223 //put on cleanupstack after the if |
|
224 } |
|
225 else { |
|
226 TThreadId threadId; |
|
227 TInt err = mResources.WsSession().GetWindowGroupClientThreadId(wgId, threadId); |
|
228 if (err == KErrNone) { |
|
229 RThread thread; |
|
230 CleanupClosePushL(thread); |
|
231 err = thread.Open(threadId); |
|
232 if (err == KErrNone) { |
|
233 tempName = thread.Name().AllocL(); // codescanner::forgottoputptroncleanupstack |
|
234 // tempName put on cleanupstack after the if |
|
235 } |
|
236 CleanupStack::PopAndDestroy(&thread); |
|
237 } |
|
238 } |
|
239 } |
|
240 else { |
|
241 tempName = caption.AllocL(); |
|
242 //put on cleanupstack after the if |
|
243 } |
|
244 CleanupStack::PushL(tempName); |
|
245 return tempName; |
|
246 } |
|
247 |
|
248 // -------------------------------------------------------------------------- |
|
249 // CTsFswDataList::FitDataToListL |
|
250 // -------------------------------------------------------------------------- |
|
251 // |
|
252 void CTsFswDataList::FitDataToList(RTsFswArray& listToFit) |
|
253 { |
|
254 TBool changed = EFalse; |
|
255 TInt listCount = listToFit.Count(); |
|
256 TInt dataCount = mData.Count(); |
|
257 |
|
258 //remove items that dont't exists in newly collected list |
|
259 for (TInt i = dataCount - 1; i >= 0; --i) { |
|
260 if (!CheckIfExists(*mData[i], listToFit)) { |
|
261 delete mData[i]; |
|
262 mData.Remove(i); |
|
263 changed = ETrue; |
|
264 } |
|
265 } |
|
266 RArray<TTsEntryKey> allKeys; |
|
267 |
|
268 //add new item at start |
|
269 for (TInt i = listToFit.Count() - 1; i >= 0; --i) { |
|
270 allKeys.Insert(listToFit[i]->Key(), 0); |
|
271 if (!CheckIfExists(*listToFit[i], mData)) { |
|
272 mData.Insert(listToFit[i], 0); |
|
273 listToFit[i] = 0; |
|
274 changed = ETrue; |
|
275 } |
|
276 } |
|
277 //establish order |
|
278 TBool orderChanged = EstablishOrder(allKeys); |
|
279 if (changed || orderChanged) { |
|
280 mObserver.DataChanged(); |
|
281 } |
|
282 allKeys.Close(); |
|
283 } |
|
284 |
|
285 // -------------------------------------------------------------------------- |
|
286 // CTsFswDataList::CheckIfExists |
|
287 // -------------------------------------------------------------------------- |
|
288 // |
|
289 TBool CTsFswDataList::CheckIfExists(const CTsFswEntry& entry, const RTsFswArray& list) const |
|
290 { |
|
291 TBool exists(EFalse); |
|
292 TTsEntryKey key; |
|
293 TInt pos = FindEntry(list, entry.Key()); |
|
294 if (pos >= 0) { |
|
295 exists = ETrue; |
|
296 } |
|
297 return exists; |
|
298 } |
|
299 |
|
300 // -------------------------------------------------------------------------- |
|
301 // CTsFswDataList::GetAppIconL |
|
302 // -------------------------------------------------------------------------- |
|
303 // |
|
304 void CTsFswDataList::GetAppIconL(const TUid& aAppUid, CFbsBitmap*& bitmapArg, CFbsBitmap*& maskArg) |
|
305 { |
|
306 bitmapArg = maskArg = NULL; |
|
307 |
|
308 TSize size(KAppIconWidth, KAppIconHeight); |
|
309 CApaMaskedBitmap* apaMaskedBitmap = CApaMaskedBitmap::NewLC(); |
|
310 TInt err = mResources.ApaSession().GetAppIcon(aAppUid, size, *apaMaskedBitmap); |
|
311 TInt iconsCount(0); |
|
312 if (err == KErrNone) { |
|
313 err = mResources.ApaSession().NumberOfOwnDefinedIcons(aAppUid, iconsCount); |
|
314 } |
|
315 |
|
316 if ((err == KErrNone) && (iconsCount > 0)) { |
|
317 bitmapArg = static_cast<CFbsBitmap*> (apaMaskedBitmap); |
|
318 TInt maskHandle = apaMaskedBitmap->Mask()->Handle(); |
|
319 maskArg = new (ELeave) CFbsBitmap; |
|
320 maskArg->Duplicate(maskHandle); |
|
321 CleanupStack::Pop(apaMaskedBitmap); |
|
322 } |
|
323 else { |
|
324 CleanupStack::PopAndDestroy(apaMaskedBitmap); |
|
325 HBufC* fileNameFromApparc = NULL; |
|
326 TInt err = mResources.ApaSession().GetAppIcon(aAppUid, fileNameFromApparc); |
|
327 if (err == KErrNone) { |
|
328 CleanupStack::PushL(fileNameFromApparc); |
|
329 CFbsBitmap *bitamp(0); |
|
330 CFbsBitmap *mask(0); |
|
331 TInt bitmapIndex = 0; |
|
332 TInt maskIndex = 1; |
|
333 // it will change bitmap ids if it is mif (checking inside) |
|
334 AknIconUtils::ValidateLogicalAppIconId(*fileNameFromApparc, bitmapIndex, maskIndex); |
|
335 AknIconUtils::CreateIconLC(bitamp, mask, fileNameFromApparc->Des(), bitmapIndex, |
|
336 maskIndex); |
|
337 |
|
338 if (AknIconUtils::IsMifFile(*fileNameFromApparc)) { |
|
339 AknIconUtils::DisableCompression(bitamp); |
|
340 AknIconUtils::SetSize(bitamp, TSize(KAppIconWidth, KAppIconHeight), |
|
341 EAspectRatioPreservedAndUnusedSpaceRemoved); |
|
342 // bitmap and icon, AknsUtils::CreateIconLC doesn't specify the order |
|
343 CleanupStack::Pop(2); |
|
344 bitmapArg = bitamp; |
|
345 maskArg = mask; |
|
346 } |
|
347 else { |
|
348 CleanupStack::PopAndDestroy(2); |
|
349 } |
|
350 CleanupStack::PopAndDestroy(fileNameFromApparc); |
|
351 } |
|
352 } |
|
353 } |
|
354 |
|
355 // -------------------------------------------------------------------------- |
|
356 // CTsFswDataList::GetAppIconL |
|
357 // -------------------------------------------------------------------------- |
|
358 // |
|
359 TBool CTsFswDataList::IsHiddenUid(TUid uid) |
|
360 { |
|
361 TInt result = mHiddenUids.Find(uid); |
|
362 return result >= 0 ? ETrue : EFalse; |
|
363 } |
|
364 |
|
365 // -------------------------------------------------------------------------- |
|
366 // CTsFswDataList::FindEntry |
|
367 // -------------------------------------------------------------------------- |
|
368 // |
|
369 TInt CTsFswDataList::FindEntry(const RTsFswArray& list, const TTsEntryKey& key) const |
|
370 { |
|
371 TInt pos(KErrNotFound); |
|
372 TInt dataCount = list.Count(); |
|
373 for (TInt entryIdx = 0; entryIdx < dataCount; ++entryIdx) { |
|
374 if (list[entryIdx]->Key() == key) { |
|
375 pos = entryIdx; |
|
376 break; |
|
377 } |
|
378 } |
|
379 return pos; |
|
380 } |
|
381 |
|
382 // -------------------------------------------------------------------------- |
|
383 // CTsFswDataList::SetScreenshotL |
|
384 // -------------------------------------------------------------------------- |
|
385 // |
|
386 void CTsFswDataList::SetScreenshotL(const CFbsBitmap* bitmap, UpdatePriority priority, TInt wgId) |
|
387 { |
|
388 TInt pos = FindEntry(mData, GenerateKeyL(wgId)); |
|
389 User::LeaveIfError(pos); |
|
390 mData[pos]->SetScreenshotL(bitmap, priority); |
|
391 } |
|
392 |
|
393 // -------------------------------------------------------------------------- |
|
394 // CTsFswDataList::RemoveScreenshotL |
|
395 // -------------------------------------------------------------------------- |
|
396 // |
|
397 void CTsFswDataList::RemoveScreenshotL(TInt wgId) |
|
398 { |
|
399 |
|
400 TInt pos = FindEntry(mData, GenerateKeyL(wgId)); |
|
401 User::LeaveIfError(pos); |
|
402 mData[pos]->RemoveScreenshotL(); |
|
403 } |
|
404 |
|
405 // -------------------------------------------------------------------------- |
|
406 // CTsFswDataList::EstablishOrder |
|
407 // -------------------------------------------------------------------------- |
|
408 // |
|
409 TBool CTsFswDataList::EstablishOrder(const RArray<TTsEntryKey>& keyList) |
|
410 { |
|
411 TBool changed(EFalse); |
|
412 __ASSERT_ALWAYS(mData.Count() == keyList.Count(), User::Panic(_L("EstablishOrder 1"), KErrBadHandle) ); |
|
413 for (TInt i = 0; i < keyList.Count(); i++) { |
|
414 const TTsEntryKey& currentdataKey = mData[i]->Key(); |
|
415 const TTsEntryKey& referenceKey = keyList[i]; |
|
416 if (!(currentdataKey == referenceKey)) { |
|
417 TInt foundPos = FindEntry(mData, referenceKey); |
|
418 __ASSERT_ALWAYS(foundPos>=0, User::Panic(_L("EstablishOrder 2"), KErrBadHandle) ); |
|
419 CTsFswEntry* entry = mData[foundPos]; |
|
420 mData.Remove(foundPos); |
|
421 mData.Insert(entry, i); |
|
422 changed = ETrue; |
|
423 } |
|
424 } |
|
425 return changed; |
|
426 } |
|
427 |
|
428 // -------------------------------------------------------------------------- |
|
429 // CTsFswDataList::GetAllowedUidsL |
|
430 // -------------------------------------------------------------------------- |
|
431 // |
|
432 TBool CTsFswDataList::VerifyApplicationL(TUid uid) |
|
433 { |
|
434 TBool retVal(EFalse); |
|
435 TApaAppInfo appInfo; |
|
436 TApaAppCapabilityBuf appCap; |
|
437 |
|
438 User::LeaveIfError(mResources.ApaSession().GetAllApps(0)); |
|
439 // for every application get uid, hidden and missing attribute |
|
440 // and add to aArray. |
|
441 while (KErrNone == mResources.ApaSession().GetNextApp(appInfo)) { |
|
442 User::LeaveIfError(mResources.ApaSession().GetAppCapability(appCap, appInfo.iUid)); |
|
443 if(!appCap().iAppIsHidden) { |
|
444 if (uid == appInfo.iUid) { |
|
445 retVal = ETrue; |
|
446 mAllowedUids.InsertL(appInfo.iUid, mAllowedUids.Count()); |
|
447 } |
|
448 } else if(KErrNotFound == mHiddenUids.Find(appInfo.iUid)) { |
|
449 mHiddenUids.InsertL(appInfo.iUid, mHiddenUids.Count()); |
|
450 } |
|
451 } |
|
452 if (EFalse == retVal && KErrNotFound == mHiddenUids.Find(uid)) { |
|
453 mHiddenUids.InsertL(uid, mHiddenUids.Count()); |
|
454 } |
|
455 return retVal; |
|
456 } |
|
457 |
|
458 // -------------------------------------------------------------------------- |
|
459 // CTsFswDataList::GenerateKeyL(TInt) |
|
460 // -------------------------------------------------------------------------- |
|
461 // |
|
462 TTsEntryKey CTsFswDataList::GenerateKeyL(TInt wgId) |
|
463 { |
|
464 RArray<RWsSession::TWindowGroupChainInfo> allWgIds; |
|
465 CleanupClosePushL(allWgIds); |
|
466 User::LeaveIfError(mResources.WsSession().WindowGroupList(0, &allWgIds)); |
|
467 const TTsEntryKey key = TsEntryKeyGeneraror::GenerateL(wgId, allWgIds.Array()); |
|
468 CleanupStack::PopAndDestroy(&allWgIds); |
|
469 return key; |
|
470 } |
|
471 |
|
472 // -------------------------------------------------------------------------- |
|
473 // CTsFswDataList::CompressLookupTable(RArray<TUid> &) |
|
474 // -------------------------------------------------------------------------- |
|
475 // |
|
476 void CTsFswDataList::CompressLookupTable(RArray<TUid> &array) |
|
477 { |
|
478 while(KMaxLookupSize < array.Count()) { |
|
479 array.Remove(0); |
|
480 } |
|
481 } |
|
482 |
|
483 // -------------------------------------------------------------------------- |
|
484 // CTsFswDataList::UpdateLookupTableL(RArray<TUid> &, TInt) |
|
485 // -------------------------------------------------------------------------- |
|
486 // |
|
487 void CTsFswDataList::UpdateLookupTableL(RArray<TUid> &array, TInt offset) |
|
488 { |
|
489 const TUid uid(array[offset]); |
|
490 array.Remove(offset); |
|
491 array.InsertL(uid, array.Count()); |
|
492 } |
|
493 // end of file |
|