menucontentsrv/srvsrc/mcsdrmscanner.cpp
changeset 85 7feec50967db
parent 4 1a2a00e78665
child 86 e492551a0d54
equal deleted inserted replaced
4:1a2a00e78665 85:7feec50967db
     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:  The API supports attributes not present in MCS from SAT Api
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "mcsdrmscanner.h"
       
    20 #include "menueng.h"
       
    21 #include "menusrveng.h"
       
    22 #include "menuengobject.h"
       
    23 #include "menusrvengutils.h"
       
    24 
       
    25 // ============================ MEMBER FUNCTIONS =============================
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // Creates an instance of CMcsDrmScanner implementation
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 CMcsDrmScanner* CMcsDrmScanner::NewL( 
       
    32     MMcsDrmAppScanner& aObserver, 
       
    33     CMenuSrvEng& aSrvEng,
       
    34     CMenuSrvEngUtils& aUtils )
       
    35     {
       
    36     CMcsDrmScanner* self = new (ELeave) CMcsDrmScanner( 
       
    37         aObserver, aSrvEng, aUtils );
       
    38     CleanupStack::PushL( self );
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop( self );
       
    41     
       
    42     return self;
       
    43     }
       
    44 
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // Destructor
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CMcsDrmScanner::~CMcsDrmScanner()
       
    51     {
       
    52     Cancel();
       
    53     iSrvEng.Engine().DequeueOperation( *this );
       
    54     iNotProtectedAppArray.Close();
       
    55     iDrmExpiredAppArray.Close();
       
    56     iDrmProtectedAppArray.Close();
       
    57     iChangedAppArray.Close();
       
    58     }
       
    59     
       
    60 // -----------------------------------------------------------------------------
       
    61 // CMcsDrmScanner::CMcsDrmScanner
       
    62 // C++ default constructor
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 CMcsDrmScanner::CMcsDrmScanner( 
       
    66     MMcsDrmAppScanner& aObserver, 
       
    67     CMenuSrvEng& aSrvEng,
       
    68     CMenuSrvEngUtils& aUtils ): 
       
    69     CActive( EPriorityNormal ), iObserver( aObserver ), 
       
    70     iSrvEng( aSrvEng ), iUtils( aUtils )
       
    71     {    
       
    72     CActiveScheduler::Add( this );
       
    73     iOpStatus = EFalse;
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CMcsDrmScanner::ConstructL
       
    78 // S2nd phase constructor.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 void CMcsDrmScanner::ConstructL()
       
    82     {
       
    83     Scan();
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // CMcsDrmScanner::DoCancel
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 void CMcsDrmScanner::DoCancel()
       
    91     {
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CMcsDrmScanner::RunL
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 void CMcsDrmScanner::RunL()
       
    99     {
       
   100     User::LeaveIfError( iStatus.Int() ); // Handle errors in RunL.
       
   101     iSrvEng.Engine().QueueOperationL( *this );    
       
   102     }    
       
   103 
       
   104 // ---------------------------------------------------------
       
   105 // CMcsDrmScanner::RunError()
       
   106 // ---------------------------------------------------------
       
   107 //
       
   108 TInt CMcsDrmScanner::RunError( TInt /*aError*/ )
       
   109     {
       
   110     // Ignore the error (what else could we do?).
       
   111     return KErrNone;
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------
       
   115 // CMcsDrmScanner::RunMenuEngOperationL
       
   116 // ---------------------------------------------------------
       
   117 //
       
   118 void CMcsDrmScanner::RunMenuEngOperationL()
       
   119     {
       
   120     ScanDrmApplicationsL();
       
   121     iOpStatus = EFalse;
       
   122     }  
       
   123     
       
   124 // ---------------------------------------------------------
       
   125 // CMcsDrmScanner::CompletedMenuEngOperation
       
   126 // ---------------------------------------------------------
       
   127 //
       
   128 void CMcsDrmScanner::CompletedMenuEngOperation( TInt /*aErr*/ )
       
   129     {
       
   130     }          
       
   131 
       
   132 // ---------------------------------------------------------
       
   133 // 
       
   134 // ---------------------------------------------------------
       
   135 //
       
   136 void CMcsDrmScanner::GetAppItemsL( 
       
   137     RArray<TMenuItem>& aItemArray, 
       
   138     RArray<TAppItem>& aAppItemArray )
       
   139     {
       
   140     //for every item in apaAndCrItems array
       
   141     CMenuEng& eng = iSrvEng.Engine();
       
   142     for ( TInt i = 0; i<aItemArray.Count(); i++ )
       
   143         {        
       
   144         TUid appUid;
       
   145         if ( KErrNone == 
       
   146             CMenuSrvEngUtils::GetAppUid( 
       
   147             	eng.ObjectL(aItemArray[i].Id()), appUid) )
       
   148             {
       
   149             TAppItem appItem( aItemArray[i].Id(), appUid );
       
   150             aAppItemArray.AppendL(appItem);        
       
   151             }        
       
   152         }
       
   153     }
       
   154 
       
   155 // ---------------------------------------------------------
       
   156 // 
       
   157 // ---------------------------------------------------------
       
   158 //
       
   159 void CMcsDrmScanner::GetUidsL( 
       
   160     RArray<TAppItem>& aAppItemArray, 
       
   161     RArray<TUid>& aUidArray )
       
   162     {
       
   163     for ( TInt i = 0; i<aAppItemArray.Count(); i++ )
       
   164         {  
       
   165         aUidArray.AppendL( aAppItemArray[i].Uid() );               
       
   166         }
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------
       
   170 // 
       
   171 // ---------------------------------------------------------
       
   172 //
       
   173 TBool CMcsDrmScanner::RemoveNotExistingApps( 
       
   174     RArray<TUid>& aArrayToModify, 
       
   175     const RArray<TUid>& aUidArray )
       
   176     {  
       
   177     TInt index = 0;
       
   178     TBool changed = EFalse;
       
   179     while ( index < aArrayToModify.Count() )
       
   180         {
       
   181         if ( aUidArray.Find( aArrayToModify[index] ) == KErrNotFound )
       
   182             {
       
   183             aArrayToModify.Remove( index );
       
   184             changed = ETrue;
       
   185             }
       
   186         else
       
   187             {
       
   188             index++;
       
   189             }       
       
   190         }
       
   191     return changed;
       
   192     }        
       
   193 
       
   194 
       
   195 // ---------------------------------------------------------
       
   196 // 
       
   197 // ---------------------------------------------------------
       
   198 //
       
   199 TBool CMcsDrmScanner::RemoveChangedApps( )
       
   200     {   
       
   201     TBool changed = EFalse;
       
   202     for( TInt i = 0; i< iChangedAppArray.Count(); i++ )
       
   203     	{
       
   204     	TInt index = iDrmExpiredAppArray.Find( iChangedAppArray[i] );
       
   205         if ( index != KErrNotFound )
       
   206                {
       
   207                iDrmExpiredAppArray.Remove( index );
       
   208                changed = ETrue;
       
   209                }
       
   210     	index = iDrmProtectedAppArray.Find( iChangedAppArray[i] );
       
   211         if ( index != KErrNotFound )
       
   212                {
       
   213                iDrmProtectedAppArray.Remove( index );
       
   214                changed = ETrue;
       
   215                }   	
       
   216     	}
       
   217     iChangedAppArray.Reset();
       
   218     return changed;
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------
       
   222 // 
       
   223 // ---------------------------------------------------------
       
   224 //
       
   225 TBool CMcsDrmScanner::RemoveMissingApps( const RArray<TUid>& aUidArray )
       
   226     {    
       
   227     RemoveNotExistingApps( iNotProtectedAppArray, aUidArray );    
       
   228     
       
   229     TBool expiredChanged = 
       
   230         RemoveNotExistingApps( iDrmExpiredAppArray, aUidArray );    
       
   231         
       
   232     TBool protectedChanged = 
       
   233         RemoveNotExistingApps( iDrmProtectedAppArray, aUidArray );    
       
   234 
       
   235     TInt changed = EFalse;
       
   236     if ( expiredChanged || protectedChanged )
       
   237         {
       
   238         changed = ETrue;
       
   239         }
       
   240     return changed;
       
   241     }
       
   242 
       
   243 // ---------------------------------------------------------
       
   244 // 
       
   245 // ---------------------------------------------------------
       
   246 //
       
   247 TBool CMcsDrmScanner::CheckDrmAppsL( const RArray<TAppItem>& aUidArray )
       
   248     {    
       
   249     TInt changed = EFalse;
       
   250     
       
   251     for ( TInt i = 0; i<aUidArray.Count(); i++ )
       
   252         {                        
       
   253         if ( iNotProtectedAppArray.Find( aUidArray[i].Uid() ) == KErrNotFound )
       
   254             {
       
   255             if ( iDrmProtectedAppArray.Find( aUidArray[i].Uid() ) == KErrNotFound &&
       
   256                 iDrmExpiredAppArray.Find( aUidArray[i].Uid() ) == KErrNotFound )
       
   257                 {
       
   258 		        TBool attrExists;
       
   259 		        RBuf attrVal;
       
   260         	    attrVal.CleanupClosePushL();
       
   261         	    attrVal.CreateL(KMenuMaxAttrValueLen);
       
   262         	    
       
   263                 iSrvEng.GetAttributeL( 
       
   264                     aUidArray[i].Id(), 
       
   265                     KMenuAttrDrmProtection,
       
   266                     attrExists,
       
   267                     attrVal );
       
   268 
       
   269                 if ( attrVal == KMenuDrmProtected )
       
   270                     {                       
       
   271                     iDrmProtectedAppArray.AppendL( aUidArray[i].Uid() );
       
   272                     changed = ETrue;
       
   273                     }
       
   274                 else if ( attrVal == KMenuDrmRightsExpired )
       
   275                     {       
       
   276                     iDrmExpiredAppArray.AppendL( aUidArray[i].Uid() );
       
   277                     changed = ETrue;    
       
   278                     }
       
   279                 else
       
   280                     {
       
   281                     iNotProtectedAppArray.AppendL( aUidArray[i].Uid() );        
       
   282                     }     
       
   283                 CleanupStack::PopAndDestroy( &attrVal );                   
       
   284                 }                                    
       
   285             }
       
   286         }
       
   287     
       
   288     return changed;
       
   289     }
       
   290     
       
   291 // ---------------------------------------------------------
       
   292 // CMcsDrmScanner::GetMcsItemsL
       
   293 // ---------------------------------------------------------
       
   294 //
       
   295 void CMcsDrmScanner::ScanDrmApplicationsL()
       
   296     {    
       
   297     RArray<TMenuItem> mcsItems; 
       
   298     CleanupClosePushL( mcsItems );
       
   299     GetMcsAppItemsL( mcsItems );
       
   300           
       
   301     RArray<TAppItem> appArray;
       
   302     CleanupClosePushL( appArray );
       
   303     
       
   304     GetAppItemsL( mcsItems, appArray );
       
   305     
       
   306     RArray<TUid> uidArray;
       
   307     CleanupClosePushL( uidArray );
       
   308     
       
   309     GetUidsL( appArray, uidArray );
       
   310     
       
   311     TBool removeChanged = RemoveChangedApps( );     
       
   312     
       
   313     TBool removeMissing = RemoveMissingApps( uidArray );     
       
   314     
       
   315     TBool drmChanged = CheckDrmAppsL( appArray );
       
   316     
       
   317     CleanupStack::PopAndDestroy( &uidArray );        
       
   318     CleanupStack::PopAndDestroy( &appArray );
       
   319     CleanupStack::PopAndDestroy( &mcsItems );
       
   320     
       
   321     if ( removeChanged || removeMissing || drmChanged )
       
   322         {
       
   323         iObserver.HandleDrmAppEvent();    
       
   324         }        
       
   325     iOpStatus = EFalse;
       
   326     }
       
   327 
       
   328 // ---------------------------------------------------------
       
   329 // CMcsDrmScanner::GetMcsItemsL
       
   330 // ---------------------------------------------------------
       
   331 //
       
   332 void CMcsDrmScanner::GetMcsAppItemsL( RArray<TMenuItem>& aArray )
       
   333     {
       
   334     TInt root;
       
   335     iSrvEng.Engine().RootFolderL( root );
       
   336     TMenuSrvTypeFilter appFilter;
       
   337     appFilter.SetType( KMenuTypeApp() );
       
   338     iSrvEng.Engine().GetItemsL( aArray, root, &appFilter, ETrue );
       
   339     }
       
   340 
       
   341 // ---------------------------------------------------------
       
   342 //
       
   343 // ---------------------------------------------------------
       
   344 //
       
   345 const RArray<TUid>& CMcsDrmScanner::DrmExpiredAppArray()
       
   346     {
       
   347     return iDrmExpiredAppArray;
       
   348     }
       
   349 
       
   350 // ---------------------------------------------------------
       
   351 //
       
   352 // ---------------------------------------------------------
       
   353 //
       
   354 const RArray<TUid>& CMcsDrmScanner::DrmProtectedAppArray()
       
   355     {
       
   356     return iDrmProtectedAppArray;
       
   357     }
       
   358 
       
   359 // -----------------------------------------------------------------------------
       
   360 // 
       
   361 // -----------------------------------------------------------------------------
       
   362 //
       
   363 void CMcsDrmScanner::Scan()
       
   364     {
       
   365     if ( !IsActive() && !iOpStatus )
       
   366         {
       
   367         iOpStatus = ETrue;
       
   368         TRequestStatus* ownStatus = &iStatus;
       
   369         *ownStatus = KRequestPending;
       
   370         SetActive();
       
   371         User::RequestComplete( ownStatus, KErrNone );
       
   372         } 
       
   373     }  
       
   374 
       
   375 // -----------------------------------------------------------------------------
       
   376 // 
       
   377 // -----------------------------------------------------------------------------
       
   378 //
       
   379 void CMcsDrmScanner::RemoveObserverAndScanL( TUid aUid )
       
   380     {
       
   381     iChangedAppArray.AppendL( aUid );
       
   382     Scan( );
       
   383     }
       
   384     
       
   385 // End of File