diff -r 000000000000 -r 79c6a41cd166 menucontentsrv/srvsrc/mcsdrmscanner.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/menucontentsrv/srvsrc/mcsdrmscanner.cpp Thu Dec 17 08:54:17 2009 +0200 @@ -0,0 +1,385 @@ +/* +* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: The API supports attributes not present in MCS from SAT Api +* +*/ + + +#include "mcsdrmscanner.h" +#include "menueng.h" +#include "menusrveng.h" +#include "menuengobject.h" +#include "menusrvengutils.h" + +// ============================ MEMBER FUNCTIONS ============================= + +// --------------------------------------------------------------------------- +// Creates an instance of CMcsDrmScanner implementation +// --------------------------------------------------------------------------- +// +CMcsDrmScanner* CMcsDrmScanner::NewL( + MMcsDrmAppScanner& aObserver, + CMenuSrvEng& aSrvEng, + CMenuSrvEngUtils& aUtils ) + { + CMcsDrmScanner* self = new (ELeave) CMcsDrmScanner( + aObserver, aSrvEng, aUtils ); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + + return self; + } + + +// --------------------------------------------------------------------------- +// Destructor +// --------------------------------------------------------------------------- +// +CMcsDrmScanner::~CMcsDrmScanner() + { + Cancel(); + iSrvEng.Engine().DequeueOperation( *this ); + iNotProtectedAppArray.Close(); + iDrmExpiredAppArray.Close(); + iDrmProtectedAppArray.Close(); + iChangedAppArray.Close(); + } + +// ----------------------------------------------------------------------------- +// CMcsDrmScanner::CMcsDrmScanner +// C++ default constructor +// ----------------------------------------------------------------------------- +// +CMcsDrmScanner::CMcsDrmScanner( + MMcsDrmAppScanner& aObserver, + CMenuSrvEng& aSrvEng, + CMenuSrvEngUtils& aUtils ): + CActive( EPriorityNormal ), iObserver( aObserver ), + iSrvEng( aSrvEng ), iUtils( aUtils ) + { + CActiveScheduler::Add( this ); + iOpStatus = EFalse; + } + +// ----------------------------------------------------------------------------- +// CMcsDrmScanner::ConstructL +// S2nd phase constructor. +// ----------------------------------------------------------------------------- +// +void CMcsDrmScanner::ConstructL() + { + Scan(); + } + +// --------------------------------------------------------------------------- +// CMcsDrmScanner::DoCancel +// --------------------------------------------------------------------------- +// +void CMcsDrmScanner::DoCancel() + { + } + +// --------------------------------------------------------------------------- +// CMcsDrmScanner::RunL +// --------------------------------------------------------------------------- +// +void CMcsDrmScanner::RunL() + { + User::LeaveIfError( iStatus.Int() ); // Handle errors in RunL. + iSrvEng.Engine().QueueOperationL( *this ); + } + +// --------------------------------------------------------- +// CMcsDrmScanner::RunError() +// --------------------------------------------------------- +// +TInt CMcsDrmScanner::RunError( TInt /*aError*/ ) + { + // Ignore the error (what else could we do?). + return KErrNone; + } + +// --------------------------------------------------------- +// CMcsDrmScanner::RunMenuEngOperationL +// --------------------------------------------------------- +// +void CMcsDrmScanner::RunMenuEngOperationL() + { + ScanDrmApplicationsL(); + iOpStatus = EFalse; + } + +// --------------------------------------------------------- +// CMcsDrmScanner::CompletedMenuEngOperation +// --------------------------------------------------------- +// +void CMcsDrmScanner::CompletedMenuEngOperation( TInt /*aErr*/ ) + { + } + +// --------------------------------------------------------- +// +// --------------------------------------------------------- +// +void CMcsDrmScanner::GetAppItemsL( + RArray& aItemArray, + RArray& aAppItemArray ) + { + //for every item in apaAndCrItems array + CMenuEng& eng = iSrvEng.Engine(); + for ( TInt i = 0; i& aAppItemArray, + RArray& aUidArray ) + { + for ( TInt i = 0; i& aArrayToModify, + const RArray& aUidArray ) + { + TInt index = 0; + TBool changed = EFalse; + while ( index < aArrayToModify.Count() ) + { + if ( aUidArray.Find( aArrayToModify[index] ) == KErrNotFound ) + { + aArrayToModify.Remove( index ); + changed = ETrue; + } + else + { + index++; + } + } + return changed; + } + + +// --------------------------------------------------------- +// +// --------------------------------------------------------- +// +TBool CMcsDrmScanner::RemoveChangedApps( ) + { + TBool changed = EFalse; + for( TInt i = 0; i< iChangedAppArray.Count(); i++ ) + { + TInt index = iDrmExpiredAppArray.Find( iChangedAppArray[i] ); + if ( index != KErrNotFound ) + { + iDrmExpiredAppArray.Remove( index ); + changed = ETrue; + } + index = iDrmProtectedAppArray.Find( iChangedAppArray[i] ); + if ( index != KErrNotFound ) + { + iDrmProtectedAppArray.Remove( index ); + changed = ETrue; + } + } + iChangedAppArray.Reset(); + return changed; + } + +// --------------------------------------------------------- +// +// --------------------------------------------------------- +// +TBool CMcsDrmScanner::RemoveMissingApps( const RArray& aUidArray ) + { + RemoveNotExistingApps( iNotProtectedAppArray, aUidArray ); + + TBool expiredChanged = + RemoveNotExistingApps( iDrmExpiredAppArray, aUidArray ); + + TBool protectedChanged = + RemoveNotExistingApps( iDrmProtectedAppArray, aUidArray ); + + TInt changed = EFalse; + if ( expiredChanged || protectedChanged ) + { + changed = ETrue; + } + return changed; + } + +// --------------------------------------------------------- +// +// --------------------------------------------------------- +// +TBool CMcsDrmScanner::CheckDrmAppsL( const RArray& aUidArray ) + { + TInt changed = EFalse; + + for ( TInt i = 0; i mcsItems; + CleanupClosePushL( mcsItems ); + GetMcsAppItemsL( mcsItems ); + + RArray appArray; + CleanupClosePushL( appArray ); + + GetAppItemsL( mcsItems, appArray ); + + RArray uidArray; + CleanupClosePushL( uidArray ); + + GetUidsL( appArray, uidArray ); + + TBool removeChanged = RemoveChangedApps( ); + + TBool removeMissing = RemoveMissingApps( uidArray ); + + TBool drmChanged = CheckDrmAppsL( appArray ); + + CleanupStack::PopAndDestroy( &uidArray ); + CleanupStack::PopAndDestroy( &appArray ); + CleanupStack::PopAndDestroy( &mcsItems ); + + if ( removeChanged || removeMissing || drmChanged ) + { + iObserver.HandleDrmAppEvent(); + } + iOpStatus = EFalse; + } + +// --------------------------------------------------------- +// CMcsDrmScanner::GetMcsItemsL +// --------------------------------------------------------- +// +void CMcsDrmScanner::GetMcsAppItemsL( RArray& aArray ) + { + TInt root; + iSrvEng.Engine().RootFolderL( root ); + TMenuSrvTypeFilter appFilter; + appFilter.SetType( KMenuTypeApp() ); + iSrvEng.Engine().GetItemsL( aArray, root, &appFilter, ETrue ); + } + +// --------------------------------------------------------- +// +// --------------------------------------------------------- +// +const RArray& CMcsDrmScanner::DrmExpiredAppArray() + { + return iDrmExpiredAppArray; + } + +// --------------------------------------------------------- +// +// --------------------------------------------------------- +// +const RArray& CMcsDrmScanner::DrmProtectedAppArray() + { + return iDrmProtectedAppArray; + } + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +void CMcsDrmScanner::Scan() + { + if ( !IsActive() && !iOpStatus ) + { + iOpStatus = ETrue; + TRequestStatus* ownStatus = &iStatus; + *ownStatus = KRequestPending; + SetActive(); + User::RequestComplete( ownStatus, KErrNone ); + } + } + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +void CMcsDrmScanner::RemoveObserverAndScanL( TUid aUid ) + { + iChangedAppArray.AppendL( aUid ); + Scan( ); + } + +// End of File