menucontentsrv/srvsrc/mcsdrmhandler.cpp
changeset 0 79c6a41cd166
child 118 8baec10861af
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  Used for receive SIM Application name, icon or 
       
    15 *                visibility information.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <sacls.h>
       
    23 #include <javaregistry.h>
       
    24 #include <javaregistrypackageentry.h>
       
    25 #include <javaregistryapplicationentry.h>
       
    26 #include <javadomainpskeys.h>
       
    27 #include "mcsdrmhandler.h"
       
    28 #include "mcsdrmscanner.h"
       
    29 #include "mcsmenunotifier.h"
       
    30 #include "menueng.h"
       
    31 #include "menusrveng.h"
       
    32 #include "menusrvengutils.h"
       
    33 #include "mcscachehandler.h"
       
    34 #include "mcsdef.h"
       
    35 
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ===============================
       
    38 // -----------------------------------------------------------------------------
       
    39 // CMcsDrmHandler::NewL
       
    40 // Two-phased constructor.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 
       
    44 CMcsDrmHandler* CMcsDrmHandler::NewL( 
       
    45     CMenuSrvEng& aSrvEng,
       
    46     CMenuSrvEngUtils& aUtils,
       
    47     CMcsCacheHandler& aCacheHandler )
       
    48     {
       
    49     CMcsDrmHandler* self = new( ELeave ) 
       
    50             CMcsDrmHandler( aSrvEng, aUtils, aCacheHandler );
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL();
       
    53     CleanupStack::Pop( self );
       
    54     return self;
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------    
       
    58 // Destructor
       
    59 // -----------------------------------------------------------------------------
       
    60 CMcsDrmHandler::~CMcsDrmHandler()
       
    61     {
       
    62     delete iInstallNotifier;
       
    63     delete iScanner;
       
    64     iObserversManager.Close();
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CMcsDrmHandler::CMcsDrmHandler
       
    69 // C++ default constructor can NOT contain any code, that
       
    70 // might leave.
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CMcsDrmHandler::CMcsDrmHandler( 
       
    74     CMenuSrvEng& aSrvEng,
       
    75     CMenuSrvEngUtils& aUtils,
       
    76     CMcsCacheHandler& aCacheHandler ): 
       
    77     iObserversManager( aUtils ), iSrvEng( aSrvEng ),
       
    78     iUtils( aUtils ), iCacheHandler( aCacheHandler )
       
    79     {
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CMcsDrmHandler::ConstructL
       
    84 // Symbian 2nd phase constructor can leave.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 void CMcsDrmHandler::ConstructL()
       
    88     {
       
    89     iScanner = CMcsDrmScanner::NewL( *this, iSrvEng, iUtils );
       
    90 	iInstallNotifier = CMcsInstallNotifier::NewL(*this, KPSUidJavaLatestInstallation);
       
    91 
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // -----------------------------------------------------------------------------
       
    96 //    
       
    97 TInt CMcsDrmHandler::AppFolderIdL( TUid aUid )
       
    98     {
       
    99     RArray<TMenuItem> mcsItems; 
       
   100     CleanupClosePushL( mcsItems );
       
   101     
       
   102     TInt root;
       
   103     iSrvEng.Engine().RootFolderL( root );
       
   104     TMenuSrvTypeAttrFilter appFilter;
       
   105     appFilter.SetType( KMenuTypeApp() );   
       
   106     
       
   107     TBuf<KUidChars> uidString;
       
   108     MenuSrvUtil::UidToStringL( aUid.iUid, uidString, 0, EHex );
       
   109     
       
   110     appFilter.SetAttr( KMenuAttrUid(), uidString );
       
   111     iSrvEng.Engine().GetItemsL( mcsItems, root, &appFilter, ETrue );
       
   112     
       
   113     TInt folderId = KErrNotFound;
       
   114     if (mcsItems.Count())
       
   115         {
       
   116         folderId = mcsItems[0].Parent();
       
   117         iCacheHandler.HandleRemoveAttribute(mcsItems[0].Id(), KMenuAttrDrmProtection);
       
   118         }
       
   119     
       
   120     CleanupStack::PopAndDestroy( &mcsItems );
       
   121     return folderId;
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // -----------------------------------------------------------------------------
       
   126 //     
       
   127 void CMcsDrmHandler::HandleDrmEvent( TUid aUid )
       
   128     {
       
   129     TRAP_IGNORE(
       
   130     		iSrvEng.Engine().AppendNotifyL( AppFolderIdL( aUid ), 
       
   131     				RMenuNotifier::EItemAttributeChanged );
       
   132     		iScanner->RemoveObserverAndScanL( aUid );
       
   133 				);
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // -----------------------------------------------------------------------------
       
   138 //     
       
   139 void CMcsDrmHandler::HandleDrmAppEvent()
       
   140     {
       
   141     TRAP_IGNORE( AddRemoveObserversL(
       
   142         iScanner->DrmProtectedAppArray() ) );     
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // -----------------------------------------------------------------------------
       
   147 //     
       
   148 void CMcsDrmHandler::AddRemoveObserversL( 
       
   149 	const RArray<TUid>& aDrmProtectedArray )
       
   150     {
       
   151     iObserversManager.RemoveMissingObservers( aDrmProtectedArray );    
       
   152     iObserversManager.CreateObserversL( aDrmProtectedArray, *this );
       
   153     }    
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // -----------------------------------------------------------------------------
       
   157 //        
       
   158 void CMcsDrmHandler::EngineEvents( TInt /*aFolder*/, TInt aEvents )
       
   159     {
       
   160     if ( aEvents & RMenuNotifier::EItemsAddedRemoved )
       
   161         {
       
   162         iScanner->Scan();
       
   163         }    
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------
       
   167 // CMcsDrmHandler::HandleInstallNotifyL
       
   168 // ---------------------------------------------------------
       
   169 //
       
   170 void CMcsDrmHandler::HandleInstallNotifyL( TInt aPackageUid )
       
   171 	{
       
   172 	RArray<TUid> uids;
       
   173 	CleanupClosePushL( uids );
       
   174 
       
   175 	Java::CJavaRegistry* javaRegistry;
       
   176 	javaRegistry = Java::CJavaRegistry::NewLC();
       
   177 
       
   178 	Java::CJavaRegistryEntry* regEntry = 
       
   179 		javaRegistry->RegistryEntryL( TUid::Uid(aPackageUid) );
       
   180 
       
   181 	if( regEntry )
       
   182 		{
       
   183 	CleanupStack::PushL( regEntry );
       
   184 
       
   185 	Java::TJavaRegistryEntryType entryType = regEntry->Type();
       
   186 	
       
   187 	if ( ( entryType >= Java::EGeneralPackage ) && 
       
   188 			(entryType < Java::EGeneralApplication) )
       
   189 		{
       
   190 		//package entry
       
   191 		Java::CJavaRegistryPackageEntry* regPackageEntry = 
       
   192 					static_cast<Java::CJavaRegistryPackageEntry*>( regEntry );
       
   193 			regPackageEntry->GetEmbeddedEntries( uids );
       
   194 			}
       
   195 		else 
       
   196 			{
       
   197 			//application entry
       
   198 			uids.AppendL( regEntry->Uid() );
       
   199 			}
       
   200 		
       
   201 		CleanupStack::PopAndDestroy( regEntry );
       
   202 	    for ( TInt i = 0; i< uids.Count(); i++ )
       
   203 	        {
       
   204 	        if ( ( iScanner->DrmExpiredAppArray()).Find(uids[i]) != KErrNotFound )
       
   205 	            {
       
   206 	            HandleDrmEvent( uids[i] );
       
   207 	            }
       
   208 	        else
       
   209 	            {
       
   210 	            iObserversManager.RefreshObserverL( iScanner->DrmProtectedAppArray(), 
       
   211 	                    uids[i], *this );
       
   212 	            }
       
   213 	        }
       
   214 		}
       
   215 	else
       
   216 	    {
       
   217 	    for ( TInt i = 0; i< iScanner->DrmProtectedAppArray().Count(); i++ )
       
   218 	        {
       
   219             iObserversManager.RefreshObserverL( iScanner->DrmProtectedAppArray(), 
       
   220         		   iScanner->DrmProtectedAppArray()[i], *this );
       
   221 	        }
       
   222 	    for ( TInt i = 0; i< iScanner->DrmExpiredAppArray().Count(); i++ )
       
   223 	        {
       
   224 	        HandleDrmEvent( iScanner->DrmExpiredAppArray()[i] );
       
   225 	        }	    
       
   226 	    }
       
   227 	
       
   228 	
       
   229 	CleanupStack::PopAndDestroy( javaRegistry );
       
   230 	CleanupStack::PopAndDestroy( &uids );
       
   231     }
       
   232 
       
   233 
       
   234 //  End of File