|
1 /* |
|
2 * Copyright (c) 2004-2008 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 * Class provides implementation to detect system events and notify UI |
|
16 * components of the event, Class keeps several instances of |
|
17 * CIRPropertyObserver2, and those instances send event notifications |
|
18 * about the particular system component state change. |
|
19 * |
|
20 */ |
|
21 |
|
22 |
|
23 #include <e32def.h> // Define before audiopolicy defs |
|
24 #include <e32std.h> // Define before audiopolicy defs |
|
25 #include <eikdef.h> |
|
26 |
|
27 #ifndef __WINS__ |
|
28 |
|
29 //#include <audiopolicypubsubdata.h> |
|
30 //#include <audiosw_pubsubkeys.h> |
|
31 |
|
32 #endif //__WINS__ |
|
33 |
|
34 #include <ctsydomainpskeys.h> |
|
35 #include <wlaninternalpskeys.h> |
|
36 #include <sacls.h> |
|
37 #ifdef MUSICSHOP_AVAILABLE |
|
38 #include <voiceuidomainpskeys.h> |
|
39 #endif |
|
40 #include <featmgr.h> |
|
41 //d #include <vrdebug.h> |
|
42 |
|
43 #include "irsystemeventdetector.h" |
|
44 #include "irsystemeventdetectorobserver.h" |
|
45 #include "irdebug.h" |
|
46 |
|
47 /** Granularity for audio category arrays. */ |
|
48 const TInt KVRAudioCategoryArrayGranularity = 3; |
|
49 |
|
50 // ================= MEMBER FUNCTIONS ======================= |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // C++ default constructor can NOT contain any code, that might leave. |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CIRSystemEventDetector::CIRSystemEventDetector(MIRSystemEventDetectorObserver& aObserver) |
|
57 : iObserver(aObserver), |
|
58 iIsMobileNetworkCoverage(EFalse), |
|
59 iIsWlanCoverage(EFalse), |
|
60 iIsCallActive(EFalse), |
|
61 iIsAudioResourcesAvailable(ETrue), |
|
62 iIsVoiceUiActive(EFalse) |
|
63 { |
|
64 IRLOG_DEBUG( "CIRSystemEventDetector::CIRSystemEventDetector" ); |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // EPOC default constructor can leave. |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 void CIRSystemEventDetector::ConstructL() |
|
72 { |
|
73 IRLOG_DEBUG( "CIRSystemEventDetector::ConstructL - Entering" ); |
|
74 FeatureManager::InitializeLibL(); |
|
75 TBool wlanSupported = FeatureManager::FeatureSupported(KFeatureIdProtocolWlan); |
|
76 FeatureManager::UnInitializeLib(); |
|
77 |
|
78 |
|
79 iNetworkStatusObserver = CIRPropertyObserver2::NewL(*this, |
|
80 KUidSystemCategory, |
|
81 KUidNetworkStatusValue, |
|
82 CIRPropertyObserver2::EIRPropertyInt); |
|
83 iNetworkStatusObserver->ActivateL(); |
|
84 |
|
85 iIsMobileNetworkCoverage = (iNetworkStatusObserver->ValueInt() == ESANetworkAvailable) ? |
|
86 ETrue : EFalse; |
|
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. We use the P&S key KPSUidWlan/KPSWlanIndicator |
|
90 // because it is the best we can get. |
|
91 if (wlanSupported) |
|
92 { |
|
93 iWlanObserver = CIRPropertyObserver2::NewL(*this, |
|
94 KPSUidWlan, |
|
95 KPSWlanIndicator, |
|
96 CIRPropertyObserver2::EIRPropertyInt); |
|
97 iWlanObserver->ActivateL(); |
|
98 |
|
99 TInt wlanStatus = iWlanObserver->ValueInt(); |
|
100 iIsWlanCoverage = (wlanStatus == EPSWlanIndicatorActive || wlanStatus == |
|
101 EPSWlanIndicatorActiveSecure) ? ETrue : EFalse; |
|
102 } |
|
103 else |
|
104 { |
|
105 iIsWlanCoverage = EFalse; |
|
106 } |
|
107 |
|
108 // Initialize call state observer. |
|
109 iCallStatusObserver = CIRPropertyObserver2::NewL(*this, |
|
110 KPSUidCtsyCallInformation, |
|
111 KCTsyCallState, |
|
112 CIRPropertyObserver2::EIRPropertyInt); |
|
113 iCallStatusObserver->ActivateL(); |
|
114 iIsCallActive = iCallStatusObserver->ValueInt() != EPSCTsyCallStateNone; |
|
115 |
|
116 #ifdef MUSICSHOP_AVAILABLE |
|
117 // Initialize voice ui observer. |
|
118 iVoiceUiObserver = CIRPropertyObserver2::NewL(*this, KPSUidVoiceUiAccMonitor, KVoiceUiOpenKey, |
|
119 CIRPropertyObserver2::EIRPropertyInt); |
|
120 iVoiceUiObserver->ActivateL(); |
|
121 #endif |
|
122 IRLOG_DEBUG( "CIRSystemEventDetector::ConstructL - Exiting" ); |
|
123 |
|
124 #ifndef __WINS__ |
|
125 // Define audio types for not resuming. |
|
126 iNoAutoResumeAudioCategories = RArray<TInt>( KVRAudioCategoryArrayGranularity ); |
|
127 // iNoAutoResumeAudioCategories.AppendL(ECatMediaPlayer) |
|
128 // iNoAutoResumeAudioCategories.AppendL(ECatMobileTv) |
|
129 // iNoAutoResumeAudioCategories.AppendL(ECatUnknownPlayer) |
|
130 iNoAutoResumeAudioCategories.Compress(); |
|
131 // Start listening audio client events |
|
132 // iAudioPolicyObserver = CIRPropertyObserver2::NewL(*this, KPSUidMMFAudioServer, KAudioPolicyAudioClients, CIRPropertyObserver2::EIRPropertyByteArray) |
|
133 // iAudioPolicyObserver->ActivateL() |
|
134 #endif |
|
135 } |
|
136 |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // Destructor |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 CIRSystemEventDetector::~CIRSystemEventDetector() |
|
143 { |
|
144 IRLOG_DEBUG( "CIRSystemEventDetector::~CIRSystemEventDetector - Entering" ); |
|
145 FeatureManager::UnInitializeLib(); |
|
146 delete iCallStatusObserver; |
|
147 delete iNetworkStatusObserver; |
|
148 delete iVoiceUiObserver; |
|
149 // delete iAudioPolicyObserver |
|
150 delete iWlanObserver; |
|
151 |
|
152 iNoAutoResumeAudioCategories.Close(); |
|
153 IRLOG_DEBUG( "CIRSystemEventDetector::~CIRSystemEventDetector - Exiting" ); |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // Two-phased constructor. |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 CIRSystemEventDetector* CIRSystemEventDetector::NewL( |
|
161 MIRSystemEventDetectorObserver& aObserver) |
|
162 { |
|
163 IRLOG_DEBUG( "CIRSystemEventDetector::NewL - Entering" ); |
|
164 CIRSystemEventDetector* self = new (ELeave) CIRSystemEventDetector(aObserver); |
|
165 |
|
166 CleanupStack::PushL( self ); |
|
167 self->ConstructL(); |
|
168 CleanupStack::Pop( self ); |
|
169 IRLOG_DEBUG( "CIRSystemEventDetector::NewL - Exiting" ); |
|
170 return self; |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // Handling of the int property changes is done here. |
|
175 // Observer components are getting notifications in correspondence with what |
|
176 // has changed |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 void CIRSystemEventDetector::HandlePropertyChangeL( const TUid& aCategory, |
|
180 const TUint aKey, |
|
181 const TInt aValue ) |
|
182 { |
|
183 IRLOG_DEBUG( "CIRSystemEventDetector::HandlePropertyChangeL - Entering" ); |
|
184 if (aCategory == KUidSystemCategory && aKey == KUidNetworkStatusValue) |
|
185 { |
|
186 switch (aValue) |
|
187 { |
|
188 case ESANetworkAvailable: |
|
189 { |
|
190 SetNetworkCoverageL( ETrue, iIsWlanCoverage ); |
|
191 break; |
|
192 } |
|
193 case ESANetworkUnAvailable: |
|
194 { |
|
195 SetNetworkCoverageL( EFalse, iIsWlanCoverage ); |
|
196 break; |
|
197 } |
|
198 default: |
|
199 { |
|
200 break; |
|
201 } |
|
202 } |
|
203 } |
|
204 else if (aCategory == KPSUidCtsyCallInformation && aKey == KCTsyCallState) |
|
205 { |
|
206 if ((!iIsCallActive) && (aValue > EPSCTsyCallStateNone)) |
|
207 { |
|
208 iIsCallActive = ETrue; |
|
209 iObserver.CallActivatedCallbackL(); |
|
210 } |
|
211 else if ((iIsCallActive) && (aValue <= EPSCTsyCallStateNone)) |
|
212 { |
|
213 iIsCallActive = EFalse; |
|
214 iObserver.CallDeactivatedCallbackL(); |
|
215 } |
|
216 } |
|
217 else if ( aCategory == KPSUidWlan && aKey == KPSWlanIndicator ) |
|
218 { |
|
219 switch (aValue) |
|
220 { |
|
221 case EPSWlanIndicatorActive: |
|
222 case EPSWlanIndicatorActiveSecure: |
|
223 { |
|
224 SetNetworkCoverageL( iIsMobileNetworkCoverage, ETrue ); |
|
225 break; |
|
226 } |
|
227 case EPSWlanIndicatorNone: |
|
228 case EPSWlanIndicatorAvailable: |
|
229 { |
|
230 SetNetworkCoverageL( iIsMobileNetworkCoverage, EFalse ); |
|
231 break; |
|
232 } |
|
233 default: |
|
234 { |
|
235 break; |
|
236 } |
|
237 } |
|
238 } |
|
239 #ifdef MUSICSHOP_AVAILABLE |
|
240 else if ( aCategory == KPSUidVoiceUiAccMonitor && aKey == KVoiceUiOpenKey ) |
|
241 { |
|
242 switch (aValue) |
|
243 { |
|
244 case KVoiceUiIsClose: |
|
245 { |
|
246 if (iIsVoiceUiActive) |
|
247 { |
|
248 iIsVoiceUiActive = EFalse; |
|
249 if (iIsAudioResourcesAvailable) |
|
250 { |
|
251 iObserver.AudioResourcesAvailableL(); |
|
252 } |
|
253 } |
|
254 break; |
|
255 } |
|
256 case KVoiceUiIsOpen: |
|
257 { |
|
258 if (!iIsVoiceUiActive) |
|
259 { |
|
260 iIsVoiceUiActive = ETrue; |
|
261 } |
|
262 break; |
|
263 } |
|
264 default: |
|
265 { |
|
266 break; |
|
267 } |
|
268 } |
|
269 } |
|
270 #endif |
|
271 else // NOP |
|
272 { |
|
273 } |
|
274 IRLOG_DEBUG( "CIRSystemEventDetector::HandlePropertyChangeL - Exiting" ); |
|
275 } |
|
276 |
|
277 #ifndef __WINS__ |
|
278 // --------------------------------------------------------------------------- |
|
279 // Handling of the byte array property changes is done here. |
|
280 // Observer components are getting notifications in correspondence with what |
|
281 // has changed |
|
282 // --------------------------------------------------------------------------- |
|
283 // |
|
284 void CIRSystemEventDetector::HandlePropertyChangeL( const TUid& aCategory, |
|
285 const TUint aKey, |
|
286 const TDesC8& aValue) |
|
287 { |
|
288 /* if (aCategory == KPSUidMMFAudioServer) |
|
289 { |
|
290 if (aKey == KAudioPolicyAudioClients) |
|
291 { |
|
292 TBool atLeastOneAutoResumeAudioPlaying(EFalse); |
|
293 TBool atLeastOneNoAutoResumeAudioPlaying(EFalse); |
|
294 TBool radioPlaying(EFalse); |
|
295 TAudioClientList audioClients; |
|
296 audioClients.Copy(aValue); |
|
297 // Check all playing audios |
|
298 for ( TInt i = 0; i < audioClients().iNumOfProcesses ; i++ ) |
|
299 { |
|
300 TInt cat = audioClients().iClientCategoryList[i]; |
|
301 VRDEBUG2(" *** S60VisualRadio -- Check audio cat %d", cat); |
|
302 if (cat == ECatFmRadio) |
|
303 { |
|
304 radioPlaying = ETrue; |
|
305 } |
|
306 else if (iNoAutoResumeAudioCategories.Find(cat) != KErrNotFound) |
|
307 { |
|
308 atLeastOneNoAutoResumeAudioPlaying = ETrue; |
|
309 } |
|
310 else |
|
311 { |
|
312 atLeastOneAutoResumeAudioPlaying = ETrue; |
|
313 } |
|
314 } |
|
315 |
|
316 if (!radioPlaying) |
|
317 { |
|
318 // Decide audio resource availability from audio category info. |
|
319 if (atLeastOneNoAutoResumeAudioPlaying) |
|
320 { |
|
321 VRDEBUG(" *** S60VisualRadio -- Audio resources not available. Change informed."); |
|
322 iIsAudioResourcesAvailable = EFalse; |
|
323 iObserver.AudioAutoResumeForbiddenL(); |
|
324 } |
|
325 else if (!atLeastOneAutoResumeAudioPlaying) |
|
326 { |
|
327 if (!iIsVoiceUiActive) |
|
328 { |
|
329 VRDEBUG(" *** S60VisualRadio -- Audio resources available. Change informed."); |
|
330 iIsAudioResourcesAvailable = ETrue; |
|
331 iObserver.AudioResourcesAvailableL(); |
|
332 } |
|
333 else |
|
334 { |
|
335 VRDEBUG(" *** S60VisualRadio -- Audio resources available. Change not informed."); |
|
336 iIsAudioResourcesAvailable = ETrue; |
|
337 } |
|
338 } |
|
339 else |
|
340 { |
|
341 VRDEBUG(" *** S60VisualRadio -- Audio resources not available. Change not informed."); |
|
342 iIsAudioResourcesAvailable = EFalse; |
|
343 } |
|
344 } |
|
345 else // audio resources are considered to be available when radio is playing |
|
346 { |
|
347 iIsAudioResourcesAvailable = ETrue; |
|
348 } |
|
349 } |
|
350 } |
|
351 */ } |
|
352 |
|
353 #else //__WINS__ |
|
354 // --------------------------------------------------------------------------- |
|
355 // Dummy version for WINS in order to avoid compiler warnings. |
|
356 // The real implementation of function is above. |
|
357 // --------------------------------------------------------------------------- |
|
358 // |
|
359 void CIRSystemEventDetector::HandlePropertyChangeL( const TUid& /*aCategory*/, |
|
360 const TUint /*aKey*/, |
|
361 const TDesC8& /*aValue*/) |
|
362 { |
|
363 IRLOG_DEBUG( "CIRSystemEventDetector::HandlePropertyChangeL" ); |
|
364 } |
|
365 #endif |
|
366 |
|
367 // --------------------------------------------------------------------------- |
|
368 // Handling of the text property changes is done here. |
|
369 // Observer components are getting notifications in correspondence with what |
|
370 // has changed |
|
371 // --------------------------------------------------------------------------- |
|
372 // |
|
373 void CIRSystemEventDetector::HandlePropertyChangeL( const TUid& /*aCategory*/, |
|
374 const TUint /*aKey*/, |
|
375 const TDesC& /*aValue*/) |
|
376 { |
|
377 IRLOG_DEBUG( "CIRSystemEventDetector::HandlePropertyChangeL" ); |
|
378 } |
|
379 |
|
380 // --------------------------------------------------------------------------- |
|
381 // This is a callback function which is called when a P&S components returns |
|
382 // an error |
|
383 // --------------------------------------------------------------------------- |
|
384 // |
|
385 void CIRSystemEventDetector::HandlePropertyChangeErrorL( const TUid& aCategory, |
|
386 const TUint aKey, |
|
387 TInt aError ) |
|
388 { |
|
389 IRLOG_DEBUG( "CIRSystemEventDetector::HandlePropertyChangeErrorL - Entering" ); |
|
390 #ifdef MUSICSHOP_AVAILABLE |
|
391 if ( aCategory == KPSUidVoiceUiAccMonitor && aKey == KVoiceUiOpenKey && aError == KErrNotFound ) |
|
392 { |
|
393 HandlePropertyChangeL( KPSUidVoiceUiAccMonitor, KVoiceUiOpenKey, KVoiceUiIsClose ); |
|
394 } |
|
395 else |
|
396 { |
|
397 iObserver.ErrorCallbackL(aError); |
|
398 } |
|
399 #else // remove warnings |
|
400 if ( aCategory.iUid == 0x101F8543 || aKey || aError) |
|
401 { |
|
402 // do nothing |
|
403 } |
|
404 #endif |
|
405 IRLOG_DEBUG( "CIRSystemEventDetector::HandlePropertyChangeErrorL - Exiting" ); |
|
406 } |
|
407 |
|
408 // --------------------------------------------------------------------------- |
|
409 TBool CIRSystemEventDetector::IsMobileNetworkCoverage() const |
|
410 { |
|
411 IRLOG_DEBUG( "CIRSystemEventDetector::IsMobileNetworkCoverage" ); |
|
412 return iIsMobileNetworkCoverage; |
|
413 } |
|
414 // CIRSystemEventDetector::IsNetworkCoverage |
|
415 // --------------------------------------------------------------------------- |
|
416 // |
|
417 TBool CIRSystemEventDetector::IsNetworkCoverage() const |
|
418 { |
|
419 IRLOG_DEBUG( "CIRSystemEventDetector::IsNetworkCoverage" ); |
|
420 return iIsWlanCoverage || iIsMobileNetworkCoverage; |
|
421 } |
|
422 |
|
423 // --------------------------------------------------------------------------- |
|
424 // CIRSystemEventDetector::IsCallActive |
|
425 // --------------------------------------------------------------------------- |
|
426 // |
|
427 TBool CIRSystemEventDetector::IsCallActive() const |
|
428 { |
|
429 IRLOG_DEBUG( "CIRSystemEventDetector::IsCallActive" ); |
|
430 return iIsCallActive; |
|
431 } |
|
432 |
|
433 // --------------------------------------------------------------------------- |
|
434 // CIRSystemEventDetector::IsAudioResourcesAvailable |
|
435 // --------------------------------------------------------------------------- |
|
436 // |
|
437 TBool CIRSystemEventDetector::IsAudioResourcesAvailable() const |
|
438 { |
|
439 IRLOG_DEBUG( "CIRSystemEventDetector::IsAudioResourcesAvailable" ); |
|
440 return iIsAudioResourcesAvailable; |
|
441 } |
|
442 |
|
443 // --------------------------------------------------------------------------- |
|
444 // CIRSystemEventDetector::IsVoiceUiActive |
|
445 // --------------------------------------------------------------------------- |
|
446 // |
|
447 TBool CIRSystemEventDetector::IsVoiceUiActive() const |
|
448 { |
|
449 IRLOG_DEBUG( "CIRSystemEventDetector::IsVoiceUiActive" ); |
|
450 return iIsVoiceUiActive; |
|
451 } |
|
452 |
|
453 |
|
454 // --------------------------------------------------------------------------- |
|
455 // CIRSystemEventDetector::SetNetworkCoverageL |
|
456 // --------------------------------------------------------------------------- |
|
457 // |
|
458 void CIRSystemEventDetector::SetNetworkCoverageL( const TBool aIsMobileNetworkCoverage, |
|
459 const TBool aIsWlanCoverage ) |
|
460 { |
|
461 IRLOG_DEBUG( "CIRSystemEventDetector::SetNetworkCoverageL - Entering" ); |
|
462 |
|
463 TBool wasCoverage = IsNetworkCoverage(); |
|
464 iIsMobileNetworkCoverage = aIsMobileNetworkCoverage; |
|
465 iIsWlanCoverage = aIsWlanCoverage; |
|
466 TBool isCoverage = IsNetworkCoverage(); |
|
467 |
|
468 if (isCoverage != wasCoverage) |
|
469 { |
|
470 if (isCoverage) |
|
471 { |
|
472 iObserver.NetworkUpCallbackL(); |
|
473 } |
|
474 else |
|
475 { |
|
476 iObserver.NetworkDownCallbackL(); |
|
477 } |
|
478 IRLOG_DEBUG( "CIRSystemEventDetector::SetNetworkCoverageL - Exiting" ); |
|
479 } |
|
480 } |