radioengine/utils/src/cradiosystemeventdetector.cpp
branchRCL_3
changeset 20 93c594350b9a
parent 19 cce62ebc198e
equal deleted inserted replaced
19:cce62ebc198e 20:93c594350b9a
     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 #include <AudioClientsListPSKeys.h>
       
    27 
       
    28 #endif //__WINS__
       
    29 
       
    30 #include <ctsydomainpskeys.h>
       
    31 #include <publicruntimeids.hrh>
       
    32 #include <sacls.h>
       
    33 
       
    34 // User includes
       
    35 #include "cradioenginelogger.h"
       
    36 #include "cradiosystemeventdetector.h"
       
    37 #include "mradiosystemeventdetectorobserver.h"
       
    38 
       
    39 /** Granularity for audio category arrays. */
       
    40 //const TInt KVRAudioCategoryArrayGranularity = 3;
       
    41 
       
    42 // This has to be the last include. 
       
    43 #ifdef STUB_CONSTELLATION
       
    44 #   include "RadioStubManager.h"
       
    45 #   define KUidSystemCategory KStub_KUidSystemCategory
       
    46 #   define KPSUidCtsyCallInformation KStub_KPSUidCtsyCallInformation
       
    47 #   define KPSUidVoiceUiAccMonitor KStub_KPSUidVoiceUiAccMonitor
       
    48 #   define KPSUidMMFAudioServer KStub_KPSUidMMFAudioServer
       
    49 #endif //STUB_CONSTELLATION
       
    50 
       
    51 // ================= MEMBER FUNCTIONS =======================
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CRadioSystemEventDetector::CRadioSystemEventDetector( MRadioSystemEventDetectorObserver&  aObserver )
       
    58     : iObserver( aObserver )
       
    59     , iIsMobileNetworkCoverage( EFalse )
       
    60     , iIsCallActive( EFalse )
       
    61     , iIsAudioResourcesAvailable( ETrue )
       
    62     {
       
    63     LEVEL3( LOG_METHOD_AUTO );
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 void CRadioSystemEventDetector::ConstructL()
       
    71     {
       
    72     LOG_METHOD_AUTO;
       
    73     iNetworkStatusObserver = CRadioPropertyObserver::NewL( *this,
       
    74                                                            KUidSystemCategory,
       
    75                                                            KUidNetworkStatusValue,
       
    76                                                            CRadioPropertyObserver::ERadioPropertyInt );
       
    77     iNetworkStatusObserver->ActivateL();
       
    78 
       
    79     iIsMobileNetworkCoverage = iNetworkStatusObserver->ValueInt() == ESANetworkAvailable;
       
    80 
       
    81     // Initialize call state observer.
       
    82     iCallStatusObserver = CRadioPropertyObserver::NewL( *this,
       
    83                                                         KPSUidCtsyCallInformation,
       
    84                                                         KCTsyCallState,
       
    85                                                         CRadioPropertyObserver::ERadioPropertyInt );
       
    86     iCallStatusObserver->ActivateL();
       
    87     iIsCallActive = iCallStatusObserver->ValueInt() != EPSCTsyCallStateNone;
       
    88 /*
       
    89 #ifndef __WINS__
       
    90     // Define audio types for not resuming.
       
    91     //TODO: Check these audio resume categories!
       
    92     iNoAutoResumeAudioCategories = RArray<TInt>( KVRAudioCategoryArrayGranularity );
       
    93     iNoAutoResumeAudioCategories.AppendL( ECatMediaPlayer );
       
    94     iNoAutoResumeAudioCategories.AppendL( ECatMobileTv );
       
    95     iNoAutoResumeAudioCategories.AppendL( ECatUnknownPlayer );
       
    96     iNoAutoResumeAudioCategories.Compress();
       
    97     // Start listening audio client events.
       
    98     iAudioPolicyObserver = CRadioPropertyObserver::NewL( *this, KPSUidMMFAudioServer, KAudioPolicyAudioClients, CRadioPropertyObserver::ERadioPropertyByteArray );
       
    99     iAudioPolicyObserver->ActivateL();
       
   100 #endif
       
   101 */
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 CRadioSystemEventDetector::~CRadioSystemEventDetector()
       
   109     {
       
   110     LEVEL3( LOG_METHOD_AUTO );
       
   111     delete iCallStatusObserver;
       
   112     delete iNetworkStatusObserver;
       
   113     delete iAudioPolicyObserver;
       
   114 
       
   115     iNoAutoResumeAudioCategories.Close();
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 CRadioSystemEventDetector* CRadioSystemEventDetector::NewL( MRadioSystemEventDetectorObserver&  aObserver )
       
   123     {
       
   124     LEVEL3( LOG_METHOD_AUTO );
       
   125     CRadioSystemEventDetector* self = new ( ELeave ) CRadioSystemEventDetector( aObserver );
       
   126     CleanupStack::PushL( self );
       
   127     self->ConstructL();
       
   128     CleanupStack::Pop( self );
       
   129     return self;
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // Handling of the int property changes is done here.
       
   134 // Observer components are getting notifications in correspondence with what
       
   135 // has changed
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 void CRadioSystemEventDetector::HandlePropertyChangeL( const TUid& aCategory,
       
   139                                                        const TUint aKey,
       
   140                                                        const TInt aValue )
       
   141     {
       
   142     LEVEL2( LOG_METHOD_AUTO );
       
   143     if ( aCategory == KPSUidCtsyCallInformation && aKey == KCTsyCallState )
       
   144         {
       
   145         if ( (!iIsCallActive ) && ( aValue > EPSCTsyCallStateNone ))
       
   146             {
       
   147             iIsCallActive = ETrue;
       
   148             iObserver.CallActivatedCallbackL();
       
   149             }
       
   150         else if ( ( iIsCallActive ) && ( aValue <= EPSCTsyCallStateNone ))
       
   151             {
       
   152             iIsCallActive = EFalse;
       
   153             iObserver.CallDeactivatedCallbackL();
       
   154             }
       
   155         }
       
   156     }
       
   157 
       
   158 #ifndef __WINS__
       
   159 // ---------------------------------------------------------------------------
       
   160 // Handling of the byte array property changes is done here.
       
   161 // Observer components are getting notifications in correspondence with what
       
   162 // has changed
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 void CRadioSystemEventDetector::HandlePropertyChangeL( const TUid& aCategory,
       
   166                                                        const TUint aKey,
       
   167                                                        const TDesC8& aValue )
       
   168     {
       
   169 #if 0
       
   170     LEVEL2( LOG_METHOD_AUTO );
       
   171     LOG_FORMAT( "Category: %d, Key: %d", aCategory, aKey );
       
   172     if ( aCategory == KPSUidMMFAudioServer )
       
   173         {
       
   174         if ( aKey == KAudioPolicyAudioClients )
       
   175             {
       
   176             TBool atLeastOneAutoResumeAudioPlaying( EFalse );
       
   177             TBool atLeastOneNoAutoResumeAudioPlaying( EFalse );
       
   178             TBool radioPlaying( EFalse );
       
   179             TAudioClientList audioClients;
       
   180             audioClients.Copy( aValue );
       
   181             // Check all playing audios!
       
   182             for ( TInt i = 0; i < audioClients().iNumOfProcesses ; ++i )
       
   183                 {
       
   184                 TInt cat = audioClients().iClientCategoryList[i];
       
   185                 LOG_FORMAT( "Check audio cat %x", cat );
       
   186                 if ( cat == ECatFmRadio )
       
   187                     {
       
   188                     radioPlaying = ETrue;
       
   189                     }
       
   190                 else if ( iNoAutoResumeAudioCategories.Find( cat ) != KErrNotFound )
       
   191                     {
       
   192                     atLeastOneNoAutoResumeAudioPlaying = ETrue;
       
   193                     }
       
   194                 else
       
   195                     {
       
   196                     atLeastOneAutoResumeAudioPlaying = ETrue;
       
   197                     }
       
   198                 }
       
   199 
       
   200             if ( !radioPlaying )
       
   201                 {
       
   202                 // Decide audio resource availability from audio category info.
       
   203                 if ( atLeastOneNoAutoResumeAudioPlaying )
       
   204                     {
       
   205                     LOG( "Audio resources not available. Change informed." );
       
   206                     iIsAudioResourcesAvailable = EFalse;
       
   207                     iObserver.AudioAutoResumeForbiddenL();
       
   208                     }
       
   209                 else if ( !atLeastOneAutoResumeAudioPlaying )
       
   210                     {
       
   211                     if ( !iIsVoiceUiActive )
       
   212                         {
       
   213                         LOG( "Audio resources available. Change informed." );
       
   214                         iIsAudioResourcesAvailable = ETrue;
       
   215                         iObserver.AudioResourcesAvailableL();
       
   216                         }
       
   217                     else
       
   218                         {
       
   219                         LOG( "Audio resources available. Change not informed." );
       
   220                         iIsAudioResourcesAvailable = ETrue;
       
   221                         }
       
   222                     }
       
   223                 else
       
   224                     {
       
   225                     LOG( "Audio resources not available. Change not informed." );
       
   226                     iIsAudioResourcesAvailable = EFalse;
       
   227                     }
       
   228                 }
       
   229             else // audio resources are considered to be available when radio is playing
       
   230                 {
       
   231                 iIsAudioResourcesAvailable = ETrue;
       
   232                 }
       
   233             }
       
   234         }
       
   235 #endif
       
   236     }
       
   237 
       
   238 #else //__WINS__
       
   239 // ---------------------------------------------------------------------------
       
   240 // Dummy version for WINS in order to avoid compiler warnings.
       
   241 // The real implementation of function is above.
       
   242 // ---------------------------------------------------------------------------
       
   243 //
       
   244 void CRadioSystemEventDetector::HandlePropertyChangeL( const TUid& /*aCategory*/,
       
   245                                                        const TUint /*aKey*/,
       
   246                                                         const TDesC8& /*aValue*/)
       
   247     {
       
   248     }
       
   249 #endif
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 // Handling of the text property changes is done here.
       
   253 // Observer components are getting notifications in correspondence with what
       
   254 // has changed
       
   255 // ---------------------------------------------------------------------------
       
   256 //
       
   257 void CRadioSystemEventDetector::HandlePropertyChangeL( const TUid& /*aCategory*/,
       
   258                                                        const TUint /*aKey*/,
       
   259                                                        const TDesC& /*aValue*/)
       
   260     {
       
   261     }
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 // This is a callback function which is called when a P&S components returns
       
   265 // an error
       
   266 // ---------------------------------------------------------------------------
       
   267 //
       
   268 void CRadioSystemEventDetector::HandlePropertyChangeErrorL( const TUid& /*aCategory*/,
       
   269                                                             const TUint /*aKey*/,
       
   270                                                             TInt /*aError*/ )
       
   271     {
       
   272     }
       
   273 
       
   274 // ---------------------------------------------------------------------------
       
   275 //
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 TBool CRadioSystemEventDetector::IsMobileNetworkCoverage() const
       
   279     {
       
   280     LEVEL3( LOG_METHOD_AUTO );
       
   281     return iIsMobileNetworkCoverage;
       
   282     }
       
   283 
       
   284 // ---------------------------------------------------------------------------
       
   285 //
       
   286 // ---------------------------------------------------------------------------
       
   287 //
       
   288 TBool CRadioSystemEventDetector::IsNetworkCoverage() const
       
   289     {
       
   290     LEVEL3( LOG_METHOD_AUTO );
       
   291     return iIsMobileNetworkCoverage;
       
   292     }
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 TBool CRadioSystemEventDetector::IsCallActive() const
       
   299     {
       
   300     LEVEL3( LOG_METHOD_AUTO );
       
   301     return iIsCallActive;
       
   302     }
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 //
       
   306 // ---------------------------------------------------------------------------
       
   307 //
       
   308 TBool CRadioSystemEventDetector::IsAudioResourcesAvailable() const
       
   309     {
       
   310     LEVEL3( LOG_METHOD_AUTO );
       
   311     return iIsAudioResourcesAvailable;
       
   312     }