convergedconnectionhandler/cchclientapi/cchuinotif/src/cchuinotifier.cpp
branchRCL_3
changeset 22 d38647835c2e
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 2008-2010 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:  Implements base class for notifier implementations
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <eikenv.h>
       
    20 #include <bautils.h>
       
    21 #include <featmgr.h>
       
    22 #include <spentry.h> 
       
    23 #include <spsettings.h>
       
    24 #include <spproperty.h>
       
    25 #include <cchuinotif.rsg>
       
    26 #include <StringLoader.h>
       
    27 #include <aknnotewrappers.h>
       
    28 #include <centralrepository.h>
       
    29 #include <cenrepnotifyhandler.h>
       
    30 #include <CoreApplicationUIsSDKCRKeys.h> // KCRUidCoreApplicationUIs, 
       
    31                                          // KCoreAppUIsNetworkConnectionAllowed
       
    32 #include <AknNotiferAppServerApplication.h>  // Application Key enable/disable
       
    33 
       
    34 #include "cchuilogger.h"
       
    35 #include "cchuinotifier.h"
       
    36 #include "cchuinotifconnectionhandler.h"
       
    37 
       
    38 _LIT( KResourceDir, "\\resource\\apps\\" );
       
    39 _LIT( KResourceFileName, "cchuinotif.r*" );
       
    40 
       
    41 // SCP-plugin uid for Sip VoIP
       
    42 const TInt32 KSipVoIPSubServicePlugId = 0x1027545A;
       
    43 
       
    44 // ======== MEMBER FUNCTIONS ========
       
    45 
       
    46 CCCHUiNotifierBase::CCCHUiNotifierBase(): 
       
    47     CActive(EPriorityStandard), iAppKeyBlocked( EFalse )
       
    48     {
       
    49     CActiveScheduler::Add(this);
       
    50     }
       
    51 
       
    52 void CCCHUiNotifierBase::ConstructL()
       
    53     {      
       
    54     CCHUIDEBUG( "CCCHUiNotifierBase::ConstructL - IN" );
       
    55     
       
    56     iEikEnv = CEikonEnv::Static();
       
    57 
       
    58     // load the resource file
       
    59     CCHUIDEBUG( "ConstructL - load resource");
       
    60    
       
    61     HBufC* resourceFile = ScanFileL( iEikEnv->FsSession(), 
       
    62         TFileName( KResourceFileName ), TFileName( KResourceDir ) );
       
    63     
       
    64     if ( resourceFile )
       
    65         {
       
    66         CCHUIDEBUG( "ConstructL - resource ready, adding");   
       
    67         
       
    68         CleanupStack::PushL( resourceFile );
       
    69         iResourceFileFlag = iEikEnv->AddResourceFileL(
       
    70             *resourceFile );    
       
    71         CleanupStack::PopAndDestroy( resourceFile );
       
    72         
       
    73         CCHUIDEBUG( "ConstructL - resource added");    
       
    74         }
       
    75     
       
    76     iSettings = CSPSettings::NewL();
       
    77     
       
    78     CCHUIDEBUG( "CCCHUiNotifierBase::ConstructL - OUT" );
       
    79     }
       
    80 
       
    81 CCCHUiNotifierBase::~CCCHUiNotifierBase()
       
    82     {
       
    83     CCHUIDEBUG( "CCCHUiNotifierBase::~CCCHUiNotifierBase - IN" );
       
    84     
       
    85     if( iAppKeyBlocked )
       
    86         {
       
    87         (void) ((CAknNotifierAppServerAppUi*)
       
    88             iEikEnv->EikAppUi())->SuppressAppSwitching(EFalse);    
       
    89         }
       
    90     
       
    91     Cancel();    
       
    92     
       
    93     delete iSettings;
       
    94     CompleteMessage( KErrDied );  
       
    95     iEikEnv->DeleteResourceFile( iResourceFileFlag );
       
    96     
       
    97     CCHUIDEBUG( "CCCHUiNotifierBase::~CCCHUiNotifierBase - OUT" );
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // CompleteMessage.
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 void CCCHUiNotifierBase::CompleteMessage( TInt aErr )
       
   105     {      
       
   106     CCHUIDEBUG2( "CCCHUiNotifierBase::CompleteMessage - err: %d", aErr );
       
   107     
       
   108     if( !iMessage.IsNull() )
       
   109         {
       
   110         CCHUIDEBUG( "CompleteMessage - do complete");
       
   111         iMessage.Complete( aErr );
       
   112         }
       
   113     
       
   114     iReplySlot = NULL;                    
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // From class MEikSrvNotifierBase2.
       
   119 // Cancelling method.
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CCCHUiNotifierBase::Cancel()
       
   123     {   
       
   124     CCHUIDEBUG( "CCCHUiNotifierBase::Cancel - IN" );
       
   125         
       
   126     // Complete with KErrCancel
       
   127     CompleteMessage(KErrCancel);        
       
   128     CActive::Cancel();
       
   129     
       
   130     CCHUIDEBUG( "CCCHUiNotifierBase::Cancel - OUT" );
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // RunL
       
   135 // From CActive.
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 void CCCHUiNotifierBase::RunL(  )
       
   139     {
       
   140     CCHUIDEBUG( "CCCHUiNotifierBase::RunL" );
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // From class MEikSrvNotifierBase2.
       
   145 // Release itself. Call to destructor.
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 void CCCHUiNotifierBase::Release()
       
   149     { 
       
   150     CCHUIDEBUG( "CCCHUiNotifierBase::Release");
       
   151     delete this;
       
   152     }
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // From class MEikSrvNotifierBase2.
       
   156 // Return registered information.
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 CCCHUiNotifierBase::TNotifierInfo CCCHUiNotifierBase::Info() const
       
   160     {      
       
   161     CCHUIDEBUG( "CCCHUiNotifierBase::Info");
       
   162     return iInfo;
       
   163     }
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // From class MEikSrvNotifierBase2.
       
   167 // Synchronic notifier launch. Does nothing here.
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 TPtrC8 CCCHUiNotifierBase::StartL( const TDesC8& /*aBuffer*/ )
       
   171     {    
       
   172     CCHUIDEBUG( "CCCHUiNotifierBase::StartL");
       
   173     TPtrC8 ret( KNullDesC8 );
       
   174     return ret;
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // From class MEikSrvNotifierBase2.
       
   179 // Asynchronic notifier launch.
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void CCCHUiNotifierBase::StartL( 
       
   183     const TDesC8& /*aBuffer*/, 
       
   184     TInt aReplySlot, 
       
   185     const RMessagePtr2& aMessage )
       
   186     {
       
   187     CCHUIDEBUG( "CCCHUiNotifierBase::StartL2 - IN");
       
   188     iMessage = aMessage;
       
   189     iReplySlot = aReplySlot;
       
   190     
       
   191     SetActive();
       
   192     
       
   193     iStatus = KRequestPending;
       
   194     TRequestStatus* stat = &iStatus;
       
   195     User::RequestComplete(stat, KErrNone);
       
   196 
       
   197     CCHUIDEBUG( "CCCHUiNotifierBase::StartL2 - OUT");
       
   198     }
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // From class MEikSrvNotifierBase2.
       
   202 // Notifier update. Not supported.
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 TPtrC8 CCCHUiNotifierBase::UpdateL( const TDesC8& /*aBuffer*/ )
       
   206     {
       
   207     CCHUIDEBUG( "CCCHUiNotifierBase::UpdateL");
       
   208     TPtrC8 ret( KNullDesC8 );
       
   209     return ret;
       
   210     }
       
   211     
       
   212 // ----------------------------------------------------------
       
   213 // CCCHUiNotifierBase::DoCancel
       
   214 // This method will be called by framework (CActive)
       
   215 // if active object is still active.
       
   216 // Does nothing here.
       
   217 // ----------------------------------------------------------
       
   218 //
       
   219 void CCCHUiNotifierBase::DoCancel()
       
   220     {
       
   221     CCHUIDEBUG( "CCCHUiNotifierBase::DoCancel - IN");
       
   222     
       
   223     // Complete request when active object is still active
       
   224     TRequestStatus* stat = &iStatus;
       
   225     if (iStatus != KErrCancel)
       
   226         {
       
   227         User::RequestComplete(stat, KErrNone);
       
   228         }
       
   229         
       
   230     CCHUIDEBUG( "CCCHUiNotifierBase::DoCancel - OUT");
       
   231     }
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // Scan resource file.
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 HBufC* CCCHUiNotifierBase::ScanFileL( 
       
   238     RFs& aSession, 
       
   239     const TDesC& aFileName, 
       
   240     const TDesC& aFilePath )
       
   241     {
       
   242     CCHUIDEBUG( "CCCHUiNotifierBase::ScanFileL");     
       
   243     
       
   244     TFindFile search( aSession ); 
       
   245     CDir* dirlist; 
       
   246     HBufC* fullName = NULL;
       
   247     TFileName filename( aFileName );
       
   248     TInt err = search.FindWildByDir( filename, aFilePath, dirlist ); 
       
   249     
       
   250     CCHUIDEBUG2( "ScanFileL - FindWildByDir err: %d", err );    
       
   251     
       
   252     if ( err == KErrNone )
       
   253         {
       
   254         CCHUIDEBUG2( "ScanFileL - dir list count: %d", dirlist->Count() );      
       
   255         
       
   256         if ( 0 < dirlist->Count() )
       
   257             {
       
   258             CCHUIDEBUG( "ScanFileL - Parsing full entry" );
       
   259             
       
   260             TParse fullentry;
       
   261             fullentry.Set( (*dirlist)[0].iName, &search.File(), NULL ); 
       
   262             TFileName nearestFile( fullentry.FullName() );
       
   263             BaflUtils::NearestLanguageFile( aSession, nearestFile );   
       
   264             fullName = HBufC::NewL( nearestFile.Length() );
       
   265             fullName->Des().Copy( nearestFile );  
       
   266             }
       
   267         delete dirlist; 
       
   268         
       
   269         CCHUIDEBUG2( "ScanFileL - full name: %S", fullName );             
       
   270         }     
       
   271     
       
   272     return fullName;
       
   273     }  
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 // Resolves service name.
       
   277 // ---------------------------------------------------------------------------
       
   278 //
       
   279 void CCCHUiNotifierBase::GetServiceNameL( 
       
   280     TUint aServiceId, TDes& aServiceName )
       
   281     {
       
   282     CCHUIDEBUG( "CCCHUiNotifierBase::GetServiceNameL" );	
       
   283 	CSPEntry* entry = CSPEntry::NewLC();
       
   284 	TRAPD( err, iSettings->FindEntryL( aServiceId, *entry ) );
       
   285 	if ( !err )
       
   286 	    {
       
   287 	    aServiceName = entry->GetServiceName();
       
   288 	    }
       
   289 	CleanupStack::PopAndDestroy( entry );    
       
   290     CCHUIDEBUG( "CCCHUiNotifierBase::GetServiceNameL OUT" );
       
   291     }
       
   292 
       
   293 // ---------------------------------------------------------------------------
       
   294 // Resolves current connection name.
       
   295 // ---------------------------------------------------------------------------
       
   296 //
       
   297 void CCCHUiNotifierBase::CurrentConnectionNameL( 
       
   298     TUint aServiceId, TUint aIapId, RBuf& aIapName )
       
   299     {
       
   300     CCHUIDEBUG( "CCCHUiNotifierBase::CurrentConnectionNameL - IN" );    
       
   301    
       
   302     CCchUiNotifConnectionHandler* connHandler = 
       
   303             CCchUiNotifConnectionHandler::NewLC();
       
   304     
       
   305     RBuf serviceName;
       
   306     CleanupClosePushL( serviceName );
       
   307     serviceName.CreateL( KServiceNameLength );
       
   308     GetServiceNameL( aServiceId, serviceName );
       
   309     
       
   310     // get connection name
       
   311     connHandler->ConnectionNameL( aIapId, serviceName, aIapName );
       
   312     
       
   313     CleanupStack::PopAndDestroy( &serviceName );
       
   314     CleanupStack::PopAndDestroy( connHandler );
       
   315     
       
   316     CCHUIDEBUG( "CCCHUiNotifierBase::CurrentConnectionNameL - OUT" );
       
   317     }
       
   318     
       
   319 // ---------------------------------------------------------------------------
       
   320 // Resolves if service is SIP/VoIP.
       
   321 // ---------------------------------------------------------------------------
       
   322 //
       
   323 TBool CCCHUiNotifierBase::IsSIPVoIPL( TUint aServiceId )
       
   324     {
       
   325     CCHUIDEBUG( "CCCHUiNotifierBase::IsSIPVoIPL" );
       
   326     
       
   327     TInt uid( 0 );
       
   328     TBool sipVoIP( EFalse );
       
   329        
       
   330     CSPProperty* property = CSPProperty::NewLC();
       
   331        
       
   332     User::LeaveIfError( iSettings->FindPropertyL( 
       
   333             aServiceId, EPropertyVoIPSubServicePluginId , *property ) );
       
   334        
       
   335     User::LeaveIfError( property->GetValue( uid ) );
       
   336        
       
   337     if ( KSipVoIPSubServicePlugId == uid )
       
   338         {
       
   339         sipVoIP = ETrue;
       
   340         }
       
   341        
       
   342     CleanupStack::PopAndDestroy( property );
       
   343        
       
   344     CCHUIDEBUG2( "CCCHUiNotifierBase::IsSIPVoIPL: %d", sipVoIP );
       
   345     
       
   346     return sipVoIP;
       
   347     }
       
   348     
       
   349 // -----------------------------------------------------------------------------
       
   350 // Checks if phone is in offline mode.
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 TBool CCCHUiNotifierBase::IsPhoneOfflineL() const
       
   354     {
       
   355     CCHUIDEBUG( "CCCHUiNotifierBase::IsPhoneOfflineL" );	
       
   356     
       
   357     if ( FeatureManager::FeatureSupported( KFeatureIdOfflineMode ) )
       
   358         {
       
   359         CRepository* repository = CRepository::NewLC(KCRUidCoreApplicationUIs);
       
   360         TInt connAllowed = ECoreAppUIsNetworkConnectionAllowed;
       
   361         repository->Get( KCoreAppUIsNetworkConnectionAllowed, connAllowed );
       
   362         CleanupStack::PopAndDestroy( repository ); 
       
   363         if ( !connAllowed )
       
   364             {
       
   365             CCHUIDEBUG( "IsPhoneOfflineL - phone is in offline" );	        
       
   366             return ETrue;
       
   367             }
       
   368         }
       
   369     
       
   370     CCHUIDEBUG( "IsPhoneOfflineL - phone is not in offline" );	
       
   371     return EFalse;
       
   372     }    
       
   373 
       
   374 // -----------------------------------------------------------------------------
       
   375 // Checks if there are GPRS IAPs available in Internet SNAP.
       
   376 // -----------------------------------------------------------------------------
       
   377 //
       
   378 TBool CCCHUiNotifierBase::IsGprsIapsAvailableL() const
       
   379     {
       
   380     CCHUIDEBUG( "CCCHUiNotifierBase::IsGprsIapsAvailableL" );   
       
   381     
       
   382     TBool available( EFalse );
       
   383     
       
   384     CCchUiNotifConnectionHandler* connHandler = 
       
   385         CCchUiNotifConnectionHandler::NewLC();
       
   386     
       
   387     RArray<TUint32> gprsIapIds;
       
   388     CleanupClosePushL( gprsIapIds );
       
   389     
       
   390     // Array for iap names. No use here, we need just iap count.
       
   391     CDesCArray* iapNames = new (ELeave) CDesCArrayFlat( 3 );
       
   392     CleanupStack::PushL( iapNames );            
       
   393     
       
   394     TRAPD( err, connHandler->GetGprsAccessPointsL( *iapNames, gprsIapIds ) );
       
   395     
       
   396     if ( gprsIapIds.Count() && !err )
       
   397         {     
       
   398         CCHUIDEBUG( "IsGprsIapsAvailableL - gprs iaps available" );      
       
   399         available = ETrue;
       
   400         }
       
   401     
       
   402     CleanupStack::PopAndDestroy( iapNames );
       
   403     CleanupStack::PopAndDestroy( &gprsIapIds );
       
   404     CleanupStack::PopAndDestroy( connHandler );
       
   405     
       
   406     CCHUIDEBUG( "IsGprsIapsAvailableL gprs iaps not available" );
       
   407     return available;
       
   408     }
       
   409 
       
   410 // -----------------------------------------------------------------------------
       
   411 // Checks if connection is used by other services.
       
   412 // -----------------------------------------------------------------------------
       
   413 //
       
   414 TBool CCCHUiNotifierBase::ConnectionUsedByOthersL( 
       
   415     TUint aServiceId, TInt aIapId )
       
   416     {
       
   417     CCHUIDEBUG( "CCCHUiNotifierBase::ConnectionUsedByOthersL" );
       
   418     
       
   419     TBool usedByOthers( EFalse );
       
   420     
       
   421     RArray<TUint32> destIds;
       
   422     CleanupClosePushL( destIds );
       
   423      
       
   424     CCchUiNotifConnectionHandler* connHandler = 
       
   425             CCchUiNotifConnectionHandler::NewLC();
       
   426     
       
   427     RBuf serviceName;
       
   428     CleanupClosePushL( serviceName );
       
   429     serviceName.CreateL( KServiceNameLength );
       
   430     GetServiceNameL( aServiceId, serviceName );
       
   431     
       
   432     CCHUIDEBUG( "ConnectionUsedByOthersL - get destinations" );
       
   433     
       
   434     // Get all but our services destinations.
       
   435     connHandler->GetDestinationsL( serviceName, destIds );
       
   436     
       
   437     CleanupStack::PopAndDestroy( &serviceName );
       
   438     
       
   439     for ( TInt i( 0 ) ; i < destIds.Count() ; i++ )
       
   440         {
       
   441         RArray<TUint32> iapIds;
       
   442         CleanupClosePushL( iapIds );
       
   443      
       
   444         connHandler->GetAccessPointsFromSnapL( iapIds, destIds[ i ] );
       
   445         
       
   446         TInt index = iapIds.Find( aIapId );
       
   447         
       
   448         if ( KErrNotFound != index  )
       
   449             {
       
   450             CCHUIDEBUG( 
       
   451             "ConnectionUsedByOthersL - iap is used by other service(s)" );
       
   452             
       
   453             usedByOthers = ETrue;
       
   454             }
       
   455         
       
   456         CleanupStack::PopAndDestroy( &iapIds );
       
   457         }
       
   458      
       
   459     CleanupStack::PopAndDestroy( connHandler );
       
   460     CleanupStack::PopAndDestroy( &destIds );
       
   461     
       
   462     return usedByOthers;
       
   463     }
       
   464