phonebookengines/VirtualPhonebook/VPbkSimStoreImpl/src/CPhone.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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:  Opens ETel RTelServer and RMobilePhone
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPhone.h"
       
    22 
       
    23 // From Virtual Phonebook
       
    24 #include "CServiceTableCmd.h"
       
    25 #include "CUsimAdnStore.h"
       
    26 #include "CAdnStore.h"
       
    27 #include "CFdnStore.h"
       
    28 #include "CSdnStore.h"
       
    29 #include "COwnNumberStore.h"
       
    30 #include "CSatRefreshNotifier.h"
       
    31 #include "CBtSapNotification.h"
       
    32 #include "TStoreParams.h"
       
    33 #include "VPbkSimStoreImplError.h"
       
    34 #include "CSimStatusNotification.h"
       
    35 #include <MVPbkSimCommand.h>
       
    36 #include <CVPbkAsyncOperation.h>
       
    37 #include <CVPbkSimStateInformation.h>
       
    38 #include <VPbkSimStoreTemplateFunctions.h>
       
    39 #include <VPbkSimStateDefinitions.h>
       
    40 #include <CVPbkAsyncCallback.h>
       
    41 
       
    42 // System includes
       
    43 #include <mmtsy_names.h>
       
    44 
       
    45 // DEBUG
       
    46 #include <VPbkDebug.h>
       
    47 
       
    48 namespace VPbkSimStoreImpl {
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CSimPdUtilities::ConvertStatus
       
    52 // Converts ETel status to SIMPD status
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 MVPbkSimPhone::TFDNStatus ConvertStatus(TInt aETelFDNStatus)
       
    56     {
       
    57     FUNC_ENTRY();
       
    58     MVPbkSimPhone::TFDNStatus status = MVPbkSimPhone::EFdnStatusUnknown;
       
    59 
       
    60     switch ( aETelFDNStatus )
       
    61         {
       
    62         case RMobilePhone::EFdnNotActive:
       
    63             {
       
    64             status = MVPbkSimPhone::EFdnIsNotActive;
       
    65             break;
       
    66             }
       
    67         case RMobilePhone::EFdnActive:
       
    68             {
       
    69             status = MVPbkSimPhone::EFdnIsActive;
       
    70             break;
       
    71             }
       
    72         case RMobilePhone::EFdnPermanentlyActive:
       
    73             {
       
    74             status = MVPbkSimPhone::EFdnIsPermanentlyActive;
       
    75             break;
       
    76             }
       
    77         case RMobilePhone::EFdnNotSupported:
       
    78             {
       
    79             status = MVPbkSimPhone::EFdnIsNotSupported;
       
    80             break;
       
    81             }
       
    82         case RMobilePhone::EFdnUnknown: // FALLTHROUGH
       
    83         default:
       
    84             {
       
    85             // Do nothing
       
    86             break;
       
    87             }
       
    88         }
       
    89 
       
    90     FUNC_EXIT();
       
    91     return status;
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CPhone::CPhone
       
    96 // C++ default constructor can NOT contain any code, that
       
    97 // might leave.
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 CPhone::CPhone( CSatRefreshNotifier& aSatNotifier, 
       
   101         CVPbkSimStateInformation& aSimStateInfo, 
       
   102         CBtSapNotification& aBtSapNotifier )
       
   103         :   CActive( EPriorityStandard ),
       
   104             iSatNotifier( aSatNotifier ),
       
   105             iSimStateInfo( aSimStateInfo ),
       
   106             iBtSapNotifier( aBtSapNotifier )
       
   107     {
       
   108     FUNC_ENTRY();
       
   109     CActiveScheduler::Add(this);
       
   110     FUNC_EXIT();
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CPhone::~CPhone
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 CPhone::~CPhone()
       
   118     {
       
   119     FUNC_ENTRY();
       
   120     Cancel();
       
   121     delete iSimStatus;
       
   122     iSatNotifier.DeActivate( *this );
       
   123     iBtSapNotifier.RemoveObserver( *this );
       
   124     delete iAsyncOp;
       
   125     delete iSTCommand;
       
   126     iObservers.Close();
       
   127     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
       
   128         "VPbkSimStoreImpl: RMobilePhone Close handle %d"),
       
   129         iPhone.SubSessionHandle());
       
   130     iPhone.Close();
       
   131     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
       
   132         "VPbkSimStoreImpl: RTelServer Close handle %d"),iTelServer.Handle());
       
   133     iTelServer.Close();
       
   134     FUNC_EXIT();
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CPhone::ETelPhone
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 RMobilePhone& CPhone::ETelPhone()
       
   142     {
       
   143     FUNC_ENTRY();
       
   144     return iPhone;
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CPhone::CreateStoreLC
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 MVPbkSimCntStore* CPhone::CreateStoreLC( TStoreParams& aParams )
       
   152     {
       
   153     FUNC_ENTRY();
       
   154     OpenETelPhoneL();
       
   155 
       
   156     VPbkSimStoreImpl::CStoreBase* store = NULL;
       
   157 
       
   158     switch ( aParams.iId )
       
   159         {
       
   160         case EVPbkSimAdnGlobalStore:
       
   161             {
       
   162             if ( USimAccessSupported() )
       
   163                 {
       
   164                 store = VPbkSimStoreImpl::CUsimAdnStore::NewL( aParams );
       
   165                 }
       
   166             else
       
   167                 {
       
   168                 store = VPbkSimStoreImpl::CAdnStore::NewL( aParams );
       
   169                 }
       
   170             break;
       
   171             }
       
   172         case EVPbkSimFdnGlobalStore:
       
   173             {
       
   174             store = 
       
   175                 VPbkSimStoreImpl::CFdnStore::NewL( aParams );
       
   176             break;
       
   177             }
       
   178         case EVPbkSimSdnGlobalStore:
       
   179             {
       
   180             store = 
       
   181                 VPbkSimStoreImpl::CSdnStore::NewL( aParams );
       
   182             break;
       
   183             }
       
   184         case EVPbkSimONStore:
       
   185             {
       
   186             store = VPbkSimStoreImpl::COwnNumberStore::NewL( aParams );
       
   187             break;
       
   188             }
       
   189         default:
       
   190             {
       
   191             __ASSERT_DEBUG( EFalse, VPbkSimStoreImpl::Panic( 
       
   192                 VPbkSimStoreImpl::ESimStoreNotSupportedYet ) );
       
   193             break;
       
   194             }
       
   195         }
       
   196 
       
   197     if ( store )
       
   198         {
       
   199         CleanupStack::PushL( store );
       
   200         }
       
   201     FUNC_EXIT();
       
   202     return store;
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CPhone::AddObserverL
       
   207 // -----------------------------------------------------------------------------
       
   208 //    
       
   209 void CPhone::AddObserverL( MVPbkSimPhoneObserver& aObserver )
       
   210     {
       
   211     FUNC_ENTRY();
       
   212     if ( iObservers.Find( &aObserver ) == KErrNotFound )
       
   213         {
       
   214         iObservers.AppendL( &aObserver );
       
   215         }
       
   216     FUNC_EXIT();
       
   217     }
       
   218         
       
   219 // -----------------------------------------------------------------------------
       
   220 // CPhone::RemoveObserver
       
   221 // -----------------------------------------------------------------------------
       
   222 //    
       
   223 void CPhone::RemoveObserver( MVPbkSimPhoneObserver& aObserver )
       
   224     {
       
   225     FUNC_ENTRY();
       
   226     TInt pos = iObservers.Find( &aObserver );
       
   227     if ( pos != KErrNotFound )
       
   228         {
       
   229         iObservers.Remove( pos );
       
   230         }
       
   231     FUNC_EXIT();
       
   232     }
       
   233     
       
   234 // -----------------------------------------------------------------------------
       
   235 // CPhone::RunL
       
   236 // -----------------------------------------------------------------------------
       
   237 //    
       
   238 void CPhone::RunL()
       
   239     {
       
   240     FUNC_ENTRY();
       
   241     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
       
   242         "VPbkSimStoreImpl:CPhone::RunL: res: % d, ETel FDN status: %d"), 
       
   243         iStatus.Int(), iFdnStatus );
       
   244         
       
   245     if ( iStatus == KErrNone )
       
   246         {
       
   247         TInt conversion = ConvertStatus( iFdnStatus );
       
   248         
       
   249         SendObserverMessageR( iObservers, 
       
   250             &MVPbkSimPhoneObserver::FixedDiallingStatusChanged, 
       
   251             conversion );
       
   252         }
       
   253         
       
   254     ActivateFDNNotification();
       
   255     FUNC_EXIT();
       
   256     }
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // CPhone::BtSapDeactivated
       
   260 // -----------------------------------------------------------------------------
       
   261 //    
       
   262 void CPhone::BtSapActivated()
       
   263     {
       
   264     FUNC_ENTRY();    
       
   265     SendObserverMessageRVV( iObservers, 
       
   266         &MVPbkSimPhoneObserver::PhoneError, *this,
       
   267         MVPbkSimPhoneObserver::EBtSapActive, KErrGeneral );
       
   268     FUNC_EXIT();
       
   269     }
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // CPhone::BtSapDeactivated
       
   273 // -----------------------------------------------------------------------------
       
   274 //    
       
   275 void CPhone::BtSapDeactivated()
       
   276     {
       
   277     FUNC_ENTRY();    
       
   278     TRAPD( res, HandleBtSapDeactivationL() );
       
   279     if ( res != KErrNone )
       
   280         {
       
   281         SendObserverMessageRVV( iObservers, 
       
   282             &MVPbkSimPhoneObserver::PhoneError, *this,
       
   283             MVPbkSimPhoneObserver::ESystem, res );    
       
   284         }
       
   285     FUNC_EXIT();
       
   286     }
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // CPhone::BtSapNotificationError
       
   290 // -----------------------------------------------------------------------------
       
   291 //    
       
   292 void CPhone::BtSapNotificationError( TInt aError )
       
   293     {
       
   294     FUNC_ENTRY();
       
   295     SendObserverMessageRVV( iObservers, 
       
   296         &MVPbkSimPhoneObserver::PhoneError, *this,
       
   297         MVPbkSimPhoneObserver::ESystem, aError );
       
   298     FUNC_EXIT();
       
   299     }
       
   300     
       
   301 // -----------------------------------------------------------------------------
       
   302 // CPhone::DoCancel
       
   303 // -----------------------------------------------------------------------------
       
   304 //    
       
   305 void CPhone::DoCancel()
       
   306     {
       
   307     FUNC_ENTRY();
       
   308     iPhone.CancelAsyncRequest( EMobilePhoneNotifyFdnStatusChange );
       
   309     FUNC_EXIT();
       
   310     }
       
   311     
       
   312 // -----------------------------------------------------------------------------
       
   313 // CPhone::OpenL
       
   314 // -----------------------------------------------------------------------------
       
   315 //
       
   316 void CPhone::OpenL( MVPbkSimPhoneObserver& aObserver )
       
   317     {
       
   318     FUNC_ENTRY();
       
   319     MVPbkSimPhoneObserver::TErrorIdentifier errorId;
       
   320     if ( SimUsableL( errorId ) )
       
   321         {
       
   322         OpenETelPhoneL();
       
   323         
       
   324         if ( !StartInitL() && iIsOpen )
       
   325             {
       
   326             // store is open
       
   327             CVPbkAsyncObjectCallback<MVPbkSimPhoneObserver>* callback =
       
   328                 VPbkEngUtils::CreateAsyncObjectCallbackLC(
       
   329                     *this, 
       
   330                     &CPhone::DoOpenL, 
       
   331                     &CPhone::DoOpenError, 
       
   332                     aObserver );
       
   333             AsyncOpL()->CallbackL( callback );
       
   334             CleanupStack::Pop( callback );
       
   335             }    
       
   336         }
       
   337     else
       
   338         {
       
   339         CVPbkAsyncObjectCallback<MVPbkSimPhoneObserver>* callback =
       
   340                 VPbkEngUtils::CreateAsyncObjectCallbackLC(
       
   341                     *this, 
       
   342                     &CPhone::DoOpenWithErrorL,
       
   343                     errorId,
       
   344                     &CPhone::DoOpenError,
       
   345                     aObserver );
       
   346             AsyncOpL()->CallbackL( callback );
       
   347             CleanupStack::Pop( callback );
       
   348         }
       
   349     
       
   350     if ( iObservers.Find( &aObserver ) == KErrNotFound )
       
   351         {
       
   352         iObservers.AppendL( &aObserver );
       
   353         }
       
   354     FUNC_EXIT();
       
   355     }
       
   356 
       
   357 // -----------------------------------------------------------------------------
       
   358 // CPhone::Close
       
   359 // -----------------------------------------------------------------------------
       
   360 //
       
   361 void CPhone::Close( MVPbkSimPhoneObserver& aObserver )
       
   362     {
       
   363     FUNC_ENTRY();
       
   364     if ( iAsyncOp )
       
   365         {
       
   366         iAsyncOp->CancelCallback( &aObserver );
       
   367         }
       
   368 
       
   369     TInt index = iObservers.Find( &aObserver );
       
   370     if ( index != KErrNotFound )
       
   371         {
       
   372         iObservers.Remove( index );
       
   373         }
       
   374 
       
   375     if ( iObservers.Count() == 0 )
       
   376         {
       
   377         if ( iAsyncOp )
       
   378             {
       
   379             iAsyncOp->Purge();
       
   380             }
       
   381         }
       
   382     FUNC_EXIT();
       
   383     }
       
   384 
       
   385 // -----------------------------------------------------------------------------
       
   386 // CPhone::USimAccessSupported
       
   387 // -----------------------------------------------------------------------------
       
   388 //
       
   389 TBool CPhone::USimAccessSupported() const
       
   390     {
       
   391     FUNC_ENTRY();
       
   392     TBool supported = EFalse;
       
   393     TUint32 iccCaps;
       
   394     
       
   395     TInt result = iPhone.GetIccAccessCaps( iccCaps );
       
   396     if ( result == KErrNone && 
       
   397          iccCaps & RMobilePhone::KCapsUSimAccessSupported )
       
   398         {
       
   399         supported = ETrue;
       
   400         }
       
   401     FUNC_EXIT();
       
   402     return supported;
       
   403     }
       
   404 
       
   405 // -----------------------------------------------------------------------------
       
   406 // CPhone::ServiceTable
       
   407 // -----------------------------------------------------------------------------
       
   408 //
       
   409 TUint32 CPhone::ServiceTable() const
       
   410     {
       
   411     FUNC_ENTRY();
       
   412     return iServiceTable;
       
   413     }
       
   414 
       
   415 // -----------------------------------------------------------------------------
       
   416 // CPhone::FixedDialingStatus
       
   417 // -----------------------------------------------------------------------------
       
   418 //
       
   419 MVPbkSimPhone::TFDNStatus CPhone::FixedDialingStatus() const
       
   420     {
       
   421     FUNC_ENTRY();
       
   422     RMobilePhone::TMobilePhoneFdnStatus etelStatus = RMobilePhone::EFdnUnknown;
       
   423     TFDNStatus ownStatus = EFdnStatusUnknown;
       
   424 
       
   425     TInt result = iPhone.GetFdnStatus( etelStatus );
       
   426     if ( result == KErrNone )
       
   427         {
       
   428         ownStatus = ConvertStatus( etelStatus );
       
   429         }
       
   430     FUNC_EXIT();
       
   431     return ownStatus;
       
   432     }
       
   433     
       
   434 // -----------------------------------------------------------------------------
       
   435 // CPhone::CommandDone
       
   436 // -----------------------------------------------------------------------------
       
   437 //
       
   438 void CPhone::CommandDone( MVPbkSimCommand& aCommand )
       
   439     {
       
   440     FUNC_ENTRY();
       
   441     if ( iSTCommand == &aCommand )
       
   442         {   
       
   443         // Delete the service table command
       
   444         delete iSTCommand;
       
   445         iSTCommand = NULL;
       
   446         
       
   447         // Activate observing BT SAP and SAT refresh.        
       
   448         TRAPD( res, ActivateBtSapAndSatRefreshL() );
       
   449         if ( res != KErrNone )
       
   450             {
       
   451             CommandError( aCommand, res );
       
   452             }
       
   453         else if ( !iIsOpen )
       
   454             {
       
   455             // The phone is open after service table have been read
       
   456             iIsOpen = ETrue;
       
   457             SendObserverMessageR( iObservers, 
       
   458                 &MVPbkSimPhoneObserver::PhoneOpened, *this );
       
   459             }
       
   460         else
       
   461             {
       
   462             // It was already open so inform observers about updated table
       
   463             SendObserverMessageR( iObservers, 
       
   464                 &MVPbkSimPhoneObserver::ServiceTableUpdated, iServiceTable );
       
   465             }
       
   466         
       
   467         // Service table is reloaded when SIM is refreshed and we
       
   468         // have to tell SAT server that we have updated ourselves.
       
   469         CompleteSatRefresh();
       
   470         }
       
   471     FUNC_EXIT();
       
   472     }
       
   473 
       
   474 // -----------------------------------------------------------------------------
       
   475 // CPhone::CommandError
       
   476 // -----------------------------------------------------------------------------
       
   477 //
       
   478 void CPhone::CommandError( MVPbkSimCommand& aCommand, TInt aError )
       
   479     {
       
   480     FUNC_ENTRY();
       
   481     if ( iSTCommand == &aCommand )
       
   482         {
       
   483         delete iSTCommand;
       
   484         iSTCommand = NULL;
       
   485         SendObserverMessageRVV( iObservers, 
       
   486             &MVPbkSimPhoneObserver::PhoneError, *this,
       
   487             MVPbkSimPhoneObserver::ESystem, aError );
       
   488         // Service table is reloaded when SIM is refreshed. If this fails
       
   489         // SAT server is still waiting client notifying.
       
   490         CompleteSatRefresh();
       
   491         }
       
   492     FUNC_EXIT();
       
   493     }
       
   494 
       
   495 // -----------------------------------------------------------------------------
       
   496 // CPhone::SimRefreshed
       
   497 // -----------------------------------------------------------------------------
       
   498 //
       
   499 void CPhone::SimRefreshed( TUint32 aSimRefreshFlags,
       
   500         MSimRefreshCompletion& aSimRefreshCompletion )
       
   501     {
       
   502     FUNC_ENTRY();
       
   503     // SAT notifier tells that SIM has been refreshed
       
   504     VPBK_DEBUG_PRINT(
       
   505         VPBK_DEBUG_STRING("CPbkSimStoreImpl:CPhone::SimRefreshed [%x]"), aSimRefreshFlags );
       
   506     // Check if there are elementary files that this class is interested in.
       
   507     // In practise service table file.
       
   508     TBool completeNow = ETrue;
       
   509     if ( aSimRefreshFlags & ElementaryFiles() )
       
   510         {
       
   511         // Service table has been updated -> load service table asynchronously.
       
   512         TRAPD( res, LoadServiceTableL() );
       
   513         VPBK_DEBUG_PRINT(
       
   514             VPBK_DEBUG_STRING("CPbkSimStoreImpl:CPhone LoadServiceTableL [%i]"), res );
       
   515         if ( res != KErrNone )
       
   516             {
       
   517             SendObserverMessageRVV( iObservers, 
       
   518                 &MVPbkSimPhoneObserver::PhoneError, *this,
       
   519                 MVPbkSimPhoneObserver::ESystem, res );
       
   520             }
       
   521         else
       
   522             {
       
   523             // Save completion to complete refresh later
       
   524             iSimRefreshCompletion = &aSimRefreshCompletion;
       
   525             completeNow = EFalse;
       
   526             }
       
   527         }
       
   528         
       
   529     // If we didn't start asyncrhonous update then complete refresh because
       
   530     // SAT server is waiting that.
       
   531     if ( completeNow )
       
   532         {
       
   533         aSimRefreshCompletion.SatRefreshCompleted( *this, EFalse );
       
   534         }
       
   535     FUNC_EXIT();
       
   536     }
       
   537 
       
   538 // -----------------------------------------------------------------------------
       
   539 // CPhone::AllowRefresh
       
   540 // -----------------------------------------------------------------------------
       
   541 //
       
   542 TBool CPhone::AllowRefresh( TUint32 /*aSimRefreshFlags*/ )
       
   543     {
       
   544     FUNC_ENTRY();
       
   545     if ( iSTCommand )
       
   546         {
       
   547         // If service table request is active then don't allow refresh yet
       
   548         return EFalse;
       
   549         }
       
   550     return ETrue;
       
   551     }
       
   552 
       
   553 // -----------------------------------------------------------------------------
       
   554 // CPhone::ElementaryFiles
       
   555 // -----------------------------------------------------------------------------
       
   556 //
       
   557 TUint32 CPhone::ElementaryFiles()
       
   558     {
       
   559     FUNC_ENTRY();
       
   560     return KSTRefresh | KSimReset | KSimInit | 
       
   561     		KSimInitFullFileChangeNotification | KUsimApplicationReset |
       
   562     		K3GSessionReset;
       
   563     }
       
   564     
       
   565 // -----------------------------------------------------------------------------
       
   566 // CPhone::AsyncOpL
       
   567 // -----------------------------------------------------------------------------
       
   568 //
       
   569 CVPbkAsyncObjectOperation<MVPbkSimPhoneObserver>* CPhone::AsyncOpL()
       
   570     {
       
   571     FUNC_ENTRY();
       
   572     if ( !iAsyncOp )
       
   573         {
       
   574         iAsyncOp = CVPbkAsyncObjectOperation<MVPbkSimPhoneObserver>::NewL();
       
   575         }
       
   576     FUNC_EXIT();
       
   577     return iAsyncOp;
       
   578     }
       
   579 
       
   580 // -----------------------------------------------------------------------------
       
   581 // CPhone::StartInitL
       
   582 // -----------------------------------------------------------------------------
       
   583 //
       
   584 TBool CPhone::StartInitL()
       
   585     {
       
   586     FUNC_ENTRY();
       
   587     if ( !iIsOpen && !iSTCommand )
       
   588         {
       
   589         VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
       
   590             "VPbkSimStoreImpl: CPhone::StartInitL"));    
       
   591 
       
   592         // phone is not open and service table is not currently loading
       
   593         LoadServiceTableL();
       
   594         FUNC_EXIT();
       
   595         return ETrue;
       
   596         }
       
   597     FUNC_EXIT();
       
   598     return EFalse;
       
   599     }
       
   600     
       
   601 // -----------------------------------------------------------------------------
       
   602 // CPhone::OpenETelPhoneL
       
   603 // -----------------------------------------------------------------------------
       
   604 //
       
   605 void CPhone::OpenETelPhoneL()
       
   606     {
       
   607     FUNC_ENTRY();
       
   608     if ( !iTelServer.Handle() )
       
   609         {
       
   610         User::LeaveIfError( iTelServer.Connect() );
       
   611         User::LeaveIfError( iTelServer.LoadPhoneModule( KMmTsyModuleName ) );
       
   612         // This enables extended errors from low level which are needed
       
   613         // to get detailed information when saving contacts
       
   614         TInt res = iTelServer.SetExtendedErrorGranularity( 
       
   615             RTelServer::EErrorExtended );
       
   616         // If no memory then leave otherwise continue -> application works
       
   617         // with core errors too. Only some error notes are not shown.
       
   618         if ( res == KErrNoMemory )
       
   619             {
       
   620             User::Leave( res );
       
   621             }
       
   622         }
       
   623 
       
   624     if ( !iPhone.SubSessionHandle() )
       
   625         {
       
   626         VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
       
   627             "VPbkSimStoreImpl: RTelServer Connected handle %d"),
       
   628             iTelServer.Handle());
       
   629         RTelServer::TPhoneInfo info;
       
   630         const TInt firstPhoneIndex = 0;
       
   631         User::LeaveIfError( iTelServer.GetPhoneInfo( 
       
   632             firstPhoneIndex , info ) );
       
   633         User::LeaveIfError( iPhone.Open( iTelServer, info.iName ) );
       
   634         VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
       
   635             "VPbkSimStoreImpl: RMobilePhone Open h%d"),
       
   636             iPhone.SubSessionHandle());
       
   637         
       
   638         ActivateFDNNotification();
       
   639         }
       
   640     FUNC_EXIT();
       
   641     }
       
   642 
       
   643 // -----------------------------------------------------------------------------
       
   644 // CPhone::HandleBtSapDeactivationL
       
   645 // -----------------------------------------------------------------------------
       
   646 //
       
   647 void CPhone::HandleBtSapDeactivationL()
       
   648     {
       
   649     FUNC_ENTRY();
       
   650     OpenETelPhoneL();
       
   651     /// If already open -> send only open message
       
   652     if ( !StartInitL() && iIsOpen )
       
   653         {
       
   654         SendObserverMessageR( iObservers, 
       
   655             &MVPbkSimPhoneObserver::PhoneOpened, *this );
       
   656         }
       
   657     FUNC_EXIT();
       
   658     }
       
   659 
       
   660 // -----------------------------------------------------------------------------
       
   661 // CPhone::ActivateBtSapAndSatRefreshL
       
   662 // -----------------------------------------------------------------------------
       
   663 //
       
   664 void CPhone::ActivateBtSapAndSatRefreshL()
       
   665     {
       
   666     FUNC_ENTRY();
       
   667     iSatNotifier.ActivateL( *this );
       
   668     iBtSapNotifier.AddObserverL( *this );
       
   669     FUNC_EXIT();
       
   670     }
       
   671 
       
   672 // -----------------------------------------------------------------------------
       
   673 // CPhone::DeActivateBtSapAndSatRefresh
       
   674 // -----------------------------------------------------------------------------
       
   675 //
       
   676 void CPhone::DeActivateBtSapAndSatRefresh()
       
   677     {
       
   678     FUNC_ENTRY();
       
   679     iSatNotifier.DeActivate( *this );
       
   680     iBtSapNotifier.RemoveObserver( *this );
       
   681     FUNC_EXIT();
       
   682     }
       
   683     
       
   684 // -----------------------------------------------------------------------------
       
   685 // CPhone::LoadServiceTable
       
   686 // -----------------------------------------------------------------------------
       
   687 //
       
   688 void CPhone::LoadServiceTableL()
       
   689     {
       
   690     FUNC_ENTRY();
       
   691     if ( !iSTCommand )
       
   692         {
       
   693         iSTCommand = CServiceTableCmd::NewLC( *this, iServiceTable );
       
   694         CleanupStack::Pop(); // iSTCommand
       
   695         iSTCommand->AddObserverL( *this );
       
   696         iSTCommand->Execute();
       
   697         }
       
   698     FUNC_EXIT();
       
   699     }
       
   700 
       
   701 // -----------------------------------------------------------------------------
       
   702 // CPhone::SimUsableL
       
   703 // -----------------------------------------------------------------------------
       
   704 //
       
   705 TBool CPhone::SimUsableL( MVPbkSimPhoneObserver::TErrorIdentifier& aErrorId )
       
   706     {
       
   707     FUNC_ENTRY();
       
   708     if ( !iSimStatus )
       
   709         {
       
   710         iSimStatus = CSimStatusNotification::NewL();
       
   711         iSimStatus->AddObserverL( *this );
       
   712         }
       
   713     TBool result = EFalse;
       
   714     if ( iSimStateInfo.BTSapEnabledL() )
       
   715         {
       
   716         aErrorId = MVPbkSimPhoneObserver::EBtSapActive;
       
   717         }
       
   718     else if ( iSimStatus->CurrentStatus() != VPbkSimStoreImpl::SimOkStatus )
       
   719         {
       
   720         aErrorId = MVPbkSimPhoneObserver::ESimCardNotInserted;
       
   721         }
       
   722     else
       
   723         {
       
   724         result = ETrue;
       
   725         }
       
   726     FUNC_EXIT();
       
   727     return result;
       
   728     }
       
   729 
       
   730 // -----------------------------------------------------------------------------
       
   731 // CPhone::ActivateFDNNotification
       
   732 // -----------------------------------------------------------------------------
       
   733 //
       
   734 void CPhone::ActivateFDNNotification()
       
   735     {
       
   736     FUNC_ENTRY();
       
   737     // Activate FDN activity notification
       
   738     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
       
   739         "VPbkSimStoreImpl: CPhone::ActivateFDNNotification"));
       
   740     iPhone.NotifyFdnStatusChange(iStatus, iFdnStatus);
       
   741     SetActive();
       
   742     FUNC_EXIT();
       
   743     }
       
   744 
       
   745 // -----------------------------------------------------------------------------
       
   746 // CPhone::CompleteSatRefresh
       
   747 // -----------------------------------------------------------------------------
       
   748 //
       
   749 void CPhone::CompleteSatRefresh()
       
   750     {
       
   751     FUNC_ENTRY();
       
   752     // If iSimRefreshCompletion exists it means that service table has
       
   753     // been updated due to SAT refresh. We have to tell SAT server
       
   754     // that we have done the update. 
       
   755     if ( iSimRefreshCompletion )
       
   756         {
       
   757         iSimRefreshCompletion->SatRefreshCompleted( *this, EFalse );
       
   758         iSimRefreshCompletion = NULL;
       
   759         }
       
   760     FUNC_EXIT();
       
   761     }
       
   762 
       
   763 // -----------------------------------------------------------------------------
       
   764 // CPhone::SimStatusOk
       
   765 // -----------------------------------------------------------------------------
       
   766 //
       
   767 void CPhone::SimStatusOk()
       
   768     {
       
   769     FUNC_ENTRY();
       
   770     OpenETelPhoneL();
       
   771     /// If already open -> send only open message
       
   772     if ( !StartInitL() && iIsOpen )
       
   773         {
       
   774         VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
       
   775             "VPbkSimStoreImpl: CPhone::SimStatusOk Send phone opened"));    
       
   776         SendObserverMessageR( iObservers, 
       
   777             &MVPbkSimPhoneObserver::PhoneOpened, *this );
       
   778         }
       
   779     FUNC_EXIT();
       
   780     }
       
   781 
       
   782 // -----------------------------------------------------------------------------
       
   783 // CPhone::SimStatusNotOk
       
   784 // -----------------------------------------------------------------------------
       
   785 //
       
   786 void CPhone::SimStatusNotOk()
       
   787     {
       
   788     FUNC_ENTRY();
       
   789     SendObserverMessageRVV( iObservers, 
       
   790         &MVPbkSimPhoneObserver::PhoneError, *this,
       
   791         MVPbkSimPhoneObserver::ESimCardNotInserted, KErrGeneral );
       
   792     FUNC_EXIT();
       
   793     }
       
   794 
       
   795 // -----------------------------------------------------------------------------
       
   796 // CPhone::SimStatusUninitialized
       
   797 // -----------------------------------------------------------------------------
       
   798 //
       
   799 void CPhone::SimStatusUninitialized()
       
   800     {
       
   801     FUNC_ENTRY();
       
   802     SendObserverMessageRVV( iObservers, 
       
   803         &MVPbkSimPhoneObserver::PhoneError, *this,
       
   804         MVPbkSimPhoneObserver::ESimCardNotInserted, KErrGeneral );
       
   805     FUNC_EXIT();
       
   806     }
       
   807 
       
   808 // -----------------------------------------------------------------------------
       
   809 // CPhone::SimStatusNotificationError
       
   810 // -----------------------------------------------------------------------------
       
   811 //
       
   812 void CPhone::SimStatusNotificationError( TInt /*aError*/ )
       
   813     {
       
   814     FUNC_ENTRY();
       
   815     SendObserverMessageRVV( iObservers, 
       
   816         &MVPbkSimPhoneObserver::PhoneError, *this,
       
   817         MVPbkSimPhoneObserver::ESimCardNotInserted, KErrGeneral );
       
   818     FUNC_EXIT();
       
   819     }
       
   820 
       
   821 // -----------------------------------------------------------------------------
       
   822 // CPhone::DoOpenL
       
   823 // -----------------------------------------------------------------------------
       
   824 //
       
   825 void CPhone::DoOpenL( MVPbkSimPhoneObserver& aObserver )
       
   826     {
       
   827     FUNC_ENTRY();
       
   828     if ( iObservers.Find( &aObserver ) != KErrNotFound )
       
   829         {
       
   830         aObserver.PhoneOpened( *this );
       
   831         }
       
   832     FUNC_EXIT();
       
   833     }
       
   834 
       
   835 // -----------------------------------------------------------------------------
       
   836 // CPhone::DoOpenError
       
   837 // -----------------------------------------------------------------------------
       
   838 //
       
   839 void CPhone::DoOpenError( MVPbkSimPhoneObserver& aObserver, TInt aError )
       
   840     {
       
   841     FUNC_ENTRY();
       
   842     if ( iObservers.Find( &aObserver ) != KErrNotFound )
       
   843         {
       
   844         aObserver.PhoneError( *this, MVPbkSimPhoneObserver::ESystem, aError );
       
   845         }
       
   846     FUNC_EXIT();
       
   847     }
       
   848 
       
   849 // -----------------------------------------------------------------------------
       
   850 // CPhone::DoOpenWithErrorL
       
   851 // -----------------------------------------------------------------------------
       
   852 //
       
   853 void CPhone::DoOpenWithErrorL
       
   854         ( MVPbkSimPhoneObserver& aObserver,
       
   855             MVPbkSimPhoneObserver::TErrorIdentifier aErrorId )
       
   856     {
       
   857     FUNC_ENTRY();
       
   858     if ( iObservers.Find( &aObserver ) != KErrNotFound )
       
   859         {
       
   860         aObserver.PhoneError( *this, aErrorId, KErrGeneral );
       
   861         }
       
   862     FUNC_EXIT();
       
   863     }
       
   864     
       
   865 } // namespace VPbkSimStoreImpl
       
   866 
       
   867 
       
   868 //  End of File