tstaskmonitor/server/src/tsfswdatalist.cpp
changeset 103 b99b84bcd2d1
parent 83 156f692b1687
equal deleted inserted replaced
83:156f692b1687 103:b99b84bcd2d1
    16  */
    16  */
    17 
    17 
    18 //INCLUDES:
    18 //INCLUDES:
    19 
    19 
    20 #include "tsfswdatalist.h"
    20 #include "tsfswdatalist.h"
    21 #include "tsfswengine.h"
       
    22 #include "tsentrykeygenerator.h"
    21 #include "tsentrykeygenerator.h"
    23 #include <mmf/common/mmfcontrollerpluginresolver.h> // for CleanupResetAndDestroyPushL
    22 #include <mmf/common/mmfcontrollerpluginresolver.h> // for CleanupResetAndDestroyPushL
    24 #include <apgwgnam.h>
    23 #include <apgwgnam.h>
    25 #include <bitstd.h>
    24 #include <bitstd.h>
    26 #include <AknIconUtils.h> // avkon
    25 #include <AknIconUtils.h> // avkon
    27 #include <apgicnfl.h> // fbsbitmap
    26 #include <apgicnfl.h> // fbsbitmap
    28 #include <AknIconSrvClient.h> 
    27 #include <AknIconSrvClient.h> 
    29 #include <fbs.h>
    28 #include <fbs.h>
    30 #include <APGWGNAM.H>
    29 #include <apgwgnam.h>
    31 
    30 
    32 
    31 
    33 // size for the created app icons
    32 // size for the created app icons
    34 const TInt KAppIconWidth = 128;
    33 const TInt KAppIconWidth = 128;
    35 const TInt KAppIconHeight = 128;
    34 const TInt KAppIconHeight = 128;
    36 
    35 
    37 //uids to be hidden
    36 //uids to be hidden
    38 const TUid KHsApplicationUid = { 0x20022F35 };
    37 const TUid KHsApplicationUid = { 0x20022F35 };
    39 
    38 
       
    39 const TInt KMaxLookupSize(75);
       
    40 
    40 // ================= MEMBER FUNCTIONS =======================
    41 // ================= MEMBER FUNCTIONS =======================
    41 
    42 
    42 // --------------------------------------------------------------------------
    43 // --------------------------------------------------------------------------
    43 // CTsFswDataList::NewL
    44 // CTsFswDataList::NewL
    44 // --------------------------------------------------------------------------
    45 // --------------------------------------------------------------------------
    45 //
    46 //
    46 CTsFswDataList* CTsFswDataList::NewL(MHsDataObserver &observer)
    47 CTsFswDataList* CTsFswDataList::NewL(MTsResourceManager& resources,
    47 {
    48                                      MTsWindowGroupsMonitor &monitor, 
    48     CTsFswDataList* self = new (ELeave) CTsFswDataList(observer);
    49                                      MHsDataObserver& observer)
       
    50 {
       
    51     CTsFswDataList* self = new (ELeave) CTsFswDataList(resources, monitor, observer);
    49     CleanupStack::PushL(self);
    52     CleanupStack::PushL(self);
    50     self->ConstructL();
    53     self->ConstructL();
    51     CleanupStack::Pop(self);
    54     CleanupStack::Pop(self);
    52     return self;
    55     return self;
    53 }
    56 }
    54 
    57 
    55 // --------------------------------------------------------------------------
    58 // --------------------------------------------------------------------------
    56 // CTsFswDataList::CTsFswDataList
    59 // CTsFswDataList::CTsFswDataList
    57 // --------------------------------------------------------------------------
    60 // --------------------------------------------------------------------------
    58 //
    61 //
    59 CTsFswDataList::CTsFswDataList(MHsDataObserver& observer) :
    62 CTsFswDataList::CTsFswDataList(MTsResourceManager& resources,
       
    63                                MTsWindowGroupsMonitor &monitor, 
       
    64                                MHsDataObserver& observer) 
       
    65 :
       
    66     CTsWindowGroupsObserver(monitor),
       
    67     mResources(resources),
    60     mObserver(observer)
    68     mObserver(observer)
    61 {
    69 {
    62 }
    70 }
    63 
    71 
    64 // --------------------------------------------------------------------------
    72 // --------------------------------------------------------------------------
    66 // --------------------------------------------------------------------------
    74 // --------------------------------------------------------------------------
    67 //
    75 //
    68 CTsFswDataList::~CTsFswDataList()
    76 CTsFswDataList::~CTsFswDataList()
    69 {
    77 {
    70     mData.ResetAndDestroy();
    78     mData.ResetAndDestroy();
    71     mAppArcSession.Close();
       
    72     mWsSession.Close();
       
    73     mHiddenUids.Close();
    79     mHiddenUids.Close();
    74     mAllowedUids.Close();
    80     mAllowedUids.Close();
    75     RFbsSession::Disconnect();
    81     RFbsSession::Disconnect();
    76     RAknIconSrvClient::Disconnect();
    82     RAknIconSrvClient::Disconnect();
    77 }
    83 }
    80 // CTsFswDataList::ConstructL
    86 // CTsFswDataList::ConstructL
    81 // --------------------------------------------------------------------------
    87 // --------------------------------------------------------------------------
    82 //
    88 //
    83 void CTsFswDataList::ConstructL()
    89 void CTsFswDataList::ConstructL()
    84 {
    90 {
    85     User::LeaveIfError(mWsSession.Connect());
    91     BaseConstructL();
    86     User::LeaveIfError(mAppArcSession.Connect());
       
    87     mHiddenUids.AppendL(KHsApplicationUid);
    92     mHiddenUids.AppendL(KHsApplicationUid);
    88     User::LeaveIfError(RFbsSession::Connect());
    93     User::LeaveIfError(RFbsSession::Connect());
    89     RAknIconSrvClient::Connect();
    94     RAknIconSrvClient::Connect();
    90 }
    95 }
    91 
    96 
   100 
   105 
   101 // --------------------------------------------------------------------------
   106 // --------------------------------------------------------------------------
   102 // CTsFswDataList::CollectTasksL
   107 // CTsFswDataList::CollectTasksL
   103 // --------------------------------------------------------------------------
   108 // --------------------------------------------------------------------------
   104 //
   109 //
   105 TBool CTsFswDataList::CollectTasksL()
   110 void CTsFswDataList::HandleWindowGroupChanged(MTsResourceManager &, 
   106 {
   111                                               const TArray<RWsSession::TWindowGroupChainInfo> &wgList)
   107     TBool changed = EFalse;
   112 {
   108     RTsFswArray newAppsList;
   113     TRAP_IGNORE(RTsFswArray newAppsList;
   109     CleanupResetAndDestroyPushL(newAppsList);
   114                 CleanupResetAndDestroyPushL(newAppsList);
   110     CollectAppsL(newAppsList);
   115                 CollectAppsL(newAppsList, wgList);
   111     changed |= FitDataToListL(newAppsList);
   116                 FitDataToList(newAppsList);
   112     CleanupStack::PopAndDestroy(&newAppsList);
   117                 CleanupStack::PopAndDestroy(&newAppsList));
   113     return changed;
   118     
   114 }
   119 }
   115 
   120 
   116 // --------------------------------------------------------------------------
   121 // --------------------------------------------------------------------------
   117 // CTsFswDataList::
   122 // CTsFswDataList::
   118 // --------------------------------------------------------------------------
   123 // --------------------------------------------------------------------------
   119 //
   124 //
   120 void CTsFswDataList::CollectAppsL(RTsFswArray& appsList)
   125 void CTsFswDataList::CollectAppsL(RTsFswArray& appsList, 
   121 {
   126                                   const TArray<RWsSession::TWindowGroupChainInfo> &wgList)
   122     // gets allowed uids - running apps without hidden uids, null uids, filtered uid
   127 {
   123     GetAllowedUidsL();
   128     TInt offset(KErrNotFound);
   124 
   129     for (TInt i = 0; i < wgList.Count(); ++i) {
   125     // get all window groups
   130         TTsEntryKey key = TsEntryKeyGeneraror::GenerateL(wgList[i].iId, wgList);
   126     RArray<RWsSession::TWindowGroupChainInfo> allWgIds;
       
   127     CleanupClosePushL(allWgIds);
       
   128     User::LeaveIfError(mWsSession.WindowGroupList(0, &allWgIds));
       
   129 
       
   130     TInt count = allWgIds.Count();
       
   131     for (TInt i = 0; i < count; ++i) {
       
   132         TTsEntryKey key = TsEntryKeyGeneraror::GenerateL(allWgIds[i].iId, allWgIds.Array());
       
   133         //skip this entry if it is already on list
   131         //skip this entry if it is already on list
   134         if (FindEntry(appsList, key) >= 0) {
   132         if (FindEntry(appsList, key) >= 0) {
   135             continue;
   133             continue;
   136         }
   134         }
   137 
   135 
   138         // get window group name
   136         // get window group name
   139         TInt wgId = key.mParentId;
   137         TInt wgId = key.mParentId;
   140         CApaWindowGroupName* windowName = CApaWindowGroupName::NewLC(mWsSession, wgId);
   138         CApaWindowGroupName* windowName = CApaWindowGroupName::NewLC(mResources.WsSession(), wgId);
   141         TUid appUid = windowName->AppUid();
   139         TUid appUid = windowName->AppUid();
   142 
   140         
   143         // add item to task list if uid is allowed
   141         //Check hidden applications
   144         if (mAllowedUids.Find(appUid) >= 0) {
   142         if (KErrNotFound != (offset = mHiddenUids.Find(appUid))) {
       
   143             UpdateLookupTableL(mHiddenUids, offset);
       
   144         } else if (KErrNotFound != (offset = mAllowedUids.Find(appUid))) {
       
   145             UpdateLookupTableL(mAllowedUids, offset);
   145             AddEntryL(key, appUid, windowName, appsList);
   146             AddEntryL(key, appUid, windowName, appsList);
       
   147         } else if(VerifyApplicationL(appUid)) {
       
   148             AddEntryL(key, appUid, windowName, appsList);
   146         }
   149         }
   147         CleanupStack::PopAndDestroy(windowName);
   150         CleanupStack::PopAndDestroy(windowName);
   148     }
   151     }
   149     CleanupStack::PopAndDestroy(&allWgIds);
   152     CompressLookupTable(mHiddenUids);
       
   153     CompressLookupTable(mAllowedUids);
   150 }
   154 }
   151 
   155 
   152 // --------------------------------------------------------------------------
   156 // --------------------------------------------------------------------------
   153 // CTsFswDataList::AddEntryL
   157 // CTsFswDataList::AddEntryL
   154 // --------------------------------------------------------------------------
   158 // --------------------------------------------------------------------------
   206 //
   210 //
   207 HBufC* CTsFswDataList::FindAppNameLC(CApaWindowGroupName* windowName, const TUid& appUid, TInt wgId)
   211 HBufC* CTsFswDataList::FindAppNameLC(CApaWindowGroupName* windowName, const TUid& appUid, TInt wgId)
   208 {
   212 {
   209     //Retrieve the app name
   213     //Retrieve the app name
   210     TApaAppInfo info;
   214     TApaAppInfo info;
   211     mAppArcSession.GetAppInfo(info, appUid);
   215     mResources.ApaSession().GetAppInfo(info, appUid);
   212     TPtrC caption = info.iShortCaption;
   216     TPtrC caption = info.iShortCaption;
   213 
   217 
   214     HBufC* tempName = 0;
   218     HBufC* tempName = 0;
   215     if (!caption.Length() && windowName) // if not set - use thread name instead
   219     if (!caption.Length() && windowName) // if not set - use thread name instead
   216     {
   220     {
   218             tempName = windowName->Caption().AllocL();
   222             tempName = windowName->Caption().AllocL();
   219             //put on cleanupstack after the if
   223             //put on cleanupstack after the if
   220         }
   224         }
   221         else {
   225         else {
   222             TThreadId threadId;
   226             TThreadId threadId;
   223             TInt err = mWsSession.GetWindowGroupClientThreadId(wgId, threadId);
   227             TInt err = mResources.WsSession().GetWindowGroupClientThreadId(wgId, threadId);
   224             if (err == KErrNone) {
   228             if (err == KErrNone) {
   225                 RThread thread;
   229                 RThread thread;
   226                 CleanupClosePushL(thread);
   230                 CleanupClosePushL(thread);
   227                 err = thread.Open(threadId);
   231                 err = thread.Open(threadId);
   228                 if (err == KErrNone) {
   232                 if (err == KErrNone) {
   243 
   247 
   244 // --------------------------------------------------------------------------
   248 // --------------------------------------------------------------------------
   245 // CTsFswDataList::FitDataToListL
   249 // CTsFswDataList::FitDataToListL
   246 // --------------------------------------------------------------------------
   250 // --------------------------------------------------------------------------
   247 //
   251 //
   248 TBool CTsFswDataList::FitDataToListL(RTsFswArray& listToFit)
   252 void CTsFswDataList::FitDataToList(RTsFswArray& listToFit)
   249 {
   253 {
   250     TBool changed = EFalse;
   254     TBool changed = EFalse;
   251     TInt listCount = listToFit.Count();
   255     TInt listCount = listToFit.Count();
   252     TInt dataCount = mData.Count();
   256     TInt dataCount = mData.Count();
   253 
   257 
   270             changed = ETrue;
   274             changed = ETrue;
   271         }
   275         }
   272     }
   276     }
   273     //establish order
   277     //establish order
   274     TBool orderChanged = EstablishOrder(allKeys);
   278     TBool orderChanged = EstablishOrder(allKeys);
   275     changed = changed || orderChanged;
   279     if (changed || orderChanged) {
       
   280         mObserver.DataChanged();
       
   281     }
   276     allKeys.Close();
   282     allKeys.Close();
   277     return changed;
       
   278 }
   283 }
   279 
   284 
   280 // --------------------------------------------------------------------------
   285 // --------------------------------------------------------------------------
   281 // CTsFswDataList::CheckIfExists
   286 // CTsFswDataList::CheckIfExists
   282 // --------------------------------------------------------------------------
   287 // --------------------------------------------------------------------------
   300 {
   305 {
   301     bitmapArg = maskArg = NULL;
   306     bitmapArg = maskArg = NULL;
   302 
   307 
   303     TSize size(KAppIconWidth, KAppIconHeight);
   308     TSize size(KAppIconWidth, KAppIconHeight);
   304     CApaMaskedBitmap* apaMaskedBitmap = CApaMaskedBitmap::NewLC();
   309     CApaMaskedBitmap* apaMaskedBitmap = CApaMaskedBitmap::NewLC();
   305     TInt err = mAppArcSession.GetAppIcon(aAppUid, size, *apaMaskedBitmap);
   310     TInt err = mResources.ApaSession().GetAppIcon(aAppUid, size, *apaMaskedBitmap);
   306     TInt iconsCount(0);
   311     TInt iconsCount(0);
   307     if (err == KErrNone) {
   312     if (err == KErrNone) {
   308         err = mAppArcSession.NumberOfOwnDefinedIcons(aAppUid, iconsCount);
   313         err = mResources.ApaSession().NumberOfOwnDefinedIcons(aAppUid, iconsCount);
   309     }
   314     }
   310 
   315 
   311     if ((err == KErrNone) && (iconsCount > 0)) {
   316     if ((err == KErrNone) && (iconsCount > 0)) {
   312         bitmapArg = static_cast<CFbsBitmap*> (apaMaskedBitmap);
   317         bitmapArg = static_cast<CFbsBitmap*> (apaMaskedBitmap);
   313         TInt maskHandle = apaMaskedBitmap->Mask()->Handle();
   318         TInt maskHandle = apaMaskedBitmap->Mask()->Handle();
   316         CleanupStack::Pop(apaMaskedBitmap);
   321         CleanupStack::Pop(apaMaskedBitmap);
   317     }
   322     }
   318     else {
   323     else {
   319         CleanupStack::PopAndDestroy(apaMaskedBitmap);
   324         CleanupStack::PopAndDestroy(apaMaskedBitmap);
   320         HBufC* fileNameFromApparc = NULL;
   325         HBufC* fileNameFromApparc = NULL;
   321         TInt err = mAppArcSession.GetAppIcon(aAppUid, fileNameFromApparc);
   326         TInt err = mResources.ApaSession().GetAppIcon(aAppUid, fileNameFromApparc);
   322         if (err == KErrNone) {
   327         if (err == KErrNone) {
   323             CleanupStack::PushL(fileNameFromApparc);
   328             CleanupStack::PushL(fileNameFromApparc);
   324             CFbsBitmap *bitamp(0);
   329             CFbsBitmap *bitamp(0);
   325             CFbsBitmap *mask(0);
   330             CFbsBitmap *mask(0);
   326             TInt bitmapIndex = 0;
   331             TInt bitmapIndex = 0;
   376 
   381 
   377 // --------------------------------------------------------------------------
   382 // --------------------------------------------------------------------------
   378 // CTsFswDataList::SetScreenshotL
   383 // CTsFswDataList::SetScreenshotL
   379 // --------------------------------------------------------------------------
   384 // --------------------------------------------------------------------------
   380 //
   385 //
   381 TBool CTsFswDataList::SetScreenshotL(const CFbsBitmap* bitmap, UpdatePriority priority, TInt wgId)
   386 void CTsFswDataList::SetScreenshotL(const CFbsBitmap* bitmap, UpdatePriority priority, TInt wgId)
   382 {
   387 {
   383     RArray<RWsSession::TWindowGroupChainInfo> allWgIds;
   388     TInt pos = FindEntry(mData, GenerateKeyL(wgId));
   384     CleanupClosePushL(allWgIds);
   389     User::LeaveIfError(pos);
   385     User::LeaveIfError(mWsSession.WindowGroupList(0, &allWgIds));
   390     mData[pos]->SetScreenshotL(bitmap, priority);
   386     TTsEntryKey key = TsEntryKeyGeneraror::GenerateL(wgId, allWgIds.Array());
       
   387     TInt pos = FindEntry(mData, key);
       
   388     TBool updated(EFalse);
       
   389     if (pos >= 0) {
       
   390         updated = mData[pos]->SetScreenshotL(bitmap, priority);
       
   391     }
       
   392     else {
       
   393         User::Leave(KErrNotFound);
       
   394     }
       
   395     CleanupStack::PopAndDestroy(&allWgIds);
       
   396     return updated;
       
   397 }
   391 }
   398 
   392 
   399 // --------------------------------------------------------------------------
   393 // --------------------------------------------------------------------------
   400 // CTsFswDataList::RemoveScreenshotL
   394 // CTsFswDataList::RemoveScreenshotL
   401 // --------------------------------------------------------------------------
   395 // --------------------------------------------------------------------------
   402 //
   396 //
   403 TBool CTsFswDataList::RemoveScreenshotL(TInt wgId)
   397 void CTsFswDataList::RemoveScreenshotL(TInt wgId)
   404 {
   398 {
   405     RArray<RWsSession::TWindowGroupChainInfo> allWgIds;
   399     
   406     CleanupClosePushL(allWgIds);
   400     TInt pos = FindEntry(mData, GenerateKeyL(wgId));
   407     User::LeaveIfError(mWsSession.WindowGroupList(0, &allWgIds));
   401     User::LeaveIfError(pos);
   408     TTsEntryKey key = TsEntryKeyGeneraror::GenerateL(wgId, allWgIds.Array());
   402     mData[pos]->RemoveScreenshotL();
   409     TInt pos = FindEntry(mData, key);
       
   410     TBool updated(EFalse);
       
   411     if (pos >= 0) {
       
   412         updated = mData[pos]->RemoveScreenshot();
       
   413     }
       
   414     else {
       
   415         User::Leave(KErrNotFound);
       
   416     }
       
   417     CleanupStack::PopAndDestroy(&allWgIds);
       
   418     return updated;
       
   419 }
   403 }
   420 
   404 
   421 // --------------------------------------------------------------------------
   405 // --------------------------------------------------------------------------
   422 // CTsFswDataList::EstablishOrder
   406 // CTsFswDataList::EstablishOrder
   423 // --------------------------------------------------------------------------
   407 // --------------------------------------------------------------------------
   443 
   427 
   444 // --------------------------------------------------------------------------
   428 // --------------------------------------------------------------------------
   445 // CTsFswDataList::GetAllowedUidsL
   429 // CTsFswDataList::GetAllowedUidsL
   446 // --------------------------------------------------------------------------
   430 // --------------------------------------------------------------------------
   447 //
   431 //
   448 void CTsFswDataList::GetAllowedUidsL()
   432 TBool CTsFswDataList::VerifyApplicationL(TUid uid)
   449 {
   433 {
   450     mAllowedUids.Close();
   434     TBool retVal(EFalse);
   451     TApaAppInfo* appInfo = new (ELeave) TApaAppInfo();
   435     TApaAppInfo appInfo;
   452     CleanupStack::PushL(appInfo);
       
   453     TApaAppCapabilityBuf appCap;
   436     TApaAppCapabilityBuf appCap;
   454 
   437 
   455     User::LeaveIfError(mAppArcSession.GetAllApps(0));
   438     User::LeaveIfError(mResources.ApaSession().GetAllApps(0));
   456     // for every application get uid, hidden and missing attribute
   439     // for every application get uid, hidden and missing attribute
   457     // and add to aArray.
   440     // and add to aArray.
   458     while (KErrNone == mAppArcSession.GetNextApp(*appInfo)) {
   441     while (KErrNone == mResources.ApaSession().GetNextApp(appInfo)) {
   459         TUid uid = appInfo->iUid;
   442         User::LeaveIfError(mResources.ApaSession().GetAppCapability(appCap, appInfo.iUid));
   460         User::LeaveIfError(mAppArcSession.GetAppCapability(appCap, uid));
   443         if(!appCap().iAppIsHidden) {
   461         // do not add hidden app and with null uid.
   444             if (uid == appInfo.iUid) {
   462         if (!appCap().iAppIsHidden && !IsHiddenUid(uid) && uid.iUid) {
   445                 retVal = ETrue;
   463             mAllowedUids.AppendL(uid);
   446                 mAllowedUids.InsertL(appInfo.iUid, mAllowedUids.Count());
   464         }
   447             }
   465     }
   448         } else if(KErrNotFound == mHiddenUids.Find(appInfo.iUid)) {
   466     CleanupStack::PopAndDestroy(appInfo);
   449             mHiddenUids.InsertL(appInfo.iUid, mHiddenUids.Count());
   467 }
   450         }
   468 
   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 }
   469 // end of file
   493 // end of file