messagingfw/senduiservices/watcher/src/senduiwatcher.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 /*
       
     2 * Copyright (c) 2006 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:   Launches SendUiServiceResolver in the events of:
       
    15 *                At all times:
       
    16 *                - mtm installation/removal
       
    17 *                - Message Server events:
       
    18 *                    * EMsvEntryCreated
       
    19 *                    * EMsvEntryDeleted
       
    20 *                    * EMsvCorruptedIndexRebuilt
       
    21 *                    * EMsvMediaChanged
       
    22 *                - Ecom service event arrives and SendUI Ecom service count has 
       
    23 *                  changed since last boot.
       
    24 *
       
    25 */
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 #include <implementationproxy.h>
       
    31 #include <msvapi.h>
       
    32 #include <data_caging_path_literals.hrh> 
       
    33 #include <msvids.h>                     // for KMsvRootIndexEntryId
       
    34 #include <coemain.h>
       
    35 #include <apgcli.h>
       
    36 #include <apacmdln.h>
       
    37 #include <eikdll.h>
       
    38 #include <apaflrec.h>
       
    39 #include <bldvariant.hrh>
       
    40 #include <e32property.h>
       
    41 #include <e32base.h>
       
    42 #include <centralrepository.h>
       
    43 #include <mtudreg.h>
       
    44 #include <featmgr.h>
       
    45 
       
    46 #include "senduiwatcher.h"
       
    47 #include "senduiecomobserver.h"
       
    48 #include "senduipropertyobserver.h"
       
    49 #include "senduiproperty.h"
       
    50 #include "SendUiPrivateCRKeys.h"
       
    51 #include "senduiserviceslog.h"
       
    52 
       
    53 _LIT( KSendUiLauncherApp, "SendUiServiceResolver.exe");
       
    54 
       
    55 const TImplementationProxy ImplementationTable[] = 
       
    56     {
       
    57     IMPLEMENTATION_PROXY_ENTRY( 0x102823B6, CSendUiWatcher::NewL )
       
    58     };
       
    59 
       
    60 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
    61     {
       
    62     aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy );
       
    63     return ImplementationTable;
       
    64     }
       
    65 
       
    66 
       
    67 // ======== LOCAL FUNCTIONS ========
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // NewL
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CSendUiWatcher* CSendUiWatcher::NewL( TAny* /*aWatcherParams */)
       
    74     {
       
    75     CSendUiWatcher* self=new (ELeave) CSendUiWatcher();
       
    76     CleanupStack::PushL(self);
       
    77     self->ConstructL();
       
    78     CleanupStack::Pop(self);
       
    79     return self;
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // Destructor
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 CSendUiWatcher::~CSendUiWatcher()
       
    87     {
       
    88     delete iPropertyObserver;
       
    89     delete iTimer;
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // DoTask
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 TInt CSendUiWatcher::DoTaskL( TAny* aThis )
       
    97 	{
       
    98     LOGTEXT(_L("CSendUiWatcher::DoTask >>"));
       
    99     CSendUiWatcher* watcher = static_cast<CSendUiWatcher*>( aThis );
       
   100     // We've waited long enough. Try to set to done. Ignore error.
       
   101     RProperty::Set(
       
   102         KPSUidSendUiProperty, 
       
   103         KSendUiUpdateOperation, 
       
   104         KSendUiUpdateOperationDone );
       
   105     watcher->HandleUpdateServicesL();
       
   106     LOGTEXT(_L("CSendUiWatcher::DoTask <<"));
       
   107 	return KErrNone;
       
   108 	}
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // HandleUpdateServicesL
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void CSendUiWatcher::HandleUpdateServicesL()
       
   115     {
       
   116     LOGTEXT(_L("CSendUiWatcher::HandleUpdateServicesL >>"));
       
   117     TInt value;
       
   118     delete iTimer;
       
   119 	iTimer = NULL;
       
   120 
       
   121     RProperty::Get( KPSUidSendUiProperty, KSendUiUpdateOperation, value );
       
   122     if ( value != KSendUiUpdateOperationDone )
       
   123         {
       
   124         // try again later
       
   125         SetTimerL();
       
   126         }
       
   127     else
       
   128         {
       
   129         // Run SendUiSr
       
   130         RApaLsSession ls;
       
   131         
       
   132         CApaCommandLine *cmd = CApaCommandLine::NewL();
       
   133         CleanupStack::PushL( cmd );
       
   134 
       
   135         cmd->SetExecutableNameL( KSendUiLauncherApp ); 
       
   136         cmd->SetCommandL( EApaCommandBackground );
       
   137         User::LeaveIfError( ls.StartApp( *cmd ) );
       
   138         CleanupStack::PopAndDestroy( cmd );
       
   139         }
       
   140     LOGTEXT(_L("CSendUiWatcher::HandleUpdateServicesL <<"));
       
   141     }
       
   142     
       
   143 // ---------------------------------------------------------------------------
       
   144 // Constructor
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 CSendUiWatcher::CSendUiWatcher() // first-phase C++ constructor
       
   148     {
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // ConstructL
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CSendUiWatcher::ConstructL() // second-phase constructor
       
   156     {
       
   157     if ( !iSession )
       
   158         {
       
   159         iSession = CMsvSession::OpenSyncL( *this );
       
   160         }
       
   161     TInt result( KErrNone );        
       
   162     
       
   163     result = RProperty::Define(
       
   164         KPSUidSendUiProperty, 
       
   165         KSendUiUpdateRequest,
       
   166         RProperty::EInt,
       
   167         TSecurityPolicy( ECapabilityReadUserData ),
       
   168         TSecurityPolicy( ECapabilityWriteUserData ));
       
   169     
       
   170     if ( result && result != KErrAlreadyExists )
       
   171         {
       
   172         User::LeaveIfError( result ); 
       
   173         }
       
   174    
       
   175     result = RProperty::Define(
       
   176         KPSUidSendUiProperty, 
       
   177         KSendUiUpdateOperation,
       
   178         RProperty::EInt,
       
   179         TSecurityPolicy( ECapabilityReadUserData ),
       
   180         TSecurityPolicy( ECapabilityWriteUserData  ));
       
   181     
       
   182     if ( result && result != KErrAlreadyExists )
       
   183         {
       
   184         User::LeaveIfError( result ); 
       
   185         }
       
   186     
       
   187     User::LeaveIfError( 
       
   188         RProperty::Set(KPSUidSendUiProperty, KSendUiUpdateOperation, KSendUiUpdateOperationDone) );
       
   189                 
       
   190     iPropertyObserver = CSendUiPropertyObserver::NewL( this );
       
   191 
       
   192     iEcomObserver = CSendUiEcomObserver::NewL();  
       
   193     
       
   194     CheckIfUpdateNeededL();
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // UpdateFeature
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 void CSendUiWatcher::FeatureStatus( TInt aFeature, TInt &aNewFeatures, TInt aFeatureFlag )
       
   202     {
       
   203     if ( FeatureManager::FeatureSupported( aFeature ) )
       
   204         {
       
   205         aNewFeatures |= aFeatureFlag;
       
   206         }
       
   207     }
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // CheckIfUpdateNeededL
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 void CSendUiWatcher::CheckIfUpdateNeededL()
       
   214     {
       
   215     LOGTEXT(_L("CSendUiWatcher::CheckIfUpdateNeededL >>"));
       
   216     CRepository* repository = CRepository::NewLC( KCRUidSendUi );
       
   217     
       
   218     TInt storedValue(KErrNotFound);
       
   219     TBool updateNeeded( EFalse );
       
   220     
       
   221     // Request service list update if phone language has changed.
       
   222     // KErrNotFound language value also indicates unsuccesfull run of SendUiServiceResolver
       
   223     TInt result = repository->Get( KKeySendUiServiceLanguage, storedValue );
       
   224     if ( result != KErrNone || storedValue != User::Language() )
       
   225     	{
       
   226     	updateNeeded = ETrue;
       
   227     	}
       
   228     
       
   229     // Issue service list update if mtm count has changed
       
   230     CMtmUiDataRegistry* mtmUiDataRegistry = CMtmUiDataRegistry::NewL( *iSession );
       
   231     TInt newMtmCount( KErrNotFound );
       
   232     if ( mtmUiDataRegistry )
       
   233     	{
       
   234     	newMtmCount = mtmUiDataRegistry->NumRegisteredMtmDlls();
       
   235 	    delete mtmUiDataRegistry;
       
   236     	}
       
   237 
       
   238     result = repository->Get( KKeySendUiServiceMtmCount, storedValue ) ;
       
   239     if ( result != KErrNone || storedValue != newMtmCount )
       
   240     	{
       
   241     	result = repository->Set( KKeySendUiServiceMtmCount, newMtmCount );
       
   242     	updateNeeded = ETrue;
       
   243     	}
       
   244    
       
   245     TInt oldFeatures(0);   
       
   246     TInt newFeatures(0);   
       
   247     if ( repository->Get( KKeySendUiFeatureManagerServices, oldFeatures ) != KErrNone )
       
   248     	{
       
   249     	updateNeeded = ETrue;
       
   250     	}
       
   251     FeatureManager::InitializeLibL();
       
   252     FeatureStatus( KFeatureIdMmsPostcard, newFeatures, KSendUiPostcard );
       
   253     FeatureStatus( KFeatureIdAudioMessaging, newFeatures, KSendUiAudioMessage );
       
   254     FeatureStatus( KFeatureIdSenduiMmsUpload, newFeatures, KSendUiMmsUpload );
       
   255     FeatureManager::UnInitializeLib();
       
   256     if ( newFeatures != oldFeatures )
       
   257         {
       
   258         repository->Set( KKeySendUiFeatureManagerServices, newFeatures );    
       
   259         updateNeeded = ETrue;
       
   260         }
       
   261 
       
   262     CleanupStack::PopAndDestroy( repository );
       
   263 
       
   264     if ( updateNeeded )
       
   265         {
       
   266         HandleUpdateServicesL();
       
   267         }
       
   268     LOGTEXT(_L("CSendUiWatcher::CheckIfUpdateNeededL <<"));
       
   269     }
       
   270 
       
   271 // ---------------------------------------------------------------------------
       
   272 // SetTimerL
       
   273 // ---------------------------------------------------------------------------
       
   274 //
       
   275 void CSendUiWatcher::SetTimerL()
       
   276     {
       
   277     LOGTEXT(_L("CSendUiWatcher::SetTimerL >>"));
       
   278     if ( !iTimer ) 
       
   279         {
       
   280         iTimer = CPeriodic::NewL( CActive::EPriorityStandard );    
       
   281         iTimer->Start( KSendUiServiceListUpdateDelay,
       
   282             KSendUiServiceListUpdateDelay,
       
   283             TCallBack( DoTaskL, this));
       
   284         }
       
   285     LOGTEXT(_L("CSendUiWatcher::SetTimerL <<"));
       
   286     }
       
   287     
       
   288 void CSendUiWatcher::HandleSessionEventL(
       
   289             TMsvSessionEvent aEvent,
       
   290             TAny* /*aArg1*/,
       
   291             TAny* aArg2,
       
   292             TAny* /*aArg3*/ )
       
   293     {   
       
   294     // TODO: Reconnect to message server
       
   295     switch ( aEvent )
       
   296         {
       
   297         case EMsvServerReady:
       
   298         	{
       
   299         	LOGTEXT(_L("Message Server is ready."));
       
   300         	break;
       
   301         	}
       
   302         case EMsvMtmGroupDeInstalled: 
       
   303         case EMsvMtmGroupInstalled:
       
   304             {
       
   305             SetTimerL();
       
   306             break;
       
   307             }
       
   308     
       
   309         case EMsvEntriesCreated:// fall through
       
   310         case EMsvEntriesDeleted:
       
   311             {
       
   312             TMsvId folderId = KMsvNullIndexEntryId;
       
   313             folderId = (*(TMsvId*) (aArg2));
       
   314             if (folderId != KMsvRootIndexEntryId)
       
   315                 {
       
   316                 break;
       
   317                 }
       
   318             SetTimerL();
       
   319             break;
       
   320                 
       
   321             }
       
   322         case EMsvCorruptedIndexRebuilt:
       
   323             LOGTEXT2(_L("Watcher event %d"), aEvent);
       
   324             HandleUpdateServicesL();
       
   325             break;
       
   326         case EMsvCloseSession:
       
   327         case EMsvServerTerminated:
       
   328             delete iSession;
       
   329             iSession = NULL;
       
   330             LOGTEXT(_L("SendUiWatcher session was terminated"));
       
   331         break;
       
   332         case EMsvMediaChanged:// Added to handle change of Msg center
       
   333             SetTimerL();
       
   334             break;        
       
   335         default:;
       
   336         }
       
   337     }
       
   338  
       
   339 // end of file
       
   340