|
1 /* |
|
2 * Copyright (c) 2009 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 #include <e32def.h> // Define before audiopolicy defs |
|
19 #include <e32std.h> // Define before audiopolicy defs |
|
20 #include <eikdef.h> |
|
21 |
|
22 #ifndef __WINS__ |
|
23 |
|
24 #include <audiopolicypubsubdata.h> |
|
25 #include <audiosw_pubsubkeys.h> |
|
26 |
|
27 #endif //__WINS__ |
|
28 |
|
29 #include <ctsydomainpskeys.h> |
|
30 #include <publicruntimeids.hrh> |
|
31 #include <sacls.h> |
|
32 |
|
33 #ifdef COMPILE_IN_IVALO |
|
34 # include <voiceuidomainpskeys.h> |
|
35 #endif //COMPILE_IN_IVALO |
|
36 #include <featmgr.h> |
|
37 |
|
38 // User includes |
|
39 #include "cradioenginelogger.h" |
|
40 #include "cradiosystemeventdetector.h" |
|
41 #include "mradiosystemeventdetectorobserver.h" |
|
42 |
|
43 /** Granularity for audio category arrays. */ |
|
44 const TInt KVRAudioCategoryArrayGranularity = 3; |
|
45 |
|
46 // This has to be the last include. |
|
47 #ifdef STUB_CONSTELLATION |
|
48 # include "RadioStubManager.h" |
|
49 # define KUidSystemCategory KStub_KUidSystemCategory |
|
50 # define KPSUidCtsyCallInformation KStub_KPSUidCtsyCallInformation |
|
51 # define KPSUidVoiceUiAccMonitor KStub_KPSUidVoiceUiAccMonitor |
|
52 # define KPSUidMMFAudioServer KStub_KPSUidMMFAudioServer |
|
53 #endif //STUB_CONSTELLATION |
|
54 |
|
55 // ================= MEMBER FUNCTIONS ======================= |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CRadioSystemEventDetector::CRadioSystemEventDetector( MRadioSystemEventDetectorObserver& aObserver ) |
|
62 : iObserver( aObserver ) |
|
63 , iIsMobileNetworkCoverage( EFalse ) |
|
64 , iIsWlanCoverage( EFalse ) |
|
65 , iIsCallActive( EFalse ) |
|
66 , iIsAudioResourcesAvailable( ETrue ) |
|
67 , iIsVoiceUiActive( EFalse ) |
|
68 { |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 void CRadioSystemEventDetector::ConstructL() |
|
76 { |
|
77 // FeatureManager::InitializeLibL(); |
|
78 // TBool wlanSupported = FeatureManager::FeatureSupported( KFeatureIdProtocolWlan ); |
|
79 // FeatureManager::UnInitializeLib(); |
|
80 TBool wlanSupported = EFalse; //TODO: Check if we have any need for this |
|
81 |
|
82 iNetworkStatusObserver = CRadioPropertyObserver::NewL( *this, |
|
83 KUidSystemCategory, |
|
84 KUidNetworkStatusValue, |
|
85 CRadioPropertyObserver::ERadioPropertyInt ); |
|
86 iNetworkStatusObserver->ActivateL(); |
|
87 |
|
88 iIsMobileNetworkCoverage = iNetworkStatusObserver->ValueInt() == ESANetworkAvailable; |
|
89 |
|
90 // On S60 platform, there is no guaranteed way of seeing whether WLAN is explicitly turned off |
|
91 // in the settings, or whether the network is available. For now, we only check the existence of |
|
92 // the WLAN support in the feature manager. We might also want to check whether WLAN access points |
|
93 // have been configured. |
|
94 iIsWlanCoverage = wlanSupported; |
|
95 |
|
96 // Initialize call state observer. |
|
97 iCallStatusObserver = CRadioPropertyObserver::NewL( *this, |
|
98 KPSUidCtsyCallInformation, |
|
99 KCTsyCallState, |
|
100 CRadioPropertyObserver::ERadioPropertyInt ); |
|
101 iCallStatusObserver->ActivateL(); |
|
102 iIsCallActive = iCallStatusObserver->ValueInt() != EPSCTsyCallStateNone; |
|
103 |
|
104 #ifdef COMPILE_IN_IVALO |
|
105 // Initialize voice ui observer. |
|
106 iVoiceUiObserver = CRadioPropertyObserver::NewL( *this, |
|
107 KPSUidVoiceUiAccMonitor, |
|
108 KVoiceUiOpenKey, |
|
109 CRadioPropertyObserver::ERadioPropertyInt ); |
|
110 iVoiceUiObserver->ActivateL(); |
|
111 #endif //COMPILE_IN_IVALO |
|
112 |
|
113 #ifndef __WINS__ |
|
114 // Define audio types for not resuming. |
|
115 iNoAutoResumeAudioCategories = RArray<TInt>( KVRAudioCategoryArrayGranularity ); |
|
116 iNoAutoResumeAudioCategories.AppendL( ECatMediaPlayer ); |
|
117 iNoAutoResumeAudioCategories.AppendL( ECatMobileTv ); |
|
118 iNoAutoResumeAudioCategories.AppendL( ECatUnknownPlayer ); |
|
119 iNoAutoResumeAudioCategories.Compress(); |
|
120 // Start listening audio client events. |
|
121 iAudioPolicyObserver = CRadioPropertyObserver::NewL( *this, KPSUidMMFAudioServer, KAudioPolicyAudioClients, CRadioPropertyObserver::ERadioPropertyByteArray ); |
|
122 iAudioPolicyObserver->ActivateL(); |
|
123 #endif |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 CRadioSystemEventDetector::~CRadioSystemEventDetector() |
|
131 { |
|
132 FeatureManager::UnInitializeLib(); |
|
133 delete iCallStatusObserver; |
|
134 delete iNetworkStatusObserver; |
|
135 delete iVoiceUiObserver; |
|
136 delete iAudioPolicyObserver; |
|
137 |
|
138 iNoAutoResumeAudioCategories.Close(); |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 CRadioSystemEventDetector* CRadioSystemEventDetector::NewL( MRadioSystemEventDetectorObserver& aObserver ) |
|
146 { |
|
147 CRadioSystemEventDetector* self = new ( ELeave ) CRadioSystemEventDetector( aObserver ); |
|
148 CleanupStack::PushL( self ); |
|
149 self->ConstructL(); |
|
150 CleanupStack::Pop( self ); |
|
151 return self; |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // Handling of the int property changes is done here. |
|
156 // Observer components are getting notifications in correspondence with what |
|
157 // has changed |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 void CRadioSystemEventDetector::HandlePropertyChangeL( const TUid& aCategory, |
|
161 const TUint aKey, |
|
162 const TInt aValue ) |
|
163 { |
|
164 //TODO: Refactor |
|
165 if ( aCategory == KUidSystemCategory && aKey == KUidNetworkStatusValue ) |
|
166 { |
|
167 switch ( aValue ) |
|
168 { |
|
169 case ESANetworkAvailable: |
|
170 { |
|
171 SetNetworkCoverageL( ETrue, iIsWlanCoverage ); |
|
172 break; |
|
173 } |
|
174 case ESANetworkUnAvailable: |
|
175 { |
|
176 SetNetworkCoverageL( EFalse, iIsWlanCoverage ); |
|
177 break; |
|
178 } |
|
179 default: |
|
180 { |
|
181 break; |
|
182 } |
|
183 } |
|
184 } |
|
185 else if ( aCategory == KPSUidCtsyCallInformation && aKey == KCTsyCallState ) |
|
186 { |
|
187 if ( (!iIsCallActive ) && ( aValue > EPSCTsyCallStateNone )) |
|
188 { |
|
189 iIsCallActive = ETrue; |
|
190 iObserver.CallActivatedCallbackL(); |
|
191 } |
|
192 else if ( ( iIsCallActive ) && ( aValue <= EPSCTsyCallStateNone )) |
|
193 { |
|
194 iIsCallActive = EFalse; |
|
195 iObserver.CallDeactivatedCallbackL(); |
|
196 } |
|
197 else |
|
198 { |
|
199 // No change |
|
200 } |
|
201 } |
|
202 #ifdef COMPILE_IN_IVALO |
|
203 else if ( aCategory == KPSUidVoiceUiAccMonitor && aKey == KVoiceUiOpenKey ) |
|
204 { |
|
205 switch ( aValue ) |
|
206 { |
|
207 case KVoiceUiIsClose: |
|
208 { |
|
209 if ( iIsVoiceUiActive ) |
|
210 { |
|
211 iIsVoiceUiActive = EFalse; |
|
212 LOG( "Voice UI not active." ); |
|
213 if ( iIsAudioResourcesAvailable ) |
|
214 { |
|
215 LOG( "Audio resources available. Change informed." ); |
|
216 iObserver.AudioResourcesAvailableL(); |
|
217 } |
|
218 } |
|
219 break; |
|
220 } |
|
221 case KVoiceUiIsOpen: |
|
222 { |
|
223 if ( !iIsVoiceUiActive ) |
|
224 { |
|
225 iIsVoiceUiActive = ETrue; |
|
226 LOG( "Voice UI active." ); |
|
227 } |
|
228 break; |
|
229 } |
|
230 default: |
|
231 { |
|
232 break; |
|
233 } |
|
234 } |
|
235 } |
|
236 #endif //COMPILE_IN_IVALO |
|
237 else // NOP |
|
238 { |
|
239 } |
|
240 } |
|
241 |
|
242 #ifndef __WINS__ |
|
243 // --------------------------------------------------------------------------- |
|
244 // Handling of the byte array property changes is done here. |
|
245 // Observer components are getting notifications in correspondence with what |
|
246 // has changed |
|
247 // --------------------------------------------------------------------------- |
|
248 // |
|
249 void CRadioSystemEventDetector::HandlePropertyChangeL( const TUid& aCategory, |
|
250 const TUint aKey, |
|
251 const TDesC8& aValue ) |
|
252 { |
|
253 #if 0 |
|
254 LOG_METHOD_AUTO; |
|
255 LOG_FORMAT( "Category: %d, Key: %d", aCategory, aKey ); |
|
256 if ( aCategory == KPSUidMMFAudioServer ) |
|
257 { |
|
258 if ( aKey == KAudioPolicyAudioClients ) |
|
259 { |
|
260 TBool atLeastOneAutoResumeAudioPlaying( EFalse ); |
|
261 TBool atLeastOneNoAutoResumeAudioPlaying( EFalse ); |
|
262 TBool radioPlaying( EFalse ); |
|
263 TAudioClientList audioClients; |
|
264 audioClients.Copy( aValue ); |
|
265 // Check all playing audios! |
|
266 for ( TInt i = 0; i < audioClients().iNumOfProcesses ; i++ ) |
|
267 { |
|
268 TInt cat = audioClients().iClientCategoryList[i]; |
|
269 LOG_FORMAT( "Check audio cat %x", cat ); |
|
270 if ( cat == ECatFmRadio ) |
|
271 { |
|
272 radioPlaying = ETrue; |
|
273 } |
|
274 else if ( iNoAutoResumeAudioCategories.Find( cat ) != KErrNotFound ) |
|
275 { |
|
276 atLeastOneNoAutoResumeAudioPlaying = ETrue; |
|
277 } |
|
278 else |
|
279 { |
|
280 atLeastOneAutoResumeAudioPlaying = ETrue; |
|
281 } |
|
282 } |
|
283 |
|
284 if ( !radioPlaying ) |
|
285 { |
|
286 // Decide audio resource availability from audio category info. |
|
287 if ( atLeastOneNoAutoResumeAudioPlaying ) |
|
288 { |
|
289 LOG( "Audio resources not available. Change informed." ); |
|
290 iIsAudioResourcesAvailable = EFalse; |
|
291 iObserver.AudioAutoResumeForbiddenL(); |
|
292 } |
|
293 else if ( !atLeastOneAutoResumeAudioPlaying ) |
|
294 { |
|
295 if ( !iIsVoiceUiActive ) |
|
296 { |
|
297 LOG( "Audio resources available. Change informed." ); |
|
298 iIsAudioResourcesAvailable = ETrue; |
|
299 iObserver.AudioResourcesAvailableL(); |
|
300 } |
|
301 else |
|
302 { |
|
303 LOG( "Audio resources available. Change not informed." ); |
|
304 iIsAudioResourcesAvailable = ETrue; |
|
305 } |
|
306 } |
|
307 else |
|
308 { |
|
309 LOG( "Audio resources not available. Change not informed." ); |
|
310 iIsAudioResourcesAvailable = EFalse; |
|
311 } |
|
312 } |
|
313 else // audio resources are considered to be available when radio is playing |
|
314 { |
|
315 iIsAudioResourcesAvailable = ETrue; |
|
316 } |
|
317 } |
|
318 } |
|
319 #endif |
|
320 } |
|
321 |
|
322 #else //__WINS__ |
|
323 // --------------------------------------------------------------------------- |
|
324 // Dummy version for WINS in order to avoid compiler warnings. |
|
325 // The real implementation of function is above. |
|
326 // --------------------------------------------------------------------------- |
|
327 // |
|
328 void CRadioSystemEventDetector::HandlePropertyChangeL( const TUid& /*aCategory*/, |
|
329 const TUint /*aKey*/, |
|
330 const TDesC8& /*aValue*/) |
|
331 { |
|
332 } |
|
333 #endif |
|
334 |
|
335 // --------------------------------------------------------------------------- |
|
336 // Handling of the text property changes is done here. |
|
337 // Observer components are getting notifications in correspondence with what |
|
338 // has changed |
|
339 // --------------------------------------------------------------------------- |
|
340 // |
|
341 void CRadioSystemEventDetector::HandlePropertyChangeL( const TUid& /*aCategory*/, |
|
342 const TUint /*aKey*/, |
|
343 const TDesC& /*aValue*/) |
|
344 { |
|
345 } |
|
346 |
|
347 // --------------------------------------------------------------------------- |
|
348 // This is a callback function which is called when a P&S components returns |
|
349 // an error |
|
350 // --------------------------------------------------------------------------- |
|
351 // |
|
352 void CRadioSystemEventDetector::HandlePropertyChangeErrorL( const TUid& aCategory, |
|
353 const TUint aKey, |
|
354 TInt aError ) |
|
355 { |
|
356 #ifdef COMPILE_IN_IVALO |
|
357 if ( aCategory == KPSUidVoiceUiAccMonitor && aKey == KVoiceUiOpenKey && aError == KErrNotFound ) |
|
358 { |
|
359 HandlePropertyChangeL( KPSUidVoiceUiAccMonitor, KVoiceUiOpenKey, KVoiceUiIsClose ); |
|
360 } |
|
361 else |
|
362 { |
|
363 iObserver.ErrorCallbackL( aError ); |
|
364 } |
|
365 #else |
|
366 (void)aCategory; |
|
367 (void)aKey; |
|
368 (void)aError; |
|
369 #endif //COMPILE_IN_IVALO |
|
370 } |
|
371 |
|
372 // --------------------------------------------------------------------------- |
|
373 // |
|
374 // --------------------------------------------------------------------------- |
|
375 // |
|
376 TBool CRadioSystemEventDetector::IsMobileNetworkCoverage() const |
|
377 { |
|
378 return iIsMobileNetworkCoverage; |
|
379 } |
|
380 |
|
381 // --------------------------------------------------------------------------- |
|
382 // |
|
383 // --------------------------------------------------------------------------- |
|
384 // |
|
385 TBool CRadioSystemEventDetector::IsNetworkCoverage() const |
|
386 { |
|
387 return iIsWlanCoverage || iIsMobileNetworkCoverage; |
|
388 } |
|
389 |
|
390 // --------------------------------------------------------------------------- |
|
391 // |
|
392 // --------------------------------------------------------------------------- |
|
393 // |
|
394 TBool CRadioSystemEventDetector::IsCallActive() const |
|
395 { |
|
396 return iIsCallActive; |
|
397 } |
|
398 |
|
399 // --------------------------------------------------------------------------- |
|
400 // |
|
401 // --------------------------------------------------------------------------- |
|
402 // |
|
403 TBool CRadioSystemEventDetector::IsAudioResourcesAvailable() const |
|
404 { |
|
405 return iIsAudioResourcesAvailable; |
|
406 } |
|
407 |
|
408 // --------------------------------------------------------------------------- |
|
409 // |
|
410 // --------------------------------------------------------------------------- |
|
411 // |
|
412 TBool CRadioSystemEventDetector::IsVoiceUiActive() const |
|
413 { |
|
414 return iIsVoiceUiActive; |
|
415 } |
|
416 |
|
417 // --------------------------------------------------------------------------- |
|
418 // |
|
419 // --------------------------------------------------------------------------- |
|
420 // |
|
421 void CRadioSystemEventDetector::SetNetworkCoverageL( const TBool aIsMobileNetworkCoverage, |
|
422 const TBool aIsWlanCoverage ) |
|
423 { |
|
424 LOG_FORMAT( "CRadioSystemEventDetector::SetNetworkCoverageL ( mobile = %d wlan = %d )", aIsMobileNetworkCoverage, aIsWlanCoverage ); |
|
425 |
|
426 TBool wasCoverage = IsNetworkCoverage(); |
|
427 iIsMobileNetworkCoverage = aIsMobileNetworkCoverage; |
|
428 iIsWlanCoverage = aIsWlanCoverage; |
|
429 TBool isCoverage = IsNetworkCoverage(); |
|
430 |
|
431 if ( isCoverage != wasCoverage ) |
|
432 { |
|
433 if ( isCoverage ) |
|
434 { |
|
435 iObserver.NetworkUpCallbackL(); |
|
436 } |
|
437 else |
|
438 { |
|
439 iObserver.NetworkDownCallbackL(); |
|
440 } |
|
441 } |
|
442 } |