coreapplicationuis/SysAp/Src/SysApAppUi.cpp
changeset 46 eea20ed08f4b
parent 29 6a787171e1de
child 51 50b444048a8d
equal deleted inserted replaced
40:951aeeb3da43 46:eea20ed08f4b
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  CSysApAppUi implementation.
    14 * Description:  CSysApAppUi implementation.
    15 *
    15 *
    16 */
    16 */
    17 
       
    18 
       
    19 // INCLUDES
    17 // INCLUDES
    20 
    18 
    21 #include <avkon.hrh>
    19 #include <startupdomainpskeys.h>
    22 #include <avkon.rsg>
    20 #include "sysapappui.h"
    23 #include <eikon.hrh>
    21 #include "coreapplicationuisprivatepskeys.h"
    24 #include <apgwgnam.h>
    22 #include <HbDeviceMessageBoxSymbian.h>
    25 #include <eiksrv.h>
    23 //#include <hbdevicepowermenusymbian.h>
    26 #include <eikdll.h>
    24 #include <sacls.h>
    27 #include <AknSmallIndicator.h>
    25 #include <featmgr.h>
    28 #include <AknBatteryNotify.h>
    26 #include <DevEncProtectedPSKey.h>
    29 #include <AknSignalNotify.h>
    27 #include <ctsydomainpskeys.h>
    30 #include <AknGlobalNote.h>
    28 #include <secuisystemlock.h>
    31 #include <AknGlobalListQuery.h>
    29 #include <apgtask.h>
    32 #include <aknsoundsystem.h>
       
    33 #include <apgcli.h>
       
    34 
       
    35 #include <hwrmpowerstatesdkpskeys.h>
    30 #include <hwrmpowerstatesdkpskeys.h>
    36 #include <hwrmdomainpskeys.h>
    31 #include <wlaninternalpskeys.h> 
    37 
    32 #include <HbDeviceNotificationDialogSymbian.h>
    38 #include <PSVariables.h>
    33 //#include <HbDeviceInputDialogSymbian.h>
    39 #include "coreapplicationuisprivatepskeys.h"
    34 #include <hbsymbianvariant.h>
    40 #include <ctsydomainpskeys.h>
    35 //#include <hbtextresolversymbian.h>
    41 #include <startupdomainpskeys.h>
    36 #include <UikonInternalPSKeys.h>
    42 #include <startupdomaincrkeys.h>
    37 
    43 
    38 //#include "SysApWsClient.h"
    44 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
    39 #include "SysApFeatureManager.h"
    45   #include <ASShdAlarm.h>
    40 #include "SysApNspsHandler.h"
    46 #else
       
    47   #include <asshddefs.h>
       
    48   #include <ASShdAlarmCal.h>
       
    49   #include <asshdalarm.h>
       
    50 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS
       
    51 
       
    52 #include <MProfileEngine.h>
       
    53 #include <MProfileName.h>
       
    54 #include <MProfilesNamesArray.h>
       
    55 #include <MProfile.h>
       
    56 #include <StringLoader.h>
       
    57 #include <secuisystemlock.h>
       
    58 #include <secui.h>
       
    59 #include <settingsinternalcrkeys.h>
       
    60 
       
    61 #include <AknNotifierController.h>
       
    62 #include <eikappui.h>
       
    63 #include <es_enum.h>
       
    64 #include <data_caging_path_literals.hrh>
       
    65 #include <eikon.hrh>
       
    66 
       
    67 #include "SysApSimChanged.h"
       
    68 
       
    69 #include <SysAp.rsg>
       
    70 #include "SysApLightsController.h"
       
    71 
       
    72 #include "SysApPubSubObserver.h"
    41 #include "SysApPubSubObserver.h"
    73 #include "SysApProfileObserver.h"
    42 #include "sysapdefaultkeyhandler.h"
    74 
    43 #include "SysApStartupController.h"
       
    44 #include "MSysApOfflineModeController.h"
       
    45 #include "SysApCenRepController.h"
    75 #include "sysapcenreplightsettingsobserver.h"
    46 #include "sysapcenreplightsettingsobserver.h"
    76 #include "SysApCenRepLogsObserver.h"
    47 #include "SysApCenRepLogsObserver.h"
    77 #include "SysApCenRepBTObserver.h"
    48 #include "SysApCenRepBTObserver.h"
    78 #include "SysApCenRepHacSettingObserver.h"
    49 #include "SysApCenRepHacSettingObserver.h"
    79 #include "SysApCenRepController.h"
    50 #include "sysapaudioroutingobserver.h"
    80 #include "coreapplicationuisprivatecrkeys.h"
    51 #include "sysapbatteryinfocontroller.h"
    81 #include "coreapplicationuisprivatepskeys.h"
    52 #include "SysApSimChanged.h"
    82 #include <UikonInternalPSKeys.h>
    53 #include "MSysApBtSapController.h"
    83 
    54 #include "MSysApBtController.h"
    84 #include "SysApStartupController.h"
    55 #include "MSysApUsbIndicator.h"
    85 #include "SysApConnectionMonitorObserver.h"
    56 //#include <hbindicatorsymbian.h>
    86 #include "SysApPowerKeyMenuObserver.h"
    57 //#include <psmclient.h>
    87 #include "SysApSsSettingsObserver.h"
    58 //#include <psmsettings.h>
    88 #include "SysApAppUi.h"
    59 #include "sysapkeymanagement.h"
    89 #include "SysApShutdownImage.h"
    60 #include "SysApShutdownImage.h"
    90 #include "SysApEtelConnector.h"
       
    91 
       
    92 #include "SysApApp.h"
       
    93 #include "SysApMsgSimMemLowQuery.h"
       
    94 #include "SysApNspsHandler.h"
       
    95 #include "SysApWaitNote.h"
       
    96 #include "SysApConfirmationQuery.h"
       
    97 #include "SysApFeatureManager.h"
       
    98 #include "SysApSubscriber.h"
       
    99 #include "MSysApOfflineModeController.h"
       
   100 #include "MSysApBtController.h"
       
   101 #include "MSysApBtSapController.h"
       
   102 #include "MSysApLocationPrivacyIndicator.h"
       
   103 #include "MSysApUsbIndicator.h"
       
   104 
       
   105 #include <sysap.mbg>
       
   106 
       
   107 #include "SysApShutdownAnimation.h"
       
   108 
       
   109 //#include <hwrmfmtx.h>
       
   110 //#include <hwrmfmtxdomainpskeys.h>
       
   111 //#include <hwrmfmtxdomaincrkeys.h>
       
   112 //#include "sysapcenrepfmtxobserver.h"
       
   113 
       
   114 #include "SysApKeySndHandler.h"
    61 #include "SysApKeySndHandler.h"
   115 
    62 
   116 #include <ir_sock.h> // KIrdaPropertyCategory // KIrdaStatus
    63 #include <settingsinternalcrkeys.h>
   117 
    64 #include <keyguardaccessapi.h>
   118 #include <networkhandlingdomainpskeys.h>
    65 #include <eikdef.h>
   119 
    66 #include <eikenv.h>
   120 // POC launching
    67 
   121 #include <AiwServiceHandler.h>
    68 class CHbSymbianVariant;
   122 #include <AiwPoCParameters.h>
       
   123 
       
   124 #include <sacls.h>  // KUidPhonePwr
       
   125 
       
   126 #include <wlaninternalpskeys.h>  // WLan indicator
       
   127 
       
   128 #include <ecom/ecom.h>
       
   129 #include "sysapkeymanagement.h"
       
   130 
       
   131 #include "SysApMediatorObserver.h"
       
   132 
       
   133 #include <SecondaryDisplay/SecondaryDisplaySysApAPI.h>
       
   134 #include "aknSDData.h"
       
   135 
       
   136 #include <AknTaskList.h>
       
   137 #include <layoutmetadata.cdl.h>
       
   138 
       
   139 #include "sysapdefaultkeyhandler.h"
       
   140 #include "sysapaudioroutingobserver.h"
       
   141 #include "sysapcenrepcallforwardingobserver.h"
       
   142 #include "sysapcenrepmsgwaitingobserver.h"
       
   143 
       
   144 #ifdef RD_MULTIPLE_DRIVE
       
   145  #include "sysapdrivelist.h"
       
   146  #include "sysapdriveunlockhandler.h"
       
   147  #include "sysapdriveejecthandler.h"
       
   148 #endif // RD_MULTIPLE_DRIVE
       
   149 
       
   150 #include "sysappsmcontroller.h"
       
   151 #include "sysapbatteryinfocontroller.h"
       
   152 
       
   153 #include <keylockpolicyapi.h>
       
   154 
       
   155 #include <UsbWatcherInternalPSKeys.h> // USB transfer modes
       
   156 #include <usbpersonalityids.h>
       
   157 #include <smsuaddr.h>
       
   158 #include <featmgr.h>
       
   159 #include <DevEncProtectedPSKey.h>
       
   160 
       
   161 // CONSTANTS
       
   162 const TInt KPowerKeyMenuSelectionCancelled( -1 );
       
   163 const TInt KPowerKeyMenuSelectionSwitchOff( 0 );
       
   164 const TInt KModifierMask( 0 );
    69 const TInt KModifierMask( 0 );
   165 const TInt KDelayBeforeShuttingDownInAlarmAndChargingStates( 500000 );
       
   166 const TInt KDelayBeforeShowingGprsSuspendedNote( 500000 );
       
   167 const TInt KDelayBeforeNextScanningRound( 1000000 );
       
   168 const TInt KActiveProfile( 0 ); //The value of ActiveProfile for accessory default profile selection in GS/SD.
       
   169 const TInt KProfileListInitialIndex( 0 );
       
   170 const TInt KMaxProfileNameLength( 64 );
       
   171 const TInt KTimeToShowShutdownNote( 2000000 ); //2 seconds time for Goodbye note to show before being shutdown
       
   172 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
   173 const TInt KCoefficientToMakeMicroToMilliSeconds = 1000;
       
   174 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
   175 
       
   176 /* ENABLE ANIMATION: Add id of background image.
       
   177    Example: const TInt KBackgroundImageID = EMbmSysapQgn_graf_startup_bg;
       
   178    If there is no image defined, clear screen is used.*/
       
   179 const TInt KBackgroundImageID = 0;
       
   180 #ifndef RD_MULTIPLE_DRIVE
       
   181 const TInt32 KAutolockAppUid = 0x100059B5;
       
   182 const TInt KFileManagerAppUid = 0x101F84EB;
       
   183 #endif // RD_MULTIPLE_DRIVE
       
   184 const TInt KCoefficientKhzToMhz = 1000;
       
   185 const TInt KDecimalsInMhzFrequency = 2;
       
   186 
       
   187 _LIT_SECURITY_POLICY_PASS(KAlwaysPassPolicy);
    70 _LIT_SECURITY_POLICY_PASS(KAlwaysPassPolicy);
   188 _LIT_SECURITY_POLICY_C1(KWriteDeviceDataPolicy, ECapabilityWriteDeviceData);
    71 _LIT_SECURITY_POLICY_C1(KWriteDeviceDataPolicy, ECapabilityWriteDeviceData);
       
    72 const TInt KDelayBeforeNextScanningRound( 1000000 );
       
    73 /*
       
    74 _LIT(KPsmPlugin,"com.nokia.hb.powersavemodeplugin/1.0");
       
    75 _LIT(KPsm,"PSM");
       
    76 _LIT(KCharging,"Charging");
       
    77 _LIT(KPsmlocalisationfile, "powermanagement_");
       
    78 _LIT(KtsfilePath, "z:/resource/qt/translations/");
       
    79 _LIT(KlowbatteryIcon,"qtg_small_bt_low_battery.svg");
       
    80 _LIT(KbatteryFullIcon,"qtg_status_battery.svg");
       
    81 
       
    82 */
   189 
    83 
   190 // ============================ MEMBER FUNCTIONS ==============================
    84 // ============================ MEMBER FUNCTIONS ==============================
   191 
    85 
   192 // ----------------------------------------------------------------------------
    86 // ----------------------------------------------------------------------------
   193 // CSysApAppUi::CSysApAppUi()
    87 // CSysApAppUi::CSysApAppUi()
   194 // ----------------------------------------------------------------------------
    88 // ----------------------------------------------------------------------------
   195 
    89 
   196 CSysApAppUi::CSysApAppUi() :
    90 CSysApAppUi::CSysApAppUi()
   197     iSysApCenRepLogsObserver( NULL ),
    91     :iSysApShutdownImage(NULL),
   198     iSysApCenRepHacSettingObserver( NULL ),
    92      iPowerMenuDialog(NULL),
   199     iSysApPowerKeyMenuObserver( NULL ),
    93      iDeviceLockEnabled(EFalse),
   200     iSysApShutdownImage( NULL ),
    94      iKeyLockEnabled(EFalse),
   201     iSysApConfirmationQuery( NULL ),
    95      iPowerKeyPopupMenuActive(EFalse),
   202     iSysApConfirmationQueryForRestart( NULL ),
    96      iResourcesFreed (EFalse),
   203     iSignalNotify( NULL ),
    97      iShutdownStarted (EFalse),
   204 #ifndef RD_MULTIPLE_DRIVE
    98      iSysApAudioRoutingObserver (NULL),
   205     iMemoryCardDialog( 0 ),
    99      iSysApBatteryInfoController (NULL),
   206 #endif // RD_MULTIPLE_DRIVE
   100      iSysApPsmController(NULL),
   207     iProfileNote( NULL ),
   101      iSapTimer (NULL),
   208     iProfileNoteId( 0 ),
   102      iSysApCenRepLogsObserver (NULL),
   209     iPowerKeyPopupMenuActive( EFalse ),
   103      iSysApUsbIndicatorController(NULL),
   210     iDisablePowerkeyMenu( EFalse ),
   104      iKeyguardController (NULL),
   211     iDeviceLockEnabled( EFalse ),
   105      iKeyLockOnBeforeCall (EFalse),
   212     iKeyLockEnabled( EFalse ),
   106      iCheckLongPowerKeyEvent (EFalse)
   213     iShowkeypadActivatedNoteAfterSoftReject( EFalse ),
   107 	{
   214     iEmergencyCallActive( EFalse ),
   108 	TRACES( RDebug::Print( _L("CSysApAppUi::CSysApAppUi()") ) );
   215     iSimChangedDone( EFalse ),
       
   216     iResourcesFreed( EFalse ),
       
   217 #ifndef RD_MULTIPLE_DRIVE
       
   218     iHideFirstBeep( ETrue ),
       
   219 #endif // RD_MULTIPLE_DRIVE
       
   220     iShutdownStarted( EFalse ),
       
   221     iIgnoreAccessorySpecificProfileChanges( ETrue ),
       
   222     iAccessoryJustConnected( EFalse ),
       
   223     iHandleNextProfileEvent( ETrue ),
       
   224     iActivateBt( EFalse ),
       
   225     iDeactivateBt( EFalse ),
       
   226     iGprsActivated( EFalse ),
       
   227     iGprsSuspended( EFalse ),
       
   228     iCallActivated( EFalse ),
       
   229     iGprsSuspendedNoteShown( EFalse ),
       
   230     iMMCEjectUsed( EFalse ),
       
   231 #ifndef RD_MULTIPLE_DRIVE
       
   232     iMMCPowerMenuEjectUsed( EFalse ),
       
   233     iMMCInserted( EFalse ),
       
   234 #endif // RD_MULTIPLE_DRIVE
       
   235     iTimer( NULL ),
       
   236     iSapTimer( NULL ),
       
   237 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
   238     iAnimTimer( NULL ),
       
   239 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
   240     iSysApTimer( NULL ),
       
   241 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
   242     iAnimationShowingTime( 0 ),
       
   243 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
   244     iShutdownContinued( EFalse ),
       
   245     iSysApAudioRoutingObserver( NULL ),
       
   246     iSysApCenRepCallForwardingObserver( NULL ),
       
   247     iSysApCenRepMsgWaitingObserver( NULL ),
       
   248 	iKeyBoardRepeatCount(-1)
       
   249     {
       
   250     TRACES( RDebug::Print( _L("CSysApAppUi::CSysApAppUi()") ) );
       
   251     }
   109     }
   252 
   110 
   253 // ----------------------------------------------------------------------------
   111 // ----------------------------------------------------------------------------
   254 // CSysApAppUi::ConstructL()
   112 // CSysApAppUi::ConstructL()
   255 // ----------------------------------------------------------------------------
   113 // ----------------------------------------------------------------------------
   256 
   114 
   257 void CSysApAppUi::ConstructL()
   115 void CSysApAppUi::ConstructL()
   258     {
   116     {
   259     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: START") ) );
   117     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: START") ) );
   260     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying BaseConstructL( EAknEnableSkin )") ) );
   118     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying BaseConstructL()") ) );
   261     BaseConstructL( EAknEnableSkin );
   119     BaseConstructL();
   262     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: BaseConstructL() OK") ) );
   120     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: BaseConstructL() OK") ) );
   263     
   121 
   264    
       
   265 
       
   266     /*SysAp is set as system application (Symbian terminology). This means some special privilege compared
       
   267       to other applications. For example it does not get closed when system is asked to close applications
       
   268     */
       
   269     iEikonEnv->SetSystem( ETrue );
   122     iEikonEnv->SetSystem( ETrue );
   270 
   123 
   271     iEikonEnv->WsSession().ComputeMode( RWsSession::EPriorityControlDisabled );
   124     iEikonEnv->WsSession().ComputeMode( RWsSession::EPriorityControlDisabled );
   272 
   125     
   273     static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds()->PushContextL( R_AVKON_SILENT_SKEY_LIST );
       
   274 
       
   275     RThread().SetProcessPriority( EPriorityForeground );
   126     RThread().SetProcessPriority( EPriorityForeground );
   276 
   127     
   277     /*SysAp does not have any visible Status pane. An exception will be Charging state
       
   278     where SysAp shows Status Pane as it is the only running application.
       
   279     */
       
   280     TInt mode;
   128     TInt mode;
   281     User::LeaveIfError( RProperty::Get( KPSUidStartup, KPSGlobalStartupMode, mode ) );
   129     User::LeaveIfError( RProperty::Get( KPSUidStartup, KPSGlobalStartupMode, mode ) );
   282 
   130     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: KPSGlobalStartupMode = %d"), mode ) );
   283     if( mode == EStartupModeCharging || mode == EStartupModeAlarm )
   131     
   284         {
   132     //SysAp needs to capture PowerKey events because it handles all functionality related to that
   285         SetStatusPaneLayoutL(
   133     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CEikApplication::RootWin()") ) );
   286             mode == EStartupModeCharging ? ESysApCharging : ESysApAlarm );
   134     RWindowGroup groupWin = iCoeEnv->RootWin();
   287 
   135     User::LeaveIfError ( iCapturedEKeyPowerOff = groupWin.CaptureKey( EKeyPowerOff, KModifierMask, KModifierMask ) );
   288         SetKeyEventFlags(
   136     User::LeaveIfError ( iCapturedEKeyPowerOffUpAndDowns = groupWin.CaptureKeyUpAndDowns( EStdKeyDevice2, KModifierMask, KModifierMask ) );
   289             CAknAppUiBase::EDisableSendKeyShort |
   137      
   290             CAknAppUiBase::EDisableSendKeyLong );
   138     TRACES ( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApDefaultKeyHandler::NewL()") ) );
   291         }
   139     iSysApDefaultKeyHandler = CSysApDefaultKeyHandler::NewL(*this);
   292     else
   140     
   293         {
       
   294         SetStatusPaneLayoutL( ESysApNormal );
       
   295         }
       
   296 
       
   297     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApFeatureManager::NewL()") ) );
       
   298     iSysApFeatureManager = CSysApFeatureManager::NewL();
       
   299 
       
   300     // Setup USB charging detector
       
   301     iSysApUsbChargerDetector.EnableUsbCharging(
       
   302         iSysApFeatureManager->Supported( KSysApFeatureIdChargerReminderNotes ) &&
       
   303         iSysApFeatureManager->Supported( KSysApFeatureIdUsbChargingWithoutReminderNotes ) );
       
   304 
       
   305     // Construct notifiers that are used frequently or in OOM situations.
       
   306     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CAknBatteryNotify::NewL()") ) );
       
   307     iBatteryNotify = CAknBatteryNotify::NewL();
       
   308     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CAknSignalNotify::NewL()") ) );
       
   309     iSignalNotify = CAknSignalNotify::NewL();
       
   310     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying new ( ELeave ) CSysApMsgSimMemLowQuery") ) );
       
   311     iSysApMsgSimMemLowQuery = new( ELeave ) CSysApMsgSimMemLowQuery( iSysApFeatureManager->CoverDisplaySupported() );
       
   312 
       
   313     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApPubSubObserver::NewL()") ) );
       
   314     iSysApPubSubObserver = CSysApPubSubObserver::NewL( *this );
       
   315     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsPoCIndicator, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
       
   316     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsPoCIndicator, ECoreAppUIsPocIndicatorUninitialized );
       
   317     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsPoCMissedIndicator, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
       
   318     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsPoCMissedIndicator, ECoreAppUIsPocMissedIndicatorUninitialized );
       
   319     
       
   320     // initial value won't be set to KCoreAppUIsUSBFileTransfer, because UsbMscPersonality-plugin may also define it if USB cable is connected during boot
       
   321     // remove this definition after all clients have taken the USB personality ids in use
       
   322     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsUSBFileTransfer, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
       
   323     
       
   324     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsVideoSharingIndicator, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
       
   325     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsVideoSharingIndicator, ECoreAppUIsVideoSharingIndicatorUninitialized );
       
   326 
       
   327     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApAccessoryObserver::NewL()") ) );
       
   328     iSysApAccessoryObserver = CSysApAccessoryObserver::NewL( *this );
       
   329 
       
   330     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApCenRepController::NewL()") ) );
       
   331     iSysApCenRepController = CSysApCenRepController::NewL();
       
   332 
       
   333     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApCenRepLightSettingsObserver::NewL") ) );
       
   334     iSysApCenRepLightSettingsObserver = CSysApCenRepLightSettingsObserver::NewL( *this );
       
   335 
       
   336     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApCenRepBtObserver::NewL") ) );
       
   337     iSysApCenRepBtObserver = CSysApCenRepBtObserver::NewL( *this );
       
   338 
       
   339 /*    if ( iSysApFeatureManager->FmTxSupported() )
       
   340         {
       
   341         TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApCenRepFmTxObserver::NewL") ) );        
       
   342         iSysApCenRepFmTxObserver = CSysApCenRepFmTxObserver::NewL( *this );    
       
   343         }
       
   344 */
       
   345     // Define P&S keys "owned" by SysAp
   141     // Define P&S keys "owned" by SysAp
   346     RProperty::Define( KPSUidUikon, KUikMMCInserted, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   142     RProperty::Define( KPSUidUikon, KUikMMCInserted, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   347     //initially assuming that the memory card is not inserted
   143     //initially assuming that the memory card is not inserted
   348     RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
   144     RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
   349     TDriveInfo driveInfo;
   145     TDriveInfo driveInfo;
   350     TInt driveNumber; 
   146     TInt driveNumber; 
   351     TInt err;    
   147     TInt err;    
   352     RFs& fileServer = iEikonEnv->FsSession();  
   148     RFs& fileServer = iEikonEnv->FsSession();  
   353     for ( driveNumber = EDriveD; driveNumber < EDriveZ; driveNumber++ )
   149     for ( driveNumber = EDriveD; driveNumber < EDriveZ; driveNumber++ )
   354          {
   150          {
   355 	  err = fileServer.Drive(driveInfo,driveNumber);
   151       err = fileServer.Drive(driveInfo,driveNumber);
   356           if(driveNumber == EDriveF && err == KErrNone && driveInfo.iType == EMediaHardDisk &&  driveInfo.iDriveAtt & KDriveAttRemovable)     
   152           if(driveNumber == EDriveF && err == KErrNone && driveInfo.iType == EMediaHardDisk &&  driveInfo.iDriveAtt & KDriveAttRemovable)     
   357         	{     
   153             {     
   358         	TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: err = %d, driveInfo.iType = %d, driveInfo.iDriveAtt %d, KDriveAttRemovable = %d "),err,driveInfo.iType,driveInfo.iDriveAtt,KDriveAttRemovable) );     
   154             TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: err = %d, driveInfo.iType = %d, driveInfo.iDriveAtt %d, KDriveAttRemovable = %d "),err,driveInfo.iType,driveInfo.iDriveAtt,KDriveAttRemovable) );     
   359         	RProperty::Set( KPSUidUikon, KUikMMCInserted, 1 );
   155             RProperty::Set( KPSUidUikon, KUikMMCInserted, 1 );
   360                 break;  // Memory card drive found...     
   156                 break;  // Memory card drive found...     
   361       		}
   157             }
   362          } 
   158          }
       
   159            
       
   160     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApFeatureManager::NewL()") ) );
       
   161     iSysApFeatureManager = CSysApFeatureManager::NewL();
       
   162     
       
   163     // Setup USB charging detector
       
   164      iSysApUsbChargerDetector.EnableUsbCharging(
       
   165          iSysApFeatureManager->Supported( KSysApFeatureIdChargerReminderNotes ) &&
       
   166          iSysApFeatureManager->Supported( KSysApFeatureIdUsbChargingWithoutReminderNotes ) );
       
   167     
       
   168     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApPubSubObserver::NewL()") ) );
       
   169     iSysApPubSubObserver = CSysApPubSubObserver::NewL( *this );
       
   170 
       
   171     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsPoCIndicator, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
       
   172     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsPoCIndicator, ECoreAppUIsPocIndicatorUninitialized );
       
   173     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsPoCMissedIndicator, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
       
   174     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsPoCMissedIndicator, ECoreAppUIsPocMissedIndicatorUninitialized );
       
   175     
       
   176     // initial value won't be set to KCoreAppUIsUSBFileTransfer, because UsbMscPersonality-plugin may also define it if USB cable is connected during boot
       
   177     // remove this definition after all clients have taken the USB personality ids in use
       
   178     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsUSBFileTransfer, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
       
   179     
       
   180     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsVideoSharingIndicator, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
       
   181     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsVideoSharingIndicator, ECoreAppUIsVideoSharingIndicatorUninitialized );
   363 
   182 
   364     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsHideAlarm, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   183     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsHideAlarm, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   365     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsDisableKeyguard, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   184     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsDisableKeyguard, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   366     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsSoftReject, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   185     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsSoftReject, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   367     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsUipInd, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   186     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsUipInd, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   379     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsMtvDvbhStatus, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   198     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsMtvDvbhStatus, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   380     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsNewEmailStatus, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   199     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsNewEmailStatus, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   381 
   200 
   382     // Initialize P&S keys "owned" by SysAp
   201     // Initialize P&S keys "owned" by SysAp
   383     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsHideAlarm, ECoreAppUIsHideAlarmUninitialized );
   202     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsHideAlarm, ECoreAppUIsHideAlarmUninitialized );
   384 
   203     
       
   204     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApAccessoryObserver::NewL()") ) );
       
   205     iSysApAccessoryObserver = CSysApAccessoryObserver::NewL( *this );
       
   206     
       
   207     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApCenRepController::NewL()") ) );
       
   208     iSysApCenRepController = CSysApCenRepController::NewL();
       
   209     
       
   210     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApCenRepLightSettingsObserver::NewL") ) );
       
   211     iSysApCenRepLightSettingsObserver = CSysApCenRepLightSettingsObserver::NewL( *this );
       
   212     
       
   213     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApCenRepBtObserver::NewL") ) );
       
   214     iSysApCenRepBtObserver = CSysApCenRepBtObserver::NewL( *this );
       
   215     
   385     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApStartupController::NewL()") ) );
   216     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApStartupController::NewL()") ) );
   386     iSysApStartupController = CSysApStartupController::NewL( *this, iSysApFeatureManager->OfflineModeSupported() );
   217     iSysApStartupController = CSysApStartupController::NewL( *this, iSysApFeatureManager->OfflineModeSupported() );
   387 
   218 
       
   219     iActiveProfileBeforeOfflineMode = iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApProfileBeforeOfflineMode );    
       
   220            
       
   221     iSysApFeatureManager->FeatureVariationCheckDone();        
       
   222     // iHbIndicatorSymbian = CHbIndicatorSymbian::NewL();
       
   223     
   388     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApLightsController::NewL()") ) );
   224     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApLightsController::NewL()") ) );
   389     iSysApLightsController = CSysApLightsController::NewL( *this,
   225     iSysApLightsController = CSysApLightsController::NewL( *this,
   390                                                            iSysApCenRepLightSettingsObserver->GetLightsTimeout(),
   226                                                            iSysApCenRepLightSettingsObserver->GetLightsTimeout(),
   391                                                            iSysApFeatureManager->CoverDisplaySupported() );
   227                                                            iSysApFeatureManager->CoverDisplaySupported() );
   392 
   228             
   393     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApEtelConnector::NewL()") ) );
       
   394     iSysApEtelConnector = CSysApEtelConnector::NewL( *this );
       
   395 
       
   396     //SysAp needs to capture PowerKey events because it handles all functionality related to that
       
   397     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CEikApplication::RootWin()") ) );
       
   398     RWindowGroup groupWin = iCoeEnv->RootWin();
       
   399     User::LeaveIfError ( iCapturedEKeyPowerOff = groupWin.CaptureKey( EKeyPowerOff, KModifierMask, KModifierMask ) );
       
   400     User::LeaveIfError ( iCapturedEKeyPowerOffUpAndDowns = groupWin.CaptureKeyUpAndDowns( EStdKeyDevice2, KModifierMask, KModifierMask ) );
       
   401 
       
   402     TRACES ( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApDefaultKeyHandler::NewL()") ) );
       
   403     iSysApDefaultKeyHandler = CSysApDefaultKeyHandler::NewL( *this );
       
   404 
       
   405 
       
   406     if ( iSysApFeatureManager->GripNotSupported() )
       
   407         {
       
   408         RProperty::Set( KPSUidHWRM, KHWRMGripStatus, EPSHWRMGripOpen );
       
   409         }
       
   410 
       
   411 #ifndef RD_MULTIPLE_DRIVE
       
   412     if ( iSysApFeatureManager->MmcSupported() )
       
   413         {
       
   414         iSysApMMCObserver = CSysApMMCObserver::NewL( this, &iEikonEnv->FsSession(), iSysApFeatureManager->MmcHotSwapSupported() );
       
   415         }
       
   416 #else // RD_MULTIPLE_DRIVE
       
   417     iSysApDriveList = CSysApDriveList::NewL( iEikonEnv->FsSession() );
       
   418     if ( iSysApFeatureManager->MmcSupported() )
       
   419         {
       
   420         iSysApMMCObserver = CSysApMMCObserver::NewL(
       
   421             iEikonEnv->FsSession(), *iSysApDriveList, *this, iSysApFeatureManager->MmcHotSwapSupported() );
       
   422         iSysApDriveUnlockHandler = CSysApDriveUnlockHandler::NewL(
       
   423             *iSysApDriveList, *this, iSysApFeatureManager->MemoryCardLockSupported() );
       
   424         iSysApDriveEjectHandler = CSysApDriveEjectHandler::NewL(
       
   425             *iSysApDriveList, *this, iEikonEnv->FsSession() );
       
   426         }
       
   427 #endif // RD_MULTIPLE_DRIVE
       
   428 
       
   429     //Instantiate the KEF plugin manager
       
   430 	//Trap constuction, since Sysap may live without iSysApKeyManagement
       
   431     TRAPD(keyManagementErr, iSysApKeyManagement=CSysApKeyManagement::NewL(CCoeEnv::Static()->RootWin(), *this));
       
   432 
       
   433     if (keyManagementErr)
       
   434     	{
       
   435     	TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL : CSysApKeyManagement::NewL returns error=%d"), keyManagementErr ) );
       
   436     	}
       
   437 
       
   438     iSysApFeatureManager->FeatureVariationCheckDone();
       
   439 
       
   440     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApProfileObserver::NewL()") ) );
       
   441     iSysApProfileObserver = CSysApProfileObserver::NewL( *this );
       
   442 
       
   443     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL : trying MProfileEngine* CreateProfileEngineL()") ) );
       
   444     iProfileEngine = CreateProfileEngineL( &( iEikonEnv->FsSession() ) );
       
   445 
       
   446     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL : trying CreateSysApOfflineModeControllerL()") ) );
   229     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL : trying CreateSysApOfflineModeControllerL()") ) );
   447     iSysApOfflineModeController = CreateSysApOfflineModeControllerL( *this );
   230     iSysApOfflineModeController = CreateSysApOfflineModeControllerL( *this );
   448 
   231     
   449     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL : trying DoInitialSwStateCheckL()") ) );
   232     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL : trying DoInitialSwStateCheckL()") ) );
   450     iSysApStartupController->DoInitialSwStateCheckL();
   233     iSysApStartupController->DoInitialSwStateCheckL();
   451 
   234     
   452     iActiveProfileBeforeOfflineMode = iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApProfileBeforeOfflineMode );
   235     TRACES( RDebug::Print( _L("CCSysApAppUi::ConstructL  trying CSysApCenRepHacSettingObserver::NewL") ) );
   453 
   236     iSysApCenRepHacSettingObserver = CSysApCenRepHacSettingObserver::NewL( *this ); 
       
   237     
       
   238     //Instantiate the KEF plugin manager
       
   239     //Trap constuction, since Sysap may live without iSysApKeyManagement
       
   240     TRAPD(keyManagementErr, iSysApKeyManagement=CSysApKeyManagement::NewL(CCoeEnv::Static()->RootWin(), *this));
       
   241 
       
   242     if (keyManagementErr)
       
   243         {
       
   244         TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL : CSysApKeyManagement::NewL returns error=%d"), keyManagementErr ) );
       
   245         }
       
   246     
   454     // Initialize animdll for handling side volume keys
   247     // Initialize animdll for handling side volume keys
   455     // (needed before normal mode in case emergency number is dialed from PIN query)
   248     // (needed before normal mode in case emergency number is dialed from PIN query)
   456     iSysApKeySndHandler = CSysApKeySndHandler::NewL(iEikonEnv->WsSession());
   249     iSysApKeySndHandler = CSysApKeySndHandler::NewL(iEikonEnv->WsSession());
   457 
   250     iKeyguardController = CKeyguardAccessApi::NewL();
   458     // Initialize shutdown image (needed by nspshandler)
       
   459     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApShutdownImage::NewL()") ) );
   251     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApShutdownImage::NewL()") ) );
   460     iSysApShutdownImage = CSysApShutdownImage::NewL();
   252     iSysApShutdownImage = CSysApShutdownImage::NewL();//NULL; //
   461 
   253     
   462     // Initialize nsps handler. Needed for proper lights control during PIN query.
   254     // Initialize nsps handler. Needed for proper lights control during PIN query.
   463     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApNspsHandler::NewL") ) );
   255     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApNspsHandler::NewL") ) );
   464     iSysApNspsHandler = CSysApNspsHandler::NewL( iEikonEnv->WsSession(), iSysApShutdownImage->ShutdownCoeControlWindow() );
   256     iSysApNspsHandler = CSysApNspsHandler::NewL( iEikonEnv->WsSession(), iSysApShutdownImage->ShutdownCoeControlWindow() );
   465 
   257 
   466 #ifdef RD_LIGHT_CONTROL_CHANGE
   258     RProperty::Define( KPSUidCoreApplicationUIs,KCoreAppUIsPowerMenuCustomDialogStatus, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   467     // NSPS Plugin has been loaded, inform lights controller that in can activate key event forwarding
   259     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsPowerMenuCustomDialogStatus, ECoreAppUIsPowerMenuCustomDialogUninitialized );
   468     iSysApLightsController->KeyEventForwardingReady();
   260     
   469 #endif // RD_LIGHT_CONTROL_CHANGE    
   261 
   470 
   262                     
   471     // Create HAC setting observer now because telephony state may change before entering to normal state
   263     // TBool result = HbTextResolverSymbian::Init(KPsmlocalisationfile, KtsfilePath);
   472     TRACES( RDebug::Print( _L("CCSysApAppUi::ConstructL  trying CSysApCenRepHacSettingObserver::NewL") ) );
   264     
   473     iSysApCenRepHacSettingObserver = CSysApCenRepHacSettingObserver::NewL( *this );
   265     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: END") ) );    
   474 
   266     }
   475     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: END") ) );
   267 
   476     }
   268 // ----------------------------------------------------------------------------
   477 
   269 // CSysApAppUi::FreeResources()
   478 // ----------------------------------------------------------------------------
   270 // ----------------------------------------------------------------------------
   479 // CSysApAppUi::~CSysApAppUi()
   271 
   480 // ----------------------------------------------------------------------------
   272 void CSysApAppUi::FreeResources()
       
   273     {
       
   274     TRACES( RDebug::Print( _L("CSysApAppUi::FreeResources") ) );
       
   275     delete iSysApBatteryInfoController;
       
   276     delete iSysApPsmController;
       
   277     //delete iVariantAccState; 
       
   278 
       
   279     delete iSysApAudioRoutingObserver;
       
   280 
       
   281     if ( iSapTimer )
       
   282         {
       
   283         iSapTimer->Cancel();
       
   284         delete iSapTimer;
       
   285         }
       
   286     //Powermenu
       
   287     if (iPowerMenuDialog!=NULL)
       
   288         {
       
   289         //PowerMenu already exist
       
   290         delete iPowerMenuDialog;
       
   291         iPowerMenuDialog = NULL;
       
   292         }
       
   293     
       
   294     RWindowGroup groupWin = iCoeEnv->RootWin();
       
   295     groupWin.CancelCaptureKey( iCapturedEKeyPowerOff );
       
   296     groupWin.CancelCaptureKeyUpAndDowns( iCapturedEKeyPowerOffUpAndDowns );
       
   297     
       
   298     delete iSysApDefaultKeyHandler;
       
   299     delete iSysApCenRepLightSettingsObserver;
       
   300     delete iSysApCenRepBtObserver;
       
   301     delete iSysApCenRepHacSettingObserver;
       
   302     delete iSysApCenRepController;
       
   303 
       
   304     delete iSysApPubSubObserver;
       
   305     
       
   306     delete iSysApLightsController;
       
   307     delete iSysApFeatureManager;
       
   308     
       
   309     delete iSysApCenRepLogsObserver;
       
   310     delete iSysApOfflineModeController;
       
   311     
       
   312     delete iSysApUsbIndicatorController;
       
   313     delete iKeyguardController;
       
   314     // delete iHbIndicatorSymbian; 
       
   315     delete iSysApKeyManagement;
       
   316     iSysApKeyManagement = NULL;
       
   317     
       
   318     REComSession::FinalClose();
       
   319     iResourcesFreed = ETrue;
       
   320     TRACES( RDebug::Print( _L("CSysApAppUi::FreeResources:END") ) );
       
   321     }
       
   322 
       
   323 // ---------------------------------------------------------------------------
       
   324 // CStartupAppUi::PrepareToExit()
       
   325 // ---------------------------------------------------------------------------
       
   326 void CSysApAppUi::PrepareToExit()
       
   327     {
       
   328     TRACES("CSysApAppUi::PrepareToExit()");
       
   329     CEikAppUi::PrepareToExit();
       
   330     }
       
   331 
       
   332 
       
   333 // ----------------------------------------------------------------------------
       
   334 // CSysApAppUi::StateOfProperty()
       
   335 // ----------------------------------------------------------------------------
       
   336 TInt CSysApAppUi::StateOfProperty( const TUid& aCategory, const TUint aKey ) const
       
   337     {
       
   338     TInt err( KErrNone );
       
   339     TInt value( 0 );
       
   340     err = RProperty::Get( aCategory, aKey, value );
       
   341     if ( err )
       
   342         {
       
   343         TRACES( RDebug::Print( _L("CSysApAppUi::StateOfProperty. RProperty::Get: err=%d"), err ) );
       
   344         return err;
       
   345         }
       
   346     return value;
       
   347     }
       
   348 
       
   349 // ----------------------------------------------------------------------------
       
   350 // CSysApAppUi::OfflineModeActive()
       
   351 // ----------------------------------------------------------------------------
       
   352 TBool CSysApAppUi::OfflineModeActive()
       
   353     {
       
   354     if(iSysApOfflineModeController)
       
   355         {
       
   356         return iSysApOfflineModeController->OfflineModeActive();
       
   357         }
       
   358     else
       
   359         {
       
   360         return EFalse;
       
   361         }
       
   362     }
       
   363 
       
   364 // ----------------------------------------------------------------------------
       
   365 // CSysApAppUi::GoOnlineL()
       
   366 // ----------------------------------------------------------------------------
       
   367 
       
   368 void CSysApAppUi::GoOnlineL( TBool /* aDoProfileChange */ )
       
   369     {
       
   370     if ( iSysApFeatureManager->OfflineModeSupported() )
       
   371         {
       
   372 //        TRACES( RDebug::Print( _L("CSysApAppUi::GoOnlineL: going from off-line into on-line: aDoProfileChange=%d" ), aDoProfileChange ) );
       
   373         iActivateBt = iSysApOfflineModeController->MustBtBeActivated();
       
   374         iSysApOfflineModeController->SwitchFromOfflineToOnlineModeL();
       
   375         TRACES( RDebug::Print( _L("CSysApAppUi::GoOnlineL: iActivateBt = %d" ), iActivateBt ) );
       
   376         }
       
   377     }
       
   378 
       
   379 // ----------------------------------------------------------------------------
       
   380 // CSysApAppUi::GoOfflineL()
       
   381 // ----------------------------------------------------------------------------
       
   382 
       
   383 void CSysApAppUi::GoOfflineL()
       
   384     {
       
   385     if ( iSysApFeatureManager->OfflineModeSupported() )
       
   386         {
       
   387         TRACES( RDebug::Print( _L("CSysApAppUi::GoOfflineL" ) ) );
       
   388         iDeactivateBt = ETrue;
       
   389         iSysApOfflineModeController->SwitchFromOnlineToOfflineModeL();
       
   390         }
       
   391     }
       
   392 
       
   393 #ifndef SYSAP_USE_STARTUP_UI_PHASE
       
   394 // need to configure the above macro.
       
   395 #else // SYSAP_USE_STARTUP_UI_PHASE
       
   396 
       
   397 // ----------------------------------------------------------------------------
       
   398 // CSysApAppUi::HandleUiReadyAfterBootL()
       
   399 // Called when startup UI activities has been finished
       
   400 // ----------------------------------------------------------------------------
       
   401 
       
   402 void CSysApAppUi::HandleUiReadyAfterBootL()
       
   403     {
       
   404     TRACES( RDebug::Print(_L("CSysApAppUi::HandleUiReadyAfterBootL" ) ) );    
       
   405     TInt state( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
   406 
       
   407     UpdateBatteryBarsL( state );   
       
   408     DoSwStateNormalConstructionL();
       
   409     HandleAccessoryProfileInStartupL();       
       
   410    
       
   411     if ( !iSysApPsmController ) // created here if first state change has not occurred yet
       
   412        {
       
   413        iSysApPsmController = CSysApPsmController::NewL( *this );        
       
   414        }
       
   415 
       
   416     if ( iSysApPsmController )
       
   417        {
       
   418         if ( iCharging ) // if charger is connected on boot PSM queries may need to be shown
       
   419         {
       
   420          HandleChargingStatusL( StateOfProperty( KPSUidHWRMPowerState, KHWRMChargingStatus ) );
       
   421         }
       
   422        }
       
   423     
       
   424     TInt batteryStatus = StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryStatus );
       
   425     TRACES( RDebug::Print(_L("CSysApAppUi::HandleUiReadyAfterBootL: batteryStatus %d" ), batteryStatus ) );
       
   426     if(  batteryStatus == EBatteryStatusLow || batteryStatus == EBatteryStatusEmpty )
       
   427         {
       
   428         // low and empty battery states are informed to the user in device startup
       
   429         HandleBatteryStatusL( batteryStatus );
       
   430         }
       
   431     else if ( iSysApPsmController && !iCharging )
       
   432         {
       
   433             TRACES( RDebug::Print(_L("CSysApAppUi::HandleUiReadyAfterBootL: batteryStatus %d, iCharging %d -> disable partial psm" ), batteryStatus, iCharging ) );
       
   434 
       
   435             iSysApPsmController->BatteryLow( EFalse );
       
   436             iSysApPsmController->DoEnablePartialPsm( EFalse );
       
   437         }
       
   438     
       
   439     if ( ! iSysApUsbIndicatorController )
       
   440         {
       
   441         TRAPD ( usbErr, iSysApUsbIndicatorController = CreateSysApUsbIndicatorL( *this ) );
       
   442         if ( usbErr )
       
   443             {
       
   444             TRACES( RDebug::Print(_L("CSysApAppUi::HandleUiReadyAfterBootL: error in constructing USB ind. controller %d" ), usbErr ) );
       
   445             }
       
   446         }
       
   447    }
       
   448 
       
   449 // ----------------------------------------------------------------------------
       
   450 // CSysApAppUi::DoStateChangedL(const RStarterSession::TGlobalState aSwState)
       
   451 // This method is not called after boot has finished.
       
   452 // ----------------------------------------------------------------------------
       
   453 
       
   454 void CSysApAppUi::DoStateChangedL(const RStarterSession::TGlobalState aSwState)
       
   455     {
       
   456     TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL: %d" ), aSwState ) );
       
   457 
       
   458     TRAPD( simChangedErr, DoSimChangedFromPreviousBootL() );
       
   459     TRACES( RDebug::Print( _L("CSysApAppUi::DoStateChangedL: simChangedErr = %d" ), simChangedErr ) );
       
   460     simChangedErr = simChangedErr; // suppress 'variable not used' warning
       
   461     LogsObserverL().HandleSimChangedCheckDoneL();
       
   462 
       
   463     if ( iSysApFeatureManager->PowerSaveSupported() )
       
   464         {
       
   465         // create controller before checking battery state, so that power saving can be enabled during boot if needed
       
   466         if ( !iSysApPsmController ) // created only in first state change
       
   467             {
       
   468             iSysApPsmController = CSysApPsmController::NewL( *this );        
       
   469             }
       
   470 
       
   471         // in charger boot explicitly disable  power save mode
       
   472         if ( aSwState == RStarterSession::ECharging )
       
   473             {
       
   474             iSysApPsmController->ChargerConnected();
       
   475             iSysApPsmController->DoEnablePartialPsm( EFalse ); // disable  power save now
       
   476             }
       
   477         }
       
   478 
       
   479     if ( aSwState == RStarterSession::ECharging || aSwState == RStarterSession::EAlarm )
       
   480         {
       
   481         TInt state( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
   482         //Also Charging status will be updated with the following function.
       
   483         UpdateBatteryBarsL( state );    
       
   484         }
       
   485         
       
   486     if( IsStateNormal() )
       
   487         {
       
   488         TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL to normal state.") ) );
       
   489 
       
   490         iSysApBtController = CreateSysApBtControllerL( *this );
       
   491         iSysApBtSapController = CreateSysApBtSapControllerL( *this );
       
   492 
       
   493         if ( iActivateBt )
       
   494             {
       
   495             TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL Activating BT" ) ) );
       
   496             SetBtPowerState( ETrue );
       
   497             }
       
   498 
       
   499         if ( iDeactivateBt )
       
   500             {
       
   501             TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL Deactivating BT" ) ) );
       
   502             SetBtPowerState( EFalse );
       
   503             }
       
   504 
       
   505         if ( !StarterSession().Handle() )
       
   506             {
       
   507             User::Leave( KErrBadHandle );
       
   508             }
       
   509 
       
   510 /*        if ( !KeyLock().Handle() )
       
   511             {
       
   512             User::Leave( KErrBadHandle );
       
   513             }
       
   514 */
       
   515 #ifdef __SYSAP_MODULE_TEST
       
   516         ModuleTestShowUiNoteL( _L("SysAp: SW state normal!") );
       
   517 #endif
       
   518         }
       
   519 
       
   520     // Allow lights
       
   521     iSysApLightsController->AllowLightsOn();
       
   522     }
       
   523 
       
   524 #endif // SYSAP_USE_STARTUP_UI_PHASE
   481 
   525 
   482 CSysApAppUi::~CSysApAppUi()
   526 CSysApAppUi::~CSysApAppUi()
   483     {
   527     {
   484     TRACES( RDebug::Print( _L("~CSysApAppUi() started") ) );
   528     TRACES( RDebug::Print( _L("~CSysApAppUi() started") ) );
   485     if( !iResourcesFreed )
   529     if( !iResourcesFreed )
   486         {
   530       {
   487         FreeResources();
   531         FreeResources();
   488 
   532       }
   489         iStarterSession.Close();
   533     delete iSysApStartupController;
   490 
   534     }
   491         }
   535         
   492 
   536 TBool CSysApAppUi::ResourcesFreed() const
   493     delete iSysApShutdownImage;
   537     {
   494 
   538     return iResourcesFreed;
       
   539     }
       
   540 
       
   541 void CSysApAppUi::ShowExampleUiNoteL( const TDesC& noteText )const
       
   542     {          
       
   543     //   QString msg  = QString::fromUtf16(aStringPointer.Ptr(),aStringPointer.Length());
       
   544  	TRACES( RDebug::Print( _L("CSysApAppUi::ShowExampleUiNoteL:: constructing CHbDeviceMessageBoxSymbian:BeGIN") ) );    
       
   545     CHbDeviceMessageBoxSymbian *note = CHbDeviceMessageBoxSymbian::NewL(CHbDeviceMessageBoxSymbian::EInformation);
       
   546  	CleanupStack::PushL(note);
       
   547     TRACES( RDebug::Print( _L("CSysApAppUi::ShowExampleUiNoteL:: construction of CHbDeviceMessageBoxSymbian:END") ) ); 
       
   548 	//	HbMessageBox *note = new HbMessageBox (HbMessageBox ::MessageTypeInformation);
       
   549     note->SetTextL(noteText);
       
   550     //  note->SetTimeout(HbPopup::NoTimeout);
       
   551 	note->SetTimeout(5);
       
   552  	TRACES( RDebug::Print( _L("CSysApAppUi:: Display of  CHbDeviceMessageBoxSymbian::Begin") ) );    
       
   553     note->ShowL();
       
   554 	TRACES( RDebug::Print( _L("CSysApAppUi:: Display of  CHbDeviceMessageBoxSymbian::End") ) );
       
   555 	CleanupStack::PopAndDestroy(note);
       
   556     }
       
   557 
       
   558 
       
   559 void CSysApAppUi::ExecQueryL( TSysapQuery aQuery, TDes8& aReturn )
       
   560     {
       
   561     ExecQueryL( aQuery, aReturn, KNullDesC8 );
       
   562     }
       
   563 
       
   564 // ----------------------------------------------------------------------------
       
   565 // CSysApAppUi::ExecQueryL
       
   566 // ----------------------------------------------------------------------------
       
   567 //
       
   568 void CSysApAppUi::ExecQueryL( TSysapQuery aQuery, TDes8& aReturn, const TDesC8& /*aParam*/ )
       
   569     {
       
   570     TRACES( RDebug::Print(_L("CSysApAppUi::ExecQueryL: aQuery=%d"), aQuery ) );
       
   571 
       
   572     switch ( aQuery )
       
   573         {
       
   574         case EGetHwrmLight: // get handle to HWRM client session. Returns CHWRMLight*.
       
   575             {
       
   576             THwrmLightBuf retBuf( iSysApLightsController->GetHwrmLight() );
       
   577             aReturn.Copy( retBuf );
       
   578             }
       
   579             break;
       
   580 
       
   581         case EGetKeylock: // get handle to keylock client session. Returns RAknKeylock2*.
       
   582             {
       
   583             // do nothing
       
   584             }
       
   585             break;
       
   586 
       
   587 
       
   588         default:
       
   589             __ASSERT_DEBUG( EFalse, User::Panic( _L("CSysApAppUi::ExecQueryL: Invalid query"), KErrArgument ) );
       
   590             User::Leave( KErrArgument );
       
   591             break;
       
   592         }
       
   593     }
       
   594 
       
   595 // ----------------------------------------------------------------------------
       
   596 // CSysApAppUi::ExecCommandL
       
   597 // ----------------------------------------------------------------------------
       
   598 //
       
   599 void CSysApAppUi::ExecCommandL( TSysapCommand aCommand )
       
   600     {
       
   601     ExecCommandL( aCommand, KNullDesC8 );
       
   602     }
       
   603 
       
   604 // ----------------------------------------------------------------------------
       
   605 // CSysApAppUi::ExecCommandL
       
   606 // ----------------------------------------------------------------------------
       
   607 //
       
   608 void CSysApAppUi::ExecCommandL( TSysapCommand aCommand, const TDesC8&  /* aParam */ )
       
   609     {
       
   610     TRACES( RDebug::Print(_L("CSysApAppUi::ExecCommandL: aCommand=%d"), aCommand ) );
       
   611 
       
   612     switch ( aCommand )
       
   613         {
       
   614         case EResetKeyguardState: // reset the internal keyguard flags of the SysAp, except for iKeyLockOnBeforeCradle
       
   615             iKeyLockOnBeforeCall = EFalse;
       
   616             iKeyLockOnBeforeAlarm = EFalse;
       
   617             break;
       
   618 
       
   619         default:
       
   620             // do nothing in release builds since no harm is done
       
   621             __ASSERT_DEBUG( EFalse, User::Panic( _L("CSysApAppUi::ExecCommandL: Invalid command"), KErrArgument ) );
       
   622             break;
       
   623         }
       
   624     }
       
   625     
       
   626 // ----------------------------------------------------------------------------
       
   627 // CSysApAppUi::TimerExpiredL()
       
   628 // ----------------------------------------------------------------------------
       
   629 void CSysApAppUi::TimerExpiredL()
       
   630     {
       
   631 /*
       
   632  * Not suppported , will take care in wk25
       
   633  * #ifndef RD_MULTIPLE_DRIVE 
       
   634  * CloseUIAppsInHotSwapL();
       
   635  * #endif // RD_MULTIPLE_DRIVE
       
   636 */   
       
   637    }
       
   638 
       
   639 
       
   640   // ----------------------------------------------------------------------------
       
   641 // CSysApAppUi::KeyLockState() const
       
   642 // ----------------------------------------------------------------------------
       
   643 
       
   644 TBool CSysApAppUi::KeyLockState() const
       
   645     {
       
   646     return iKeyLockEnabled;
       
   647     }
       
   648 
       
   649 // ----------------------------------------------------------------------------
       
   650 // CSysApAppUi::DeviceLockState() const
       
   651 // ----------------------------------------------------------------------------
       
   652 
       
   653 TBool CSysApAppUi::DeviceLockState() const
       
   654     {
       
   655     return iDeviceLockEnabled;
       
   656     }
       
   657     
       
   658 // ----------------------------------------------------------------------------
       
   659 // CSysApAppUi::SysApFeatureManager
       
   660 // ----------------------------------------------------------------------------
       
   661 
       
   662 CSysApFeatureManager& CSysApAppUi::SysApFeatureManager()
       
   663     {
       
   664     __ASSERT_DEBUG( iSysApFeatureManager, User::Panic( _L("iSysApFeatureManager == NULL"), KErrBadHandle ) );
       
   665 
       
   666     return *iSysApFeatureManager;
       
   667     }
       
   668     
       
   669 // ----------------------------------------------------------------------------
       
   670 // CSysApAppUi::ActivateKeyeventForwardingForLights()
       
   671 // ----------------------------------------------------------------------------
       
   672 
       
   673 void CSysApAppUi::ActivateKeyeventForwardingForLights(TBool aActivate)
       
   674     {
       
   675     if( iSysApNspsHandler )
       
   676         {
       
   677         if ( aActivate )
       
   678             {
       
   679             iSysApNspsHandler->ActivateKeyeventForwardingForLights();
       
   680             }
       
   681         else
       
   682             {
       
   683             iSysApNspsHandler->DeActivateKeyeventForwardingForLights();
       
   684             }
       
   685         }
       
   686     }
       
   687 
       
   688 // ----------------------------------------------------------------------------
       
   689 // CSysApAppUi::StarterSession()
       
   690 // ----------------------------------------------------------------------------
       
   691 
       
   692 RStarterSession& CSysApAppUi::StarterSession()
       
   693     {
       
   694     if ( !iStarterSession.Handle() )
       
   695         {
       
   696         // All server connections are tried to be made KTriesToConnectServer times because occasional
       
   697         // fails on connections are possible at least on some servers
       
   698         TRACES( RDebug::Print( _L("CSysApAppUi::StarterSession: trying RStarterSession::Connect()") ) );
       
   699         TInt thisTry = 0;
       
   700         TInt err;
       
   701         while ( ( err = iStarterSession.Connect() ) != KErrNone && ( thisTry++ ) <= KTriesToConnectServer )
       
   702             {
       
   703             User::After( KTimeBeforeRetryingServerConnection );
       
   704             }
       
   705 
       
   706         if ( err != KErrNone )
       
   707             {
       
   708             // What do in error case?
       
   709             TRACES( RDebug::Print( _L("CSysApAppUi::StarterSession: RStarterSession::Connect() failed with %d"), err ) );
       
   710             }
       
   711         }
       
   712 
       
   713     return iStarterSession;
       
   714     }
       
   715 
       
   716 // ----------------------------------------------------------------------------
       
   717 // CSysApAppUi::SetBtPowerState()
       
   718 // ----------------------------------------------------------------------------
       
   719 TInt CSysApAppUi::SetBtPowerState( TBool aBtState )
       
   720     {
       
   721     if ( iSysApBtController )
       
   722         {
       
   723         return iSysApBtController->SetPowerState( aBtState );
       
   724         }
       
   725     else
       
   726         {
       
   727         return KErrNotReady;
       
   728         }
       
   729     }
       
   730 
       
   731 // ----------------------------------------------------------------------------
       
   732 // CSysApAppUi::SetStarterState()
       
   733 // ----------------------------------------------------------------------------
       
   734 
       
   735 TInt CSysApAppUi::SetStarterState( const RStarterSession::TGlobalState aState )
       
   736     {
       
   737     if ( iSysApStartupController->GlobalStateChangeAllowed( aState ) )
       
   738         {
       
   739         TRACES( RDebug::Print( _L("CSysApAppUi::SetStarterState: aState=%d" ), aState ) );
       
   740         return StarterSession().SetState( aState );
       
   741         }
       
   742     else
       
   743         {
       
   744         TRACES( RDebug::Print( _L("CSysApAppUi::SetStarterState: aState=%d - not allowed" ), aState ) );
       
   745         return KErrNone;
       
   746         }
       
   747     }
       
   748 
       
   749 // ----------------------------------------------------------------------------
       
   750 // CSysApAppUi::SetNetworkConnectionAllowed()
       
   751 // ----------------------------------------------------------------------------
       
   752 
       
   753 void CSysApAppUi::SetNetworkConnectionAllowed( TCoreAppUIsNetworkConnectionAllowed aNetworkConnectionAllowed )
       
   754     {
       
   755     TRACES( RDebug::Print( _L("CSysApAppUi::SetNetworkConnectionAllowed: status: %d" ), aNetworkConnectionAllowed ) );
       
   756 
       
   757     iSysApCenRepController->SetInt( KCRUidCoreApplicationUIs, KCoreAppUIsNetworkConnectionAllowed, (TInt) aNetworkConnectionAllowed );
       
   758 
       
   759     // Also set the Symbian PS key used for the same purpose:
       
   760     RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, aNetworkConnectionAllowed ? ESAPhoneOn : ESAPhoneOff);
       
   761     }
       
   762 
       
   763 // ----------------------------------------------------------------------------
       
   764 // CSysApAppUi::BluetoothPowerMode()
       
   765 // ----------------------------------------------------------------------------
       
   766 TInt CSysApAppUi::BluetoothPowerMode() const
       
   767     {
       
   768     return iSysApCenRepBtObserver->BluetoothPowerMode();
       
   769     }
       
   770 
       
   771 // ----------------------------------------------------------------------------
       
   772 // CSysApAppUi::SimSupported()
       
   773 // ----------------------------------------------------------------------------
       
   774 TBool CSysApAppUi::SimSupported()
       
   775     {
       
   776     return iSysApFeatureManager->SimSupported();
       
   777     }
       
   778 
       
   779 // ----------------------------------------------------------------------------
       
   780 // CSysApAppUi::BtSapEnabled()
       
   781 // ----------------------------------------------------------------------------
       
   782 
       
   783 TBool CSysApAppUi::BtSapEnabled()
       
   784     {
       
   785     if ( iSysApBtSapController )
       
   786         {
       
   787         return iSysApBtSapController->BtSapEnabled();    
       
   788         }  
       
   789     return EFalse;
       
   790     }
       
   791 
       
   792 
       
   793 // ----------------------------------------------------------------------------
       
   794 // CSysApAppUi::OfflineModeChangedL()
       
   795 // ----------------------------------------------------------------------------
       
   796 void CSysApAppUi::OfflineModeChangedL()
       
   797     {
       
   798 #ifdef SYSAP_USE_STARTUP_UI_PHASE    
       
   799     // if UI is not ready, don't update indicators
       
   800     if ( !UiReady() )
       
   801         {
       
   802         return;
       
   803         }
       
   804 #endif // SYSAP_USE_STARTUP_UI_PHASE
       
   805 
       
   806 #if 0 // Not used as of now
       
   807     SetHacIndicatorL();
       
   808 #endif //0	
       
   809     }
       
   810 
       
   811 // ----------------------------------------------------------------------------
       
   812 // CSysApAppUi::UiReady()
       
   813 // 
       
   814 // ----------------------------------------------------------------------------
       
   815 
       
   816 TBool CSysApAppUi::UiReady() const
       
   817     {
       
   818 #ifdef SYSAP_USE_STARTUP_UI_PHASE    
       
   819     return iSysApStartupController->UiReady(); 
       
   820 #else // SYSAP_USE_STARTUP_UI_PHASE
       
   821     // if startup UI phase information is not used, global system state normal is handled as UI idle state
       
   822     return IsStateNormal();
       
   823 #endif // SYSAP_USE_STARTUP_UI_PHASE        
       
   824     }
       
   825 
       
   826 
       
   827 // ----------------------------------------------------------------------------
       
   828 // CSysApAppUi::CompleteShutdown()
       
   829 // ----------------------------------------------------------------------------
       
   830 
       
   831 void CSysApAppUi::CompleteShutdown( const TBool aReset, const TInt aResetReason )
       
   832     {
       
   833     TRACES( RDebug::Print(_L("CSysApAppUi::CompleteShutdown(): START" ) ) );
       
   834     
       
   835     iCheckLongPowerKeyEvent = ETrue;
       
   836 
       
   837     PrepareForShutdownImage();//SysAp's internal preparation for ShutDown with image
       
   838 
       
   839     FreeResources();
       
   840 
       
   841     if ( aReset )
       
   842         {
       
   843         __ASSERT_DEBUG( aResetReason >= RStarterSession::ELanguageSwitchReset &&
       
   844                         aResetReason <= RStarterSession::EDataRestoreReset,
       
   845                         User::Invariant() );
       
   846         StarterSession().Reset( static_cast<RStarterSession::TResetReason>( aResetReason ) );
       
   847         }
       
   848     else
       
   849         {
       
   850         StarterSession().Shutdown();
       
   851         }
       
   852 
       
   853     StarterSession().Close();
       
   854 
       
   855     TRACES( RDebug::Print(_L("CSysApAppUi::CompleteShutdown(): END" ) ) );
       
   856     }
       
   857 
       
   858 
       
   859 
       
   860 // ----------------------------------------------------------------------------
       
   861 // CSysApAppUi::DoShutdownL( const TBool aReset, const TSWStartupReason aSWStartupReason )
       
   862 // ----------------------------------------------------------------------------
       
   863 
       
   864 void CSysApAppUi::DoShutdownL( const TBool aReset, const TInt aResetReason )
       
   865     {
       
   866     TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL: aResetReason:%d, aReset:%d" ),
       
   867         aResetReason, aReset ) );
   495 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
   868 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
   496     if (iSysApShutdownAnimation)
   869     TBool animationenabled( EFalse );
   497         {
       
   498         RemoveFromStack( iSysApShutdownAnimation );
       
   499 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
   870 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
   500         delete iSysApShutdownAnimation;
   871 
       
   872     if( OkToInitiateShutdown() )
       
   873         {
       
   874         TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL: Was OkToToInitiateShutdown" ) ) );
       
   875 
       
   876 
       
   877         if ( !aReset && iSysApFeatureManager->Supported(KSysApFeatureIdGoodbyeNote) )
       
   878             {
       
   879             // show shutdown note
       
   880             }
       
   881 
       
   882         if( !aReset )
       
   883             {
       
   884     #ifdef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
   885 //            TRAPD( err, ShowAnimationL() );
       
   886 //            if ( err )
       
   887                 {
       
   888      //           TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL ShowAnimationL() leaved: %d" ), err ) );
       
   889                 CompleteShutdown(aReset, aResetReason);
       
   890                 }
       
   891             }
       
   892         else // aReset
       
   893            {
       
   894             CompleteShutdown(aReset, aResetReason);
       
   895             }
       
   896     #else // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
   897             TRAPD( err, animationenabled = ShowAnimationL() );
       
   898             if ( err )
       
   899                 {
       
   900                 TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL ShowAnimationL() leaved: %d" ), err ) );
       
   901                 }
       
   902             }
       
   903 
       
   904         if ( !animationenabled )
       
   905             {
       
   906             CompleteShutdown(aReset, aResetReason);
       
   907             }
       
   908     #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
   909         }
       
   910     else
       
   911         {
       
   912         TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL: Was not OkToToInitiateShutdown" ) ) );
       
   913         }
       
   914     TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL: END" ) ) );
       
   915     }
       
   916 
       
   917 
       
   918 
       
   919 /* 
       
   920 ----------------------------------------------------------------------------
       
   921 CSysApAppUi::IsEncryptionOperationOngoingL()
       
   922 Introduced the code as a part of Sub : 405-3362 - Power Management SUB for ES 
       
   923 recapture functionalities in platform which support multidrive as well. 
       
   924 -------------------------------------------------------------------------------
       
   925 */
       
   926 TBool CSysApAppUi::IsEncryptionOperationOngoingL() const
       
   927     {
       
   928         TBool deFeatureSupported(EFalse);
       
   929         FeatureManager::InitializeLibL();
       
   930         deFeatureSupported = FeatureManager::FeatureSupported( KFeatureIdFfDeviceEncryptionFeature);
       
   931         FeatureManager::UnInitializeLib();
       
   932 
       
   933         if(deFeatureSupported)
       
   934             {         
       
   935             /**
       
   936              * Store the last memory status changed
       
   937              * 0: Idle. It can be Encrypted or Decrypted
       
   938              * 1: Encrypting
       
   939              * 2: Decrypting
       
   940              **/
       
   941              
       
   942             RProperty deProperty;
       
   943             User::LeaveIfError(deProperty.Attach(KDevEncProtectedUid, KDevEncOperationKey,EOwnerThread));
       
   944             TInt deValue = 0;
       
   945             if((deProperty.Get(deValue)== KErrNone)&&( deValue == EOpEncrypting || deValue == EOpDecrypting))
       
   946                 {
       
   947                 deProperty.Close();
       
   948                 return ETrue;
       
   949                 }
       
   950             else
       
   951                 {
       
   952                 deProperty.Close();
       
   953                 return EFalse;
       
   954                 }
       
   955             }
       
   956         else
       
   957             {
       
   958             return EFalse;
       
   959             }
       
   960     }
       
   961 
       
   962 // ----------------------------------------------------------------------------
       
   963 // CSysApAppUi::HandleLongPowerKeyPressedL()
       
   964 // ----------------------------------------------------------------------------
       
   965 
       
   966 void CSysApAppUi::HandleLongPowerKeyPressedL()
       
   967     {
       
   968     TRACES( RDebug::Print( _L("CSysApAppUi::HandleLongPowerKeyPressedL()") ) );
       
   969 
       
   970     TInt swState;
       
   971     RProperty::Get( KPSUidStartup, KPSGlobalSystemState, swState );
       
   972     
       
   973     iSysApLightsController->PowerKeyPressedL();  //need to handle later.
       
   974 
       
   975     if( swState == ESwStateStartingCriticalApps ||
       
   976         swState == ESwStateSelfTestOK ||
       
   977         swState == ESwStateSecurityCheck ||
       
   978         swState == ESwStateCriticalPhaseOK ||
       
   979         swState == ESwStateEmergencyCallsOnly ||
       
   980         swState == ESwStateNormalRfOn ||
       
   981         swState == ESwStateNormalRfOff ||
       
   982         swState == ESwStateNormalBTSap ||
       
   983         swState == ESwStateFatalStartupError )
       
   984         {
       
   985         if( !iDeviceLockEnabled )
       
   986             {
       
   987             if( iPowerKeyPopupMenuActive )
       
   988                 {
       
   989                 // do nothing
       
   990                 }
       
   991             else if( !iIgnoreNextPowerKeyRepeats )
       
   992                 {
       
   993                 if( !iKeyLockEnabled && !IsEncryptionOperationOngoingL() )
       
   994                     {
       
   995                     DoShutdownL( EFalse, KDummyReason );
       
   996                     }
       
   997                 }
       
   998             iIgnoreNextPowerKeyRepeats = ETrue;
       
   999             }
       
  1000         }
       
  1001     else if( swState == ESwStateAlarm )
       
  1002         {
       
  1003         //Just comment here to highlight that this is not possible since
       
  1004         //from alarm state already a short press always shuts the device down.
       
  1005         }
       
  1006     else if( swState == ESwStateCharging )
       
  1007         //Startup to Normal state
       
  1008         {
       
  1009         if( !iIgnoreNextPowerKeyRepeats )
       
  1010             {
       
  1011             iIgnoreNextPowerKeyRepeats = ETrue;
       
  1012 
       
  1013             SetStarterState( RStarterSession::ENormal );
       
  1014             }
       
  1015         }
       
  1016     }
       
  1017 
       
  1018 // ----------------------------------------------------------------------------
       
  1019 // CSysApAppUi::IsDeviceModeKey
       
  1020 // ----------------------------------------------------------------------------
       
  1021 
       
  1022 TBool CSysApAppUi::IsDeviceModeKey( const TKeyEvent& aKeyEvent ) const
       
  1023     {
       
  1024     return CSysApDefaultKeyHandler::IsDeviceModeKey( aKeyEvent );
       
  1025     }
       
  1026 
       
  1027 
       
  1028 // ----------------------------------------------------------------------------
       
  1029 // CSysApAppUi::ShowShutdownImage
       
  1030 // ----------------------------------------------------------------------------
       
  1031 //
       
  1032 TInt CSysApAppUi::ShowShutdownImage( TInt aBitmapId )
       
  1033     {
       
  1034     TRACES( RDebug::Print(_L("CSysApAppUi::ShowShutdownImage") ) );
       
  1035 
       
  1036     TRAPD( err, ShowShutdownImageL( aBitmapId ) );
       
  1037 
       
  1038     if ( err != KErrNone )
       
  1039         {
       
  1040         TRACES( RDebug::Print(_L("CSysApAppUi::ShowShutdownImageL failed, err=%d"), err ) );
       
  1041         }
       
  1042 
       
  1043     return err;
       
  1044     }
       
  1045 
       
  1046 
       
  1047 // ----------------------------------------------------------------------------
       
  1048 // CSysApAppUi::ShowShutdownImageL
       
  1049 // ----------------------------------------------------------------------------
       
  1050 //
       
  1051 void CSysApAppUi::ShowShutdownImageL( TInt aBitmapId )
       
  1052     {
       
  1053     TRACES( RDebug::Print(_L("CSysApAppUi::ShowShutdownImageL") ) );
       
  1054     // do nothing
       
  1055     if ( !iSysApShutdownImage ) // Shutdown image may be shown without entering normal state (e.g. charging), so construct here
       
  1056         {
       
  1057         TRACES( RDebug::Print( _L("CSysApAppUi::ShowShutdownImageL: trying CSysApShutdownImage::NewL()") ) );
       
  1058         iSysApShutdownImage = CSysApShutdownImage::NewL();
       
  1059         }
       
  1060     TRACES( RDebug::Print( _L("CSysApAppUi::ShowShutdownImageL: trying CSysApShutdownImage::ShowShutdownImageL()") ) );
       
  1061     iSysApShutdownImage->ShowShutdownImageL( aBitmapId );
       
  1062    }
       
  1063    
       
  1064 // ----------------------------------------------------------------------------
       
  1065 // CSysApAppUi::PrepareForShutdownImage()
       
  1066 // ----------------------------------------------------------------------------
       
  1067 
       
  1068 void CSysApAppUi::PrepareForShutdownImage()
       
  1069     {
       
  1070     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownImage() START" ) ) );
       
  1071  
       
  1072     // If RD_STARTUP_ANIMATION_CUSTOMIZATION is enabled, the following actions are always taken in PrepareForShutdownAnimation
   501 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
  1073 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  1074     if ( !iAnimationShowingTime ) // actions already taken in PrepareForShutdownAnimation
       
  1075         {
       
  1076         static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds()->PlaySound( EAvkonSIDPowerOffTone );
       
  1077         CancelGlobalListQuery();
       
  1078         
       
  1079         if ( iSysApPowerKeyMenuObserver )
       
  1080             {
       
  1081             iSysApPowerKeyMenuObserver->Cancel();
       
  1082             }
       
  1083         
       
  1084         // deactivate notifiers before showing the shutdown image
       
  1085         AknNotifierController::CancelAllNotifications();
       
  1086         AknNotifierController::HideAllNotifications(ETrue);
       
  1087         RWindowGroup groupWin = iCoeEnv->RootWin();
       
  1088         iCapturedAppskey = groupWin.CaptureKey( EKeyApplication, KModifierMask, KModifierMask );
       
  1089         iCapturedAppskeyUpAndDowns = groupWin.CaptureKeyUpAndDowns( EStdKeyApplication0, KModifierMask, KModifierMask );
   502         }
  1090         }
   503 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
  1091 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
   504 
  1092 
   505     delete iProfileNote;
  1093 #ifndef __SYSAP_MODULE_TEST //to make errors during shutdown sequence being seen more easily
   506 
  1094     iEikonEnv->RootWin().SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront );
   507 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
  1095     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownImage() Show Shutdown image" ) ) );
   508     if( iAnimTimer )
  1096     ShowShutdownImage( 1  );//EMbmSysapQgn_startup_screen
   509         {
  1097 #endif
   510         iAnimTimer->Cancel();
  1098     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownImage() END" ) ) );
   511         }
  1099     }
   512     delete iAnimTimer;
  1100 
   513 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
  1101 // ----------------------------------------------------------------------------
   514 
  1102 // CSysApAppUi::OkToInitiateShutdown()
   515     delete iSysApPowerKeyMenuObserver;
  1103 // ----------------------------------------------------------------------------
   516 
  1104 
   517     delete iSysApStartupController;
  1105 TBool CSysApAppUi::OkToInitiateShutdown()
   518 
  1106     {
   519 #ifdef RD_MULTIPLE_DRIVE
  1107     TInt swState;
   520     iInsertedMemoryCards.Close();
  1108     RProperty::Get( KPSUidStartup, KPSGlobalSystemState, swState );
   521     delete  iSysApDriveEjectHandler;
  1109 
   522     delete iSysApDriveUnlockHandler;
  1110     if( !iShutdownStarted &&
   523     delete iSysApDriveList;
  1111         swState == ESwStateStartingCriticalApps ||
       
  1112         swState == ESwStateSelfTestOK ||
       
  1113         swState == ESwStateSecurityCheck ||
       
  1114         swState == ESwStateCriticalPhaseOK ||
       
  1115         swState == ESwStateEmergencyCallsOnly ||
       
  1116         swState == ESwStateCharging ||
       
  1117         swState == ESwStateAlarm ||
       
  1118         swState == ESwStateNormalRfOn ||
       
  1119         swState == ESwStateNormalRfOff ||
       
  1120         swState == ESwStateNormalBTSap ||
       
  1121         swState == ESwStateFatalStartupError )
       
  1122         {
       
  1123         iShutdownStarted = ETrue;
       
  1124         return ETrue;
       
  1125         }
       
  1126     else
       
  1127         {
       
  1128         return EFalse;
       
  1129         }
       
  1130     }
       
  1131 
       
  1132 
       
  1133 void CSysApAppUi::PopupNote()
       
  1134     {
       
  1135     iIgnoreNextPowerKeyUpEvent = ETrue;
       
  1136     // TRACES( RDebug::Print( _L("CSysApAppUi::Key was consumed") ) );
       
  1137     _LIT(KPowerPressKey,"Short power key");
       
  1138     HBufC* aString = HBufC16::NewLC(50);
       
  1139     TPtrC aStringPointer = aString->Des();
       
  1140     aStringPointer.Set(KPowerPressKey);
       
  1141     TRACES( RDebug::Print( _L("CSysApWsClient::RunL(): Key EEventKeyUp 01") ) );   
       
  1142     ShowExampleUiNoteL( aStringPointer );  
       
  1143     CleanupStack::PopAndDestroy(); // aString
       
  1144     }
       
  1145 
       
  1146 
       
  1147 // ----------------------------------------------------------------------------
       
  1148 // CSysApAppUi::SetUsbAttachStatus
       
  1149 // ----------------------------------------------------------------------------
       
  1150 #ifndef RD_MULTIPLE_DRIVE
       
  1151 void CSysApAppUi::SetUsbAttachStatus( const TBool aUsbAttached )
       
  1152     {
       
  1153     // Prevent double beep when USB file transfer gets activated but
       
  1154     // allow MMC inserted beep when:
       
  1155     // a) USB file transfer is active
       
  1156     // b) MMC is not inserted when USB cable is attached
       
  1157     iHideNextBeep = ( iMMCInserted && aUsbAttached );
       
  1158     }
       
  1159 #else // RD_MULTIPLE_DRIVE
       
  1160 void CSysApAppUi::SetUsbAttachStatus( const TBool aUsbAttached )
       
  1161     {
       
  1162     TRACES( RDebug::Print(
       
  1163         _L( "CSysApAppUi::SetUsbAttachStatus: aUsbAttached: %d" ),
       
  1164         aUsbAttached ) );
       
  1165 
       
  1166     if ( aUsbAttached )
       
  1167         {
       
  1168           // For ignoring extra beeps caused by USB file transfer
       
  1169 /*        iSysApDriveList->ResetDrivesInsertBeepIgnored();
       
  1170         iSysApDriveList->MarkDrivesInsertBeepIgnored( iInsertedMemoryCards );
       
  1171         // Will take care in next sub
       
  1172 */        }
       
  1173     }
   524 #endif // RD_MULTIPLE_DRIVE
  1174 #endif // RD_MULTIPLE_DRIVE
   525 
  1175 
   526     TRACES( RDebug::Print( _L("~CSysApAppUi() completed") ) );
  1176 
   527     }
  1177 // ----------------------------------------------------------------------------
   528 
  1178 // CSysApAppUi::UsbChargerDetector
   529 
  1179 // ----------------------------------------------------------------------------
   530 // ----------------------------------------------------------------------------
  1180 //
   531 // CSysApAppUi::HandleLocationPrivacyIndicatorL()
  1181 TSysApUsbChargerDetector& CSysApAppUi::UsbChargerDetector()
   532 // ----------------------------------------------------------------------------
  1182     {
   533 
  1183     return iSysApUsbChargerDetector;
   534 void CSysApAppUi::HandleLocationPrivacyIndicatorL( const TInt aState )
  1184     }
   535     {
  1185 
   536     TRACES( RDebug::Print( _L("CSysApAppUi::HandleLocationPrivacyIndicatorL() state=%d"), aState ) );
  1186 
   537     if ( iSysApFeatureManager->LocationPrivacySupported() )
  1187 // ----------------------------------------------------------------------------
   538         {
  1188 // CSysApAppUi::HandleAccessoryDisconnectedL()
   539         // Phase 1. Set all Location Privacy indicators off
  1189 // ----------------------------------------------------------------------------
   540         if ( iSysApLocationPrivacyIndicator->iIndicatorIdAcceptAll != KSysApNoIndicator )
  1190 
   541             {
  1191 void CSysApAppUi::HandleAccessoryDisconnectedL()
   542             SetIndicatorStateL( iSysApLocationPrivacyIndicator->iIndicatorIdRejectAll, EAknIndicatorStateOff );
  1192     {
   543             }
  1193     TRACES( RDebug::Print( _L("CSysApAppUi::HandleAccessoryDisconnectedL()" ) ) );
   544         if ( iSysApLocationPrivacyIndicator->iIndicatorIdRejectAll != KSysApNoIndicator )
  1194 
   545             {
  1195 
   546             SetIndicatorStateL( iSysApLocationPrivacyIndicator->iIndicatorIdRejectAll, EAknIndicatorStateOff );
  1196     TAccMode accessoryState(EAccModeHandPortable);
   547             }
  1197     if ( iSysApAccessoryObserver )
   548         if ( iSysApLocationPrivacyIndicator->iIndicatorIdAlwaysAsk != KSysApNoIndicator )
  1198         {
   549             {
  1199         accessoryState = iSysApAccessoryObserver->GetAccessoryMode();
   550             SetIndicatorStateL( iSysApLocationPrivacyIndicator->iIndicatorIdAlwaysAsk, EAknIndicatorStateOff );
  1200         }
   551             }
  1201 
   552         if ( iSysApLocationPrivacyIndicator->iIndicatorIdIndividualPrivacy != KSysApNoIndicator )
  1202     if ( accessoryState == EAccModeHandPortable )
   553             {
  1203         {
   554             SetIndicatorStateL( iSysApLocationPrivacyIndicator->iIndicatorIdIndividualPrivacy, EAknIndicatorStateOff );
  1204         iSysApLightsController->AccessoryConnectedL( EFalse );
   555             }
  1205         iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApAccessoryConnected, 0 );
   556         // Phase 2. Set the required Location Privacy indicator on
  1206         }
   557         switch ( aState )
  1207 
   558             {
  1208     SetIhfIndicatorL();
   559             case EPSLocPrivAcceptAll:
  1209     SetHacIndicatorL();
   560                 if ( iSysApLocationPrivacyIndicator->iIndicatorIdAcceptAll != KSysApNoIndicator )
  1210 
       
  1211     // If lock disabled because of accessory, reactivate it, unless phone call or alarm is ongoing
       
  1212     if ( iKeyLockOnBeforeCradle )
       
  1213         {
       
  1214         iKeyLockOnBeforeCradle = EFalse;
       
  1215         if ( !iKeyLockOnBeforeCall && !iKeyLockOnBeforeAlarm )
       
  1216             {
       
  1217             if ( !iDeviceLockEnabled )
       
  1218                 {
       
  1219                 iKeyguardController->EnableKeyguard(ETrue);
       
  1220                 }
       
  1221             else
       
  1222                 {
       
  1223                 iKeyguardController->EnableKeyguard(EFalse);
       
  1224                 }
       
  1225             }
       
  1226         }
       
  1227     }
       
  1228 
       
  1229 
       
  1230 // ----------------------------------------------------------------------------
       
  1231 // CSysApAppUi::HandleAccessoryConnectedL()
       
  1232 // ----------------------------------------------------------------------------
       
  1233 
       
  1234 void CSysApAppUi::HandleAccessoryConnectedL( TAccMode aAccessoryState )
       
  1235     {
       
  1236     TRACES( RDebug::Print( _L("CSysApAppUi::HandleAccessoryConnectedL( aAccessoryState: %d ) "), aAccessoryState ) );
       
  1237 
       
  1238     if ( aAccessoryState == EAccModeWirelessHeadset ||
       
  1239          aAccessoryState == EAccModeWiredHeadset ||
       
  1240          aAccessoryState == EAccModeHeadphones )
       
  1241         {
       
  1242         }
       
  1243     else if ( aAccessoryState == EAccModeLoopset )
       
  1244         {
       
  1245         }
       
  1246     else if ( aAccessoryState == EAccModeTextDevice )
       
  1247         {
       
  1248         }
       
  1249     else if ( aAccessoryState == EAccModeWirelessCarKit || aAccessoryState == EAccModeWiredCarKit )
       
  1250         {
       
  1251         }
       
  1252     else if ( aAccessoryState == EAccModeTVOut )
       
  1253         {
       
  1254         }
       
  1255     else if (aAccessoryState == EAccModeHDMI )
       
  1256             {
       
  1257             }
       
  1258 
       
  1259     TInt swState( StateOfProperty( KPSUidStartup, KPSGlobalSystemState ) );
       
  1260     TRACES( RDebug::Print( _L("CSysApAppUi::HandleAccessoryConnectedL: swState: %d"), swState ) );
       
  1261 
       
  1262     if( UiReady() || swState == ESwStateSecurityCheck )
       
  1263         {
       
  1264         iSysApLightsController->AccessoryConnectedL( ETrue );
       
  1265         }
       
  1266 
       
  1267     if ( ( ! iSysApOfflineModeController->OfflineModeActive() ))
       
  1268         {
       
  1269         if ( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApAccessoryConnected ) < 1 )
       
  1270             // accessory not connected already
       
  1271              {
       
  1272             iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApAccessoryConnected, 1 );
       
  1273            }
       
  1274         }
       
  1275     
       
  1276     // Carkit and music stand have also light on permanently option that needs to be checked
       
  1277     if( aAccessoryState == EAccModeWiredCarKit || aAccessoryState == EAccModeMusicStand )
       
  1278         {
       
  1279         // When device is placed on a handsfree cradle, keyguard must be disabled (unless device is locked)
       
  1280         // Note: It is assumed that if carkit/music stand is connected, the phone is in the cradle.
       
  1281         if ( iKeyLockEnabled || iDeviceLockEnabled || iKeyLockOnBeforeCall || iKeyLockOnBeforeAlarm )
       
  1282             {
       
  1283             iKeyLockOnBeforeCradle = ETrue;
       
  1284 
       
  1285             if ( iKeyLockEnabled && !iDeviceLockEnabled )
       
  1286                 {
       
  1287                 iKeyguardController->DisableKeyguard(EFalse);
       
  1288                 }
       
  1289             }
       
  1290         }
       
  1291     SetIhfIndicatorL();
       
  1292     SetHacIndicatorL();
       
  1293     }
       
  1294 
       
  1295 
       
  1296 // ----------------------------------------------------------------------------
       
  1297 // CSysApAppUi::SetHacIndicatorL()
       
  1298 // ----------------------------------------------------------------------------
       
  1299 void CSysApAppUi::SetHacIndicatorL()
       
  1300     {
       
  1301 
       
  1302     if ( !iSysApCenRepHacSettingObserver )
       
  1303         {
       
  1304         // Do nothing if HAC setting observer has not been created yet
       
  1305         // This occurs in case some party is trying to set HAC indicator during
       
  1306         // ConstructL(), e.g. when switching from offline to online during startup
       
  1307         TRACES( RDebug::Print( _L("CSysApAppUi::SetHacIndicatorL: do nothing, HAC observer does not exist yet") ) );
       
  1308         return;
       
  1309         }
       
  1310 
       
  1311     if ( iSysApCenRepHacSettingObserver->HacMode() )
       
  1312         {
       
  1313         TBool accessoryConnected ( EFalse );
       
  1314 
       
  1315         TAccMode accMode(EAccModeHandPortable);
       
  1316 
       
  1317         if ( iSysApAccessoryObserver )
       
  1318             {
       
  1319             accMode = iSysApAccessoryObserver->GetAccessoryMode();
       
  1320 
       
  1321             if ( accMode != EAccModeHandPortable )
       
  1322                 {
       
  1323                 accessoryConnected = ETrue;
       
  1324                 }
       
  1325             }
       
  1326 
       
  1327 //        TInt indicatorState = EAknIndicatorStateOn;
       
  1328 
       
  1329         if ( !accessoryConnected ) // When accessory is not connected, check offline and call state
       
  1330             {
       
  1331             if ( OfflineModeActive() ) // HAC indicator is not shown in offline mode
       
  1332                 {
       
  1333  //               indicatorState = EAknIndicatorStateOff;
       
  1334                 }
       
  1335             else
       
  1336                 {
       
  1337                 // during active call with IHF activated HAC indicator is not shown
       
  1338                 TInt callState( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
       
  1339                 if ( callState < KErrNone )
   561                     {
  1340                     {
   562                     SetIndicatorStateL( iSysApLocationPrivacyIndicator->iIndicatorIdAcceptAll, EAknIndicatorStateOn );
  1341                     callState = EPSCTsyCallStateNone;
   563                     }
  1342                     }
       
  1343 
       
  1344                 if ( callState != EPSCTsyCallStateNone && IhfEnabledL() )
       
  1345                     {
       
  1346  //                   indicatorState = EAknIndicatorStateOff;
       
  1347                     }
       
  1348                 }
       
  1349 
       
  1350             }
       
  1351         else
       
  1352             {
       
  1353             // If an accessory is connected, HAC indicator should not be shown
       
  1354 //            indicatorState = EAknIndicatorStateOff;
       
  1355             }
       
  1356 
       
  1357  //       SetIndicatorStateL( EAknIndicatorHAC, indicatorState );
       
  1358 
       
  1359         }
       
  1360     else
       
  1361         {
       
  1362         // If HAC is not active, always disable indicator regardless of accessory state
       
  1363  //       SetIndicatorStateL( EAknIndicatorHAC, EAknIndicatorStateOff );
       
  1364         }
       
  1365 
       
  1366 
       
  1367     }
       
  1368 
       
  1369 
       
  1370 // ----------------------------------------------------------------------------
       
  1371 // CSysApAppUi::DoNotActivateBt()
       
  1372 // ----------------------------------------------------------------------------
       
  1373 void CSysApAppUi::DoNotActivateBt()
       
  1374     {
       
  1375     iSysApOfflineModeController->DoNotActivateBt();
       
  1376     }
       
  1377 
       
  1378 
       
  1379 // ----------------------------------------------------------------------------
       
  1380 // CSysApAppUi::IhfEnabledL
       
  1381 // ----------------------------------------------------------------------------
       
  1382 
       
  1383 TBool CSysApAppUi::IhfEnabledL()
       
  1384     {
       
  1385     TRACES( RDebug::Print( _L("CSysApAppUi::IhfEnabledL(): iSysApAudioRoutingObserver=0x%x"), iSysApAudioRoutingObserver ) );
       
  1386 
       
  1387     if ( !iSysApAudioRoutingObserver ) // create observer if needed
       
  1388         {
       
  1389         iSysApAudioRoutingObserver = CSysApAudioRoutingObserver::NewL( *this );
       
  1390         }
       
  1391 
       
  1392     return iSysApAudioRoutingObserver->IhfEnabled();
       
  1393     }
       
  1394 
       
  1395 
       
  1396 // ----------------------------------------------------------------------------
       
  1397 // CSysApAppUi::SetIhfIndicatorL()
       
  1398 // ----------------------------------------------------------------------------
       
  1399 void CSysApAppUi::SetIhfIndicatorL()
       
  1400     {
       
  1401     TBool accessoryConnected ( EFalse );
       
  1402 
       
  1403     TInt callState( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
       
  1404 
       
  1405     TAccMode accMode(EAccModeHandPortable);
       
  1406 
       
  1407     if ( iSysApAccessoryObserver )
       
  1408         {
       
  1409         accMode = iSysApAccessoryObserver->GetAccessoryMode();
       
  1410 
       
  1411         if ( accMode != EAccModeHandPortable )
       
  1412             {
       
  1413             accessoryConnected = ETrue;
       
  1414             }
       
  1415         }
       
  1416 
       
  1417     if( (callState != EPSCTsyCallStateNone && IhfEnabledL() && !accessoryConnected)
       
  1418         || accMode == EAccModeMusicStand )  // Music stand always shows IHF indicator
       
  1419         {
       
  1420         if ( accMode == EAccModeMusicStand )
       
  1421             {
       
  1422             // do nothing
       
  1423             }
       
  1424         }
       
  1425     else
       
  1426         {
       
  1427         // do nothing
       
  1428         }
       
  1429     }
       
  1430 
       
  1431 // ----------------------------------------------------------------------------
       
  1432 // CSysApAppUi::DoLightsTimeoutChangedL
       
  1433 // ----------------------------------------------------------------------------
       
  1434 void CSysApAppUi::DoLightsTimeoutChangedL( const TInt aTimeout )
       
  1435     {
       
  1436     iSysApLightsController->DoLightsTimeoutChangedL( aTimeout );
       
  1437     }
       
  1438 
       
  1439 
       
  1440 // ----------------------------------------------------------------------------
       
  1441 // CSysApAppUi::DoSwStateNormalConstructionL()
       
  1442 // ----------------------------------------------------------------------------
       
  1443 
       
  1444 void CSysApAppUi::DoSwStateNormalConstructionL()
       
  1445     {
       
  1446     // Let's ensure that the lights will remain on for 15 secs after sw state normal
       
  1447     User::ResetInactivityTime();
       
  1448 
       
  1449     TRACES( RDebug::Print( _L("CSysApAppUi::DoSwStateNormalConstructionL : START" ) ) );
       
  1450 
       
  1451     // In case of unexpected reset (e.g. hidden boot) the keylock must be enabled silently. Locking is done
       
  1452     // prior to time-consuming initializations, because otherwise UI is in unlocked state for a few seconds.
       
  1453     if ( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApKeyguardActive ) == 1  )
       
  1454         {
       
  1455         TRACES( RDebug::Print( _L("CSysApAppUi::DoSwStateNormalConstructionL: enabling keylock") ) );
       
  1456         iKeyguardController->EnableKeyguard(ETrue);
       
  1457         }
       
  1458 
       
  1459     // Initiate bearer change observation
       
  1460 //    iSysApConnectionMonitorObserver = CSysApConnectionMonitorObserver::NewL( *this );
       
  1461 
       
  1462     TRACES( RDebug::Print( _L("SysAp: trying CSystemLock::NewL" ) ) );
       
  1463     iSysApSystemLock = CSystemLock::NewL();
       
  1464 
       
  1465     
       
  1466     if ( iSysApFeatureManager->Supported( KSysApFeatureIdBatteryInfoPopup ) )
       
  1467         {
       
  1468         iSysApBatteryInfoController = CSysApBatteryInfoController::NewL( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsConf, 
       
  1469                                                                                                      KCoreAppUIsBatteryInformationLowThreshold ) );    
       
  1470         }
       
  1471     TRACES( RDebug::Print( _L("CSysApAppUi::DoSwStateNormalConstructionL : END" ) ) );
       
  1472     }
       
  1473 
       
  1474 
       
  1475 
       
  1476 // ----------------------------------------------------------------------------
       
  1477 // CSysApAppUi::DoSimChangedFromPreviousBootL()
       
  1478 // ----------------------------------------------------------------------------
       
  1479 
       
  1480 void CSysApAppUi::DoSimChangedFromPreviousBootL()
       
  1481     {
       
  1482     TRACES( RDebug::Print( _L("CSysApAppUi::DoSimChangedFromPreviousBootL: iSimChangedDone=%d" ), iSimChangedDone ) );
       
  1483 
       
  1484     if ( !iSimChangedDone  )
       
  1485         {
       
  1486         iSimChangedDone = ETrue;
       
  1487         CSysApSimChanged* simChanged = CSysApSimChanged::NewL( *this, iEikonEnv->FsSession() );
       
  1488         CleanupStack::PushL( simChanged );
       
  1489         simChanged->HandleSimChangedL();
       
  1490         CleanupStack::PopAndDestroy( simChanged );
       
  1491         }
       
  1492     }
       
  1493 
       
  1494 
       
  1495 // ----------------------------------------------------------------------------
       
  1496 // CSysApAppUi::IgnoreZeroNetworkBarNotifications
       
  1497 // ----------------------------------------------------------------------------
       
  1498 //
       
  1499 void CSysApAppUi::IgnoreZeroNetworkBarNotifications(TBool aIgnore)
       
  1500     {
       
  1501     iIgnoreZeroNetworkBarNotifications = aIgnore;
       
  1502     }
       
  1503 
       
  1504 
       
  1505 
       
  1506 // ----------------------------------------------------------------------------
       
  1507 // CSysApAppUi::SwitchFromOnlineToOfflineModeL()
       
  1508 // ----------------------------------------------------------------------------
       
  1509 void CSysApAppUi::SwitchFromOnlineToOfflineModeL()
       
  1510     {
       
  1511    iSysApOfflineModeController->SwitchFromOnlineToOfflineModeL();
       
  1512     }
       
  1513 
       
  1514 
       
  1515 // ----------------------------------------------------------------------------
       
  1516 // CSysApAppUi::InitCloseSimApplicationsL()
       
  1517 // ----------------------------------------------------------------------------
       
  1518 void CSysApAppUi::InitCloseSimApplicationsL()
       
  1519     {
       
  1520     iApplicationScanningRoundNumberInBtSap = 0;
       
  1521     iTimeToKillInBtSap = EFalse;
       
  1522     CloseSimApplicationsL();
       
  1523     }
       
  1524 
       
  1525 
       
  1526 // ----------------------------------------------------------------------------
       
  1527 // CSysApAppUi::CloseSimApplicationsL()
       
  1528 // ----------------------------------------------------------------------------
       
  1529 void CSysApAppUi::CloseSimApplicationsL()
       
  1530     {
       
  1531     iApplicationScanningRoundNumberInBtSap++;
       
  1532     TRACES( RDebug::Print( _L("CSysApAppUi::CloseSimApplicationsL: scanning round = %d"),
       
  1533                            iApplicationScanningRoundNumberInBtSap ) );
       
  1534 
       
  1535     if ( iApplicationScanningRoundNumberInBtSap == KMaxExitTimeInBtSap )
       
  1536         {
       
  1537         iTimeToKillInBtSap = ETrue;
       
  1538         }
       
  1539 
       
  1540     const TInt KNumberOfSimDependantApps( 7 );
       
  1541     TUid simDependantAppUid[ KNumberOfSimDependantApps ];
       
  1542     simDependantAppUid[ 0 ] = KSysApGSUid;
       
  1543     simDependantAppUid[ 1 ] = KSysApSATUid;
       
  1544     simDependantAppUid[ 2 ] = KSysApMailboxUid;
       
  1545     simDependantAppUid[ 3 ] = KSysApSpeedDialingUid;
       
  1546     simDependantAppUid[ 4 ] = KSysApSimDirectoryUid;
       
  1547     simDependantAppUid[ 5 ] = KSysApMCEUid;
       
  1548     simDependantAppUid[ 6 ] = KSysApCellBroadcastMessagesUid;
       
  1549 
       
  1550     TBool appsExiting( EFalse );
       
  1551     TApaTaskList apaTaskList( CCoeEnv::Static()->WsSession() );
       
  1552 
       
  1553     for ( TInt i = 0; i < KNumberOfSimDependantApps; i++ )
       
  1554         {
       
  1555         TApaTask apaTask = apaTaskList.FindApp( simDependantAppUid[ i ] );
       
  1556         if ( apaTask.Exists() )
       
  1557             {
       
  1558             appsExiting = ETrue;
       
  1559             if ( iApplicationScanningRoundNumberInBtSap == 1 )
       
  1560                 {
       
  1561                 apaTask.EndTask();  // applications are kindly requested to close themselves on the first round
       
  1562                 }
       
  1563             else if ( iTimeToKillInBtSap )
       
  1564                 {
       
  1565                 apaTask.KillTask(); // used after timeout on the last round
       
  1566                 }
       
  1567             }
       
  1568         }
       
  1569 
       
  1570     if ( !appsExiting || iTimeToKillInBtSap )
       
  1571         {
       
  1572         iSysApBtSapController->SimApplicationsClosed();
       
  1573         }
       
  1574     else
       
  1575         {
       
  1576         if ( !iSapTimer )
       
  1577             {
       
  1578             iSapTimer = CPeriodic::NewL( EPriorityNormal );
       
  1579             }
       
  1580         iSapTimer->Cancel();
       
  1581         iSapTimer->Start( KDelayBeforeNextScanningRound,
       
  1582                           KDelayBeforeNextScanningRound,
       
  1583                           TCallBack( DoCloseSimApplicationsAfterCallBack, this ) );
       
  1584         }
       
  1585     }
       
  1586 
       
  1587 
       
  1588 // ----------------------------------------------------------------------------
       
  1589 // CSysApAppUi::DoCloseSimApplicationsAfterCallBack
       
  1590 // ----------------------------------------------------------------------------
       
  1591 TInt CSysApAppUi::DoCloseSimApplicationsAfterCallBack( TAny* aObject )
       
  1592     {
       
  1593     CSysApAppUi* appUi = STATIC_CAST( CSysApAppUi*, aObject );
       
  1594 
       
  1595     if ( appUi->iSapTimer )
       
  1596         {
       
  1597         appUi->iSapTimer->Cancel();
       
  1598         }
       
  1599 
       
  1600     TRAP_IGNORE( appUi->CloseSimApplicationsL() );
       
  1601 
       
  1602     return KErrNone;
       
  1603     }
       
  1604 
       
  1605 
       
  1606 // ----------------------------------------------------------------------------
       
  1607 // CSysApAppUi::NotifyPowerSaveModeL
       
  1608 // ----------------------------------------------------------------------------
       
  1609 //
       
  1610 void CSysApAppUi::NotifyPowerSaveModeL( TSysApPsmStatus aStatus )
       
  1611     {
       
  1612     TRACES( RDebug::Print( _L("CSysApAppUi::NotifyPowerSaveModeL aStatus: %d"), aStatus ) );
       
  1613 
       
  1614     // cancel any active power saving query because user has changed the state manually
       
  1615     // CancelQuery( ESysApBattChargingPowerSavingQuery );
       
  1616     // CancelQuery( ESysApBattLowPowerSavingQuery );
       
  1617     // will take care in next sub
       
  1618     
       
  1619     switch ( aStatus )
       
  1620         {
       
  1621         case MSysApPsmControllerNotifyCallback::EPsmActivationComplete:
       
  1622              UpdateBatteryBarsL( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
  1623              ShowUiNoteL( EPowerSaveModeActivated );
       
  1624              break;
       
  1625         
       
  1626         case MSysApPsmControllerNotifyCallback::EPsmDeactivationComplete:
       
  1627              UpdateBatteryBarsL( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
  1628              ShowUiNoteL( EPowerSaveModeDeactivated );
       
  1629              break;
       
  1630             
       
  1631         case MSysApPsmControllerNotifyCallback::EPsmActivationFailed:
       
  1632             ShowUiNoteL( ECannotActivatePowerSaveMode );
       
  1633             break;
       
  1634             
       
  1635         case MSysApPsmControllerNotifyCallback::EPsmDeactivationFailed:
       
  1636             ShowUiNoteL( ECannotDeactivatePowerSaveMode );
       
  1637             break;            
       
  1638         
       
  1639         default:
       
  1640             break;   
       
  1641         }
       
  1642     }
       
  1643 
       
  1644 
       
  1645 // ----------------------------------------------------------------------------
       
  1646 // CSysApAppUi::ShowAlarmIndicatorL()
       
  1647 // ----------------------------------------------------------------------------
       
  1648 
       
  1649 void CSysApAppUi::ShowAlarmIndicatorL( TBool aShowIndicator )
       
  1650     {
       
  1651     if ( aShowIndicator)
       
  1652         {
       
  1653         // do nothing
       
  1654         }
       
  1655     else
       
  1656         {
       
  1657         // do nothing
       
  1658         }
       
  1659     }
       
  1660 
       
  1661 
       
  1662 // ----------------------------------------------------------------------------
       
  1663 // CSysApAppUi::AlertUiAlertingL( const TBool aAlerting )
       
  1664 // ----------------------------------------------------------------------------
       
  1665 void CSysApAppUi::AlertUiAlertingL( const TBool aAlerting )
       
  1666     {
       
  1667     TRACES( RDebug::Print( _L("CSysApAppUi::AlertUiAlerting aAlerting:%d"), aAlerting ) );
       
  1668 
       
  1669     if ( aAlerting )
       
  1670         {
       
  1671         TInt swState;
       
  1672         RProperty::Get( KPSUidStartup, KPSGlobalSystemState, swState );
       
  1673 
       
  1674         if( swState == ESwStateCharging )
       
  1675             {
       
  1676             SetStarterState( RStarterSession::EAlarm );
       
  1677             }
       
  1678         }
       
  1679 
       
  1680     iSysApLightsController->AlarmOccuredL( aAlerting );
       
  1681     }
       
  1682 
       
  1683 
       
  1684 // ----------------------------------------------------------------------------
       
  1685 // CSysApAppUi::HandleForcedLightsVTRequireL( const TInt aLightParameter )
       
  1686 // ----------------------------------------------------------------------------
       
  1687 
       
  1688 void CSysApAppUi::HandleForcedLightsVTRequireL( const TInt aLightsParameter ) const
       
  1689     {
       
  1690     iSysApLightsController->HandleForcedLightsVTRequireL( aLightsParameter );
       
  1691     }
       
  1692 
       
  1693 
       
  1694 // ----------------------------------------------------------------------------
       
  1695 // CSysApAppUi::HandleForcedLightsSSRequireL( const TInt aLightParameter )
       
  1696 // ----------------------------------------------------------------------------
       
  1697 
       
  1698 void CSysApAppUi::HandleForcedLightsSSRequireL( const TInt aLightsParameter ) const
       
  1699     {
       
  1700     iSysApLightsController->HandleForcedLightsSSRequireL( aLightsParameter );
       
  1701     }
       
  1702 
       
  1703 // ---------------------------------------------------------------------------- 
       
  1704 // CSysApAppUi::HandleForcedLightsATCRequireL( const TInt aLightParameter ) 
       
  1705 // ---------------------------------------------------------------------------- 
       
  1706 void CSysApAppUi::HandleForcedLightsATCRequireL( const TInt aLightsParameter ) const 
       
  1707     { 
       
  1708     iSysApLightsController->HandleForcedLightsATCRequireL( aLightsParameter ); 
       
  1709     } 
       
  1710 
       
  1711 
       
  1712 // ----------------------------------------------------------------------------
       
  1713 // CSysApAppUi::HandleLightsRequireL()
       
  1714 // ----------------------------------------------------------------------------
       
  1715 
       
  1716 void CSysApAppUi::HandleLightsRequireL() const
       
  1717     {
       
  1718     iSysApLightsController->HandleLightsRequireL();
       
  1719     }
       
  1720 
       
  1721 
       
  1722 // ----------------------------------------------------------------------------
       
  1723 // CSysApAppUi::AlertUiKeyLockOff( const TBool aKeyLockOff )
       
  1724 // ----------------------------------------------------------------------------
       
  1725 
       
  1726 void CSysApAppUi::AlertUiKeyLockOff( const TBool aKeyLockOff )
       
  1727     {
       
  1728     TRACES( RDebug::Print( _L("CSysApAppUi::AlertUiKeyLockOff aKeyLockOff:%d, devicelock:%d"), 
       
  1729         aKeyLockOff, iDeviceLockEnabled ) );
       
  1730     
       
  1731     if( aKeyLockOff )
       
  1732         {
       
  1733         // Notification to release keypad might come several times if e.g. calls are received
       
  1734         if ( !iKeyLockOnBeforeAlarm )
       
  1735             {
       
  1736             if ( iKeyLockEnabled || iKeyLockOnBeforeCradle || iKeyLockOnBeforeCall )
       
  1737                 {
       
  1738                 iKeyLockOnBeforeAlarm = ETrue;
       
  1739                 }
       
  1740             }
       
  1741         iKeyguardController->DisableKeyguard(EFalse);
       
  1742         }
       
  1743     else
       
  1744         {
       
  1745         if (iDeviceLockEnabled)
       
  1746             {
       
  1747             // Re-enable keylock in devicelock case only if phone call is not ongoing or is 
       
  1748             // connected. Otherwise e.g. messages can be read using softkeys during ongoing call.
       
  1749             TInt callState( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
       
  1750             if ( callState == EPSCTsyCallStateNone || callState == EPSCTsyCallStateConnected )
       
  1751                 {
       
  1752                 iKeyguardController->EnableKeyguard(EFalse);
       
  1753                 }
       
  1754             }
       
  1755         else if ( iKeyLockOnBeforeAlarm && !iKeyLockOnBeforeCradle && !iKeyLockOnBeforeCall )
       
  1756             {
       
  1757             iKeyguardController->EnableKeyguard(ETrue);
       
  1758             }
       
  1759         iKeyLockOnBeforeAlarm = EFalse;
       
  1760         }
       
  1761     }
       
  1762 
       
  1763 
       
  1764 // ----------------------------------------------------------------------------
       
  1765 // CSysApAppUi::DoNotEnableKeylock()
       
  1766 // ----------------------------------------------------------------------------
       
  1767 
       
  1768 void CSysApAppUi::DoNotEnableKeylock()
       
  1769     {
       
  1770     if ( !iKeyLockOnBeforeCradle )
       
  1771         {
       
  1772         iShowkeypadActivatedNoteAfterSoftReject = iKeyLockOnBeforeCall;
       
  1773         }
       
  1774 
       
  1775     iKeyLockOnBeforeCall = EFalse;
       
  1776     }
       
  1777 
       
  1778 
       
  1779 // ----------------------------------------------------------------------------
       
  1780 // CSysApAppUi::SwitchLightsOnSoftRejectL()
       
  1781 // ----------------------------------------------------------------------------
       
  1782 void CSysApAppUi::SwitchLightsOnSoftRejectL()
       
  1783     {
       
  1784     iSysApLightsController->SwitchLightsOnSoftRejectL();
       
  1785     }
       
  1786 
       
  1787 
       
  1788 // ----------------------------------------------------------------------------
       
  1789 // CSysApAppUi::SetDeviceLockEnabledL( const TBool aLockEnabled )
       
  1790 // ----------------------------------------------------------------------------
       
  1791 
       
  1792 void CSysApAppUi::SetDeviceLockEnabledL( const TBool aLockEnabled )
       
  1793     {
       
  1794     TRACES( RDebug::Print(_L("CSysApAppUi::SetDeviceLockEnabledL aLockEnabled:%d" ), aLockEnabled ) );
       
  1795     TBool currentState( iDeviceLockEnabled );
       
  1796     
       
  1797     iDeviceLockEnabled = aLockEnabled;
       
  1798     
       
  1799     if ( currentState != iDeviceLockEnabled ) // filter out unnecessary light status modifications
       
  1800         {
       
  1801         iSysApLightsController->DeviceLockStateChangedL( iDeviceLockEnabled );
       
  1802         }
       
  1803     
       
  1804     if( iDeviceLockEnabled )
       
  1805         {
       
  1806         if( iKeyLockEnabled )
       
  1807             {
       
  1808             iKeyguardController->DisableKeyguard(EFalse);
       
  1809             }
       
  1810         }
       
  1811     else
       
  1812         {
       
  1813         // let's not activate keylock in case device lock was disabled during call or in cradle
       
  1814         iKeyLockOnBeforeCall = EFalse;
       
  1815         iKeyLockOnBeforeCradle = EFalse;
       
  1816 
       
  1817         // Memory card needs to be unlocked when device is unlocked
       
  1818         if ( iSysApFeatureManager->MmcHotSwapSupported() )
       
  1819             {
       
  1820             // RunUnlockNotifierL();
       
  1821             // Need to handle feature for unlocking the MMC card
       
  1822             }
       
  1823         }
       
  1824     }
       
  1825 
       
  1826 
       
  1827 // ----------------------------------------------------------------------------
       
  1828 // CSysApAppUi::HandleBatteryStatusL
       
  1829 // ----------------------------------------------------------------------------
       
  1830 //
       
  1831 void CSysApAppUi::HandleBatteryStatusL( const TInt aValue )
       
  1832     {
       
  1833     TRACES( RDebug::Print( _L("CSysApAppUi::HandleBatteryStatusL aValue: %d"), aValue ) );
       
  1834     
       
  1835     if ( aValue == EBatteryStatusEmpty )
       
  1836         {
       
  1837         //Display Recharge Battery note
       
  1838         ShowUiNoteL( ERechargeBatteryNote );
       
  1839         BatteryEmptyL();
       
  1840         }
       
  1841     else if ( aValue == EBatteryStatusLow )
       
  1842         {
       
  1843         if ( iSysApPsmController && UiReady() )
       
  1844             {
       
  1845             iSysApPsmController->BatteryLow( ETrue );
       
  1846             
       
  1847                        
       
  1848             if ( iSysApPsmController->ShowActivateQuery())
       
  1849                 {
       
  1850                 // show activation query, replaces the first battery low query
       
  1851                 ShowQueryL( ESysApBattLowPowerSavingQuery );
       
  1852                 }
       
  1853             else // default low warning note must be shown
       
  1854                 {
       
  1855                 // activate partial power save mode on first low warning
       
  1856                 iSysApPsmController->DoEnablePartialPsm( ETrue ); // activated on first warning note
       
  1857                 //Display Battery Low note.
       
  1858                 ShowUiNoteL( EBatteryLowNote );    
       
  1859                 }                
       
  1860             }
       
  1861         else
       
  1862             {
       
  1863             //Display Battery Low note.
       
  1864             ShowUiNoteL( EBatteryLowNote );     
       
  1865             }            
       
  1866         }
       
  1867         
       
  1868     if ( iSysApBatteryInfoController )
       
  1869     {
       
  1870      iSysApBatteryInfoController->BatteryStatusUpdated( aValue );
       
  1871     }
       
  1872       
       
  1873    }
       
  1874 
       
  1875 // ----------------------------------------------------------------------------
       
  1876 // CSysApAppUi::ShowUiNoteL( const TSysApNoteIds aNote ) const
       
  1877 // ----------------------------------------------------------------------------
       
  1878 
       
  1879 void CSysApAppUi::ShowUiNoteL( const TSysApNoteIds aNote ) const
       
  1880     {
       
  1881     TRACES( RDebug::Print( _L("CSysApAppUi::ShowUiNoteL aNote: %d"), aNote ) );
       
  1882     
       
  1883     TInt swState( StateOfProperty( KPSUidStartup, KPSGlobalSystemState ) );
       
  1884 
       
  1885     if( UiReady() || swState == ESwStateSecurityCheck)
       
  1886       {
       
  1887           switch ( aNote )
       
  1888             {
       
  1889             case EBatteryLowNote:
       
  1890                 {
       
  1891                  _LIT(KPowerPressKey,"Battery low");
       
  1892                  HBufC* aString = HBufC16::NewLC(100);
       
  1893                  TPtrC aStringPointer = aString->Des();
       
  1894                  aStringPointer.Set(KPowerPressKey);
       
  1895                  TRACES( RDebug::Print( _L("CSysApWsClient::RunL(): Key EEventKeyUp 01") ) );   
       
  1896                  ShowExampleUiNoteL( aStringPointer );
       
  1897                  CleanupStack::PopAndDestroy(); // aString
       
  1898                 }
   564                 break;
  1899                 break;
   565             case EPSLocPrivRejectAll:
  1900             case EBatteryFullNote:
   566                 if ( iSysApLocationPrivacyIndicator->iIndicatorIdRejectAll != KSysApNoIndicator )
  1901                 {
   567                     {
  1902                 _LIT(KPowerPressKey,"Battery full");
   568                     SetIndicatorStateL( iSysApLocationPrivacyIndicator->iIndicatorIdRejectAll, EAknIndicatorStateOn );
  1903                 HBufC* aString = HBufC16::NewLC(100);
   569                     }
  1904                 TPtrC aStringPointer = aString->Des();
       
  1905                 aStringPointer.Set(KPowerPressKey);
       
  1906                 TRACES( RDebug::Print( _L("CSysApWsClient::RunL(): Key EEventKeyUp 01") ) );   
       
  1907                 ShowExampleUiNoteL( aStringPointer );
       
  1908                 CleanupStack::PopAndDestroy(); // aString
       
  1909                 }
   570                 break;
  1910                 break;
   571             case EPSLocPrivAlwaysAsk:
  1911             case ERechargeBatteryNote:
   572                 if ( iSysApLocationPrivacyIndicator->iIndicatorIdAlwaysAsk != KSysApNoIndicator )
  1912                 {
   573                     {
  1913                 iSysApLightsController->BatteryEmptyL( ETrue );
   574                     SetIndicatorStateL( iSysApLocationPrivacyIndicator->iIndicatorIdAlwaysAsk, EAknIndicatorStateOn );
  1914                 _LIT(KPowerPressKey,"Battery empty. Recharge");
   575                     }
  1915                 HBufC* aString = HBufC16::NewLC(100);
       
  1916                 TPtrC aStringPointer = aString->Des();
       
  1917                 aStringPointer.Set(KPowerPressKey);
       
  1918                 TRACES( RDebug::Print( _L("CSysApWsClient::RunL(): Key EEventKeyUp 01") ) );   
       
  1919                 ShowExampleUiNoteL( aStringPointer );
       
  1920                 CleanupStack::PopAndDestroy(); // aString
       
  1921                 }
   576                 break;
  1922                 break;
   577             case EPSLocPrivIndividualPrivacy:
  1923             case ENotChargingNote:
   578                 if ( iSysApLocationPrivacyIndicator->iIndicatorIdIndividualPrivacy != KSysApNoIndicator )
  1924                 {
   579                     {
  1925                 _LIT(KPowerPressKey,"Not charging");
   580                     SetIndicatorStateL( iSysApLocationPrivacyIndicator->iIndicatorIdIndividualPrivacy, EAknIndicatorStateOn );
  1926                 HBufC* aString = HBufC16::NewLC(100);
   581                     }
  1927                 TPtrC aStringPointer = aString->Des();
       
  1928                 aStringPointer.Set(KPowerPressKey);
       
  1929                 TRACES( RDebug::Print( _L("CSysApWsClient::RunL(): Key EEventKeyUp 01") ) );   
       
  1930                 ShowExampleUiNoteL( aStringPointer );
       
  1931                 CleanupStack::PopAndDestroy(); // aString
       
  1932                 }
       
  1933                 break;
       
  1934             case EBatteryFullUnplugChargerNote:
       
  1935                 {
       
  1936                 /*	
       
  1937                 TRACES( RDebug::Print( _L("CSysApWsClient::RunL(): Key EEventKeyUp 01") ) ); 
       
  1938                 iSysApLightsController->BatteryEmptyL( ETrue );
       
  1939                  _LIT(KunplugCharger,"txt_power_dpopinfo_unplug_charger_to_save_energy");                 
       
  1940                  HBufC* unplugCharger = HbTextResolverSymbian::LoadL(KunplugCharger);
       
  1941                  _LIT(KbatteryFull,"txt_power_management_dpophead_100_full");
       
  1942                  HBufC* batteryFull = HbTextResolverSymbian::LoadL(KbatteryFull);
       
  1943                  CHbDeviceNotificationDialogSymbian::NotificationL(KbatteryFullIcon,*unplugCharger,*batteryFull);  
       
  1944                  */
       
  1945                  
       
  1946                  iSysApLightsController->BatteryEmptyL( ETrue );
       
  1947                  _LIT(KPowerPressKey,"Charging complete. Unplug charger to save energy.");
       
  1948                  HBufC* aString = HBufC16::NewLC(200);
       
  1949                  TPtrC aStringPointer = aString->Des();
       
  1950                  aStringPointer.Set(KPowerPressKey);
       
  1951                  TRACES( RDebug::Print( _L("CSysApWsClient::RunL(): Key EEventKeyUp 01") ) );   
       
  1952                  ShowExampleUiNoteL( aStringPointer );
       
  1953                  CleanupStack::PopAndDestroy(); // aString     
       
  1954                  }
       
  1955                 break;
       
  1956             case EUnplugChargerNote:
       
  1957                 {
       
  1958                 _LIT(KPowerPressKey,"Unplug charger from power supply to save energy");
       
  1959                 HBufC* aString = HBufC16::NewLC(250);
       
  1960                 TPtrC aStringPointer = aString->Des();
       
  1961                 aStringPointer.Set(KPowerPressKey);
       
  1962                 TRACES( RDebug::Print( _L("CSysApWsClient::RunL(): Key EEventKeyUp 01") ) );   
       
  1963                 ShowExampleUiNoteL( aStringPointer );
       
  1964                 CleanupStack::PopAndDestroy(); // aString
       
  1965                 }
   582                 break;
  1966                 break;
   583             default:
  1967             default:
   584                 break;
  1968                 break;
   585             }
  1969             }
   586         }
  1970         }
   587     }
  1971     }
   588 
  1972 
   589 
  1973 
   590 // ----------------------------------------------------------------------------
  1974 // ----------------------------------------------------------------------------
       
  1975 // CSysApAppUi::BatteryEmptyL()
       
  1976 // ----------------------------------------------------------------------------
       
  1977 
       
  1978 void CSysApAppUi::BatteryEmptyL()
       
  1979     {
       
  1980     iSysApLightsController->BatteryEmptyL( ETrue );
       
  1981     // Do not reactivate keyguard in the next startup
       
  1982     iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApKeyguardActive, 0 );
       
  1983     }
       
  1984 
       
  1985 
       
  1986 // ----------------------------------------------------------------------------
       
  1987 // CSysApAppUi::ShowQueryL()
       
  1988 // ----------------------------------------------------------------------------
       
  1989 
       
  1990 void CSysApAppUi::ShowQueryL( const TSysApConfirmationQueryIds /* aQueryId */, const TDesC& /* aValue */)
       
  1991     {
       
  1992     // do nothing
       
  1993     }
       
  1994 
       
  1995 
       
  1996 
       
  1997 // ----------------------------------------------------------------------------
       
  1998 // CSysApAppUi::HandleChargingStatusL
       
  1999 // ----------------------------------------------------------------------------
       
  2000 //
       
  2001 void CSysApAppUi::HandleChargingStatusL( const TInt aValue )
       
  2002     {
       
  2003     TRACES( RDebug::Print( _L("CSysApAppUi::HandleChargingStatusL aValue: %d"), aValue ) );
       
  2004     
       
  2005     TBool showNote( ETrue );
       
  2006     
       
  2007     UpdateBatteryBarsL( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
  2008 
       
  2009     if ( iSysApPsmController && UiReady() ) 
       
  2010         {             
       
  2011         if ( iCharging && !iSysApPsmController->ChargerConnected() ) // first time after charger connection
       
  2012             {
       
  2013             iSysApPsmController->ConnectCharger( ETrue );
       
  2014             if ( iSysApPsmController->ShowDeactivateQuery() )
       
  2015                 {
       
  2016                 ShowQueryL( ESysApBattChargingPowerSavingQuery );
       
  2017                 // Query is on the display. Don't show the note.
       
  2018                 showNote = EFalse;               
       
  2019                 }
       
  2020             else
       
  2021                 {
       
  2022                 iSysApPsmController->DoEnablePartialPsm( EFalse );
       
  2023                 }              
       
  2024             }
       
  2025         else if ( aValue == EChargingStatusNotConnected )
       
  2026             {
       
  2027             iSysApPsmController->ConnectCharger( EFalse );
       
  2028             }            
       
  2029         }
       
  2030     if( showNote )
       
  2031         {
       
  2032         HandleChargerNotesL( aValue );    
       
  2033         }
       
  2034     }
       
  2035 
       
  2036 
       
  2037 // ----------------------------------------------------------------------------
       
  2038 // CSysApAppUi::HandleChargerNotesL()
       
  2039 // ----------------------------------------------------------------------------
       
  2040 void CSysApAppUi::HandleChargerNotesL( const TInt aValue )
       
  2041     {
       
  2042     TBool showNote(StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) !=  EPSCTsyCallStateRinging);
       
  2043     if ( aValue == EChargingStatusCharging )
       
  2044         {
       
  2045         iSysApLightsController->BatteryEmptyL( EFalse );
       
  2046         TRACES( RDebug::Print( _L("SysAp: charger connected") ) );
       
  2047         iSysApLightsController->ChargerConnectedL( ETrue );
       
  2048         ShowChargingNoteL();
       
  2049         }
       
  2050     //Display Not Charging note
       
  2051     else if ( aValue == EChargingStatusError )
       
  2052         {
       
  2053         if(showNote)
       
  2054             {
       
  2055             ShowUiNoteL( ENotChargingNote );
       
  2056             }
       
  2057         }
       
  2058     else if ( aValue == EChargingStatusChargingComplete )
       
  2059         {
       
  2060         iSysApLightsController->ChargingCompleteL();
       
  2061         
       
  2062         TSysApNoteIds note( EBatteryFullNote );
       
  2063         
       
  2064         if ( !iSysApUsbChargerDetector.HostOnlyUsbChargingUsed() &&
       
  2065              iSysApFeatureManager->Supported( KSysApFeatureIdChargerReminderNotes ) )
       
  2066             {
       
  2067             note = EBatteryFullUnplugChargerNote;
       
  2068             }
       
  2069         iSysApUsbChargerDetector.Reset();
       
  2070         if(showNote)
       
  2071             {
       
  2072             ShowUiNoteL( note );
       
  2073             }
       
  2074         }
       
  2075     else if ( aValue == EChargingStatusNotConnected )
       
  2076         {
       
  2077         TRACES( RDebug::Print( _L("SysAp: charger removed") ) );
       
  2078         iSysApLightsController->ChargerConnectedL( EFalse );
       
  2079         
       
  2080         if ( !iSysApUsbChargerDetector.HostOnlyUsbChargingUsed() &&
       
  2081              iSysApFeatureManager->Supported( KSysApFeatureIdChargerReminderNotes ) )
       
  2082             {
       
  2083         if(showNote)
       
  2084                 {
       
  2085                 ShowUiNoteL( EUnplugChargerNote );
       
  2086                 }
       
  2087             }
       
  2088         iSysApUsbChargerDetector.Reset();
       
  2089         }
       
  2090     else if ( aValue == EChargingStatusNotCharging )
       
  2091         {
       
  2092         TRACES( RDebug::Print( _L("SysAp: Not charging") ) );
       
  2093         }
       
  2094     else if ( aValue == EChargingStatusAlmostComplete )
       
  2095         {
       
  2096         TRACES( RDebug::Print( _L("SysAp: Charging almost complete") ) );
       
  2097         }
       
  2098     else if ( aValue == EChargingStatusChargingContinued )
       
  2099         {
       
  2100         //in this case we simply want to scroll the battery bars and not turn light on or show ui note
       
  2101         // set lights controller iBatteryEmpty to EFalse
       
  2102         iSysApLightsController->BatteryEmptyL( EFalse );
       
  2103         TRACES( RDebug::Print( _L("SysAp: charging continues") ) );
       
  2104         }
       
  2105     }
       
  2106 
       
  2107 
       
  2108 // ----------------------------------------------------------------------------
       
  2109 // CSysApAppUi::UpdateBatteryBarsL( const TInt aState )
       
  2110 // ----------------------------------------------------------------------------
       
  2111 
       
  2112 void CSysApAppUi::UpdateBatteryBarsL( const TInt  /* aState */)
       
  2113     {
       
  2114     TInt state( StateOfProperty( KPSUidHWRMPowerState, KHWRMChargingStatus ) );
       
  2115 //    TRACES( RDebug::Print( _L("CSysApAppUi::UpdateBatteryBarsL aState: %d, chargerState:%d"), aState, state ) );
       
  2116     HandleUsbCharger( state );
       
  2117     if( state == EChargingStatusCharging ||
       
  2118         state == EChargingStatusChargingContinued ||
       
  2119         state == EChargingStatusAlmostComplete )
       
  2120         {
       
  2121         if ( !iCharging )
       
  2122             {
       
  2123             TRACES( RDebug::Print( _L("CSysApAppUi::UpdateBatteryBarsL: Starting Charging") ) );
       
  2124             iCharging = ETrue;
       
  2125             }
       
  2126         }
       
  2127     else
       
  2128         {
       
  2129         if ( iCharging )
       
  2130             {
       
  2131             TRACES( RDebug::Print( _L("CSysApAppUi::UpdateBatteryBarsL: Stopping Charging") ) );
       
  2132             iCharging = EFalse;
       
  2133             }
       
  2134         }
       
  2135     
       
  2136     if ( !iSysApPsmController ) // created here if first state change has not occurred yet
       
  2137         {
       
  2138         iSysApPsmController = CSysApPsmController::NewL( *this );        
       
  2139         }
       
  2140 
       
  2141     if ( iSysApPsmController )
       
  2142         {
       
  2143         if ( iSysApPsmController->FullPsmEnabled() )
       
  2144             {
       
  2145              // activate psm indicator 
       
  2146             }
       
  2147         else
       
  2148             {
       
  2149             // deactivate psm indicator
       
  2150             }            
       
  2151         }
       
  2152         
       
  2153        if ( iSysApBatteryInfoController )        
       
  2154         {
       
  2155          iSysApBatteryInfoController->BatteryLevelUpdatedL();
       
  2156         }
       
  2157         
       
  2158      }
       
  2159 
       
  2160 
       
  2161 
       
  2162 // ----------------------------------------------------------------------------
       
  2163 // CSysApAppUi::ShowChargingNoteL()
       
  2164 // ----------------------------------------------------------------------------
       
  2165 
       
  2166 void CSysApAppUi::ShowChargingNoteL()
       
  2167     {
       
  2168     TRACES( RDebug::Print( _L("CSysApAppUi::ShowChargingNoteL") ) );
       
  2169     TBool showNote( ETrue );
       
  2170 
       
  2171     TInt swState( StateOfProperty( KPSUidStartup, KPSGlobalSystemState ) );
       
  2172     TRACES( RDebug::Print( _L("CSysApAppUi::ShowChargingNoteL: swState: %d"), swState ) );
       
  2173 
       
  2174     if( UiReady() || swState == ESwStateSecurityCheck )
       
  2175         {
       
  2176         if ( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) ==  EPSCTsyCallStateRinging )
       
  2177             {
       
  2178             showNote = EFalse;
       
  2179             }
       
  2180         TRACES( RDebug::Print( _L("CSysApAppUi::ShowChargingNoteL KCTsyCallState=%d"), StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) ) );
       
  2181         if ( showNote ) // Power Mgmt UI spec defines that no Charging note is shown while the phone is ringing/alerting
       
  2182             {
       
  2183             /* 
       
  2184             TRACES( RDebug::Print( _L("CSysApWsClient::RunL(): Key EEventKeyUp 01") ) );   
       
  2185             _LIT(KChargingNote,"txt_power_management_dblist_charging");
       
  2186             HBufC* chargingNote = HbTextResolverSymbian::LoadL(KChargingNote);
       
  2187             CHbDeviceNotificationDialogSymbian::NotificationL(KNullDesC,*chargingNote);     
       
  2188             */
       
  2189              
       
  2190             _LIT(KChargingNote,"Charging");
       
  2191             HBufC* aString = HBufC16::NewLC(50);
       
  2192             TPtrC aStringPointer = aString->Des();
       
  2193             aStringPointer.Set(KChargingNote);
       
  2194             TRACES( RDebug::Print( _L("CSysApWsClient::RunL(): Key EEventKeyUp 01") ) );   
       
  2195             ShowExampleUiNoteL( aStringPointer );
       
  2196             CleanupStack::PopAndDestroy(); // aString            
       
  2197             }
       
  2198         }
       
  2199     }
       
  2200 
       
  2201 
       
  2202 // ----------------------------------------------------------------------------
       
  2203 // CSysApAppUi::HandleUsbCharger
       
  2204 // ----------------------------------------------------------------------------
       
  2205 //
       
  2206 void CSysApAppUi::HandleUsbCharger( const TInt aValue )
       
  2207     {        
       
  2208     if ( aValue == EChargingStatusCharging ||
       
  2209          aValue == EChargingStatusChargingContinued ||
       
  2210          aValue == EChargingStatusAlmostComplete )
       
  2211         {
       
  2212         iSysApUsbChargerDetector.SetChargingUsed( ETrue );
       
  2213         if ( !iSysApUsbIndicatorController &&
       
  2214              iSysApFeatureManager->Supported( KSysApFeatureIdChargerReminderNotes ) &&
       
  2215              iSysApFeatureManager->Supported( KSysApFeatureIdUsbChargingWithoutReminderNotes ) )
       
  2216             {
       
  2217             // Start observing USB state for the reminder note
       
  2218             TRAPD ( usbErr, iSysApUsbIndicatorController = CreateSysApUsbIndicatorL( *this ) );
       
  2219             if ( usbErr )
       
  2220                 {
       
  2221                 TRACES( RDebug::Print(
       
  2222                     _L("CSysApAppUi::HandleUsbCharger: error in constructing USB ind. controller %d" ),
       
  2223                     usbErr ) );
       
  2224                 }
       
  2225             }
       
  2226         }
       
  2227     }
       
  2228 
       
  2229 // ----------------------------------------------------------------------------
       
  2230 // CSysApAppUi::HandleCurrentCallStateChangeL()
       
  2231 // ----------------------------------------------------------------------------
       
  2232 
       
  2233 void CSysApAppUi::HandleCurrentCallStateChangeL( TInt aCurrentCallState )
       
  2234     {
       
  2235     TRACES( RDebug::Print( _L("CSysApAppUi::HandleCurrentCallStateChangeL: KUidCurrentCall: %d" ), aCurrentCallState ) );
       
  2236 
       
  2237     switch ( aCurrentCallState )
       
  2238         {
       
  2239         case EPSCTsyCallStateRinging:
       
  2240             {
       
  2241             iSysApLightsController->CallComingInL( ETrue );
       
  2242             // Disable keylock when a call is coming in
       
  2243             if ( iKeyLockEnabled || iDeviceLockEnabled || iKeyLockOnBeforeCradle || iKeyLockOnBeforeAlarm )
       
  2244                 {
       
  2245                 TRACES( RDebug::Print( _L("CSysApAppUi::HandleCurrentCallStateChangeL: EPSCTsyCallStateRinging: disable keylock") ) );
       
  2246                 iKeyLockOnBeforeCall = ETrue;
       
  2247 
       
  2248                 if ( iKeyLockEnabled || iDeviceLockEnabled )
       
  2249                     {
       
  2250                     if ( !iSysApFeatureManager->TouchUnlockStrokeSupported() )
       
  2251                         {
       
  2252                         iKeyguardController->DisableKeyguard(EFalse);
       
  2253                         }
       
  2254                     }
       
  2255                 }
       
  2256             break;
       
  2257             }
       
  2258             
       
  2259         case EPSCTsyCallStateDialling:
       
  2260             {
       
  2261             // Disable keypad lock during an emergency call
       
  2262             // no need to disable the key lock when a call is made using the wireless car-kit
       
  2263             // but if the call is an emergency one then we will disable the keypad lock
       
  2264             if ( iKeyLockEnabled || iDeviceLockEnabled || iKeyLockOnBeforeCradle )
       
  2265                 {
       
  2266                 TRACES( RDebug::Print( _L("CSysApAppUi::HandleCurrentCallStateChangeL: EPSCTsyCallStateDialling: disable keylock") ) );
       
  2267                 iKeyLockOnBeforeCall = ETrue;
       
  2268 
       
  2269                 if ( IsEmergencyCall() && (iKeyLockEnabled || iDeviceLockEnabled ))
       
  2270                     {
       
  2271                     iKeyguardController->DisableKeyguard(EFalse);
       
  2272                     }
       
  2273                 }
       
  2274 
       
  2275             // Enable signal & network indicators when an emergency call is made in Offline Mode
       
  2276             if( iSysApOfflineModeController->OfflineModeActive() )
       
  2277                     {
       
  2278                     // Signal indicators not updated with VoIP call
       
  2279                     if ( StateOfProperty(KPSUidCtsyCallInformation, KCTsyCallType) != EPSCTsyCallTypeVoIP) 
       
  2280                         {
       
  2281                         iEmergencyCallActive = ETrue;
       
  2282                         // not supporting this
       
  2283                         // UpdateSignalBarsL();
       
  2284                         // SetSignalIndicatorL();
       
  2285                         }
       
  2286                     }
       
  2287             break;
       
  2288             }
       
  2289             
       
  2290         case EPSCTsyCallStateConnected:
       
  2291             {
       
  2292             if (StateOfProperty(KPSUidCtsyCallInformation, KCTsyCallType) == EPSCTsyCallTypeCSVoice)
       
  2293                 {
       
  2294                 // Check if GPRS suspended note is required
       
  2295                 iCallActivated = ETrue;
       
  2296                 // not supporting this
       
  2297                 // HandleGprsNotesL();
       
  2298                 }
       
  2299             if ( iDeviceLockEnabled )
       
  2300                 {
       
  2301                 // Enable keylock via autolock emulation if device lock enabled. 
       
  2302                 // Otherwise e.g. messages can be read using softkeys during ongoing call.
       
  2303                 iKeyguardController->EnableKeyguard(EFalse);
       
  2304                 }
       
  2305             break;
       
  2306             }
       
  2307 
       
  2308         case EPSCTsyCallStateNone:
       
  2309             {
       
  2310             // Reset timers in ScreenSaver and Autolock
       
  2311             User::ResetInactivityTime();
       
  2312 
       
  2313             if ( iEmergencyCallActive )
       
  2314                 {
       
  2315                 iEmergencyCallActive = EFalse;
       
  2316                 // not supporting this
       
  2317                 // UpdateSignalBarsL( 0 );
       
  2318                 // SetSignalIndicatorL();
       
  2319                 }
       
  2320             if ( iKeyLockOnBeforeCall )
       
  2321                 {
       
  2322                 TRACES( RDebug::Print( _L("CSysApAppUi::HandleCurrentCallStateChangeL: EPSCTsyCallStateNone: enable keylock") ) );
       
  2323                 iKeyLockOnBeforeCall = EFalse;
       
  2324                 if ( !iDeviceLockEnabled )
       
  2325                     {
       
  2326                     if ( !iKeyLockOnBeforeCradle && !iKeyLockOnBeforeAlarm &&
       
  2327                           !iSysApFeatureManager->TouchUnlockStrokeSupported() )
       
  2328                         {
       
  2329                         if ( iSysApCenRepController->GetInt( KCRUidCommonTelephonySettings, KSettingsSummaryAfterCall ) == 1 )
       
  2330                             {
       
  2331                             // Let's not hide "Summary After Call" dialog
       
  2332                             iKeyguardController->EnableKeyguard(EFalse);
       
  2333                             }
       
  2334                         else
       
  2335                             {
       
  2336                             iKeyguardController->EnableKeyguard(ETrue);
       
  2337                             }
       
  2338                         }
       
  2339                     }
       
  2340                 else
       
  2341                     {
       
  2342                     iKeyguardController->EnableKeyguard(EFalse);
       
  2343                     }
       
  2344                 }
       
  2345             if ( iShowkeypadActivatedNoteAfterSoftReject )
       
  2346                 {
       
  2347                 ShowUiNoteL( EKeypadActiveNote );
       
  2348                 iShowkeypadActivatedNoteAfterSoftReject = EFalse;
       
  2349                 }
       
  2350             iCallActivated = EFalse;
       
  2351             break;
       
  2352             }
       
  2353             
       
  2354         default:
       
  2355             break;
       
  2356         }
       
  2357 
       
  2358     if ( aCurrentCallState != EPSCTsyCallStateRinging )
       
  2359         {
       
  2360         iSysApLightsController->CallComingInL( EFalse );
       
  2361         }
       
  2362 
       
  2363     SetIhfIndicatorL();
       
  2364     SetHacIndicatorL();
       
  2365     }
       
  2366 
       
  2367 
       
  2368 
       
  2369 /**
       
  2370  * To check the for an emergency call. 
       
  2371  * 
       
  2372  * @return ETrue if there is an emergency call active otherwise, EFalse.
       
  2373  */
       
  2374 TBool CSysApAppUi::IsEmergencyCall()
       
  2375         {
       
  2376         TBool retVal( EFalse );
       
  2377         TInt err( KErrNone );
       
  2378         TInt state( 0 );
       
  2379      
       
  2380         err = RProperty::Get(KPSUidCtsyEmergencyCallInfo, KCTSYEmergencyCallInfo, state );
       
  2381         if ( err == KErrNone && state )
       
  2382             {
       
  2383             retVal = ETrue;            
       
  2384             }
       
  2385         return retVal;
       
  2386         }
       
  2387 
       
  2388 
       
  2389 
       
  2390 // ----------------------------------------------------------------------------
       
  2391 // CSysApAppUi::IsStateNormal()
       
  2392 //
       
  2393 // ----------------------------------------------------------------------------
       
  2394 TBool CSysApAppUi::IsStateNormal() const
       
  2395     {
       
  2396     TInt state;
       
  2397     TInt errorCode =
       
  2398         RProperty::Get( KPSUidStartup, KPSGlobalSystemState, state );
       
  2399     if ( errorCode == KErrNone )
       
  2400         {
       
  2401         return state == ESwStateNormalRfOn ||
       
  2402                state == ESwStateNormalRfOff ||
       
  2403                state == ESwStateNormalBTSap;
       
  2404         }
       
  2405     else
       
  2406         {
       
  2407         TRACES( RDebug::Print( _L( "CSysApAppUi::IsStateNormal: Failed to read global system state, error code %d." ), errorCode ) );
       
  2408         return EFalse;
       
  2409         }
       
  2410     }
       
  2411 
       
  2412 
       
  2413 // ----------------------------------------------------------------------------
       
  2414 // CSysApAppUi::HandleAccessoryProfileInStartupL()
       
  2415 // ----------------------------------------------------------------------------
       
  2416 
       
  2417 void CSysApAppUi::HandleAccessoryProfileInStartupL()
       
  2418     {
       
  2419     TRACES( RDebug::Print( _L( "CSysApAppUi::HandleAccessoryProfileInStartupL" ) ) );
       
  2420 
       
  2421     if ( !iSysApOfflineModeController->OfflineModeActive() )
       
  2422         {
       
  2423         iIgnoreAccessorySpecificProfileChanges = EFalse;
       
  2424         TBool accessoryConnectedInShutdown( EFalse );
       
  2425         TInt accessoryTemp( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApAccessoryConnected ) );
       
  2426         if ( accessoryTemp == 1 )
       
  2427             {
       
  2428             accessoryConnectedInShutdown = ETrue;
       
  2429             }
       
  2430 
       
  2431         TBool accessoryConnectedNow ( EFalse );
       
  2432 
       
  2433         TAccMode accessoryState(EAccModeHandPortable);
       
  2434         if ( iSysApAccessoryObserver )
       
  2435             {
       
  2436             accessoryState = iSysApAccessoryObserver->GetAccessoryMode();
       
  2437             }
       
  2438 
       
  2439         if ( accessoryState != EAccModeHandPortable )
       
  2440             {
       
  2441             accessoryConnectedNow = ETrue;
       
  2442             }
       
  2443         TRACES( RDebug::Print( _L( "CSysApAppUi::HandleAccessoryProfileInStartupL: accessoryConnectedInShutdown: %d, accessoryConnectedNow: %d" ),
       
  2444                               accessoryConnectedInShutdown, accessoryConnectedNow ) );
       
  2445 
       
  2446         if ( accessoryConnectedInShutdown && !accessoryConnectedNow )
       
  2447             {
       
  2448             HandleAccessoryDisconnectedL();
       
  2449             }
       
  2450         else if ( !accessoryConnectedInShutdown && accessoryConnectedNow )
       
  2451             {
       
  2452             HandleAccessoryConnectedL( accessoryState );
       
  2453             }
       
  2454         else if ( !accessoryConnectedNow )
       
  2455             {
       
  2456             // not supporting this 
       
  2457             // TInt activeProfile ( ActiveProfileId() );
       
  2458             // SysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApActiveProfileBeforeAccessoryConnected, activeProfile );
       
  2459             }
       
  2460         }
       
  2461     }
       
  2462 
       
  2463 
       
  2464 // ----------------------------------------------------------------------------
       
  2465 // CSysApAppUi::CenRepController()
       
  2466 // ----------------------------------------------------------------------------
       
  2467 
       
  2468 CSysApCenRepController& CSysApAppUi::CenRepController()
       
  2469     {
       
  2470     __ASSERT_ALWAYS( iSysApCenRepController, User::Panic( _L("CSysApAppUi::CenRepController"), KErrBadHandle ) );
       
  2471 
       
  2472     return *iSysApCenRepController;
       
  2473     }
       
  2474 
       
  2475 
       
  2476 // ----------------------------------------------------------------------------
       
  2477 // CSysApAppUi::LogsObserverL
       
  2478 // ----------------------------------------------------------------------------
       
  2479 //
       
  2480 CSysApCenRepLogsObserver& CSysApAppUi::LogsObserverL()
       
  2481     {
       
  2482     TRACES( RDebug::Print( _L("CSysApAppUi::LogsObserverL()") ) );
       
  2483     
       
  2484     // Create Logs observer when it is needed for the first time
       
  2485     if ( !iSysApCenRepLogsObserver )
       
  2486         {
       
  2487         iSysApCenRepLogsObserver = CSysApCenRepLogsObserver::NewL( *this );
       
  2488         }
       
  2489     
       
  2490     return *iSysApCenRepLogsObserver;
       
  2491     }
       
  2492 
       
  2493 
       
  2494 // ----------------------------------------------------------------------------
       
  2495 // CSysApAppUi::HandleWlanIndicator()
       
  2496 // ----------------------------------------------------------------------------
       
  2497 void CSysApAppUi::HandleWlanIndicatorL( TInt aValue )
       
  2498     {
       
  2499     if ( aValue == EPSWlanIndicatorAvailable )
       
  2500         {
       
  2501         // do nothing
       
  2502         }
       
  2503     else if ( aValue == EPSWlanIndicatorActive )
       
  2504         {
       
  2505         // do nothing
       
  2506         }
       
  2507     else if ( aValue == EPSWlanIndicatorActiveSecure )
       
  2508         {
       
  2509         // do nothing
       
  2510         }
       
  2511     else // No indication required
       
  2512         {
       
  2513         // do nothing
       
  2514         }
       
  2515     }
       
  2516 
       
  2517 void CSysApAppUi::ShowNotificationDialog(const TDesC& noteText)const
       
  2518 {
       
  2519     //Todo:4.Notification--Just Popup message
       
  2520     //Todo: #include <HbDeviceNotificationDialogSymbian.h>
       
  2521     CHbDeviceNotificationDialogSymbian *notificationDialog =  CHbDeviceNotificationDialogSymbian::NewL();
       
  2522     CleanupStack::PushL(notificationDialog);
       
  2523     notificationDialog->SetTextL(noteText);//noteText with Qm file input
       
  2524     notificationDialog->SetTimeout(100);
       
  2525     notificationDialog->ShowL();
       
  2526     CleanupStack::PopAndDestroy(notificationDialog);
       
  2527 }
       
  2528 
       
  2529 void CSysApAppUi::SetKeyLockEnabledL()
       
  2530     {
       
  2531     iKeyLockEnabled = ETrue;
       
  2532     iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApKeyguardActive, 1 );
       
  2533     // not supporting indicator 
       
  2534 //    SetIndicatorStateL( EAknIndicatorKeyguard, EAknIndicatorStateOn );
       
  2535     iSysApLightsController->KeylockStateChangedL( ETrue );
       
  2536     }
       
  2537 
       
  2538 void CSysApAppUi::SetKeyLockDisabledL()
       
  2539     {
       
  2540     iKeyLockEnabled = EFalse;
       
  2541     iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApKeyguardActive, 0 );
       
  2542     // SetIndicatorStateL( EAknIndicatorKeyguard, EAknIndicatorStateOff );
       
  2543     if (! iDeviceLockEnabled )
       
  2544         {
       
  2545         iSysApLightsController->KeylockStateChangedL( EFalse );
       
  2546         if ( iSysApFeatureManager->MmcHotSwapSupported() )
       
  2547             {
       
  2548             if ( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) !=  EPSCTsyCallStateRinging && StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) !=  EPSCTsyCallStateAlerting )
       
  2549                 {
       
  2550                 // RunUnlockNotifierL();
       
  2551                 // need to handle MMC unlock query in next sub
       
  2552                 }
       
  2553             }
       
  2554         }
       
  2555     }
       
  2556 
       
  2557 void CSysApAppUi::SetLightsOnUnlockNoteL()
       
  2558     {
       
  2559     iSysApLightsController->SetLightsOnUnlockNoteL();
       
  2560     }
       
  2561 
       
  2562 void CSysApAppUi::SetLightsOnEcsQueryL()
       
  2563     {
       
  2564     iSysApLightsController->SetLightsOnEcsQueryL();
       
  2565     }
       
  2566 
       
  2567 void CSysApAppUi::SetLightsOnSecurityQueryL()
       
  2568     {
       
  2569     iSysApLightsController->SetLightsOnSecurityQueryL();
       
  2570     }
       
  2571 
       
  2572 TBool CSysApAppUi::CheckLongPowerKeyPressed()
       
  2573     {
       
  2574     return iCheckLongPowerKeyEvent;
       
  2575     }
       
  2576 
       
  2577 
       
  2578 // ----------------------------------------------------------------------------
   591 // CSysApAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
  2579 // CSysApAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
   592 // ----------------------------------------------------------------------------
  2580 // ----------------------------------------------------------------------------
   593 
  2581 
   594 TKeyResponse CSysApAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
  2582 TKeyResponse CSysApAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
   595     {
  2583     {
   604             {
  2592             {
   605             TRACES( RDebug::Print( _L("e_KEY_EVENT_SENDING 0") ) );
  2593             TRACES( RDebug::Print( _L("e_KEY_EVENT_SENDING 0") ) );
   606             }
  2594             }
   607 #endif // _DEBUG
  2595 #endif // _DEBUG
   608 
  2596 
   609         TKeyResponse response( EKeyWasNotConsumed );
  2597         TKeyResponse response(EKeyWasNotConsumed);
       
  2598         if (response)
       
  2599             {
       
  2600             //Do nothing:: To supress warning
       
  2601             }
   610         if (iSysApKeyManagement && aKeyEvent.iCode != EKeyPowerOff && aKeyEvent.iCode != 'E')
  2602         if (iSysApKeyManagement && aKeyEvent.iCode != EKeyPowerOff && aKeyEvent.iCode != 'E')
   611             {
  2603             {
   612             response = iSysApKeyManagement->HandleKeyEventL(aKeyEvent, aType );
  2604             response = iSysApKeyManagement->HandleKeyEventL(aKeyEvent, aType );
   613             }
  2605             }
   614         
  2606         
   626                     iKeyBoardRepeatCount++;
  2618                     iKeyBoardRepeatCount++;
   627                     if( aKeyEvent.iRepeats == 0 )
  2619                     if( aKeyEvent.iRepeats == 0 )
   628                         {
  2620                         {
   629                         TRACES( RDebug::Print(_L("CSysApAppUi::HandleKeyEventL, Short powerkey") ) );
  2621                         TRACES( RDebug::Print(_L("CSysApAppUi::HandleKeyEventL, Short powerkey") ) );
   630                         iLastPowerKeyWasShort = ETrue;
  2622                         iLastPowerKeyWasShort = ETrue;
   631                         HandleShortPowerKeyPressedL();
  2623                         TRACES( RDebug::Print( _L("CSysApAppUi::Key was consumed by pressing short power") ) );          
       
  2624                         //Powermenu
       
  2625                         if (iPowerMenuDialog != NULL)
       
  2626                             {
       
  2627                             //PowerMenu already exist
       
  2628                             delete iPowerMenuDialog;
       
  2629                             iPowerMenuDialog = NULL;
       
  2630                             } 
       
  2631                             
       
  2632                         iPowerMenuDialog = CHbDevicePowerMenuSymbian::NewL(*this);
       
  2633                         iPowerMenuDialog->ShowL();                        
   632                         iIgnoreNextPowerKeyRepeats = EFalse;
  2634                         iIgnoreNextPowerKeyRepeats = EFalse;
   633                         }
  2635                         }
   634                     //Long power key press
  2636                     //Long power key press
   635                     else if( aKeyEvent.iRepeats > 0 && iKeyBoardRepeatCount >= iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApPowerkeyRepeatcount ))
  2637                     else if( aKeyEvent.iRepeats > 0 && iKeyBoardRepeatCount >= iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApPowerkeyRepeatcount ))
   636                         {
  2638                         {
   640                         HandleLongPowerKeyPressedL();
  2642                         HandleLongPowerKeyPressedL();
   641                         }
  2643                         }
   642                     break;
  2644                     break;
   643 
  2645 
   644                 default:
  2646                 default:
   645                 	{
  2647                     {
   646                 	TKeyResponse response = EKeyWasNotConsumed;
  2648                     TKeyResponse response = EKeyWasNotConsumed;
   647                 	if (iSysApKeyManagement)
  2649                     if (iSysApKeyManagement)
   648                 		{
  2650                         {
   649                 		response = iSysApKeyManagement->HandleKeyEventL(aKeyEvent, aType );
  2651                         response = iSysApKeyManagement->HandleKeyEventL(aKeyEvent, aType );
   650                 		}
  2652                         }
   651 
  2653 
   652                     if ( response == EKeyWasNotConsumed ) // none of the plugins consumed the key, offer it to default handling
  2654                     if ( response == EKeyWasNotConsumed ) // none of the plugins consumed the key, offer it to default handling
   653                         {
  2655                         {
   654                         iSysApDefaultKeyHandler->HandleKeyEventL( aKeyEvent, aType );
  2656                         iSysApDefaultKeyHandler->HandleKeyEventL( aKeyEvent, aType );
   655                         }
  2657                         }
   656                 	}
  2658                     }
   657                     break;
  2659                     break;
   658                 }
  2660                 }
   659             }
  2661             }
   660         else if( aType == EEventKeyUp )
  2662         else if( aType == EEventKeyUp )
   661             {
  2663             {
   671                     }
  2673                     }
   672                 else if( iLastPowerKeyWasShort )
  2674                 else if( iLastPowerKeyWasShort )
   673                     {
  2675                     {
   674                     if ( iPowerKeyPopupMenuActive )
  2676                     if ( iPowerKeyPopupMenuActive )
   675                         {
  2677                         {
   676                         if ( iGlobalListQuery )
       
   677                             {
       
   678                             if ( iSysApFeatureManager->NoPowerKeySupported() )
       
   679                                 {
       
   680                             	CancelGlobalListQuery();
       
   681                                 }
       
   682                             else
       
   683                                 {
       
   684                                 iGlobalListQuery->MoveSelectionDown();	
       
   685                                 }                            
       
   686                             }
       
   687                         }
  2678                         }
   688                     }
  2679                     }
   689 
  2680 
   690                 }
  2681                 }
   691             }
  2682             }
   705             if ( aType == EEventKey && iSysApKeyManagement )
  2696             if ( aType == EEventKey && iSysApKeyManagement )
   706                 {
  2697                 {
   707                 iSysApKeyManagement->HandleKeyEventL( aKeyEvent, aType );
  2698                 iSysApKeyManagement->HandleKeyEventL( aKeyEvent, aType );
   708                 }
  2699                 }
   709             }
  2700             }
   710     #ifdef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
   711         else if ( aType == EEventKey && iSysApShutdownAnimation && !iShutdownContinued )
       
   712             {
       
   713             if ( aKeyEvent.iCode != EKeyPowerOff || iLastPowerKeyWasShort )
       
   714                 {
       
   715                 iSysApShutdownAnimation->Cancel();
       
   716                 NotifyShutdownAnimationSkip();
       
   717                 }
       
   718             }
       
   719 
       
   720     #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
   721 
       
   722         TRACES( RDebug::Print( _L("CSysApAppUi::HandleKeyEventL: ended") ) );
  2701         TRACES( RDebug::Print( _L("CSysApAppUi::HandleKeyEventL: ended") ) );
   723         }
  2702         }
   724     return EKeyWasConsumed;
  2703     return EKeyWasConsumed;
   725     }
  2704     }
       
  2705 
   726 
  2706 
   727 // ----------------------------------------------------------------------------
  2707 // ----------------------------------------------------------------------------
   728 // CSysApAppUi::HandleCommandL( TInt aCommand)
  2708 // CSysApAppUi::HandleCommandL( TInt aCommand)
   729 // ----------------------------------------------------------------------------
  2709 // ----------------------------------------------------------------------------
   730 
  2710 
   739         default:
  2719         default:
   740             break;
  2720             break;
   741         }
  2721         }
   742     }
  2722     }
   743 
  2723 
   744 // ----------------------------------------------------------------------------
  2724 TBool CSysApAppUi::ReleasePowerMenuCustomDialogMemory()
   745 // CSysApAppUi::HandleApplicationSpecificEventL(TInt aType,const TWsEvent& aEvent)
  2725     {
   746 // ----------------------------------------------------------------------------
  2726     if (iPowerMenuDialog!=NULL)
   747 
  2727         {
   748 void CSysApAppUi::HandleApplicationSpecificEventL(TInt aType,const TWsEvent& aEvent)
  2728         //PowerMenu already exist
   749     {
  2729         delete iPowerMenuDialog;
   750     TRACES( RDebug::Print( _L("CSysApAppUi::HandleApplicationSpecificEventL: aType:%d"), aType ) );
  2730         iPowerMenuDialog = NULL;
   751 
       
   752     CAknAppUi::HandleApplicationSpecificEventL(aType, aEvent);
       
   753     
       
   754     if ( ResourcesFreed() )
       
   755         {
       
   756         TRACES( RDebug::Print( _L("CSysApAppUi::HandleApplicationSpecificEventL: discarded, shutting down") ) );
       
   757         return;
       
   758         }
       
   759     
       
   760     switch( aType )
       
   761         {
       
   762         case EEikKeyLockEnabled:
       
   763             iKeyLockEnabled = ETrue;
       
   764             iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApKeyguardActive, 1 );
       
   765             SetIndicatorStateL( EAknIndicatorKeyguard, EAknIndicatorStateOn );
       
   766             iSysApLightsController->KeylockStateChangedL( ETrue );
       
   767             break;
       
   768         case EEikKeyLockDisabled:
       
   769             iKeyLockEnabled = EFalse;
       
   770             iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApKeyguardActive, 0 );
       
   771             SetIndicatorStateL( EAknIndicatorKeyguard, EAknIndicatorStateOff );
       
   772             if (! iDeviceLockEnabled )
       
   773                 {
       
   774                 iSysApLightsController->KeylockStateChangedL( EFalse );
       
   775                 if ( iSysApFeatureManager->MmcHotSwapSupported() )
       
   776                     {
       
   777                     if ( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) !=  EPSCTsyCallStateRinging && StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) !=  EPSCTsyCallStateAlerting )
       
   778                         {
       
   779                         RunUnlockNotifierL();
       
   780                         }
       
   781                     }
       
   782                 }
       
   783             break;
       
   784         case EEikKeyLockPowerKeyPressed: //sent when power key is captured by keylockserver
       
   785             HandleShortPowerKeyPressedL();
       
   786             break;
       
   787 
       
   788         case EEikKeyLockLightsOnRequest:
       
   789             iSysApLightsController->SetLightsOnUnlockNoteL();
       
   790             break;
       
   791 
       
   792         case EEikEcsQueryLights: // emergency note is shown
       
   793             iSysApLightsController->SetLightsOnEcsQueryL();
       
   794             break;
       
   795 
       
   796         case EEikSecurityQueryLights: // for device lock security query
       
   797             iSysApLightsController->SetLightsOnSecurityQueryL();
       
   798             break;
       
   799 
       
   800         default:
       
   801             break;
       
   802             }
       
   803     }
       
   804 
       
   805 
       
   806 // ----------------------------------------------------------------------------
       
   807 // CSysApAppUi::InitializeStatusPaneAreaL()
       
   808 // ----------------------------------------------------------------------------
       
   809 
       
   810 void CSysApAppUi::InitializeStatusPaneAreaL()
       
   811     {
       
   812     TRACES( RDebug::Print( _L("CSysApAppUi::InitializeStatusPaneAreaL(): START") ) );
       
   813     TInt state( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
   814 
       
   815     //Also Charging status will be updated with the following function.
       
   816     UpdateBatteryBarsL( state );
       
   817 
       
   818 #ifdef SYSAP_USE_STARTUP_UI_PHASE
       
   819     if ( OfflineModeActive() )
       
   820         {
       
   821         UpdateSignalBarsL( KAknSignalOffLineMode );
       
   822         }
       
   823     else
       
   824         {
       
   825         UpdateSignalBarsL();    
       
   826         }          
       
   827 #else
       
   828     UpdateSignalBarsL();
       
   829 #endif // SYSAP_USE_STARTUP_UI_PHASE
       
   830     
       
   831     SetSignalIndicatorL();
       
   832     SetIhfIndicatorL();
       
   833     SetHacIndicatorL();
       
   834     LogsObserverL().HandleUiReadyL();
       
   835 
       
   836     if ( iSysApEtelConnector )
       
   837         {
       
   838         iSysApEtelConnector->ReadSimSmsStoreStatusInStartup();
       
   839         }
       
   840 
       
   841     SetEnvelopeIndicatorL();
       
   842 
       
   843     TRACES( RDebug::Print( _L("CSysApAppUi::InitializeStatusPaneAreaL(): accessories") ) );
       
   844 
       
   845     TAccMode accessoryState(EAccModeHandPortable);
       
   846     if ( iSysApAccessoryObserver )
       
   847         {
       
   848         accessoryState = iSysApAccessoryObserver->GetAccessoryMode();
       
   849         }
       
   850 
       
   851     if( accessoryState == EAccModeWiredHeadset ||
       
   852         accessoryState == EAccModeWirelessHeadset ||
       
   853         accessoryState == EAccModeHeadphones )
       
   854         {
       
   855         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
   856         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
   857         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOn );
       
   858         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
   859         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
   860         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
   861         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
   862         }
       
   863     else if( accessoryState == EAccModeLoopset )
       
   864         {
       
   865         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
   866         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
   867         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOn );
       
   868         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
   869         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
   870         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
   871         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
   872         }
       
   873     else if( accessoryState == EAccModeTextDevice )
       
   874         {
       
   875         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
   876         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
   877         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOn );
       
   878         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
   879         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
   880         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
   881         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
   882         }
       
   883     else if( accessoryState == EAccModeWiredCarKit || accessoryState == EAccModeWirelessCarKit )
       
   884         {
       
   885         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
   886         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
   887         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
   888         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
   889         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOn );
       
   890         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
   891         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
   892         }
       
   893     else if( accessoryState == EAccModeTVOut )
       
   894         {
       
   895         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
   896         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
   897         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
   898         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
   899         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
   900         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOn );
       
   901         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
   902         }
       
   903     else if (accessoryState == EAccModeHDMI )
       
   904         {
       
   905         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
   906                 SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
   907                 SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
   908                 SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
   909                 SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
   910                 SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff);
       
   911                 SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOn );
       
   912         }
       
   913     else // all indicators off
       
   914         {
       
   915         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
   916         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
   917         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
   918         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
   919         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
   920         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
   921         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
   922         }
       
   923 
       
   924     TRACES( RDebug::Print( _L("CSysApAppUi::InitializeStatusPaneAreaL(): msg") ) );
       
   925     state = StateOfProperty( KUidSystemCategory, KUidOutboxStatusValue );
       
   926     if( state == ESADocumentsInOutbox )
       
   927         {
       
   928         SetIndicatorStateL( EAknIndicatorOutbox, EAknIndicatorStateOn );
       
   929         }
       
   930     else
       
   931         {
       
   932         SetIndicatorStateL( EAknIndicatorOutbox, EAknIndicatorStateOff );
       
   933         }
       
   934 
       
   935     state = StateOfProperty( KAlarmServerPubSubCategory, KWakeupAlarmPubSubKey );
       
   936     
       
   937     if( state == EActiveWakeupAlarmSet )
       
   938         {
       
   939         TRACES( RDebug::Print(_L("CSysApAppUi::InitializeStatusPaneAreaL called the SetIndicatorStateL with EActiveWakeupAlarmSet ")));
       
   940         SetIndicatorStateL( EAknIndicatorAlarmClock, EAknIndicatorStateOn );
       
   941         }
       
   942     else
       
   943         {
       
   944         TRACES( RDebug::Print(_L("CSysApAppUi::InitializeStatusPaneAreaL called the SetIndicatorStateL with EActiveNoWakeupAlarmsSet ")));
       
   945         SetIndicatorStateL( EAknIndicatorAlarmClock, EAknIndicatorStateOff );
       
   946         }
       
   947 
       
   948     state = StateOfProperty( KIrdaPropertyCategory, KIrdaStatus );
       
   949     if( state == TIrdaStatusCodes::EIrLoaded || state == TIrdaStatusCodes::EIrDisconnected || state == TIrdaStatusCodes::EIrBlocked )
       
   950         {
       
   951         SetIndicatorStateL( EAknIndicatorIrActive, EAknIndicatorStateAnimate );
       
   952         }
       
   953     else if( state == TIrdaStatusCodes::EIrConnected  )
       
   954         {
       
   955         SetIndicatorStateL( EAknIndicatorIrActive, EAknIndicatorStateOn );
       
   956         }
       
   957     else
       
   958         {
       
   959         SetIndicatorStateL( EAknIndicatorIrActive, EAknIndicatorStateOff );
       
   960         }
       
   961 
       
   962     iSysApCenRepCallForwardingObserver->UpdateCallForwardingIndicatorsL();
       
   963 
       
   964     iSysApCenRepMsgWaitingObserver->UpdateMessageWaitingIndicatorsL();
       
   965 
       
   966     state = StateOfProperty( KPSUidNetworkInfo, KNWHomeZoneStatus );
       
   967     if( state == ENWNone || state == ENWCityZone )
       
   968         {
       
   969         SetIndicatorStateL( EAknIndicatorHomeZone, EAknIndicatorStateOff );
       
   970         }
       
   971     else if( state == ENWHomeZone )
       
   972         {
       
   973         SetIndicatorStateL( EAknIndicatorHomeZone, EAknIndicatorStateOn );
       
   974         }
       
   975 
       
   976     // Initialize WLan state
       
   977     state = StateOfProperty( KPSUidWlan, KPSWlanIndicator );
       
   978     HandleWlanIndicatorL(state);
       
   979 
       
   980     // Initialize Tarm state
       
   981     state = StateOfProperty( KPSUidCoreApplicationUIs, KCoreAppUIsTarmIndicator );
       
   982     HandleTarmIndicatorL(state);
       
   983 
       
   984     TRACES( RDebug::Print( _L("CSysApAppUi::InitializeStatusPaneAreaL(): END") ) );
       
   985     }
       
   986 
       
   987 // ----------------------------------------------------------------------------
       
   988 // CSysApAppUi::HandleWlanIndicator()
       
   989 // ----------------------------------------------------------------------------
       
   990 void CSysApAppUi::HandleWlanIndicatorL( TInt aValue )
       
   991     {
       
   992     if ( aValue == EPSWlanIndicatorAvailable )
       
   993         {
       
   994         SetIndicatorStateL( EAknIndicatorWlanActive,       EAknIndicatorStateOff );
       
   995         SetIndicatorStateL( EAknIndicatorWlanActiveSecure, EAknIndicatorStateOff );
       
   996         SetIndicatorStateL( EAknIndicatorWlanAvailable,    EAknIndicatorStateOn  );
       
   997         }
       
   998     else if ( aValue == EPSWlanIndicatorActive )
       
   999         {
       
  1000         SetIndicatorStateL( EAknIndicatorWlanAvailable,    EAknIndicatorStateOff );
       
  1001         SetIndicatorStateL( EAknIndicatorWlanActiveSecure, EAknIndicatorStateOff );
       
  1002         SetIndicatorStateL( EAknIndicatorWlanActive,       EAknIndicatorStateOn  );
       
  1003         }
       
  1004     else if ( aValue == EPSWlanIndicatorActiveSecure )
       
  1005         {
       
  1006         SetIndicatorStateL( EAknIndicatorWlanAvailable,    EAknIndicatorStateOff );
       
  1007         SetIndicatorStateL( EAknIndicatorWlanActive,       EAknIndicatorStateOff );
       
  1008         SetIndicatorStateL( EAknIndicatorWlanActiveSecure, EAknIndicatorStateOn  );
       
  1009         }
       
  1010     else // No indication required
       
  1011         {
       
  1012         SetIndicatorStateL( EAknIndicatorWlanAvailable,    EAknIndicatorStateOff );
       
  1013         SetIndicatorStateL( EAknIndicatorWlanActive,       EAknIndicatorStateOff );
       
  1014         SetIndicatorStateL( EAknIndicatorWlanActiveSecure, EAknIndicatorStateOff );
       
  1015         }
       
  1016     }
       
  1017 
       
  1018 // ----------------------------------------------------------------------------
       
  1019 // CSysApAppUi::HandleTarmIndicatorL()
       
  1020 // ----------------------------------------------------------------------------
       
  1021 
       
  1022 void CSysApAppUi::HandleTarmIndicatorL( TInt aValue )
       
  1023     {
       
  1024     if ( aValue == ECoreAppUIsTarmTerminalSecurityOnIndicatorOn )
       
  1025         {
       
  1026         SetIndicatorStateL( EAknIndicatorTARM, EAknIndicatorStateOff );
       
  1027         SetIndicatorStateL( EAknIndicatorTARMModuleOn, EAknIndicatorStateOn );
       
  1028         }
       
  1029     else if ( aValue == ECoreAppUIsTarmMngActiveIndicatorOn )
       
  1030         {
       
  1031         SetIndicatorStateL( EAknIndicatorTARMModuleOn, EAknIndicatorStateOff );
       
  1032         SetIndicatorStateL( EAknIndicatorTARM, EAknIndicatorStateOn );
       
  1033         }
       
  1034     else
       
  1035         {
       
  1036         SetIndicatorStateL( EAknIndicatorTARM, EAknIndicatorStateOff );
       
  1037         SetIndicatorStateL( EAknIndicatorTARMModuleOn, EAknIndicatorStateOff );
       
  1038         }
       
  1039     }
       
  1040 
       
  1041 // ----------------------------------------------------------------------------
       
  1042 // CSysApAppUi::HandleShortPowerKeyPressedL()
       
  1043 // ----------------------------------------------------------------------------
       
  1044 
       
  1045 void CSysApAppUi::HandleShortPowerKeyPressedL()
       
  1046     {
       
  1047     TInt callState( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
       
  1048 
       
  1049     TRACES (
       
  1050         RDebug::Print(
       
  1051         _L("CSysApAppUi::HandleShortPowerKeyPressedL() callState:%d, iDeviceLockEnabled:%d" ),
       
  1052         callState,
       
  1053         iDeviceLockEnabled );
       
  1054     );
       
  1055     iSysApLightsController->PowerKeyPressedL();
       
  1056 
       
  1057     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsHideAlarm, ECoreAppUIsHideAlarm );
       
  1058 
       
  1059 
       
  1060     if( UiReady() && !iDeviceLockEnabled )
       
  1061         {
       
  1062         if ( iPowerKeyPopupMenuActive )
       
  1063             {
       
  1064             //Do nothing here. EEventKeyUp moves selection in the list!
       
  1065             }
       
  1066         else if ( !iKeyLockEnabled
       
  1067             && callState != EPSCTsyCallStateAlerting
       
  1068             && callState != EPSCTsyCallStateRinging
       
  1069             && callState != EPSCTsyCallStateDialling )
       
  1070             //Show power key menu
       
  1071             {
       
  1072             ShowPowerKeyPopUpMenuL();
       
  1073             }
       
  1074         }
       
  1075     else 
       
  1076         {
       
  1077         TInt swState( StateOfProperty( KPSUidStartup, KPSGlobalSystemState ) );
       
  1078         
       
  1079         if( swState == ESwStateAlarm )
       
  1080             //From Alarm state even a short press causes shutdown but charger state need to be checked
       
  1081             {
       
  1082             TInt chargerState( StateOfProperty( KPSUidHWRMPowerState, KHWRMChargingStatus ) );
       
  1083             if( chargerState == EChargingStatusNotConnected )
       
  1084                 //shutdown
       
  1085                 {
       
  1086                 StartShutDownTimerOnAlarmAndChargingStates();
       
  1087                 }
       
  1088             else
       
  1089                 //to charging state
       
  1090                 {
       
  1091                 SetStarterState( RStarterSession::ECharging );
       
  1092                 }
       
  1093             }
       
  1094         }
       
  1095     }
       
  1096 
       
  1097 // ----------------------------------------------------------------------------
       
  1098 // CSysApAppUi::HandleLongPowerKeyPressedL()
       
  1099 // ----------------------------------------------------------------------------
       
  1100 
       
  1101 void CSysApAppUi::HandleLongPowerKeyPressedL()
       
  1102     {
       
  1103     TRACES( RDebug::Print( _L("CSysApAppUi::HandleLongPowerKeyPressedL()") ) );
       
  1104 
       
  1105     TInt swState;
       
  1106     RProperty::Get( KPSUidStartup, KPSGlobalSystemState, swState );
       
  1107 
       
  1108     iSysApLightsController->PowerKeyPressedL();
       
  1109 
       
  1110     if( swState == ESwStateStartingCriticalApps ||
       
  1111         swState == ESwStateSelfTestOK ||
       
  1112         swState == ESwStateSecurityCheck ||
       
  1113         swState == ESwStateCriticalPhaseOK ||
       
  1114         swState == ESwStateEmergencyCallsOnly ||
       
  1115         swState == ESwStateNormalRfOn ||
       
  1116         swState == ESwStateNormalRfOff ||
       
  1117         swState == ESwStateNormalBTSap ||
       
  1118         swState == ESwStateFatalStartupError )
       
  1119         {
       
  1120         if( !iDeviceLockEnabled )
       
  1121             {
       
  1122             if( iPowerKeyPopupMenuActive )
       
  1123                 {
       
  1124                 if ( iGlobalListQuery )
       
  1125                     {
       
  1126                     iGlobalListQuery->SelectItem();
       
  1127                     }
       
  1128                 }
       
  1129             else if( !iIgnoreNextPowerKeyRepeats )
       
  1130                 {
       
  1131                 if( !iKeyLockEnabled && !IsEncryptionOperationOngoingL() )
       
  1132                     {
       
  1133                     DoShutdownL( EFalse, KDummyReason );
       
  1134                     }
       
  1135                 }
       
  1136             iIgnoreNextPowerKeyRepeats = ETrue;
       
  1137             }
       
  1138         }
       
  1139     else if( swState == ESwStateAlarm )
       
  1140         {
       
  1141         //Just comment here to highlight that this is not possible since
       
  1142         //from alarm state already a short press always shuts the device down.
       
  1143         }
       
  1144     else if( swState == ESwStateCharging )
       
  1145         //Startup to Normal state
       
  1146         {
       
  1147         if( !iIgnoreNextPowerKeyRepeats )
       
  1148             {
       
  1149             iIgnoreNextPowerKeyRepeats = ETrue;
       
  1150 
       
  1151             SetStarterState( RStarterSession::ENormal );
       
  1152             }
       
  1153         }
       
  1154     }
       
  1155 
       
  1156 // ----------------------------------------------------------------------------
       
  1157 // CSysApAppUi::FreeResources()
       
  1158 // ----------------------------------------------------------------------------
       
  1159 
       
  1160 void CSysApAppUi::FreeResources()
       
  1161     {
       
  1162     TRACES( RDebug::Print( _L("CSysApAppUi::FreeResources") ) );
       
  1163 
       
  1164     delete iSysApBatteryInfoController;
       
  1165     delete iSysApPsmController;
       
  1166 
       
  1167     delete iSysApAudioRoutingObserver;
       
  1168 
       
  1169     delete iProfileNamesArray;
       
  1170     iProfileNamesArray = NULL;
       
  1171 
       
  1172     if ( iTimer )
       
  1173         {
       
  1174         iTimer->Cancel();
       
  1175         delete iTimer;
       
  1176         }
       
  1177 
       
  1178     if ( iSapTimer )
       
  1179         {
       
  1180         iSapTimer->Cancel();
       
  1181         delete iSapTimer;
       
  1182         }
       
  1183 
       
  1184     if ( iSysApTimer )
       
  1185         {
       
  1186         iSysApTimer->Cancel();
       
  1187         delete iSysApTimer;
       
  1188         }
       
  1189 
       
  1190     delete iGlobalListQuery;
       
  1191 
       
  1192     RWindowGroup groupWin = iCoeEnv->RootWin();
       
  1193     groupWin.CancelCaptureKey( iCapturedEKeyPowerOff );
       
  1194     groupWin.CancelCaptureKeyUpAndDowns( iCapturedEKeyPowerOffUpAndDowns );
       
  1195 
       
  1196     delete iSysApDefaultKeyHandler;
       
  1197 
       
  1198     if ( iProfileEngine )
       
  1199         {
       
  1200         iProfileEngine->Release();
       
  1201         }
       
  1202 
       
  1203     delete iSysApSsSettingsObserver;
       
  1204     delete iSysApEtelConnector;
       
  1205 
       
  1206     delete iSysApProfileObserver;
       
  1207     delete iSysApNspsHandler;
       
  1208     delete iSysApKeySndHandler;
       
  1209     delete iSysApCenRepMsgWaitingObserver;
       
  1210     delete iSysApCenRepCallForwardingObserver;
       
  1211     delete iSysApConnectionMonitorObserver;
       
  1212     delete iSysApCenRepLightSettingsObserver;
       
  1213     delete iSysApCenRepLogsObserver;
       
  1214     delete iSysApCenRepBtObserver;
       
  1215 //    delete iSysApCenRepFmTxObserver;
       
  1216     delete iSysApCenRepHacSettingObserver;
       
  1217     delete iSysApCenRepController;
       
  1218 
       
  1219     delete iSysApPubSubObserver;
       
  1220 
       
  1221     delete iSysApMMCObserver;
       
  1222     delete iSysApMsgSimMemLowQuery;
       
  1223     delete iSysApWaitNote;
       
  1224     delete iSysApConfirmationQuery;
       
  1225     delete iSysApConfirmationQueryForRestart;
       
  1226     delete iSysApOfflineModeController;
       
  1227     delete iSysApUsbIndicatorController;
       
  1228     delete iSysApBtController;
       
  1229     delete iSysApBtSapController;
       
  1230     delete iSignalNotify;
       
  1231     delete iBatteryNotify;
       
  1232     delete iSysApSystemLock;
       
  1233     delete iSysApLocationPrivacyIndicator;
       
  1234     delete iSysApAccessoryObserver;
       
  1235     delete iSysApMediatorObserver;
       
  1236 
       
  1237     delete iSysApKeyManagement;
       
  1238     iSysApKeyManagement = NULL;
       
  1239     delete iSysApLightsController;
       
  1240     iKeyLock.Close();
       
  1241     delete iSysApFeatureManager;
       
  1242 
       
  1243     // Cleanup ECom, used by key management and light control
       
  1244     REComSession::FinalClose();
       
  1245 
       
  1246     iResourcesFreed = ETrue;
       
  1247     TRACES( RDebug::Print( _L("CSysApAppUi::FreeResources:END") ) );
       
  1248     }
       
  1249 
       
  1250 // ----------------------------------------------------------------------------
       
  1251 // CSysApAppUi::ShowUiNoteL( const TSysApNoteIds aNote ) const
       
  1252 // ----------------------------------------------------------------------------
       
  1253 
       
  1254 void CSysApAppUi::ShowUiNoteL( const TSysApNoteIds aNote ) const
       
  1255     {
       
  1256     TRACES( RDebug::Print( _L("CSysApAppUi::ShowUiNoteL aNote: %d"), aNote ) );
       
  1257 
       
  1258     TInt tone( EAvkonSIDNoSound );
       
  1259     TAknGlobalNoteType noteType( EAknGlobalBatteryLowNote );
       
  1260     CAknGlobalNote* note = CAknGlobalNote::NewLC();
       
  1261     TInt secondaryDisplayId(SecondaryDisplay::ECmdNoNote);
       
  1262 
       
  1263     switch ( aNote )
       
  1264         {
       
  1265         case EBatteryLowNote:
       
  1266             noteType = EAknGlobalBatteryLowNote;
       
  1267             tone = EAvkonSIDBatteryLowTone;
       
  1268             break;
       
  1269         case EBatteryFullNote:
       
  1270             noteType = EAknGlobalBatteryFullNote;
       
  1271             tone = EAvkonSIDInformationTone;
       
  1272             break;
       
  1273         case ERechargeBatteryNote:
       
  1274             iSysApLightsController->BatteryEmptyL( ETrue );
       
  1275             noteType = EAknGlobalRechargeBatteryNote;
       
  1276             tone = EAvkonSIDRechargeBatteryTone;
       
  1277             break;
       
  1278         case ENotChargingNote:
       
  1279             noteType = EAknGlobalNotChargingNote;
       
  1280             tone = EAvkonSIDWrongCharger;
       
  1281             break;
       
  1282         case EInsertSimNote:
       
  1283             noteType = EAknGlobalInformationNote;
       
  1284             tone = EAvkonSIDInformationTone;
       
  1285             secondaryDisplayId = SecondaryDisplay::ECmdShowInsertSimNote;
       
  1286             break;
       
  1287         case EMemoryCardRemovedWithoutEjectNote:
       
  1288             noteType = EAknGlobalInformationNote;
       
  1289             tone = EAvkonSIDInformationTone;
       
  1290             secondaryDisplayId = SecondaryDisplay::ECmdShowMemoryCardRemovedWithoutEjectNote;
       
  1291             break;
       
  1292         case EGprsSuspendedNote:
       
  1293             noteType = EAknGlobalInformationNote;
       
  1294             tone = EAvkonSIDInformationTone;
       
  1295             secondaryDisplayId = SecondaryDisplay::ECmdShowGprsSuspendedNote;
       
  1296             break;
       
  1297         case EGprsResumedNote:
       
  1298             noteType = EAknGlobalInformationNote;
       
  1299             tone = EAvkonSIDInformationTone;
       
  1300             secondaryDisplayId = SecondaryDisplay::ECmdShowGprsResumedNote;
       
  1301             break;
       
  1302         case EShutdownNote:
       
  1303             noteType = EAknGlobalInformationNote;
       
  1304             tone = EAvkonSIDInformationTone;
       
  1305             secondaryDisplayId = SecondaryDisplay::ECmdShowShutdownNote;
       
  1306             break;
       
  1307         case ECannotActivateOfflineModeNote:
       
  1308             noteType = EAknGlobalErrorNote;
       
  1309             tone = EAvkonSIDErrorTone;
       
  1310             secondaryDisplayId = SecondaryDisplay::ECmdShowCannotActivateOfflineModeNote;
       
  1311             break;
       
  1312         case ECannotDeactivateOfflineModeNote:
       
  1313             noteType = EAknGlobalErrorNote;
       
  1314             tone = EAvkonSIDErrorTone;
       
  1315             secondaryDisplayId = SecondaryDisplay::ECmdShowCannotDeactivateOfflineModeNote;
       
  1316             break;
       
  1317         case EKeypadActiveNote:
       
  1318             noteType = EAknGlobalInformationNote;
       
  1319             tone = EAvkonSIDInformationTone;
       
  1320             secondaryDisplayId = SecondaryDisplay::ECmdShowKeypadActiveNote;
       
  1321             break;
       
  1322 /*        case EFmTxAccessoryStandbyNote:
       
  1323             noteType = EAknGlobalInformationNote; 
       
  1324             tone = EAvkonSIDInformationTone;
       
  1325             secondaryDisplayId = SecondaryDisplay::ECmdShowFmTxStandbyInAccessoryConnectionNote;
       
  1326             break;
       
  1327         case EFmTxAccessoryForbidsNote:
       
  1328             noteType = EAknGlobalInformationNote; 
       
  1329             tone = EAvkonSIDInformationTone;
       
  1330             secondaryDisplayId = SecondaryDisplay::ECmdShowFmTxCannotEnableWhileAccessoryConnectedNote;
       
  1331             break;
       
  1332         case EFmTxVolumeDisabledNote:
       
  1333             noteType = EAknGlobalInformationNote; 
       
  1334             tone = EAvkonSIDInformationTone;
       
  1335             secondaryDisplayId = SecondaryDisplay::ECmdShowFmTxVolumeDisabledNote;
       
  1336             break;
       
  1337         case EFmTxOnNote:
       
  1338             noteType = EAknGlobalInformationNote; 
       
  1339             tone = EAvkonSIDInformationTone;
       
  1340             secondaryDisplayId = SecondaryDisplay::ECmdShowFmTxTuneRadioToFrequencyNote;
       
  1341             break;
       
  1342         case EFmTxOffNote:
       
  1343             noteType = EAknGlobalInformationNote; 
       
  1344             tone = EAvkonSIDInformationTone;
       
  1345             secondaryDisplayId = SecondaryDisplay::ECmdShowFmTxDisabledNote;
       
  1346             break;
       
  1347 */        case EBatteryFullUnplugChargerNote:
       
  1348             noteType = EAknGlobalBatteryFullUnplugNote;
       
  1349             tone = EAvkonSIDInformationTone;
       
  1350             break;
       
  1351         case EUnplugChargerNote:
       
  1352             noteType = EAknGlobalUnplugChargerNote;
       
  1353             tone = EAvkonSIDInformationTone;
       
  1354             break;
       
  1355         case EPowerSaveModeActivated:
       
  1356             noteType = EAknGlobalConfirmationNote;
       
  1357             tone = EAvkonSIDConfirmationTone;
       
  1358             secondaryDisplayId = SecondaryDisplay::ECmdShowPowerSavingActivatedNote;
       
  1359             break;
       
  1360         case EPowerSaveModeDeactivated:
       
  1361             noteType = EAknGlobalConfirmationNote;
       
  1362             tone = EAvkonSIDConfirmationTone;
       
  1363             secondaryDisplayId = SecondaryDisplay::ECmdShowPowerSavingDeactivatedNote;
       
  1364             break;
       
  1365         case ECannotActivatePowerSaveMode:
       
  1366             noteType = EAknGlobalWarningNote;
       
  1367             tone = EAvkonSIDWarningTone;
       
  1368             secondaryDisplayId = SecondaryDisplay::ECmdShowCannotActivatePowerSavingNote;
       
  1369             break;
       
  1370         case ECannotDeactivatePowerSaveMode:
       
  1371             noteType = EAknGlobalWarningNote;
       
  1372             tone = EAvkonSIDWarningTone;
       
  1373             secondaryDisplayId = SecondaryDisplay::ECmdShowCannotDeactivatePowerSavingNote;
       
  1374             break;
       
  1375         default:
       
  1376             break;
       
  1377 
       
  1378         }
       
  1379 
       
  1380     TInt swState( StateOfProperty( KPSUidStartup, KPSGlobalSystemState ) );
       
  1381 
       
  1382     if( UiReady() || swState == ESwStateSecurityCheck)
       
  1383         {
       
  1384         HBufC* noteStringBuf = NULL;
       
  1385 
       
  1386         switch ( aNote )
       
  1387             {
       
  1388             case EInsertSimNote:
       
  1389                 noteStringBuf = StringLoader::LoadLC( R_QTN_SU_NOTE_INSERT_SIM, iEikonEnv );
       
  1390                 break;
       
  1391             case EMemoryCardRemovedWithoutEjectNote:
       
  1392                 noteStringBuf = StringLoader::LoadLC( R_QTN_MEMS_EJECT_ERROR, iEikonEnv );
       
  1393                 note->SetSoftkeys( R_AVKON_SOFTKEYS_OK_EMPTY );
       
  1394                 break;
       
  1395             case EGprsSuspendedNote:
       
  1396                 noteStringBuf = StringLoader::LoadLC( R_QTN_GPRS_CONF_GPRS_SUSPENDED, iEikonEnv );
       
  1397                 break;
       
  1398             case EGprsResumedNote:
       
  1399                 noteStringBuf = StringLoader::LoadLC( R_QTN_GPRS_CONF_GPRS_RESUMED, iEikonEnv );
       
  1400                 break;
       
  1401             case EShutdownNote:
       
  1402                 noteStringBuf = StringLoader::LoadLC( R_QTN_PWRC_INFO_GOODBYE, iEikonEnv);
       
  1403                 break;
       
  1404             case ECannotActivateOfflineModeNote:
       
  1405                 noteStringBuf = StringLoader::LoadLC( R_QTN_ERR_OFFLINE_UNABLE, iEikonEnv );
       
  1406                 break;
       
  1407             case ECannotDeactivateOfflineModeNote:
       
  1408                 noteStringBuf = StringLoader::LoadLC( R_QTN_ERR_OFFLINE_UNABLE_PROFILE, iEikonEnv );
       
  1409                 break;
       
  1410             case EKeypadActiveNote:
       
  1411                 if ( iSysApFeatureManager->PenEnabled() )
       
  1412                     {
       
  1413                     noteStringBuf = StringLoader::LoadLC( R_QTN_KEYG_CONF_DISPLAY_KEYS_ACTIVE,
       
  1414                                                           iEikonEnv );
       
  1415                     }
       
  1416                 else
       
  1417                     {
       
  1418                     noteStringBuf = StringLoader::LoadLC( R_QTN_KEYG_CONF_KEYPAD_ACTIVE,
       
  1419                                                           iEikonEnv );
       
  1420                     }
       
  1421                 note->SetAnimation( R_QGN_NOTE_KEYGUARD_OPEN_ANIM );
       
  1422                 break;
       
  1423 /*            case EFmTxOnNote:
       
  1424                 {
       
  1425                 const TInt KFrequencyMaxLength(7);
       
  1426                 // read frequency
       
  1427                 TInt frequencykHz = iSysApCenRepFmTxObserver->Frequency();
       
  1428                 TReal frequencyMHz = static_cast<TReal>( frequencykHz ) / KCoefficientKhzToMhz; // kHz to Mhz
       
  1429                 TBuf<KFrequencyMaxLength> frequencyAsString;
       
  1430                 frequencyAsString.AppendNum( frequencyMHz, TRealFormat( KFrequencyMaxLength, KDecimalsInMhzFrequency ) );
       
  1431                 AknTextUtils::LanguageSpecificNumberConversion( frequencyAsString );
       
  1432                 noteStringBuf 
       
  1433                       = StringLoader::LoadLC( R_QTN_FMTX_SYSAP_INFO_NOTE_CHANGE_FREQ, 
       
  1434                                               frequencyAsString,
       
  1435                                               iEikonEnv );
       
  1436                 break;
       
  1437                 }
       
  1438             case EFmTxAccessoryForbidsNote:
       
  1439                 {
       
  1440                 noteStringBuf = StringLoader::LoadLC( R_QTN_FMTX_SYSAP_INFO_NOTE_ACCESSORY_FORBIDS, 
       
  1441                                                        iEikonEnv );
       
  1442                 break;
       
  1443                 }
       
  1444             case EFmTxAccessoryStandbyNote:
       
  1445                 {                                     
       
  1446                 noteStringBuf = StringLoader::LoadLC( R_QTN_FMTX_SYSAP_INFO_NOTE_ACCESSORY_STANDBY, 
       
  1447                                                        iEikonEnv );
       
  1448                 break;
       
  1449                 }
       
  1450             case EFmTxVolumeDisabledNote:
       
  1451                 {
       
  1452                 noteStringBuf = StringLoader::LoadLC( R_QTN_FMTX_SYSAP_INFO_NOTE_VOLUME_DISABLED, 
       
  1453                                                        iEikonEnv );
       
  1454                 break;
       
  1455                 }
       
  1456             case EFmTxOffNote:
       
  1457                 {
       
  1458                 noteStringBuf = StringLoader::LoadLC( R_QTN_FMTX_SYSAP_INFO_NOTE_DISABLED, 
       
  1459                                                        iEikonEnv );
       
  1460                 break;
       
  1461                 }
       
  1462 */            case EPowerSaveModeActivated:
       
  1463                 noteStringBuf = StringLoader::LoadLC( R_QTN_POWER_SAVING_ACTIVATED_CONF_NOTE, iEikonEnv );
       
  1464                 break;
       
  1465             case EPowerSaveModeDeactivated:
       
  1466                 noteStringBuf = StringLoader::LoadLC( R_QTN_POWER_SAVING_DEACTIVATED_CONF_NOTE, iEikonEnv );
       
  1467                 break;
       
  1468             case ECannotActivatePowerSaveMode:
       
  1469                 noteStringBuf = StringLoader::LoadLC( R_QTN_POWER_SAVING_FAILED_WARNING_NOTE, iEikonEnv );
       
  1470                 break;
       
  1471             case ECannotDeactivatePowerSaveMode:
       
  1472                 noteStringBuf = StringLoader::LoadLC( R_QTN_POWER_SAVING_DEACTIVATION_FAILED_WARNING_NOTE, iEikonEnv ); 
       
  1473                 break;
       
  1474             default:
       
  1475                 break;
       
  1476             }
       
  1477 
       
  1478         note->SetTone( tone );
       
  1479 
       
  1480         // Set secondary display data if necessary
       
  1481 /*        if ( iSysApFeatureManager->CoverDisplaySupported() && secondaryDisplayId != SecondaryDisplay::ECmdNoNote)
       
  1482             {
       
  1483             TRACES( RDebug::Print( _L("CSysApAppUi::ShowUiNoteL - Notifying secondary display") ) );
       
  1484             CAknSDData* sd;
       
  1485             
       
  1486             if ( aNote == EFmTxOnNote ) // frequency information is passed to secondary display
       
  1487                 {
       
  1488                 SecondaryDisplay::TFmTxFrequencyInKhzPckg pckg( iSysApCenRepFmTxObserver->Frequency() );
       
  1489                 sd = CAknSDData::NewL( SecondaryDisplay::KCatSysAp, secondaryDisplayId, pckg );
       
  1490                 }
       
  1491             else
       
  1492                 {
       
  1493                 sd = CAknSDData::NewL(SecondaryDisplay::KCatSysAp, secondaryDisplayId, KNullDesC8);
       
  1494                 }
       
  1495              
       
  1496             note->SetSecondaryDisplayData(sd); // ownership to notifier client
       
  1497             }
       
  1498 */
       
  1499         if ( noteStringBuf )
       
  1500             {
       
  1501             TPtr textBuffer = noteStringBuf->Des();
       
  1502             TRACES( RDebug::Print( _L("CSysApAppUi::ShowUiNoteL Next:note->ShowNoteL" ) ) );
       
  1503             note->ShowNoteL( noteType, textBuffer );
       
  1504             CleanupStack::PopAndDestroy( ); // noteStringbuf
       
  1505             }
       
  1506         else
       
  1507             {
       
  1508             TRACES( RDebug::Print( _L("CSysApAppUi::ShowUiNoteL Next:note->ShowNoteL" ) ) );
       
  1509             note->ShowNoteL( noteType, KNullDesC );
       
  1510             }
       
  1511         }
       
  1512     else if( swState == ESwStateAlarm || swState == ESwStateCharging )
       
  1513         {
       
  1514         if ( aNote != EUnplugChargerNote ) // don't play tone when charger is disconnected in charging state
       
  1515             {
       
  1516             static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds()->PlaySound( tone );    
       
  1517             }
       
  1518         }
       
  1519 
       
  1520     CleanupStack::PopAndDestroy(); // note
       
  1521     }
       
  1522 
       
  1523 // ----------------------------------------------------------------------------
       
  1524 // CSysApAppUi::ShowChargingNoteL()
       
  1525 // ----------------------------------------------------------------------------
       
  1526 
       
  1527 void CSysApAppUi::ShowChargingNoteL()
       
  1528     {
       
  1529     TRACES( RDebug::Print( _L("CSysApAppUi::ShowChargingNoteL") ) );
       
  1530     TBool showNote( ETrue );
       
  1531 
       
  1532     TInt swState( StateOfProperty( KPSUidStartup, KPSGlobalSystemState ) );
       
  1533     TRACES( RDebug::Print( _L("CSysApAppUi::ShowChargingNoteL: swState: %d"), swState ) );
       
  1534 
       
  1535     if( UiReady() || swState == ESwStateSecurityCheck )
       
  1536         {
       
  1537         if ( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) ==  EPSCTsyCallStateRinging )
       
  1538             {
       
  1539             showNote = EFalse;
       
  1540             }
       
  1541         TRACES( RDebug::Print( _L("CSysApAppUi::ShowChargingNoteL KCTsyCallState=%d"), StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) ) );
       
  1542         if ( showNote ) // Power Mgmt UI spec defines that no Charging note is shown while the phone is ringing/alerting
       
  1543             {
       
  1544             CAknGlobalNote* chargingNote = CAknGlobalNote::NewLC();
       
  1545             chargingNote->SetTone( EAvkonSIDChargingBatteryTone );
       
  1546             chargingNote->ShowNoteL( EAknGlobalChargingNote, KNullDesC );
       
  1547             CleanupStack::PopAndDestroy( chargingNote );
       
  1548             }
       
  1549         }
       
  1550     else if( swState == ESwStateAlarm || swState == ESwStateCharging )
       
  1551         {
       
  1552         TRACES( RDebug::Print( _L("CSysApAppUi::ShowChargingNoteL - Just play tone") ) );
       
  1553         static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds()->PlaySound( EAvkonSIDChargingBatteryTone );
       
  1554         }
       
  1555     else
       
  1556         {
       
  1557         TRACES( RDebug::Print( _L("CSysApAppUi::ShowChargingNoteL - No note shown") ) );
       
  1558         }
       
  1559     }
       
  1560 
       
  1561 // ----------------------------------------------------------------------------
       
  1562 // CSysApAppUi::HandleChargerNotesL()
       
  1563 // ----------------------------------------------------------------------------
       
  1564 void CSysApAppUi::HandleChargerNotesL( const TInt aValue )
       
  1565     {
       
  1566     TBool showNote(StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) !=  EPSCTsyCallStateRinging);
       
  1567     if ( aValue == EChargingStatusCharging )
       
  1568         {
       
  1569         iSysApLightsController->BatteryEmptyL( EFalse );
       
  1570         TRACES( RDebug::Print( _L("SysAp: charger connected") ) );
       
  1571         iSysApLightsController->ChargerConnectedL( ETrue );
       
  1572         ShowChargingNoteL();
       
  1573         }
       
  1574     //Display Not Charging note
       
  1575     else if ( aValue == EChargingStatusError )
       
  1576         {
       
  1577         if(showNote)
       
  1578             {
       
  1579             ShowUiNoteL( ENotChargingNote );
       
  1580             }
       
  1581         }
       
  1582     else if ( aValue == EChargingStatusChargingComplete )
       
  1583         {
       
  1584         iSysApLightsController->ChargingCompleteL();
       
  1585         
       
  1586         TSysApNoteIds note( EBatteryFullNote );
       
  1587         
       
  1588         if ( !iSysApUsbChargerDetector.HostOnlyUsbChargingUsed() &&
       
  1589              iSysApFeatureManager->Supported( KSysApFeatureIdChargerReminderNotes ) )
       
  1590             {
       
  1591             note = EBatteryFullUnplugChargerNote;
       
  1592             }
       
  1593         iSysApUsbChargerDetector.Reset();
       
  1594         if(showNote)
       
  1595             {
       
  1596             ShowUiNoteL( note );
       
  1597             }
       
  1598         }
       
  1599     else if ( aValue == EChargingStatusNotConnected )
       
  1600         {
       
  1601         TRACES( RDebug::Print( _L("SysAp: charger removed") ) );
       
  1602         iSysApLightsController->ChargerConnectedL( EFalse );
       
  1603         
       
  1604         if ( !iSysApUsbChargerDetector.HostOnlyUsbChargingUsed() &&
       
  1605              iSysApFeatureManager->Supported( KSysApFeatureIdChargerReminderNotes ) )
       
  1606             {
       
  1607 		if(showNote)
       
  1608                 {
       
  1609                 ShowUiNoteL( EUnplugChargerNote );
       
  1610                 }
       
  1611             }
       
  1612         iSysApUsbChargerDetector.Reset();
       
  1613         }
       
  1614     else if ( aValue == EChargingStatusNotCharging )
       
  1615         {
       
  1616         TRACES( RDebug::Print( _L("SysAp: Not charging") ) );
       
  1617         }
       
  1618     else if ( aValue == EChargingStatusAlmostComplete )
       
  1619         {
       
  1620         TRACES( RDebug::Print( _L("SysAp: Charging almost complete") ) );
       
  1621         }
       
  1622     else if ( aValue == EChargingStatusChargingContinued )
       
  1623         {
       
  1624         //in this case we simply want to scroll the battery bars and not turn light on or show ui note
       
  1625         // set lights controller iBatteryEmpty to EFalse
       
  1626         iSysApLightsController->BatteryEmptyL( EFalse );
       
  1627         TRACES( RDebug::Print( _L("SysAp: charging continues") ) );
       
  1628         }
       
  1629     }
       
  1630 
       
  1631 // ----------------------------------------------------------------------------
       
  1632 // CSysApAppUi::ShowProfileNoteL()
       
  1633 // ----------------------------------------------------------------------------
       
  1634 
       
  1635 void CSysApAppUi::ShowProfileNoteL()
       
  1636     {
       
  1637     TRACES( RDebug::Print( _L("CSysApAppUi::ShowProfileNoteL") ) );
       
  1638 
       
  1639     if ( UiReady() )
       
  1640         {
       
  1641         if ( iProfileNote )
       
  1642             {
       
  1643             // when a call is coming in, there might be a pending "Selected profile"
       
  1644             // we don't want to show anymore
       
  1645             iProfileNote->CancelNoteL( iProfileNoteId );
       
  1646             }
       
  1647 
       
  1648         TBufC<KMaxProfileNameLength> profileName;
       
  1649         HBufC* noteStringBuf = NULL;
       
  1650         ActiveProfileNameL( profileName.Des() );
       
  1651         noteStringBuf = StringLoader::LoadLC( R_TEXT_MODE_SELECTED, profileName, iEikonEnv );
       
  1652         TPtr textBuffer = noteStringBuf->Des();
       
  1653         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( textBuffer );
       
  1654 
       
  1655         // profile note is constructed when it is needed for the first time
       
  1656         if ( !iProfileNote )
       
  1657             {
       
  1658             iProfileNote = CAknGlobalNote::NewL();
       
  1659             iProfileNote->SetTone( EAvkonSIDConfirmationTone );
       
  1660             }
       
  1661 
       
  1662         // Set secondary display data if necessary
       
  1663         if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  1664             {
       
  1665             TRACES( RDebug::Print( _L("CSysApAppUi::ShowProfileNoteL - Notifying secondary display") ) );
       
  1666             SecondaryDisplay::TProfileName sdProfileName;
       
  1667             sdProfileName.Append(profileName.Left(SecondaryDisplay::KProfileNameMaxLen));
       
  1668             SecondaryDisplay::TProfileNotePckg pckg(sdProfileName);
       
  1669             CAknSDData* sd = CAknSDData::NewL(SecondaryDisplay::KCatSysAp, SecondaryDisplay::ECmdShowProfileNote, pckg);
       
  1670             iProfileNote->SetSecondaryDisplayData(sd); // ownership to notifier client
       
  1671             }
       
  1672 
       
  1673         iProfileNoteId = iProfileNote->ShowNoteL( EAknGlobalConfirmationNote, textBuffer );
       
  1674 
       
  1675         CleanupStack::PopAndDestroy( ); // noteStringbuf
       
  1676 
       
  1677         iSysApLightsController->ProfileChangedL(); // All notes should always turn lights on.
       
  1678         }
       
  1679     }
       
  1680 
       
  1681 // ----------------------------------------------------------------------------
       
  1682 // CSysApAppUi::ShowQueryL()
       
  1683 // ----------------------------------------------------------------------------
       
  1684 
       
  1685 void CSysApAppUi::ShowQueryL( const TSysApConfirmationQueryIds aQueryId, const TDesC& aValue )
       
  1686     {
       
  1687     CancelGlobalListQuery();
       
  1688 
       
  1689     if ( aQueryId == ESysApRestartPhoneQuery )
       
  1690         {
       
  1691         iDisablePowerkeyMenu = ETrue;
       
  1692         // Cancel any other query that might be outstanding (i.e. ESysApRemoveMmcNote),
       
  1693         // to avoid multiple overlapping queries causing problems
       
  1694         if ( iSysApConfirmationQuery )
       
  1695             {
       
  1696             iSysApConfirmationQuery->Cancel();
       
  1697             }
       
  1698 
       
  1699         if ( !iSysApConfirmationQueryForRestart )
       
  1700             {
       
  1701             TRACES( RDebug::Print( _L("CSysApAppUi::ShowQueryL: trying CSysApConfirmationQuery::NewL() for restart") ) );
       
  1702             iSysApConfirmationQueryForRestart = CSysApConfirmationQuery::NewL( *this );
       
  1703             }
       
  1704 
       
  1705         iSysApConfirmationQueryForRestart->ShowQueryL( aQueryId, iEikonEnv );
       
  1706         }
       
  1707     else
       
  1708         {
       
  1709         if ( !iSysApConfirmationQuery )
       
  1710             {
       
  1711             TRACES( RDebug::Print( _L("CSysApAppUi::ShowQueryL: trying CSysApConfirmationQuery::NewL()") ) );
       
  1712             iSysApConfirmationQuery = CSysApConfirmationQuery::NewL( *this );
       
  1713             }
       
  1714 
       
  1715         iSysApConfirmationQuery->ShowQueryL( aQueryId, aValue, iEikonEnv );
       
  1716         }
       
  1717     }
       
  1718 
       
  1719 // ----------------------------------------------------------------------------
       
  1720 // CSysApAppUi::UpdateBatteryBarsL( const TInt aState )
       
  1721 // ----------------------------------------------------------------------------
       
  1722 
       
  1723 void CSysApAppUi::UpdateBatteryBarsL( const TInt aState )
       
  1724     {
       
  1725     TInt state( StateOfProperty( KPSUidHWRMPowerState, KHWRMChargingStatus ) );
       
  1726     TRACES( RDebug::Print( _L("CSysApAppUi::UpdateBatteryBarsL aState: %d, chargerState:%d"), aState, state ) );
       
  1727     HandleUsbCharger( state );
       
  1728     if( state == EChargingStatusCharging ||
       
  1729         state == EChargingStatusChargingContinued ||
       
  1730         state == EChargingStatusAlmostComplete )
       
  1731         {
       
  1732         if ( !iCharging )
       
  1733             {
       
  1734             TRACES( RDebug::Print( _L("CSysApAppUi::UpdateBatteryBarsL: Starting Charging") ) );
       
  1735             iBatteryNotify->StartChargingL();
       
  1736             iCharging = ETrue;
       
  1737             }
       
  1738 
       
  1739         // When Avkon supports battery state sending while charging,
       
  1740         // add setting battery level here also.
       
  1741         }
       
  1742     else
       
  1743         {
       
  1744         if ( iCharging )
       
  1745             {
       
  1746             TRACES( RDebug::Print( _L("CSysApAppUi::UpdateBatteryBarsL: Stopping Charging") ) );
       
  1747             iBatteryNotify->StopChargingL();
       
  1748             iCharging = EFalse;
       
  1749             }
       
  1750 
       
  1751         if( state == KErrUnknown || aState == KErrUnknown )
       
  1752             {
       
  1753             TRACES( RDebug::Print( _L("CSysApAppUi::UpdateBatteryBarsL: CAknBatteryNotify::SetBatteryLevelL(0)") ) );
       
  1754             iBatteryNotify->SetBatteryLevelL( 0 );
       
  1755             }
       
  1756         else
       
  1757             {
       
  1758             TRACES( RDebug::Print( _L("CSysApAppUi::UpdateBatteryBarsL: CAknBatteryNotify::SetBatteryLevelL(%d)"), aState - EBatteryLevelLevel0 ) );
       
  1759             iBatteryNotify->SetBatteryLevelL( aState - EBatteryLevelLevel0 );
       
  1760             }
       
  1761         }
       
  1762     
       
  1763     if ( !iSysApPsmController ) // created here if first state change has not occurred yet
       
  1764         {
       
  1765         iSysApPsmController = CSysApPsmController::NewL( *this );        
       
  1766         }
       
  1767 
       
  1768     if ( iSysApPsmController )
       
  1769         {
       
  1770         if ( iSysApPsmController->FullPsmEnabled() )
       
  1771             {
       
  1772             iBatteryNotify->SetBatteryStateL( EAknBatteryIndicatorPowerSave );
       
  1773             }
       
  1774         else
       
  1775             {
       
  1776             iBatteryNotify->SetBatteryStateL( EAknBatteryIndicatorNormal );
       
  1777             }            
       
  1778         }
       
  1779         
       
  1780     if ( iSysApBatteryInfoController )        
       
  1781         {
       
  1782         iSysApBatteryInfoController->BatteryLevelUpdatedL();
       
  1783         }
       
  1784     }
       
  1785 
       
  1786 // ----------------------------------------------------------------------------
       
  1787 // CSysApAppUi::UpdateSignalBarsL()
       
  1788 // ----------------------------------------------------------------------------
       
  1789 
       
  1790 void CSysApAppUi::UpdateSignalBarsL()
       
  1791     {
       
  1792     UpdateSignalBarsL(iSysApEtelConnector->GetSignalBars());
       
  1793     }
       
  1794 
       
  1795 // ----------------------------------------------------------------------------
       
  1796 // CSysApAppUi::UpdateSignalBarsL( const TInt aState )
       
  1797 // ----------------------------------------------------------------------------
       
  1798 
       
  1799 void CSysApAppUi::UpdateSignalBarsL( const TInt aState )
       
  1800     {
       
  1801     TRACES( RDebug::Print( _L("CSysApAppUi::UpdateSignalBarsL aState: %d"), aState ) );
       
  1802 
       
  1803     if( aState == KAknSignalOffLineMode || (iSysApOfflineModeController->OfflineModeActive() && !iEmergencyCallActive) )
       
  1804         {
       
  1805         iSignalNotify->SetSignalLevelL( KAknSignalOffLineMode );
       
  1806         }
       
  1807     else if( aState <= 0 )
       
  1808         {
       
  1809         // Do not update indicator show zero bars if we should be showing X over bars
       
  1810         // This is required for indicator to work correctly in BT SAP mode.
       
  1811         // Cannot use check for BT SAP enabled status, as zero bars notify comes before enabled status changes.
       
  1812         if ( !iIgnoreZeroNetworkBarNotifications )
       
  1813             {
       
  1814             iSignalNotify->SetSignalLevelL( 0 );
       
  1815             }
       
  1816         }
       
  1817     else
       
  1818         {
       
  1819         iSignalNotify->SetSignalLevelL( aState );
       
  1820         }
       
  1821     }
       
  1822 
       
  1823 // ----------------------------------------------------------------------------
       
  1824 // CSysApAppUi::SetSignalIndicatorL()
       
  1825 // ----------------------------------------------------------------------------
       
  1826 
       
  1827 void CSysApAppUi::SetSignalIndicatorL()
       
  1828     {
       
  1829     TSysApNetworkMode networkMode( ESysApGSM );
       
  1830 
       
  1831     TInt networkModeFromNetworkInfo( StateOfProperty( KPSUidNetworkInfo, KNWTelephonyNetworkMode ) );
       
  1832     if ( networkModeFromNetworkInfo == ENWNetworkModeWcdma )
       
  1833         {
       
  1834         networkMode = ESysApWCDMA;
       
  1835         }
       
  1836     else
       
  1837         {
       
  1838         networkMode = ESysApGSM;
       
  1839         }
       
  1840 
       
  1841     TRACES( RDebug::Print( _L("CSysApAppUi::SetSignalIndicatorL: networkMode = %d" ), networkMode ) );
       
  1842 
       
  1843     if( iSysApOfflineModeController->OfflineModeActive() && !iEmergencyCallActive )
       
  1844         {
       
  1845         // The device is in Offline Mode
       
  1846         if ( iSysApFeatureManager->Supported( KSysApFeatureIdGprs_G_Icon ) )
       
  1847             {
       
  1848             iSignalNotify->SetGprsStateL( EAknSignalGprsIndicatorOff );
       
  1849             }
       
  1850         else
       
  1851             {
       
  1852             iSignalNotify->SetCommonPacketDataStateL( EAknSignalCommonPacketDataIndicatorOff );
       
  1853             }
       
  1854         iSignalNotify->SetWcdmaStateL( EAknSignalWcdmaIndicatorOff );
       
  1855         iSignalNotify->SetHsdpaStateL( EAknSignalHsdpaIndicatorOff);
       
  1856         }
       
  1857     else
       
  1858         {
       
  1859         // The device is in Online Mode
       
  1860         switch ( networkMode )
       
  1861             {
       
  1862             case ESysApGSM:
       
  1863                 SetSignalIndicatorGsmL();
       
  1864                 break;
       
  1865 
       
  1866             case ESysApWCDMA:
       
  1867                 SetSignalIndicatorWcdmaL();
       
  1868                 break;
       
  1869 
       
  1870             default:
       
  1871                 break;
       
  1872             }
       
  1873         }
       
  1874     }
       
  1875 
       
  1876 // ----------------------------------------------------------------------------
       
  1877 // CSysApAppUi::SetSignalIndicatorGsmL()
       
  1878 // ----------------------------------------------------------------------------
       
  1879 void CSysApAppUi::SetSignalIndicatorGsmL()
       
  1880     {
       
  1881     TInt signalGprsIndicatorState( 0 );
       
  1882     TInt signalIndicatorState( 0 );
       
  1883 	TInt bearerValue = EBearerUnknown;
       
  1884 
       
  1885 	if(iSysApConnectionMonitorObserver)
       
  1886 		{
       
  1887 		bearerValue = iSysApConnectionMonitorObserver->GetBearerValue();
       
  1888 		}
       
  1889 
       
  1890 	if(bearerValue == EBearerEdgeGPRS)
       
  1891 		{
       
  1892 		TInt egprsStatus = StateOfProperty( KUidSystemCategory, KPSUidGprsStatusValue );
       
  1893 	    TRACES( RDebug::Print( _L("CSysApAppUi::SetSignalIndicatorGsmL gprsStatus: %d" ), egprsStatus ) );
       
  1894 	    iSignalNotify->SetWcdmaStateL( EAknSignalWcdmaIndicatorOff );
       
  1895 	    iSignalNotify->SetHsdpaStateL( EAknSignalHsdpaIndicatorOff );
       
  1896 	    switch ( egprsStatus )
       
  1897 	        {
       
  1898 	        case EPSGprsContextActive:
       
  1899 	            signalGprsIndicatorState = EAknSignalEdgeIndicatorContext;
       
  1900 	            signalIndicatorState = EAknSignalCommonPacketDataIndicatorContext;
       
  1901 	            iGprsActivated = ETrue;
       
  1902 	            iGprsSuspended = EFalse;
       
  1903 	            HandleGprsNotesL();
       
  1904 	            break;
       
  1905 
       
  1906 	        case EPSGprsContextActivating:
       
  1907 	            signalGprsIndicatorState = EAknSignalEdgeIndicatorEstablishingContext;
       
  1908 	            signalIndicatorState = EAknSignalCommonPacketDataIndicatorEstablishingContext;
       
  1909 	            iGprsActivated = EFalse;
       
  1910 	            iGprsSuspended = EFalse;
       
  1911 	            break;
       
  1912 
       
  1913 	        case EPSGprsSuspend:
       
  1914 	            signalGprsIndicatorState = EAknSignalEdgeIndicatorSuspended;
       
  1915 	            signalIndicatorState = EAknSignalCommonPacketDataIndicatorSuspended;
       
  1916 	            iGprsSuspended = ETrue;
       
  1917 	            HandleGprsNotesL();
       
  1918 	            break;
       
  1919 
       
  1920 	        case EPSGprsAttach:
       
  1921 	            signalGprsIndicatorState = EAknSignalEdgeIndicatorAttached;
       
  1922 	            signalIndicatorState = EAknSignalCommonPacketDataIndicatorAttached;
       
  1923 	            iGprsActivated = EFalse;
       
  1924 	            iGprsSuspended = EFalse;
       
  1925 	            break;
       
  1926 
       
  1927 	        case EPSGprsMultibleContextActive:
       
  1928 	            signalGprsIndicatorState = EAknSignalEdgeIndicatorMultipdp;
       
  1929 	            signalIndicatorState = EAknSignalCommonPacketDataIndicatorMultipdp;
       
  1930 	            iGprsActivated = ETrue;
       
  1931 	            iGprsSuspended = EFalse;
       
  1932 	            HandleGprsNotesL();
       
  1933 	            break;
       
  1934 
       
  1935 	        case EPSGprsUnattached:
       
  1936 	        default:
       
  1937 	            signalGprsIndicatorState = EAknSignalEdgeIndicatorOff;
       
  1938 	            signalIndicatorState = EAknSignalCommonPacketDataIndicatorOff;
       
  1939 	            iGprsSuspendedNoteShown = EFalse;
       
  1940 	            iGprsActivated = EFalse;
       
  1941 	            iGprsSuspended = EFalse;
       
  1942 	            iCallActivated = EFalse;
       
  1943 	            break;
       
  1944 	        }
       
  1945         }
       
  1946 	else
       
  1947 		{
       
  1948 
       
  1949 		TInt gprsStatus = StateOfProperty( KUidSystemCategory, KPSUidGprsStatusValue );
       
  1950     	TRACES( RDebug::Print( _L("CSysApAppUi::SetSignalIndicatorGsmL gprsStatus: %d" ), gprsStatus ) );
       
  1951     	iSignalNotify->SetWcdmaStateL( EAknSignalWcdmaIndicatorOff );
       
  1952     	iSignalNotify->SetHsdpaStateL( EAknSignalHsdpaIndicatorOff );
       
  1953     	switch ( gprsStatus )
       
  1954             {
       
  1955             case EPSGprsContextActive:
       
  1956                 signalGprsIndicatorState = EAknSignalGprsIndicatorContext;
       
  1957                 signalIndicatorState = EAknSignalCommonPacketDataIndicatorContext;
       
  1958                 iGprsActivated = ETrue;
       
  1959                 iGprsSuspended = EFalse;
       
  1960                 HandleGprsNotesL();
       
  1961                 break;
       
  1962 
       
  1963             case EPSGprsContextActivating:
       
  1964                 signalGprsIndicatorState = EAknSignalGprsIndicatorEstablishingContext;
       
  1965                 signalIndicatorState = EAknSignalCommonPacketDataIndicatorEstablishingContext;
       
  1966                 iGprsActivated = EFalse;
       
  1967                 iGprsSuspended = EFalse;
       
  1968                 break;
       
  1969 
       
  1970             case EPSGprsSuspend:
       
  1971                 signalGprsIndicatorState = EAknSignalGprsIndicatorSuspended;
       
  1972                 signalIndicatorState = EAknSignalCommonPacketDataIndicatorSuspended;
       
  1973                 iGprsSuspended = ETrue;
       
  1974                 HandleGprsNotesL();
       
  1975                 break;
       
  1976 
       
  1977             case EPSGprsAttach:
       
  1978                 signalGprsIndicatorState = EAknSignalGprsIndicatorAttached;
       
  1979                 signalIndicatorState = EAknSignalCommonPacketDataIndicatorAttached;
       
  1980                 iGprsActivated = EFalse;
       
  1981                 iGprsSuspended = EFalse;
       
  1982                 break;
       
  1983 
       
  1984             case EPSGprsMultibleContextActive:
       
  1985                 signalGprsIndicatorState = EAknSignalGprsIndicatorMultipdp;
       
  1986                 signalIndicatorState = EAknSignalCommonPacketDataIndicatorMultipdp;
       
  1987                 iGprsActivated = ETrue;
       
  1988                 iGprsSuspended = EFalse;
       
  1989                 HandleGprsNotesL();
       
  1990                 break;
       
  1991 
       
  1992             case EPSGprsUnattached:
       
  1993             default:
       
  1994                 signalGprsIndicatorState = EAknSignalGprsIndicatorOff;
       
  1995                 signalIndicatorState = EAknSignalCommonPacketDataIndicatorOff;
       
  1996                 iGprsSuspendedNoteShown = EFalse;
       
  1997                 iGprsActivated = EFalse;
       
  1998                 iGprsSuspended = EFalse;
       
  1999                 iCallActivated = EFalse;
       
  2000                 break;
       
  2001             }
       
  2002 		}
       
  2003 
       
  2004 	if(bearerValue == EBearerEdgeGPRS) //EdgeGPRS connection
       
  2005 		{
       
  2006 		if( iSysApFeatureManager->Supported( KSysApFeatureIdUseEdgeGPRSIcon ) )
       
  2007 	    	{
       
  2008 	    	iSignalNotify->SetEdgeStateL( signalGprsIndicatorState );
       
  2009 	    	}
       
  2010 	    else
       
  2011         	{
       
  2012         	iSignalNotify->SetCommonPacketDataStateL( signalIndicatorState );
       
  2013         	}
       
  2014 		}
       
  2015 	else
       
  2016 		{
       
  2017 
       
  2018 	    if ( iSysApFeatureManager->Supported( KSysApFeatureIdGprs_G_Icon ) )
       
  2019     	    {
       
  2020         	iSignalNotify->SetGprsStateL( signalGprsIndicatorState );
       
  2021         	}
       
  2022     	else
       
  2023         	{
       
  2024         	TRACES( RDebug::Print( _L("CSysApAppUi::SetSignalIndicatorGsmL SetCommonPacketDataStateL( %d )" ), signalIndicatorState ) );
       
  2025         	iSignalNotify->SetCommonPacketDataStateL( signalIndicatorState );
       
  2026         	}
       
  2027 		}
       
  2028     }
       
  2029 
       
  2030 // ----------------------------------------------------------------------------
       
  2031 // CSysApAppUi::SetSignalIndicatorWcdmaL()
       
  2032 // ----------------------------------------------------------------------------
       
  2033 void CSysApAppUi::SetSignalIndicatorWcdmaL()
       
  2034     {
       
  2035     TInt wcdmaStatus;
       
  2036     wcdmaStatus = StateOfProperty( KUidSystemCategory, KPSUidWcdmaStatusValue );
       
  2037     TRACES( RDebug::Print( _L("CSysApAppUi::SetSignalIndicatorWcdmaL: wcdmaStatus: %d" ), wcdmaStatus ) );
       
  2038 
       
  2039     if ( iSysApFeatureManager->Supported( KSysApFeatureIdGprs_G_Icon ) )
       
  2040         {
       
  2041         iSignalNotify->SetGprsStateL( EAknSignalGprsIndicatorOff );
       
  2042         }
       
  2043     else
       
  2044         {
       
  2045         iSignalNotify->SetCommonPacketDataStateL( EAknSignalCommonPacketDataIndicatorOff );
       
  2046         }
       
  2047 
       
  2048     TInt signalWcdmaIndicatorState;
       
  2049     TInt signalHsdpaIndicatorState;
       
  2050 
       
  2051     switch ( wcdmaStatus )
       
  2052         {
       
  2053         case EPSWcdmaContextActive:
       
  2054             signalWcdmaIndicatorState = EAknSignalWcdmaIndicatorContext;
       
  2055             signalHsdpaIndicatorState = EAknSignalHsdpaIndicatorContext;
       
  2056             break;
       
  2057         case EPSWcdmaContextActivating:
       
  2058             signalWcdmaIndicatorState = EAknSignalWcdmaIndicatorEstablishingContext;
       
  2059             signalHsdpaIndicatorState = EAknSignalHsdpaIndicatorEstablishingContext;
       
  2060             break;
       
  2061         case EPSWcdmaSuspend:
       
  2062             signalWcdmaIndicatorState = EAknSignalWcdmaIndicatorSuspended;
       
  2063             signalHsdpaIndicatorState = EAknSignalHsdpaIndicatorSuspended;
       
  2064             break;
       
  2065         case EPSWcdmaAttach:
       
  2066             signalWcdmaIndicatorState = EAknSignalWcdmaIndicatorAttached;
       
  2067             signalHsdpaIndicatorState = EAknSignalHsdpaIndicatorAttached;
       
  2068             break;
       
  2069         case EPSWcdmaMultipleContextActive:
       
  2070             signalWcdmaIndicatorState = EAknSignalWcdmaIndicatorMultipdp;
       
  2071             signalHsdpaIndicatorState = EAknSignalHsdpaIndicatorMultipdp;
       
  2072             break;
       
  2073         case EPSWcdmaUnattached:
       
  2074         default:
       
  2075             signalWcdmaIndicatorState = EAknSignalWcdmaIndicatorAvailable;
       
  2076             signalHsdpaIndicatorState = EAknSignalHsdpaIndicatorAvailable;
       
  2077             break;
       
  2078         }
       
  2079 
       
  2080     TBool showHsdpaAvailable = EFalse;
       
  2081 
       
  2082     if ( iSysApFeatureManager->Supported( KSysApFeatureIdUseHsdpaAvailableIcon ) )
       
  2083         {
       
  2084         // HSDPA Resource Availability information is a configurable feature.
       
  2085         showHsdpaAvailable = iSysApEtelConnector->HsdpaAvailable();
       
  2086         }
       
  2087     
       
  2088     TBool isHsdpaBearer = iSysApEtelConnector->IsBearerHsdpa();
       
  2089     
       
  2090     TRACES( RDebug::Print( _L("CSysApAppUi::SetSignalIndicatorWcdmaL: isHdpaBearer=%d, showHsdpaAvailable=%d" ),
       
  2091             isHsdpaBearer, showHsdpaAvailable ) );
       
  2092     
       
  2093     if ( isHsdpaBearer || showHsdpaAvailable )
       
  2094         {
       
  2095         iSignalNotify->SetWcdmaStateL( EAknSignalWcdmaIndicatorOff );
       
  2096     	iSignalNotify->SetHsdpaStateL( signalHsdpaIndicatorState );
       
  2097         }
       
  2098     else
       
  2099         {
       
  2100         iSignalNotify->SetHsdpaStateL( EAknSignalHsdpaIndicatorOff );
       
  2101         iSignalNotify->SetWcdmaStateL( signalWcdmaIndicatorState );
       
  2102         }
       
  2103     }
       
  2104 
       
  2105 // ----------------------------------------------------------------------------
       
  2106 // CSysApAppUi::HandleGprsNotesL()
       
  2107 // ----------------------------------------------------------------------------
       
  2108 
       
  2109 void CSysApAppUi::HandleGprsNotesL()
       
  2110     {
       
  2111     TRACES( RDebug::Print( _L("CSysApAppUi::HandleGprsNotesL" ) ) );
       
  2112     if ( iSysApFeatureManager->Supported( KSysApFeatureIdGPRSNotes ) )
       
  2113         {
       
  2114         // In WCDMA system, receiving or making calls has no effect to the possibly
       
  2115         // existing PDP contexts i.e. GPRS notes are not needed.
       
  2116         TInt networkMode = StateOfProperty( KPSUidNetworkInfo, KNWTelephonyNetworkMode );
       
  2117         TRACES( RDebug::Print( _L("CSysApAppUi::HandleGprsNotesL: networkMode %d" ), networkMode ) );
       
  2118         if ( networkMode != ENWNetworkModeWcdma )
       
  2119             {
       
  2120             if ( iGprsActivated && iGprsSuspended && iCallActivated && !iGprsSuspendedNoteShown )
       
  2121                 {
       
  2122                 StartGprsSuspendedTimer();
       
  2123                 }
       
  2124             else if ( iGprsSuspendedNoteShown && !iGprsSuspended )
       
  2125                 {
       
  2126                 ShowUiNoteL( EGprsResumedNote );
       
  2127                 iGprsSuspendedNoteShown = EFalse;
       
  2128                 iGprsSuspended = EFalse;
       
  2129                 iCallActivated = EFalse;
       
  2130                 }
       
  2131             }
       
  2132         }
       
  2133     }
       
  2134 
       
  2135 // ----------------------------------------------------------------------------
       
  2136 // CSysApAppUi::SetIndicatorStateL( TInt aIndicator, TInt aState )
       
  2137 // ----------------------------------------------------------------------------
       
  2138 
       
  2139 void CSysApAppUi::SetIndicatorStateL( const TInt aIndicator, const TInt aState ) const
       
  2140     {
       
  2141     CAknSmallIndicator* theIndicator = CAknSmallIndicator::NewLC( TUid::Uid( aIndicator ) );
       
  2142     theIndicator->SetIndicatorStateL( aState );
       
  2143     CleanupStack::PopAndDestroy(); //theIndicator
       
  2144     }
       
  2145 
       
  2146 // ----------------------------------------------------------------------------
       
  2147 // CSysApAppUi::GoOnlineL()
       
  2148 // ----------------------------------------------------------------------------
       
  2149 
       
  2150 void CSysApAppUi::GoOnlineL( TBool aDoProfileChange )
       
  2151     {
       
  2152     if ( iSysApFeatureManager->OfflineModeSupported() )
       
  2153         {
       
  2154         TRACES( RDebug::Print( _L("CSysApAppUi::GoOnlineL: going from off-line into on-line: aDoProfileChange=%d" ), aDoProfileChange ) );
       
  2155         // in case profile change is not needed, event handling for subsequent profile changes are must be allowed
       
  2156         iHandleNextProfileEvent = !aDoProfileChange;
       
  2157         iActivateBt = iSysApOfflineModeController->MustBtBeActivated();
       
  2158 
       
  2159         if ( aDoProfileChange )
       
  2160             {
       
  2161             TRAPD( err, ActivateProfileL( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApProfileBeforeOfflineMode ) ) );
       
  2162             if ( err == KErrNotFound )
       
  2163                 {
       
  2164                 // Activate general profile instead, if previously used profile was not found
       
  2165                 TRACES( RDebug::Print( _L("CSysApAppUi::GoOnlineL: Previously used profile was not found, restoring to general profile" ) ) );
       
  2166                 ActivateProfileL(KGeneralProfileId);
       
  2167                 }
       
  2168             }
       
  2169 
       
  2170         iSysApOfflineModeController->SwitchFromOfflineToOnlineModeL();
       
  2171         TRACES( RDebug::Print( _L("CSysApAppUi::GoOnlineL: iActivateBt = %d" ), iActivateBt ) );
       
  2172         }
       
  2173     }
       
  2174 
       
  2175 // ----------------------------------------------------------------------------
       
  2176 // CSysApAppUi::GoOfflineL()
       
  2177 // ----------------------------------------------------------------------------
       
  2178 
       
  2179 void CSysApAppUi::GoOfflineL()
       
  2180     {
       
  2181     if ( iSysApFeatureManager->OfflineModeSupported() )
       
  2182         {
       
  2183         TRACES( RDebug::Print( _L("CSysApAppUi::GoOfflineL" ) ) );
       
  2184         iHandleNextProfileEvent = EFalse;
       
  2185         iDeactivateBt = ETrue;
       
  2186         ActivateProfileL( KOfflineModeProfileId );
       
  2187         iSysApOfflineModeController->SwitchFromOnlineToOfflineModeL();
       
  2188         }
       
  2189     }
       
  2190 
       
  2191 // ----------------------------------------------------------------------------
       
  2192 // CSysApAppUi::SwitchFromOnlineToOfflineModeL()
       
  2193 // ----------------------------------------------------------------------------
       
  2194 void CSysApAppUi::SwitchFromOnlineToOfflineModeL()
       
  2195     {
       
  2196 /*    if ( iSysApFeatureManager->FmTxSupported() )
       
  2197         {
       
  2198         TFmTxState state = static_cast<TFmTxState>(StateOfProperty( KPSUidHWRMFmTx, KHWRMFmTxStatus ));
       
  2199         switch ( state )
       
  2200             {
       
  2201             case EFmTxStateActive:
       
  2202             case EFmTxStateInactive:
       
  2203             case EFmTxStateScanning:
       
  2204                 ShowQueryL( ESysApUseFmTxInOfflineQuery ); // show "use fm tx in offline?" if FM TX is on
       
  2205                 break;
       
  2206             
       
  2207             default:
       
  2208                 // do nothing
       
  2209                 break;                
       
  2210             }
       
  2211         }
       
  2212 */    iSysApOfflineModeController->SwitchFromOnlineToOfflineModeL();
       
  2213     }
       
  2214 
       
  2215 // ----------------------------------------------------------------------------
       
  2216 // CSysApAppUi::OfflineModeChangedL()
       
  2217 // ----------------------------------------------------------------------------
       
  2218 void CSysApAppUi::OfflineModeChangedL()
       
  2219     {
       
  2220 #ifdef SYSAP_USE_STARTUP_UI_PHASE    
       
  2221     // if UI is not ready, don't update indicators
       
  2222     if ( !UiReady() )
       
  2223         {
       
  2224         return;
       
  2225         }
       
  2226 #endif // SYSAP_USE_STARTUP_UI_PHASE
       
  2227     
       
  2228     // Update network bar indicator
       
  2229     if ( OfflineModeActive() )
       
  2230         {
       
  2231         UpdateSignalBarsL( KAknSignalOffLineMode );
       
  2232         }
       
  2233     else
       
  2234         {
       
  2235         UpdateSignalBarsL();    
       
  2236         }        
       
  2237     
       
  2238     // Update network mode indicator
       
  2239     SetSignalIndicatorL();
       
  2240     
       
  2241     // Update HAC indicator
       
  2242     SetHacIndicatorL();
       
  2243     }
       
  2244 
       
  2245 // ----------------------------------------------------------------------------
       
  2246 // CSysApAppUi::OfflineModeActive()
       
  2247 // ----------------------------------------------------------------------------
       
  2248 TBool CSysApAppUi::OfflineModeActive()
       
  2249     {
       
  2250     return iSysApOfflineModeController->OfflineModeActive();
       
  2251     }
       
  2252 
       
  2253 // ----------------------------------------------------------------------------
       
  2254 // CSysApAppUi::DoNotActivateBt()
       
  2255 // ----------------------------------------------------------------------------
       
  2256 void CSysApAppUi::DoNotActivateBt()
       
  2257     {
       
  2258     iSysApOfflineModeController->DoNotActivateBt();
       
  2259     }
       
  2260 
       
  2261 // ----------------------------------------------------------------------------
       
  2262 // CSysApAppUi::SetBtPowerState()
       
  2263 // ----------------------------------------------------------------------------
       
  2264 TInt CSysApAppUi::SetBtPowerState( TBool aBtState )
       
  2265     {
       
  2266     if ( iSysApBtController )
       
  2267         {
       
  2268         return iSysApBtController->SetPowerState( aBtState );
       
  2269         }
       
  2270     else
       
  2271         {
       
  2272         return KErrNotReady;
       
  2273         }
       
  2274     }
       
  2275 
       
  2276 // ----------------------------------------------------------------------------
       
  2277 // CSysApAppUi::KeyLockState() const
       
  2278 // ----------------------------------------------------------------------------
       
  2279 
       
  2280 TBool CSysApAppUi::KeyLockState() const
       
  2281     {
       
  2282     return iKeyLockEnabled;
       
  2283     }
       
  2284 
       
  2285 // ----------------------------------------------------------------------------
       
  2286 // CSysApAppUi::DeviceLockState() const
       
  2287 // ----------------------------------------------------------------------------
       
  2288 
       
  2289 TBool CSysApAppUi::DeviceLockState() const
       
  2290     {
       
  2291     return iDeviceLockEnabled;
       
  2292     }
       
  2293 /*
       
  2294 // ----------------------------------------------------------------------------
       
  2295 // CSysApAppUi::ChangeFmTxStateL()
       
  2296 // ----------------------------------------------------------------------------     
       
  2297 void CSysApAppUi::ChangeFmTxStateL( TBool aEnable )
       
  2298     {
       
  2299     // disable fm transmission
       
  2300     CHWRMFmTx* fmtx = CHWRMFmTx::NewLC();
       
  2301     if ( aEnable )
       
  2302        {
       
  2303        fmtx->EnableL();
       
  2304        }
       
  2305     else 
       
  2306        {
       
  2307        fmtx->DisableL();
       
  2308        }
       
  2309     CleanupStack::PopAndDestroy( fmtx );
       
  2310     } 
       
  2311 */
       
  2312 
       
  2313 // ----------------------------------------------------------------------------
       
  2314 // CSysApAppUi::SetIhfIndicatorL()
       
  2315 // ----------------------------------------------------------------------------
       
  2316 void CSysApAppUi::SetIhfIndicatorL()
       
  2317     {
       
  2318     TBool accessoryConnected ( EFalse );
       
  2319 
       
  2320     TInt callState( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
       
  2321 
       
  2322     TAccMode accMode(EAccModeHandPortable);
       
  2323 
       
  2324     if ( iSysApAccessoryObserver )
       
  2325         {
       
  2326         accMode = iSysApAccessoryObserver->GetAccessoryMode();
       
  2327 
       
  2328         if ( accMode != EAccModeHandPortable )
       
  2329             {
       
  2330             accessoryConnected = ETrue;
       
  2331             }
       
  2332         }
       
  2333 
       
  2334     if( (callState != EPSCTsyCallStateNone && IhfEnabledL() && !accessoryConnected)
       
  2335         || accMode == EAccModeMusicStand )  // Music stand always shows IHF indicator
       
  2336         {
       
  2337         SetIndicatorStateL( EAknIndicatorIHFActive, EAknIndicatorStateOn );
       
  2338 
       
  2339         if ( accMode == EAccModeMusicStand )
       
  2340             {
       
  2341             // hide other accessory indicators to prevent displaying of duplicate icons in some cases
       
  2342             // e.g. when wireless hf is connected
       
  2343             SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
  2344             SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
  2345             SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
  2346             SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  2347             SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
  2348             SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
  2349             SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
  2350             }
       
  2351         }
       
  2352     else
       
  2353         {
       
  2354         SetIndicatorStateL( EAknIndicatorIHFActive, EAknIndicatorStateOff );
       
  2355         }
       
  2356     }
       
  2357 
       
  2358 // ----------------------------------------------------------------------------
       
  2359 // CSysApAppUi::HandleSmsStorageNotificationL( TBool aSimStoreFull )
       
  2360 // ----------------------------------------------------------------------------
       
  2361 
       
  2362 void CSysApAppUi::HandleSmsStorageNotificationL( TBool aSimStoreFull )
       
  2363     {
       
  2364     TRACES( RDebug::Print( _L("CSysApAppUi::HandleSmsStorageNotificationL: aSimStoreFull: %d "), aSimStoreFull ) );
       
  2365 
       
  2366     if ( aSimStoreFull )
       
  2367         {
       
  2368         HBufC* noteStringBuf;
       
  2369         noteStringBuf = StringLoader::LoadLC( R_QTN_MEMLO_MEMORY_LOW_SIM_MES, iEikonEnv );
       
  2370         TPtr textBuffer = noteStringBuf->Des();
       
  2371         iSysApMsgSimMemLowQuery->StartL( textBuffer );
       
  2372         CleanupStack::PopAndDestroy();
       
  2373         }
       
  2374 
       
  2375     SetEnvelopeIndicatorL();
       
  2376     }
       
  2377 
       
  2378 // ----------------------------------------------------------------------------
       
  2379 // CSysApAppUi::HandleNspsRawKeyEventL()
       
  2380 // ----------------------------------------------------------------------------
       
  2381 
       
  2382 void CSysApAppUi::HandleNspsRawKeyEventL()
       
  2383     {
       
  2384 #ifdef __SYSAP_MODULE_TEST
       
  2385     ModuleTestShowUiNoteL( _L("Network wakeup from NSPS") );
       
  2386 #endif
       
  2387 
       
  2388     if ( iSysApEtelConnector )
       
  2389         {
       
  2390         iSysApEtelConnector->CommandNetCsWakeupOnNsps();
       
  2391         }
       
  2392     }
       
  2393 
       
  2394 // ----------------------------------------------------------------------------
       
  2395 // CSysApAppUi::HandleNetworkNspsNotification( RMmCustomAPI::TNspsStatus aNspsStatus )
       
  2396 // ----------------------------------------------------------------------------
       
  2397 
       
  2398 void CSysApAppUi::HandleNetworkNspsNotification( RMmCustomAPI::TNspsStatus aNspsStatus )
       
  2399     {
       
  2400     TRACES( RDebug::Print( _L("CSysApAppUi::HandleNetworkNspsNotification aNspsStatus:%d, iNsps:%d )" ), aNspsStatus, iNsps ) );
       
  2401     if( iSysApNspsHandler )
       
  2402         {
       
  2403         if( aNspsStatus == RMmCustomAPI::ENspsOn )
       
  2404             {
       
  2405             if( !iNsps )
       
  2406                 {
       
  2407 #ifdef __SYSAP_MODULE_TEST
       
  2408                 TRAPD( err, ModuleTestShowUiNoteL( _L("Setting NSPS on") ) );
       
  2409 #endif
       
  2410                 iSysApNspsHandler->SetNspsOn();
       
  2411                 iNsps = ETrue;
       
  2412                 }
       
  2413             }
       
  2414         else if( aNspsStatus == RMmCustomAPI::ENspsOff )
       
  2415             {
       
  2416             if( iNsps )
       
  2417                 {
       
  2418 #ifdef __SYSAP_MODULE_TEST
       
  2419                 TRAPD( err, ModuleTestShowUiNoteL( _L("Setting NSPS off") ) );
       
  2420 #endif
       
  2421                 iSysApNspsHandler->SetNspsOff();
       
  2422                 iNsps = EFalse;
       
  2423                 }
       
  2424             }
       
  2425         }
       
  2426     }
       
  2427 
       
  2428 // ----------------------------------------------------------------------------
       
  2429 // CSysApAppUi::HandleMessageTonePlayingQuitability( TInt aTonePlayingStatus )
       
  2430 // ----------------------------------------------------------------------------
       
  2431 
       
  2432 void CSysApAppUi::HandleMessageTonePlayingQuitability( TInt aTonePlayingStatus )
       
  2433     {
       
  2434     if( iSysApNspsHandler )
       
  2435         {
       
  2436         if( aTonePlayingStatus == ECoreAppUIsStopTonePlaying )
       
  2437             {
       
  2438             iSysApNspsHandler->SetMessageToneNotPlaying();
       
  2439             }
       
  2440         else if( aTonePlayingStatus == ECoreAppUIsTonePlaying )
       
  2441             {
       
  2442             iSysApNspsHandler->SetMessageTonePlaying();
       
  2443             }
       
  2444         }
       
  2445     }
       
  2446 
       
  2447 // ----------------------------------------------------------------------------
       
  2448 // CSysApAppUi::ActivateKeyeventForwardingForLights()
       
  2449 // ----------------------------------------------------------------------------
       
  2450 
       
  2451 void CSysApAppUi::ActivateKeyeventForwardingForLights(TBool aActivate)
       
  2452     {
       
  2453     if( iSysApNspsHandler )
       
  2454         {
       
  2455         if ( aActivate )
       
  2456             {
       
  2457             iSysApNspsHandler->ActivateKeyeventForwardingForLights();
       
  2458             }
       
  2459         else
       
  2460             {
       
  2461             iSysApNspsHandler->DeActivateKeyeventForwardingForLights();
       
  2462             }
       
  2463         }
       
  2464     }
       
  2465 
       
  2466 // ----------------------------------------------------------------------------
       
  2467 // CSysApAppUi::StartShutDownTimerOnAlarmAndChargingStates()
       
  2468 // ----------------------------------------------------------------------------
       
  2469 
       
  2470 void CSysApAppUi::StartShutDownTimerOnAlarmAndChargingStates()
       
  2471     {
       
  2472     if( !iAlarmOrChargingStateShutdownStarted )
       
  2473         {
       
  2474         if ( !iTimer )
       
  2475             {
       
  2476             TRAPD( err, iTimer = CPeriodic::NewL( EPriorityNormal ) );
       
  2477 
       
  2478             if ( err != KErrNone )
       
  2479                 {
       
  2480                 TRACES( RDebug::Print( _L("CSysApAppUi::StartShutDownTimerOnAlarmAndChargingStates: CPeriodic::NewL failed: %d"), err ) );
       
  2481                 return;
       
  2482                 }
       
  2483             }
       
  2484         iTimer->Cancel();
       
  2485         iTimer->Start( KDelayBeforeShuttingDownInAlarmAndChargingStates,
       
  2486                        KDelayBeforeShuttingDownInAlarmAndChargingStates,
       
  2487                        TCallBack( DoShutdownOnAlarmStateAfterCallBack, this ) );
       
  2488         iAlarmOrChargingStateShutdownStarted = ETrue;
       
  2489         }
       
  2490     }
       
  2491 
       
  2492 // ----------------------------------------------------------------------------
       
  2493 // CSysApAppUi::DoShutdownOnAlarmStateAfterCallBack( TAny* aObject )
       
  2494 // ----------------------------------------------------------------------------
       
  2495 
       
  2496 TInt CSysApAppUi::DoShutdownOnAlarmStateAfterCallBack( TAny* aObject )
       
  2497     {
       
  2498     CSysApAppUi* appUi = STATIC_CAST( CSysApAppUi*, aObject );
       
  2499 
       
  2500     if ( appUi->iTimer )
       
  2501         {
       
  2502         appUi->iTimer->Cancel();
       
  2503         }
       
  2504 
       
  2505     TRAP_IGNORE( appUi->DoShutdownL( EFalse, KDummyReason ) );
       
  2506 
       
  2507     return KErrNone;
       
  2508     }
       
  2509 
       
  2510 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  2511 // ----------------------------------------------------------------------------
       
  2512 // CSysApAppUi::StartAnimTiming()
       
  2513 // ----------------------------------------------------------------------------
       
  2514 void CSysApAppUi::StartAnimTiming()
       
  2515     {
       
  2516     TRACES( RDebug::Print( _L("CSysApAppUi::StartAnimTiming() Start animation timer, time %d ms" ), iAnimationShowingTime  ) );
       
  2517 
       
  2518     if ( !iAnimTimer )
       
  2519         {
       
  2520         TRAPD( err, iAnimTimer = CPeriodic::NewL( EPriorityNormal ) );
       
  2521 
       
  2522         if ( err != KErrNone )
       
  2523             {
       
  2524             TRACES( RDebug::Print( _L("CSysApAppUi::StartAnimTiming() CPeriodic::NewL failed %d " ), err ) );
       
  2525             return;
       
  2526             }
       
  2527         }
       
  2528 
       
  2529     iAnimTimer->Start(
       
  2530         iAnimationShowingTime*KCoefficientToMakeMicroToMilliSeconds,
       
  2531         iAnimationShowingTime*KCoefficientToMakeMicroToMilliSeconds,
       
  2532         TCallBack( DoStopAnimTiming, this ) );
       
  2533     }
       
  2534 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  2535 
       
  2536 // ----------------------------------------------------------------------------
       
  2537 // CSysApAppUi::DoStopAnimTiming( TAny* aObject )
       
  2538 // ----------------------------------------------------------------------------
       
  2539 
       
  2540 TInt CSysApAppUi::DoStopAnimTiming( TAny* aObject )
       
  2541     {
       
  2542     TInt err(KErrNone);
       
  2543     CSysApAppUi* appUi = STATIC_CAST( CSysApAppUi*, aObject );
       
  2544 
       
  2545     // This method could theoretically be called by two timers (iAnimTimer and one in CSysApShutdownAnimation),
       
  2546     // so a check is needed to prevent multiple executions.
       
  2547     if ( !(appUi->iShutdownContinued) )
       
  2548         {
       
  2549         appUi->iShutdownContinued = ETrue;
       
  2550 
       
  2551         TRACES( RDebug::Print( _L("CSysApAppUi::DoStopAnimTiming() Animation timer completed or animation skipped" ) ) );
       
  2552 
       
  2553 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  2554         if ( appUi->iAnimTimer )
       
  2555             {
       
  2556             appUi->iAnimTimer->Cancel();
       
  2557             }
       
  2558 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  2559 
       
  2560         if ( appUi->iTimer )
       
  2561             {
       
  2562             appUi->iTimer->Cancel();
       
  2563             }
       
  2564 
       
  2565         TRACES( RDebug::Print( _L("CSysApAppUi::DoStopAnimTiming() Call ContinueShutdown(...)" ) ) );
       
  2566         appUi->ContinueShutdown();
       
  2567         TRACES( RDebug::Print( _L("CSysApAppUi::DoStopAnimTiming() end") ) );
       
  2568         }
       
  2569 
       
  2570     return err;
       
  2571     }
       
  2572 
       
  2573 
       
  2574 // ----------------------------------------------------------------------------
       
  2575 // CSysApAppUi::StartGprsSuspendedTimer()
       
  2576 // ----------------------------------------------------------------------------
       
  2577 
       
  2578 void CSysApAppUi::StartGprsSuspendedTimer()
       
  2579     {
       
  2580     TRACES( RDebug::Print( _L("CSysApAppUi::StartGprsSuspendedTimer()") ) );
       
  2581     if( !iAlarmOrChargingStateShutdownStarted ) // not relevant if shutting down
       
  2582         {
       
  2583         if ( !iTimer )
       
  2584             {
       
  2585             TRAPD( err, iTimer = CPeriodic::NewL( EPriorityNormal ) );
       
  2586 
       
  2587             if ( err != KErrNone )
       
  2588                 {
       
  2589                 TRACES( RDebug::Print( _L("CSysApAppUi::StartGprsSuspendedTimer: CPeriodic::NewL failed: %d"), err ) );
       
  2590                 return;
       
  2591                 }
       
  2592             }
       
  2593 
       
  2594         iTimer->Cancel();
       
  2595         iTimer->Start( KDelayBeforeShowingGprsSuspendedNote,
       
  2596                        KDelayBeforeShowingGprsSuspendedNote,
       
  2597                        TCallBack( ShowGprsSuspendedNoteAfterCallBack, this ) );
       
  2598         }
       
  2599     }
       
  2600 
       
  2601 // ----------------------------------------------------------------------------
       
  2602 // CSysApAppUi::ShowGprsSuspendedNoteAfterCallBack( TAny* aObject )
       
  2603 // ----------------------------------------------------------------------------
       
  2604 
       
  2605 TInt CSysApAppUi::ShowGprsSuspendedNoteAfterCallBack( TAny* aObject )
       
  2606     {
       
  2607     TRACES( RDebug::Print( _L("CSysApAppUi::ShowGprsSuspendedNoteAfterCallBack") ) );
       
  2608 
       
  2609     CSysApAppUi* appUi = STATIC_CAST( CSysApAppUi*, aObject );
       
  2610 
       
  2611     if ( appUi->iTimer )
       
  2612         {
       
  2613         appUi->iTimer->Cancel();
       
  2614         }
       
  2615 
       
  2616     // Note is needed if call is still active and used network is not WCDMA
       
  2617     TInt callType = appUi->StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallType );
       
  2618     TInt networkMode = appUi->StateOfProperty( KPSUidNetworkInfo, KNWTelephonyNetworkMode );
       
  2619     TRACES( RDebug::Print(
       
  2620         _L("CSysApAppUi::ShowGprsSuspendedNoteAfterCallBack: callType %d networkMode %d"),
       
  2621         callType, networkMode ) );
       
  2622     if ( EPSCTsyCallTypeCSVoice == callType && ENWNetworkModeWcdma != networkMode )
       
  2623         {
       
  2624         appUi->iGprsSuspendedNoteShown = ETrue;
       
  2625         TRAP_IGNORE( appUi->ShowUiNoteL( EGprsSuspendedNote ) );
       
  2626         }
       
  2627     return KErrNone;
       
  2628     }
       
  2629 
       
  2630 // ----------------------------------------------------------------------------
       
  2631 // CSysApAppUi::HandleAccessoryConnectedL()
       
  2632 // ----------------------------------------------------------------------------
       
  2633 
       
  2634 void CSysApAppUi::HandleAccessoryConnectedL( TAccMode aAccessoryState )
       
  2635     {
       
  2636     TRACES( RDebug::Print( _L("CSysApAppUi::HandleAccessoryConnectedL( aAccessoryState: %d ) "), aAccessoryState ) );
       
  2637 
       
  2638     if ( aAccessoryState == EAccModeWirelessHeadset ||
       
  2639          aAccessoryState == EAccModeWiredHeadset ||
       
  2640          aAccessoryState == EAccModeHeadphones )
       
  2641         {
       
  2642         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
  2643         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
  2644         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOn );
       
  2645         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  2646         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
  2647         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
  2648         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
  2649         }
       
  2650     else if ( aAccessoryState == EAccModeLoopset )
       
  2651         {
       
  2652         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
  2653         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
  2654         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOn );
       
  2655         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  2656         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
  2657         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
  2658         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
  2659         }
       
  2660     else if ( aAccessoryState == EAccModeTextDevice )
       
  2661         {
       
  2662         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
  2663         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
  2664         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOn );
       
  2665         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  2666         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
  2667         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
  2668         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
  2669         }
       
  2670     else if ( aAccessoryState == EAccModeWirelessCarKit || aAccessoryState == EAccModeWiredCarKit )
       
  2671         {
       
  2672         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
  2673         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
  2674         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
  2675         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  2676         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOn );
       
  2677         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
  2678         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
  2679         }
       
  2680     else if ( aAccessoryState == EAccModeTVOut )
       
  2681         {
       
  2682         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
  2683         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
  2684         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
  2685         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  2686         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
  2687         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOn );
       
  2688         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
  2689         }
       
  2690     else if (aAccessoryState == EAccModeHDMI )
       
  2691             {
       
  2692             SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
  2693                     SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
  2694                     SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
  2695                     SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  2696                     SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
  2697                     SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff);
       
  2698                     SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOn );
       
  2699             }
       
  2700 
       
  2701     TInt swState( StateOfProperty( KPSUidStartup, KPSGlobalSystemState ) );
       
  2702     TRACES( RDebug::Print( _L("CSysApAppUi::HandleAccessoryConnectedL: swState: %d"), swState ) );
       
  2703 
       
  2704     if( UiReady() || swState == ESwStateSecurityCheck )
       
  2705         {
       
  2706         iSysApLightsController->AccessoryConnectedL( ETrue );
       
  2707         }
       
  2708 
       
  2709     if ( ( ! iIgnoreAccessorySpecificProfileChanges ) && ( ! iSysApOfflineModeController->OfflineModeActive() ) )
       
  2710         {
       
  2711         TInt profileId( 0 );
       
  2712         TInt currentProfile( 0 );
       
  2713         currentProfile = ActiveProfileId();
       
  2714 
       
  2715         if ( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApAccessoryConnected ) < 1 )
       
  2716             // accessory not connected already
       
  2717              {
       
  2718             iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApAccessoryConnected, 1 );
       
  2719             iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApActiveProfileBeforeAccessoryConnected, currentProfile );
       
  2720             }
       
  2721 
       
  2722         if ( aAccessoryState == EAccModeWirelessCarKit )
       
  2723             {
       
  2724             profileId = iSysApCenRepController->ProfileIdForSelectedAccessory( ESysApWirelessCarkit );
       
  2725             }
       
  2726         else if( aAccessoryState == EAccModeWiredHeadset ||
       
  2727                  aAccessoryState == EAccModeWirelessHeadset )
       
  2728             {
       
  2729             profileId = iSysApCenRepController->ProfileIdForSelectedAccessory( ESysApHeadset );
       
  2730             }
       
  2731         else if( aAccessoryState == EAccModeLoopset  )
       
  2732             {
       
  2733             profileId = iSysApCenRepController->ProfileIdForSelectedAccessory( ESysApLoopset );
       
  2734             }
       
  2735         else if( aAccessoryState == EAccModeTextDevice )
       
  2736             {
       
  2737             profileId = iSysApCenRepController->ProfileIdForSelectedAccessory( ESysApTty );
       
  2738             }
       
  2739         else if( aAccessoryState == EAccModeTVOut || aAccessoryState == EAccModeHDMI )
       
  2740             {
       
  2741             profileId = iSysApCenRepController->ProfileIdForSelectedAccessory( ESysApTvOut );
       
  2742             }
       
  2743         else if( aAccessoryState == EAccModeHeadphones )
       
  2744             {
       
  2745             profileId = iSysApCenRepController->ProfileIdForSelectedAccessory( ESysApHeadphones );
       
  2746             }
       
  2747         else if ( aAccessoryState == EAccModeWiredCarKit )
       
  2748             {
       
  2749             profileId = iSysApCenRepController->ProfileIdForSelectedAccessory( ESysApCarkit );
       
  2750             }
       
  2751         else if ( aAccessoryState == EAccModeMusicStand )
       
  2752             {
       
  2753             profileId = iSysApCenRepController->ProfileIdForSelectedAccessory( ESysApMusicStand );
       
  2754             }
       
  2755 
       
  2756         // Carkit and music stand have also light on permanently option that needs to be checked
       
  2757         if( aAccessoryState == EAccModeWiredCarKit || aAccessoryState == EAccModeMusicStand )
       
  2758             {
       
  2759             // When device is placed on a handsfree cradle, keyguard must be disabled (unless device is locked)
       
  2760             // Note: It is assumed that if carkit/music stand is connected, the phone is in the cradle.
       
  2761             if ( iKeyLockEnabled || iDeviceLockEnabled || iKeyLockOnBeforeCall || iKeyLockOnBeforeAlarm )
       
  2762                 {
       
  2763                 iKeyLockOnBeforeCradle = ETrue;
       
  2764 
       
  2765                 if ( iKeyLockEnabled && !iDeviceLockEnabled )
       
  2766                     {
       
  2767                     KeyLock().DisableWithoutNote();
       
  2768                     }
       
  2769                 }
       
  2770             }
       
  2771 
       
  2772         if( profileId != KActiveProfile )
       
  2773             {
       
  2774             /*-1 because the first item in Accessory default profiles shared data values
       
  2775             is KActiveProfile and that must be subtracted from the index of profile to be activated*/
       
  2776 
       
  2777             profileId -= 1;
       
  2778 
       
  2779             TRACES( RDebug::Print( _L("CSysApAppUi::HandleAccessoryConnectedL: current profile: %d, accessory profile: %d" ),
       
  2780                                currentProfile, profileId ) );
       
  2781 
       
  2782             if ( profileId != currentProfile )
       
  2783                 {
       
  2784                 iAccessoryJustConnected = ETrue;
       
  2785                 iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApProfileUpdateRequired, 1 );
       
  2786                 ActivateProfileL( profileId );
       
  2787                 }
       
  2788             }
       
  2789         }
       
  2790     SetIhfIndicatorL();
       
  2791     SetHacIndicatorL();
       
  2792     }
       
  2793 
       
  2794 // ----------------------------------------------------------------------------
       
  2795 // CSysApAppUi::HandleAccessoryDisconnectedL()
       
  2796 // ----------------------------------------------------------------------------
       
  2797 
       
  2798 void CSysApAppUi::HandleAccessoryDisconnectedL()
       
  2799     {
       
  2800     TRACES( RDebug::Print( _L("CSysApAppUi::HandleAccessoryDisconnectedL()" ) ) );
       
  2801 
       
  2802 
       
  2803     TAccMode accessoryState(EAccModeHandPortable);
       
  2804     if ( iSysApAccessoryObserver )
       
  2805         {
       
  2806         accessoryState = iSysApAccessoryObserver->GetAccessoryMode();
       
  2807         }
       
  2808 
       
  2809     if ( accessoryState == EAccModeHandPortable )
       
  2810         {
       
  2811         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
  2812         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
  2813         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
  2814         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
  2815         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  2816         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
  2817         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
  2818 
       
  2819         iSysApLightsController->AccessoryConnectedL( EFalse );
       
  2820 
       
  2821         if ( ! iIgnoreAccessorySpecificProfileChanges )
       
  2822             {
       
  2823             TInt activeProfile ( ActiveProfileId() );
       
  2824 
       
  2825             TInt activeProfileBeforeConnectingAccessory(
       
  2826                  iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApActiveProfileBeforeAccessoryConnected )
       
  2827                                                         );
       
  2828             if ( activeProfileBeforeConnectingAccessory < 0 ) // error
       
  2829                 {
       
  2830                 activeProfileBeforeConnectingAccessory = 0; // General Profile
       
  2831                 }
       
  2832             TRACES( RDebug::Print( _L("CSysApAppUi::HandleAccessoryDisconnectedL: active profile now: %d, active profile before: %d," ),
       
  2833                                    activeProfile, activeProfileBeforeConnectingAccessory ) );
       
  2834 
       
  2835             if ( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApProfileUpdateRequired ) == 1 )
       
  2836                 {
       
  2837                 iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApProfileUpdateRequired, 0 );
       
  2838                 if ( activeProfile != activeProfileBeforeConnectingAccessory && ! iSysApOfflineModeController->OfflineModeActive() )
       
  2839                     {
       
  2840                     ActivateProfileL( activeProfileBeforeConnectingAccessory );
       
  2841                     }
       
  2842                 }
       
  2843             iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApAccessoryConnected, 0 );
       
  2844             }
       
  2845         }
       
  2846 
       
  2847     SetIhfIndicatorL();
       
  2848     SetHacIndicatorL();
       
  2849 
       
  2850     // If lock disabled because of accessory, reactivate it, unless phone call or alarm is ongoing
       
  2851     if ( iKeyLockOnBeforeCradle )
       
  2852         {
       
  2853         iKeyLockOnBeforeCradle = EFalse;
       
  2854         if ( !iKeyLockOnBeforeCall && !iKeyLockOnBeforeAlarm )
       
  2855             {
       
  2856             if ( !iDeviceLockEnabled )
       
  2857                 {
       
  2858                 KeyLock().EnableKeyLock();
       
  2859                 }
       
  2860             else
       
  2861                 {
       
  2862                 KeyLock().EnableAutoLockEmulation();
       
  2863                 }
       
  2864             }
       
  2865         }
       
  2866     }
       
  2867 
       
  2868 // ----------------------------------------------------------------------------
       
  2869 // CSysApAppUi::HandleAccessoryProfileInStartupL()
       
  2870 // ----------------------------------------------------------------------------
       
  2871 
       
  2872 void CSysApAppUi::HandleAccessoryProfileInStartupL()
       
  2873     {
       
  2874     TRACES( RDebug::Print( _L( "CSysApAppUi::HandleAccessoryProfileInStartupL" ) ) );
       
  2875 
       
  2876     if ( !iSysApOfflineModeController->OfflineModeActive() )
       
  2877         {
       
  2878         iIgnoreAccessorySpecificProfileChanges = EFalse;
       
  2879         TBool accessoryConnectedInShutdown( EFalse );
       
  2880         TInt accessoryTemp( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApAccessoryConnected ) );
       
  2881         if ( accessoryTemp == 1 )
       
  2882             {
       
  2883             accessoryConnectedInShutdown = ETrue;
       
  2884             }
       
  2885 
       
  2886         TBool accessoryConnectedNow ( EFalse );
       
  2887 
       
  2888         TAccMode accessoryState(EAccModeHandPortable);
       
  2889         if ( iSysApAccessoryObserver )
       
  2890             {
       
  2891             accessoryState = iSysApAccessoryObserver->GetAccessoryMode();
       
  2892             }
       
  2893 
       
  2894         if ( accessoryState != EAccModeHandPortable )
       
  2895             {
       
  2896             accessoryConnectedNow = ETrue;
       
  2897             }
       
  2898         TRACES( RDebug::Print( _L( "CSysApAppUi::HandleAccessoryProfileInStartupL: accessoryConnectedInShutdown: %d, accessoryConnectedNow: %d" ),
       
  2899                               accessoryConnectedInShutdown, accessoryConnectedNow ) );
       
  2900 
       
  2901         if ( accessoryConnectedInShutdown && !accessoryConnectedNow )
       
  2902             {
       
  2903             HandleAccessoryDisconnectedL();
       
  2904             }
       
  2905         else if ( !accessoryConnectedInShutdown && accessoryConnectedNow )
       
  2906             {
       
  2907             HandleAccessoryConnectedL( accessoryState );
       
  2908             }
       
  2909         else if ( !accessoryConnectedNow )
       
  2910             {
       
  2911             TInt activeProfile ( ActiveProfileId() );
       
  2912             iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApActiveProfileBeforeAccessoryConnected, activeProfile );
       
  2913             }
       
  2914         }
       
  2915     }
       
  2916 
       
  2917 #ifndef RD_MULTIPLE_DRIVE
       
  2918 
       
  2919 // ----------------------------------------------------------------------------
       
  2920 // CSysApAppUi::ResolveUidFromThread()
       
  2921 // ----------------------------------------------------------------------------
       
  2922 TInt32 CSysApAppUi::ResolveUidFromThread( TUint aThreadId ) const
       
  2923     {
       
  2924     TInt resolvedUid = 0;
       
  2925 
       
  2926     RThread appThread;
       
  2927     TInt err = appThread.Open( aThreadId );
       
  2928 
       
  2929     if ( err == KErrNone )
       
  2930         {
       
  2931         resolvedUid = appThread.SecureId().iId;
       
  2932         }
       
  2933 
       
  2934     appThread.Close();
       
  2935 
       
  2936     TRACES( RDebug::Print( _L("CSysApAppUi::ResolveUidFromThread: err=%d, aThreadId=%d, resolvedUid=0x%x"),
       
  2937                            err, aThreadId, resolvedUid ) );
       
  2938 
       
  2939     return resolvedUid;
       
  2940     }
       
  2941 
       
  2942 // ----------------------------------------------------------------------------
       
  2943 // CSysApAppUi::CloseUIAppsInHotSwapL()
       
  2944 // ----------------------------------------------------------------------------
       
  2945 void CSysApAppUi::CloseUIAppsInHotSwapL()
       
  2946     {
       
  2947     TRACES( RDebug::Print( _L("CSysApAppUi::CloseUIAppsInHotSwapL") ) );
       
  2948 
       
  2949     CArrayFixFlat<TInt>* wgIds=new(ELeave) CArrayFixFlat<TInt>(4);
       
  2950     CleanupStack::PushL(wgIds);
       
  2951     User::LeaveIfError(iCoeEnv->WsSession().WindowGroupList(0, wgIds));
       
  2952     TInt lastEntry=wgIds->Count()-1;
       
  2953     TRACES( RDebug::Print( _L( "CSysApAppUi::CloseUIAppsInHotSwapL: Found %d UI applications running." ), lastEntry + 1 ) );
       
  2954     TInt numberOfApplicationsToShutDown( 0 );
       
  2955     iApplicationScanningRoundNumber++;
       
  2956 
       
  2957     for ( TInt i=lastEntry; i>=0; i--)
       
  2958         {
       
  2959         CApaWindowGroupName* doomedApp = CApaWindowGroupName::NewLC(iCoeEnv->WsSession(),wgIds->At(i));
       
  2960 
       
  2961         TBool systemApp = doomedApp->IsSystem();
       
  2962         TBool hiddenApp = doomedApp->Hidden();
       
  2963 
       
  2964         if ( systemApp || hiddenApp )
       
  2965             {
       
  2966             TRACES (
       
  2967                     TPtrC caption=doomedApp->Caption();
       
  2968                     RDebug::Print( _L("CSysApAppUi::CloseUIAppsInHotSwapL: Privileged app \"%S\" UID 0x%x will not be closed, system: %d, hidden: %d" ),
       
  2969                                    &caption,
       
  2970                                    doomedApp->AppUid().iUid,
       
  2971                                    systemApp,
       
  2972                                    hiddenApp);
       
  2973                     );
       
  2974             }
       
  2975         else if ( ( iFileManagerCloseDisabled && doomedApp->AppUid().iUid == KFileManagerAppUid ) ||
       
  2976                   doomedApp->AppUid().iUid == KAutolockAppUid )
       
  2977             {
       
  2978             // An additional failure protection: Autolock must not be closed in any circumstances
       
  2979             TRACES (
       
  2980                     TPtrC caption=doomedApp->Caption();
       
  2981                     RDebug::Print( _L("CSysApAppUi::CloseUIAppsInHotSwapL: Privileged app \"%S\" will not be closed, UID 0x%x"),
       
  2982                                    &caption,
       
  2983                                    doomedApp->AppUid().iUid );
       
  2984                     );
       
  2985             }
       
  2986         else if ( doomedApp->AppUid().iUid == 0 && !iTimeToKill )
       
  2987             {
       
  2988 #ifdef _DEBUG
       
  2989             TApaTask task(iCoeEnv->WsSession());
       
  2990             task.SetWgId(wgIds->At(i));
       
  2991             TUint threadId = (TUint)(task.ThreadId());
       
  2992             TInt32 uid = ResolveUidFromThread( threadId );
       
  2993             // CApaWindowGroupName stores the application UID, and in early application startup state AppUid()-method returns 0
       
  2994             // In order not to accidentally close application that hasn't yet its window group properly set up, decicision whether
       
  2995             // to close the application is postponed, in maximum to the end of the waiting period.
       
  2996             TRACES ( RDebug::Print( _L("CSysApAppUi::CloseUIAppsInHotSwapL: Unknown app will not be closed yet, threadId=%d, UID 0x%x, size=%d"),
       
  2997                                     threadId, uid, sizeof(TApaTask) ) );
       
  2998 #endif // _DEBUG
       
  2999             numberOfApplicationsToShutDown++; // wait note must be displayed
       
  3000             }
       
  3001         else
       
  3002             {
       
  3003             numberOfApplicationsToShutDown++;
       
  3004             TApaTask* task = new (ELeave) TApaTask(iCoeEnv->WsSession());
       
  3005             CleanupDeletePushL(task);
       
  3006             task->SetWgId(wgIds->At(i));
       
  3007 
       
  3008             TRACES (
       
  3009                     const TDesC& caption = doomedApp->Caption();
       
  3010                     const TDesC& docname = doomedApp->DocName();
       
  3011                     const TDesC& wgname = doomedApp->WindowGroupName();
       
  3012                     TUid uid = doomedApp->AppUid();
       
  3013                     RDebug::Print( _L("CSysApAppUi::CloseUIAppsInHotSwapL: Closing app \"%S\" (ThreadId %d, WgId %d, UID 0x%X); Docname: %S, WGName : %S"),
       
  3014                                    &caption,
       
  3015                                    (TUint)(task->ThreadId()),
       
  3016                                    wgIds->At(i),
       
  3017                                    uid.iUid,
       
  3018                                    &docname,
       
  3019                                    &wgname);
       
  3020                     );
       
  3021 
       
  3022             ResolveUidFromThread( (TUint)(task->ThreadId()) );
       
  3023 
       
  3024             if ( iApplicationScanningRoundNumber == 1 )
       
  3025                 {
       
  3026                 task->EndTask(); // applications are kindly requested to close themselves on the first round
       
  3027                 }
       
  3028             else if ( iTimeToKill )
       
  3029                 {
       
  3030                 TBool doKill = ETrue;
       
  3031 
       
  3032                 // final check, window group may still be uninitialized so use thread id for checking UID
       
  3033                 if ( doomedApp->AppUid().iUid == 0 )
       
  3034                     {
       
  3035                     if ( ResolveUidFromThread( (TUint)(task->ThreadId()) ) == KAutolockAppUid )
       
  3036                         {
       
  3037                         doKill = EFalse;
       
  3038                         }
       
  3039                     }
       
  3040 
       
  3041                 if ( doKill )
       
  3042                     {
       
  3043                     TRACES( RDebug::Print( _L("CSysApAppUi::CloseUIAppsInHotSwapL: Killing app \"%S\""), &caption ) );
       
  3044                     task->KillTask(); // used after timeout on the last round
       
  3045                     }
       
  3046                 }
       
  3047 
       
  3048             CleanupStack::PopAndDestroy(); // task
       
  3049             }
       
  3050         CleanupStack::PopAndDestroy();  // doomedApp
       
  3051         }
       
  3052     CleanupStack::PopAndDestroy(); // wgIds
       
  3053 
       
  3054     if ( numberOfApplicationsToShutDown > 0 && iApplicationScanningRoundNumber <= KMaxExitTimeInHotSwap )
       
  3055         {
       
  3056         TRACES( RDebug::Print( _L("CSysApAppUi::CloseUIAppsInHotSwapL: Show wait note, unless already showing") ) );
       
  3057         if ( !iSysApWaitNote )
       
  3058             {
       
  3059             HBufC* noteStringBuf = StringLoader::LoadLC( R_QTN_MEMC_WAIT_EJECT, iEikonEnv );
       
  3060             iSysApWaitNote = CSysApWaitNote::NewL( iSysApFeatureManager->CoverDisplaySupported() );
       
  3061             iSysApWaitNote->ShowNoteL( EClosingApplicationsNote, noteStringBuf );
       
  3062             CleanupStack::PopAndDestroy();
       
  3063             }
       
  3064 
       
  3065         if ( iApplicationScanningRoundNumber >= KMaxExitTimeInHotSwap )
       
  3066             {
       
  3067             iTimeToKill = ETrue;
       
  3068             }
       
  3069 
       
  3070         if ( !iSysApTimer )
       
  3071             {
       
  3072             iSysApTimer = new ( ELeave ) CSysApTimer( *this );
       
  3073             }
       
  3074 
       
  3075         iSysApTimer->ActivateTimerL( KApplicationScanningInterval );
       
  3076         }
       
  3077     else
       
  3078         {
       
  3079         iFileManagerCloseDisabled = EFalse;
       
  3080         CompleteAppsShuttingInHotSwapL();
       
  3081         }
       
  3082     }
       
  3083 
       
  3084 #endif // RD_MULTIPLE_DRIVE
       
  3085 
       
  3086 // ----------------------------------------------------------------------------
       
  3087 // CSysApAppUi::TimerExpiredL()
       
  3088 // ----------------------------------------------------------------------------
       
  3089 void CSysApAppUi::TimerExpiredL()
       
  3090     {
       
  3091 #ifndef RD_MULTIPLE_DRIVE
       
  3092     CloseUIAppsInHotSwapL();
       
  3093 #endif // RD_MULTIPLE_DRIVE
       
  3094     }
       
  3095 
       
  3096 #ifndef RD_MULTIPLE_DRIVE
       
  3097 // ----------------------------------------------------------------------------
       
  3098 // CSysApAppUi::CompleteAppsShuttingInHotSwapL()
       
  3099 // ----------------------------------------------------------------------------
       
  3100 void CSysApAppUi::CompleteAppsShuttingInHotSwapL()
       
  3101     {
       
  3102     TRACES( RDebug::Print( _L("CSysApAppUi::CompleteAppsShuttingInHotSwapL iMMCEjectUsed=%d, iMMCInserted=%d"), iMMCEjectUsed, iMMCInserted ) );
       
  3103     CancelWaitNote();
       
  3104 
       
  3105     if ( iMMCEjectUsed ) // From Powerkey Menu
       
  3106         {
       
  3107         DismountMMC();
       
  3108         TRACES( RDebug::Print( _L( "CSysApAppUi::CompleteAppsShuttingInHotSwapL: Show note: Remove MMC and press OK...." ) ) );
       
  3109         ShowQueryL( ESysApRemoveMmcNote );
       
  3110         }
       
  3111     else if ( !iMMCInserted ) // The MMC might have been already re-mounted, that's why !iMMCInserted
       
  3112         {
       
  3113         ShowMMCDismountedDialogL();
       
  3114         }
       
  3115     }
       
  3116 #endif // RD_MULTIPLE_DRIVE
       
  3117 
       
  3118 // ----------------------------------------------------------------------------
       
  3119 // CSysApAppUi::InitCloseSimApplicationsL()
       
  3120 // ----------------------------------------------------------------------------
       
  3121 void CSysApAppUi::InitCloseSimApplicationsL()
       
  3122     {
       
  3123     iApplicationScanningRoundNumberInBtSap = 0;
       
  3124     iTimeToKillInBtSap = EFalse;
       
  3125     CloseSimApplicationsL();
       
  3126     }
       
  3127 
       
  3128 // ----------------------------------------------------------------------------
       
  3129 // CSysApAppUi::CloseSimApplicationsL()
       
  3130 // ----------------------------------------------------------------------------
       
  3131 void CSysApAppUi::CloseSimApplicationsL()
       
  3132     {
       
  3133     iApplicationScanningRoundNumberInBtSap++;
       
  3134     TRACES( RDebug::Print( _L("CSysApAppUi::CloseSimApplicationsL: scanning round = %d"),
       
  3135                            iApplicationScanningRoundNumberInBtSap ) );
       
  3136 
       
  3137     if ( iApplicationScanningRoundNumberInBtSap == KMaxExitTimeInBtSap )
       
  3138         {
       
  3139         iTimeToKillInBtSap = ETrue;
       
  3140         }
       
  3141 
       
  3142     const TInt KNumberOfSimDependantApps( 7 );
       
  3143     TUid simDependantAppUid[ KNumberOfSimDependantApps ];
       
  3144     simDependantAppUid[ 0 ] = KSysApGSUid;
       
  3145     simDependantAppUid[ 1 ] = KSysApSATUid;
       
  3146     simDependantAppUid[ 2 ] = KSysApMailboxUid;
       
  3147     simDependantAppUid[ 3 ] = KSysApSpeedDialingUid;
       
  3148     simDependantAppUid[ 4 ] = KSysApSimDirectoryUid;
       
  3149     simDependantAppUid[ 5 ] = KSysApMCEUid;
       
  3150     simDependantAppUid[ 6 ] = KSysApCellBroadcastMessagesUid;
       
  3151 
       
  3152     TBool appsExiting( EFalse );
       
  3153     TApaTaskList apaTaskList( CCoeEnv::Static()->WsSession() );
       
  3154 
       
  3155     for ( TInt i = 0; i < KNumberOfSimDependantApps; i++ )
       
  3156         {
       
  3157         TApaTask apaTask = apaTaskList.FindApp( simDependantAppUid[ i ] );
       
  3158         if ( apaTask.Exists() )
       
  3159             {
       
  3160             appsExiting = ETrue;
       
  3161             if ( iApplicationScanningRoundNumberInBtSap == 1 )
       
  3162                 {
       
  3163                 apaTask.EndTask();  // applications are kindly requested to close themselves on the first round
       
  3164                 }
       
  3165             else if ( iTimeToKillInBtSap )
       
  3166                 {
       
  3167                 apaTask.KillTask(); // used after timeout on the last round
       
  3168                 }
       
  3169             }
       
  3170         }
       
  3171 
       
  3172     if ( !appsExiting || iTimeToKillInBtSap )
       
  3173         {
       
  3174         iSysApBtSapController->SimApplicationsClosed();
       
  3175         }
       
  3176     else
       
  3177         {
       
  3178         if ( !iSapTimer )
       
  3179             {
       
  3180             iSapTimer = CPeriodic::NewL( EPriorityNormal );
       
  3181             }
       
  3182         iSapTimer->Cancel();
       
  3183         iSapTimer->Start( KDelayBeforeNextScanningRound,
       
  3184                           KDelayBeforeNextScanningRound,
       
  3185                           TCallBack( DoCloseSimApplicationsAfterCallBack, this ) );
       
  3186         }
       
  3187     }
       
  3188 
       
  3189 // ----------------------------------------------------------------------------
       
  3190 // CSysApAppUi::DoCloseSimApplicationsAfterCallBack
       
  3191 // ----------------------------------------------------------------------------
       
  3192 TInt CSysApAppUi::DoCloseSimApplicationsAfterCallBack( TAny* aObject )
       
  3193     {
       
  3194     CSysApAppUi* appUi = STATIC_CAST( CSysApAppUi*, aObject );
       
  3195 
       
  3196     if ( appUi->iSapTimer )
       
  3197         {
       
  3198         appUi->iSapTimer->Cancel();
       
  3199         }
       
  3200 
       
  3201     TRAP_IGNORE( appUi->CloseSimApplicationsL() );
       
  3202 
       
  3203     return KErrNone;
       
  3204     }
       
  3205 
       
  3206 // ----------------------------------------------------------------------------
       
  3207 // CSysApAppUi::AlertUiAlertingL( const TBool aAlerting )
       
  3208 // ----------------------------------------------------------------------------
       
  3209 void CSysApAppUi::AlertUiAlertingL( const TBool aAlerting )
       
  3210     {
       
  3211     TRACES( RDebug::Print( _L("CSysApAppUi::AlertUiAlerting aAlerting:%d"), aAlerting ) );
       
  3212 
       
  3213     if ( aAlerting )
       
  3214         {
       
  3215         TInt swState;
       
  3216         RProperty::Get( KPSUidStartup, KPSGlobalSystemState, swState );
       
  3217 
       
  3218         if( swState == ESwStateCharging )
       
  3219             {
       
  3220             SetStarterState( RStarterSession::EAlarm );
       
  3221             }
       
  3222         }
       
  3223 
       
  3224     iSysApLightsController->AlarmOccuredL( aAlerting );
       
  3225     }
       
  3226 
       
  3227 // ----------------------------------------------------------------------------
       
  3228 // CSysApAppUi::AlertUiKeyLockOff( const TBool aKeyLockOff )
       
  3229 // ----------------------------------------------------------------------------
       
  3230 
       
  3231 void CSysApAppUi::AlertUiKeyLockOff( const TBool aKeyLockOff )
       
  3232     {
       
  3233     TRACES( RDebug::Print( _L("CSysApAppUi::AlertUiKeyLockOff aKeyLockOff:%d, devicelock:%d"), 
       
  3234         aKeyLockOff, iDeviceLockEnabled ) );
       
  3235     
       
  3236     if( aKeyLockOff )
       
  3237         {
       
  3238         // Notification to release keypad might come several times if e.g. calls are received
       
  3239         if ( !iKeyLockOnBeforeAlarm )
       
  3240             {
       
  3241             if ( iKeyLockEnabled || iKeyLockOnBeforeCradle || iKeyLockOnBeforeCall )
       
  3242                 {
       
  3243                 iKeyLockOnBeforeAlarm = ETrue;
       
  3244                 }
       
  3245             }
       
  3246         KeyLock().DisableWithoutNote();
       
  3247         }
       
  3248     else
       
  3249         {
       
  3250         if (iDeviceLockEnabled)
       
  3251             {
       
  3252             // Re-enable keylock in devicelock case only if phone call is not ongoing or is 
       
  3253             // connected. Otherwise e.g. messages can be read using softkeys during ongoing call.
       
  3254             TInt callState( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
       
  3255             if ( callState == EPSCTsyCallStateNone || callState == EPSCTsyCallStateConnected )
       
  3256                 {
       
  3257                 KeyLock().EnableAutoLockEmulation();
       
  3258                 }
       
  3259             }
       
  3260         else if ( iKeyLockOnBeforeAlarm && !iKeyLockOnBeforeCradle && !iKeyLockOnBeforeCall )
       
  3261             {
       
  3262             KeyLock().EnableKeyLock();
       
  3263             }
       
  3264         iKeyLockOnBeforeAlarm = EFalse;
       
  3265         }
       
  3266     }
       
  3267 
       
  3268 // ----------------------------------------------------------------------------
       
  3269 // CSysApAppUi::HandleLightsRequireL()
       
  3270 // ----------------------------------------------------------------------------
       
  3271 
       
  3272 void CSysApAppUi::HandleLightsRequireL() const
       
  3273     {
       
  3274     iSysApLightsController->HandleLightsRequireL();
       
  3275     }
       
  3276 
       
  3277 // ----------------------------------------------------------------------------
       
  3278 // CSysApAppUi::HandleRawKeyEventLightsRequireL()
       
  3279 // ----------------------------------------------------------------------------
       
  3280 
       
  3281 void CSysApAppUi::HandleRawKeyEventLightsRequireL() const
       
  3282     {
       
  3283     iSysApLightsController->HandleRawKeyEventLightsRequireL();
       
  3284     }
       
  3285 
       
  3286 // ----------------------------------------------------------------------------
       
  3287 // CSysApAppUi::HandleForcedLightsVTRequireL( const TInt aLightParameter )
       
  3288 // ----------------------------------------------------------------------------
       
  3289 
       
  3290 void CSysApAppUi::HandleForcedLightsVTRequireL( const TInt aLightsParameter ) const
       
  3291     {
       
  3292     iSysApLightsController->HandleForcedLightsVTRequireL( aLightsParameter );
       
  3293     }
       
  3294 
       
  3295 // ----------------------------------------------------------------------------
       
  3296 // CSysApAppUi::HandleForcedLightsSSRequireL( const TInt aLightParameter )
       
  3297 // ----------------------------------------------------------------------------
       
  3298 
       
  3299 void CSysApAppUi::HandleForcedLightsSSRequireL( const TInt aLightsParameter ) const
       
  3300     {
       
  3301     iSysApLightsController->HandleForcedLightsSSRequireL( aLightsParameter );
       
  3302     }
       
  3303 
       
  3304 // ---------------------------------------------------------------------------- 
       
  3305 // CSysApAppUi::HandleForcedLightsATCRequireL( const TInt aLightParameter ) 
       
  3306 // ---------------------------------------------------------------------------- 
       
  3307 void CSysApAppUi::HandleForcedLightsATCRequireL( const TInt aLightsParameter ) const 
       
  3308     { 
       
  3309     iSysApLightsController->HandleForcedLightsATCRequireL( aLightsParameter ); 
       
  3310     } 
       
  3311       
       
  3312 // ----------------------------------------------------------------------------
       
  3313 // CSysApAppUi::SwitchLightsOnSoftRejectL()
       
  3314 // ----------------------------------------------------------------------------
       
  3315 void CSysApAppUi::SwitchLightsOnSoftRejectL()
       
  3316     {
       
  3317     iSysApLightsController->SwitchLightsOnSoftRejectL();
       
  3318     }
       
  3319 
       
  3320 // ----------------------------------------------------------------------------
       
  3321 // CSysApAppUi::StateOfProperty()
       
  3322 // ----------------------------------------------------------------------------
       
  3323 TInt CSysApAppUi::StateOfProperty( const TUid& aCategory, const TUint aKey ) const
       
  3324     {
       
  3325     TInt err( KErrNone );
       
  3326     TInt value( 0 );
       
  3327     err = RProperty::Get( aCategory, aKey, value );
       
  3328     if ( err )
       
  3329         {
       
  3330         TRACES( RDebug::Print( _L("CSysApAppUi::StateOfProperty. RProperty::Get: err=%d"), err ) );
       
  3331         return err;
       
  3332         }
       
  3333     return value;
       
  3334     }
       
  3335 
       
  3336 // ----------------------------------------------------------------------------
       
  3337 // CSysApAppUi::BluetoothPowerMode()
       
  3338 // ----------------------------------------------------------------------------
       
  3339 TInt CSysApAppUi::BluetoothPowerMode() const
       
  3340     {
       
  3341     return iSysApCenRepBtObserver->BluetoothPowerMode();
       
  3342     }
       
  3343 
       
  3344 // ----------------------------------------------------------------------------
       
  3345 // CSysApAppUi::ActivateProfileL( const TInt aProfileId ) const
       
  3346 // ----------------------------------------------------------------------------
       
  3347 
       
  3348 void CSysApAppUi::ActivateProfileL( const TInt aProfileId ) const
       
  3349     {
       
  3350     TRACES( RDebug::Print( _L("CSysApAppUi::ActivateProfile aProfileId: %d"), aProfileId ) );
       
  3351     //No use of returning the Profile error code since it only tells if the activation was succesfull or not.
       
  3352     iProfileEngine->SetActiveProfileL( aProfileId );
       
  3353     }
       
  3354 
       
  3355 // ----------------------------------------------------------------------------
       
  3356 // CSysApAppUi::ActivateOnlineProfileL() const
       
  3357 // ----------------------------------------------------------------------------
       
  3358 
       
  3359 void CSysApAppUi::ActivateOnlineProfileL() const
       
  3360     {
       
  3361     ActivateProfileL( iProfileToBeActivated );
       
  3362     }
       
  3363 
       
  3364 // ----------------------------------------------------------------------------
       
  3365 // CSysApAppUi::ActiveProfileNameL( TPtr aProfileName ) const
       
  3366 // ----------------------------------------------------------------------------
       
  3367 
       
  3368 void CSysApAppUi::ActiveProfileNameL( TPtr aProfileName )
       
  3369     {
       
  3370     TRACES( RDebug::Print( _L("CSysApAppUi::ActiveProfileNameL START") ) );
       
  3371     MProfile* profile = iProfileEngine->ActiveProfileL();
       
  3372     const MProfileName& mProfileName = profile->ProfileName();
       
  3373     aProfileName = mProfileName.Name();
       
  3374     profile->Release();
       
  3375     TRACES( RDebug::Print( _L("CSysApAppUi::ActiveProfileNameL END") ) );
       
  3376     }
       
  3377 
       
  3378 // ----------------------------------------------------------------------------
       
  3379 // CSysApAppUi::CheckSilentModeL()
       
  3380 // ----------------------------------------------------------------------------
       
  3381 void CSysApAppUi::CheckSilentModeL()
       
  3382     {
       
  3383     TBool isSilent( EFalse );
       
  3384     MProfile* profile = iProfileEngine->ActiveProfileL();
       
  3385     isSilent = profile->IsSilent();
       
  3386     profile->Release();
       
  3387     if ( isSilent )
       
  3388         {
       
  3389         TRACES( RDebug::Print( _L("CSysApAppUi::CheckSilentModeL: active profile is SILENT") ) );
       
  3390         iSysApLightsController->SetSilentModeOn( ETrue );
       
  3391         }
       
  3392     else
       
  3393         {
       
  3394         TRACES( RDebug::Print( _L("CSysApAppUi::CheckSilentModeL: active profile is NOT SILENT") ) );
       
  3395         iSysApLightsController->SetSilentModeOn( EFalse );
       
  3396         }
       
  3397     }
       
  3398 
       
  3399 // ----------------------------------------------------------------------------
       
  3400 // CSysApAppUi::HandleProfileChangedL( const TInt aValue )
       
  3401 // ----------------------------------------------------------------------------
       
  3402 void CSysApAppUi::HandleProfileChangedL( const TInt aNewProfileId )
       
  3403     {
       
  3404     TRACES( RDebug::Print( _L("CSysApAppUi::HandleProfileChangedL: aNewProfileId=%d"), aNewProfileId ) );
       
  3405     CheckSilentModeL();
       
  3406     if ( iHandleNextProfileEvent )
       
  3407         {
       
  3408         if ( iAccessoryJustConnected )
       
  3409             {
       
  3410             iAccessoryJustConnected = EFalse;
       
  3411             }
       
  3412         else
       
  3413             {
       
  3414             // if the user delibarately changes profiles, the selected profile will
       
  3415             // remain active after disconnecting an accessory.
       
  3416             iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApProfileUpdateRequired, 0 );
       
  3417             }
       
  3418 
       
  3419 		// Added as a part of REQ 415-6750 : Conditional UI-note for "Activated profile"
       
  3420         TInt   noNeedToShowTheNote = 0;      // if True, then note should not be shown
       
  3421         TInt    err = KErrNone;                            
       
  3422                                      
       
  3423       	err = RProperty::Get( KPSUidCoreApplicationUIs, KCoreAppUIsProfileActivatedNote, 
       
  3424                               noNeedToShowTheNote );   
       
  3425 		/*
       
  3426   		If there occured an error, it is likely caused by the non-existing property. 
       
  3427   		So trying to set it only if no error occured for maintaining the default behavior. 
       
  3428 		*/       
       
  3429         if( KErrNone == err )
       
  3430             { 
       
  3431             TInt error = RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsProfileActivatedNote, 
       
  3432                                      ECoreAppUIsProfileActivatedNoteNotShown );
       
  3433             }
       
  3434                
       
  3435         if(!noNeedToShowTheNote)  //    The value doesn't deny the showing, then...
       
  3436             {
       
  3437             ShowProfileNoteL();
       
  3438             }    
       
  3439         }
       
  3440 
       
  3441     if ( aNewProfileId != KOfflineModeProfileId )
       
  3442         {
       
  3443         iActiveProfileBeforeOfflineMode = aNewProfileId;
       
  3444         iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApProfileBeforeOfflineMode, aNewProfileId );
       
  3445         }
       
  3446 
       
  3447     if ( aNewProfileId == KOfflineModeProfileId && ! iSysApOfflineModeController->OfflineModeActive() )
       
  3448         {
       
  3449         if ( BtSapEnabled() )
       
  3450             {
       
  3451             // Choosing "Offline Mode" will disconnect BT SAP
       
  3452             // SwitchFromOnlineToOfflineModeL() will be called from CSysApBtSapController
       
  3453             iSysApBtSapController->SwitchingToOffline();
       
  3454             iSysApBtSapController->Disconnect();
       
  3455             }
       
  3456         else
       
  3457             {
       
  3458             SwitchFromOnlineToOfflineModeL();
       
  3459             }
       
  3460         }
       
  3461     else if ( aNewProfileId != KOfflineModeProfileId && iSysApOfflineModeController->OfflineModeActive() )
       
  3462         {
       
  3463         if ( BtSapEnabled() )
       
  3464             {
       
  3465             iSysApOfflineModeController->DoNotActivateRF(); // Will be activated after BT SAP disconnection
       
  3466             }
       
  3467         iSysApOfflineModeController->SwitchFromOfflineToOnlineModeL();
       
  3468         }
       
  3469     iHandleNextProfileEvent = ETrue;
       
  3470     }
       
  3471 
       
  3472 
       
  3473 // ----------------------------------------------------------------------------
       
  3474 // CSysApAppUi::RestoreProfileL()
       
  3475 // ----------------------------------------------------------------------------
       
  3476 
       
  3477 void CSysApAppUi::RestoreProfileL( const TBool aOffline )
       
  3478     {
       
  3479     iHandleNextProfileEvent = EFalse;
       
  3480     if ( aOffline )
       
  3481         {
       
  3482         ActivateProfileL( KOfflineModeProfileId );
       
  3483         }
       
  3484     else
       
  3485         {
       
  3486         ActivateProfileL( iActiveProfileBeforeOfflineMode );
       
  3487         }
       
  3488     }
       
  3489 
       
  3490 // ----------------------------------------------------------------------------
       
  3491 // CSysApAppUi::ActiveProfileId()
       
  3492 // ----------------------------------------------------------------------------
       
  3493 
       
  3494 TInt CSysApAppUi::ActiveProfileId()
       
  3495     {
       
  3496     return iProfileEngine->ActiveProfileId();
       
  3497     }
       
  3498 
       
  3499 // ----------------------------------------------------------------------------
       
  3500 // CSysApAppUi::ShowPowerKeyPopUpMenuL()
       
  3501 // ----------------------------------------------------------------------------
       
  3502 
       
  3503 void CSysApAppUi::ShowPowerKeyPopUpMenuL()
       
  3504     {
       
  3505     TRACES( RDebug::Print(_L("CSysApAppUi::ShowPowerKeyPopUpMenuL iPowerKeyPopupMenuActive: %d" ),
       
  3506                           iPowerKeyPopupMenuActive ) );
       
  3507 
       
  3508     if ( !iPowerKeyPopupMenuActive && !iDisablePowerkeyMenu 
       
  3509          && iSysApPowerKeyMenuObserver ) // normal state construction has been executed
       
  3510         {
       
  3511         iPowerKeyPopupMenuDismissed = EFalse;
       
  3512         iPowerkeyMenuPowerOffShown = EFalse;
       
  3513         CancelGlobalListQuery();
       
  3514 
       
  3515         iGlobalListQuery = CAknGlobalListQuery::NewL();
       
  3516 
       
  3517         iSysApPowerKeyMenuObserver->Cancel();
       
  3518 
       
  3519         CDesCArray* profileNameCDesCArray; // Array for Powerkey Menu items
       
  3520 
       
  3521         RArray<TInt> itemIdArray; // needed for cover UI
       
  3522         CleanupClosePushL(itemIdArray);
       
  3523 
       
  3524         // make sure old profile names array is clean
       
  3525         delete iProfileNamesArray;
       
  3526         iProfileNamesArray = NULL;
       
  3527 
       
  3528         // Must pop iProfileNamesArray here as cannot leave trap harness with uneven push/pop count.
       
  3529         // This is because profileEngine doesn't provide non-LC version of ProfilesNamesArrayLC
       
  3530         TRAPD( err,
       
  3531               iProfileNamesArray = iProfileEngine->ProfilesNamesArrayLC();
       
  3532               CleanupStack::Pop();
       
  3533              );
       
  3534 
       
  3535         if ( err != KErrNone )
       
  3536             {
       
  3537             // creating menu failed, return (i.e. just don't show the menu)
       
  3538             TRACES( RDebug::Print(_L("CSysApAppUi::ShowPowerKeyPopUpMenuL iProfileEngine->ProfilesNamesArrayLC() ERROR: %d" ), err ) );
       
  3539             iNumberOfProfileNamesInPowerKeyMenu = 0;
       
  3540             }
       
  3541         else
       
  3542             {
       
  3543             iNumberOfProfileNamesInPowerKeyMenu = iProfileNamesArray->MdcaCount();
       
  3544             TRACES( RDebug::Print(_L("CSysApAppUi::ShowPowerKeyPopUpMenuL iNumberOfProfileNamesInPowerKeyMenu: %d" ),
       
  3545                                   iNumberOfProfileNamesInPowerKeyMenu ) );
       
  3546             }
       
  3547 
       
  3548         if ( BtSapEnabled() )
       
  3549             {
       
  3550             profileNameCDesCArray = new( ELeave ) CDesCArrayFlat( iNumberOfProfileNamesInPowerKeyMenu + 4 );
       
  3551             }
       
  3552         else
       
  3553             {
       
  3554             profileNameCDesCArray = new( ELeave ) CDesCArrayFlat( iNumberOfProfileNamesInPowerKeyMenu + 3 );
       
  3555             }
       
  3556 
       
  3557         CleanupStack::PushL( profileNameCDesCArray );
       
  3558         profileNameCDesCArray->Reset();
       
  3559         HBufC* itemStringBuf;
       
  3560 
       
  3561         TInt powerMenuItemIndex( 0 );
       
  3562 
       
  3563         // "Switch off" menu item
       
  3564         if ( !IsEncryptionOperationOngoingL() )
       
  3565             {
       
  3566         itemStringBuf = StringLoader::LoadLC( R_QTN_PWRC_SWITCH_OFF, iEikonEnv );
       
  3567         profileNameCDesCArray->InsertL( 0, itemStringBuf->Des() );
       
  3568         CleanupStack::PopAndDestroy(); // itemStringBuf
       
  3569         if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  3570             {
       
  3571             itemIdArray.AppendL(SecondaryDisplay::EPwrMenuItemSwitchOff);
       
  3572             }
       
  3573             iPowerkeyMenuPowerOffShown = ETrue;
       
  3574         powerMenuItemIndex++;
       
  3575             }
       
  3576 
       
  3577         iPowerkeyMenuLockKeypadShown     = EFalse;
       
  3578         iPowerkeyMenuExitSapShown        = EFalse;
       
  3579         iPowerkeyMenuLockSystemShown     = EFalse;
       
  3580         iPowerkeyMenuEjectShown          = EFalse;
       
  3581 
       
  3582         iPowerkeyMenuLockKeypadSelection = KErrAccessDenied;
       
  3583         iPowerkeyMenuExitSapSelection    = KErrAccessDenied;
       
  3584         iPowerkeyMenuLockSystemSelection = KErrAccessDenied;
       
  3585 
       
  3586 #ifndef RD_MULTIPLE_DRIVE
       
  3587         iPowerkeyMenuEjectSelection     = KErrAccessDenied;
       
  3588 #else // RD_MULTIPLE_DRIVE
       
  3589         iPowerkeyMenuEjectSelectionBase = KErrAccessDenied;
       
  3590 #endif // RD_MULTIPLE_DRIVE
       
  3591 
       
  3592         // "Lock keypad" menu item
       
  3593 		
       
  3594 		TInt callState ( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
       
  3595 		TInt callType ( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallType ) );
       
  3596 		if ( !( callState == EPSCTsyCallStateConnected && callType == EPSCTsyCallTypeH324Multimedia ) )
       
  3597 			{
       
  3598 			if ( iSysApFeatureManager->GripNotSupported() ||
       
  3599 				( (!iSysApFeatureManager->GripNotSupported() ) && ( StateOfProperty( KPSUidHWRM, KHWRMGripStatus ) ==  EPSHWRMGripClosed ) ) )
       
  3600 				// "Lock keypad" command is shown always when there is no grip, and if there
       
  3601 				// there is no grip, only when the grip is closed.
       
  3602 				{
       
  3603 				if ( CKeyLockPolicyApi::KeyguardAllowed() )
       
  3604 					{
       
  3605 					if ( iSysApFeatureManager->PenEnabled() )
       
  3606 						{
       
  3607 						itemStringBuf = StringLoader::LoadLC( R_QTN_PWRC_LOCK_DISPLAY, iEikonEnv );
       
  3608 						}
       
  3609 					else
       
  3610 						{
       
  3611 						itemStringBuf = StringLoader::LoadLC( R_QTN_PWRC_LOCK_KEYS, iEikonEnv );
       
  3612 						}                
       
  3613 					profileNameCDesCArray->AppendL( itemStringBuf->Des() );
       
  3614 					CleanupStack::PopAndDestroy(); // itemStringBuf
       
  3615 					if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  3616 						{
       
  3617 						itemIdArray.AppendL(SecondaryDisplay::EPwrMenuItemLockKeypad);
       
  3618 						}
       
  3619 					iPowerkeyMenuLockKeypadShown = ETrue;
       
  3620 					iPowerkeyMenuLockKeypadSelection = powerMenuItemIndex;
       
  3621 					powerMenuItemIndex++;
       
  3622 					}
       
  3623 				}
       
  3624 			}
       
  3625 
       
  3626         // "Exit SIM access profile" menu item
       
  3627 
       
  3628         if ( BtSapEnabled() )
       
  3629             {
       
  3630             TRACES( RDebug::Print(_L( "CSysApAppUi::ShowPowerKeyPopUpMenuL: show \"Exit SIM access profile\" item" ) ) );
       
  3631             itemStringBuf = StringLoader::LoadLC( R_QTN_PWRC_EXIT_SIM_ACCESS, iEikonEnv );
       
  3632             profileNameCDesCArray->AppendL( itemStringBuf->Des() );
       
  3633             CleanupStack::PopAndDestroy(); // itemStringBuf
       
  3634             if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  3635                 {
       
  3636                 itemIdArray.AppendL(SecondaryDisplay::EPwrMenuItemExitBtSap);
       
  3637                 }
       
  3638             iPowerkeyMenuExitSapShown = ETrue;
       
  3639             iPowerkeyMenuExitSapSelection = powerMenuItemIndex;
       
  3640             powerMenuItemIndex++;
       
  3641             }
       
  3642 
       
  3643         // Profile menu items
       
  3644 
       
  3645         TInt arrayIndex ( 0 );
       
  3646         TBufC<KMaxProfileNameLength> profileName;
       
  3647 
       
  3648         for ( arrayIndex = 0; arrayIndex < iNumberOfProfileNamesInPowerKeyMenu; arrayIndex++ )
       
  3649             {
       
  3650             profileName = iProfileNamesArray->MdcaPoint( arrayIndex );
       
  3651             TPtr profileNamePtr = profileName.Des();
       
  3652             AknTextUtils::DisplayTextLanguageSpecificNumberConversion( profileNamePtr );
       
  3653             profileNameCDesCArray->AppendL( profileNamePtr );
       
  3654 
       
  3655             if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  3656                 {
       
  3657                 TInt profileId = ( iProfileNamesArray->ProfileName( arrayIndex ) )->Id();
       
  3658                 itemIdArray.AppendL(SecondaryDisplay::EPwrMenuItemProfileItemBase+profileId);
       
  3659                 }
       
  3660             powerMenuItemIndex++;
       
  3661             }
       
  3662 
       
  3663         // "Lock device" menu item
       
  3664 
       
  3665         callState = StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState );
       
  3666         
       
  3667         TInt devLockStatus( EAutolockStatusUninitialized );
       
  3668         devLockStatus = StateOfProperty( KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus );  // check whether Autolock has been started
       
  3669         
       
  3670 
       
  3671         if ( callState == EPSCTsyCallStateNone && devLockStatus != EAutolockStatusUninitialized )
       
  3672             {
       
  3673             TRACES( RDebug::Print(_L("CSysApAppUi::ShowPowerKeyPopUpMenuL: adding \"Lock device\", devLockStatus=%d" ), devLockStatus ) );
       
  3674 			iPowerkeyMenuLockSystemShown = ETrue;
       
  3675             itemStringBuf = StringLoader::LoadLC( R_QTN_SET_SEC_LOCK_SYSTEM, iEikonEnv );
       
  3676             profileNameCDesCArray->AppendL( itemStringBuf->Des() );
       
  3677             CleanupStack::PopAndDestroy(); // itemStringBuf
       
  3678             if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  3679                 {
       
  3680                 itemIdArray.AppendL(SecondaryDisplay::EPwrMenuItemLockDevice);
       
  3681                 }
       
  3682             iPowerkeyMenuLockSystemShown = ETrue;
       
  3683             iPowerkeyMenuLockSystemSelection = powerMenuItemIndex;
       
  3684             powerMenuItemIndex++;
       
  3685             }
       
  3686 
       
  3687         // "Eject MMC" menu item
       
  3688 
       
  3689         TInt propertyValue( StateOfProperty( KPSUidUsbWatcher, KUsbWatcherSelectedPersonality ) );
       
  3690 
       
  3691 #ifndef RD_MULTIPLE_DRIVE
       
  3692 			if ( !IsEncryptionOperationOngoingL() )
       
  3693 			{
       
  3694         if ( iSysApFeatureManager->MmcHotSwapSupported() &&
       
  3695              iMMCInserted &&
       
  3696              iSysApFeatureManager->EjectRequiredInPowerMenu() &&
       
  3697              propertyValue != KUsbPersonalityIdMS )
       
  3698             {
       
  3699             iPowerkeyMenuEjectShown = ETrue;
       
  3700             TRACES( RDebug::Print(_L("CSysApAppUi::ShowPowerKeyPopUpMenuL: adding \"Eject\"" ) ) );
       
  3701             itemStringBuf = StringLoader::LoadLC( R_QTN_PWRC_EJECT_MMC, iEikonEnv );
       
  3702             profileNameCDesCArray->AppendL( itemStringBuf->Des() );
       
  3703             CleanupStack::PopAndDestroy(); // itemStringBuf
       
  3704             if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  3705                 {
       
  3706                 itemIdArray.AppendL(SecondaryDisplay::EPwrMenuItemEjectMMC);
       
  3707                 }
       
  3708             iPowerkeyMenuEjectShown = ETrue;
       
  3709             iPowerkeyMenuEjectSelection = powerMenuItemIndex;
       
  3710             powerMenuItemIndex++;
       
  3711             }
       
  3712         }
       
  3713 
       
  3714 #else // RD_MULTIPLE_DRIVE
       
  3715 			if ( !IsEncryptionOperationOngoingL() )
       
  3716 			{
       
  3717         if ( iSysApFeatureManager->MmcHotSwapSupported() &&
       
  3718              iSysApFeatureManager->EjectRequiredInPowerMenu() &&
       
  3719              propertyValue != KUsbPersonalityIdMS )
       
  3720             {
       
  3721             // Reset old eject status and dialog
       
  3722             iSysApDriveList->ResetDrivesToEject();
       
  3723             if ( iSysApConfirmationQuery )
       
  3724                 {
       
  3725                 if ( iSysApConfirmationQuery->CurrentQuery() == ESysApEjectMmcQuery )
       
  3726                     {
       
  3727                     iSysApConfirmationQuery->Cancel();
       
  3728                     }
       
  3729                 }
       
  3730 
       
  3731             // Append memory cards for eject selection
       
  3732             TInt count( iInsertedMemoryCards.Count() );
       
  3733             for ( TInt i( 0 ); i < count; ++i )
       
  3734                 {
       
  3735                 itemStringBuf = iSysApDriveList->GetFormattedDriveNameLC(
       
  3736                     iInsertedMemoryCards[ i ].iDrive,
       
  3737                     R_QTN_PWRC_EJECT_MEMORY_STORAGE );
       
  3738                 profileNameCDesCArray->AppendL( *itemStringBuf );
       
  3739                 CleanupStack::PopAndDestroy( itemStringBuf );
       
  3740 
       
  3741                 if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  3742                     {
       
  3743                     itemIdArray.AppendL( SecondaryDisplay::EPwrMenuItemEjectItemBase + i );
       
  3744                     }
       
  3745                 }
       
  3746             if ( count > 0 )
       
  3747                 {
       
  3748                 TRACES( RDebug::Print(_L("CSysApAppUi::ShowPowerKeyPopUpMenuL: added \"Eject\"" ) ) );
       
  3749                 iPowerkeyMenuEjectShown = ETrue;
       
  3750                 iPowerkeyMenuEjectSelectionBase = powerMenuItemIndex;
       
  3751                 powerMenuItemIndex += count;
       
  3752                 }
       
  3753             }
       
  3754 				}
       
  3755 #endif // RD_MULTIPLE_DRIVE
       
  3756         
       
  3757         // Activate/deactive power save mode
       
  3758         if ( iSysApPsmController ) // variable feature, not create if power save is not used
       
  3759             {
       
  3760             TBool showActivate = !(iSysApPsmController->FullPsmEnabled());
       
  3761             
       
  3762             TInt textId = ( showActivate ? R_QTN_PWRC_ACTIVATE_POWER_SAVING : R_QTN_PWRC_DEACTIVATE_POWER_SAVING );
       
  3763             
       
  3764             itemStringBuf = StringLoader::LoadLC( textId, iEikonEnv );
       
  3765             iSysApPsmController->SetNextUiOperation( showActivate );
       
  3766             
       
  3767             if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  3768                 {
       
  3769                 itemIdArray.AppendL( showActivate ? 
       
  3770                                      SecondaryDisplay::EPwrMenuItemActivatePowerSaving :
       
  3771                                      SecondaryDisplay::EPwrMenuItemDeactivatePowerSaving );
       
  3772                 }
       
  3773                 
       
  3774             profileNameCDesCArray->AppendL( itemStringBuf->Des() );
       
  3775             CleanupStack::PopAndDestroy( itemStringBuf );
       
  3776                 
       
  3777             iSysApPsmController->SetUiItemId( powerMenuItemIndex );
       
  3778             powerMenuItemIndex++;    
       
  3779             }
       
  3780         
       
  3781         TRACES( RDebug::Print(_L("CSysApAppUi::ShowPowerKeyPopUpMenuL NumberOfAllItemsInPowerKeyMenu: %d" ),
       
  3782                               profileNameCDesCArray->Count() ) );
       
  3783 
       
  3784         iSysApPowerKeyMenuObserver->Start();
       
  3785 
       
  3786         // Set secondary display data if necessary
       
  3787         if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  3788             {
       
  3789             CAknSDData* sd = CAknSDData::NewL(SecondaryDisplay::KCatSysAp, SecondaryDisplay::ECmdShowPowerKeyListQuery, KNullDesC8);
       
  3790             sd->InsertGlobalListQueryItemIdsL(itemIdArray);
       
  3791             iGlobalListQuery->SetSecondaryDisplayData(sd); // ownership to notifier client
       
  3792             }
       
  3793 
       
  3794         iGlobalListQuery->ShowListQueryL( (MDesCArray*) profileNameCDesCArray,
       
  3795                                           iSysApPowerKeyMenuObserver->iStatus,
       
  3796                                           KProfileListInitialIndex );
       
  3797 
       
  3798         TRACES( RDebug::Print(_L("CSysApAppUi::ShowPowerKeyPopUpMenuL: list query shown" ) ) );
       
  3799 
       
  3800         CleanupStack::PopAndDestroy( profileNameCDesCArray ); // profileNameCDesCArray
       
  3801         TRACES( RDebug::Print(_L("CSysApAppUi::ShowPowerKeyPopUpMenuL: profileNameCDesCArray popped" ) ) );
       
  3802 
       
  3803         CleanupStack::Pop(&itemIdArray);
       
  3804         itemIdArray.Close();
       
  3805 
       
  3806         // Without following variable set ETrue powerkey up event would change the hightlighted item to be
       
  3807         // the second one instead of the wanted first one.
       
  3808         iIgnoreNextPowerKeyUpEvent = ETrue;
       
  3809 
       
  3810         if ( iSysApBatteryInfoController )        
       
  3811             {
       
  3812             iSysApBatteryInfoController->PowerMenuShownL();
       
  3813             }
       
  3814         
       
  3815         TRACES( RDebug::Print(_L("CSysApAppUi::ShowPowerKeyPopUpMenuL:end" ) ) );
       
  3816     }
       
  3817 }
       
  3818 
       
  3819 // ----------------------------------------------------------------------------
       
  3820 // CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL( TInt aSelection )
       
  3821 // ----------------------------------------------------------------------------
       
  3822 
       
  3823 void CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL( TInt aSelection )
       
  3824     {
       
  3825     iPowerKeyPopupMenuDismissed = ETrue;
       
  3826     iPowerKeyPopupMenuActive = EFalse;
       
  3827     TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: START aSelection:%d" ), aSelection ) );
       
  3828     if ( aSelection == KPowerKeyMenuSelectionCancelled )
       
  3829         {
       
  3830         TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: Powerkey menu cancelled" ) ) );
       
  3831         }
       
  3832     else if( aSelection < KPowerKeyMenuSelectionCancelled )
       
  3833         {
       
  3834         iIgnoreNextPowerKeyUpEvent = EFalse;
       
  3835         }
       
  3836     else
       
  3837         {
       
  3838         TInt firstProfileItemIndex( 1 + Max( 0, iPowerkeyMenuLockKeypadSelection, iPowerkeyMenuExitSapSelection ) ); // index of "General" profile
       
  3839 
       
  3840         if ( aSelection == KPowerKeyMenuSelectionSwitchOff )
       
  3841             {
       
  3842             TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: \"Switch off\" selected" ) ) );
       
  3843             DoShutdownL( EFalse, KDummyReason );
       
  3844             }
       
  3845 
       
  3846         else if ( iPowerkeyMenuLockKeypadShown && aSelection == iPowerkeyMenuLockKeypadSelection )
       
  3847             {
       
  3848             TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: \"Lock keypad\" selected" ) ) );
       
  3849             KeyLock().EnableKeyLock();
       
  3850             }
       
  3851 
       
  3852         else if ( iPowerkeyMenuExitSapShown && aSelection == iPowerkeyMenuExitSapSelection )
       
  3853             {
       
  3854             TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: \"Exit SAP\" selected" ) ) );
       
  3855             ShowQueryL( ESysApBtSapDisconnectQuery );
       
  3856             }
       
  3857 
       
  3858         else if ( aSelection < firstProfileItemIndex + iNumberOfProfileNamesInPowerKeyMenu )
       
  3859             {
       
  3860             __ASSERT_DEBUG( iProfileNamesArray, User::Invariant() );
       
  3861 
       
  3862             if ( iProfileNamesArray )
       
  3863                 {
       
  3864                 iProfileToBeActivated = ( iProfileNamesArray->ProfileName( aSelection - firstProfileItemIndex ) )->Id();
       
  3865 
       
  3866                 TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: profile id: %d selected" ), iProfileToBeActivated ) );
       
  3867                 if ( ! iSysApOfflineModeController->OfflineModeActive() ||
       
  3868                     ( iProfileToBeActivated ) == KOfflineModeProfileId )
       
  3869                     {
       
  3870                     ActivateProfileL( iProfileToBeActivated );
       
  3871                     }
       
  3872                 else
       
  3873                     {
       
  3874                     // iProfileToBeActivated profile will be activated from iSysApOfflineModeController if ok
       
  3875                     iSysApOfflineModeController->GoOnlineIfOkL();
       
  3876                     }
       
  3877                 }
       
  3878             }
       
  3879 
       
  3880         else if ( iPowerkeyMenuLockSystemShown && aSelection == iPowerkeyMenuLockSystemSelection )
       
  3881             {
       
  3882             TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: \"Lock system\" selected" ) ) );
       
  3883             iSysApSystemLock->SetLockedL();
       
  3884             }
       
  3885 #ifndef RD_MULTIPLE_DRIVE
       
  3886         else if ( iPowerkeyMenuEjectShown && aSelection == iPowerkeyMenuEjectSelection )
       
  3887             {
       
  3888             TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: \"Eject\" selected" ) ) );
       
  3889             ShowQueryL( ESysApEjectMmcQuery );
       
  3890             }
       
  3891 #else // RD_MULTIPLE_DRIVE
       
  3892         else if ( iPowerkeyMenuEjectShown &&
       
  3893                 aSelection >= iPowerkeyMenuEjectSelectionBase &&
       
  3894                 aSelection < iPowerkeyMenuEjectSelectionBase + iInsertedMemoryCards.Count() )
       
  3895             {
       
  3896             iDriveToEject =
       
  3897                 iInsertedMemoryCards[ aSelection - iPowerkeyMenuEjectSelectionBase ].iDrive;
       
  3898             TRACES( RDebug::Print(
       
  3899                 _L( "CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: \"Eject\" selected, drive=%d" ),
       
  3900                 iDriveToEject ) );
       
  3901             iSysApDriveList->ResetDrivesToEject();
       
  3902             RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
       
  3903             EjectMMCL();
       
  3904             }
       
  3905 #endif // RD_MULTIPLE_DRIVE
       
  3906         else if ( iSysApPsmController && aSelection == iSysApPsmController->UiItemId() )
       
  3907             {
       
  3908             TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: \"Activate|Deactivate power save\" selected" ) ) );
       
  3909             iSysApPsmController->DoEnableFullPsm( iSysApPsmController->NextUiOperation() );
       
  3910             }
       
  3911 
       
  3912         }
       
  3913 
       
  3914     delete iProfileNamesArray;
       
  3915     iProfileNamesArray = NULL;
       
  3916 
       
  3917     TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: END" ) ) );
       
  3918     }
       
  3919 
       
  3920 // ----------------------------------------------------------------------------
       
  3921 // CSysApAppUi::SetDeviceLockEnabledL( const TBool aLockEnabled )
       
  3922 // ----------------------------------------------------------------------------
       
  3923 
       
  3924 void CSysApAppUi::SetDeviceLockEnabledL( const TBool aLockEnabled )
       
  3925     {
       
  3926     TRACES( RDebug::Print(_L("CSysApAppUi::SetDeviceLockEnabledL aLockEnabled:%d" ), aLockEnabled ) );
       
  3927     TBool currentState( iDeviceLockEnabled );
       
  3928     
       
  3929     iDeviceLockEnabled = aLockEnabled;
       
  3930     
       
  3931     if ( currentState != iDeviceLockEnabled ) // filter out unnecessary light status modifications
       
  3932         {
       
  3933         iSysApLightsController->DeviceLockStateChangedL( iDeviceLockEnabled );
       
  3934         }
       
  3935     
       
  3936     if( iDeviceLockEnabled )
       
  3937         {
       
  3938         if( iKeyLockEnabled )
       
  3939             {
       
  3940             KeyLock().DisableWithoutNote();
       
  3941             }
       
  3942         }
       
  3943     else
       
  3944         {
       
  3945         // let's not activate keylock in case device lock was disabled during call or in cradle
       
  3946         iKeyLockOnBeforeCall = EFalse;
       
  3947         iKeyLockOnBeforeCradle = EFalse;
       
  3948 
       
  3949         // Memory card needs to be unlocked when device is unlocked
       
  3950         if ( iSysApFeatureManager->MmcHotSwapSupported() )
       
  3951             {
       
  3952             RunUnlockNotifierL();
       
  3953             }
       
  3954         }
       
  3955     }
       
  3956 
       
  3957 // ----------------------------------------------------------------------------
       
  3958 // CSysApAppUi::DoNotEnableKeylock()
       
  3959 // ----------------------------------------------------------------------------
       
  3960 
       
  3961 void CSysApAppUi::DoNotEnableKeylock()
       
  3962     {
       
  3963     if ( !iKeyLockOnBeforeCradle )
       
  3964         {
       
  3965         iShowkeypadActivatedNoteAfterSoftReject = iKeyLockOnBeforeCall;
       
  3966         }
       
  3967 
       
  3968     iKeyLockOnBeforeCall = EFalse;
       
  3969     }
       
  3970 
       
  3971 // ----------------------------------------------------------------------------
       
  3972 // CSysApAppUi::DoShutdownL( const TBool aReset, const TSWStartupReason aSWStartupReason )
       
  3973 // ----------------------------------------------------------------------------
       
  3974 
       
  3975 void CSysApAppUi::DoShutdownL( const TBool aReset, const TInt aResetReason )
       
  3976     {
       
  3977     TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL: aResetReason:%d, aReset:%d" ),
       
  3978         aResetReason, aReset ) );
       
  3979 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  3980     TBool animationenabled( EFalse );
       
  3981 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  3982 
       
  3983     if( OkToInitiateShutdown() )
       
  3984         {
       
  3985         TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL: Was OkToToInitiateShutdown" ) ) );
       
  3986 
       
  3987 
       
  3988         if ( !aReset && iSysApFeatureManager->Supported(KSysApFeatureIdGoodbyeNote) )
       
  3989             {
       
  3990             TRAPD( ignore, ShowShutdownNoteL() );
       
  3991             if ( ignore ) ignore = 0; // hide compiler warning about not using variable
       
  3992             }
       
  3993 
       
  3994         if( !aReset )
       
  3995             {
       
  3996     #ifdef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  3997             TRAPD( err, ShowAnimationL() );
       
  3998             if ( err )
       
  3999                 {
       
  4000                 TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL ShowAnimationL() leaved: %d" ), err ) );
       
  4001                 CompleteShutdown(aReset, aResetReason);
       
  4002                 }
       
  4003             }
       
  4004         else // aReset
       
  4005             {
       
  4006             CompleteShutdown(aReset, aResetReason);
       
  4007             }
       
  4008     #else // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4009             TRAPD( err, animationenabled = ShowAnimationL() );
       
  4010             if ( err )
       
  4011                 {
       
  4012                 TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL ShowAnimationL() leaved: %d" ), err ) );
       
  4013                 }
       
  4014             }
       
  4015 
       
  4016         if ( !animationenabled )
       
  4017             {
       
  4018             CompleteShutdown(aReset, aResetReason);
       
  4019             }
       
  4020     #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4021         }
       
  4022     else
       
  4023         {
       
  4024         TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL: Was not OkToToInitiateShutdown" ) ) );
       
  4025         }
       
  4026     TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL: END" ) ) );
       
  4027     }
       
  4028 
       
  4029 // ----------------------------------------------------------------------------
       
  4030 // CSysApAppUi::ContinueShutdown()
       
  4031 // ----------------------------------------------------------------------------
       
  4032 
       
  4033 void CSysApAppUi::ContinueShutdown()
       
  4034     {
       
  4035     TRACES( RDebug::Print(_L("CSysApAppUi::ContinueShutdown() started" ) ) );
       
  4036     CompleteShutdown();
       
  4037     TRACES( RDebug::Print(_L("CSysApAppUi::ContinueShutdown() completed" ) ) );
       
  4038     }
       
  4039 
       
  4040 // ----------------------------------------------------------------------------
       
  4041 // CSysApAppUi::ShowAnimationL()
       
  4042 // ----------------------------------------------------------------------------
       
  4043 
       
  4044 #ifdef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4045 void
       
  4046 #else // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4047 TBool
       
  4048 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4049 CSysApAppUi::ShowAnimationL()
       
  4050     {
       
  4051     TRACES( RDebug::Print(_L("CSysApAppUi::ShowAnimationL(): START" ) ) );
       
  4052 
       
  4053     TRACES( RDebug::Print( _L("CSysApAppUi::ShowAnimationL: Initialise shutdown animation") ) );
       
  4054 
       
  4055 #ifdef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4056 
       
  4057     PrepareForShutdownAnimation();
       
  4058 
       
  4059     iSysApShutdownAnimation = CSysApShutdownAnimation::NewL( *iSysApShutdownImage );
       
  4060     iSysApShutdownAnimation->Play( TCallBack( DoStopAnimTiming, this ) );
       
  4061 
       
  4062     TRACES( RDebug::Print(_L("CSysApAppUi::ShowAnimationL(): End" ) ) );
       
  4063 
       
  4064 #else // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4065     iSysApShutdownAnimation = CSysApShutdownAnimation::NewL( this );
       
  4066     AddToStackL( iSysApShutdownAnimation );
       
  4067     iAnimationShowingTime = iSysApShutdownAnimation->ShowingTime();
       
  4068     TRACES( RDebug::Print( _L("CSysApAppUi::ShowAnimationL: Shutdown animation initialised. Animation time = %d") ,iAnimationShowingTime) );
       
  4069 
       
  4070     TBool ret_val( EFalse );
       
  4071 
       
  4072     if ( iAnimationShowingTime )
       
  4073         {
       
  4074         if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  4075             {
       
  4076             // Construct mediator observer
       
  4077             iSysApMediatorObserver = CSysApMediatorObserver::NewL( this );
       
  4078 
       
  4079             // Sync animation
       
  4080             TInt err = iSysApMediatorObserver->SyncShutdownAnimation();
       
  4081 
       
  4082             if ( err != KErrNone )
       
  4083                 {
       
  4084                 // Pretend coverUI synced instantly if error in issuing command.
       
  4085                 ShutdownAnimationSyncOK();
       
  4086                 }
       
  4087             }
       
  4088         else
       
  4089             {
       
  4090             // Pretend coverUI synced instantly when it is not supported.
       
  4091             ShutdownAnimationSyncOK();
       
  4092             }
       
  4093 
       
  4094         ret_val = ETrue;
       
  4095         }
       
  4096 
       
  4097     TRACES( RDebug::Print(_L("CSysApAppUi::ShowAnimationL(): returns: %d" ),ret_val ) );
       
  4098     return ret_val;
       
  4099 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4100     }
       
  4101 
       
  4102 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4103 // ----------------------------------------------------------------------------
       
  4104 // CSysApAppUi::ShutdownAnimationSyncOK()
       
  4105 // ----------------------------------------------------------------------------
       
  4106 
       
  4107 void CSysApAppUi::ShutdownAnimationSyncOK()
       
  4108     {
       
  4109     TRACES( RDebug::Print(_L("CSysApAppUi::ShutdownAnimationSyncOK(): Call PrepareForShutdownAnimation()" ) ) );
       
  4110     PrepareForShutdownAnimation();//SysAp's internal preparation for ShutDown with animation
       
  4111     TRACES( RDebug::Print(_L("CSysApAppUi::ShutdownAnimationSyncOK(): Called PrepareForShutdownAnimation()" ) ) );
       
  4112     }
       
  4113 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4114 
       
  4115 // ----------------------------------------------------------------------------
       
  4116 // CSysApAppUi::SkipShutdownAnimation()
       
  4117 // ----------------------------------------------------------------------------
       
  4118 
       
  4119 void CSysApAppUi::SkipShutdownAnimation()
       
  4120     {
       
  4121     TRACES( RDebug::Print(_L("CSysApAppUi::SkipShutdownAnimation() " ) ) );
       
  4122 
       
  4123 #ifdef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4124     if ( iSysApShutdownAnimation )
       
  4125         {
       
  4126         iSysApShutdownAnimation->Cancel();
       
  4127         }
       
  4128 #else // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4129     if ( iAnimationShowingTime )
       
  4130         {
       
  4131         iSysApShutdownAnimation->EndAnimation();
       
  4132         }
       
  4133 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4134     }
       
  4135 
       
  4136 // ----------------------------------------------------------------------------
       
  4137 // CSysApAppUi::NotifyShutdownAnimationSkip()
       
  4138 // ----------------------------------------------------------------------------
       
  4139 
       
  4140 void CSysApAppUi::NotifyShutdownAnimationSkip()
       
  4141     {
       
  4142     TRACES( RDebug::Print(_L("CSysApAppUi::NotifyShutdownAnimationSkip() " ) ) );
       
  4143 
       
  4144     if ( iSysApMediatorObserver )
       
  4145         {
       
  4146         iSysApMediatorObserver->ShutdownAnimationSkipped();
       
  4147         }
       
  4148     }
       
  4149 
       
  4150 // ----------------------------------------------------------------------------
       
  4151 // CSysApAppUi::CompleteShutdown()
       
  4152 // ----------------------------------------------------------------------------
       
  4153 
       
  4154 void CSysApAppUi::CompleteShutdown( const TBool aReset, const TInt aResetReason )
       
  4155     {
       
  4156     TRACES( RDebug::Print(_L("CSysApAppUi::CompleteShutdown(): START" ) ) );
       
  4157 
       
  4158     PrepareForShutdownImage();//SysAp's internal preparation for ShutDown with image
       
  4159 
       
  4160     FreeResources();
       
  4161 
       
  4162     if ( aReset )
       
  4163         {
       
  4164         __ASSERT_DEBUG( aResetReason >= RStarterSession::ELanguageSwitchReset &&
       
  4165                         aResetReason <= RStarterSession::EDataRestoreReset,
       
  4166                         User::Invariant() );
       
  4167         StarterSession().Reset( static_cast<RStarterSession::TResetReason>( aResetReason ) );
       
  4168         }
       
  4169     else
       
  4170         {
       
  4171         StarterSession().Shutdown();
       
  4172         }
       
  4173 
       
  4174     StarterSession().Close();
       
  4175 
       
  4176     TRACES( RDebug::Print(_L("CSysApAppUi::CompleteShutdown(): END" ) ) );
       
  4177     }
       
  4178 
       
  4179 #ifndef SYSAP_USE_STARTUP_UI_PHASE
       
  4180 // ----------------------------------------------------------------------------
       
  4181 // CSysApAppUi::DoStateChangedL(const RStarterSession::TGlobalState aSwState)
       
  4182 // This method is not called after boot has finished.
       
  4183 // ----------------------------------------------------------------------------
       
  4184 
       
  4185 void CSysApAppUi::DoStateChangedL(const RStarterSession::TGlobalState aSwState)
       
  4186     {
       
  4187     TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL: %d" ), aSwState ) );
       
  4188 
       
  4189     switch ( aSwState )
       
  4190         {
       
  4191         case RStarterSession::ENormal:
       
  4192             SetStatusPaneLayoutL( ESysApNormal );
       
  4193             break;
       
  4194         case RStarterSession::ECharging:
       
  4195             SetStatusPaneLayoutL( ESysApCharging );
       
  4196             break;
       
  4197         case RStarterSession::EAlarm:
       
  4198             SetStatusPaneLayoutL( ESysApAlarm );
       
  4199             break;
       
  4200         default:
       
  4201             break;
       
  4202         };
       
  4203 
       
  4204     TRAPD( simChangedErr, DoSimChangedFromPreviousBootL() );
       
  4205     TRACES( RDebug::Print( _L("CSysApAppUi::DoStateChangedL: simChangedErr = %d" ), simChangedErr ) );
       
  4206     simChangedErr = simChangedErr; // suppress 'variable not used' warning
       
  4207     LogsObserverL().HandleSimChangedCheckDoneL();
       
  4208 
       
  4209     if ( iSysApFeatureManager->PowerSaveSupported() )
       
  4210         {
       
  4211         // create controller before checking battery state, so that power saving can be enabled during boot if needed
       
  4212         if ( !iSysApPsmController ) // created only in first state change
       
  4213             {
       
  4214             iSysApPsmController = CSysApPsmController::NewL( *this );        
       
  4215             }
       
  4216 
       
  4217         // in charger boot explicitly disable partial power save mode
       
  4218         if ( aSwState == RStarterSession::ECharging && !iCharging )
       
  4219             {
       
  4220             iSysApPsmController->ChargerConnected();
       
  4221             iSysApPsmController->DoEnablePartialPsm( EFalse ); // disable partial power save now
       
  4222             }
       
  4223         }
       
  4224 
       
  4225     TInt state( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
  4226     //Also Charging status will be updated with the following function.
       
  4227     UpdateBatteryBarsL( state );
       
  4228 
       
  4229     if( IsStateNormal() )
       
  4230         {
       
  4231         TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL to normal state.") ) );
       
  4232 
       
  4233         DoSwStateNormalConstructionL();
       
  4234 
       
  4235         InitializeStatusPaneAreaL();
       
  4236         CheckSilentModeL();
       
  4237         HandleAccessoryProfileInStartupL();
       
  4238 
       
  4239         if ( iSysApFeatureManager->MmcSupported() )
       
  4240             {
       
  4241 #ifndef RD_MULTIPLE_DRIVE
       
  4242             MountMMC();
       
  4243             MMCStatusChangedL();
       
  4244             iHideFirstBeep = EFalse;
       
  4245 #else // RD_MULTIPLE_DRIVE
       
  4246             iSysApDriveList->MountDrive( iSysApDriveList->DefaultMemoryCard() );
       
  4247             UpdateInsertedMemoryCardsL();
       
  4248 #endif // RD_MULTIPLE_DRIVE
       
  4249             }
       
  4250         if ( iSysApFeatureManager->MmcHotSwapSupported() )
       
  4251             {
       
  4252             iSysApMMCObserver->StartMountObserver();
       
  4253             }
       
  4254 
       
  4255         
       
  4256         if ( iSysApPsmController )
       
  4257             {
       
  4258             if ( iCharging ) // if charger is connected on boot PSM queries may need to be shown
       
  4259                 {
       
  4260                 HandleChargingStatusL( StateOfProperty( KPSUidHWRMPowerState, KHWRMChargingStatus ) );
       
  4261                 }
       
  4262             }
       
  4263         
       
  4264         TInt batteryStatus = StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryStatus );
       
  4265         TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL: batteryStatus %d" ), batteryStatus ) );
       
  4266         if(  batteryStatus == EBatteryStatusLow || batteryStatus == EBatteryStatusEmpty )
       
  4267             {
       
  4268             // low and empty battery states are informed to the user in device startup
       
  4269             HandleBatteryStatusL( batteryStatus );
       
  4270             }
       
  4271         else if ( iSysApPsmController && !iCharging )
       
  4272         	{
       
  4273 				TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL: batteryStatus %d, iCharging %d -> disable partial psm" ), batteryStatus, iCharging ) );
       
  4274 
       
  4275 				iSysApPsmController->BatteryLow( EFalse );
       
  4276 				iSysApPsmController->DoEnablePartialPsm( EFalse );
       
  4277 			}
       
  4278 
       
  4279         iSysApBtController = CreateSysApBtControllerL( *this );
       
  4280         iSysApBtSapController = CreateSysApBtSapControllerL( *this );
       
  4281 
       
  4282         if ( iActivateBt )
       
  4283             {
       
  4284             TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL Activating BT" ) ) );
       
  4285             SetBtPowerState( ETrue );
       
  4286             }
       
  4287 
       
  4288         if ( iDeactivateBt )
       
  4289             {
       
  4290             TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL Deactivating BT" ) ) );
       
  4291             SetBtPowerState( EFalse );
       
  4292             }
       
  4293         iSysApLocationPrivacyIndicator = CreateSysApLocationPrivacyIndicatorL( *this );
       
  4294         iSysApLocationPrivacyIndicator->InitL();
       
  4295 
       
  4296         if ( ! iSysApUsbIndicatorController )
       
  4297             {
       
  4298             TRAPD ( usbErr, iSysApUsbIndicatorController = CreateSysApUsbIndicatorL( *this ) );
       
  4299             if ( usbErr )
       
  4300                 {
       
  4301                 TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL: error in constructing USB ind. controller %d" ), usbErr ) );
       
  4302                 }
       
  4303             }
       
  4304 
       
  4305         // Other late initializations.
       
  4306         // In order to prevent unexpected behaviour e.g. in OOM situations, these calls are made to ensure
       
  4307         // that the services are connected when they are needed for the first time.
       
  4308         if ( !StarterSession().Handle() )
       
  4309             {
       
  4310             User::Leave( KErrBadHandle );
       
  4311             }
       
  4312 
       
  4313         if ( !KeyLock().Handle() )
       
  4314             {
       
  4315             User::Leave( KErrBadHandle );
       
  4316             }
       
  4317 
       
  4318 #ifdef __SYSAP_MODULE_TEST
       
  4319         ModuleTestShowUiNoteL( _L("SysAp: SW state normal!") );
       
  4320 #endif
       
  4321         }
       
  4322 
       
  4323     // Allow lights
       
  4324     iSysApLightsController->AllowLightsOn();
       
  4325     }
       
  4326 
       
  4327 #else // SYSAP_USE_STARTUP_UI_PHASE
       
  4328 
       
  4329 // ----------------------------------------------------------------------------
       
  4330 // CSysApAppUi::HandleUiReadyAfterBootL()
       
  4331 // Called when startup UI activities has been finished
       
  4332 // ----------------------------------------------------------------------------
       
  4333 
       
  4334 void CSysApAppUi::HandleUiReadyAfterBootL()
       
  4335     {
       
  4336     TRACES( RDebug::Print(_L("CSysApAppUi::HandleUiReadyAfterBootL" ) ) );
       
  4337     
       
  4338     SetStatusPaneLayoutL( ESysApNormal );
       
  4339     
       
  4340     TInt state( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
  4341     //Also Charging status will be updated with the following function.
       
  4342     UpdateBatteryBarsL( state );
       
  4343     
       
  4344     DoSwStateNormalConstructionL();
       
  4345 
       
  4346     InitializeStatusPaneAreaL();
       
  4347     CheckSilentModeL();
       
  4348     HandleAccessoryProfileInStartupL();
       
  4349     
       
  4350     if ( iSysApFeatureManager->MmcSupported() )
       
  4351         {
       
  4352 #ifndef RD_MULTIPLE_DRIVE
       
  4353         MountMMC();
       
  4354         MMCStatusChangedL();
       
  4355         iHideFirstBeep = EFalse;
       
  4356 #else // RD_MULTIPLE_DRIVE
       
  4357         iSysApDriveList->MountDrive( iSysApDriveList->DefaultMemoryCard() );
       
  4358         UpdateInsertedMemoryCardsL();
       
  4359 #endif // RD_MULTIPLE_DRIVE
       
  4360         }
       
  4361     
       
  4362     if ( iSysApFeatureManager->MmcHotSwapSupported() )
       
  4363         {
       
  4364         iSysApMMCObserver->StartMountObserver();
       
  4365         }
       
  4366 
       
  4367     if ( iSysApPsmController )
       
  4368         {
       
  4369         if ( iCharging ) // if charger is connected on boot PSM queries may need to be shown
       
  4370             {
       
  4371             HandleChargingStatusL( StateOfProperty( KPSUidHWRMPowerState, KHWRMChargingStatus ) );
       
  4372             }
       
  4373         }
       
  4374     
       
  4375     TInt batteryStatus = StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryStatus );
       
  4376     TRACES( RDebug::Print(_L("CSysApAppUi::HandleUiReadyAfterBootL: batteryStatus %d" ), batteryStatus ) );
       
  4377     if(  batteryStatus == EBatteryStatusLow || batteryStatus == EBatteryStatusEmpty )
       
  4378         {
       
  4379         // low and empty battery states are informed to the user in device startup
       
  4380         HandleBatteryStatusL( batteryStatus );
       
  4381         }
       
  4382     else if ( iSysApPsmController && !iCharging )
       
  4383       	{
       
  4384 		    TRACES( RDebug::Print(_L("CSysApAppUi::HandleUiReadyAfterBootL: batteryStatus %d, iCharging %d -> disable partial psm" ), batteryStatus, iCharging ) );
       
  4385 
       
  4386 			iSysApPsmController->BatteryLow( EFalse );
       
  4387 			iSysApPsmController->DoEnablePartialPsm( EFalse );
       
  4388         }
       
  4389 
       
  4390     iSysApLocationPrivacyIndicator = CreateSysApLocationPrivacyIndicatorL( *this );
       
  4391     iSysApLocationPrivacyIndicator->InitL();
       
  4392 
       
  4393     if ( ! iSysApUsbIndicatorController )
       
  4394         {
       
  4395         TRAPD ( usbErr, iSysApUsbIndicatorController = CreateSysApUsbIndicatorL( *this ) );
       
  4396         if ( usbErr )
       
  4397             {
       
  4398             TRACES( RDebug::Print(_L("CSysApAppUi::HandleUiReadyAfterBootL: error in constructing USB ind. controller %d" ), usbErr ) );
       
  4399             }
       
  4400         }
       
  4401     }
       
  4402 
       
  4403 // ----------------------------------------------------------------------------
       
  4404 // CSysApAppUi::DoStateChangedL(const RStarterSession::TGlobalState aSwState)
       
  4405 // This method is not called after boot has finished.
       
  4406 // ----------------------------------------------------------------------------
       
  4407 
       
  4408 void CSysApAppUi::DoStateChangedL(const RStarterSession::TGlobalState aSwState)
       
  4409     {
       
  4410     TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL: %d" ), aSwState ) );
       
  4411 
       
  4412     switch ( aSwState )
       
  4413         {
       
  4414         case RStarterSession::ENormal:
       
  4415             // status pane layout will updated when UI is ready
       
  4416             break;
       
  4417         case RStarterSession::ECharging:
       
  4418             SetStatusPaneLayoutL( ESysApCharging );
       
  4419             break;
       
  4420         case RStarterSession::EAlarm:
       
  4421             SetStatusPaneLayoutL( ESysApAlarm );
       
  4422             break;
       
  4423         default:
       
  4424             break;
       
  4425         };
       
  4426 
       
  4427     TRAPD( simChangedErr, DoSimChangedFromPreviousBootL() );
       
  4428     TRACES( RDebug::Print( _L("CSysApAppUi::DoStateChangedL: simChangedErr = %d" ), simChangedErr ) );
       
  4429     simChangedErr = simChangedErr; // suppress 'variable not used' warning
       
  4430     LogsObserverL().HandleSimChangedCheckDoneL();
       
  4431 
       
  4432     if ( iSysApFeatureManager->PowerSaveSupported() )
       
  4433         {
       
  4434         // create controller before checking battery state, so that power saving can be enabled during boot if needed
       
  4435         if ( !iSysApPsmController ) // created only in first state change
       
  4436             {
       
  4437             iSysApPsmController = CSysApPsmController::NewL( *this );        
       
  4438             }
       
  4439 
       
  4440         // in charger boot explicitly disable partial power save mode
       
  4441         if ( aSwState == RStarterSession::ECharging )
       
  4442             {
       
  4443             iSysApPsmController->ChargerConnected();
       
  4444             iSysApPsmController->DoEnablePartialPsm( EFalse ); // disable partial power save now
       
  4445             }
       
  4446         }
       
  4447 
       
  4448     if ( aSwState == RStarterSession::ECharging || aSwState == RStarterSession::EAlarm )
       
  4449         {
       
  4450         TInt state( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
  4451         //Also Charging status will be updated with the following function.
       
  4452         UpdateBatteryBarsL( state );    
       
  4453         }
       
  4454         
       
  4455     if( IsStateNormal() )
       
  4456         {
       
  4457         TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL to normal state.") ) );
       
  4458 
       
  4459         iSysApBtController = CreateSysApBtControllerL( *this );
       
  4460         iSysApBtSapController = CreateSysApBtSapControllerL( *this );
       
  4461 
       
  4462         if ( iActivateBt )
       
  4463             {
       
  4464             TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL Activating BT" ) ) );
       
  4465             SetBtPowerState( ETrue );
       
  4466             }
       
  4467 
       
  4468         if ( iDeactivateBt )
       
  4469             {
       
  4470             TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL Deactivating BT" ) ) );
       
  4471             SetBtPowerState( EFalse );
       
  4472             }
       
  4473 
       
  4474         // Other late initializations.
       
  4475         // In order to prevent unexpected behaviour e.g. in OOM situations, these calls are made to ensure
       
  4476         // that the services are connected when they are needed for the first time.
       
  4477         if ( !StarterSession().Handle() )
       
  4478             {
       
  4479             User::Leave( KErrBadHandle );
       
  4480             }
       
  4481 
       
  4482         if ( !KeyLock().Handle() )
       
  4483             {
       
  4484             User::Leave( KErrBadHandle );
       
  4485             }
       
  4486 
       
  4487 #ifdef __SYSAP_MODULE_TEST
       
  4488         ModuleTestShowUiNoteL( _L("SysAp: SW state normal!") );
       
  4489 #endif
       
  4490         }
       
  4491 
       
  4492     // Allow lights
       
  4493     iSysApLightsController->AllowLightsOn();
       
  4494     }
       
  4495 
       
  4496 
       
  4497 #endif // SYSAP_USE_STARTUP_UI_PHASE
       
  4498 
       
  4499 // ----------------------------------------------------------------------------
       
  4500 // CSysApAppUi::UiReady()
       
  4501 // 
       
  4502 // ----------------------------------------------------------------------------
       
  4503 
       
  4504 TBool CSysApAppUi::UiReady() const
       
  4505     {
       
  4506 #ifdef SYSAP_USE_STARTUP_UI_PHASE    
       
  4507     return iSysApStartupController->UiReady(); 
       
  4508 #else // SYSAP_USE_STARTUP_UI_PHASE
       
  4509     // if startup UI phase information is not used, global system state normal is handled as UI idle state
       
  4510     return IsStateNormal();
       
  4511 #endif // SYSAP_USE_STARTUP_UI_PHASE        
       
  4512     }
       
  4513 
       
  4514 // ----------------------------------------------------------------------------
       
  4515 // CSysApAppUi::PrepareForShutdownAnimation()
       
  4516 // ----------------------------------------------------------------------------
       
  4517 void CSysApAppUi::PrepareForShutdownAnimation()
       
  4518     {
       
  4519     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownAnimation() begin") ) );
       
  4520 
       
  4521 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4522     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownAnimation() showtime = %d"), iAnimationShowingTime ) );
       
  4523     if ( iAnimationShowingTime )
       
  4524         {
       
  4525 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4526         static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds()->PlaySound( EAvkonSIDPowerOffTone );
       
  4527         CancelGlobalListQuery();
       
  4528 
       
  4529         if ( iSysApPowerKeyMenuObserver )
       
  4530             {
       
  4531             iSysApPowerKeyMenuObserver->Cancel();
       
  4532             }
       
  4533 
       
  4534         // deactivate notifiers before showing the shutdown image
       
  4535         AknNotifierController::CancelAllNotifications();
       
  4536         AknNotifierController::HideAllNotifications(ETrue);
       
  4537         RWindowGroup groupWin = iCoeEnv->RootWin();
       
  4538         iCapturedAppskey = groupWin.CaptureKey( EKeyApplication, KModifierMask, KModifierMask );
       
  4539         iCapturedAppskeyUpAndDowns = groupWin.CaptureKeyUpAndDowns( EStdKeyApplication0, KModifierMask, KModifierMask );
       
  4540         iEikonEnv->RootWin().SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront );
       
  4541 
       
  4542         TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownAnimation() Draw background image" ) ) );
       
  4543 
       
  4544         ShowShutdownImage( KBackgroundImageID );
       
  4545 
       
  4546 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4547         TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownAnimation() Show Shutdown animation" ) ) );
       
  4548         TInt err(0);
       
  4549         TRAP( err, iSysApShutdownAnimation->StartL( iLastPowerKeyWasShort ) );
       
  4550         if ( err )
       
  4551             {
       
  4552             TRACES( RDebug::Print( _L("SysAp: Shutdown animation fails. Error code: %d" ), err ) );
       
  4553             // Start animation timing immediatily if animation starting fails.
       
  4554             // Otherwise animation will call StartAnimTiming when it is ready.
       
  4555             StartAnimTiming();
       
  4556             }
       
  4557         }
       
  4558 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4559 
       
  4560     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownAnimation() end") ) );
       
  4561     }
       
  4562 
       
  4563 
       
  4564 // ----------------------------------------------------------------------------
       
  4565 // CSysApAppUi::PrepareForShutdownImage()
       
  4566 // ----------------------------------------------------------------------------
       
  4567 
       
  4568 void CSysApAppUi::PrepareForShutdownImage()
       
  4569     {
       
  4570     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownImage() START" ) ) );
       
  4571 
       
  4572     // If RD_STARTUP_ANIMATION_CUSTOMIZATION is enabled, the following actions are always taken in PrepareForShutdownAnimation
       
  4573 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4574     if ( !iAnimationShowingTime ) // actions already taken in PrepareForShutdownAnimation
       
  4575         {
       
  4576         static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds()->PlaySound( EAvkonSIDPowerOffTone );
       
  4577         CancelGlobalListQuery();
       
  4578         
       
  4579         if ( iSysApPowerKeyMenuObserver )
       
  4580             {
       
  4581             iSysApPowerKeyMenuObserver->Cancel();
       
  4582             }
       
  4583         
       
  4584         // deactivate notifiers before showing the shutdown image
       
  4585         AknNotifierController::CancelAllNotifications();
       
  4586         AknNotifierController::HideAllNotifications(ETrue);
       
  4587         RWindowGroup groupWin = iCoeEnv->RootWin();
       
  4588         iCapturedAppskey = groupWin.CaptureKey( EKeyApplication, KModifierMask, KModifierMask );
       
  4589         iCapturedAppskeyUpAndDowns = groupWin.CaptureKeyUpAndDowns( EStdKeyApplication0, KModifierMask, KModifierMask );
       
  4590         }
       
  4591 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4592 
       
  4593 #ifndef __SYSAP_MODULE_TEST //to make errors during shutdown sequence being seen more easily
       
  4594     iEikonEnv->RootWin().SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront );
       
  4595     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownImage() Show Shutdown image" ) ) );
       
  4596     ShowShutdownImage( EMbmSysapQgn_startup_screen );
       
  4597 #endif
       
  4598     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownImage() END" ) ) );
       
  4599     }
       
  4600 
       
  4601 // ----------------------------------------------------------------------------
       
  4602 // CSysApAppUi::SetStatusPaneLauoutL( const TSysApPhoneState aState )
       
  4603 // ----------------------------------------------------------------------------
       
  4604 
       
  4605 void CSysApAppUi::SetStatusPaneLayoutL( const TSysApPhoneState aState )
       
  4606     {
       
  4607     TRACES( RDebug::Print( _L("CSysApAppUi::SetStatusPaneLayoutL aState: %d"), aState ) );
       
  4608     if( aState == ESysApNormal )
       
  4609         //Status pane cannot be even visible on Normal mode
       
  4610         {
       
  4611         StatusPane()->MakeVisible( EFalse );
       
  4612         StatusPane()->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_EMPTY );
       
  4613         }
       
  4614     else if( aState == ESysApCharging )
       
  4615         //SysAp's statuspane is visible on Charging mode
       
  4616         {
       
  4617         StatusPane()->MakeVisible( ETrue );
       
  4618         StatusPane()->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_POWER_OFF_RECHARGE );
       
  4619         }
       
  4620     else if( aState == ESysApAlarm )
       
  4621     	{
       
  4622     	if ( !Layout_Meta_Data::IsLandscapeOrientation() )
       
  4623     		{
       
  4624     		// Portrait mode
       
  4625 	        StatusPane()->MakeVisible( ETrue );
       
  4626 	        StatusPane()->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_POWER_OFF_RECHARGE );
       
  4627     		}
       
  4628     	else
       
  4629     		{
       
  4630     		// Landscape mode
       
  4631 	        TInt layout = R_AVKON_STATUS_PANE_LAYOUT_POWER_OFF_RECHARGE;
       
  4632 	        // For side softkey devices, use different layout
       
  4633 	        if (AVKONENV->StatusPaneResIdForCurrentLayout(R_AVKON_STATUS_PANE_LAYOUT_USUAL) == R_AVKON_STACON_PANE_LAYOUT_USUAL_SOFTKEYS_RIGHT)
       
  4634 	        	layout = R_AVKON_STACON_PANE_LAYOUT_EMPTY_SOFTKEYS_RIGHT;
       
  4635 	        else if (AVKONENV->StatusPaneResIdForCurrentLayout(R_AVKON_STATUS_PANE_LAYOUT_USUAL) == R_AVKON_STACON_PANE_LAYOUT_USUAL_SOFTKEYS_LEFT)
       
  4636 	        	layout = R_AVKON_STACON_PANE_LAYOUT_EMPTY_SOFTKEYS_LEFT;
       
  4637 
       
  4638 	        StatusPane()->MakeVisible( ETrue );
       
  4639 	        StatusPane()->SwitchLayoutL( layout );
       
  4640     		}
       
  4641     	}
       
  4642     }
       
  4643 
       
  4644 // ----------------------------------------------------------------------------
       
  4645 // CSysApAppUi::OkToInitiateShutdown()
       
  4646 // ----------------------------------------------------------------------------
       
  4647 
       
  4648 TBool CSysApAppUi::OkToInitiateShutdown()
       
  4649     {
       
  4650     TInt swState;
       
  4651     RProperty::Get( KPSUidStartup, KPSGlobalSystemState, swState );
       
  4652 
       
  4653     if( !iShutdownStarted &&
       
  4654         swState == ESwStateStartingCriticalApps ||
       
  4655         swState == ESwStateSelfTestOK ||
       
  4656         swState == ESwStateSecurityCheck ||
       
  4657         swState == ESwStateCriticalPhaseOK ||
       
  4658         swState == ESwStateEmergencyCallsOnly ||
       
  4659         swState == ESwStateCharging ||
       
  4660         swState == ESwStateAlarm ||
       
  4661         swState == ESwStateNormalRfOn ||
       
  4662         swState == ESwStateNormalRfOff ||
       
  4663         swState == ESwStateNormalBTSap ||
       
  4664         swState == ESwStateFatalStartupError )
       
  4665         {
       
  4666         iShutdownStarted = ETrue;
       
  4667         return ETrue;
  2731         return ETrue;
  4668         }
  2732         }
  4669     else
       
  4670         {
       
  4671         return EFalse;
       
  4672         }
       
  4673     }
       
  4674 
       
  4675 /**
       
  4676  * To check the for an emergency call. 
       
  4677  * 
       
  4678  * @return ETrue if there is an emergency call active otherwise, EFalse.
       
  4679  */
       
  4680 TBool IsEmergencyCall()
       
  4681         {
       
  4682         TBool retVal( EFalse );
       
  4683         TInt err( KErrNone );
       
  4684         TInt state( 0 );
       
  4685      
       
  4686         err = RProperty::Get(KPSUidCtsyEmergencyCallInfo, KCTSYEmergencyCallInfo, state );
       
  4687         if ( err == KErrNone && state )
       
  4688             {
       
  4689             retVal = ETrue;            
       
  4690             }
       
  4691         return retVal;
       
  4692         }	
       
  4693 
       
  4694 // ----------------------------------------------------------------------------
       
  4695 // CSysApAppUi::HandleCurrentCallStateChangeL()
       
  4696 // ----------------------------------------------------------------------------
       
  4697 
       
  4698 void CSysApAppUi::HandleCurrentCallStateChangeL( TInt aCurrentCallState )
       
  4699     {
       
  4700     TRACES( RDebug::Print( _L("CSysApAppUi::HandleCurrentCallStateChangeL: KUidCurrentCall: %d" ), aCurrentCallState ) );
       
  4701 
       
  4702     if( iPowerKeyPopupMenuActive )
       
  4703         {
       
  4704         CancelGlobalListQuery();
       
  4705         }
       
  4706 
       
  4707     switch ( aCurrentCallState )
       
  4708         {
       
  4709         case EPSCTsyCallStateRinging:
       
  4710             {
       
  4711             iSysApLightsController->CallComingInL( ETrue );
       
  4712             // Disable keylock when a call is coming in
       
  4713             if ( iKeyLockEnabled || iDeviceLockEnabled || iKeyLockOnBeforeCradle || iKeyLockOnBeforeAlarm )
       
  4714                 {
       
  4715                 TRACES( RDebug::Print( _L("CSysApAppUi::HandleCurrentCallStateChangeL: EPSCTsyCallStateRinging: disable keylock") ) );
       
  4716                 iKeyLockOnBeforeCall = ETrue;
       
  4717 
       
  4718                 if ( iKeyLockEnabled || iDeviceLockEnabled )
       
  4719                     {
       
  4720                     if ( !iSysApFeatureManager->TouchUnlockStrokeSupported() )
       
  4721                         {
       
  4722                         KeyLock().DisableWithoutNote();
       
  4723                         }
       
  4724                     }
       
  4725                 }
       
  4726             break;
       
  4727             }
       
  4728             
       
  4729         case EPSCTsyCallStateDialling:
       
  4730             {
       
  4731             // Disable keypad lock during an emergency call
       
  4732             // no need to disable the key lock when a call is made using the wireless car-kit
       
  4733             // but if the call is an emergency one then we will disable the keypad lock
       
  4734             if ( iKeyLockEnabled || iDeviceLockEnabled || iKeyLockOnBeforeCradle )
       
  4735                 {
       
  4736                 TRACES( RDebug::Print( _L("CSysApAppUi::HandleCurrentCallStateChangeL: EPSCTsyCallStateDialling: disable keylock") ) );
       
  4737                 iKeyLockOnBeforeCall = ETrue;
       
  4738 
       
  4739                 if ( IsEmergencyCall() && (iKeyLockEnabled || iDeviceLockEnabled ))
       
  4740                     {
       
  4741                     KeyLock().DisableWithoutNote();
       
  4742                     }
       
  4743                 }
       
  4744 
       
  4745             // Enable signal & network indicators when an emergency call is made in Offline Mode
       
  4746             if( iSysApOfflineModeController->OfflineModeActive() )
       
  4747                     {
       
  4748                     // Signal indicators not updated with VoIP call
       
  4749                     if ( StateOfProperty(KPSUidCtsyCallInformation, KCTsyCallType) != EPSCTsyCallTypeVoIP) 
       
  4750                         {
       
  4751                         iEmergencyCallActive = ETrue;
       
  4752                         UpdateSignalBarsL();
       
  4753                         SetSignalIndicatorL();
       
  4754                         }
       
  4755                     }
       
  4756             break;
       
  4757             }
       
  4758             
       
  4759         case EPSCTsyCallStateConnected:
       
  4760             {
       
  4761             if (StateOfProperty(KPSUidCtsyCallInformation, KCTsyCallType) == EPSCTsyCallTypeCSVoice)
       
  4762                 {
       
  4763                 // Check if GPRS suspended note is required
       
  4764                 iCallActivated = ETrue;
       
  4765                 HandleGprsNotesL();
       
  4766                 }
       
  4767             if ( iDeviceLockEnabled )
       
  4768                 {
       
  4769                 // Enable keylock via autolock emulation if device lock enabled. 
       
  4770                 // Otherwise e.g. messages can be read using softkeys during ongoing call.
       
  4771                 KeyLock().EnableAutoLockEmulation();
       
  4772                 }
       
  4773             break;
       
  4774             }
       
  4775 
       
  4776         case EPSCTsyCallStateNone:
       
  4777             {
       
  4778             // Reset timers in ScreenSaver and Autolock
       
  4779             User::ResetInactivityTime();
       
  4780 
       
  4781             if ( iEmergencyCallActive )
       
  4782                 {
       
  4783                 iEmergencyCallActive = EFalse;
       
  4784                 UpdateSignalBarsL( 0 );
       
  4785                 SetSignalIndicatorL();
       
  4786                 }
       
  4787             if ( iKeyLockOnBeforeCall )
       
  4788                 {
       
  4789                 TRACES( RDebug::Print( _L("CSysApAppUi::HandleCurrentCallStateChangeL: EPSCTsyCallStateNone: enable keylock") ) );
       
  4790                 iKeyLockOnBeforeCall = EFalse;
       
  4791                 if ( !iDeviceLockEnabled )
       
  4792                     {
       
  4793                     if ( !iKeyLockOnBeforeCradle && !iKeyLockOnBeforeAlarm &&
       
  4794                           !iSysApFeatureManager->TouchUnlockStrokeSupported() )
       
  4795                         {
       
  4796                         if ( iSysApCenRepController->GetInt( KCRUidCommonTelephonySettings, KSettingsSummaryAfterCall ) == 1 )
       
  4797                             {
       
  4798                             KeyLock().EnableWithoutNote(); // Let's not hide "Summary After Call" dialog
       
  4799                             }
       
  4800                         else
       
  4801                             {
       
  4802                             KeyLock().EnableKeyLock();
       
  4803                             }
       
  4804                         }
       
  4805                     }
       
  4806                 else
       
  4807                     {
       
  4808                     KeyLock().EnableAutoLockEmulation();
       
  4809                     }
       
  4810                 }
       
  4811             if ( iShowkeypadActivatedNoteAfterSoftReject )
       
  4812                 {
       
  4813                 ShowUiNoteL( EKeypadActiveNote );
       
  4814                 iShowkeypadActivatedNoteAfterSoftReject = EFalse;
       
  4815                 }
       
  4816             iCallActivated = EFalse;
       
  4817             break;
       
  4818             }
       
  4819             
       
  4820         default:
       
  4821             break;
       
  4822         }
       
  4823 
       
  4824     if ( aCurrentCallState != EPSCTsyCallStateRinging )
       
  4825         {
       
  4826         iSysApLightsController->CallComingInL( EFalse );
       
  4827         }
       
  4828 
       
  4829     SetIhfIndicatorL();
       
  4830     SetHacIndicatorL();
       
  4831     }
       
  4832 
       
  4833 // ----------------------------------------------------------------------------
       
  4834 // CSysApAppUi::DoSwStateNormalConstructionL()
       
  4835 // ----------------------------------------------------------------------------
       
  4836 
       
  4837 void CSysApAppUi::DoSwStateNormalConstructionL()
       
  4838     {
       
  4839     // Let's ensure that the lights will remain on for 15 secs after sw state normal
       
  4840     User::ResetInactivityTime();
       
  4841 
       
  4842     TRACES( RDebug::Print( _L("CSysApAppUi::DoSwStateNormalConstructionL : START" ) ) );
       
  4843 
       
  4844     // In case of unexpected reset (e.g. hidden boot) the keylock must be enabled silently. Locking is done
       
  4845     // prior to time-consuming initializations, because otherwise UI is in unlocked state for a few seconds.
       
  4846     if ( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApKeyguardActive ) == 1  )
       
  4847         {
       
  4848         TRACES( RDebug::Print( _L("CSysApAppUi::DoSwStateNormalConstructionL: enabling keylock") ) );
       
  4849         KeyLock().EnableWithoutNote();
       
  4850         }
       
  4851 
       
  4852     // Initiate bearer change observation
       
  4853     iSysApConnectionMonitorObserver = CSysApConnectionMonitorObserver::NewL( *this );
       
  4854 
       
  4855     TRACES( RDebug::Print( _L("CSysApAppUi::DoSwStateNormalConstructionL: trying CSysApSsSettingsObserver::NewL()") ) );
       
  4856     iSysApSsSettingsObserver = CSysApSsSettingsObserver::NewL( *this );
       
  4857 
       
  4858     TRACES( RDebug::Print( _L("CSysApAppUi::DoSwStateNormalConstructionL: trying new ( ELeave ) CSysApPowerKeyMenuObserver") ) );
       
  4859     iSysApPowerKeyMenuObserver = new( ELeave ) CSysApPowerKeyMenuObserver( *this );
       
  4860 
       
  4861     TRACES( RDebug::Print( _L("SysAp: trying CSystemLock::NewL" ) ) );
       
  4862     iSysApSystemLock = CSystemLock::NewL();
       
  4863 
       
  4864     iSysApCenRepCallForwardingObserver = CSysApCenRepCallForwardingObserver::NewL( *this );
       
  4865 
       
  4866     iSysApCenRepMsgWaitingObserver = CSysApCenRepMsgWaitingObserver::NewL( *this );
       
  4867 
       
  4868     
       
  4869     if ( iSysApFeatureManager->Supported( KSysApFeatureIdBatteryInfoPopup ) )
       
  4870         {
       
  4871         iSysApBatteryInfoController = CSysApBatteryInfoController::NewL( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsConf, 
       
  4872                                                                                                      KCoreAppUIsBatteryInformationLowThreshold ) );    
       
  4873         }
       
  4874     
       
  4875 
       
  4876     TRACES( RDebug::Print( _L("CSysApAppUi::DoSwStateNormalConstructionL : END" ) ) );
       
  4877     }
       
  4878 
       
  4879 // ----------------------------------------------------------------------------
       
  4880 // CSysApAppUi::DoSimChangedFromPreviousBootL()
       
  4881 // ----------------------------------------------------------------------------
       
  4882 
       
  4883 void CSysApAppUi::DoSimChangedFromPreviousBootL()
       
  4884     {
       
  4885     TRACES( RDebug::Print( _L("CSysApAppUi::DoSimChangedFromPreviousBootL: iSimChangedDone=%d" ), iSimChangedDone ) );
       
  4886 
       
  4887     if ( !iSimChangedDone  )
       
  4888         {
       
  4889         iSimChangedDone = ETrue;
       
  4890         CSysApSimChanged* simChanged = CSysApSimChanged::NewL( *this, iEikonEnv->FsSession() );
       
  4891         CleanupStack::PushL( simChanged );
       
  4892         simChanged->HandleSimChangedL();
       
  4893         CleanupStack::PopAndDestroy( simChanged );
       
  4894         }
       
  4895     }
       
  4896 
       
  4897 // ----------------------------------------------------------------------------
       
  4898 // CSysApAppUi::CancelWaitNote()
       
  4899 // ----------------------------------------------------------------------------
       
  4900 
       
  4901 void CSysApAppUi::CancelWaitNote()
       
  4902     {
       
  4903     TRACES( RDebug::Print( _L("CSysApAppUi::CancelWaitNote" ) ) );
       
  4904     if ( iSysApWaitNote )
       
  4905         {
       
  4906         iSysApWaitNote->Cancel();
       
  4907         delete iSysApWaitNote;
       
  4908         iSysApWaitNote = NULL;
       
  4909         }
       
  4910     }
       
  4911 
       
  4912 // ----------------------------------------------------------------------------
       
  4913 // CSysApAppUi::CancelGlobalListQuery()
       
  4914 // ----------------------------------------------------------------------------
       
  4915 
       
  4916 void CSysApAppUi::CancelGlobalListQuery()
       
  4917     {
       
  4918     TRACES( RDebug::Print( _L("CSysApAppUi::CancelGlobalListQuery" ) ) );
       
  4919     if ( iGlobalListQuery )
       
  4920         {
       
  4921         iGlobalListQuery->CancelListQuery();
       
  4922         delete iGlobalListQuery;
       
  4923         iGlobalListQuery = NULL;
       
  4924         }
       
  4925     }
       
  4926 
       
  4927 #ifndef RD_MULTIPLE_DRIVE
       
  4928 // ----------------------------------------------------------------------------
       
  4929 // CSysApAppUi::MountMMC()
       
  4930 // ----------------------------------------------------------------------------
       
  4931 
       
  4932 TInt CSysApAppUi::MountMMC()
       
  4933     {
       
  4934     TRACES( RDebug::Print( _L("CSysApAppUi::MountMMC") ) );
       
  4935     TInt err ( KErrNotSupported );
       
  4936     if ( iSysApFeatureManager->MmcSupported() )
       
  4937         {
       
  4938 #ifdef __WINS__ // Let's sleep a second in WINS
       
  4939         User::After( 1000000 );
       
  4940 #endif
       
  4941         err = iEikonEnv->FsSession().MountFileSystem( KFSName, KMMCDrive );
       
  4942         TRACES( RDebug::Print( _L("CSysApAppUi::MountMMC: RFs::MountFileSystem() returned: %d"), err ) );
       
  4943         if ( err == KErrInUse )
       
  4944             {
       
  4945             User::After( 1000000 );
       
  4946             err = iEikonEnv->FsSession().MountFileSystem( KFSName, KMMCDrive );
       
  4947             TRACES( RDebug::Print( _L("CSysApAppUi::MountMMC: RFs::MountFileSystem() returned: %d"), err ) );
       
  4948             }
       
  4949         }
       
  4950     return err;
       
  4951     }
       
  4952 
       
  4953 // ----------------------------------------------------------------------------
       
  4954 // CSysApAppUi::DismountMMC()
       
  4955 // ----------------------------------------------------------------------------
       
  4956 
       
  4957 TInt CSysApAppUi::DismountMMC()
       
  4958     {
       
  4959     TRACES( RDebug::Print( _L("CSysApAppUi::DismountMMC") ) );
       
  4960 #ifdef __WINS__ // Let's sleep a second in WINS
       
  4961         User::After( 1000000 );
       
  4962 #endif
       
  4963 
       
  4964     TInt err ( KErrNotSupported );
       
  4965     if ( iSysApFeatureManager->MmcSupported() )
       
  4966         {
       
  4967         err = iEikonEnv->FsSession().DismountFileSystem( KFSName, KMMCDrive );
       
  4968         TRACES( RDebug::Print( _L("CSysApAppUi::DismountMMC: RFs::DismountFileSystem() returned: %d"), err ) );
       
  4969         }
       
  4970     return err;
       
  4971     }
       
  4972 
       
  4973 // ----------------------------------------------------------------------------
       
  4974 // CSysApAppUi::EjectMMCL()
       
  4975 // ----------------------------------------------------------------------------
       
  4976 
       
  4977 void CSysApAppUi::EjectMMCL()
       
  4978     {
       
  4979     TRACES( RDebug::Print( _L("CSysApAppUi::EjectMMCL") ) );
       
  4980     iMMCEjectUsed = ETrue;
       
  4981     iMMCPowerMenuEjectUsed = ETrue;
       
  4982     iTimeToKill = EFalse;
       
  4983     iApplicationScanningRoundNumber = 0;
       
  4984     CloseUIAppsInHotSwapL();
       
  4985     }
       
  4986 
       
  4987 #else // RD_MULTIPLE_DRIVE
       
  4988 
       
  4989 // ----------------------------------------------------------------------------
       
  4990 // CSysApAppUi::EjectMMCL()
       
  4991 // ----------------------------------------------------------------------------
       
  4992 
       
  4993 void CSysApAppUi::EjectMMCL()
       
  4994     {
       
  4995     // Called from eject confirm query, check drive inserted before start
       
  4996     TInt insertedIndex( CSysApDriveList::Find(
       
  4997         iInsertedMemoryCards, iDriveToEject ) );
       
  4998 
       
  4999     TRACES( RDebug::Print(
       
  5000         _L( "CSysApAppUi::EjectMMCL: iMMCEjectUsed: %d, drive: %d, index: %d "),
       
  5001         iMMCEjectUsed, iDriveToEject, insertedIndex ) );
       
  5002 
       
  5003     if ( insertedIndex != KErrNotFound )
       
  5004         {
       
  5005         iSysApDriveList->MarkDriveToEject(
       
  5006             iDriveToEject, CSysApDriveList::EEjectFromMenu );
       
  5007         iSysApDriveEjectHandler->StartEject();
       
  5008         }
       
  5009     iMMCEjectUsed = EFalse;
       
  5010     }
       
  5011 
       
  5012 #endif // RD_MULTIPLE_DRIVE
       
  5013 
       
  5014 // ----------------------------------------------------------------------------
       
  5015 // CSysApAppUi::DisconnectBtSap()
       
  5016 // ----------------------------------------------------------------------------
       
  5017 
       
  5018 void CSysApAppUi::DisconnectBtSap()
       
  5019     {
       
  5020     TRACES( RDebug::Print( _L("CSysApAppUi::DisconnectBtSap") ) );
       
  5021     iSysApBtSapController->Disconnect();
       
  5022     }
       
  5023 
       
  5024 #ifndef RD_MULTIPLE_DRIVE
       
  5025 // ----------------------------------------------------------------------------
       
  5026 // CSysApAppUi::RunUnlockNotifierL()
       
  5027 // ----------------------------------------------------------------------------
       
  5028 
       
  5029 void CSysApAppUi::RunUnlockNotifierL( TSysApMemoryCardStatus aMemoryCardStatus )
       
  5030     {
       
  5031     TRACES( RDebug::Print( _L("CSysApAppUi::RunUnlockNotifierL: START") ) );
       
  5032     if ( iSysApFeatureManager->MmcSupported() )
       
  5033         {
       
  5034         if ( UiReady() )
       
  5035             {
       
  5036             TSysApMemoryCardStatus memoryCardStatus;
       
  5037             if ( aMemoryCardStatus == ESysApMemoryCardStatusNotKnown )
       
  5038                 {
       
  5039                 memoryCardStatus = iSysApMMCObserver->MemoryCardStatus();
       
  5040                 }
       
  5041             else
       
  5042                 {
       
  5043                 memoryCardStatus = aMemoryCardStatus;
       
  5044                 }
       
  5045 
       
  5046             TRACES( RDebug::Print( _L("CSysApAppUi::RunUnlockNotifierL: memoryCardStatus=%d"), memoryCardStatus ) );
       
  5047 
       
  5048             switch ( memoryCardStatus )
       
  5049                 {
       
  5050                 case ESysApMemoryCardInserted:
       
  5051                     TRACES( RDebug::Print( _L("CSysApAppUi::RunUnlockNotifierL MMC inserted") ) );
       
  5052                     if ( aMemoryCardStatus == ESysApMemoryCardInserted )
       
  5053                         {
       
  5054                         RProperty::Set( KPSUidUikon, KUikMMCInserted, 1 );
       
  5055                         }
       
  5056                     break;
       
  5057                 case ESysApMemoryCardLocked:
       
  5058                     {
       
  5059                     TRACES( RDebug::Print( _L("CSysApAppUi::RunUnlockNotifierL MMC locked") ) );
       
  5060                     RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
       
  5061                     TInt callState = StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState );
       
  5062 
       
  5063                     if (  (! ( iDeviceLockEnabled || iKeyLockEnabled ) ) &&
       
  5064                           callState != EPSCTsyCallStateRinging && // We don't want to see the MMC passwd query
       
  5065                           callState != EPSCTsyCallStateAlerting ) // when the user is e.g. making an emergency call
       
  5066                         {
       
  5067                         if ( iSysApFeatureManager->MemoryCardLockSupported() )
       
  5068                             {
       
  5069                             if ( ! iMemoryCardDialog )
       
  5070                                 {
       
  5071                                 TRACES( RDebug::Print( _L("CSysApAppUi::RunUnlockNotifierL: ACTIVATE MMC passwd query") ) );
       
  5072                                 CAknMemoryCardDialog* mmcDialog = CAknMemoryCardDialog::NewLC( this );
       
  5073                                 iMemoryCardDialog = mmcDialog; // temporary variable used for hiding codescanner error 
       
  5074                                 iMemoryCardDialog->SetSelfPointer( &iMemoryCardDialog );
       
  5075                                 iMemoryCardDialog->UnlockCardLD(); // when UnlockCardLD completes it calls UnlockComplete()
       
  5076                                 }
       
  5077                             }
       
  5078                         else
       
  5079                             {
       
  5080                             // Since locked cards are not supported, notify user that card is locked.
       
  5081                             ShowQueryL( ESysApMemoryCardLockedNote );
       
  5082                             }
       
  5083                         }
       
  5084                     }
       
  5085                     break;
       
  5086 
       
  5087                 case ESysApMemoryCardNotInserted:
       
  5088                 default:
       
  5089                     TRACES( RDebug::Print( _L("CSysApAppUi::RunUnlockNotifierL MMC not inserted") ) );
       
  5090                     if ( aMemoryCardStatus == ESysApMemoryCardNotInserted )
       
  5091                         {
       
  5092                         RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
       
  5093                         }
       
  5094                 }
       
  5095             }
       
  5096         }
       
  5097     TRACES( RDebug::Print( _L("CSysApAppUi::RunUnlockNotifierL: END") ) );
       
  5098     }
       
  5099 
       
  5100 // ----------------------------------------------------------------------------
       
  5101 // CSysApAppUi::UnlockComplete() from MAknMemoryCardDialogObserver
       
  5102 // ----------------------------------------------------------------------------
       
  5103 
       
  5104 void CSysApAppUi::UnlockComplete( TInt aResult )
       
  5105     {
       
  5106     TRACES( RDebug::Print( _L("CSysApAppUi::UnlockComplete result: %d"), aResult ) );
       
  5107     if ( aResult == KErrNone )
       
  5108         {
       
  5109         RProperty::Set( KPSUidUikon, KUikMMCInserted, 1 );
       
  5110         }
       
  5111     }
       
  5112 
       
  5113 // ----------------------------------------------------------------------------
       
  5114 // CSysApAppUi::MMCStatusChangedL() from MSysApMemoryCardObserver
       
  5115 // ----------------------------------------------------------------------------
       
  5116 
       
  5117 void CSysApAppUi::MMCStatusChangedL()
       
  5118     {
       
  5119     TRACES( RDebug::Print( _L( "CSysApAppUi::MMCStatusChangedL START: iMMCInserted: %d, iMMCEjectUsed: %d, iHideFirstBeep: %d, iHideNextBeep: %d" ), iMMCInserted, iMMCEjectUsed, iHideFirstBeep, iHideNextBeep ) );
       
  5120 
       
  5121     if ( iSysApFeatureManager->MmcSupported() && !iShutdownStarted )
       
  5122         {
       
  5123         TSysApMemoryCardStatus memoryCardStatus = iSysApMMCObserver->MemoryCardStatus();
       
  5124         TRACES( RDebug::Print( _L( "CSysApAppUi::MMCStatusChangedL memoryCardStatus=%d" ), memoryCardStatus ) );
       
  5125 
       
  5126         switch ( memoryCardStatus )
       
  5127             {
       
  5128             case ESysApMemoryCardInserted:
       
  5129             case ESysApMemoryCardLocked:
       
  5130                 TRACES( RDebug::Print( _L( "CSysApAppUi::MMCStatusChangedL: MMC drive mounted" ) ) );
       
  5131                 if ( ! iMMCInserted ) // MMC was not inserted before
       
  5132                     {
       
  5133                     TRACES( RDebug::Print( _L( "CSysApAppUi::MMCStatusChangedL: MMC newly inserted" ) ) );
       
  5134                     CancelWaitNote(); // just to be sure, the user might keep on closing and opening the MMC latch
       
  5135                     // An MMC has been newly inserted, so play a sound and check if its password protected
       
  5136 
       
  5137                     if ( UiReady() )
       
  5138                         {
       
  5139                         if ( !iHideFirstBeep && !iHideNextBeep ) // starting up
       
  5140                             {
       
  5141                             Beep();
       
  5142                             // Switch lights on
       
  5143                             iSysApLightsController->MemoryCardInsertedL();
       
  5144                             }
       
  5145                         iHideNextBeep = EFalse;
       
  5146                         }
       
  5147 
       
  5148                     iMMCPowerMenuEjectUsed = EFalse;
       
  5149                     iMMCEjectUsed = EFalse;
       
  5150                     iMMCInserted = ETrue;
       
  5151 
       
  5152                     // No need to show ESysApRemoveMmcNote after MMC already mounted
       
  5153                     if ( iSysApConfirmationQuery )
       
  5154                         {
       
  5155                         if ( iSysApConfirmationQuery->CurrentQuery() == ESysApRemoveMmcNote )
       
  5156                             {
       
  5157                             iSysApConfirmationQuery->Cancel();
       
  5158                             }
       
  5159                         }
       
  5160 
       
  5161                     // Check if the MMC is locked and unlock it if necessary
       
  5162                     RunUnlockNotifierL( memoryCardStatus );
       
  5163                     }
       
  5164                 break;
       
  5165             default:
       
  5166                 TRACES( RDebug::Print( _L( "CSysApAppUi::MMCStatusChangedL: MMC drive not mounted" ) ) );
       
  5167                 delete iMemoryCardDialog; // sets itself to null
       
  5168                 RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
       
  5169                 if ( iMMCInserted )
       
  5170                     {
       
  5171                     // No need to show ESysApEjectMmcQuery after MMC already removed
       
  5172                     if ( iSysApConfirmationQuery )
       
  5173                         {
       
  5174                         if ( iSysApConfirmationQuery->CurrentQuery() == ESysApEjectMmcQuery )
       
  5175                             {
       
  5176                             iSysApConfirmationQuery->Cancel();
       
  5177                             }
       
  5178                         }
       
  5179 
       
  5180                     iMMCInserted = EFalse;
       
  5181 
       
  5182                     TInt propertyValue( StateOfProperty( KPSUidUsbWatcher, KUsbWatcherSelectedPersonality ) );
       
  5183                     if ( !iMMCEjectUsed && propertyValue != KUsbPersonalityIdMS )
       
  5184                         {
       
  5185                         // if USB file transfer active, do not close applications
       
  5186                         // if eject selected in MMC App, MMC App takes care of the following and
       
  5187                         // if eject selected from powerkeymenu, applications have already been shutdown
       
  5188                         iTimeToKill = EFalse;
       
  5189                         iApplicationScanningRoundNumber = 0;
       
  5190                         CloseUIAppsInHotSwapL();
       
  5191                         }
       
  5192                     }
       
  5193                 else
       
  5194                     {
       
  5195                     // If MMC was not previously inserted and eject was chosed from power key menu, attempt to remount.
       
  5196                     if ( iMMCPowerMenuEjectUsed )
       
  5197                         {
       
  5198                         TRACES( RDebug::Print( _L( "CSysApAppUi::MMCStatusChangedL: Attempt to remount" ) ) );
       
  5199                         MountMMC();
       
  5200                         // If mount was successful, unnecessary note will be canceled in insert notification handling.
       
  5201                         }
       
  5202                     }
       
  5203                 break;
       
  5204             }
       
  5205 
       
  5206         // Update memory card indicator status
       
  5207         SetMemoryCardIndicatorL();
       
  5208         }
       
  5209     TRACES( RDebug::Print( _L( "CSysApAppUi::MMCStatusChangedL   END: iMMCInserted: %d, iMMCEjectUsed: %d, iHideFirstBeep: %d, iHideNextBeep: %d" ), iMMCInserted, iMMCEjectUsed, iHideFirstBeep, iHideNextBeep ) );
       
  5210     }
       
  5211 
       
  5212 // ----------------------------------------------------------------------------
       
  5213 // CSysApAppUi::ShowMMCDismountedDialogL()
       
  5214 // ----------------------------------------------------------------------------
       
  5215 
       
  5216 void CSysApAppUi::ShowMMCDismountedDialogL()
       
  5217     {
       
  5218     TInt propertyValue( StateOfProperty( KPSUidUsbWatcher, KUsbWatcherSelectedPersonality ) );
       
  5219 
       
  5220     // Do not show any note if USB file transfer is active.
       
  5221     if ( propertyValue != KUsbPersonalityIdMS )
       
  5222         {
       
  5223         if ( iSysApFeatureManager->MemoryCardHatchSupported() )
       
  5224             { // MMC hatch has been opened and MMC has been dismounted
       
  5225             TRACES( RDebug::Print( _L( "CSysApAppUi::ShowMMCDismountedDialogL: Show note: Remove MMC and press OK." ) ) );
       
  5226             ShowQueryL( ESysApRemoveMmcNote );
       
  5227             }
       
  5228         else
       
  5229             {
       
  5230             // MMC has been removed and dismounted
       
  5231             TRACES( RDebug::Print( _L( "CSysApAppUi::ShowMMCDismountedDialogL: Show note: You might have lost some data." ) ) );
       
  5232             // No confirmation but let's set this true to enable MMC passwd query
       
  5233             ShowUiNoteL( EMemoryCardRemovedWithoutEjectNote );
       
  5234             }
       
  5235         }
       
  5236     else
       
  5237         {
       
  5238         TRACES( RDebug::Print( _L( "CSysApAppUi::ShowMMCDismountedDialogL: No note shown, USB file transfer caused dismount." ) ) );
       
  5239         }
       
  5240     }
       
  5241 
       
  5242 // ----------------------------------------------------------------------------
       
  5243 // CSysApAppUi::MMCDismountedDialogConfirmed
       
  5244 // ----------------------------------------------------------------------------
       
  5245 
       
  5246 void CSysApAppUi::MMCDismountedDialogConfirmed()
       
  5247     {
       
  5248     TRACES( RDebug::Print( _L( "CSysApAppUi::MMCDismountedDialogConfirmed") ) );
       
  5249 
       
  5250     // Try to remount just in case when eject was chosen from power key menu
       
  5251     if ( iMMCPowerMenuEjectUsed )
       
  5252         {
       
  5253         iMMCPowerMenuEjectUsed = EFalse;
       
  5254 
       
  5255         if ( MountMMC() == KErrLocked ) // In case a locked card was not removed after all
       
  5256             {
       
  5257             TRAPD( err, MMCStatusChangedL() ); // This will update power menu and memory card icon. Also memory card password is requeried.
       
  5258             if ( err != KErrNone )
       
  5259                 {
       
  5260                 TRACES( RDebug::Print( _L( "CSysApAppUi::MMCDismountedDialogConfirmed: MMCStatusChangedL failed, err=%d"), err ) );
       
  5261                 }
       
  5262             }
       
  5263         }
       
  5264 
       
  5265     }
       
  5266 
       
  5267 #else // RD_MULTIPLE_DRIVE
       
  5268 
       
  5269 // ----------------------------------------------------------------------------
       
  5270 // CSysApAppUi::MMCInsertedL
       
  5271 // ----------------------------------------------------------------------------
       
  5272 
       
  5273 void CSysApAppUi::MMCInsertedL()
       
  5274     {
       
  5275     TRACES( RDebug::Print( _L( "CSysApAppUi::MMCInsertedL") ) );
       
  5276 
       
  5277     if ( iSysApFeatureManager->MmcSupported() && !iShutdownStarted )
       
  5278 		{
       
  5279 		TBool normalState( UiReady() );
       
  5280 
       
  5281 		if ( normalState )
       
  5282 			{
       
  5283 			TInt defaultMemoryCard( iSysApDriveList->DefaultMemoryCard() );
       
  5284 			TSysApMemoryCardStatus memoryCardStatus( iSysApDriveList->MemoryCardStatus( defaultMemoryCard ) );
       
  5285 
       
  5286 			TRACES( RDebug::Print(
       
  5287 				_L( "CSysApAppUi::MMCInsertedL: drive: %d, memoryCardStatus: %d" ), defaultMemoryCard, memoryCardStatus ) );
       
  5288 
       
  5289 			switch ( memoryCardStatus )
       
  5290 				{
       
  5291 				case ESysApMemoryCardInserted: // Fall through
       
  5292 				case ESysApMemoryCardLocked:
       
  5293 					{
       
  5294 					// Reset eject and unlock of inserted memory card
       
  5295 					iSysApDriveList->ResetDriveToEject( defaultMemoryCard );
       
  5296 					iSysApDriveList->ResetDriveUnlockQueryShown( defaultMemoryCard );
       
  5297 
       
  5298 					CancelWaitNote();
       
  5299 
       
  5300 					if ( memoryCardStatus == ESysApMemoryCardInserted )
       
  5301 						{
       
  5302 						TRACES( RDebug::Print(
       
  5303 							_L( "CSysApAppUi::MMCInsertedL: memoryCardStatus ESysApMemoryCardInserted: %d" ), memoryCardStatus ) );
       
  5304 						RProperty::Set( KPSUidUikon, KUikMMCInserted, 1 );
       
  5305 						}
       
  5306 					else
       
  5307 						{
       
  5308 						TRACES( RDebug::Print(
       
  5309 							_L( "CSysApAppUi::MMCInsertedL: memoryCardStatus ESysApMemoryCardLocked: %d" ), memoryCardStatus ) );
       
  5310 						RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
       
  5311 						}
       
  5312 					break;
       
  5313 					}
       
  5314 				case ESysApMemoryCardNotInserted:
       
  5315 					{
       
  5316 					// Always reset eject and unlock of removed memory card
       
  5317 					TBool isEject( iSysApDriveList->IsDriveToEject( defaultMemoryCard ) );
       
  5318 
       
  5319 					TRACES( RDebug::Print(
       
  5320 						_L( "CSysApAppUi::MMCInsertedL: isEject: %d, drive: %d" ),
       
  5321 						isEject, defaultMemoryCard ) );
       
  5322 
       
  5323 					iSysApDriveList->ResetDriveToEject( defaultMemoryCard );
       
  5324 					iSysApDriveList->ResetDriveUnlockQueryShown( defaultMemoryCard );
       
  5325 
       
  5326 					TRACES( RDebug::Print(
       
  5327 						_L( "SysApAppUi::MMCInsertedL: memoryCardStatus ESysApMemoryCardNotInserted: %d" ), memoryCardStatus ) );
       
  5328 
       
  5329 					RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
       
  5330 					break;
       
  5331 					}
       
  5332 				case ESysApMemoryCardStatusNotKnown: // Fall through
       
  5333 				default:
       
  5334 					{
       
  5335 					break;
       
  5336 					}
       
  5337 				}
       
  5338 				RunUnlockNotifierL();
       
  5339 			}
       
  5340 		}
       
  5341 	}
       
  5342 
       
  5343 
       
  5344 // ----------------------------------------------------------------------------
       
  5345 // CSysApAppUi::RunUnlockNotifierL()
       
  5346 // ----------------------------------------------------------------------------
       
  5347 
       
  5348 void CSysApAppUi::RunUnlockNotifierL()
       
  5349     {
       
  5350     TRACES( RDebug::Print(
       
  5351         _L("CSysApAppUi::RunUnlockNotifierL: START iDeviceLockEnabled: %d, iKeyLockEnabled: %d" ),
       
  5352          iDeviceLockEnabled, iKeyLockEnabled ) );
       
  5353 
       
  5354     if ( !iSysApFeatureManager->MmcSupported() ||
       
  5355          iDeviceLockEnabled ||
       
  5356          iKeyLockEnabled ||
       
  5357          !UiReady() )
       
  5358         {
       
  5359         TRACES( RDebug::Print( _L("CSysApAppUi::RunUnlockNotifierL: END") ) );
       
  5360         return;
       
  5361         }
       
  5362 
       
  5363     // We don't want to see the MMC passwd query
       
  5364     // when the user is e.g. making an emergency call
       
  5365     TInt callState( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
       
  5366     if ( callState != EPSCTsyCallStateRinging &&
       
  5367         callState != EPSCTsyCallStateAlerting )
       
  5368         {
       
  5369         iSysApDriveUnlockHandler->StartUnlock();
       
  5370         }
       
  5371 
       
  5372     TRACES( RDebug::Print(
       
  5373         _L("CSysApAppUi::RunUnlockNotifierL: END callState: %d"), callState ) );
       
  5374     }
       
  5375 
       
  5376 // ----------------------------------------------------------------------------
       
  5377 // CSysApAppUi::MMCStatusChangedL() from MSysApMemoryCardObserver
       
  5378 // ----------------------------------------------------------------------------
       
  5379 
       
  5380 void CSysApAppUi::MMCStatusChangedL( TInt aDrive )
       
  5381     {
       
  5382     TRACES( RDebug::Print(
       
  5383         _L( "CSysApAppUi::MMCStatusChangedL START: MMCCount: %d, iMMCEjectUsed: %d" ),
       
  5384         iInsertedMemoryCards.Count(), iMMCEjectUsed ) );
       
  5385 
       
  5386     if ( iShutdownStarted || !iSysApFeatureManager->MmcSupported() )
       
  5387         {
       
  5388         TRACES( RDebug::Print(
       
  5389             _L( "CSysApAppUi::MMCStatusChangedL iShutdownStarted: %d END" ),
       
  5390             iShutdownStarted ) );
       
  5391         return;
       
  5392         }
       
  5393 
       
  5394     TBool normalState( UiReady() );
       
  5395 
       
  5396     TInt defaultMemoryCard( iSysApDriveList->DefaultMemoryCard() );
       
  5397     TSysApMemoryCardStatus memoryCardStatus( iSysApDriveList->MemoryCardStatus( aDrive ) );
       
  5398     TInt insertedIndex( CSysApDriveList::Find( iInsertedMemoryCards, aDrive ) );
       
  5399 
       
  5400     TRACES( RDebug::Print(
       
  5401         _L( "CSysApAppUi::MMCStatusChangedL: normalState: %d, index: %d, drive: %d, memoryCardStatus: %d" ),
       
  5402         normalState, insertedIndex, aDrive, memoryCardStatus ) );
       
  5403 
       
  5404     switch ( memoryCardStatus )
       
  5405         {
       
  5406         case ESysApMemoryCardInserted: // Fall through
       
  5407         case ESysApMemoryCardLocked:
       
  5408             {
       
  5409             if ( insertedIndex == KErrNotFound ) // Not inserted before
       
  5410                 {
       
  5411                 // Reset eject and unlock of inserted memory card
       
  5412                 iSysApDriveList->ResetDriveToEject( aDrive );
       
  5413                 iSysApDriveList->ResetDriveUnlockQueryShown( aDrive );
       
  5414 
       
  5415                 CancelWaitNote();
       
  5416 
       
  5417                 if ( aDrive == defaultMemoryCard )
       
  5418                     {
       
  5419                     if ( memoryCardStatus == ESysApMemoryCardInserted )
       
  5420                         {
       
  5421                          RProperty::Set( KPSUidUikon, KUikMMCInserted, 1 );
       
  5422                       	}
       
  5423                     else
       
  5424                         {
       
  5425                         RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
       
  5426                         }
       
  5427                     }
       
  5428 
       
  5429                 if ( normalState )
       
  5430                     {
       
  5431                     // Ignore extra beep from USB file transfer
       
  5432                     TBool ignoreBeep(
       
  5433                         iSysApDriveList->IsDriveInsertBeepIgnored( aDrive ) );
       
  5434 
       
  5435                     TRACES( RDebug::Print(
       
  5436                         _L( "CSysApAppUi::MMCStatusChangedL: ignoreBeep: %d, drive: %d" ),
       
  5437                         ignoreBeep, aDrive ) );
       
  5438 
       
  5439                     if ( !ignoreBeep )
       
  5440                         {
       
  5441                         Beep();
       
  5442                         iSysApLightsController->MemoryCardInsertedL();
       
  5443                         }
       
  5444 
       
  5445                     iSysApDriveList->ResetDriveInsertBeepIgnored( aDrive );
       
  5446 
       
  5447                     // Keep ignoring extra beep if USB file transfer is active
       
  5448                     TInt propertyValue( StateOfProperty( KPSUidUsbWatcher, KUsbWatcherSelectedPersonality ) );
       
  5449 
       
  5450                     TRACES( RDebug::Print(
       
  5451                         _L( "CSysApAppUi::MMCStatusChangedL: usbState: %d" ), propertyValue ) );
       
  5452 
       
  5453                     if ( propertyValue == KUsbPersonalityIdMS )
       
  5454                         {
       
  5455                         iSysApDriveList->MarkDriveInsertBeepIgnored( aDrive );
       
  5456                         }
       
  5457                     }
       
  5458 
       
  5459                 if ( iDriveToDismount == aDrive && iSysApConfirmationQuery )
       
  5460                     {
       
  5461                     if ( iSysApConfirmationQuery->CurrentQuery() == ESysApRemoveMmcNote )
       
  5462                         {
       
  5463                         // User put back ejected memory card or did not remove it
       
  5464                         iSysApConfirmationQuery->Cancel();
       
  5465                         }
       
  5466                     }
       
  5467                 RunUnlockNotifierL();
       
  5468                 }
       
  5469             break;
       
  5470             }
       
  5471         case ESysApMemoryCardNotInserted:
       
  5472             {
       
  5473             // Always reset eject and unlock of removed memory card
       
  5474             TBool isEject( iSysApDriveList->IsDriveToEject( aDrive ) );
       
  5475 
       
  5476             TRACES( RDebug::Print(
       
  5477                 _L( "CSysApAppUi::MMCStatusChangedL: isEject: %d, drive: %d" ),
       
  5478                 isEject, aDrive ) );
       
  5479 
       
  5480             iSysApDriveList->ResetDriveToEject( aDrive );
       
  5481             iSysApDriveList->ResetDriveUnlockQueryShown( aDrive );
       
  5482 
       
  5483             if ( insertedIndex != KErrNotFound ) // Inserted before
       
  5484                 {
       
  5485                 if ( memoryCardStatus == ESysApMemoryCardNotInserted )
       
  5486                     {
       
  5487                     // Reset extra beep ignore if memory card was removed without eject
       
  5488                     iSysApDriveList->ResetDriveInsertBeepIgnored( aDrive );
       
  5489                     }
       
  5490 
       
  5491                 CancelGlobalListQuery(); // Cancel power menu
       
  5492 
       
  5493                 if ( aDrive == defaultMemoryCard )
       
  5494                     {
       
  5495                     RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
       
  5496                     }
       
  5497 
       
  5498                 if ( iSysApConfirmationQuery )
       
  5499                     {
       
  5500                     if ( iSysApConfirmationQuery->CurrentQuery() == ESysApEjectMmcQuery )
       
  5501                         {
       
  5502                         // User removed memory card too early
       
  5503                         iSysApConfirmationQuery->Cancel();
       
  5504                         // Allow application closing to execute.
       
  5505                         // Also FileManager is closed in this case, regardless where the eject was initiated from.
       
  5506                         iMMCEjectUsed = EFalse;
       
  5507                         }
       
  5508                     }
       
  5509 
       
  5510                 // Stop unlock of removed memory card
       
  5511                 iSysApDriveUnlockHandler->StopUnlock( aDrive );
       
  5512 
       
  5513                 if ( !iMMCEjectUsed && !isEject )
       
  5514                     {
       
  5515                     TInt propertyValue( StateOfProperty( KPSUidUsbWatcher, KUsbWatcherSelectedPersonality ) );
       
  5516 
       
  5517                     TRACES( RDebug::Print(
       
  5518                         _L( "CSysApAppUi::MMCStatusChangedL: usbState: %d" ), propertyValue ) );
       
  5519 
       
  5520                     if ( propertyValue != KUsbPersonalityIdMS )
       
  5521                         {
       
  5522                         if ( iSysApFeatureManager->MemoryCardHatchSupported() )
       
  5523                             {
       
  5524                             // Store drive removed without eject and start eject handling
       
  5525                             iSysApDriveList->MarkDriveToEject(
       
  5526                                 aDrive, CSysApDriveList::EEjectRemovedWithoutEject );
       
  5527                             iSysApDriveEjectHandler->StartEject();
       
  5528                             }
       
  5529                         else
       
  5530                             {
       
  5531                             // Just show the note
       
  5532                             ShowUiNoteL( EMemoryCardRemovedWithoutEjectNote );
       
  5533                             }
       
  5534                         }
       
  5535                     }
       
  5536                 iMMCEjectUsed = EFalse;
       
  5537                 }
       
  5538             break;
       
  5539             }
       
  5540         case ESysApMemoryCardStatusNotKnown: // Fall through
       
  5541         default:
       
  5542             {
       
  5543             break;
       
  5544             }
       
  5545         }
       
  5546 
       
  5547     // Update inserted memory cards
       
  5548     iSysApDriveList->GetMemoryCardsL(
       
  5549         iInsertedMemoryCards, CSysApDriveList::EIncludeInserted );
       
  5550 
       
  5551     // Update memory card indicator status
       
  5552     SetMemoryCardIndicatorL();
       
  5553 
       
  5554     TRACES( RDebug::Print(
       
  5555         _L( "CSysApAppUi::MMCStatusChangedL END: MMCCount: %d, iMMCEjectUsed: %d" ),
       
  5556         iInsertedMemoryCards.Count(), iMMCEjectUsed ) );
       
  5557     }
       
  5558 
       
  5559 // ----------------------------------------------------------------------------
       
  5560 // CSysApAppUi::ShowMMCDismountedDialogL()
       
  5561 // ----------------------------------------------------------------------------
       
  5562 
       
  5563 TBool CSysApAppUi::ShowMMCDismountedDialogL(
       
  5564         TInt aDrive, CSysApDriveList::TDriveEjectType aEjectType )
       
  5565     {
       
  5566     TRACES( RDebug::Print(
       
  5567         _L( "CSysApAppUi::ShowMMCDismountedDialogL: aDrive: %d, aEjectType: %d" ),
       
  5568         aDrive, aEjectType ) );
       
  5569 
       
  5570     TBool ret( EFalse );
       
  5571     iDriveToDismount = aDrive;
       
  5572     HBufC* driveName = iSysApDriveList->GetFormattedDriveNameLC(
       
  5573         aDrive,
       
  5574         R_QTN_EJECT_REMOVE_MEMORY_INFO );
       
  5575 
       
  5576     if ( aEjectType == CSysApDriveList::EEjectFromMenu )
       
  5577         {
       
  5578         TRACES( RDebug::Print(
       
  5579             _L( "CSysApAppUi::ShowMMCDismountedDialogL: Show note: Remove MMC and press OK...." ) ) );
       
  5580         ShowQueryL( ESysApRemoveMmcNote, *driveName );
       
  5581         ret = ETrue;
       
  5582         }
       
  5583     else
       
  5584         {
       
  5585         // Memory card was removed without eject
       
  5586         TInt propertyValue( StateOfProperty( KPSUidUsbWatcher, KUsbWatcherSelectedPersonality ) );
       
  5587 
       
  5588         // Do not show any note if USB file transfer is active.
       
  5589         if ( propertyValue != KUsbPersonalityIdMS )
       
  5590             {
       
  5591             if ( iSysApFeatureManager->MemoryCardHatchSupported() )
       
  5592                 {
       
  5593                 // MMC hatch has been opened and MMC has been dismounted
       
  5594                 TRACES( RDebug::Print(
       
  5595                     _L( "CSysApAppUi::ShowMMCDismountedDialogL: Show note: Remove MMC and press OK." ) ) );
       
  5596                 ShowQueryL( ESysApRemoveMmcNote, *driveName );
       
  5597                 ret = ETrue;
       
  5598                 }
       
  5599             else
       
  5600                 {
       
  5601                 iSysApDriveList->ResetDrivesToEject();
       
  5602 
       
  5603                 // MMC has been removed and dismounted
       
  5604                 TRACES( RDebug::Print( _L(
       
  5605                     "CSysApAppUi::ShowMMCDismountedDialogL: Show note: You might have lost some data." ) ) );
       
  5606 
       
  5607                 // No confirmation but let's set this true to enable MMC passwd query
       
  5608                 ShowUiNoteL( EMemoryCardRemovedWithoutEjectNote );
       
  5609                 }
       
  5610             }
       
  5611         else
       
  5612             {
       
  5613             iSysApDriveList->ResetDrivesToEject();
       
  5614             TRACES( RDebug::Print(
       
  5615                 _L( "CSysApAppUi::ShowMMCDismountedDialogL: No note shown, USB file transfer caused dismount." ) ) );
       
  5616             }
       
  5617         }
       
  5618 
       
  5619     CleanupStack::PopAndDestroy( driveName );
       
  5620 
       
  5621     TRACES( RDebug::Print(
       
  5622         _L( "CSysApAppUi::ShowMMCDismountedDialogL: ret: %d" ), ret ) );
       
  5623 
       
  5624     return ret;
       
  5625     }
       
  5626 
       
  5627 // ----------------------------------------------------------------------------
       
  5628 // CSysApAppUi::MMCDismountedDialogConfirmed
       
  5629 // ----------------------------------------------------------------------------
       
  5630 
       
  5631 void CSysApAppUi::MMCDismountedDialogConfirmed()
       
  5632     {
       
  5633     TRACES( RDebug::Print(
       
  5634         _L( "CSysApAppUi::MMCDismountedDialogConfirmed: iDriveToDismount: %d" ),
       
  5635         iDriveToDismount ) );
       
  5636 
       
  5637     // Try remount to check if drive was put back
       
  5638     iSysApDriveList->MountDrive( iDriveToDismount );
       
  5639     if ( !iSysApDriveEjectHandler->CompleteDismount( iDriveToDismount ) )
       
  5640         {
       
  5641         // When ready, check for locked memory cards and update indicators
       
  5642         TRAP_IGNORE( SetMemoryCardIndicatorL() );
       
  5643         TRAP_IGNORE( RunUnlockNotifierL() );
       
  5644         }
       
  5645     }
       
  5646 
       
  5647 #endif // RD_MULTIPLE_DRIVE
       
  5648 
       
  5649 // ----------------------------------------------------------------------------
       
  5650 // CSysApAppUi::EjectStarted()
       
  5651 // ----------------------------------------------------------------------------
       
  5652 
       
  5653 void CSysApAppUi::EjectStarted( TBool ejectStarted )
       
  5654     {
       
  5655     TRACES( RDebug::Print( _L( "CSysApAppUi::EjectStarted" ) ) );
       
  5656     iMMCEjectUsed = ejectStarted;
       
  5657     
       
  5658 #ifndef RD_MULTIPLE_DRIVE
       
  5659     iFileManagerCloseDisabled = ejectStarted;
       
  5660 #endif // RD_MULTIPLE_DRIVE
       
  5661 }
       
  5662 
       
  5663 // ----------------------------------------------------------------------------
       
  5664 // CSysApAppUi::DoLightsTimeoutChangedL
       
  5665 // ----------------------------------------------------------------------------
       
  5666 void CSysApAppUi::DoLightsTimeoutChangedL( const TInt aTimeout )
       
  5667     {
       
  5668     iSysApLightsController->DoLightsTimeoutChangedL( aTimeout );
       
  5669     }
       
  5670 
       
  5671 #ifdef __SYSAP_MODULE_TEST
       
  5672 
       
  5673 // ----------------------------------------------------------------------------
       
  5674 // CSysApAppUi::ModuleTestShowUiNoteL()
       
  5675 // ----------------------------------------------------------------------------
       
  5676 
       
  5677 void CSysApAppUi::ModuleTestShowUiNoteL( const TDesC& noteText ) const
       
  5678     {
       
  5679     CAknGlobalNote* note = CAknGlobalNote::NewLC();
       
  5680     note->SetTone( EAvkonSIDNoSound );
       
  5681     note->ShowNoteL( EAknGlobalInformationNote, noteText );
       
  5682     CleanupStack::PopAndDestroy(); // note
       
  5683     }
       
  5684 
       
  5685 #endif
       
  5686 
       
  5687 // ----------------------------------------------------------------------------
       
  5688 // CSysApAppUi::ShowShutdownNoteL()
       
  5689 // ----------------------------------------------------------------------------
       
  5690 void CSysApAppUi::ShowShutdownNoteL()
       
  5691     {
       
  5692     TRACES( RDebug::Print( _L( "CSysApAppUi::ShowShutdownNoteL") ) );
       
  5693     ShowUiNoteL( EShutdownNote );
       
  5694     User::After( KTimeToShowShutdownNote );
       
  5695     }
       
  5696 
       
  5697 // ----------------------------------------------------------------------------
       
  5698 // CSysApAppUi::Beep()
       
  5699 // ----------------------------------------------------------------------------
       
  5700 void CSysApAppUi::Beep()
       
  5701     {
       
  5702     static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds()->PlaySound( EAvkonSIDInformationTone );
       
  5703     }
       
  5704 
       
  5705 // ----------------------------------------------------------------------------
       
  5706 // CSysApAppUi::SimSupported()
       
  5707 // ----------------------------------------------------------------------------
       
  5708 TBool CSysApAppUi::SimSupported()
       
  5709     {
       
  5710     return iSysApFeatureManager->SimSupported();
       
  5711     }
       
  5712 
       
  5713 // ----------------------------------------------------------------------------
       
  5714 // CSysApAppUi::IsStateNormal()
       
  5715 //
       
  5716 // ----------------------------------------------------------------------------
       
  5717 TBool CSysApAppUi::IsStateNormal() const
       
  5718     {
       
  5719     TInt state;
       
  5720     TInt errorCode =
       
  5721         RProperty::Get( KPSUidStartup, KPSGlobalSystemState, state );
       
  5722     if ( errorCode == KErrNone )
       
  5723         {
       
  5724         return state == ESwStateNormalRfOn ||
       
  5725                state == ESwStateNormalRfOff ||
       
  5726                state == ESwStateNormalBTSap;
       
  5727         }
       
  5728     else
       
  5729         {
       
  5730         TRACES( RDebug::Print( _L( "CSysApAppUi::IsStateNormal: Failed to read global system state, error code %d." ), errorCode ) );
       
  5731         return EFalse;
       
  5732         }
       
  5733     }
       
  5734 
       
  5735 // ----------------------------------------------------------------------------
       
  5736 // CSysApAppUi::BatteryEmptyL()
       
  5737 // ----------------------------------------------------------------------------
       
  5738 
       
  5739 void CSysApAppUi::BatteryEmptyL()
       
  5740     {
       
  5741     iSysApLightsController->BatteryEmptyL( ETrue );
       
  5742     // Do not reactivate keyguard in the next startup
       
  5743     iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApKeyguardActive, 0 );
       
  5744     }
       
  5745 
       
  5746 // ----------------------------------------------------------------------------
       
  5747 // CSysApAppUi::Max()
       
  5748 // ----------------------------------------------------------------------------
       
  5749 
       
  5750 TInt CSysApAppUi::Max( const TInt aA, const TInt aB, const TInt aC )
       
  5751      {
       
  5752      TInt max( aA );
       
  5753      if ( aB > max )
       
  5754          {
       
  5755          max = aB;
       
  5756          }
       
  5757      if ( aC > max )
       
  5758          {
       
  5759          max = aC;
       
  5760          }
       
  5761      return max;
       
  5762      }
       
  5763 
       
  5764 // ----------------------------------------------------------------------------
       
  5765 // CSysApAppUi::SetStarterState()
       
  5766 // ----------------------------------------------------------------------------
       
  5767 
       
  5768 TInt CSysApAppUi::SetStarterState( const RStarterSession::TGlobalState aState )
       
  5769     {
       
  5770     if ( iSysApStartupController->GlobalStateChangeAllowed( aState ) )
       
  5771         {
       
  5772         TRACES( RDebug::Print( _L("CSysApAppUi::SetStarterState: aState=%d" ), aState ) );
       
  5773         return StarterSession().SetState( aState );
       
  5774         }
       
  5775     else
       
  5776         {
       
  5777         TRACES( RDebug::Print( _L("CSysApAppUi::SetStarterState: aState=%d - not allowed" ), aState ) );
       
  5778         return KErrNone;
       
  5779         }
       
  5780     }
       
  5781 
       
  5782 // ----------------------------------------------------------------------------
       
  5783 // CSysApAppUi::GetBtSapDeviceNameL()
       
  5784 // ----------------------------------------------------------------------------
       
  5785 
       
  5786 HBufC* CSysApAppUi::GetBtSapDeviceNameL()
       
  5787     {
       
  5788     return iSysApBtSapController->GetBtSapDeviceNameL();
       
  5789     }
       
  5790 
       
  5791 // ----------------------------------------------------------------------------
       
  5792 // CSysApAppUi::ShowAlarmIndicatorL()
       
  5793 // ----------------------------------------------------------------------------
       
  5794 
       
  5795 void CSysApAppUi::ShowAlarmIndicatorL( TBool aShowIndicator )
       
  5796     {
       
  5797     if ( aShowIndicator)
       
  5798         {
       
  5799         SetIndicatorStateL( EAknIndicatorAlarmClock, EAknIndicatorStateOn );
       
  5800         }
       
  5801     else
       
  5802         {
       
  5803         SetIndicatorStateL( EAknIndicatorAlarmClock, EAknIndicatorStateOff );
       
  5804         }
       
  5805     }
       
  5806 
       
  5807 // ----------------------------------------------------------------------------
       
  5808 // CSysApAppUi::SimulateFlipKeyEventL()
       
  5809 // ----------------------------------------------------------------------------
       
  5810 
       
  5811 void CSysApAppUi::SimulateFlipKeyEventL( TBool aFlipOpen )
       
  5812     {
       
  5813     TRACES( RDebug::Print( _L("CSysApAppUi::SimulateFlipKeyEventL: aFlipOpen: %d" ), aFlipOpen ) );
       
  5814 
       
  5815     /*
       
  5816        Flip key is constructed when a flip notification via Pub&Sub is received. The reason behind
       
  5817        providing this as a key event is to enable unified handling of keys also with flip, and because
       
  5818        flip is captured&consumed by Avkon it is not possible to capture flip key events directly
       
  5819        from default handler/plugins.
       
  5820     */
       
  5821 
       
  5822     TKeyEvent flipEvent;
       
  5823     flipEvent.iCode = aFlipOpen ? EKeyFlipOpen : EKeyFlipClose;
       
  5824     flipEvent.iScanCode = 0;
       
  5825     flipEvent.iModifiers = 0;
       
  5826 	flipEvent.iRepeats = 0;
       
  5827 
       
  5828     HandleKeyEventL( flipEvent, EEventKey );
       
  5829     }
       
  5830 
       
  5831 // ----------------------------------------------------------------------------
       
  5832 // CSysApAppUi::SetFlipOpenL()
       
  5833 // ----------------------------------------------------------------------------
       
  5834 
       
  5835 void CSysApAppUi::SetFlipOpenL( TBool aFlipOpen )
       
  5836     {
       
  5837     iSysApLightsController->SetFlipOpenL( aFlipOpen );
       
  5838     }
       
  5839 
       
  5840 // ----------------------------------------------------------------------------
       
  5841 // CSysApAppUi::SetGripOpenL()
       
  5842 // ----------------------------------------------------------------------------
       
  5843 void CSysApAppUi::SetGripOpenL( TBool aGripOpen )
       
  5844     {
       
  5845     iSysApLightsController->SetGripOpenL( aGripOpen );
       
  5846     }
       
  5847 
       
  5848 // ----------------------------------------------------------------------------
       
  5849 // CSysApAppUi::SetNetworkConnectionAllowed()
       
  5850 // ----------------------------------------------------------------------------
       
  5851 
       
  5852 void CSysApAppUi::SetNetworkConnectionAllowed( TCoreAppUIsNetworkConnectionAllowed aNetworkConnectionAllowed )
       
  5853     {
       
  5854     TRACES( RDebug::Print( _L("CSysApAppUi::SetNetworkConnectionAllowed: status: %d" ), aNetworkConnectionAllowed ) );
       
  5855 
       
  5856     iSysApCenRepController->SetInt( KCRUidCoreApplicationUIs, KCoreAppUIsNetworkConnectionAllowed, (TInt) aNetworkConnectionAllowed );
       
  5857 
       
  5858     // Also set the Symbian PS key used for the same purpose:
       
  5859     RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, aNetworkConnectionAllowed ? ESAPhoneOn : ESAPhoneOff);
       
  5860     }
       
  5861 
       
  5862 // ----------------------------------------------------------------------------
       
  5863 // CSysApAppUi::GetTelServerL()
       
  5864 // ----------------------------------------------------------------------------
       
  5865 
       
  5866 RTelServer* CSysApAppUi::GetTelServer()
       
  5867     {
       
  5868     if ( iSysApEtelConnector )
       
  5869         {
       
  5870         return iSysApEtelConnector->GetTelServer();
       
  5871         }
       
  5872     else
       
  5873         {
       
  5874         return NULL;
       
  5875         }
       
  5876     }
       
  5877 
       
  5878 // ----------------------------------------------------------------------------
       
  5879 // CSysApAppUi::CoverDisplaySupported()
       
  5880 // ----------------------------------------------------------------------------
       
  5881 
       
  5882 TBool CSysApAppUi::CoverDisplaySupported()
       
  5883     {
       
  5884     return iSysApFeatureManager->CoverDisplaySupported();
       
  5885     }
       
  5886 
       
  5887 // ----------------------------------------------------------------------------
       
  5888 // CSysApAppUi::StarterSession()
       
  5889 // ----------------------------------------------------------------------------
       
  5890 
       
  5891 RStarterSession& CSysApAppUi::StarterSession()
       
  5892     {
       
  5893     if ( !iStarterSession.Handle() )
       
  5894         {
       
  5895         // All server connections are tried to be made KTriesToConnectServer times because occasional
       
  5896         // fails on connections are possible at least on some servers
       
  5897         TRACES( RDebug::Print( _L("CSysApAppUi::StarterSession: trying RStarterSession::Connect()") ) );
       
  5898         TInt thisTry = 0;
       
  5899         TInt err;
       
  5900         while ( ( err = iStarterSession.Connect() ) != KErrNone && ( thisTry++ ) <= KTriesToConnectServer )
       
  5901             {
       
  5902             User::After( KTimeBeforeRetryingServerConnection );
       
  5903             }
       
  5904 
       
  5905         if ( err != KErrNone )
       
  5906             {
       
  5907             // What do in error case?
       
  5908             TRACES( RDebug::Print( _L("CSysApAppUi::StarterSession: RStarterSession::Connect() failed with %d"), err ) );
       
  5909             }
       
  5910         }
       
  5911 
       
  5912     return iStarterSession;
       
  5913     }
       
  5914 
       
  5915 // ----------------------------------------------------------------------------
       
  5916 // CSysApAppUi::KeyLock()
       
  5917 // ----------------------------------------------------------------------------
       
  5918 
       
  5919 RAknKeylock2& CSysApAppUi::KeyLock()
       
  5920     {
       
  5921     if ( !iKeyLock.Handle() )
       
  5922         {
       
  5923         // All server connections are tried to be made KTriesToConnectServer times because occasional
       
  5924         // fails on connections are possible at least on some servers
       
  5925         TInt thisTry = 0;
       
  5926         TInt err;
       
  5927 
       
  5928         TRACES( RDebug::Print( _L("CSysApAppUi::KeyLock: trying RAknKeylock2::Connect()") ) );
       
  5929         thisTry = 0;
       
  5930         while ( ( err = iKeyLock.Connect() ) != KErrNone && ( thisTry++ ) <= KTriesToConnectServer )
       
  5931             {
       
  5932             User::After( KTimeBeforeRetryingServerConnection );
       
  5933             }
       
  5934 
       
  5935         if ( err != KErrNone )
       
  5936             {
       
  5937             // What do in error case?
       
  5938             TRACES( RDebug::Print( _L("CSysApAppUi::KeyLock: RAknKeylock2::Connect() failed with %d"), err ) );
       
  5939             }
       
  5940         }
       
  5941 
       
  5942     return iKeyLock;
       
  5943     }
       
  5944 
       
  5945 // ----------------------------------------------------------------------------
       
  5946 // CSysApAppUi::CenRepController()
       
  5947 // ----------------------------------------------------------------------------
       
  5948 
       
  5949 CSysApCenRepController& CSysApAppUi::CenRepController()
       
  5950     {
       
  5951     __ASSERT_ALWAYS( iSysApCenRepController, User::Panic( _L("CSysApAppUi::CenRepController"), KErrBadHandle ) );
       
  5952 
       
  5953     return *iSysApCenRepController;
       
  5954     }
       
  5955 
       
  5956 // ----------------------------------------------------------------------------
       
  5957 // CSysApAppUi::ExecCommandL
       
  5958 // ----------------------------------------------------------------------------
       
  5959 //
       
  5960 void CSysApAppUi::ExecCommandL( TSysapCommand aCommand )
       
  5961     {
       
  5962     ExecCommandL( aCommand, KNullDesC8 );
       
  5963     }
       
  5964 
       
  5965 // ----------------------------------------------------------------------------
       
  5966 // CSysApAppUi::ExecCommandL
       
  5967 // ----------------------------------------------------------------------------
       
  5968 //
       
  5969 void CSysApAppUi::ExecCommandL( TSysapCommand aCommand, const TDesC8& aParam )
       
  5970     {
       
  5971     TRACES( RDebug::Print(_L("CSysApAppUi::ExecCommandL: aCommand=%d"), aCommand ) );
       
  5972 
       
  5973     switch ( aCommand )
       
  5974         {
       
  5975         case EResetKeyguardState: // reset the internal keyguard flags of the SysAp, except for iKeyLockOnBeforeCradle
       
  5976             iKeyLockOnBeforeCall = EFalse;
       
  5977             iKeyLockOnBeforeAlarm = EFalse;
       
  5978             break;
       
  5979 
       
  5980         case ECancelPowermenu: // hide power menu if it is visible
       
  5981             if( iPowerKeyPopupMenuActive )
       
  5982                 {
       
  5983                 CancelGlobalListQuery();
       
  5984                 }
       
  5985             break;
       
  5986 
       
  5987         case EUpdateLights: // apply key specific light handling
       
  5988             {
       
  5989             TUpdateLightsBuf lightBuf;
       
  5990             lightBuf.Copy( aParam );
       
  5991 
       
  5992             switch ( lightBuf() )
       
  5993                 {
       
  5994                 case EKeyGripClose:
       
  5995                     SetGripOpenL( EFalse );
       
  5996                     break;
       
  5997 
       
  5998                 case EKeyGripOpen:
       
  5999                     SetGripOpenL( ETrue );
       
  6000                     break;
       
  6001 
       
  6002                 case EKeyFlipClose:
       
  6003                     SetFlipOpenL( EFalse );
       
  6004                     break;
       
  6005 
       
  6006                 case EKeyFlipOpen:
       
  6007                     SetFlipOpenL( ETrue );
       
  6008                     break;
       
  6009 
       
  6010                 default:
       
  6011                     // No specific light handling for other keys.
       
  6012                     break;
       
  6013                 }
       
  6014             }
       
  6015             break;
       
  6016 
       
  6017         default:
       
  6018             // do nothing in release builds since no harm is done
       
  6019             __ASSERT_DEBUG( EFalse, User::Panic( _L("CSysApAppUi::ExecCommandL: Invalid command"), KErrArgument ) );
       
  6020             break;
       
  6021         }
       
  6022     }
       
  6023 
       
  6024 // ----------------------------------------------------------------------------
       
  6025 // CSysApAppUi::ExecQueryL
       
  6026 // ----------------------------------------------------------------------------
       
  6027 //
       
  6028 void CSysApAppUi::ExecQueryL( TSysapQuery aQuery, TDes8& aReturn )
       
  6029     {
       
  6030     ExecQueryL( aQuery, aReturn, KNullDesC8 );
       
  6031     }
       
  6032 
       
  6033 // ----------------------------------------------------------------------------
       
  6034 // CSysApAppUi::ExecQueryL
       
  6035 // ----------------------------------------------------------------------------
       
  6036 //
       
  6037 void CSysApAppUi::ExecQueryL( TSysapQuery aQuery, TDes8& aReturn, const TDesC8& /*aParam*/ )
       
  6038     {
       
  6039     TRACES( RDebug::Print(_L("CSysApAppUi::ExecQueryL: aQuery=%d"), aQuery ) );
       
  6040 
       
  6041     switch ( aQuery )
       
  6042         {
       
  6043         case EGetHwrmLight: // get handle to HWRM client session. Returns CHWRMLight*.
       
  6044             {
       
  6045             THwrmLightBuf retBuf( iSysApLightsController->GetHwrmLight() );
       
  6046             aReturn.Copy( retBuf );
       
  6047             }
       
  6048             break;
       
  6049 
       
  6050         case EGetKeylock: // get handle to keylock client session. Returns RAknKeylock2*.
       
  6051             {
       
  6052             TKeyLockBuf retBuf( &(KeyLock()) );
       
  6053             aReturn.Copy( retBuf );
       
  6054             }
       
  6055             break;
       
  6056 
       
  6057         default:
       
  6058             __ASSERT_DEBUG( EFalse, User::Panic( _L("CSysApAppUi::ExecQueryL: Invalid query"), KErrArgument ) );
       
  6059             User::Leave( KErrArgument );
       
  6060             break;
       
  6061         }
       
  6062     }
       
  6063 
       
  6064 // ----------------------------------------------------------------------------
       
  6065 // CSysApAppUi::ShowShutdownImage
       
  6066 // ----------------------------------------------------------------------------
       
  6067 //
       
  6068 TInt CSysApAppUi::ShowShutdownImage( TInt aBitmapId )
       
  6069     {
       
  6070     TRACES( RDebug::Print(_L("CSysApAppUi::ShowShutdownImage") ) );
       
  6071 
       
  6072     TRAPD( err, ShowShutdownImageL( aBitmapId ) );
       
  6073 
       
  6074     if ( err != KErrNone )
       
  6075         {
       
  6076         TRACES( RDebug::Print(_L("CSysApAppUi::ShowShutdownImageL failed, err=%d"), err ) );
       
  6077         }
       
  6078 
       
  6079     return err;
       
  6080     }
       
  6081 
       
  6082 // ----------------------------------------------------------------------------
       
  6083 // CSysApAppUi::ShowShutdownImageL
       
  6084 // ----------------------------------------------------------------------------
       
  6085 //
       
  6086 void CSysApAppUi::ShowShutdownImageL( TInt aBitmapId )
       
  6087     {
       
  6088     TRACES( RDebug::Print(_L("CSysApAppUi::ShowShutdownImageL") ) );
       
  6089 
       
  6090     if ( !iSysApShutdownImage ) // Shutdown image may be shown without entering normal state (e.g. charging), so construct here
       
  6091         {
       
  6092         TRACES( RDebug::Print( _L("CSysApAppUi::ShowShutdownImageL: trying CSysApShutdownImage::NewL()") ) );
       
  6093         iSysApShutdownImage = CSysApShutdownImage::NewL();
       
  6094         }
       
  6095 
       
  6096     TRACES( RDebug::Print( _L("CSysApAppUi::ShowShutdownImageL: trying CSysApShutdownImage::ShowShutdownImageL()") ) );
       
  6097     iSysApShutdownImage->ShowShutdownImageL( aBitmapId );
       
  6098     }
       
  6099 
       
  6100 // ----------------------------------------------------------------------------
       
  6101 // CSysApAppUi::IgnoreZeroNetworkBarNotifications
       
  6102 // ----------------------------------------------------------------------------
       
  6103 //
       
  6104 void CSysApAppUi::IgnoreZeroNetworkBarNotifications(TBool aIgnore)
       
  6105     {
       
  6106     iIgnoreZeroNetworkBarNotifications = aIgnore;
       
  6107     }
       
  6108 
       
  6109 // ----------------------------------------------------------------------------
       
  6110 // CSysApAppUi::BtSapEnabled()
       
  6111 // ----------------------------------------------------------------------------
       
  6112 
       
  6113 TBool CSysApAppUi::BtSapEnabled()
       
  6114     {
       
  6115     if ( iSysApBtSapController )
       
  6116         {
       
  6117         return iSysApBtSapController->BtSapEnabled();    
       
  6118         }
       
  6119     
       
  6120     return EFalse;
  2733     return EFalse;
  6121     }
  2734     }
  6122 
  2735 
  6123 // ----------------------------------------------------------------------------
  2736 
  6124 // CSysApAppUi::DeactivateBT
  2737 //end of file
  6125 // ----------------------------------------------------------------------------
       
  6126 //
       
  6127 void CSysApAppUi::DeactivateBT()
       
  6128     {
       
  6129     // Will deactivate BT when changing to normal mode
       
  6130     iDeactivateBt = ETrue;
       
  6131     }
       
  6132 
       
  6133 // ----------------------------------------------------------------------------
       
  6134 // CSysApAppUi::SetHacIndicatorL()
       
  6135 // ----------------------------------------------------------------------------
       
  6136 void CSysApAppUi::SetHacIndicatorL()
       
  6137     {
       
  6138 
       
  6139     if ( !iSysApCenRepHacSettingObserver )
       
  6140         {
       
  6141         // Do nothing if HAC setting observer has not been created yet
       
  6142         // This occurs in case some party is trying to set HAC indicator during
       
  6143         // ConstructL(), e.g. when switching from offline to online during startup
       
  6144         TRACES( RDebug::Print( _L("CSysApAppUi::SetHacIndicatorL: do nothing, HAC observer does not exist yet") ) );
       
  6145         return;
       
  6146         }
       
  6147 
       
  6148     if ( iSysApCenRepHacSettingObserver->HacMode() )
       
  6149         {
       
  6150         TBool accessoryConnected ( EFalse );
       
  6151 
       
  6152         TAccMode accMode(EAccModeHandPortable);
       
  6153 
       
  6154         if ( iSysApAccessoryObserver )
       
  6155             {
       
  6156             accMode = iSysApAccessoryObserver->GetAccessoryMode();
       
  6157 
       
  6158             if ( accMode != EAccModeHandPortable )
       
  6159                 {
       
  6160                 accessoryConnected = ETrue;
       
  6161                 }
       
  6162             }
       
  6163 
       
  6164         TInt indicatorState = EAknIndicatorStateOn;
       
  6165 
       
  6166         if ( !accessoryConnected ) // When accessory is not connected, check offline and call state
       
  6167             {
       
  6168             if ( OfflineModeActive() ) // HAC indicator is not shown in offline mode
       
  6169                 {
       
  6170                 indicatorState = EAknIndicatorStateOff;
       
  6171                 }
       
  6172             else
       
  6173                 {
       
  6174                 // during active call with IHF activated HAC indicator is not shown
       
  6175                 TInt callState( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
       
  6176                 if ( callState < KErrNone )
       
  6177                     {
       
  6178                     callState = EPSCTsyCallStateNone;
       
  6179                     }
       
  6180 
       
  6181                 if ( callState != EPSCTsyCallStateNone && IhfEnabledL() )
       
  6182                     {
       
  6183                     indicatorState = EAknIndicatorStateOff;
       
  6184                     }
       
  6185                 }
       
  6186 
       
  6187             }
       
  6188         else
       
  6189             {
       
  6190             // If an accessory is connected, HAC indicator should not be shown
       
  6191             indicatorState = EAknIndicatorStateOff;
       
  6192             }
       
  6193 
       
  6194         SetIndicatorStateL( EAknIndicatorHAC, indicatorState );
       
  6195 
       
  6196         }
       
  6197     else
       
  6198         {
       
  6199         // If HAC is not active, always disable indicator regardless of accessory state
       
  6200         SetIndicatorStateL( EAknIndicatorHAC, EAknIndicatorStateOff );
       
  6201         }
       
  6202 
       
  6203 
       
  6204     }
       
  6205 
       
  6206 // ----------------------------------------------------------------------------
       
  6207 // CSysApAppUi::HandleResourceChangeL()
       
  6208 // ----------------------------------------------------------------------------
       
  6209 
       
  6210 void CSysApAppUi::HandleResourceChangeL( TInt aType )
       
  6211     {
       
  6212     TRACES( RDebug::Print( _L("CSysApAppUi::HandleResourceChangeL aType: %d"), aType ) );
       
  6213     CAknAppUi::HandleResourceChangeL(aType);
       
  6214 
       
  6215     if ( aType == KEikDynamicLayoutVariantSwitch )
       
  6216         {
       
  6217 #ifdef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  6218         iSysApShutdownImage->SetRect( ApplicationRect() );
       
  6219 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  6220 
       
  6221         TInt mode;
       
  6222         User::LeaveIfError( RProperty::Get( KPSUidStartup, KPSGlobalStartupMode, mode ) );
       
  6223 
       
  6224         if ( mode == EStartupModeAlarm )
       
  6225             {
       
  6226             SetStatusPaneLayoutL( ESysApAlarm );
       
  6227             }
       
  6228         }
       
  6229     }
       
  6230 
       
  6231 // ----------------------------------------------------------------------------
       
  6232 // CSysApAppUi::SetMemoryCardIndicatorL
       
  6233 // ----------------------------------------------------------------------------
       
  6234 
       
  6235 void CSysApAppUi::SetMemoryCardIndicatorL()
       
  6236     {
       
  6237     if ( iSysApFeatureManager->Supported( KSysApFeatureIdMemoryCardIcon ) )
       
  6238         {
       
  6239 #ifndef RD_MULTIPLE_DRIVE
       
  6240         TSysApMemoryCardStatus memoryCardStatus = iSysApMMCObserver->MemoryCardStatus();
       
  6241 
       
  6242         TRACES( RDebug::Print( _L("CSysApAppUi::SetMemoryCardIndicatorL: memoryCardStatus=%d"), memoryCardStatus ) );
       
  6243 
       
  6244         if ( memoryCardStatus == ESysApMemoryCardInserted || memoryCardStatus == ESysApMemoryCardLocked )
       
  6245 #else // RD_MULTIPLE_DRIVE
       
  6246         TInt insertedCount( CSysApDriveList::NonUsbDriveCount( iInsertedMemoryCards ) );
       
  6247 
       
  6248         TRACES( RDebug::Print( _L("CSysApAppUi::SetMemoryCardIndicatorL: insertedCount=%d"), insertedCount ) );
       
  6249 
       
  6250         if ( insertedCount > 0 )
       
  6251 #endif // RD_MULTIPLE_DRIVE
       
  6252             {
       
  6253             SetIndicatorStateL( EAknIndicatorMemoryCard, EAknIndicatorStateOn );
       
  6254             }
       
  6255         else
       
  6256             {
       
  6257             SetIndicatorStateL( EAknIndicatorMemoryCard, EAknIndicatorStateOff );
       
  6258             }
       
  6259         }
       
  6260     }
       
  6261 
       
  6262 // ----------------------------------------------------------------------------
       
  6263 // CSysApAppUi::SysApFeatureManager
       
  6264 // ----------------------------------------------------------------------------
       
  6265 
       
  6266 CSysApFeatureManager& CSysApAppUi::SysApFeatureManager()
       
  6267     {
       
  6268     __ASSERT_DEBUG( iSysApFeatureManager, User::Panic( _L("iSysApFeatureManager == NULL"), KErrBadHandle ) );
       
  6269 
       
  6270     return *iSysApFeatureManager;
       
  6271     }
       
  6272 
       
  6273 // ----------------------------------------------------------------------------
       
  6274 // CSysApAppUi::SetUsbAttachStatus
       
  6275 // ----------------------------------------------------------------------------
       
  6276 #ifndef RD_MULTIPLE_DRIVE
       
  6277 void CSysApAppUi::SetUsbAttachStatus( const TBool aUsbAttached )
       
  6278     {
       
  6279     // Prevent double beep when USB file transfer gets activated but
       
  6280     // allow MMC inserted beep when:
       
  6281     // a) USB file transfer is active
       
  6282     // b) MMC is not inserted when USB cable is attached
       
  6283     iHideNextBeep = ( iMMCInserted && aUsbAttached );
       
  6284     }
       
  6285 #else // RD_MULTIPLE_DRIVE
       
  6286 void CSysApAppUi::SetUsbAttachStatus( const TBool aUsbAttached )
       
  6287     {
       
  6288     TRACES( RDebug::Print(
       
  6289         _L( "CSysApAppUi::SetUsbAttachStatus: aUsbAttached: %d" ),
       
  6290         aUsbAttached ) );
       
  6291 
       
  6292     if ( aUsbAttached )
       
  6293         {
       
  6294         // For ignoring extra beeps caused by USB file transfer
       
  6295         iSysApDriveList->ResetDrivesInsertBeepIgnored();
       
  6296         iSysApDriveList->MarkDrivesInsertBeepIgnored( iInsertedMemoryCards );
       
  6297         }
       
  6298     }
       
  6299 #endif // RD_MULTIPLE_DRIVE
       
  6300 
       
  6301 // ----------------------------------------------------------------------------
       
  6302 // CSysApAppUi::IhfEnabledL
       
  6303 // ----------------------------------------------------------------------------
       
  6304 
       
  6305 TBool CSysApAppUi::IhfEnabledL()
       
  6306     {
       
  6307     TRACES( RDebug::Print( _L("CSysApAppUi::IhfEnabledL(): iSysApAudioRoutingObserver=0x%x"), iSysApAudioRoutingObserver ) );
       
  6308 
       
  6309     if ( !iSysApAudioRoutingObserver ) // create observer if needed
       
  6310         {
       
  6311         iSysApAudioRoutingObserver = CSysApAudioRoutingObserver::NewL( *this );
       
  6312         }
       
  6313 
       
  6314     return iSysApAudioRoutingObserver->IhfEnabled();
       
  6315     }
       
  6316 
       
  6317 // ----------------------------------------------------------------------------
       
  6318 // CSysApAppUi::IsDeviceModeKey
       
  6319 // ----------------------------------------------------------------------------
       
  6320 
       
  6321 TBool CSysApAppUi::IsDeviceModeKey( const TKeyEvent& aKeyEvent ) const
       
  6322     {
       
  6323     return CSysApDefaultKeyHandler::IsDeviceModeKey( aKeyEvent );
       
  6324     }
       
  6325 
       
  6326 // ----------------------------------------------------------------------------
       
  6327 // CSysApAppUi::ResourcesFreed
       
  6328 // ----------------------------------------------------------------------------
       
  6329 
       
  6330 TBool CSysApAppUi::ResourcesFreed() const
       
  6331     {
       
  6332     return iResourcesFreed;
       
  6333     }
       
  6334 
       
  6335 /* 
       
  6336 ----------------------------------------------------------------------------
       
  6337 CSysApAppUi::IsEncryptionOperationOngoingL()
       
  6338 Introduced the code as a part of Sub : 405-3362 - Power Management SUB for ES 
       
  6339 recapture functionalities in platform which support multidrive as well. 
       
  6340 -------------------------------------------------------------------------------
       
  6341 */
       
  6342 TBool CSysApAppUi::IsEncryptionOperationOngoingL() const
       
  6343     {
       
  6344 		TBool deFeatureSupported(EFalse);
       
  6345 		FeatureManager::InitializeLibL();
       
  6346 		deFeatureSupported = FeatureManager::FeatureSupported( KFeatureIdFfDeviceEncryptionFeature);
       
  6347 		FeatureManager::UnInitializeLib();
       
  6348 
       
  6349 		if(deFeatureSupported)
       
  6350 			{         
       
  6351 			/**
       
  6352 			 * Store the last memory status changed
       
  6353 			 * 0: Idle. It can be Encrypted or Decrypted
       
  6354 			 * 1: Encrypting
       
  6355 			 * 2: Decrypting
       
  6356 			 **/
       
  6357 			 
       
  6358 			RProperty deProperty;
       
  6359 			User::LeaveIfError(deProperty.Attach(KDevEncProtectedUid, KDevEncOperationKey,EOwnerThread));
       
  6360 			TInt deValue = 0;
       
  6361 			if((deProperty.Get(deValue)== KErrNone)&&( deValue == EOpEncrypting || deValue == EOpDecrypting))
       
  6362 				{
       
  6363 				deProperty.Close();
       
  6364 				return ETrue;
       
  6365 				}
       
  6366 			else
       
  6367 				{
       
  6368 				deProperty.Close();
       
  6369 				return EFalse;
       
  6370 				}
       
  6371 			}
       
  6372 		else
       
  6373 			{
       
  6374 			return EFalse;
       
  6375 			}
       
  6376     }
       
  6377 // ----------------------------------------------------------------------------
       
  6378 // CSysApAppUi::EtelConnector
       
  6379 // ----------------------------------------------------------------------------
       
  6380 
       
  6381 CSysApEtelConnector* CSysApAppUi::EtelConnector() const
       
  6382     {
       
  6383     return iSysApEtelConnector;
       
  6384     }
       
  6385 
       
  6386 #ifndef RD_MULTIPLE_DRIVE
       
  6387 
       
  6388 // ----------------------------------------------------------------------------
       
  6389 // CSysApAppUi::EjectUsed
       
  6390 // ----------------------------------------------------------------------------
       
  6391 
       
  6392 void CSysApAppUi::EjectUsed( TInt /*aDrive*/ )
       
  6393     {
       
  6394     }
       
  6395 
       
  6396 #else // RD_MULTIPLE_DRIVE
       
  6397 
       
  6398 // ----------------------------------------------------------------------------
       
  6399 // CSysApAppUi::ShowEjectWaitNoteL
       
  6400 // ----------------------------------------------------------------------------
       
  6401 
       
  6402 void CSysApAppUi::ShowEjectWaitNoteL( TInt aDriveToEject )
       
  6403     {
       
  6404     if ( iSysApWaitNote )
       
  6405         {
       
  6406         return;
       
  6407         }
       
  6408     HBufC* text = iSysApDriveList->GetFormattedDriveNameLC(
       
  6409         aDriveToEject,
       
  6410         0, // Not used
       
  6411         R_QTN_EJECTING_MEMORY_NAME_WAIT );
       
  6412     iSysApWaitNote = CSysApWaitNote::NewL(
       
  6413         iSysApFeatureManager->CoverDisplaySupported() );
       
  6414     iSysApWaitNote->ShowNoteL( EClosingApplicationsNote, text );
       
  6415     CleanupStack::PopAndDestroy( text );
       
  6416     }
       
  6417 
       
  6418 // ----------------------------------------------------------------------------
       
  6419 // CSysApAppUi::IsEjectQueryVisible
       
  6420 // ----------------------------------------------------------------------------
       
  6421 
       
  6422 TBool CSysApAppUi::IsEjectQueryVisible()
       
  6423     {
       
  6424     if ( !iSysApConfirmationQuery )
       
  6425         {
       
  6426         return EFalse;
       
  6427         }
       
  6428     TInt queryId( iSysApConfirmationQuery->CurrentQuery() );
       
  6429     return ( queryId == ESysApEjectMmcQuery || queryId == ESysApRemoveMmcNote );
       
  6430     }
       
  6431 
       
  6432 // ----------------------------------------------------------------------------
       
  6433 // CSysApAppUi::UpdateInsertedMemoryCardsL
       
  6434 // ----------------------------------------------------------------------------
       
  6435 
       
  6436 void CSysApAppUi::UpdateInsertedMemoryCardsL()
       
  6437     {
       
  6438     // Update inserted memory cards
       
  6439     iSysApDriveList->GetMemoryCardsL(
       
  6440         iInsertedMemoryCards, CSysApDriveList::EIncludeInserted );
       
  6441 
       
  6442     // Update memory card indicator status
       
  6443     SetMemoryCardIndicatorL();
       
  6444 
       
  6445     // Handle unlock
       
  6446     RunUnlockNotifierL();
       
  6447     }
       
  6448 
       
  6449 // ----------------------------------------------------------------------------
       
  6450 // CSysApAppUi::EjectUsed
       
  6451 // ----------------------------------------------------------------------------
       
  6452 
       
  6453 void CSysApAppUi::EjectUsed( TInt aDrive )
       
  6454     {
       
  6455     // Check drive inserted before starting eject confirm query
       
  6456     TInt insertedIndex( CSysApDriveList::Find( iInsertedMemoryCards, aDrive ) );
       
  6457 
       
  6458     TRACES( RDebug::Print(
       
  6459         _L( "CSysApAppUi::EjectUsed: drive: %d, index: %d" ),
       
  6460         aDrive, insertedIndex ) );
       
  6461 
       
  6462     if ( insertedIndex == KErrNotFound )
       
  6463         {
       
  6464         return;
       
  6465         }
       
  6466 
       
  6467     iMMCEjectUsed = ETrue;
       
  6468     iDriveToEject = aDrive;
       
  6469     iSysApDriveList->ResetDrivesToEject();
       
  6470     TRAPD( err, EjectMMCL() );
       
  6471     if ( err != KErrNone )
       
  6472         {
       
  6473         TRACES( RDebug::Print(
       
  6474             _L( "CSysApAppUi::EjectUsed: err: %d" ), err ) );
       
  6475         iMMCEjectUsed = EFalse;
       
  6476         }
       
  6477     }
       
  6478 
       
  6479 #endif // RD_MULTIPLE_DRIVE
       
  6480 
       
  6481 // ----------------------------------------------------------------------------
       
  6482 // CSysApAppUi::EjectMMCCanceled
       
  6483 // ----------------------------------------------------------------------------
       
  6484 
       
  6485 void CSysApAppUi::EjectMMCCanceled()
       
  6486     {
       
  6487     // Called from eject confirm query, reset eject status
       
  6488 #ifdef RD_MULTIPLE_DRIVE
       
  6489     iMMCEjectUsed = EFalse;
       
  6490 #endif // RD_MULTIPLE_DRIVE
       
  6491     }
       
  6492 
       
  6493 // ----------------------------------------------------------------------------
       
  6494 // CSysApAppUi::UsbChargerDetector
       
  6495 // ----------------------------------------------------------------------------
       
  6496 //
       
  6497 TSysApUsbChargerDetector& CSysApAppUi::UsbChargerDetector()
       
  6498     {
       
  6499     return iSysApUsbChargerDetector;
       
  6500     }
       
  6501 
       
  6502 // ----------------------------------------------------------------------------
       
  6503 // CSysApAppUi::HandleUsbCharger
       
  6504 // ----------------------------------------------------------------------------
       
  6505 //
       
  6506 void CSysApAppUi::HandleUsbCharger( const TInt aValue )
       
  6507     {        
       
  6508     if ( aValue == EChargingStatusCharging ||
       
  6509          aValue == EChargingStatusChargingContinued ||
       
  6510          aValue == EChargingStatusAlmostComplete )
       
  6511         {
       
  6512         iSysApUsbChargerDetector.SetChargingUsed( ETrue );
       
  6513         if ( !iSysApUsbIndicatorController &&
       
  6514              iSysApFeatureManager->Supported( KSysApFeatureIdChargerReminderNotes ) &&
       
  6515              iSysApFeatureManager->Supported( KSysApFeatureIdUsbChargingWithoutReminderNotes ) )
       
  6516             {
       
  6517             // Start observing USB state for the reminder note
       
  6518             TRAPD ( usbErr, iSysApUsbIndicatorController = CreateSysApUsbIndicatorL( *this ) );
       
  6519             if ( usbErr )
       
  6520                 {
       
  6521                 TRACES( RDebug::Print(
       
  6522                     _L("CSysApAppUi::HandleUsbCharger: error in constructing USB ind. controller %d" ),
       
  6523                     usbErr ) );
       
  6524                 }
       
  6525             }
       
  6526         }
       
  6527     }
       
  6528 
       
  6529 // ----------------------------------------------------------------------------
       
  6530 // CSysApAppUi::SetEnvelopeIndicatorL
       
  6531 // ----------------------------------------------------------------------------
       
  6532 //
       
  6533 void CSysApAppUi::SetEnvelopeIndicatorL()
       
  6534     {
       
  6535     TInt phoneStoreStatus( StateOfProperty( KUidPSSMSStackCategory, KUidPSSMSStackDiskSpaceMonitorKey ) );
       
  6536     TInt inboxStatus( StateOfProperty( KUidSystemCategory, KUidInboxStatusValue ) );
       
  6537     TBool simStoreFull( iSysApEtelConnector && iSysApEtelConnector->IsSimSmsStoreFull() );
       
  6538 
       
  6539     TRACES( RDebug::Print(
       
  6540         _L("CSysApAppUi::SetEnvelopeIndicatorL() phoneStoreStatus %d, simStoreFull %d, inboxStatus %d"),
       
  6541         phoneStoreStatus, simStoreFull, inboxStatus ) );
       
  6542 
       
  6543     if ( phoneStoreStatus == ESmsDiskSpaceFull || simStoreFull )
       
  6544         {
       
  6545         // Blink the Envelope indicator
       
  6546         SetIndicatorStateL( EAknIndicatorEnvelope, EAknIndicatorStateAnimate );
       
  6547         }
       
  6548     else if ( inboxStatus == ESADocumentsInInbox )
       
  6549         {
       
  6550         // Show the Envelope indicator.
       
  6551         SetIndicatorStateL( EAknIndicatorEnvelope, EAknIndicatorStateOn );
       
  6552         }
       
  6553     else
       
  6554         {
       
  6555         // Hide the Envelope indicator.
       
  6556         SetIndicatorStateL( EAknIndicatorEnvelope, EAknIndicatorStateOff );
       
  6557         }
       
  6558     }
       
  6559     
       
  6560 // ----------------------------------------------------------------------------
       
  6561 // CSysApAppUi::LogsObserverL
       
  6562 // ----------------------------------------------------------------------------
       
  6563 //
       
  6564 CSysApCenRepLogsObserver& CSysApAppUi::LogsObserverL()
       
  6565     {
       
  6566     TRACES( RDebug::Print( _L("CSysApAppUi::LogsObserverL()") ) );
       
  6567     
       
  6568     // Create Logs observer when it is needed for the first time
       
  6569     if ( !iSysApCenRepLogsObserver )
       
  6570         {
       
  6571         iSysApCenRepLogsObserver = CSysApCenRepLogsObserver::NewL( *this );
       
  6572         }
       
  6573     
       
  6574     return *iSysApCenRepLogsObserver;
       
  6575     }
       
  6576     
       
  6577 // ----------------------------------------------------------------------------
       
  6578 // CSysApAppUi::NotifyPowerSaveModeL
       
  6579 // ----------------------------------------------------------------------------
       
  6580 //
       
  6581 void CSysApAppUi::NotifyPowerSaveModeL( TSysApPsmStatus aStatus )
       
  6582     {
       
  6583     TRACES( RDebug::Print( _L("CSysApAppUi::NotifyPowerSaveModeL aStatus: %d"), aStatus ) );
       
  6584 
       
  6585     // cancel any active power saving query because user has changed the state manually
       
  6586     CancelQuery( ESysApBattChargingPowerSavingQuery );
       
  6587     CancelQuery( ESysApBattLowPowerSavingQuery );
       
  6588     
       
  6589     switch ( aStatus )
       
  6590         {
       
  6591         case MSysApPsmControllerNotifyCallback::EPsmActivationComplete:
       
  6592             UpdateBatteryBarsL( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
  6593             ShowUiNoteL( EPowerSaveModeActivated );
       
  6594             break;
       
  6595         
       
  6596         case MSysApPsmControllerNotifyCallback::EPsmDeactivationComplete:
       
  6597             UpdateBatteryBarsL( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
  6598             ShowUiNoteL( EPowerSaveModeDeactivated );
       
  6599             break;
       
  6600             
       
  6601         case MSysApPsmControllerNotifyCallback::EPsmActivationFailed:
       
  6602             ShowUiNoteL( ECannotActivatePowerSaveMode );
       
  6603             break;
       
  6604             
       
  6605         case MSysApPsmControllerNotifyCallback::EPsmDeactivationFailed:
       
  6606             ShowUiNoteL( ECannotDeactivatePowerSaveMode );
       
  6607             break;            
       
  6608         
       
  6609         default:
       
  6610             break;   
       
  6611         }
       
  6612     }
       
  6613 
       
  6614 // ----------------------------------------------------------------------------
       
  6615 // CSysApAppUi::HandleBatteryStatusL
       
  6616 // ----------------------------------------------------------------------------
       
  6617 //
       
  6618 void CSysApAppUi::HandleBatteryStatusL( const TInt aValue )
       
  6619     {
       
  6620     TRACES( RDebug::Print( _L("CSysApAppUi::HandleBatteryStatusL aValue: %d"), aValue ) );
       
  6621     
       
  6622     if ( aValue == EBatteryStatusEmpty )
       
  6623         {
       
  6624         //Display Recharge Battery note
       
  6625         ShowUiNoteL( ERechargeBatteryNote );
       
  6626         BatteryEmptyL();
       
  6627         }
       
  6628     else if ( aValue == EBatteryStatusLow )
       
  6629         {
       
  6630         if ( iSysApPsmController && UiReady() )
       
  6631             {
       
  6632             iSysApPsmController->BatteryLow( ETrue );
       
  6633             
       
  6634             if ( iSysApPsmController->ShowActivateQuery())
       
  6635                 {
       
  6636                 // show activation query, replaces the first battery low query
       
  6637                 ShowQueryL( ESysApBattLowPowerSavingQuery );
       
  6638                 }
       
  6639             else // default low warning note must be shown
       
  6640                 {
       
  6641                 // activate partial power save mode on first low warning
       
  6642                 iSysApPsmController->DoEnablePartialPsm( ETrue ); // activated on first warning note
       
  6643                 //Display Battery Low note.
       
  6644                 ShowUiNoteL( EBatteryLowNote );    
       
  6645                 }                
       
  6646             }
       
  6647         else
       
  6648             {
       
  6649             //Display Battery Low note.
       
  6650             ShowUiNoteL( EBatteryLowNote );    
       
  6651             }            
       
  6652         }
       
  6653     
       
  6654     if ( iSysApBatteryInfoController )
       
  6655         {
       
  6656         iSysApBatteryInfoController->BatteryStatusUpdated( aValue );
       
  6657         }
       
  6658             
       
  6659     }
       
  6660 
       
  6661 // ----------------------------------------------------------------------------
       
  6662 // CSysApAppUi::HandleChargingStatusL
       
  6663 // ----------------------------------------------------------------------------
       
  6664 //
       
  6665 void CSysApAppUi::HandleChargingStatusL( const TInt aValue )
       
  6666     {
       
  6667     TRACES( RDebug::Print( _L("CSysApAppUi::HandleChargingStatusL aValue: %d"), aValue ) );
       
  6668     
       
  6669     TBool showNote( ETrue );
       
  6670     
       
  6671     UpdateBatteryBarsL( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
  6672 
       
  6673     if ( iSysApPsmController && UiReady() ) 
       
  6674         {
       
  6675         if ( iCharging ) // iCharging updated in UpdateBatteryBarsL
       
  6676             {
       
  6677             // cancel activation query if charger is connected while query is on display
       
  6678             CancelQuery( ESysApBattLowPowerSavingQuery );
       
  6679             }
       
  6680              
       
  6681         if ( iCharging && !iSysApPsmController->ChargerConnected() ) // first time after charger connection
       
  6682             {
       
  6683             iSysApPsmController->ConnectCharger( ETrue );
       
  6684             
       
  6685             if ( iSysApPsmController->ShowDeactivateQuery() )
       
  6686                 {
       
  6687                 ShowQueryL( ESysApBattChargingPowerSavingQuery );
       
  6688                 // Query is on the display. Don't show the note.
       
  6689                 showNote = EFalse;               
       
  6690                 }
       
  6691             else
       
  6692                 {
       
  6693                 iSysApPsmController->DoEnablePartialPsm( EFalse );
       
  6694                 }                
       
  6695             }
       
  6696         else if ( aValue == EChargingStatusNotConnected )
       
  6697             {
       
  6698             iSysApPsmController->ConnectCharger( EFalse );
       
  6699             
       
  6700             // cancel deactivation query if charger is disconnected while query is on display 
       
  6701             CancelQuery( ESysApBattChargingPowerSavingQuery );
       
  6702             }            
       
  6703         }
       
  6704     if( showNote )
       
  6705         {
       
  6706         HandleChargerNotesL( aValue );    
       
  6707         }
       
  6708     }
       
  6709 
       
  6710 // ----------------------------------------------------------------------------
       
  6711 // CSysApAppUi::HandleActivatePsmQueryResponse
       
  6712 // ----------------------------------------------------------------------------
       
  6713 //
       
  6714 void CSysApAppUi::HandleActivatePsmQueryResponse( TBool aEnable )
       
  6715     {
       
  6716     TRACES( RDebug::Print( _L("CSysApAppUi::HandleActivatePsmQueryResponse aEnable: %d"), 
       
  6717         aEnable ) );
       
  6718     
       
  6719     __ASSERT_DEBUG( iSysApPsmController, User::Invariant() );
       
  6720     
       
  6721     if ( aEnable )
       
  6722         {
       
  6723         iSysApPsmController->DoEnableFullPsm( ETrue );    
       
  6724         }
       
  6725     else
       
  6726         {
       
  6727         iSysApPsmController->DoEnablePartialPsm( ETrue );     
       
  6728         }        
       
  6729     }
       
  6730 
       
  6731 // ----------------------------------------------------------------------------
       
  6732 // CSysApAppUi::HandleDeactivatePsmQueryResponse
       
  6733 // ----------------------------------------------------------------------------
       
  6734 //
       
  6735 void CSysApAppUi::HandleDeactivatePsmQueryResponse( TBool aDisable )
       
  6736     {
       
  6737     TRACES( RDebug::Print( _L("CSysApAppUi::HandleDeactivatePsmQueryResponse aDisable: %d"), 
       
  6738         aDisable ) );
       
  6739 
       
  6740     __ASSERT_DEBUG( iSysApPsmController, User::Invariant() );
       
  6741     
       
  6742     if ( aDisable )
       
  6743         {
       
  6744         iSysApPsmController->DoEnableFullPsm( EFalse );        
       
  6745         }
       
  6746     }
       
  6747     
       
  6748 // ----------------------------------------------------------------------------
       
  6749 // CSysApAppUi::CancelQuery
       
  6750 // ----------------------------------------------------------------------------
       
  6751 //
       
  6752 void CSysApAppUi::CancelQuery( TSysApConfirmationQueryIds aQueryId )
       
  6753     {
       
  6754     TRACES( RDebug::Print( _L("CSysApAppUi::CancelQuery aQueryId: %d"), aQueryId ) );
       
  6755 
       
  6756     if ( iSysApConfirmationQuery )
       
  6757         {
       
  6758         if ( aQueryId == iSysApConfirmationQuery->CurrentQuery() || aQueryId == ESysApNoQuery )
       
  6759             {
       
  6760             iSysApConfirmationQuery->Cancel();
       
  6761             }
       
  6762         }
       
  6763     }
       
  6764 // End of File