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