phoneapp/phoneuicontrol/src/cphonecbamanager.cpp
changeset 77 2be0b271d017
parent 72 c76a0b1755b9
equal deleted inserted replaced
72:c76a0b1755b9 77:2be0b271d017
     1 /*
       
     2 * Copyright (c) 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: Class takes care of CBA's.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cphonecbamanager.h"
       
    19 
       
    20 #include "mpeengineinfo.h"
       
    21 #include "mphoneviewcommandhandle.h"
       
    22 #include "mphonestatemachine.h"
       
    23 
       
    24 #include <featmgr.h>
       
    25 
       
    26 #include "phonerssbase.h"
       
    27 #include "phoneui.pan"
       
    28 #include "phonelogger.h"
       
    29 
       
    30 #include "cphonestate.h"
       
    31 #include "cphonecenrepproxy.h"
       
    32 #include "cphonemainresourceresolver.h"
       
    33 
       
    34 #include "telephonyvariant.hrh"
       
    35 #include "phoneui.hrh"
       
    36 
       
    37 #include "tphonecmdparamboolean.h"
       
    38 #include "tphonecmdparaminteger.h"
       
    39 #include "tphonecmdparamcallstatedata.h"
       
    40 #include "tphonecmdparamboolean.h"
       
    41 
       
    42 
       
    43 // ======== MEMBER FUNCTIONS ========
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CPhoneCbaManager::CPhoneCbaManager
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CPhoneCbaManager::CPhoneCbaManager(
       
    50          CPhoneState* aState,
       
    51          MPhoneViewCommandHandle& aViewCommandHandle,
       
    52          MPhoneStateMachine& aStateMachine )
       
    53    : iState ( aState ), 
       
    54      iViewCommandHandle ( aViewCommandHandle ),
       
    55      iStateMachine ( aStateMachine ),
       
    56      iSoftRejectStatus ( ETrue )
       
    57     {
       
    58     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneCbaManager::CPhoneCbaManager() ");
       
    59     }
       
    60 
       
    61  // ---------------------------------------------------------------------------
       
    62  // CPhoneCbaManager::NewL
       
    63  // ---------------------------------------------------------------------------
       
    64  //
       
    65 CPhoneCbaManager* CPhoneCbaManager::NewL( 
       
    66         CPhoneState* aState,
       
    67         MPhoneViewCommandHandle& aViewCommandHandle,
       
    68         MPhoneStateMachine& aStateMachine )
       
    69      {
       
    70      __LOGMETHODSTARTEND( EPhoneControl, "CPhoneCbaManager::NewL() ");
       
    71      return new (ELeave) CPhoneCbaManager( aState, aViewCommandHandle, aStateMachine );
       
    72      }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 //  CPhoneCbaManager::~CPhoneCbaManager
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 CPhoneCbaManager::~CPhoneCbaManager()
       
    79      {
       
    80      __LOGMETHODSTARTEND( EPhoneControl, "CPhoneCbaManager::~CPhoneCbaManager() ");
       
    81      }
       
    82  
       
    83 // ======== LOCAL FUNCTIONS ========
       
    84 
       
    85 // -----------------------------------------------------------
       
    86 // CPhoneCbaManager::UpdateInCallCbaL
       
    87 // -----------------------------------------------------------
       
    88 //
       
    89 void CPhoneCbaManager::UpdateInCallCbaL()
       
    90     {
       
    91     __LOGMETHODSTARTEND(EPhoneControl, "CPhoneCbaManager::UpdateInCallCbaL() ");
       
    92     UpdateCbaL( EPhoneCallHandlingInCallCBA );
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------
       
    96 // CPhoneCbaManager::UpdateCbaL
       
    97 // -----------------------------------------------------------
       
    98 //
       
    99 EXPORT_C void CPhoneCbaManager::UpdateCbaL( TInt aResource )
       
   100     {
       
   101     __LOGMETHODSTARTEND(EPhoneControl, "CPhoneCbaManager::UpdateCbaL() ");
       
   102     __ASSERT_DEBUG( iStateMachine.PhoneEngineInfo(),
       
   103         Panic( EPhoneCtrlInvariant ) );
       
   104     TInt resourceId = aResource;
       
   105     TPhoneCmdParamBoolean hold;
       
   106     iViewCommandHandle.ExecuteCommandL( EPhoneViewGetHoldFlag, &hold );
       
   107 
       
   108     const TBool coverHideSendEndKey =
       
   109         CPhoneCenRepProxy::Instance()->IsTelephonyFeatureSupported(
       
   110             KTelephonyLVFlagCoverHideSendEndKey );
       
   111 
       
   112     const TPEAudioOutput audioOutput =
       
   113         iStateMachine.PhoneEngineInfo()->AudioOutput();
       
   114 
       
   115     TBool btAvailable = iStateMachine.PhoneEngineInfo()->AudioOutputAvailable(
       
   116         EPEBTAudioAccessory );
       
   117     
       
   118     TPhoneCmdParamBoolean btParam;
       
   119     btParam.SetBoolean( audioOutput == EPEBTAudioAccessory );        
       
   120     iViewCommandHandle.ExecuteCommand(EPhoneViewSetBlueToothFlag,&btParam);
       
   121 
       
   122     SetSoftRejectDimmedFlag();
       
   123     
       
   124     TPhoneCmdParamBoolean btAvailableParam;
       
   125     btAvailableParam.SetBoolean( btAvailable );        
       
   126     iViewCommandHandle.ExecuteCommand(
       
   127             EPhoneViewSetBluetoothAvailableFlag,&btAvailableParam);
       
   128 
       
   129     // Check is Audio muted
       
   130     if ( iStateMachine.PhoneEngineInfo()->AudioMute() )
       
   131         {
       
   132         resourceId = EPhoneCallHandlingInCallUnmuteCBA;
       
   133         }
       
   134     // Multicall swap
       
   135     else if ( EPhoneCallHandlingNewCallSwapCBA == aResource )
       
   136         {
       
   137         resourceId = EPhoneCallHandlingNewCallSwapCBA;
       
   138         }
       
   139     // Call waiting cases
       
   140     else if ( EPhoneCallHandlingCallWaitingCBA == aResource )
       
   141         {
       
   142         resourceId = EPhoneCallHandlingCallWaitingCBA;
       
   143         if ( iState->IsSwivelClosed() )
       
   144             {
       
   145             TPhoneCmdParamInteger activeCallCount;
       
   146             iViewCommandHandle.ExecuteCommandL(
       
   147                     EPhoneViewGetCountOfActiveCalls, &activeCallCount );
       
   148             if( activeCallCount.Integer() == EOneActiveCall )
       
   149                 {
       
   150                 resourceId = EPhoneCallHandlingWaitingAnswerSwivelClosedCBA;
       
   151                 }
       
   152             else if( activeCallCount.Integer() == ETwoActiveCalls )
       
   153                 {
       
   154                 resourceId = EPhoneCallHandlingWaitingReplaceSwivelClosedCBA;
       
   155                 }
       
   156             }
       
   157         }
       
   158     // Check is call in hold
       
   159     else if ( hold.Boolean() )
       
   160         {
       
   161         resourceId = EPhoneCallHandlingInCallUnholdCBA;
       
   162         }
       
   163     // Is BT accessory connected
       
   164     else if ( audioOutput == EPEBTAudioAccessory &&
       
   165               IsVoiceCallAlertingOrActiveL() &&
       
   166               !coverHideSendEndKey )
       
   167         {
       
   168         resourceId = EPhoneCallHandlingInCallHandsetCBA;
       
   169         }
       
   170     else if ( audioOutput == EPEWiredAudioAccessory ||
       
   171               coverHideSendEndKey || iState->IsSwivelClosed() )
       
   172         {
       
   173         resourceId = EPhoneCallHandlingInCallNoIhfCBA;
       
   174         }
       
   175     // Check BT availability
       
   176     else if ( audioOutput == EPELoudspeaker )
       
   177         {
       
   178         if ( btAvailable )
       
   179             {
       
   180             resourceId = EPhoneCallHandlingInCallBtaaCBA;
       
   181             }
       
   182         else
       
   183             {
       
   184             resourceId = EPhoneCallHandlingInCallHandsetCBA;
       
   185             }
       
   186         }
       
   187     else if ( audioOutput == EPEHandset &&  btAvailable )
       
   188         {
       
   189         resourceId = EPhoneCallHandlingInCallBtaaCBA;
       
   190         }
       
   191     SetCbaL( resourceId );
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------
       
   195 // CPhoneCbaManager::UpdateIncomingCbaL
       
   196 // -----------------------------------------------------------
       
   197 //
       
   198 EXPORT_C void CPhoneCbaManager::UpdateIncomingCbaL( TInt aCallId )
       
   199     {
       
   200     __LOGMETHODSTARTEND(EPhoneControl,"CPhoneCbaManager::UpdateIncomingCbaL()" );
       
   201     const TBool coverHideSendEndKey =
       
   202         CPhoneCenRepProxy::Instance()->IsTelephonyFeatureSupported(
       
   203             KTelephonyLVFlagCoverHideSendEndKey );
       
   204 
       
   205     const TProfileRingingType ringingType =
       
   206         iStateMachine.PhoneEngineInfo()->RingingType();
       
   207 
       
   208     const TBool callIsAlerting =
       
   209             !(( ringingType == EProfileRingingTypeSilent ) ||
       
   210               ( ringingType == EProfileRingingTypeBeepOnce ));
       
   211 
       
   212     // Update soft reject flag
       
   213     iSoftRejectStatus = ETrue;
       
   214     // VoIP calls do not support sms sending
       
   215     if ( iStateMachine.PhoneEngineInfo()->CallType( aCallId ) == EPECallTypeVoIP 
       
   216         || iStateMachine.PhoneEngineInfo()->RemotePhoneNumber( aCallId ).Length() == 0 )
       
   217         {
       
   218         iSoftRejectStatus = EFalse;
       
   219         }
       
   220     
       
   221     TPhoneCmdParamBoolean dimSoftRejectParam;
       
   222     dimSoftRejectParam.SetBoolean( !iSoftRejectStatus );        
       
   223     iViewCommandHandle.ExecuteCommand(
       
   224             EPhoneViewSetSoftRejectDimmed, &dimSoftRejectParam );
       
   225     
       
   226     TInt incomingCbaResourceId;
       
   227 
       
   228     if ( iState->IsSwivelClosed() )
       
   229         {
       
   230         if ( !callIsAlerting || iRingtoneSilenced )
       
   231             {
       
   232             incomingCbaResourceId = EPhoneCallHandlingIncomingSilentSwivelClosedCBA;
       
   233             }
       
   234         else
       
   235             {
       
   236             incomingCbaResourceId = EPhoneCallHandlingIncomingSwivelClosedCBA;
       
   237             }
       
   238         }
       
   239     else if ( coverHideSendEndKey )
       
   240         {
       
   241         if ( callIsAlerting )
       
   242             {
       
   243             // Set CBA to Options..Silence
       
   244             incomingCbaResourceId = EPhoneCallHandlingIncomingSliderCBA;
       
   245             }
       
   246         else if ( iSoftRejectStatus )
       
   247             {
       
   248             // Set CBA for soft reject
       
   249             incomingCbaResourceId = EPhoneCallHandlingIncomingSoftRejectSliderCBA;
       
   250             }
       
   251         else
       
   252             {
       
   253             // Set CBA to Options..Reject
       
   254             incomingCbaResourceId = EPhoneCallHandlingIncomingSilentSliderCBA;
       
   255             }
       
   256         }
       
   257     else
       
   258         {
       
   259         if ( callIsAlerting )
       
   260             {
       
   261             incomingCbaResourceId = GetIncomingCallSilenceCBA( iSoftRejectStatus );
       
   262             }
       
   263         else if ( iSoftRejectStatus )
       
   264             {
       
   265             // Set CBA for soft reject
       
   266             incomingCbaResourceId = EPhoneCallHandlingIncomingSoftRejectCBA;
       
   267             }
       
   268         else
       
   269             {
       
   270             incomingCbaResourceId = EPhoneCallHandlingIncomingRejectCBA;
       
   271             }
       
   272         }
       
   273     SetCbaL( incomingCbaResourceId );
       
   274     }
       
   275 
       
   276 // -----------------------------------------------------------
       
   277 // CPhoneCbaManager::SetCbaL
       
   278 // -----------------------------------------------------------
       
   279 //
       
   280 EXPORT_C void CPhoneCbaManager::SetCbaL( TInt aResource )
       
   281     {
       
   282     __LOGMETHODSTARTEND(EPhoneControl,"CPhoneCbaManager::SetCbaL()" );
       
   283     __PHONELOG1( EBasic, EPhoneControl,
       
   284             "CPhoneCbaManager::SetCbaL : %d",aResource );
       
   285     if ( EPhoneCallHandlingIncomingRejectCBA == aResource ||
       
   286          EPhoneCallHandlingIncomingSoftRejectCBA == aResource )
       
   287         {
       
   288         SetSoftRejectDimmedFlag();
       
   289         }
       
   290     
       
   291     TPhoneCmdParamInteger integerParam;
       
   292     integerParam.SetInteger(
       
   293         CPhoneMainResourceResolver::Instance()->ResolveResourceID(
       
   294         aResource ) );
       
   295     iViewCommandHandle.ExecuteCommandL( EPhoneViewUpdateCba,
       
   296         &integerParam );
       
   297     }
       
   298 
       
   299 // -----------------------------------------------------------
       
   300 // CPhoneCbaManager::UpdateCbaSwivelStateChangedL
       
   301 // -----------------------------------------------------------
       
   302 //
       
   303 void CPhoneCbaManager::UpdateCbaSwivelStateChangedL()
       
   304     {
       
   305     __LOGMETHODSTARTEND(EPhoneControl,"CPhoneCbaManager::UpdateCbaSwivelStateChangedL()" );
       
   306     TPhoneCmdParamCallStateData callStateData;
       
   307     callStateData.SetCallState( EPEStateRinging );
       
   308     iViewCommandHandle.HandleCommandL(
       
   309         EPhoneViewGetCallIdByState, &callStateData );
       
   310     TInt incomingCall = callStateData.CallId();
       
   311 
       
   312     TPhoneCmdParamInteger activeCallCount;
       
   313     iViewCommandHandle.ExecuteCommandL(
       
   314             EPhoneViewGetCountOfActiveCalls, &activeCallCount );
       
   315 
       
   316     if ( incomingCall > KErrNotFound )
       
   317         {
       
   318        if( activeCallCount.Integer() == ENoActiveCalls )
       
   319             {
       
   320             UpdateIncomingCbaL( incomingCall );
       
   321             }
       
   322         else
       
   323             {
       
   324             UpdateCbaL( EPhoneCallHandlingCallWaitingCBA );
       
   325             }
       
   326         }
       
   327     else if ( activeCallCount.Integer() != ENoActiveCalls )
       
   328         {
       
   329         UpdateInCallCbaL();
       
   330         }
       
   331     }
       
   332 
       
   333 // -----------------------------------------------------------
       
   334 // CPhoneCbaManager::IsVoiceCallAlertingOrActiveL
       
   335 // -----------------------------------------------------------
       
   336 //
       
   337 TBool CPhoneCbaManager::IsVoiceCallAlertingOrActiveL()
       
   338     {
       
   339     __LOGMETHODSTARTEND( EPhoneControl,
       
   340         "CPhoneCbaManager::IsVoiceCallAlertingOrActiveL()" );
       
   341     TBool retVal = EFalse;
       
   342     // Fetch alerting call's id from view
       
   343     TPhoneCmdParamCallStateData callStateData;
       
   344     callStateData.SetCallState( EPEStateConnecting );
       
   345     iViewCommandHandle.HandleCommandL(
       
   346         EPhoneViewGetCallIdByState, &callStateData );
       
   347 
       
   348     if ( callStateData.CallId() > KErrNotFound )
       
   349         {
       
   350         TPECallType type = iStateMachine.PhoneEngineInfo()->CallType(
       
   351             callStateData.CallId() );
       
   352         if ( EPECallTypeCSVoice == type || EPECallTypeVoIP == type )
       
   353             {
       
   354             retVal = ETrue;
       
   355             }
       
   356         }
       
   357     else
       
   358         {
       
   359         // Fetch active call's id from view
       
   360         TPhoneCmdParamCallStateData callStateData;
       
   361         callStateData.SetCallState( EPEStateConnected );
       
   362         iViewCommandHandle.HandleCommandL(
       
   363             EPhoneViewGetCallIdByState, &callStateData );
       
   364         if ( callStateData.CallId() > KErrNotFound )
       
   365             {
       
   366             TPECallType type = iStateMachine.PhoneEngineInfo()->CallType(
       
   367                  callStateData.CallId() );
       
   368 
       
   369             if ( EPECallTypeCSVoice == type || EPECallTypeVoIP == type )
       
   370                 {
       
   371                 retVal = ETrue;
       
   372                 }
       
   373             }
       
   374         }
       
   375     return retVal;
       
   376     }
       
   377 
       
   378 // -----------------------------------------------------------
       
   379 // CPhoneCbaManager::SetRingtoneSilencedStatus
       
   380 // -----------------------------------------------------------
       
   381 //
       
   382 void CPhoneCbaManager::SetRingtoneSilencedStatus( const TBool aSilencedStatus )
       
   383     {
       
   384     __LOGMETHODSTARTEND(EPhoneControl, "CPhoneCbaManager::SetRingtoneSilencedStatus ()" );
       
   385     // Set the internal TBool variable
       
   386     iRingtoneSilenced = aSilencedStatus;
       
   387     __PHONELOG1( 
       
   388             EBasic, 
       
   389             EPhoneControl, 
       
   390             "CPhoneCbaManager::SetRingtoneSilencedStatus - iRingtoneSilenced =%d", 
       
   391             iRingtoneSilenced  );
       
   392     }
       
   393 
       
   394 // -----------------------------------------------------------
       
   395 // CPhoneCbaManager::SetSoftRejectStatus
       
   396 // -----------------------------------------------------------
       
   397 //
       
   398 void CPhoneCbaManager::SetSoftRejectStatus( TBool aSoftRejectStatus )
       
   399     {
       
   400     __LOGMETHODSTARTEND(EPhoneControl, "CPhoneCbaManager::SetSoftRejectStatus ()" );
       
   401     // Set the internal TBool variable
       
   402     iSoftRejectStatus = aSoftRejectStatus;
       
   403     __PHONELOG1( 
       
   404             EBasic, 
       
   405             EPhoneControl, 
       
   406             "CPhoneCbaManager::SetSoftRejectStatus - iSoftRejectStatus =%d", 
       
   407             iSoftRejectStatus  );
       
   408     }
       
   409 
       
   410 // -----------------------------------------------------------
       
   411 // CPhoneCbaManager::SoftRejectStatus
       
   412 // -----------------------------------------------------------
       
   413 //
       
   414 TBool CPhoneCbaManager::SoftRejectStatus()
       
   415     {
       
   416     return iSoftRejectStatus;
       
   417     }
       
   418 
       
   419 // -----------------------------------------------------------
       
   420 // CPhoneCbaManager::GetIncomingCallSilenceCBA
       
   421 // -----------------------------------------------------------
       
   422 //
       
   423 TInt CPhoneCbaManager::GetIncomingCallSilenceCBA( 
       
   424         const TBool /*aSoftRejectActivated*/ )
       
   425     {
       
   426     __LOGMETHODSTARTEND(EPhoneControl, "CPhoneCbaManager::GetIncomingCallSilenceCBA ()" );
       
   427     return EPhoneCallHandlingIncomingCBA;
       
   428     }
       
   429 
       
   430 // -----------------------------------------------------------
       
   431 // CPhoneCbaManager::SetSoftRejectDimmedFlag
       
   432 // -----------------------------------------------------------
       
   433 //
       
   434 void CPhoneCbaManager::SetSoftRejectDimmedFlag()
       
   435     {
       
   436     __LOGMETHODSTARTEND(EPhoneControl, "CPhoneCbaManager::GetIncomingCallSilenceCBA ()" );
       
   437     TPhoneCmdParamCallStateData callStateData;
       
   438     callStateData.SetCallState( EPEStateRinging );
       
   439     iViewCommandHandle.HandleCommandL(
       
   440         EPhoneViewGetCallIdByState, &callStateData );
       
   441     TPhoneCmdParamBoolean dimSoftRejectParam;
       
   442     if ( callStateData.CallId() > KErrNotFound )
       
   443         {
       
   444         TBool privateNumber = iStateMachine.PhoneEngineInfo()->
       
   445                 RemotePhoneNumber( callStateData.CallId() ).Length() == 0;
       
   446         
       
   447         dimSoftRejectParam.SetBoolean( privateNumber || !iSoftRejectStatus );        
       
   448         }
       
   449     else
       
   450         {
       
   451         iSoftRejectStatus = ETrue;
       
   452         dimSoftRejectParam.SetBoolean( EFalse );
       
   453         }
       
   454     iViewCommandHandle.ExecuteCommand(
       
   455             EPhoneViewSetSoftRejectDimmed, &dimSoftRejectParam );
       
   456     }
       
   457 
       
   458