phoneuis/TelephonyDeviceMode/src/CTelDMCommandHandler.cpp
changeset 50 377c906a8701
parent 46 bc5a64e5bc3c
child 52 a49bfe5190e4
equal deleted inserted replaced
46:bc5a64e5bc3c 50:377c906a8701
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of the CTelDMCommandHandler class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include    <mphonedevicemodeobserver.h>
       
    23 #include    <PSVariables.h>
       
    24 #include    <ctsydomainpskeys.h>
       
    25 
       
    26 #include    "cteldmcommandhandler.h"
       
    27 #include    "cteldmcallstatelistener.h"
       
    28 #include    "mteldmaccessory.h"
       
    29 #include    "cteldmdebug.h"
       
    30 #include     <coreapplicationuisdomainpskeys.h>
       
    31 
       
    32 // MODULE DATA STRUCTURES
       
    33  
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35  
       
    36 // -----------------------------------------------------------------------------
       
    37 // CTelDMCommandHandler::NewL
       
    38 // 
       
    39 // -----------------------------------------------------------------------------
       
    40 //  
       
    41 CTelDMCommandHandler* CTelDMCommandHandler::NewL( 
       
    42                                     MPhoneDeviceModeObserver& aCallHandler, 
       
    43                                     MTelDMAccessory& aAccessory ) 
       
    44     {
       
    45     CTelDMCommandHandler* self =
       
    46         new ( ELeave ) CTelDMCommandHandler( aCallHandler, 
       
    47                                                 aAccessory );
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL();
       
    50     CleanupStack::Pop( self );
       
    51     return self;
       
    52     }
       
    53 
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CTelDMCommandHandler::CTelDMCommandHandler
       
    57 // 
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CTelDMCommandHandler::CTelDMCommandHandler( 
       
    61                                     MPhoneDeviceModeObserver& aCallHandler, 
       
    62                                     MTelDMAccessory& aAccessory ):
       
    63     iCallHandler( aCallHandler ),
       
    64     iAccessory ( aAccessory ),
       
    65     iGripOpen ( EFalse ),
       
    66     iGripOpenOnRingingState ( EFalse )
       
    67     {
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CTelDMCommandHandler::~CTelDMCommandHandler
       
    72 // 
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CTelDMCommandHandler::~CTelDMCommandHandler()
       
    76     {
       
    77     iKeyLock.Close();
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CTelDMCommandHandler::ConstructL
       
    82 // 
       
    83 // -----------------------------------------------------------------------------
       
    84 //    
       
    85 void CTelDMCommandHandler::ConstructL()
       
    86     { 
       
    87     User::LeaveIfError( iKeyLock.Connect() );                             
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CTelDMCommandHandler::CallStateChanged()
       
    92 // 
       
    93 // -----------------------------------------------------------------------------
       
    94 //    
       
    95 void CTelDMCommandHandler::CallStateChangedL( TInt aCallState )
       
    96     {
       
    97     FLOG( _L( "CTelDMCommandHandler::CallStateChanged<" ) )
       
    98     FTRACE( FPrint( _L( "CTelDMCommandHandler::CallStateChangedL.aCallState=%d"), 
       
    99                                                                 aCallState ))
       
   100     iCallState = aCallState;                                                            
       
   101     switch( aCallState )
       
   102         {  
       
   103         // Arriving call                    
       
   104         case EPSCTsyCallStateRinging: 
       
   105             FLOG( _L( "CTelDMCommandHandler::CallStateChanged.Ringing" ) )
       
   106             RProperty::Set( KPSUidCoreApplicationUIs,
       
   107                             KCoreAppUIsSoftReject,
       
   108                             ECoreAppUIsSoftRejectUninitialized );
       
   109             iGripOpenOnRingingState = iGripOpen;
       
   110             break;
       
   111         // Answered
       
   112         case EPSCTsyCallStateConnected:  
       
   113             {   
       
   114             FLOG( _L( "CTelDMCommandHandler::CallStateChanged.Connected" ) )
       
   115             if ( iGripOpenOnRingingState )
       
   116                 {
       
   117                 OfferKeyLock(); 
       
   118                 }
       
   119             
       
   120             // Clear the flag.
       
   121             iGripOpenOnRingingState = EFalse;
       
   122             }
       
   123             break;
       
   124         // Disconnected 
       
   125         case EPSCTsyCallStateNone:
       
   126             {
       
   127             FLOG( _L( "CTelDMCommandHandler::CallStateChanged.None" ) )
       
   128             if ( iGripOpenOnRingingState )
       
   129                 {
       
   130                 OfferKeyLock(); 
       
   131                 }           
       
   132             }
       
   133             break; 
       
   134         default:
       
   135             break;
       
   136         }     
       
   137     FLOG( _L( "CTelDMCommandHandler::CallStateChanged>" ) )  
       
   138     }
       
   139 // -----------------------------------------------------------------------------
       
   140 // CTelDMCommandHandler::HandleEvent
       
   141 // 
       
   142 // -----------------------------------------------------------------------------
       
   143 //    
       
   144 void CTelDMCommandHandler::HandleCommand( TCommands aCommand )
       
   145     {           
       
   146     FLOG( _L( "CTelDMCommandHandler::HandleCommand<" ) ) 
       
   147     switch( aCommand )
       
   148         {                      
       
   149         case EGripOpen:
       
   150             {
       
   151             FLOG( _L( "CTelDMCommandHandler::HandleCommand.Open" ) ) 
       
   152             iGripOpen = ETrue;
       
   153             if ( !IsSoftRejectOngoing() )
       
   154                 {
       
   155                 iCallHandler.Answer();
       
   156                 }
       
   157             }
       
   158             break;
       
   159         // Do not end calls if accessory is connected. 
       
   160         case EGripClose:
       
   161             {
       
   162             FLOG( _L( "CTelDMCommandHandler::HandleCommand.Close" ) ) 
       
   163             iGripOpen = EFalse;
       
   164             EndCalls();
       
   165             break;
       
   166             }
       
   167         default:
       
   168             break;
       
   169         }  
       
   170     FLOG( _L( "CTelDMCommandHandler::HandleCommand>" ) )      
       
   171     }
       
   172     
       
   173 // -----------------------------------------------------------------------------
       
   174 // CTelDMCommandHandler::EndCalls
       
   175 // 
       
   176 // -----------------------------------------------------------------------------
       
   177 //    
       
   178 void CTelDMCommandHandler::EndCalls()
       
   179 
       
   180     {
       
   181     if ( IsEmergencyCall() )
       
   182         {
       
   183         // None
       
   184         }
       
   185     else if ( iAccessory.IsAccessoryAttached()  &&
       
   186               !iAccessory.IsAnyActiveAccessory() &&
       
   187               iCallState == EPSCTsyCallStateConnected )
       
   188         {
       
   189         FLOG( _L( "CTelDMCommandHandler::EndCalls#1" ) )
       
   190         iCallHandler.EndVoiceCalls();
       
   191         }
       
   192     else if ( !iAccessory.IsAccessoryAttached() )
       
   193         {
       
   194         FLOG( _L( "CTelDMCommandHandler::EndCalls#2" ) )
       
   195         iCallHandler.EndVoiceCalls();
       
   196         }
       
   197     }
       
   198 // -----------------------------------------------------------------------------
       
   199 // CTelDMCommandHandler::OfferKeyLock
       
   200 //
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 void CTelDMCommandHandler::OfferKeyLock()
       
   204 
       
   205     {
       
   206     //- AudioAccessory attached (BT headset, Wired headset etc.)
       
   207     //- Arriving call and grip open.  
       
   208     //- Call terminated or answered  
       
   209     //-> KeyLock query is shown if not locked       
       
   210     if ( iAccessory.IsAccessoryAttached() && 
       
   211                                        !iGripOpen && 
       
   212                                        !iKeyLock.IsKeyLockEnabled() )
       
   213         {
       
   214         FLOG( _L( "CTelDMCommandHandler::CallStateChanged -lock?" ) ) 
       
   215         //Lock keypad ?
       
   216         iKeyLock.OfferKeyLock();
       
   217         }  
       
   218     }
       
   219 
       
   220 // ---------------------------------------------------------
       
   221 // CTelDMCommandHandler::IsEmergencyCall
       
   222 // ---------------------------------------------------------
       
   223 //
       
   224 TBool CTelDMCommandHandler::IsEmergencyCall() const
       
   225     {
       
   226     FLOG( _L( "CTelDMCommandHandler::IsEmergencyCall" ) ) 
       
   227     TBool retVal( EFalse );
       
   228     TInt err( KErrNone );
       
   229     TInt state( 0 );
       
   230     
       
   231     err = RProperty::Get(
       
   232             KPSUidCtsyEmergencyCallInfo,
       
   233             KCTSYEmergencyCallInfo,
       
   234             state );
       
   235     
       
   236     if ( err == KErrNone && state )
       
   237         {
       
   238         retVal = ETrue;            
       
   239         }
       
   240     return retVal;
       
   241     }
       
   242 
       
   243 // ---------------------------------------------------------
       
   244 // CTelDMCommandHandler::IsSoftRejectOngoing
       
   245 // ---------------------------------------------------------
       
   246 //
       
   247 TBool CTelDMCommandHandler::IsSoftRejectOngoing() const
       
   248     {
       
   249     FLOG( _L( "CTelDMCommandHandler::IsSoftRejectOngoing" ) )
       
   250     TBool retVal( EFalse );
       
   251     TInt err( KErrNone );
       
   252     TInt state( 0 );
       
   253         
       
   254     err = RProperty::Get(
       
   255             KPSUidCoreApplicationUIs,
       
   256             KCoreAppUIsSoftReject,
       
   257             state );
       
   258     
       
   259     if ( err == KErrNone && state == ECoreAppUIsSoftReject )
       
   260         {
       
   261         retVal = ETrue;            
       
   262         }
       
   263     return retVal;
       
   264     }
       
   265 
       
   266 // End of File