cellular/telephonysettings/src/PSetCallDivertingBasicImpl.cpp
changeset 0 ff3b6d0fd310
child 3 a4a774cb6ea7
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2008-2008 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: Implementation of CPSetCallDivertingBasicImpl class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "PSetCallDivertingBasicImpl.h"
       
    21 
       
    22 #include <badesca.h>
       
    23 #include <etelmm.h>           
       
    24 #include <e32math.h>
       
    25 #include <vmnumber.h>
       
    26 #include <e32svr.h>
       
    27 #include <featmgr.h>
       
    28 #include <centralrepository.h>
       
    29 #include <SettingsInternalCRKeys.h>
       
    30 
       
    31 #include "PsetCallDiverting.h"
       
    32 #include "PsetContainer.h"
       
    33 #include "MPsetDivertObs.h"
       
    34 #include "PsetTelephony.h"
       
    35 #include "PSetPanic.h"
       
    36 #include "MPsetRequestObs.h"
       
    37 #include "PSetUtility.h"
       
    38 #include "PhoneSettingsLogger.h"
       
    39 #include "PsetSAObserver.h"
       
    40 
       
    41 //  LOCAL CONSTANTS AND MACROS
       
    42 _LIT( KPSetIntNbr, "+" );
       
    43 _LIT( KPSNameOfClass, "CPSetCallDivertingBasicImpl" );
       
    44 
       
    45 // ============================ MEMBER FUNCTIONS ===============================
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CPSetCallDivertingBasicImpl::NewL
       
    49 // Two-phased constructor.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CPSetCallDivertingBasicImpl* CPSetCallDivertingBasicImpl::NewL( 
       
    53         MPsetDivertObserver& aObserver, 
       
    54         RMobilePhone& aPhone,
       
    55         CPsetCallDiverting* aDivert )
       
    56     {
       
    57     CPSetCallDivertingBasicImpl* self = new ( ELeave ) CPSetCallDivertingBasicImpl( aPhone, aDivert );
       
    58     CleanupStack::PushL( self );
       
    59     self->ConstructL( aObserver );
       
    60     CleanupStack::Pop( self );
       
    61     return self;
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CPSetCallDivertingBasicImpl::~CPSetCallDivertingBasicImpl
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CPSetCallDivertingBasicImpl::~CPSetCallDivertingBasicImpl()
       
    69     {
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CPSetCallDivertingBasicImpl::CPSetCallDivertingBasicImpl
       
    74 // C++ constructor can NOT contain any code, that
       
    75 // might leave.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CPSetCallDivertingBasicImpl::CPSetCallDivertingBasicImpl( 
       
    79                     RMobilePhone& aPhone, CPsetCallDiverting* aDivert ) : 
       
    80                     CPSetCallDivertingBase( aPhone, aDivert )
       
    81     {
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CPSetCallDivertingBasicImpl::ConstructL
       
    86 // Symbian 2nd phase constructor can leave.
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CPSetCallDivertingBasicImpl::ConstructL( MPsetDivertObserver& aObserver )
       
    90     {
       
    91     CPSetCallDivertingBase::ConstructL( aObserver );
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CPSetCallDivertingBasicImpl::ConstructL
       
    96 // Symbian 2nd phase constructor can leave.
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CPSetCallDivertingBasicImpl::SetDivertingL( const TCallDivertSetting& aDivert,  TBasicServiceGroups aBsc )
       
   100     {
       
   101     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBasicImpl::SetDivertingL");
       
   102     __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBasicImpl::SetDivertingL: aBsc: %d", aBsc );
       
   103    if ( IsActive() )
       
   104        {
       
   105        User::Leave( KErrInUse );
       
   106        }
       
   107    iBsc = aBsc;
       
   108    
       
   109    CPsetTelephony::CheckLineModeL( aDivert.iServiceGroup, &iPhone, iLine );
       
   110    if ( !iLine->SubSessionHandle() )
       
   111        {
       
   112        User::Leave( KErrBadHandle );
       
   113        }
       
   114        
       
   115    SetRequestStatus( EPSetChangeDivert );
       
   116    iReason = PSetUtility::GetDivertReason ( aDivert.iCondition );
       
   117    iVoiceDivert = SetVoiceDivert( aDivert, aBsc );
       
   118 
       
   119    ValidateBsc( aBsc );
       
   120    iPluralNotes = IsMultiAffectingDivert( aDivert, aBsc );
       
   121 
       
   122    //Copy data to member variable
       
   123    iChangeInfo.iNumber.iTelNumber.Copy( aDivert.iNumber );
       
   124    iChangeInfo.iTimeout = KPSetDefaultDelayTimeValue;
       
   125    if ( aBsc == EAltTele )
       
   126        {
       
   127        iChangeInfo.iServiceGroup = PSetUtility::VerifyAltLineUseL();
       
   128        }
       
   129    iChangeInfo.iServiceGroup = PSetUtility::ChangeToEtelInternal( aBsc ); 
       
   130    iChangeInfo.iNumber.iNumberPlan = RMobilePhone::EIsdnNumberPlan;
       
   131    iChangeInfo.iNumber.iTypeOfNumber = RMobilePhone::EUnknownNumber;
       
   132    if ( iChangeInfo.iNumber.iTelNumber.Length() > 0 )
       
   133        {
       
   134        if ( iChangeInfo.iNumber.iTelNumber.Left(1) == KPSetIntNbr )
       
   135            {
       
   136            iChangeInfo.iNumber.iTypeOfNumber = 
       
   137                RMobilePhone::EInternationalNumber;
       
   138            }
       
   139        }
       
   140 
       
   141    switch ( aDivert.iSetting )
       
   142        {
       
   143        case ERegisterDiverting:
       
   144           /*****************************************************
       
   145           *    Series 60 Customer / ETel
       
   146           *    Series 60  ETel API
       
   147           *****************************************************/
       
   148           iChangeInfo.iAction = RMobilePhone::EServiceActionRegister;
       
   149           iChangeInfo.iTimeout = aDivert.iNoReplyTimer;
       
   150           __PHSLOGSTRING("[PHS]    CPSetCallDivertingBasicImpl::SetDivertingL: ERegisterDiverting" );
       
   151           break;
       
   152        case EEraseDiverting:
       
   153            iChangeInfo.iAction = RMobilePhone::EServiceActionErase;
       
   154            __PHSLOGSTRING("[PHS]    CPSetCallDivertingBasicImpl::SetDivertingL: EEraseDiverting" );
       
   155            break;
       
   156        case EActivateDiverting:
       
   157            iChangeInfo.iAction = RMobilePhone::EServiceActionActivate;
       
   158            iChangeInfo.iTimeout = aDivert.iNoReplyTimer;
       
   159            __PHSLOGSTRING("[PHS]    CPSetCallDivertingBasicImpl::SetDivertingL: EActivateDiverting" );
       
   160            break;
       
   161        case ECancelDiverting:
       
   162            iChangeInfo.iAction = RMobilePhone::EServiceActionDeactivate;
       
   163            __PHSLOGSTRING("[PHS]    CPSetCallDivertingBasicImpl::SetDivertingL: ECancelDiverting" );
       
   164            break;
       
   165        default:
       
   166            User::Leave( KErrArgument );
       
   167            break;
       
   168        }
       
   169 
       
   170    //Start requesting for setting Divert.
       
   171    iPhone.SetCallForwardingStatus( iStatus, iReason, iChangeInfo );
       
   172    StartRequestingL( KPsetRequestAlreadySet );    
       
   173    __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBasicImpl::SetDivertingL" );
       
   174    }
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // RunL
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 void CPSetCallDivertingBasicImpl::RunL()
       
   181     {
       
   182     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBasicImpl::RunL" );           
       
   183    __ASSERT_ALWAYS( 
       
   184        iObserver != NULL, Panic( KPSNameOfClass, ECDRequestPanicNoObserver ) );
       
   185 
       
   186    //Hide requesting note - does not leave when deleting a note.
       
   187    iObserver->SetEngineContact( iDivert );
       
   188    iObserver->HandleCFRequestingL( EFalse, EFalse );
       
   189 
       
   190    //Handle error case.
       
   191    if ( iStatus != KErrNone )
       
   192        {
       
   193        iObserver->HandleDivertingErrorL( iStatus.Int() );
       
   194        RequestCompleted( iStatus.Int() );
       
   195        return;
       
   196        }
       
   197        
       
   198    iDivertStatus.Initialize();
       
   199    switch ( iCurrentReq )
       
   200        {
       
   201        case EPSetChangeDivert:
       
   202            {
       
   203            __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBasicImpl::RunL: EPSetChangeDivert" );
       
   204            //Notify Observer            
       
   205            iDivertStatus.iStatus = PSetUtility::GetChangeInfoStatus( iChangeInfo.iAction );
       
   206            
       
   207             // Check is done because of VOIP notification functionality(PSetNotesUI).
       
   208            if ( iVoiceDivert && !iVideoDivert )
       
   209                {
       
   210                iDivertStatus.iServiceGroup = EServiceGroupVoice;
       
   211                }
       
   212            
       
   213            iObserver->HandleDivertingChangedL( iDivertStatus, iPluralNotes );
       
   214            
       
   215            //Notify observer.
       
   216            HandleSANotificationL( 
       
   217                IsVMBXDivertL( iChangeInfo.iNumber.iTelNumber ), 
       
   218                iDivertStatus.iStatus );
       
   219            break;
       
   220            }
       
   221        case EPSetGetDivertStatus:
       
   222            {
       
   223            __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBasicImpl::RunL: EPSetGetDivertStatus" );
       
   224 
       
   225            CMobilePhoneCFList* cfList = iCfInterrogator->RetrieveListL();
       
   226            CleanupStack::PushL( cfList );
       
   227            CMobilePhoneCFList* cleanedList = CMobilePhoneCFList::NewL();            
       
   228            CleanupStack::PushL( cleanedList );
       
   229            
       
   230            TInt numOfItems = cfList->Enumerate();
       
   231            TInt index = 0;
       
   232            RMobilePhone::TMobilePhoneCFInfoEntryV1 cfEntry;
       
   233            RMobilePhone::TMobilePhoneCFInfoEntryV1 copy;
       
   234            iDivertStatus.iStatus = EDivertingStatusNotRegistered;
       
   235            while( index < numOfItems )
       
   236                {
       
   237                cfEntry = cfList->GetEntryL( index );
       
   238                iBsc = PSetUtility::ChangeToGSM( cfEntry.iServiceGroup );
       
   239 
       
   240                if ( cfEntry.iStatus == RMobilePhone::ECallForwardingStatusActive )
       
   241                    {
       
   242                    copy.iServiceGroup = cfEntry.iServiceGroup;
       
   243                    copy.iCondition = cfEntry.iCondition;
       
   244                    copy.iStatus = cfEntry.iStatus;
       
   245                    copy.iNumber = cfEntry.iNumber;
       
   246                    copy.iTimeout = cfEntry.iTimeout;
       
   247                    cleanedList->AddEntryL( copy );
       
   248                    }
       
   249                    
       
   250                 __PHSLOGSTRING1("[PHS] CPSetCallDivertingBasicImpl::RunL: EPSetGetDivertStatus     iBsc: %d", iBsc );
       
   251                 __PHSLOGSTRING1("[PHS] CPSetCallDivertingBasicImpl::RunL: EPSetGetDivertStatus iStatus: %d", cfEntry.iStatus );
       
   252                if ( iBsc == EAllTeleAndBearer || iBsc == EAllTele || iBsc == ETelephony || iBsc == EAltTele ||
       
   253                    iBsc == EAllBearer || iBsc == EAllSync || iBsc == ESyncData )
       
   254                    {
       
   255                    // iVoiceDivert is set to true to ensure that the icons are updated in every case.
       
   256                    iVoiceDivert = ETrue;
       
   257                    if ( ( cfEntry.iStatus != RMobilePhone::ECallForwardingStatusNotRegistered )
       
   258                        && ( cfEntry.iStatus != RMobilePhone::ECallForwardingStatusNotActive )
       
   259                        && ( cfEntry.iStatus != RMobilePhone::ECallForwardingStatusNotProvisioned ) )
       
   260                        {
       
   261                        iDivertStatus.iStatus = EDivertingStatusActive;
       
   262                        }
       
   263                    else
       
   264                        {
       
   265                        iDivertStatus.iStatus = EDivertingStatusNotRegistered;
       
   266                        }
       
   267                    
       
   268                    HandleSANotificationL( 
       
   269                            IsVMBXDivertL( cfEntry.iNumber.iTelNumber ), 
       
   270                            iDivertStatus.iStatus );
       
   271                    }
       
   272                index++;
       
   273                }
       
   274            if ( cleanedList->Enumerate() == 0 )
       
   275                {
       
   276                iObserver->HandleDivertingStatusL( *cfList, iPluralNotes );
       
   277                }
       
   278            else
       
   279                {
       
   280                iObserver->HandleDivertingStatusL( *cleanedList, iPluralNotes );
       
   281                }
       
   282            CleanupStack::PopAndDestroy( 2 ); //cleanedList, cfList
       
   283            cfList = NULL;
       
   284            cleanedList = NULL;
       
   285            iCFStatusCheck = EFalse; 
       
   286            break;
       
   287            }
       
   288        default:
       
   289            Panic( KPSNameOfClass, ECDRequestPanicIncorrectRequest );
       
   290            break;
       
   291        } 
       
   292     RequestCompleted( KErrNone );
       
   293     __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBasicImpl::RunL" );
       
   294     }    
       
   295 
       
   296 // ---------------------------------------------------------------------------
       
   297 // DoCancel
       
   298 // ---------------------------------------------------------------------------
       
   299 //
       
   300 void CPSetCallDivertingBasicImpl::DoCancel()
       
   301     {
       
   302     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBasicImpl::DoCancel" );
       
   303     //Decide which request to cancel.
       
   304     switch( iCurrentReq )
       
   305         {
       
   306         case EPSetChangeDivert:
       
   307             __PHSLOGSTRING("[PHS]   DoCancel - EPSetChangeDivert" );
       
   308             iPhone.CancelAsyncRequest( EMobilePhoneSetCallForwardingStatus );
       
   309             break;
       
   310         case EPSetGetDivertStatus:
       
   311             __PHSLOGSTRING("[PHS]   DoCancel - EPSetGetDivertStatus" );
       
   312             iCfInterrogator->Cancel();
       
   313             delete iCfInterrogator;
       
   314             iCfInterrogator = NULL;
       
   315             break;
       
   316         default:
       
   317             break;
       
   318         }
       
   319     
       
   320     //Set current request to none.
       
   321     iCurrentReq = EPSetNone;
       
   322     iVoiceDivert = EFalse;
       
   323     iVideoDivert = EFalse;
       
   324     __PHSLOGSTRING("[PHS]<-- CPSetCallDivertingBasicImpl::DoCancel" );
       
   325     }
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 // RunError
       
   329 // ---------------------------------------------------------------------------
       
   330 //
       
   331 TInt CPSetCallDivertingBasicImpl::RunError( TInt aError ) 
       
   332     {
       
   333     __PHSLOGSTRING1("[PHS]--> CPSetCallDivertingBasicImpl::RunError aError: %d", aError );
       
   334     if ( ( iCurrentReq == EPSetGetDivertStatus || iCurrentReq == EPSetChangeDivert)
       
   335          && iVoiceDivert )
       
   336         {
       
   337         __PHSLOGSTRING("[PHS]   RunError - HandleSANotificationL" );
       
   338         TRAP_IGNORE( HandleSANotificationL( EFalse, iDivertStatus.iStatus ) );
       
   339         }
       
   340         
       
   341     if ( iCurrentReq == EPSetGetDivertStatus )
       
   342         {
       
   343         iCFStatusCheck = EFalse;
       
   344         }   
       
   345     aError = KErrNone;
       
   346         
       
   347     //Set current request to none.
       
   348     iCurrentReq = EPSetNone;    
       
   349     iVoiceDivert = EFalse;
       
   350     iVideoDivert = EFalse;
       
   351     __PHSLOGSTRING("[PHS]<-- CPSetCallDivertingBasicImpl::RunError" );
       
   352     return aError;  
       
   353     }
       
   354 
       
   355 // ---------------------------------------------------------------------------
       
   356 //  If unconditional voice divert is activated/cancelled, notifies observer, 
       
   357 //  so that it can set on/off indicators.
       
   358 // ---------------------------------------------------------------------------
       
   359 //
       
   360 void CPSetCallDivertingBasicImpl::HandleSANotificationL( 
       
   361     TBool aVmbxDivert, TDivertingStatus& aCfStatus )
       
   362     {
       
   363     __PHSLOGSTRING2("[PHS]--> CPSetCallDivertingBasicImpl::HandleSANotificationL aVmbxDivert: %d, aCfStatus: %d", aVmbxDivert, aCfStatus );
       
   364     TBool divertChanged = EFalse;
       
   365 
       
   366     //If divert is not with voice, do not touch indicators.
       
   367     if ( !iVoiceDivert )
       
   368         {
       
   369         return;
       
   370         }
       
   371 
       
   372     //Unconditional divert and all diverts
       
   373     if ( iReason == RMobilePhone::ECallForwardingUnconditional ||
       
   374         iReason == RMobilePhone::ECallForwardingAllCases )
       
   375         {
       
   376         if ( iCurrentReq == EPSetChangeDivert )
       
   377             {
       
   378             //show indicator if, activation/registration, else hide it
       
   379             //these are probably incorrect....
       
   380             divertChanged = 
       
   381                 ( iChangeInfo.iAction == RMobilePhone::EServiceActionRegister ||
       
   382                   iChangeInfo.iAction == RMobilePhone::EServiceActionActivate);
       
   383             }
       
   384         else
       
   385             {
       
   386             //show indicator if status is activated, hide for cancelled.
       
   387             divertChanged = ( aCfStatus == EDivertingStatusActive );
       
   388             }
       
   389         }
       
   390     else
       
   391         {
       
   392         //if not unconditional, do not touch indicators.
       
   393         return;
       
   394         }
       
   395 
       
   396     CPsetSAObserver* systemObserver = CPsetSAObserver::NewL();
       
   397     CleanupStack::PushL( systemObserver );
       
   398     
       
   399     TUnconditionalCFStatus status(KCFIndicatorUnknown);
       
   400     
       
   401     User::LeaveIfError( systemObserver->GetCurrentDivertStatus( status ) );
       
   402     
       
   403     TCallDivertNotifySetting setting = CreateDivertNotifySetting(
       
   404         status, divertChanged, aVmbxDivert, iBsc );
       
   405     
       
   406     // Notify observer that Diverts have changed.
       
   407     systemObserver->NotifyDivertChange( GetSAAls(), 
       
   408         setting,
       
   409         -1 );
       
   410     
       
   411     CleanupStack::PopAndDestroy( systemObserver );
       
   412 
       
   413     __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBasicImpl::HandleSANotificationL" );
       
   414     }
       
   415 
       
   416 // ---------------------------------------------------------------------------
       
   417 // Returns ETrue if divert operation is to voice or to all operations.
       
   418 // ---------------------------------------------------------------------------
       
   419 //
       
   420 TBool CPSetCallDivertingBasicImpl::SetVoiceDivert( const TCallDivertSetting& aDivert,
       
   421     const TBasicServiceGroups aBsc )
       
   422     {
       
   423     iVideoDivert = EFalse;
       
   424     if ( aDivert.iServiceGroup == EServiceGroupVoice ||
       
   425          aDivert.iServiceGroup == EServiceGroupAllTeleservices)
       
   426         {
       
   427         return ETrue;
       
   428         }
       
   429     else if ( ( aDivert.iServiceGroup == EServiceGroupData && ( aBsc == EAllBearer ||
       
   430              aBsc == EAllSync || aBsc == ESyncData ) ) )
       
   431         {
       
   432         iVideoDivert = ETrue;
       
   433         return ETrue;
       
   434         }
       
   435     return EFalse;
       
   436     }
       
   437 
       
   438 // ---------------------------------------------------------------------------
       
   439 // Gets Als information.
       
   440 // ---------------------------------------------------------------------------
       
   441 //
       
   442 TSelectedLine CPSetCallDivertingBasicImpl::GetSAAls()
       
   443     {
       
   444     __PHSLOGSTRING("[PHS]--> CPSetCallDivertingBasicImpl::GetSAAls" );
       
   445     __PHSLOGSTRING2("[PHS] iAls: %d iBsc: %d", iAls, iBsc  );
       
   446     TSelectedLine alsValue = ENotSupportedLine;
       
   447     switch ( iAls )
       
   448         {
       
   449         case ESSSettingsAlsNotSupported:
       
   450             alsValue = ENotSupportedLine;
       
   451             break;
       
   452         case ESSSettingsAlsPrimary:
       
   453             iChangeInfo.iServiceGroup == RMobilePhone::EAuxVoiceService 
       
   454                 ? ( alsValue = EAuxiliaryLine )  
       
   455                 : ( alsValue = EPrimaryLine );
       
   456             break;
       
   457         case ESSSettingsAlsAlternate:
       
   458             alsValue = EAuxiliaryLine;
       
   459             break;
       
   460         default:
       
   461             alsValue = ENotSupportedLine;
       
   462             break;
       
   463         }
       
   464     
       
   465     // If user checks/activates divert to line which is not selected currently than we have
       
   466     // to change returned alsvalue accordinly, if this is not done divert icon status is updated to wrong status.
       
   467     // Example case: Line 2 active user activates divert to line 1: **21*phonenumber*11#.
       
   468     if ( iBsc == EAltTele && iAls == ESSSettingsAlsPrimary )
       
   469         {
       
   470         __PHSLOGSTRING("[PHS]    CPSetCallDivertingBasicImpl::GetSAAls - Line 2 divert activation/check from Line 1" );
       
   471         alsValue = EAuxiliaryLine;
       
   472         }
       
   473     else if ( iBsc == ETelephony && iAls == ESSSettingsAlsAlternate )
       
   474         {
       
   475         __PHSLOGSTRING("[PHS]    CPSetCallDivertingBasicImpl::GetSAAls - Line 1 divert activation/check from Line 2" );
       
   476         alsValue = EPrimaryLine;
       
   477         }
       
   478     
       
   479     __PHSLOGSTRING1("[PHS]    CPSetCallDivertingBasicImpl::GetSAAls: alsValue: %d", alsValue );
       
   480     __PHSLOGSTRING("[PHS] <--CPSetCallDivertingBasicImpl::GetSAAls" );
       
   481     return alsValue;
       
   482     }
       
   483 
       
   484 // End of File