coreapplicationuis/SysAp/Src/SysApStartupController.cpp
changeset 0 2e3d3ce01487
child 21 c4cbaa4fb734
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2005-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:  CSysApStartupController implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <startupdomainpskeys.h>
       
    22 #include <startupdomaincrkeys.h>
       
    23 #include "CoreApplicationUIsPrivateCRKeys.h"
       
    24 #include <hwrmpowerstatesdkpskeys.h>
       
    25 #include "SysApStartupController.h"
       
    26 #include "SysApAppUi.h"
       
    27 #include "SysApSubscriber.h"
       
    28 #include "SysAp.hrh"
       
    29 
       
    30 //CONSTANTS
       
    31 
       
    32 // ========================== MEMBER FUNCTIONS ================================
       
    33 
       
    34 // ----------------------------------------------------------------------------
       
    35 // CSysApStartupController* CSysApStartupController::NewL()
       
    36 // ----------------------------------------------------------------------------
       
    37 
       
    38 CSysApStartupController* CSysApStartupController::NewL( CSysApAppUi& aSysApAppUi, TBool aOfflineModeSupported )
       
    39     {       
       
    40     TRACES( RDebug::Print( _L("CSysApStartupController::NewL" ) ) );
       
    41     CSysApStartupController* self = new ( ELeave ) CSysApStartupController( aSysApAppUi, aOfflineModeSupported );
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop(); //self
       
    45     return self;
       
    46     }
       
    47 
       
    48 #pragma warning( disable : 4355 ) // 'this' used in base member initializer list
       
    49 // ----------------------------------------------------------------------------
       
    50 // CSysApStartupController::CSysApStartupController( CSysApAppUi& aSysApAppUi )
       
    51 // ----------------------------------------------------------------------------
       
    52 
       
    53 CSysApStartupController::CSysApStartupController( CSysApAppUi& aSysApAppUi, TBool aOfflineModeSupported  )
       
    54     : 
       
    55     iSysApAppUi( aSysApAppUi ),
       
    56     iOfflineModeSupported( aOfflineModeSupported ),
       
    57     iFirstNormalState( ETrue ),
       
    58     iSystemStateBeingNotified( EFalse ),
       
    59     iNotifiedGlobalState( 0 )
       
    60 #ifdef SYSAP_USE_STARTUP_UI_PHASE
       
    61     , iStartupUiPhaseSubscriber( NULL ),
       
    62     iStartupUiAllDoneHandled( EFalse ),
       
    63     iStartupUiAllDone( EFalse )
       
    64 #endif // SYSAP_USE_STARTUP_UI_PHASE    
       
    65     {
       
    66     TRACES( RDebug::Print( _L("CSysApStartupController::CSysApStartupController iOfflineModeSupported = %d" ), iOfflineModeSupported ) );
       
    67     }
       
    68 #pragma warning( default : 4355 )
       
    69 
       
    70 // ----------------------------------------------------------------------------
       
    71 // CSysApStartupController::~CSysApStartupController()
       
    72 // ----------------------------------------------------------------------------
       
    73 
       
    74 CSysApStartupController::~CSysApStartupController()
       
    75     {
       
    76     TRACES( RDebug::Print( _L("~CSysApStartupController") ) );
       
    77     delete iGlobalSystemState;
       
    78 
       
    79 #ifdef SYSAP_USE_STARTUP_UI_PHASE
       
    80     delete iStartupUiPhaseSubscriber;
       
    81 #endif // SYSAP_USE_STARTUP_UI_PHASE    
       
    82     }
       
    83 
       
    84 // ----------------------------------------------------------------------------
       
    85 // CSysApStartupController::ConstructL()
       
    86 // ----------------------------------------------------------------------------
       
    87 
       
    88 void CSysApStartupController::ConstructL(  )
       
    89     {
       
    90     iGlobalSystemState = CSysApSubscriber::NewL( *this, KPSUidStartup, KPSGlobalSystemState ); // Old Shared Data name: KStateValueKey
       
    91     iGlobalSystemState->Subscribe();
       
    92     
       
    93 #ifdef SYSAP_USE_STARTUP_UI_PHASE
       
    94     iStartupUiPhaseSubscriber = CSysApSubscriber::NewL( *this, KPSUidStartup, KPSStartupUiPhase );
       
    95     iStartupUiPhaseSubscriber->Subscribe();
       
    96 #endif // SYSAP_USE_STARTUP_UI_PHASE    
       
    97     }
       
    98 
       
    99 // ----------------------------------------------------------------------------
       
   100 // CSysApStartupController::HandlePropertyChangedL
       
   101 // ----------------------------------------------------------------------------
       
   102 
       
   103 void CSysApStartupController::HandlePropertyChangedL( const TUid& aCategory, const TUint aKey )
       
   104     {
       
   105     TInt value( iSysApAppUi.StateOfProperty( aCategory, aKey ) );
       
   106     
       
   107     TRACES( RDebug::Print( _L("CSysApStartupController::HandlePropertyChangedL: aCategory=0x%x, aKey=%d, value=%d" ), 
       
   108                            aCategory, aKey, value ) );
       
   109 
       
   110     
       
   111     if ( iSysApAppUi.ResourcesFreed() )
       
   112         {
       
   113         TRACES( RDebug::Print( _L( "CSysApStartupController::HandlePropertyChangedL: discarded, already shutting down" ) ) );
       
   114         return;
       
   115         }
       
   116     
       
   117     if ( aKey == KPSGlobalSystemState )
       
   118         {
       
   119         iSystemStateBeingNotified = ETrue;
       
   120         iNotifiedGlobalState = value;
       
   121         TRAPD( err, HandleGlobalSystemStateChangeL( value ) );
       
   122         iSystemStateBeingNotified = EFalse;
       
   123         if ( err != KErrNone )
       
   124             {
       
   125             TRACES( RDebug::Print( _L("CSysApStartupController::HandlePropertyChangedL: err=%d"), err ) );
       
   126             }
       
   127         User::LeaveIfError( err );
       
   128 
       
   129         }
       
   130         
       
   131 #ifdef SYSAP_USE_STARTUP_UI_PHASE
       
   132      if ( aKey == KPSStartupUiPhase && value == EStartupUiPhaseAllDone && !iStartupUiAllDoneHandled )
       
   133         {
       
   134         iStartupUiAllDoneHandled = ETrue;
       
   135         iStartupUiAllDone = ETrue;
       
   136         iSysApAppUi.HandleUiReadyAfterBootL();    
       
   137         }
       
   138 #endif // SYSAP_USE_STARTUP_UI_PHASE        
       
   139     }
       
   140 
       
   141 // ----------------------------------------------------------------------------
       
   142 // CSysApStartupController::DoInitialSwStateCheckL()
       
   143 // ----------------------------------------------------------------------------
       
   144 
       
   145 void CSysApStartupController::DoInitialSwStateCheckL()
       
   146     {
       
   147     TRACES( RDebug::Print( _L( "CSysApStartupController::DoInitialSwStateCheckL : START" ) ) );
       
   148 
       
   149     HandlePropertyChangedL( KPSUidStartup, KPSGlobalSystemState );
       
   150 
       
   151 #ifdef SYSAP_USE_STARTUP_UI_PHASE
       
   152     HandlePropertyChangedL( KPSUidStartup, KPSStartupUiPhase );
       
   153 #endif // SYSAP_USE_STARTUP_UI_PHASE
       
   154 
       
   155     TRACES( RDebug::Print( _L( "CSysApStartupController::DoInitialSwStateCheckL : END" ) ) );
       
   156     }
       
   157     
       
   158 // ----------------------------------------------------------------------------
       
   159 // CSysApStartupController::HandleGlobalSystemStateChangeL
       
   160 // ----------------------------------------------------------------------------
       
   161 
       
   162 void CSysApStartupController::HandleGlobalSystemStateChangeL( TInt aValue )
       
   163     {
       
   164     TBool normalState(EFalse);
       
   165 
       
   166     switch ( aValue )
       
   167         {
       
   168         case ESwStateNormalRfOn:
       
   169             normalState = ETrue;
       
   170             if ( iOfflineModeSupported && (iSysApAppUi.OfflineModeActive() || iFirstNormalState) )
       
   171                 {
       
   172                 TBool changeProfile = ETrue;
       
   173                 
       
   174                 // during boot, allow profile change only if switching from offline to online state
       
   175                 if ( iFirstNormalState && !iSysApAppUi.OfflineModeActive() )
       
   176                     {
       
   177                     changeProfile = EFalse;
       
   178                     }
       
   179                     
       
   180                 // Offline/Online mode changed by some other application (or boot)
       
   181                 iSysApAppUi.GoOnlineL( changeProfile );
       
   182                 }
       
   183 
       
   184             break;
       
   185         case ESwStateNormalRfOff:
       
   186             normalState = ETrue;
       
   187             if ( iOfflineModeSupported && (!iSysApAppUi.OfflineModeActive() || iFirstNormalState) )
       
   188                 {
       
   189                 // Offline/Online mode changed by some other application (or boot)
       
   190                 iSysApAppUi.GoOfflineL();
       
   191                 }
       
   192             break;
       
   193         case ESwStateNormalBTSap:
       
   194             // This mode can conceivably only be set by SysAp, so ignore.
       
   195             break;
       
   196         case ESwStateCharging:
       
   197             iSysApAppUi.DoStateChangedL(RStarterSession::ECharging);     
       
   198             break;
       
   199         case ESwStateAlarm:
       
   200             iSysApAppUi.DoStateChangedL(RStarterSession::EAlarm);     
       
   201             break;
       
   202 #ifdef SYSAP_USE_STARTUP_UI_PHASE
       
   203         case ESwStateEmergencyCallsOnly:
       
   204             // idle state UI initializations are not allowed
       
   205             iStartupUiAllDoneHandled = ETrue;
       
   206             iStartupUiAllDone = EFalse;
       
   207             break;
       
   208 #endif // SYSAP_USE_STARTUP_UI_PHASE
       
   209         default:
       
   210             break;
       
   211         }
       
   212 
       
   213     if ( iFirstNormalState && normalState )
       
   214         {      
       
   215         iSysApAppUi.DoStateChangedL(RStarterSession::ENormal);
       
   216         User::ResetInactivityTime();
       
   217         iFirstNormalState = EFalse;              
       
   218         }
       
   219     }
       
   220 
       
   221 // ----------------------------------------------------------------------------
       
   222 // CSysApStartupController::GlobalStateChangeAllowed()
       
   223 // ----------------------------------------------------------------------------
       
   224 
       
   225 TBool CSysApStartupController::GlobalStateChangeAllowed( const RStarterSession::TGlobalState aState ) const
       
   226     {
       
   227     TRACES( RDebug::Print( _L( "CSysApStartupController::GlobalStateChangeAllowed : aState=%d, iSystemStateBeingNotified=%d, iNotifiedGlobalState=%d" ),
       
   228                            aState, iSystemStateBeingNotified, iNotifiedGlobalState ) );
       
   229     
       
   230     // Redundant state changes are filtered out when a global state change is ongoing
       
   231     if ( iSystemStateBeingNotified ) // KPSGlobalSystemState notification currently handled 
       
   232         {
       
   233         if ( aState == RStarterSession::ENormal && iNotifiedGlobalState == ESwStateNormalRfOn 
       
   234             || aState == RStarterSession::EOffline && iNotifiedGlobalState == ESwStateNormalRfOff )
       
   235             {
       
   236             return EFalse;
       
   237             }
       
   238         }
       
   239     
       
   240     return ETrue;
       
   241     }
       
   242 
       
   243 #ifdef SYSAP_USE_STARTUP_UI_PHASE
       
   244 // ----------------------------------------------------------------------------
       
   245 // CSysApStartupController::UiReady()
       
   246 // ----------------------------------------------------------------------------
       
   247 
       
   248 TBool CSysApStartupController::UiReady() const
       
   249     {
       
   250     return iStartupUiAllDone;    
       
   251     }
       
   252 #endif // SYSAP_USE_STARTUP_UI_PHASE
       
   253 
       
   254 // End of File
       
   255