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