|
1 /* |
|
2 * Copyright (c) 2005 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // USER |
|
20 #include "musengtelephoneutils.h" |
|
21 #include "musengaudioroutingobserver.h" |
|
22 #include "muslogger.h" |
|
23 |
|
24 // SYSTEM |
|
25 #include <centralrepository.h> |
|
26 #include <telincallvolcntrlcrkeys.h> |
|
27 #include <e32property.h> |
|
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 |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CMusEngTelephoneUtils* CMusEngTelephoneUtils::NewL() |
|
43 { |
|
44 CMusEngTelephoneUtils* self = new( ELeave ) CMusEngTelephoneUtils(); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CMusEngTelephoneUtils::~CMusEngTelephoneUtils() |
|
57 { |
|
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 } |
|
104 |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 void CMusEngTelephoneUtils::LoudspeakerL( TBool aEnable, TBool aShowDialog ) |
|
111 { |
|
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 } |
|
153 |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 TBool CMusEngTelephoneUtils::IsLoudSpeakerEnabled() const |
|
160 { |
|
161 return ( iTelephonyAudioRouting->Output() == |
|
162 CTelephonyAudioRouting::ELoudspeaker ); |
|
163 } |
|
164 |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // Gets the CS call volume level. |
|
168 // Leaves if error occurs when accessing central repository. |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 TInt CMusEngTelephoneUtils::GetVolumeL() const |
|
172 { |
|
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 } |
|
187 |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // Sets the CS call volume level. |
|
191 // Leaves if error occurs when accessing central repository. |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 void CMusEngTelephoneUtils::SetVolumeL( TInt aVolume ) |
|
195 { |
|
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 } |
|
212 |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 void CMusEngTelephoneUtils::MuteMicL( TBool aMute ) |
|
219 { |
|
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 } |
|
376 |
|
377 |
|
378 // ----------------------------------------------------------------------------- |
|
379 // |
|
380 // ----------------------------------------------------------------------------- |
|
381 // |
|
382 void CMusEngTelephoneUtils::ConstructL() |
|
383 { |
|
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 } |
|
402 |
|
403 |
|
404 // ----------------------------------------------------------------------------- |
|
405 // 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. |
|
407 // ----------------------------------------------------------------------------- |
|
408 // |
|
409 TInt CMusEngTelephoneUtils::ValidateVolume( const TInt aVolume ) const |
|
410 { |
|
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 } |
|
426 |
|
427 |
|
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 |
|
445 |