diff -r 33a5d2bbf6fc -r 73a1feb507fb tsrc/musenginestub/src/musengtelephoneutils.cpp --- a/tsrc/musenginestub/src/musengtelephoneutils.cpp Thu Aug 19 09:51:39 2010 +0300 +++ b/tsrc/musenginestub/src/musengtelephoneutils.cpp Tue Aug 31 15:12:07 2010 +0300 @@ -18,12 +18,21 @@ // USER #include "musengtelephoneutils.h" +#include "musengaudioroutingobserver.h" +#include "muslogger.h" // SYSTEM -/* #include -#include -*/ +#include +#include +#include +#include // for CPhCltCommandHandler + +// Constants +const TInt KMusEngMaxVolume = 10; +const TInt KMusEngMinVolume = 0; + + // ----------------------------------------------------------------------------- @@ -46,6 +55,51 @@ // CMusEngTelephoneUtils::~CMusEngTelephoneUtils() { + MUS_LOG( "mus: [ENGINE] -> CMusEngTelephoneUtils::~CMusEngTelephoneUtils()" ) + + Cancel(); + + delete iPhoneCommandHandler; + + if( iTelephonyAudioRouting ) // If 2nd phase construction has succeeded + { + CTelephonyAudioRouting::TAudioOutput currentMode = + iTelephonyAudioRouting->Output(); + if( currentMode != iAudioOutputAtStartup ) + { + // As going down, let audiorouting api to show notification + iTelephonyAudioRouting->SetShowNote( ETrue ); + TRAPD( err, DoSetOutputL( iAudioOutputAtStartup ) ); + MUS_LOG1( "mus: [ENGINE] final route change completed: %d", err ) + err++; + } + } + + delete iRepository; + delete iTelephonyAudioRouting; + MUS_LOG( "mus: [ENGINE] <- CMusEngTelephoneUtils::~CMusEngTelephoneUtils()" ) + } + + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +TBool CMusEngTelephoneUtils::AudioRoutingCanBeChanged() + { + MUS_LOG( "mus: [ENGINE] -> CMusEngTelephoneUtils::AudioRoutingCanBeChanged" ) + + TBool retValue = ( iTelephonyAudioRouting->Output() != + CTelephonyAudioRouting::EWiredAudioAccessory && + iTelephonyAudioRouting->Output() != + CTelephonyAudioRouting::EBTAudioAccessory && + iTelephonyAudioRouting->Output() != + CTelephonyAudioRouting::ETTY ); + + MUS_LOG1( "mus: [ENGINE] <- CMusEngTelephoneUtils::AudioRoutingCanBeChanged: %d", + retValue ) + + return retValue; } @@ -55,6 +109,46 @@ // void CMusEngTelephoneUtils::LoudspeakerL( TBool aEnable, TBool aShowDialog ) { + MUS_LOG1( "mus: [ENGINE] -> CMusEngTelephoneUtils::LoudspeakerL(%d)", + aEnable ) + + if ( aEnable ) + { + if ( iTelephonyAudioRouting->Output() == + CTelephonyAudioRouting::EHandset ) + { + // Disable note shown by audiorouting api as it causes + // application going to background for a while. Instead, display + // note by ourselves once setting output completes. This mechanism + // is needed only for loudspeaker enabling as going to background + // causes problems only at beginning of sharing session. + if ( aShowDialog ) + { + iTelephonyAudioRouting->SetShowNote( EFalse ); + + iShowDialog = aShowDialog; + } + + DoSetOutputL( CTelephonyAudioRouting::ELoudspeaker ); + } + } + else + { + iTelephonyAudioRouting->SetShowNote( aShowDialog ); + + if ( iAudioOutputAtStartup == CTelephonyAudioRouting::ELoudspeaker ) + { + DoSetOutputL( CTelephonyAudioRouting::EHandset ); + } + else + { + DoSetOutputL( iAudioOutputAtStartup ); + } + } + + + + MUS_LOG( "mus: [ENGINE] <- CMusEngTelephoneUtils::LoudspeakerL(...)" ) } @@ -64,6 +158,8 @@ // TBool CMusEngTelephoneUtils::IsLoudSpeakerEnabled() const { + return ( iTelephonyAudioRouting->Output() == + CTelephonyAudioRouting::ELoudspeaker ); } @@ -74,6 +170,19 @@ // TInt CMusEngTelephoneUtils::GetVolumeL() const { + TInt currentVolume = 0; + if ( IsLoudSpeakerEnabled() ) + { + User::LeaveIfError( iRepository->Get( KTelIncallLoudspeakerVolume, + currentVolume ) ); + } + else + { + User::LeaveIfError( iRepository->Get( KTelIncallEarVolume, + currentVolume ) ); + } + + return ValidateVolume( currentVolume ); } @@ -84,6 +193,62 @@ // void CMusEngTelephoneUtils::SetVolumeL( TInt aVolume ) { + TInt newVolume = ValidateVolume( aVolume ); + + if ( GetVolumeL() != newVolume ) + { + if ( IsLoudSpeakerEnabled() ) + { + User::LeaveIfError( iRepository->Set( KTelIncallLoudspeakerVolume, + newVolume ) ); + } + else + { + User::LeaveIfError( iRepository->Set( KTelIncallEarVolume, + newVolume ) ); + } + } + } + + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +void CMusEngTelephoneUtils::MuteMicL( TBool aMute ) + { + MUS_LOG1( "mus: [ENGINE] -> CMusEngTelephoneUtils::MuteMicL(%d)", aMute ) + + if ( IsActive() ) + { + MUS_LOG( "mus: [ENGINE] Cancel pending request" ) + Cancel(); + } + + iPhoneCommandHandler->MuteMicrophone( iStatus, aMute ); + SetActive(); + + MUS_LOG( "mus: [ENGINE] <- CMusEngTelephoneUtils::MuteMicL()" ) + } + + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +TBool CMusEngTelephoneUtils::IsMicMutedL() + { + MUS_LOG( "mus: [ENGINE] -> CMusEngTelephoneUtils::IsMicMutedL()" ) + + TInt psVal; + User::LeaveIfError( RProperty::Get( KPSUidTelMicrophoneMuteStatus, + KTelMicrophoneMuteState, + psVal ) ); + + MUS_LOG1( "mus: [ENGINE] Mute status in PS is (%d)", psVal ) + MUS_LOG( "mus: [ENGINE] <- CMusEngTelephoneUtils::IsMicMutedL()" ) + + return ( psVal == EPSTelMicMuteOn ); } @@ -91,8 +256,122 @@ // // ----------------------------------------------------------------------------- // -CMusEngTelephoneUtils::CMusEngTelephoneUtils() +void CMusEngTelephoneUtils::SetAudioRoutingObserver( + MMusEngAudioRoutingObserver* aObserver ) + { + iAudioRoutingObserver = aObserver; + } + + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +void CMusEngTelephoneUtils::RunL() + { + MUS_LOG( "mus: [ENGINE] -> CMusEngTelephoneUtils::RunL()" ) + + // NOP, since we really cannot do anything but log the result + MUS_LOG1( "mus: [ENGINE] Asynchronous call completed with code %d", + iStatus.Int() ) + + MUS_LOG( "mus: [ENGINE] <- CMusEngTelephoneUtils::RunL()" ) + } + + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +void CMusEngTelephoneUtils::DoCancel() + { + MUS_LOG( "mus: [ENGINE] -> CMusEngTelephoneUtils::DoCancel()" ) + + if ( iPhoneCommandHandler ) + { + iPhoneCommandHandler->CancelAsyncRequest( EPhCltCommandMuteMic ); + } + + MUS_LOG( "mus: [ENGINE] <- CMusEngTelephoneUtils::DoCancel()" ) + } + + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +void CMusEngTelephoneUtils::AvailableOutputsChanged( + CTelephonyAudioRouting& /*aTelephonyAudioRouting*/ ) + { + // NOP + } + + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +void CMusEngTelephoneUtils::OutputChanged( + CTelephonyAudioRouting& aTelephonyAudioRouting ) { + MUS_LOG( "mus: [ENGINE] -> CMusEngTelephoneUtils::OutputChanged()" ) + + // Some other application has changed audio output routing. We consider + // this as a last will of a user and return to this state after sharing + + iAudioOutputAtStartup = aTelephonyAudioRouting.Output(); + + MUS_LOG1( "mus: [ENGINE] New audio routing is %d", iAudioOutputAtStartup ) + + if ( iAudioRoutingObserver ) + { + iAudioRoutingObserver->AudioRoutingChanged( EFalse ); + } + + MUS_LOG( "mus: [ENGINE] <- CMusEngTelephoneUtils::OutputChanged()" ) + } + + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +void CMusEngTelephoneUtils::SetOutputComplete( + CTelephonyAudioRouting& /*aTelephonyAudioRouting*/, + TInt aError ) + { + MUS_LOG( "mus: [ENGINE] -> CMusEngTelephoneUtils::SetOutputComplete()" ) + + if ( aError == KErrNone && iAudioRoutingObserver ) + { + // If audio routing api didn't shown note and show dialog mode is on, + // we know that this completion is for such setoutput call for which + // we need to show the note. Show note mode is turned off only in that + // case. + TBool dialogShownByUs( EFalse ); + TBool dialogShownByAudioRouting( EFalse ); + aError = iTelephonyAudioRouting->GetShowNote( dialogShownByAudioRouting ); + if ( aError == KErrNone && !dialogShownByAudioRouting && iShowDialog ) + { + dialogShownByUs = iShowDialog; + iShowDialog = EFalse; + } + + iAudioRoutingObserver->AudioRoutingChanged( dialogShownByUs ); + } + + MUS_LOG( "mus: [ENGINE] <- CMusEngTelephoneUtils::SetOutputComplete()" ) + } + + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +CMusEngTelephoneUtils::CMusEngTelephoneUtils() + : CActive( CActive::EPriorityStandard ) + { + iAudioOutputAtStartup = CTelephonyAudioRouting::ENotActive; } @@ -102,6 +381,23 @@ // void CMusEngTelephoneUtils::ConstructL() { + MUS_LOG( "mus: [ENGINE] -> CMusEngTelephoneUtils::ConstructL()" ) + + // Volume control + iRepository = CRepository::NewL( KCRUidInCallVolume ); + + // Audio routing control + iTelephonyAudioRouting = CTelephonyAudioRouting::NewL( *this ); + + iAudioOutputAtStartup = iTelephonyAudioRouting->Output(); + + // Phone + MUS_LOG( "mus: [ENGINE] Use static DLL" ) + iPhoneCommandHandler = CPhCltCommandHandler::NewL(); + + CActiveScheduler::Add( this ); + + MUS_LOG( "mus: [ENGINE] <- CMusEngTelephoneUtils::ConstructL()" ) } @@ -112,8 +408,38 @@ // TInt CMusEngTelephoneUtils::ValidateVolume( const TInt aVolume ) const { + if ( aVolume < KMusEngMinVolume ) + { + return KMusEngMinVolume; + } + else if ( aVolume > KMusEngMaxVolume ) + { + return KMusEngMaxVolume; + } + else + { + // NOP, to keep PC-Lint happy + } + + return aVolume; } +// ----------------------------------------------------------------------------- +// Set output if setting is currently allowed. +// ----------------------------------------------------------------------------- +// +void CMusEngTelephoneUtils::DoSetOutputL( + CTelephonyAudioRouting::TAudioOutput aAudioOutput ) + { + MUS_LOG( "mus: [ENGINE] -> CMusEngTelephoneUtils::DoSetOutputL()" ) + if ( iAudioRoutingObserver && !iAudioRoutingObserver->AudioRouteChangeAllowed() ) + { + MUS_LOG( "mus: [ENGINE] change not allowed!" ) + User::Leave( KErrAccessDenied ); + } + iTelephonyAudioRouting->SetOutputL( aAudioOutput ); + MUS_LOG( "mus: [ENGINE] <- CMusEngTelephoneUtils::DoSetOutputL()" ) + }