tsrc/musenginestub/src/musengtelephoneutils.cpp
branchRCL_3
changeset 33 bc78a40cd63c
parent 32 73a1feb507fb
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 // USER
    19 // USER
    20 #include "musengtelephoneutils.h"
    20 #include "musengtelephoneutils.h"
    21 #include "musengaudioroutingobserver.h"
       
    22 #include "muslogger.h"
       
    23 
    21 
    24 // SYSTEM
    22 // SYSTEM
       
    23 /*
    25 #include <centralrepository.h>
    24 #include <centralrepository.h>
    26 #include <telincallvolcntrlcrkeys.h>
    25 #include <telephonyinternalcrkeys.h>
    27 #include <e32property.h>
    26 */
    28 #include <telephonydomainpskeys.h>
       
    29 #include <cphcltcommandhandler.h> // for CPhCltCommandHandler
       
    30 
       
    31 // Constants
       
    32 const TInt KMusEngMaxVolume = 10;
       
    33 const TInt KMusEngMinVolume = 0;
       
    34 
       
    35 
       
    36 
    27 
    37 
    28 
    38 // -----------------------------------------------------------------------------
    29 // -----------------------------------------------------------------------------
    39 //
    30 //
    40 // -----------------------------------------------------------------------------
    31 // -----------------------------------------------------------------------------
    53 //
    44 //
    54 // -----------------------------------------------------------------------------
    45 // -----------------------------------------------------------------------------
    55 //
    46 //
    56 CMusEngTelephoneUtils::~CMusEngTelephoneUtils()
    47 CMusEngTelephoneUtils::~CMusEngTelephoneUtils()
    57     {
    48     {
    58     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::~CMusEngTelephoneUtils()" )
       
    59     
       
    60     Cancel();
       
    61 
       
    62     delete iPhoneCommandHandler;
       
    63     
       
    64     if( iTelephonyAudioRouting ) // If 2nd phase construction has succeeded 
       
    65         {
       
    66         CTelephonyAudioRouting::TAudioOutput currentMode =
       
    67                                             iTelephonyAudioRouting->Output();
       
    68         if( currentMode != iAudioOutputAtStartup )
       
    69             {
       
    70             // As going down, let audiorouting api to show notification
       
    71             iTelephonyAudioRouting->SetShowNote( ETrue );
       
    72             TRAPD( err, DoSetOutputL( iAudioOutputAtStartup ) );
       
    73             MUS_LOG1( "mus: [ENGINE]    final route change completed: %d", err )
       
    74             err++;
       
    75         	}
       
    76         }
       
    77 
       
    78     delete iRepository;
       
    79     delete iTelephonyAudioRouting;
       
    80     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::~CMusEngTelephoneUtils()" )
       
    81     }
       
    82 
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 TBool CMusEngTelephoneUtils::AudioRoutingCanBeChanged()
       
    89     {
       
    90     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::AudioRoutingCanBeChanged" )
       
    91     
       
    92     TBool retValue = ( iTelephonyAudioRouting->Output() !=
       
    93                        CTelephonyAudioRouting::EWiredAudioAccessory &&
       
    94                        iTelephonyAudioRouting->Output() !=
       
    95                        CTelephonyAudioRouting::EBTAudioAccessory &&
       
    96                        iTelephonyAudioRouting->Output() !=
       
    97                        CTelephonyAudioRouting::ETTY );
       
    98     
       
    99     MUS_LOG1( "mus: [ENGINE]  <- CMusEngTelephoneUtils::AudioRoutingCanBeChanged: %d",
       
   100               retValue )
       
   101               
       
   102     return retValue;
       
   103     }
    49     }
   104 
    50 
   105 
    51 
   106 // -----------------------------------------------------------------------------
    52 // -----------------------------------------------------------------------------
   107 //
    53 //
   108 // -----------------------------------------------------------------------------
    54 // -----------------------------------------------------------------------------
   109 //
    55 //
   110 void CMusEngTelephoneUtils::LoudspeakerL( TBool aEnable, TBool aShowDialog )
    56 void CMusEngTelephoneUtils::LoudspeakerL( TBool aEnable, TBool aShowDialog )
   111     {
    57     {
   112     MUS_LOG1( "mus: [ENGINE]  -> CMusEngTelephoneUtils::LoudspeakerL(%d)",
       
   113               aEnable )
       
   114     
       
   115     if ( aEnable )
       
   116         {
       
   117         if ( iTelephonyAudioRouting->Output() == 
       
   118              CTelephonyAudioRouting::EHandset )
       
   119             {
       
   120             // Disable note shown by audiorouting api as it causes
       
   121             // application going to background for a while. Instead, display
       
   122             // note by ourselves once setting output completes. This mechanism
       
   123             // is needed only for loudspeaker enabling as going to background
       
   124             // causes problems only at beginning of sharing session.
       
   125             if ( aShowDialog )
       
   126                 {   
       
   127                 iTelephonyAudioRouting->SetShowNote( EFalse );
       
   128                 
       
   129                 iShowDialog = aShowDialog;
       
   130                 }
       
   131     
       
   132             DoSetOutputL( CTelephonyAudioRouting::ELoudspeaker );
       
   133             }
       
   134         }
       
   135     else
       
   136         {
       
   137         iTelephonyAudioRouting->SetShowNote( aShowDialog );
       
   138         
       
   139         if ( iAudioOutputAtStartup == CTelephonyAudioRouting::ELoudspeaker )
       
   140             {
       
   141             DoSetOutputL( CTelephonyAudioRouting::EHandset );
       
   142             }
       
   143         else
       
   144             {
       
   145             DoSetOutputL( iAudioOutputAtStartup );
       
   146             }
       
   147         }
       
   148 
       
   149     
       
   150                                 
       
   151     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::LoudspeakerL(...)" )
       
   152     }
    58     }
   153 
    59 
   154 
    60 
   155 // -----------------------------------------------------------------------------
    61 // -----------------------------------------------------------------------------
   156 //
    62 //
   157 // -----------------------------------------------------------------------------
    63 // -----------------------------------------------------------------------------
   158 //
    64 //
   159 TBool CMusEngTelephoneUtils::IsLoudSpeakerEnabled() const
    65 TBool CMusEngTelephoneUtils::IsLoudSpeakerEnabled() const
   160     {
    66     {
   161     return ( iTelephonyAudioRouting->Output() ==
       
   162              CTelephonyAudioRouting::ELoudspeaker );
       
   163     }
    67     }
   164 
    68 
   165 
    69 
   166 // -----------------------------------------------------------------------------
    70 // -----------------------------------------------------------------------------
   167 // Gets the CS call volume level.
    71 // Gets the CS call volume level.
   168 // Leaves if error occurs when accessing central repository.
    72 // Leaves if error occurs when accessing central repository.
   169 // -----------------------------------------------------------------------------
    73 // -----------------------------------------------------------------------------
   170 //
    74 //
   171 TInt CMusEngTelephoneUtils::GetVolumeL() const
    75 TInt CMusEngTelephoneUtils::GetVolumeL() const
   172     {
    76     {
   173     TInt currentVolume = 0;
       
   174     if ( IsLoudSpeakerEnabled() )
       
   175         {
       
   176         User::LeaveIfError( iRepository->Get( KTelIncallLoudspeakerVolume,
       
   177                                               currentVolume ) );
       
   178         }
       
   179     else
       
   180         {
       
   181         User::LeaveIfError( iRepository->Get( KTelIncallEarVolume,
       
   182                                               currentVolume ) );
       
   183         }
       
   184 
       
   185     return ValidateVolume( currentVolume );
       
   186     }
    77     }
   187 
    78 
   188 
    79 
   189 // -----------------------------------------------------------------------------
    80 // -----------------------------------------------------------------------------
   190 // Sets the CS call volume level.
    81 // Sets the CS call volume level.
   191 // Leaves if error occurs when accessing central repository.
    82 // Leaves if error occurs when accessing central repository.
   192 // -----------------------------------------------------------------------------
    83 // -----------------------------------------------------------------------------
   193 //
    84 //
   194 void CMusEngTelephoneUtils::SetVolumeL( TInt aVolume )
    85 void CMusEngTelephoneUtils::SetVolumeL( TInt aVolume )
   195     {
    86     {
   196     TInt newVolume = ValidateVolume( aVolume );
       
   197 
       
   198     if ( GetVolumeL() != newVolume )
       
   199         {
       
   200         if ( IsLoudSpeakerEnabled() )
       
   201             {
       
   202             User::LeaveIfError( iRepository->Set( KTelIncallLoudspeakerVolume,
       
   203                                                   newVolume ) );
       
   204             }
       
   205         else
       
   206             {
       
   207             User::LeaveIfError( iRepository->Set( KTelIncallEarVolume, 
       
   208                                                   newVolume ) );
       
   209             }
       
   210         }
       
   211     }
    87     }
   212 
    88 
   213 
    89 
   214 // -----------------------------------------------------------------------------
    90 // -----------------------------------------------------------------------------
   215 //
    91 //
   216 // -----------------------------------------------------------------------------
    92 // -----------------------------------------------------------------------------
   217 //
    93 //
   218 void CMusEngTelephoneUtils::MuteMicL( TBool aMute )
    94 CMusEngTelephoneUtils::CMusEngTelephoneUtils()
   219     {
    95     {
   220     MUS_LOG1( "mus: [ENGINE]  -> CMusEngTelephoneUtils::MuteMicL(%d)", aMute )
       
   221     
       
   222     if ( IsActive() )
       
   223         {
       
   224         MUS_LOG( "mus: [ENGINE]     Cancel pending request" )
       
   225         Cancel();
       
   226         }
       
   227     
       
   228     iPhoneCommandHandler->MuteMicrophone( iStatus, aMute );
       
   229     SetActive();
       
   230     
       
   231     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::MuteMicL()" )
       
   232     }
       
   233 
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 TBool CMusEngTelephoneUtils::IsMicMutedL()
       
   240     {
       
   241     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::IsMicMutedL()" )
       
   242     
       
   243     TInt psVal;
       
   244     User::LeaveIfError( RProperty::Get( KPSUidTelMicrophoneMuteStatus,
       
   245                                         KTelMicrophoneMuteState,
       
   246                                         psVal ) );
       
   247                                         
       
   248     MUS_LOG1( "mus: [ENGINE]     Mute status in PS is (%d)", psVal )
       
   249     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::IsMicMutedL()" )
       
   250 
       
   251     return ( psVal == EPSTelMicMuteOn );
       
   252     }
       
   253 
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 void CMusEngTelephoneUtils::SetAudioRoutingObserver( 
       
   260                                     MMusEngAudioRoutingObserver* aObserver )
       
   261     {
       
   262     iAudioRoutingObserver = aObserver;
       
   263     }
       
   264     
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // 
       
   268 // -----------------------------------------------------------------------------
       
   269 //
       
   270 void CMusEngTelephoneUtils::RunL()
       
   271     {
       
   272     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::RunL()" )
       
   273 
       
   274     // NOP, since we really cannot do anything but log the result
       
   275     MUS_LOG1( "mus: [ENGINE]    Asynchronous call completed with code %d",
       
   276              iStatus.Int() )
       
   277 
       
   278     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::RunL()" )
       
   279     }
       
   280 
       
   281 
       
   282 // -----------------------------------------------------------------------------
       
   283 // 
       
   284 // -----------------------------------------------------------------------------
       
   285 //
       
   286 void CMusEngTelephoneUtils::DoCancel()
       
   287     {
       
   288     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::DoCancel()" )
       
   289     
       
   290     if ( iPhoneCommandHandler )
       
   291         {
       
   292         iPhoneCommandHandler->CancelAsyncRequest( EPhCltCommandMuteMic );
       
   293         }
       
   294         
       
   295     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::DoCancel()" )
       
   296     }
       
   297     
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 void CMusEngTelephoneUtils::AvailableOutputsChanged( 
       
   304                         CTelephonyAudioRouting& /*aTelephonyAudioRouting*/ )
       
   305     {
       
   306     // NOP
       
   307     }
       
   308 
       
   309 
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 // -----------------------------------------------------------------------------
       
   313 //
       
   314 void CMusEngTelephoneUtils::OutputChanged( 
       
   315                 CTelephonyAudioRouting& aTelephonyAudioRouting )
       
   316     {
       
   317     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::OutputChanged()" )
       
   318 
       
   319     // Some other application has changed audio output routing. We consider
       
   320     // this as a last will of a user and return to this state after sharing
       
   321     
       
   322     iAudioOutputAtStartup = aTelephonyAudioRouting.Output();
       
   323     
       
   324     MUS_LOG1( "mus: [ENGINE]     New audio routing is %d", iAudioOutputAtStartup )
       
   325     
       
   326     if ( iAudioRoutingObserver )
       
   327         {
       
   328         iAudioRoutingObserver->AudioRoutingChanged( EFalse );
       
   329         }
       
   330         
       
   331     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::OutputChanged()" )
       
   332     }
       
   333     
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 //
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 void CMusEngTelephoneUtils::SetOutputComplete( 
       
   340                     CTelephonyAudioRouting& /*aTelephonyAudioRouting*/,
       
   341                     TInt aError )
       
   342     {
       
   343     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::SetOutputComplete()" )
       
   344 
       
   345     if ( aError == KErrNone && iAudioRoutingObserver )
       
   346         {
       
   347         // If audio routing api didn't shown note and show dialog mode is on,
       
   348         // we know that this completion is for such setoutput call for which
       
   349         // we need to show the note. Show note mode is turned off only in that
       
   350         // case.
       
   351         TBool dialogShownByUs( EFalse );
       
   352         TBool dialogShownByAudioRouting( EFalse );     
       
   353         aError = iTelephonyAudioRouting->GetShowNote( dialogShownByAudioRouting );
       
   354         if ( aError == KErrNone && !dialogShownByAudioRouting && iShowDialog )
       
   355             {
       
   356             dialogShownByUs = iShowDialog;
       
   357             iShowDialog = EFalse;
       
   358             }
       
   359 
       
   360         iAudioRoutingObserver->AudioRoutingChanged( dialogShownByUs );
       
   361         }
       
   362     
       
   363     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::SetOutputComplete()" )
       
   364     }
       
   365                             
       
   366 
       
   367 // -----------------------------------------------------------------------------
       
   368 //
       
   369 // -----------------------------------------------------------------------------
       
   370 //
       
   371 CMusEngTelephoneUtils::CMusEngTelephoneUtils() 
       
   372 	: CActive( CActive::EPriorityStandard )
       
   373     {
       
   374     iAudioOutputAtStartup = CTelephonyAudioRouting::ENotActive;
       
   375     }
    96     }
   376 
    97 
   377 
    98 
   378 // -----------------------------------------------------------------------------
    99 // -----------------------------------------------------------------------------
   379 //
   100 //
   380 // -----------------------------------------------------------------------------
   101 // -----------------------------------------------------------------------------
   381 //
   102 //
   382 void CMusEngTelephoneUtils::ConstructL()
   103 void CMusEngTelephoneUtils::ConstructL()
   383     {
   104     {
   384     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::ConstructL()" )
       
   385 
       
   386     // Volume control
       
   387     iRepository = CRepository::NewL( KCRUidInCallVolume );
       
   388 
       
   389     // Audio routing control
       
   390     iTelephonyAudioRouting = CTelephonyAudioRouting::NewL( *this );
       
   391 
       
   392     iAudioOutputAtStartup = iTelephonyAudioRouting->Output();
       
   393     
       
   394     // Phone
       
   395     MUS_LOG( "mus: [ENGINE]     Use static DLL" )
       
   396     iPhoneCommandHandler = CPhCltCommandHandler::NewL();
       
   397         
       
   398     CActiveScheduler::Add( this );
       
   399 
       
   400     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::ConstructL()" )
       
   401     }
   105     }
   402 
   106 
   403 
   107 
   404 // -----------------------------------------------------------------------------
   108 // -----------------------------------------------------------------------------
   405 // Validates that requested volume level is valid (between 1-10) and if it is
   109 // Validates that requested volume level is valid (between 1-10) and if it is
   406 // not, modifies requested volume level to be valid.  Returns validated volume.
   110 // not, modifies requested volume level to be valid.  Returns validated volume.
   407 // -----------------------------------------------------------------------------
   111 // -----------------------------------------------------------------------------
   408 //
   112 //
   409 TInt CMusEngTelephoneUtils::ValidateVolume( const TInt aVolume ) const
   113 TInt CMusEngTelephoneUtils::ValidateVolume( const TInt aVolume ) const
   410     {
   114     {
   411     if ( aVolume < KMusEngMinVolume )
       
   412         {
       
   413         return KMusEngMinVolume;
       
   414         }
       
   415     else if ( aVolume > KMusEngMaxVolume )
       
   416         {
       
   417         return KMusEngMaxVolume;
       
   418         }
       
   419     else
       
   420         {
       
   421         // NOP, to keep PC-Lint happy
       
   422         }
       
   423         
       
   424     return aVolume;
       
   425     }
   115     }
   426 
   116 
   427 
   117 
   428 // -----------------------------------------------------------------------------
       
   429 // Set output if setting is currently allowed.
       
   430 // -----------------------------------------------------------------------------
       
   431 //
       
   432 void CMusEngTelephoneUtils::DoSetOutputL( 
       
   433     CTelephonyAudioRouting::TAudioOutput aAudioOutput )
       
   434     {
       
   435     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::DoSetOutputL()" )
       
   436     if ( iAudioRoutingObserver && !iAudioRoutingObserver->AudioRouteChangeAllowed() )
       
   437         {
       
   438         MUS_LOG( "mus: [ENGINE]     change not allowed!" )
       
   439         User::Leave( KErrAccessDenied );
       
   440         }
       
   441     iTelephonyAudioRouting->SetOutputL( aAudioOutput );
       
   442     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::DoSetOutputL()" )
       
   443     }
       
   444 
   118 
   445 
   119