htiui/HtiServicePlugins/HtiSysInfoServicePlugin/src/HtiSysInfoServicePlugin.cpp
changeset 2 453d490c84a5
parent 1 753e33780645
child 3 6952856dc269
equal deleted inserted replaced
1:753e33780645 2:453d490c84a5
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  SysInfoPlugin implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "HtiSysInfoServicePlugin.h"
       
    21 #include "HtiLightsController.h"
       
    22 #include "HtiPropertySubscriber.h"
       
    23 #include <HtiDispatcherInterface.h>
       
    24 #include <HtiLogging.h>
       
    25 
       
    26 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 )
       
    27 #include <aknkeylock.h>
       
    28 #include <ScreensaverInternalPSKeys.h>
       
    29 #endif
       
    30 
       
    31 #include <AknSkinsInternalCRKeys.h>
       
    32 #include <AknsSkinUID.h>
       
    33 #include <AknsSrvClient.h>
       
    34 #include <AknFepInternalCRKeys.h>
       
    35 #include <AknFepGlobalEnums.h> //For chinese input modes
       
    36 #include <CommonEngineDomainCRKeys.h>
       
    37 #include <featmgr.h>
       
    38 #include <bautils.h>
       
    39 #include <btengsettings.h>
       
    40 #include <btengdomaincrkeys.h>
       
    41 #include <bt_subscribe.h>
       
    42 #include <btmanclient.h>
       
    43 #include <centralrepository.h>
       
    44 #include <CoreApplicationUIsSDKCRKeys.h>
       
    45 #include <DRMRightsClient.h>
       
    46 #include <e32property.h>
       
    47 #include <etel.h>
       
    48 #include <etelmm.h>
       
    49 #include <hal.h>
       
    50 #include <ir_sock.h>
       
    51 #include <mmtsy_names.h>
       
    52 #include <rmmcustomapi.h>
       
    53 #include <hwrmpowerstatesdkpskeys.h>
       
    54 #include <settingsinternalcrkeys.h>
       
    55 #include <sysutil.h>
       
    56 #include <tz.h>
       
    57 
       
    58 // CONSTANTS
       
    59 const static TUid KSysInfoServiceUid = { 0x10210CC7 };
       
    60 
       
    61 // from irinternalpskey.h
       
    62 const static TUid KPSUidIrdaActivation = { 0x2000276D };
       
    63 
       
    64 const TInt KTimeDataLength = 7;
       
    65 const TInt KMaxBtNameLength = 30;
       
    66 const TInt KDateTimeFormatCmdLength = 6;
       
    67 
       
    68 const TInt KFepChineseInputModeLength = 10;
       
    69 
       
    70 _LIT( KTempFilePath, "\\" );
       
    71 _LIT( KTempFileName, "HtiTempFile.tmp" );
       
    72 _LIT( KMatchFileName, "HtiTempFile.tmp*" );
       
    73 _LIT( KDateSeparatorChars, ".:/-" );
       
    74 _LIT( KTimeSeparatorChars, ".:" );
       
    75 
       
    76 _LIT8( KErrDescrArgument, "Invalid argument" );
       
    77 _LIT8( KErrDescrNotSupported, "Command not supported" );
       
    78 _LIT8( KErrDescrHAL, "Error retrieving HAL attribute" );
       
    79 _LIT8( KErrDescrAttOutOfRange, "HAL attribute argument is out of range" );
       
    80 _LIT8( KErrDescrFreeRAM, "Error retrieving the amount of free RAM" );
       
    81 _LIT8( KErrDescrTotalRAM, "Error retrieving the amount of total RAM" );
       
    82 _LIT8( KErrDescrAllocRAM, "Error allocating RAM" );
       
    83 _LIT8( KErrDescrInvalidRAM, "Requested free RAM larger than currently free" );
       
    84 _LIT8( KErrDescrVolInfo, "Error retrieving volume info" );
       
    85 _LIT8( KErrDescrNotEnoughSpace, "Not enough disk space" );
       
    86 _LIT8( KErrDescrCreateTempFile, "Error creating temp file" );
       
    87 _LIT8( KErrDescrSetSizeTempFile, "Error allocating size for temp file" );
       
    88 _LIT8( KErrDescrDeleteTempFile, "Error deleting temp file" );
       
    89 _LIT8( KErrDescrSysUtil, "SysUtil failed" );
       
    90 _LIT8( KErrDescrSetTime, "Setting time failed" );
       
    91 _LIT8( KErrDescrDateTimeFormat, "Setting date and time formats failed" );
       
    92 _LIT8( KErrDescrSetLanguage, "Setting language failed");
       
    93 _LIT8( KErrDescrGetNetworkModes, "Getting network modes failed" );
       
    94 _LIT8( KErrDescrSetNetworkMode, "Setting network mode failed" );
       
    95 _LIT8( KErrDescrIrActivation, "IR activation failed" );
       
    96 _LIT8( KErrDescrGetBtPower, "Getting BT power state failed" );
       
    97 _LIT8( KErrDescrSetBtPower, "Setting BT power state failed" );
       
    98 _LIT8( KErrDescrBtOnDenied, "Turning BT on not allowed (Offline mode)" );
       
    99 _LIT8( KErrDescrBtOffDenied, "Turning BT off not allowed (active connections)" );
       
   100 _LIT8( KErrDescrBtSettings, "Bluetooth settings failed" );
       
   101 _LIT8( KErrDescrBtDeletePairings, "Deleting Bluetooth pairing(s) failed" );
       
   102 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 )
       
   103 _LIT8( KErrDescrKeyLock, "Key lock toggle failed" );
       
   104 _LIT8( KErrDescrScreenSaver, "Setting screen saver state failed" );
       
   105 _LIT8( KErrDescrInvalidSSTimeout, "Invalid screen saver timeout value" );
       
   106 _LIT8( KErrDescrSSTimeoutFailed, "Setting screen saver timeout failed" );
       
   107 #endif
       
   108 _LIT8( KErrDescrInvalidTime, "Auto key guard time value too large (max 3600)" );
       
   109 _LIT8( KErrDescrAutoKeyGuardFailed, "Setting auto key guard time failed" );
       
   110 _LIT8( KErrDescrDrmDbConnect, "DRM DB connect failed." );
       
   111 _LIT8( KErrDescrDrmDbDelete,  "DRM DB delete failed." );
       
   112 _LIT8( KErrDescrBatteryLevel, "Getting battery level failed." );
       
   113 _LIT8( KErrDescrChargingStatus, "Getting charging status failed." );
       
   114 _LIT8( KErrDescrSignalStrength, "Getting signal strength failed." );
       
   115 _LIT8( KErrDescrMGUpdate, "Update Media Gallery failed" );
       
   116 _LIT8( KErrDescrActivateSkin, "Activating Skin failed" );
       
   117 
       
   118 enum TSysInfoCommand
       
   119     {
       
   120     ESysInfoHAL =             0x01,
       
   121     ESysInfoIMEI=             0x02,
       
   122     ESysInfoSWVersion =       0x03,
       
   123     ESysInfoLangVersion =     0x04,
       
   124     ESysInfoSWLangVersion =   0x05,
       
   125     ESysInfoUserAgent =       0x06,
       
   126     EFreeRAM =                0x07,
       
   127     EUsedRAM =                0x08,
       
   128     ETotalRAM =               0x09,
       
   129     EEatRAM =                 0x0A,
       
   130     EReleaseRAM =             0x0B,
       
   131     EFreeDiskSpace =          0x0C,
       
   132     EUsedDiskSpace =          0x0D,
       
   133     ETotalDiskSize =          0x0E,
       
   134     EEatDiskSpace =           0x0F,
       
   135     EReleaseDiskSpace =       0x10,
       
   136 
       
   137     ESysInfoSetHomeTime =     0x20,
       
   138     ESysInfoGetHomeTime =     0x21,
       
   139     ESetDateTimeFormat =      0x22,
       
   140     
       
   141     ESetLanguage =            0x25,
       
   142 
       
   143     ELightStatus =            0x30,
       
   144     ELightOn =                0x31,
       
   145     ELightOff =               0x32,
       
   146     ELightBlink =             0x33,
       
   147     ELightRelease =           0x3A,
       
   148 
       
   149     EScreenSaverDisable =     0x40,
       
   150     EScreenSaverEnable  =     0x41,
       
   151     EScreenSaverTimeout =     0x42,
       
   152 
       
   153     ENetworkModeGet =         0x50,
       
   154     ENetworkModeSet =         0x51,
       
   155     ENetworkModeSetNoReboot = 0x52,
       
   156     EHsdpaSet =               0x53,
       
   157 
       
   158     EIrActivate =             0x5A,
       
   159     EBtPower =                0x5B,
       
   160     EBtSettings =             0x5C,
       
   161     EBtDeletePairings =       0x5D,
       
   162 
       
   163     EKeylockToggle =          0x60,
       
   164     EAutoKeyGuardTime =       0x61,
       
   165 
       
   166     EEmtpyDrmRightsDb =       0x65,
       
   167 
       
   168     EBatteryStatus =          0x70,
       
   169     ESignalStrength =         0x71,
       
   170 
       
   171     EUpdateMediaGallery =     0x7A,
       
   172 
       
   173     EActivateSkin =           0x80
       
   174     };
       
   175 
       
   176 enum TGSNumberModes
       
   177     {
       
   178     EGSNbrModeLatin, EGSNbrModeArabic = 1, EGSNbrModeIndic = 1
       
   179     };
       
   180 
       
   181 // Number mode type
       
   182 enum TGSNumberModeType
       
   183     {
       
   184     EGSNbrModeTypeArabic, EGSNbrModeTypeIndic, EGSNbrModeTypeEasternArabic
       
   185     // for Urdu & Farsi languages
       
   186     };
       
   187 
       
   188 //------------------------------------------------------------------------------
       
   189 // Create instance of concrete ECOM interface implementation
       
   190 //------------------------------------------------------------------------------
       
   191 CHtiSysInfoServicePlugin* CHtiSysInfoServicePlugin::NewL()
       
   192     {
       
   193     CHtiSysInfoServicePlugin* self = new (ELeave) CHtiSysInfoServicePlugin;
       
   194     CleanupStack::PushL (self);
       
   195     self->ConstructL();
       
   196     CleanupStack::Pop();
       
   197     return self;
       
   198     }
       
   199 
       
   200 //------------------------------------------------------------------------------
       
   201 // Constructor
       
   202 //------------------------------------------------------------------------------
       
   203 CHtiSysInfoServicePlugin::CHtiSysInfoServicePlugin():
       
   204     iMemEater( NULL ), iReply( NULL ), iGalleryUpdateSupported( ETrue )
       
   205     {
       
   206 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 )
       
   207         iAllowSSValue = -1;
       
   208         iAllowSSPropertyAttached = EFalse;
       
   209 #endif
       
   210     }
       
   211 
       
   212 //------------------------------------------------------------------------------
       
   213 // Destructor
       
   214 //------------------------------------------------------------------------------
       
   215 CHtiSysInfoServicePlugin::~CHtiSysInfoServicePlugin()
       
   216     {
       
   217     HTI_LOG_TEXT( "CHtiSysInfoServicePlugin destroy" );
       
   218     delete iMemEater;
       
   219     delete iReply;
       
   220 
       
   221     CleanUpTempFiles();
       
   222     delete iFileMan;
       
   223     iFs.Close();
       
   224     delete iLightsController;
       
   225 
       
   226     if ( iAllowSSSubscriber )
       
   227         {
       
   228         iAllowSSSubscriber->Unsubscribe();
       
   229         }
       
   230 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 )
       
   231     iAllowSSProperty.Close();
       
   232 #endif 
       
   233     delete iAllowSSSubscriber;
       
   234     
       
   235     FeatureManager::UnInitializeLib();
       
   236     }
       
   237 
       
   238 //------------------------------------------------------------------------------
       
   239 // Second phase construction
       
   240 //------------------------------------------------------------------------------
       
   241 void CHtiSysInfoServicePlugin::ConstructL()
       
   242     {
       
   243     HTI_LOG_TEXT( "CHtiSysInfoServicePlugin::ConstructL" );
       
   244     User::LeaveIfError( iFs.Connect() );
       
   245     iFileMan = CFileMan::NewL( iFs );
       
   246     
       
   247     FeatureManager::InitializeLibL();
       
   248     }
       
   249 
       
   250 //------------------------------------------------------------------------------
       
   251 // CHtiSysInfoServicePlugin::ProcessMessageL
       
   252 //------------------------------------------------------------------------------
       
   253 void CHtiSysInfoServicePlugin::ProcessMessageL(const TDesC8& aMessage,
       
   254                                 THtiMessagePriority /*aPriority*/)
       
   255     {
       
   256     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::ProcessMessage" );
       
   257     HTI_LOG_FORMAT( "Message length: %d", aMessage.Length() );
       
   258 
       
   259     if ( aMessage.Length() > 0 )
       
   260         {
       
   261         HTI_LOG_FORMAT( "Command: %d", aMessage[0] );
       
   262 
       
   263         switch ( aMessage[0] )
       
   264             {
       
   265             case ESysInfoHAL:
       
   266                 {
       
   267                 HTI_LOG_TEXT( "ESysInfoHAL" );
       
   268                 HandleGetHalAttrL( aMessage );
       
   269                 }
       
   270                 break;
       
   271             case ESysInfoIMEI:
       
   272                 {
       
   273                 HTI_LOG_TEXT( "ESysInfoIMEI" );
       
   274                 HandleGetImeiL( aMessage );
       
   275                 }
       
   276                 break;
       
   277             case ESysInfoSWVersion:
       
   278                 {
       
   279                 HTI_LOG_TEXT( "ESysInfoSWVersion" );
       
   280                 HandleGetSwVersionL( aMessage );
       
   281                 }
       
   282                 break;
       
   283             case ESysInfoLangVersion:
       
   284                 {
       
   285                 HTI_LOG_TEXT( "ESysInfoLangVersion" );
       
   286                 HandleGetLangVersionL( aMessage );
       
   287                 }
       
   288                 break;
       
   289             case ESysInfoSWLangVersion:
       
   290                 {
       
   291                 HTI_LOG_TEXT( "ESysInfoSWLangVersion" );
       
   292                 HandleGetSwLangVersionL( aMessage );
       
   293                 }
       
   294                 break;
       
   295             case ESysInfoUserAgent:
       
   296                 {
       
   297                 HTI_LOG_TEXT( "ESysInfoUserAgent" );
       
   298                 HandleGetUserAgentStringL( aMessage );
       
   299                 }
       
   300                 break;
       
   301             case EFreeRAM:
       
   302                 {
       
   303                 HTI_LOG_TEXT( "EFreeRAM" );
       
   304                 HandleGetFreeRamL( aMessage );
       
   305                 }
       
   306                 break;
       
   307             case EUsedRAM:
       
   308                 {
       
   309                 HTI_LOG_TEXT( "EUsedRAM" );
       
   310                 HandleGetUsedRamL( aMessage );
       
   311                 }
       
   312                 break;
       
   313             case ETotalRAM:
       
   314                 {
       
   315                 HTI_LOG_TEXT( "ETotalRAM" );
       
   316                 HandleGetTotalRamL( aMessage );
       
   317                 }
       
   318                 break;
       
   319             case EEatRAM:
       
   320                 {
       
   321                 HTI_LOG_TEXT( "EEatRAM" );
       
   322                 HandleEatRamL( aMessage );
       
   323                 }
       
   324                 break;
       
   325             case EReleaseRAM:
       
   326                 {
       
   327                 HTI_LOG_TEXT( "EReleaseRAM" );
       
   328                 HandleReleaseRamL( aMessage );
       
   329                 }
       
   330                 break;
       
   331             case EFreeDiskSpace:
       
   332                 {
       
   333                 HTI_LOG_TEXT( "EFreeDiskSpace" );
       
   334                 HandleGetFreeDiskSpaceL( aMessage );
       
   335                 }
       
   336                 break;
       
   337             case EUsedDiskSpace:
       
   338                 {
       
   339                 HTI_LOG_TEXT( "EUsedDiskSpace" );
       
   340                 HandleGetUsedDiskSpaceL( aMessage );
       
   341                 }
       
   342                 break;
       
   343             case ETotalDiskSize:
       
   344                 {
       
   345                 HTI_LOG_TEXT( "ETotalDiskSize" );
       
   346                 HandleGetTotalDiskSpaceL( aMessage );
       
   347                 }
       
   348                 break;
       
   349             case EEatDiskSpace:
       
   350                 {
       
   351                 HTI_LOG_TEXT( "EEatDiskSpace" );
       
   352                 HandleEatDiskSpaceL( aMessage );
       
   353                 }
       
   354                 break;
       
   355             case EReleaseDiskSpace:
       
   356                 {
       
   357                 HTI_LOG_TEXT( "EReleaseDiskSpace" );
       
   358                 HandleReleaseDiskSpaceL( aMessage );
       
   359                 }
       
   360                 break;
       
   361             case ESysInfoSetHomeTime:
       
   362                 {
       
   363                 HTI_LOG_TEXT( "ESysInfoSetHomeTime" );
       
   364                 HandleSetHomeTimeL( aMessage );
       
   365                 }
       
   366                 break;
       
   367             case ESysInfoGetHomeTime:
       
   368                 {
       
   369                 HTI_LOG_TEXT( "ESysInfoGetHomeTime" );
       
   370                 HandleGetHomeTimeL( aMessage );
       
   371                 }
       
   372                 break;
       
   373             case ESetDateTimeFormat:
       
   374                 {
       
   375                 HTI_LOG_TEXT( "ESetDateTimeFormat" );
       
   376                 HandleSetDateTimeFormatL( aMessage );
       
   377                 }
       
   378                 break;
       
   379             case ESetLanguage:
       
   380                 {
       
   381                 HTI_LOG_TEXT("ESetLanguage");
       
   382                 HandleSetLanguageL( aMessage);
       
   383                 }
       
   384                 break;
       
   385             case ELightStatus:
       
   386             case ELightOn:
       
   387             case ELightOff:
       
   388             case ELightBlink:
       
   389             case ELightRelease:
       
   390                 {
       
   391                 HTI_LOG_TEXT( "ELight*" );
       
   392                 HandleLightsCommandL( aMessage );
       
   393                 }
       
   394                 break;
       
   395             case EScreenSaverDisable:
       
   396             case EScreenSaverEnable:
       
   397                 {
       
   398                 HTI_LOG_TEXT( "EScreenSaver*" );
       
   399                 HandleScreenSaverCommandL( aMessage );
       
   400                 }
       
   401                 break;
       
   402             case EScreenSaverTimeout:
       
   403                 {
       
   404                 HTI_LOG_TEXT( "EScreenSaverTimeout" );
       
   405                 HandleScreenSaverTimeoutCommandL( aMessage );
       
   406                 }
       
   407                 break;
       
   408             case ENetworkModeSet:
       
   409             case ENetworkModeSetNoReboot:
       
   410             case ENetworkModeGet:
       
   411                 {
       
   412                 HTI_LOG_TEXT( "ENetworkMode*" );
       
   413                 HandleNetworkModeCommandL( aMessage );
       
   414                 }
       
   415                 break;
       
   416             case EHsdpaSet:
       
   417                 {
       
   418                 HTI_LOG_TEXT( "EHsdpaSet" );
       
   419                 HandleHsdpaCommandL( aMessage );
       
   420                 }
       
   421                 break;
       
   422             case EIrActivate:
       
   423                 {
       
   424                 HTI_LOG_TEXT( "EIrActivate" );
       
   425                 HandleIrActivateCommandL( aMessage );
       
   426                 }
       
   427                 break;
       
   428             case EBtPower:
       
   429                 {
       
   430                 HTI_LOG_TEXT( "EBtPower" );
       
   431                 HandleBtPowerCommandL( aMessage );
       
   432                 }
       
   433                 break;
       
   434             case EBtSettings:
       
   435                 {
       
   436                 HTI_LOG_TEXT( "EBtSettings" );
       
   437                 HandleBtSettingsCommandL( aMessage );
       
   438                 }
       
   439                 break;
       
   440             case EBtDeletePairings:
       
   441                 {
       
   442                 HTI_LOG_TEXT( "EBtDeletePairings" );
       
   443                 HandleBtDeletePairingsL( aMessage );
       
   444                 }
       
   445                 break;
       
   446             case EKeylockToggle:
       
   447                 {
       
   448                 HTI_LOG_TEXT( "EKeylockToggle" );
       
   449                 HandleKeyLockToggleL( aMessage );
       
   450                 }
       
   451                 break;
       
   452             case EAutoKeyGuardTime:
       
   453                 {
       
   454                 HTI_LOG_TEXT( "EAutoKeyGuardTime" );
       
   455                 HandleAutoKeyGuardTimeL( aMessage );
       
   456                 }
       
   457                 break;
       
   458             case EEmtpyDrmRightsDb:
       
   459                 {
       
   460                 HTI_LOG_TEXT( "EEmtpyDrmRightsDb" );
       
   461                 HandleEmptyDrmRightsDbL( aMessage );
       
   462                 }
       
   463                 break;
       
   464             case EBatteryStatus:
       
   465                 {
       
   466                 HTI_LOG_TEXT( "EBatteryStatus" );
       
   467                 HandleBatteryStatusL( aMessage );
       
   468                 }
       
   469                 break;
       
   470             case ESignalStrength:
       
   471                 {
       
   472                 HTI_LOG_TEXT( "ESignalStrength" );
       
   473                 HandleSignalStrengthL( aMessage );
       
   474                 }
       
   475                 break;
       
   476             case EUpdateMediaGallery:
       
   477                 {
       
   478                 HTI_LOG_TEXT( "EUpdateMediaGallery" );
       
   479                 HandleUpdateMediaGalleryL( aMessage );
       
   480                 }
       
   481                 break;
       
   482             case EActivateSkin:
       
   483                 {
       
   484                 HTI_LOG_TEXT( "EActivateSkin" );
       
   485                 HandleActivateSkinL( aMessage );
       
   486                 }
       
   487                 break;
       
   488             default:
       
   489                 {
       
   490                 iDispatcher->DispatchOutgoingErrorMessage(
       
   491                     KErrArgument,
       
   492                     KErrDescrNotSupported,
       
   493                     KSysInfoServiceUid );
       
   494                 }
       
   495             }
       
   496         }
       
   497 
       
   498     else // aMessage.Length() > 0
       
   499         {
       
   500         iDispatcher->DispatchOutgoingErrorMessage(
       
   501             KErrArgument,
       
   502             KErrDescrArgument,
       
   503             KSysInfoServiceUid);
       
   504         }
       
   505 
       
   506     if ( iReply )
       
   507         {
       
   508         TInt err = iDispatcher->DispatchOutgoingMessage( iReply,
       
   509                                                          KSysInfoServiceUid );
       
   510         if ( err == KErrNoMemory )
       
   511             {
       
   512             HTI_LOG_TEXT( "KErrNoMemory" );
       
   513             iDispatcher->AddMemoryObserver( this );
       
   514             }
       
   515         else
       
   516             {
       
   517             iReply = NULL;
       
   518             }
       
   519         }
       
   520 
       
   521     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::ProcessMessage" );
       
   522     }
       
   523 
       
   524 //------------------------------------------------------------------------------
       
   525 // CHtiSysInfoServicePlugin::NotifyMemoryChange
       
   526 //------------------------------------------------------------------------------
       
   527 void CHtiSysInfoServicePlugin::NotifyMemoryChange( TInt aAvailableMemory )
       
   528     {
       
   529 
       
   530     if ( iReply )
       
   531         {
       
   532         if ( aAvailableMemory >= iReply->Size() )
       
   533             {
       
   534             TInt err = iDispatcher->DispatchOutgoingMessage(
       
   535                 iReply, KSysInfoServiceUid );
       
   536 
       
   537             if ( err == KErrNone )
       
   538                 {
       
   539                 iReply = NULL;
       
   540                 iDispatcher->RemoveMemoryObserver( this );
       
   541                 }
       
   542             else if ( err != KErrNoMemory ) //some other error
       
   543                 {
       
   544                 delete iReply;
       
   545                 iReply = NULL;
       
   546                 iDispatcher->RemoveMemoryObserver( this );
       
   547                 }
       
   548             }
       
   549         }
       
   550     else
       
   551         {
       
   552         // some error, should not be called
       
   553         iDispatcher->RemoveMemoryObserver( this );
       
   554         }
       
   555     }
       
   556 
       
   557 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 )
       
   558 //------------------------------------------------------------------------------
       
   559 // CHtiSysInfoServicePlugin::HandleAllowSSPropertyChange
       
   560 //------------------------------------------------------------------------------
       
   561 TInt CHtiSysInfoServicePlugin::HandleAllowSSPropertyChange( TAny* aPtr )
       
   562     {
       
   563     HTI_LOG_TEXT( "Allow SS property was changed" );
       
   564     TInt newValue = -1;
       
   565     TInt wantedValue =
       
   566         STATIC_CAST( CHtiSysInfoServicePlugin*, aPtr )->iAllowSSValue;
       
   567     RProperty::Get( KPSUidScreenSaver,
       
   568                     KScreenSaverAllowScreenSaver, newValue );
       
   569     HTI_LOG_FORMAT( "New value is %d", newValue );
       
   570 
       
   571     TInt err = KErrNone;
       
   572     if ( newValue == 0 && wantedValue == 1 )
       
   573         {
       
   574         HTI_LOG_TEXT( "Restoring the SS disabled value" );
       
   575         err = RProperty::Set( KPSUidScreenSaver,
       
   576                               KScreenSaverAllowScreenSaver, wantedValue );
       
   577         }
       
   578     return err;
       
   579     }
       
   580 
       
   581 #endif
       
   582 /*
       
   583  * Private helper methods
       
   584  */
       
   585 
       
   586 //------------------------------------------------------------------------------
       
   587 // CHtiSysInfoServicePlugin::HandleGetHalAttrL
       
   588 //------------------------------------------------------------------------------
       
   589 void CHtiSysInfoServicePlugin::HandleGetHalAttrL( const TDesC8& aMessage )
       
   590     {
       
   591     // check the message length
       
   592     if ( aMessage.Length() != 5 )
       
   593         {
       
   594         iDispatcher->DispatchOutgoingErrorMessage(
       
   595             KErrArgument,
       
   596             KErrDescrArgument,
       
   597             KSysInfoServiceUid );
       
   598         return;
       
   599         }
       
   600 
       
   601     TInt att =  aMessage[1] +
       
   602               ( aMessage[2] << 8  ) +
       
   603               ( aMessage[3] << 16 ) +
       
   604               ( aMessage[4] << 24 );
       
   605 
       
   606     // check that requested HAL attribute is valid
       
   607     if ( att < 0 || att >= HALData::ENumHalAttributes )
       
   608         {
       
   609         iDispatcher->DispatchOutgoingErrorMessage(
       
   610             KErrArgument,
       
   611             KErrDescrAttOutOfRange,
       
   612             KSysInfoServiceUid);
       
   613         return;
       
   614         }
       
   615 
       
   616     // get the HAL attribute
       
   617     TInt result;
       
   618     TInt err = HAL::Get( ( HALData::TAttribute ) att, result );
       
   619     if ( err )
       
   620         {
       
   621         iDispatcher->DispatchOutgoingErrorMessage(
       
   622             err,
       
   623             KErrDescrHAL,
       
   624             KSysInfoServiceUid );
       
   625         }
       
   626     else
       
   627         {
       
   628         iReply = HBufC8::NewL( 4 );
       
   629         iReply->Des().Append( ( TUint8* )( &result ), 4 );
       
   630         }
       
   631     }
       
   632 
       
   633 //------------------------------------------------------------------------------
       
   634 // CHtiSysInfoServicePlugin::HandleGetImeiL
       
   635 //------------------------------------------------------------------------------
       
   636 void CHtiSysInfoServicePlugin::HandleGetImeiL( const TDesC8& aMessage )
       
   637     {
       
   638     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleGetImeiL" );
       
   639 
       
   640     if ( aMessage.Length() != 1 )
       
   641         {
       
   642         iDispatcher->DispatchOutgoingErrorMessage( KErrArgument,
       
   643             KErrDescrArgument, KSysInfoServiceUid );
       
   644         return;
       
   645         }
       
   646 
       
   647 #if !defined (__WINS__) // no IMEI in emulator
       
   648     RTelServer server;
       
   649     User::LeaveIfError( server.Connect() );
       
   650     CleanupClosePushL( server );
       
   651     User::LeaveIfError( server.LoadPhoneModule( KMmTsyModuleName ) );
       
   652 
       
   653     RTelServer::TPhoneInfo info;
       
   654     TInt ret = KErrNotSupported;
       
   655     TInt count;
       
   656 
       
   657     RMobilePhone mobilePhone;
       
   658 
       
   659     User::LeaveIfError( server.EnumeratePhones( count ) );
       
   660 
       
   661     for ( TInt i = 0; i < count; i++ )
       
   662         {
       
   663         ret = server.GetPhoneInfo( i, info );
       
   664         if ( ret == KErrNone )
       
   665             {
       
   666             User::LeaveIfError( mobilePhone.Open( server, info.iName ) );
       
   667             CleanupClosePushL( mobilePhone );
       
   668             break;
       
   669             }
       
   670         }
       
   671 
       
   672     TRequestStatus status;
       
   673     RMobilePhone::TMobilePhoneIdentityV1 identity;
       
   674 
       
   675     mobilePhone.GetPhoneId( status, identity );
       
   676     User::WaitForRequest( status );
       
   677 
       
   678     CleanupStack::PopAndDestroy(); // mobilePhone
       
   679 
       
   680     server.UnloadPhoneModule( KMmTsyModuleName );
       
   681     CleanupStack::PopAndDestroy(); // server
       
   682 
       
   683     iReply = HBufC8::NewL( identity.iSerialNumber.Length() );
       
   684     iReply->Des().Copy( identity.iSerialNumber );
       
   685 
       
   686 #else // __WINS__
       
   687     // no IMEI in emulator
       
   688     iDispatcher->DispatchOutgoingErrorMessage( KErrNotSupported,
       
   689         KErrDescrNotSupported, KSysInfoServiceUid );
       
   690 #endif // __WINS__
       
   691     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleGetImeiL" );
       
   692     }
       
   693 
       
   694 //------------------------------------------------------------------------------
       
   695 // CHtiSysInfoServicePlugin::HandleGetSwVersionL
       
   696 //------------------------------------------------------------------------------
       
   697 void CHtiSysInfoServicePlugin::HandleGetSwVersionL( const TDesC8& aMessage )
       
   698     {
       
   699     if ( aMessage.Length() != 1 )
       
   700         {
       
   701         iDispatcher->DispatchOutgoingErrorMessage(
       
   702             KErrArgument,
       
   703             KErrDescrArgument,
       
   704             KSysInfoServiceUid);
       
   705         return;
       
   706         }
       
   707 
       
   708     TBuf<KSysUtilVersionTextLength> reply16;
       
   709     TInt err = SysUtil::GetSWVersion( reply16 );
       
   710     if ( err )
       
   711         {
       
   712         iDispatcher->DispatchOutgoingErrorMessage(
       
   713             err,
       
   714             KErrDescrSysUtil,
       
   715             KSysInfoServiceUid );
       
   716         }
       
   717     else
       
   718         {
       
   719         iReply = HBufC8::NewL( reply16.Size() );
       
   720         iReply->Des().Append( ( TUint8* )reply16.Ptr(), reply16.Size() );
       
   721         }
       
   722     }
       
   723 
       
   724 //------------------------------------------------------------------------------
       
   725 // CHtiSysInfoServicePlugin::HandleGetLangVersionL
       
   726 //------------------------------------------------------------------------------
       
   727 void CHtiSysInfoServicePlugin::HandleGetLangVersionL( const TDesC8& aMessage )
       
   728     {
       
   729     if ( aMessage.Length() != 1 )
       
   730         {
       
   731         iDispatcher->DispatchOutgoingErrorMessage(
       
   732             KErrArgument,
       
   733             KErrDescrArgument,
       
   734             KSysInfoServiceUid );
       
   735         return;
       
   736         }
       
   737 
       
   738     TBuf<KSysUtilVersionTextLength> reply16;
       
   739     TInt err = SysUtil::GetLangVersion( reply16 );
       
   740     if ( err )
       
   741         {
       
   742         iDispatcher->DispatchOutgoingErrorMessage(
       
   743             err,
       
   744             KErrDescrSysUtil,
       
   745             KSysInfoServiceUid );
       
   746         }
       
   747     else
       
   748         {
       
   749         iReply = HBufC8::NewL( reply16.Size() );
       
   750         iReply->Des().Append( ( TUint8* )reply16.Ptr(), reply16.Size() );
       
   751         }
       
   752     }
       
   753 
       
   754 //------------------------------------------------------------------------------
       
   755 // CHtiSysInfoServicePlugin::HandleGetSwLangVersionL
       
   756 //------------------------------------------------------------------------------
       
   757 void CHtiSysInfoServicePlugin::HandleGetSwLangVersionL( const TDesC8& aMessage )
       
   758     {
       
   759     if ( aMessage.Length() != 1 )
       
   760         {
       
   761         iDispatcher->DispatchOutgoingErrorMessage(
       
   762             KErrArgument,
       
   763             KErrDescrArgument,
       
   764             KSysInfoServiceUid);
       
   765         return;
       
   766         }
       
   767 
       
   768     TBuf<KSysUtilVersionTextLength> reply16;
       
   769     TInt err = SysUtil::GetLangSWVersion( reply16 );
       
   770     if ( err )
       
   771         {
       
   772         iDispatcher->DispatchOutgoingErrorMessage(
       
   773             err,
       
   774             KErrDescrSysUtil,
       
   775             KSysInfoServiceUid );
       
   776         }
       
   777     else
       
   778         {
       
   779         iReply = HBufC8::NewL( reply16.Size() );
       
   780         iReply->Des().Append( ( TUint8* )reply16.Ptr(), reply16.Size() );
       
   781         }
       
   782     }
       
   783 
       
   784 //------------------------------------------------------------------------------
       
   785 // CHtiSysInfoServicePlugin::HandleGetUserAgentStringL
       
   786 //------------------------------------------------------------------------------
       
   787 void CHtiSysInfoServicePlugin::HandleGetUserAgentStringL(
       
   788         const TDesC8& aMessage )
       
   789     {
       
   790     aMessage.Length(); // get rid of compiler warning
       
   791     iDispatcher->DispatchOutgoingErrorMessage(
       
   792         KErrNotSupported,
       
   793         KErrDescrNotSupported,
       
   794         KSysInfoServiceUid);
       
   795     }
       
   796 
       
   797 //------------------------------------------------------------------------------
       
   798 // CHtiSysInfoServicePlugin::HandleGetFreeRamL
       
   799 //------------------------------------------------------------------------------
       
   800 void CHtiSysInfoServicePlugin::HandleGetFreeRamL( const TDesC8& aMessage )
       
   801     {
       
   802     if ( aMessage.Length() != 1 )
       
   803         {
       
   804         iDispatcher->DispatchOutgoingErrorMessage(
       
   805             KErrArgument,
       
   806             KErrDescrArgument,
       
   807             KSysInfoServiceUid );
       
   808         return;
       
   809         }
       
   810 
       
   811     User::CompressAllHeaps();
       
   812     TInt result;
       
   813     TInt err = HAL::Get( HALData::EMemoryRAMFree, result );
       
   814     if ( err )
       
   815         {
       
   816         iDispatcher->DispatchOutgoingErrorMessage(
       
   817             err,
       
   818             KErrDescrFreeRAM,
       
   819             KSysInfoServiceUid );
       
   820         }
       
   821     else
       
   822         {
       
   823         iReply = HBufC8::NewL( 4 );
       
   824         iReply->Des().Append( ( TUint8* )( &result ), 4 );
       
   825         }
       
   826     }
       
   827 
       
   828 //------------------------------------------------------------------------------
       
   829 // CHtiSysInfoServicePlugin::HandleGetUsedRamL
       
   830 //------------------------------------------------------------------------------
       
   831 void CHtiSysInfoServicePlugin::HandleGetUsedRamL( const TDesC8& aMessage )
       
   832     {
       
   833     if ( aMessage.Length() != 1 )
       
   834         {
       
   835         iDispatcher->DispatchOutgoingErrorMessage(
       
   836             KErrArgument,
       
   837             KErrDescrArgument,
       
   838             KSysInfoServiceUid);
       
   839         return;
       
   840         }
       
   841 
       
   842     User::CompressAllHeaps();
       
   843 
       
   844     TInt totalRam;
       
   845     TInt freeRam;
       
   846     TInt usedRam;
       
   847 
       
   848     // first get the total RAM...
       
   849     TInt err = HAL::Get( HALData::EMemoryRAM, totalRam );
       
   850     if ( err != KErrNone )
       
   851         {
       
   852         iDispatcher->DispatchOutgoingErrorMessage(
       
   853             err,
       
   854             KErrDescrTotalRAM,
       
   855             KSysInfoServiceUid );
       
   856         return;
       
   857         }
       
   858 
       
   859     // ...then get the free RAM
       
   860     err = HAL::Get( HALData::EMemoryRAMFree, freeRam );
       
   861     if ( err )
       
   862         {
       
   863         iDispatcher->DispatchOutgoingErrorMessage(
       
   864             err,
       
   865             KErrDescrFreeRAM,
       
   866             KSysInfoServiceUid );
       
   867         return;
       
   868         }
       
   869 
       
   870     // calculate used RAM from total and free RAM
       
   871     usedRam = totalRam - freeRam;
       
   872     iReply = HBufC8::NewL( 4 );
       
   873     iReply->Des().Append( ( TUint8* )( &usedRam ), 4 );
       
   874     }
       
   875 
       
   876 //------------------------------------------------------------------------------
       
   877 // CHtiSysInfoServicePlugin::HandleGetTotalRamL
       
   878 //------------------------------------------------------------------------------
       
   879 void CHtiSysInfoServicePlugin::HandleGetTotalRamL( const TDesC8& aMessage )
       
   880     {
       
   881     if ( aMessage.Length() != 1 )
       
   882         {
       
   883         iDispatcher->DispatchOutgoingErrorMessage(
       
   884             KErrArgument,
       
   885             KErrDescrArgument,
       
   886             KSysInfoServiceUid);
       
   887         return;
       
   888         }
       
   889 
       
   890     User::CompressAllHeaps();
       
   891 
       
   892     TInt result;
       
   893     TInt err = HAL::Get( HALData::EMemoryRAM, result );
       
   894     if ( err )
       
   895         {
       
   896         iDispatcher->DispatchOutgoingErrorMessage(
       
   897             err,
       
   898             KErrDescrTotalRAM,
       
   899             KSysInfoServiceUid );
       
   900         }
       
   901     else
       
   902         {
       
   903         iReply = HBufC8::NewL( 4 );
       
   904         iReply->Des().Append( ( TUint8* )( &result ), 4 );
       
   905         }
       
   906     }
       
   907 
       
   908 //------------------------------------------------------------------------------
       
   909 // CHtiSysInfoServicePlugin::HandleEatRamL
       
   910 //------------------------------------------------------------------------------
       
   911 void CHtiSysInfoServicePlugin::HandleEatRamL( const TDesC8& aMessage )
       
   912     {
       
   913     if ( aMessage.Length() != 5 )
       
   914         {
       
   915         iDispatcher->DispatchOutgoingErrorMessage(
       
   916             KErrArgument,
       
   917             KErrDescrArgument,
       
   918             KSysInfoServiceUid );
       
   919         return;
       
   920         }
       
   921 
       
   922     // get the amount of memory to be left free from the message
       
   923     TInt memLeftFree =  aMessage[1] +
       
   924                       ( aMessage[2] << 8  ) +
       
   925                       ( aMessage[3] << 16 ) +
       
   926                       ( aMessage[4] << 24 );
       
   927 
       
   928     // if there's a previous memory eater, delete it
       
   929     if ( iMemEater != NULL )
       
   930         {
       
   931         delete iMemEater;
       
   932         iMemEater = NULL;
       
   933         }
       
   934 
       
   935     User::CompressAllHeaps();
       
   936 
       
   937     // get the current free memory
       
   938     TInt memFree;
       
   939     TInt err = HAL::Get( HALData::EMemoryRAMFree, memFree );
       
   940     if ( err )
       
   941         {
       
   942         iDispatcher->DispatchOutgoingErrorMessage(
       
   943             err,
       
   944             KErrDescrFreeRAM,
       
   945             KSysInfoServiceUid );
       
   946         return;
       
   947         }
       
   948 
       
   949     // try to eat the memory
       
   950     TInt memToBeEaten = memFree - memLeftFree;
       
   951 
       
   952     if ( memToBeEaten < 0 )
       
   953         {
       
   954         iDispatcher->DispatchOutgoingErrorMessage(
       
   955                 KErrUnderflow,
       
   956                 KErrDescrInvalidRAM,
       
   957                 KSysInfoServiceUid );
       
   958         return;
       
   959         }
       
   960 
       
   961     TRAP( err, iMemEater = HBufC8::NewL( memToBeEaten ) );
       
   962     if ( err )
       
   963         {
       
   964         iDispatcher->DispatchOutgoingErrorMessage(
       
   965             err,
       
   966             KErrDescrAllocRAM,
       
   967             KSysInfoServiceUid );
       
   968         return;
       
   969         }
       
   970 
       
   971     // get the amount of memory left
       
   972     err = HAL::Get( HALData::EMemoryRAMFree, memFree );
       
   973     if ( err )
       
   974         {
       
   975         iDispatcher->DispatchOutgoingErrorMessage(
       
   976             err,
       
   977             KErrDescrFreeRAM,
       
   978             KSysInfoServiceUid );
       
   979         return;
       
   980         }
       
   981 
       
   982     // send the amount of memory back
       
   983     iReply = HBufC8::NewL( 4 );
       
   984     iReply->Des().Append( ( TUint8* )( &memFree ), 4 );
       
   985     }
       
   986 
       
   987 //------------------------------------------------------------------------------
       
   988 // CHtiSysInfoServicePlugin::HandleReleaseRamL
       
   989 //------------------------------------------------------------------------------
       
   990 void CHtiSysInfoServicePlugin::HandleReleaseRamL( const TDesC8& aMessage )
       
   991     {
       
   992     if ( aMessage.Length() != 1 )
       
   993         {
       
   994         iDispatcher->DispatchOutgoingErrorMessage(
       
   995             KErrArgument,
       
   996             KErrDescrArgument,
       
   997             KSysInfoServiceUid );
       
   998         return;
       
   999         }
       
  1000 
       
  1001     // if there's a memory eater, delete it
       
  1002     if ( iMemEater != NULL )
       
  1003         {
       
  1004         delete iMemEater;
       
  1005         iMemEater = NULL;
       
  1006         }
       
  1007 
       
  1008     User::CompressAllHeaps();
       
  1009 
       
  1010     // query the amount of memory and send it back
       
  1011     TInt memFree;
       
  1012     TInt err = HAL::Get( HALData::EMemoryRAMFree, memFree );
       
  1013     if ( err )
       
  1014         {
       
  1015         iDispatcher->DispatchOutgoingErrorMessage(
       
  1016             err,
       
  1017             KErrDescrHAL,
       
  1018             KSysInfoServiceUid );
       
  1019         }
       
  1020     else
       
  1021         {
       
  1022         iReply = HBufC8::NewL( 4 );
       
  1023         iReply->Des().Append( ( TUint8* )( &memFree ), 4 );
       
  1024         }
       
  1025     }
       
  1026 
       
  1027 //------------------------------------------------------------------------------
       
  1028 // CHtiSysInfoServicePlugin::HandleGetFreeDiskSpaceL
       
  1029 //------------------------------------------------------------------------------
       
  1030 void CHtiSysInfoServicePlugin::HandleGetFreeDiskSpaceL( const TDesC8& aMessage )
       
  1031     {
       
  1032     if ( aMessage.Length() != 2 )
       
  1033         {
       
  1034         iDispatcher->DispatchOutgoingErrorMessage(
       
  1035             KErrArgument,
       
  1036             KErrDescrArgument,
       
  1037             KSysInfoServiceUid);
       
  1038         return;
       
  1039         }
       
  1040 
       
  1041     TInt drive;
       
  1042     RFs::CharToDrive( TChar( aMessage[1] ), drive );
       
  1043     TVolumeInfo volInfo;
       
  1044     TInt err = iFs.Volume( volInfo, drive );
       
  1045 
       
  1046     if ( err )
       
  1047         {
       
  1048         iDispatcher->DispatchOutgoingErrorMessage(
       
  1049             err,
       
  1050             KErrDescrVolInfo,
       
  1051             KSysInfoServiceUid );
       
  1052         }
       
  1053     else
       
  1054         {
       
  1055         iReply = HBufC8::NewL( 8 );
       
  1056         iReply->Des().Append( ( TUint8* )( &volInfo.iFree ), 8 );
       
  1057         }
       
  1058     }
       
  1059 
       
  1060 //------------------------------------------------------------------------------
       
  1061 // CHtiSysInfoServicePlugin::HandleGetUsedDiskSpaceL
       
  1062 //------------------------------------------------------------------------------
       
  1063 void CHtiSysInfoServicePlugin::HandleGetUsedDiskSpaceL( const TDesC8& aMessage )
       
  1064     {
       
  1065     if ( aMessage.Length() != 2 )
       
  1066         {
       
  1067         iDispatcher->DispatchOutgoingErrorMessage(
       
  1068             KErrArgument,
       
  1069             KErrDescrArgument,
       
  1070             KSysInfoServiceUid);
       
  1071         return;
       
  1072         }
       
  1073 
       
  1074     TInt drive;
       
  1075     RFs::CharToDrive( TChar( aMessage[1] ), drive );
       
  1076     TVolumeInfo volInfo;
       
  1077     TInt err = iFs.Volume( volInfo, drive );
       
  1078 
       
  1079     if ( err )
       
  1080         {
       
  1081         iDispatcher->DispatchOutgoingErrorMessage(
       
  1082             err,
       
  1083             KErrDescrVolInfo,
       
  1084             KSysInfoServiceUid );
       
  1085         }
       
  1086     else
       
  1087         {
       
  1088         TInt64 used = volInfo.iSize - volInfo.iFree;
       
  1089         iReply = HBufC8::NewL( 8 );
       
  1090         iReply->Des().Append( ( TUint8* )( &used ), 8 );
       
  1091         }
       
  1092     }
       
  1093 
       
  1094 //------------------------------------------------------------------------------
       
  1095 // CHtiSysInfoServicePlugin::HandleGetTotalDiskSpaceL
       
  1096 //------------------------------------------------------------------------------
       
  1097 void CHtiSysInfoServicePlugin::HandleGetTotalDiskSpaceL(
       
  1098         const TDesC8& aMessage )
       
  1099     {
       
  1100     if ( aMessage.Length() != 2 )
       
  1101         {
       
  1102         iDispatcher->DispatchOutgoingErrorMessage(
       
  1103             KErrArgument,
       
  1104             KErrDescrArgument,
       
  1105             KSysInfoServiceUid);
       
  1106         return;
       
  1107         }
       
  1108 
       
  1109     TInt drive;
       
  1110     RFs::CharToDrive( TChar( aMessage[1] ), drive );
       
  1111     TVolumeInfo volInfo;
       
  1112     TInt err = iFs.Volume( volInfo, drive );
       
  1113 
       
  1114     if ( err )
       
  1115         {
       
  1116         iDispatcher->DispatchOutgoingErrorMessage(
       
  1117             err,
       
  1118             KErrDescrVolInfo,
       
  1119             KSysInfoServiceUid );
       
  1120         }
       
  1121     else
       
  1122         {
       
  1123         iReply = HBufC8::NewL( 8 );
       
  1124         iReply->Des().Append( ( TUint8* )( &volInfo.iSize ), 8 );
       
  1125         }
       
  1126     }
       
  1127 
       
  1128 //------------------------------------------------------------------------------
       
  1129 // CHtiSysInfoServicePlugin::HandleEatDiskSpaceL
       
  1130 //------------------------------------------------------------------------------
       
  1131 void CHtiSysInfoServicePlugin::HandleEatDiskSpaceL( const TDesC8& aMessage )
       
  1132     {
       
  1133     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleEatDiskSpaceL" );
       
  1134     
       
  1135     if ( aMessage.Length() != 10 )
       
  1136         {
       
  1137         iDispatcher->DispatchOutgoingErrorMessage(
       
  1138             KErrArgument,
       
  1139             KErrDescrArgument,
       
  1140             KSysInfoServiceUid );
       
  1141         HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleEatDiskSpaceL" );
       
  1142         return;
       
  1143         }
       
  1144 
       
  1145     TFileName commonpath;
       
  1146     commonpath.Append( aMessage[1] );
       
  1147     commonpath.Append( _L( ":" ) );
       
  1148     commonpath.Append( KTempFilePath );
       
  1149     commonpath.Append( KTempFileName );
       
  1150     TFileName path;
       
  1151         
       
  1152     // get free disk space
       
  1153     TInt drive;
       
  1154     RFs::CharToDrive( TChar( aMessage[1] ), drive );
       
  1155     TVolumeInfo volInfo;
       
  1156     TInt err = iFs.Volume( volInfo, drive );
       
  1157     if ( err )
       
  1158         {
       
  1159         iDispatcher->DispatchOutgoingErrorMessage(
       
  1160             err,
       
  1161             KErrDescrVolInfo,
       
  1162             KSysInfoServiceUid );
       
  1163         HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleEatDiskSpaceL" );
       
  1164         return;
       
  1165         }
       
  1166 
       
  1167     // calculate how much we must eat the disk space
       
  1168     TInt64 temp1 = aMessage[2] +
       
  1169                  ( aMessage[3] << 8  ) +
       
  1170                  ( aMessage[4] << 16 ) +
       
  1171                  ( aMessage[5] << 24 );
       
  1172     TInt64 temp2 = aMessage[6] +
       
  1173                  ( aMessage[7] << 8  ) +
       
  1174                  ( aMessage[8] << 16 ) +
       
  1175                  ( aMessage[9] << 24 );
       
  1176 
       
  1177     TInt64 spaceLeftFree = temp1 + ( temp2 << 32) ;
       
  1178     TInt64 spaceToEat = volInfo.iFree - spaceLeftFree;
       
  1179 
       
  1180     HTI_LOG_FORMAT( "Disk space to eat: %Ld", spaceToEat );
       
  1181 
       
  1182     // check that there is enough free disk space
       
  1183     if ( spaceToEat < 0 )
       
  1184         {
       
  1185         iDispatcher->DispatchOutgoingErrorMessage(
       
  1186             KErrDiskFull,
       
  1187             KErrDescrNotEnoughSpace,
       
  1188             KSysInfoServiceUid );
       
  1189         HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleEatDiskSpaceL" );
       
  1190         return;
       
  1191         }
       
  1192 
       
  1193     // check if scaceToEat is greater than KMaxTInt
       
  1194     //  --> it must be eaten in several chunks
       
  1195     //  --> not yet supported.
       
  1196 
       
  1197     TInt64 size;
       
  1198     for(TInt i=1;  spaceToEat>0; i++)
       
  1199         {
       
  1200         path.Zero();
       
  1201         path.Copy(commonpath);
       
  1202         path.AppendNum(i);
       
  1203         if ( BaflUtils::FileExists( iFs, path ) )
       
  1204             {
       
  1205             continue;
       
  1206             }
       
  1207         
       
  1208         if(spaceToEat > KMaxTInt)  
       
  1209             size=KMaxTInt;
       
  1210         else
       
  1211             size=spaceToEat;
       
  1212         
       
  1213         err = CreatFileToEatDiskSpace(path, size);
       
  1214         if(err)
       
  1215             { 
       
  1216             HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleEatDiskSpaceL CreateFile Fail" );
       
  1217             return;  
       
  1218             }        
       
  1219         
       
  1220         iFs.Volume( volInfo, drive );
       
  1221         HTI_LOG_FORMAT( "current free space: %Ld", volInfo.iFree );
       
  1222         spaceToEat = volInfo.iFree - spaceLeftFree;           
       
  1223         }
       
  1224 
       
  1225     // all ok, send the remaining disk size back
       
  1226     iReply = HBufC8::NewL( 8 );
       
  1227     iReply->Des().Append( ( TUint8* )( &volInfo.iFree ), 8 );
       
  1228     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleEatDiskSpaceL" );
       
  1229     }
       
  1230 
       
  1231 TInt CHtiSysInfoServicePlugin::CreatFileToEatDiskSpace( TFileName aPath, TInt64 aSpaceToEat  )
       
  1232     {
       
  1233     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::CreatFileToEatDiskSpace" );
       
  1234     
       
  1235     HTI_LOG_FORMAT( "Create file: %S", &aPath );
       
  1236     HTI_LOG_FORMAT( "file size %Ld", aSpaceToEat );
       
  1237     
       
  1238     // create a temp file
       
  1239     RFile diskEater;
       
  1240     TInt err = diskEater.Replace( iFs, aPath, EFileWrite );
       
  1241     if ( err )
       
  1242         {
       
  1243         iDispatcher->DispatchOutgoingErrorMessage(
       
  1244             err,
       
  1245             KErrDescrCreateTempFile,
       
  1246             KSysInfoServiceUid );
       
  1247         HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::CreatFileToEatDiskSpace Replace error" );
       
  1248         return err;
       
  1249         }
       
  1250     
       
  1251     // set the size for temp file
       
  1252     err = diskEater.SetSize( I64LOW( aSpaceToEat ) );
       
  1253     if ( err )
       
  1254         {
       
  1255         iDispatcher->DispatchOutgoingErrorMessage(
       
  1256             err,
       
  1257             KErrDescrSetSizeTempFile,
       
  1258             KSysInfoServiceUid );
       
  1259         diskEater.Close();
       
  1260         HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::CreatFileToEatDiskSpace SetSize error" );
       
  1261         return err;
       
  1262         }
       
  1263     diskEater.Close();
       
  1264     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::CreatFileToEatDiskSpace" );
       
  1265     return 0;
       
  1266     }
       
  1267 
       
  1268 //------------------------------------------------------------------------------
       
  1269 // CHtiSysInfoServicePlugin::HandleReleaseDiskSpaceL
       
  1270 //------------------------------------------------------------------------------
       
  1271 void CHtiSysInfoServicePlugin::HandleReleaseDiskSpaceL( const TDesC8& aMessage )
       
  1272     {
       
  1273     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleReleaseDiskSpaceL" );
       
  1274     if ( aMessage.Length() != 2 )
       
  1275         {
       
  1276         iDispatcher->DispatchOutgoingErrorMessage(
       
  1277             KErrArgument,
       
  1278             KErrDescrArgument,
       
  1279             KSysInfoServiceUid);
       
  1280         HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleReleaseDiskSpaceL" );
       
  1281         return;
       
  1282         }
       
  1283 
       
  1284     TFileName path;
       
  1285     path.Append( aMessage[1] );
       
  1286     path.Append( _L( ":" ) );
       
  1287     path.Append(KTempFilePath);
       
  1288     path.Append(KMatchFileName);
       
  1289     TInt err = iFileMan->Delete(path);
       
  1290     if ( err )
       
  1291         {
       
  1292         iDispatcher->DispatchOutgoingErrorMessage(
       
  1293                 err,
       
  1294                 KErrDescrDeleteTempFile,
       
  1295                 KSysInfoServiceUid );
       
  1296         HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleReleaseDiskSpaceL" );
       
  1297         return;
       
  1298         } 
       
  1299     
       
  1300     // query the free disk space
       
  1301     TInt drive;
       
  1302     RFs::CharToDrive( TChar( aMessage[1] ), drive );
       
  1303     TVolumeInfo volInfo;
       
  1304     err = iFs.Volume( volInfo, drive );
       
  1305     if ( err )
       
  1306         {
       
  1307         iDispatcher->DispatchOutgoingErrorMessage(
       
  1308             err,
       
  1309             KErrDescrVolInfo,
       
  1310             KSysInfoServiceUid );
       
  1311         HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleReleaseDiskSpaceL" );
       
  1312         return;
       
  1313         }
       
  1314 
       
  1315     // all ok, send the free disk space back
       
  1316     iReply = HBufC8::NewL( 8 );
       
  1317     iReply->Des().Append( ( TUint8* )( &volInfo.iFree ), 8 );
       
  1318 
       
  1319     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleReleaseDiskSpaceL" );
       
  1320     }
       
  1321 
       
  1322 //------------------------------------------------------------------------------
       
  1323 // CHtiSysInfoServicePlugin::HandleSetHomeTimeL
       
  1324 //------------------------------------------------------------------------------
       
  1325 void CHtiSysInfoServicePlugin::HandleSetHomeTimeL( const TDesC8& aMessage )
       
  1326     {
       
  1327     TTime time;
       
  1328     TRAPD( err, ParseTimeDataL( aMessage.Mid( 1 ), time ) );
       
  1329     if ( err )
       
  1330         {
       
  1331         iDispatcher->DispatchOutgoingErrorMessage( err,
       
  1332                                KErrDescrArgument,
       
  1333                                KSysInfoServiceUid);
       
  1334         return;
       
  1335         }
       
  1336 
       
  1337     // User::SetHomeTime() does not work correctly with daylight saving time
       
  1338     // in S60 3.0 - have to use time zone server instead.
       
  1339     RTz tzServer;
       
  1340     err = tzServer.Connect();
       
  1341     if ( err == KErrNone )
       
  1342         {
       
  1343         err = tzServer.SetHomeTime( time );
       
  1344         }
       
  1345     tzServer.Close();
       
  1346 
       
  1347     if ( err )
       
  1348         {
       
  1349         iDispatcher->DispatchOutgoingErrorMessage( err,
       
  1350                                KErrDescrSetTime,
       
  1351                                KSysInfoServiceUid);
       
  1352         return;
       
  1353         }
       
  1354 
       
  1355     iReply = HBufC8::NewL( 1 );
       
  1356     iReply->Des().Append( 0 );
       
  1357     }
       
  1358 
       
  1359 //------------------------------------------------------------------------------
       
  1360 // CHtiSysInfoServicePlugin::HandleGetHomeTimeL
       
  1361 //------------------------------------------------------------------------------
       
  1362 void CHtiSysInfoServicePlugin::HandleGetHomeTimeL( const TDesC8& aMessage )
       
  1363     {
       
  1364     if ( aMessage.Length() != 1 )
       
  1365         {
       
  1366         iDispatcher->DispatchOutgoingErrorMessage(
       
  1367             KErrArgument,
       
  1368             KErrDescrArgument,
       
  1369             KSysInfoServiceUid );
       
  1370 
       
  1371         return;
       
  1372         }
       
  1373 
       
  1374     TTime time;
       
  1375     time.HomeTime();
       
  1376     TDateTime dateTime = time.DateTime();
       
  1377     TUint year = dateTime.Year();
       
  1378     iReply = HBufC8::NewL( KTimeDataLength );
       
  1379     iReply->Des().Append( (TUint8*)(&year), 2 );
       
  1380     iReply->Des().Append( dateTime.Month() + 1 );
       
  1381     iReply->Des().Append( dateTime.Day() + 1 );
       
  1382     iReply->Des().Append( dateTime.Hour() );
       
  1383     iReply->Des().Append( dateTime.Minute() );
       
  1384     iReply->Des().Append( dateTime.Second() );
       
  1385     }
       
  1386 
       
  1387 
       
  1388 //------------------------------------------------------------------------------
       
  1389 // CHtiSysInfoServicePlugin::HandleSetDateTimeFormatL
       
  1390 //------------------------------------------------------------------------------
       
  1391 void CHtiSysInfoServicePlugin::HandleSetDateTimeFormatL( const TDesC8& aMessage )
       
  1392     {
       
  1393     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleSetDateTimeFormatL" );
       
  1394 
       
  1395     if ( aMessage.Length() != KDateTimeFormatCmdLength )
       
  1396         {
       
  1397         iDispatcher->DispatchOutgoingErrorMessage( KErrArgument,
       
  1398             KErrDescrArgument, KSysInfoServiceUid );
       
  1399         return;
       
  1400         }
       
  1401 
       
  1402     // Parse values from message
       
  1403     TDateFormat dateFormat = STATIC_CAST( TDateFormat, aMessage[1] );
       
  1404     TChar dateSepar = aMessage[2];
       
  1405     TTimeFormat timeFormat = STATIC_CAST( TTimeFormat, aMessage[3] );
       
  1406     TChar timeSepar = aMessage[4];
       
  1407     TClockFormat clockFormat = STATIC_CAST( TClockFormat, aMessage[5] );
       
  1408 
       
  1409     HTI_LOG_FORMAT( "Date format   : %d", dateFormat );
       
  1410     HTI_LOG_FORMAT( "Date separator: %c", aMessage[2] );
       
  1411     HTI_LOG_FORMAT( "Time format   : %d", timeFormat );
       
  1412     HTI_LOG_FORMAT( "Time separator: %c", aMessage[4] );
       
  1413     HTI_LOG_FORMAT( "Clock format  : %d", clockFormat );
       
  1414 
       
  1415     // Check validity of values
       
  1416     if ( dateFormat < EDateAmerican || dateFormat > EDateJapanese ||
       
  1417          timeFormat < ETime12 || timeFormat > ETime24 ||
       
  1418          clockFormat < EClockAnalog || clockFormat > EClockDigital ||
       
  1419          KDateSeparatorChars().Locate( dateSepar ) == KErrNotFound ||
       
  1420          KTimeSeparatorChars().Locate( timeSepar ) == KErrNotFound )
       
  1421         {
       
  1422         iDispatcher->DispatchOutgoingErrorMessage( KErrArgument,
       
  1423             KErrDescrArgument, KSysInfoServiceUid );
       
  1424         return;
       
  1425         }
       
  1426 
       
  1427     // Set the values
       
  1428     TLocale locale;
       
  1429     locale.SetDateFormat( dateFormat );
       
  1430     locale.SetDateSeparator( dateSepar, 1 );
       
  1431     locale.SetDateSeparator( dateSepar, 2 );
       
  1432     locale.SetTimeFormat( timeFormat );
       
  1433     locale.SetTimeSeparator( timeSepar, 1 );
       
  1434     locale.SetTimeSeparator( timeSepar, 2 );
       
  1435     locale.SetClockFormat( clockFormat );
       
  1436     TInt err = locale.Set();
       
  1437 
       
  1438     if ( err != KErrNone )
       
  1439         {
       
  1440         iDispatcher->DispatchOutgoingErrorMessage( err,
       
  1441             KErrDescrDateTimeFormat, KSysInfoServiceUid );
       
  1442         }
       
  1443     else
       
  1444         {
       
  1445         iReply = HBufC8::NewL( 1 );
       
  1446         iReply->Des().Append( 0 );
       
  1447         }
       
  1448 
       
  1449     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleSetDateTimeFormatL" );
       
  1450     }
       
  1451 
       
  1452 
       
  1453 //------------------------------------------------------------------------------
       
  1454 // CHtiSysInfoServicePlugin::HandleLightsCommandL
       
  1455 //------------------------------------------------------------------------------
       
  1456 void CHtiSysInfoServicePlugin::HandleLightsCommandL( const TDesC8& aMessage )
       
  1457     {
       
  1458     if ( aMessage[0] == ELightRelease )
       
  1459         {
       
  1460         if ( aMessage.Length() != 1 )
       
  1461             {
       
  1462             iDispatcher->DispatchOutgoingErrorMessage(
       
  1463                 KErrArgument,
       
  1464                 KErrDescrArgument,
       
  1465                 KSysInfoServiceUid);
       
  1466             }
       
  1467 
       
  1468         else
       
  1469             {
       
  1470             HTI_LOG_TEXT( "ELightRelease" );
       
  1471             delete iLightsController;
       
  1472             iLightsController = NULL;
       
  1473             iReply = HBufC8::NewL( 1 );
       
  1474             iReply->Des().Append( 0 );
       
  1475             }
       
  1476         }
       
  1477 
       
  1478     else
       
  1479         {
       
  1480         if ( !iLightsController )
       
  1481             {
       
  1482             HTI_LOG_TEXT( "Creating lights controller" );
       
  1483             iLightsController = CHtiLightsController::NewL(
       
  1484                                     iDispatcher );
       
  1485             }
       
  1486         TBuf8<4> reply;
       
  1487         iLightsController->ProcessMessageL( aMessage, reply );
       
  1488         if ( reply.Length() > 0 )
       
  1489             {
       
  1490             iReply = HBufC8::NewL( reply.Length() );
       
  1491             iReply->Des().Copy( reply );
       
  1492             }
       
  1493         }
       
  1494     }
       
  1495 
       
  1496 //------------------------------------------------------------------------------
       
  1497 // CHtiSysInfoServicePlugin::HandleScreenSaverCommandL
       
  1498 //------------------------------------------------------------------------------
       
  1499 void CHtiSysInfoServicePlugin::HandleScreenSaverCommandL(
       
  1500                                     const TDesC8& aMessage )
       
  1501     {
       
  1502     HTI_LOG_FUNC_IN(
       
  1503             "CHtiSysInfoServicePlugin::HandleScreenSaverCommandL" );
       
  1504 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 ) 
       
  1505     if ( aMessage.Length() != 1 )
       
  1506         {
       
  1507         iDispatcher->DispatchOutgoingErrorMessage(
       
  1508             KErrArgument,
       
  1509             KErrDescrArgument,
       
  1510             KSysInfoServiceUid);
       
  1511         return;
       
  1512         }
       
  1513 
       
  1514     if ( aMessage[0] == EScreenSaverDisable ) iAllowSSValue = 1;
       
  1515     else if ( aMessage[0] == EScreenSaverEnable ) iAllowSSValue = 0;
       
  1516     else User::Leave( KErrArgument );
       
  1517 
       
  1518     HTI_LOG_FORMAT( "Setting allow screen saver state %d", iAllowSSValue );
       
  1519 
       
  1520     TInt err = KErrNone;
       
  1521 
       
  1522     if ( !iAllowSSPropertyAttached )
       
  1523         {
       
  1524         HTI_LOG_TEXT( "Attaching to KScreenSaverAllowScreenSaver property" );
       
  1525         err = iAllowSSProperty.Attach(
       
  1526                 KPSUidScreenSaver, KScreenSaverAllowScreenSaver );
       
  1527 
       
  1528         if ( err )
       
  1529             {
       
  1530             iDispatcher->DispatchOutgoingErrorMessage(
       
  1531                 err, KErrDescrScreenSaver, KSysInfoServiceUid );
       
  1532             return;
       
  1533             }
       
  1534 
       
  1535         iAllowSSPropertyAttached = ETrue;
       
  1536         }
       
  1537 
       
  1538     if ( iAllowSSValue == 1 )
       
  1539         {
       
  1540         iAllowSSProperty.Set( iAllowSSValue ); // ignore error
       
  1541         // Screen saver disabled. We want to keep it disabled, so
       
  1542         // subscribe to the property to get notified about changes in it.
       
  1543         if ( !iAllowSSSubscriber )
       
  1544             {
       
  1545             iAllowSSSubscriber = new (ELeave) CHtiPropertySubscriber(
       
  1546                 TCallBack( HandleAllowSSPropertyChange, this ),
       
  1547                 iAllowSSProperty );
       
  1548             iAllowSSSubscriber->Subscribe();
       
  1549             }
       
  1550         }
       
  1551 
       
  1552     else  // iAllowSSValue == 0
       
  1553         {
       
  1554         // Enabling screen saver. Cancel possible subscription so
       
  1555         // other applications can control the property.
       
  1556         if ( iAllowSSSubscriber )
       
  1557             {
       
  1558             iAllowSSSubscriber->Unsubscribe();
       
  1559             }
       
  1560         iAllowSSProperty.Set( iAllowSSValue ); // ignore error
       
  1561         iAllowSSProperty.Close();
       
  1562         iAllowSSPropertyAttached = EFalse;
       
  1563         delete iAllowSSSubscriber;
       
  1564         iAllowSSSubscriber = NULL;
       
  1565         }
       
  1566 
       
  1567     iReply = HBufC8::NewL( 1 );
       
  1568     iReply->Des().Append( 0 );
       
  1569 #else
       
  1570     iDispatcher->DispatchOutgoingErrorMessage(KErrArgument,
       
  1571             KErrDescrNotSupported, KSysInfoServiceUid);
       
  1572 #endif 
       
  1573     HTI_LOG_FUNC_OUT(
       
  1574                 "CHtiSysInfoServicePlugin::HandleScreenSaverCommandL" );
       
  1575     }
       
  1576 
       
  1577 //------------------------------------------------------------------------------
       
  1578 // CHtiSysInfoServicePlugin::HandleScreenSaverTimeoutCommandL
       
  1579 //------------------------------------------------------------------------------
       
  1580 void CHtiSysInfoServicePlugin::HandleScreenSaverTimeoutCommandL(
       
  1581                                     const TDesC8& aMessage )
       
  1582     {
       
  1583     HTI_LOG_FUNC_IN(
       
  1584             "CHtiSysInfoServicePlugin::HandleScreenSaverTimeoutCommandL" );
       
  1585 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 )
       
  1586     if ( aMessage.Length() != 2 )
       
  1587         {
       
  1588         iDispatcher->DispatchOutgoingErrorMessage(
       
  1589             KErrArgument,
       
  1590             KErrDescrArgument,
       
  1591             KSysInfoServiceUid);
       
  1592         return;
       
  1593         }
       
  1594 
       
  1595     TInt time = aMessage[1];
       
  1596     HTI_LOG_FORMAT( "Requested timeout %d", time );
       
  1597     if ( time < 5 )
       
  1598         {
       
  1599         iDispatcher->DispatchOutgoingErrorMessage( KErrArgument,
       
  1600             KErrDescrInvalidSSTimeout, KSysInfoServiceUid );
       
  1601         return;
       
  1602         }
       
  1603 
       
  1604     CRepository* persRep = CRepository::NewL( KCRUidPersonalizationSettings );
       
  1605     TInt err = persRep->Set( KSettingsScreenSaverPeriod, time );
       
  1606 
       
  1607     if ( err == KErrNone )
       
  1608         {
       
  1609         iReply = HBufC8::NewL( 1 );
       
  1610         iReply->Des().Append( 0 );
       
  1611         }
       
  1612 
       
  1613     else
       
  1614         {
       
  1615         iDispatcher->DispatchOutgoingErrorMessage( err,
       
  1616             KErrDescrSSTimeoutFailed, KSysInfoServiceUid );
       
  1617         }
       
  1618 
       
  1619     delete persRep;
       
  1620 #else
       
  1621     iDispatcher->DispatchOutgoingErrorMessage(KErrArgument,
       
  1622             KErrDescrNotSupported, KSysInfoServiceUid);
       
  1623 #endif 
       
  1624     HTI_LOG_FUNC_OUT(
       
  1625         "CHtiSysInfoServicePlugin::HandleScreenSaverTimeoutCommandL" );
       
  1626     }
       
  1627 
       
  1628 //------------------------------------------------------------------------------
       
  1629 // CHtiSysInfoServicePlugin::HandleNetworkModeCommandL
       
  1630 //------------------------------------------------------------------------------
       
  1631 void CHtiSysInfoServicePlugin::HandleNetworkModeCommandL( const TDesC8& aMessage )
       
  1632 {
       
  1633     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleNetworkModeCommandL" );
       
  1634 
       
  1635     TInt err = StartC32();
       
  1636     if ( ( err != KErrNone ) && ( err != KErrAlreadyExists ) )
       
  1637         {
       
  1638         HTI_LOG_FORMAT( "StartC32 failed %d", err );
       
  1639         User::Leave( err );
       
  1640         }
       
  1641 
       
  1642     // Connect to telephony server
       
  1643     RTelServer telServer;
       
  1644     err = telServer.Connect();
       
  1645     if ( err != KErrNone )
       
  1646         {
       
  1647         HTI_LOG_FORMAT( "RTelServer::Connect() failed %d", err );
       
  1648         User::Leave( err );
       
  1649         }
       
  1650     CleanupClosePushL( telServer );
       
  1651 
       
  1652     // load phonetsy
       
  1653     err = telServer.LoadPhoneModule( KMmTsyModuleName );
       
  1654     if ( err != KErrNone )
       
  1655         {
       
  1656         HTI_LOG_FORMAT( "RTelServer::LoadPhoneModule() failed %d", err );
       
  1657         User::Leave( err );
       
  1658         }
       
  1659 
       
  1660     // get phones
       
  1661     TInt noOfPhones;
       
  1662     err = telServer.EnumeratePhones( noOfPhones );
       
  1663     if ( err != KErrNone )
       
  1664         {
       
  1665         HTI_LOG_FORMAT( "RTelServer::EnumeratePhones() failed %d", err );
       
  1666         User::Leave( err );
       
  1667         }
       
  1668 
       
  1669     if ( noOfPhones == 0 )
       
  1670         {
       
  1671         HTI_LOG_TEXT( "No phones found" );
       
  1672         User::Leave( KErrNotFound );
       
  1673         }
       
  1674 
       
  1675     HTI_LOG_FORMAT( "noOfPhones %d", noOfPhones );
       
  1676 
       
  1677     RTelServer::TPhoneInfo phoneInfo;
       
  1678     for ( TInt i = 0; i < noOfPhones; i++ )
       
  1679         {
       
  1680         TName phoneTsy;
       
  1681         telServer.GetTsyName( i, phoneTsy );
       
  1682         HTI_LOG_DES( phoneTsy );
       
  1683 
       
  1684         err = telServer.GetPhoneInfo( i, phoneInfo );
       
  1685         if ( err != KErrNone )
       
  1686             {
       
  1687             HTI_LOG_FORMAT( "RTelServer::GetPhoneInfo() %d", i );
       
  1688             HTI_LOG_FORMAT( "failed %d", err );
       
  1689             User::Leave( err );
       
  1690             }
       
  1691         HTI_LOG_DES( phoneInfo.iName );
       
  1692         }
       
  1693 
       
  1694     // open phone
       
  1695     RMobilePhone phone;
       
  1696     err = phone.Open( telServer, phoneInfo.iName );
       
  1697     if ( err != KErrNone )
       
  1698         {
       
  1699         HTI_LOG_FORMAT( "RMobilePhone::Open() failed %d", err );
       
  1700         User::Leave( err );
       
  1701         }
       
  1702     CleanupClosePushL( phone );
       
  1703 
       
  1704     err = phone.Initialise();
       
  1705     if ( err != KErrNone )
       
  1706         {
       
  1707         HTI_LOG_FORMAT( "RMobilePhone::Initialise() failed %d", err );
       
  1708         User::Leave( err );
       
  1709         }
       
  1710 
       
  1711     // Open customapi
       
  1712     RMmCustomAPI customAPI;
       
  1713     err = customAPI.Open( phone );
       
  1714     if ( err != KErrNone )
       
  1715         {
       
  1716         HTI_LOG_FORMAT( "RMmCustomAPI::Open() %d", err );
       
  1717         User::LeaveIfError( err );
       
  1718         }
       
  1719     CleanupClosePushL( customAPI );
       
  1720 
       
  1721     switch ( aMessage[0] )
       
  1722     {
       
  1723     case ENetworkModeGet:
       
  1724         {
       
  1725         HTI_LOG_TEXT( "ENetworkModeGet" );
       
  1726         TUint32 networkModes = 0;
       
  1727         err = customAPI.GetCurrentSystemNetworkModes( networkModes );
       
  1728         if ( err )
       
  1729             {
       
  1730             HTI_LOG_FORMAT(
       
  1731                     "RMmCustomAPI::GetCurrentSystemNetworkModes() failed %d",
       
  1732                     err );
       
  1733             User::LeaveIfError(
       
  1734                 iDispatcher->DispatchOutgoingErrorMessage(
       
  1735                         err,
       
  1736                         KErrDescrGetNetworkModes,
       
  1737                         KSysInfoServiceUid ) );
       
  1738             }
       
  1739         else
       
  1740             {
       
  1741             HTI_LOG_FORMAT( "networkModes 0x%x", networkModes );
       
  1742             TBuf8<5> okMsg;
       
  1743             okMsg.Append( ENetworkModeGet );
       
  1744             okMsg.Append( (TUint8*) &networkModes, 4 );
       
  1745             iReply = okMsg.AllocL();
       
  1746             }
       
  1747         }
       
  1748         break;
       
  1749 
       
  1750     case ENetworkModeSet:
       
  1751         HTI_LOG_TEXT( "ENetworkModeSet" );
       
  1752         if ( aMessage.Length() != 5 )
       
  1753             {
       
  1754             HTI_LOG_TEXT( "KErrArgument" );
       
  1755             User::LeaveIfError(
       
  1756                 iDispatcher->DispatchOutgoingErrorMessage(
       
  1757                         KErrArgument,
       
  1758                         KErrDescrArgument,
       
  1759                         KSysInfoServiceUid ) );
       
  1760             }
       
  1761         else
       
  1762             {
       
  1763             TUint32 mode = aMessage[1] + ( aMessage[2] << 8 ) +
       
  1764                            ( aMessage[3] << 16 ) + ( aMessage[4] << 24 );
       
  1765 
       
  1766             HTI_LOG_FORMAT( "SetSystemNetworkMode 0x%x", mode );
       
  1767             err = customAPI.SetSystemNetworkMode(
       
  1768                     ( RMmCustomAPI::TNetworkModeCaps ) mode );
       
  1769             if ( err )
       
  1770                 {
       
  1771                 HTI_LOG_FORMAT(
       
  1772                         "RMmCustomAPI::SetSystemNetworkMode() failed %d", err );
       
  1773                 iDispatcher->DispatchOutgoingErrorMessage(
       
  1774                     err,
       
  1775                     KErrDescrSetNetworkMode,
       
  1776                     KSysInfoServiceUid );
       
  1777                 }
       
  1778             else
       
  1779                 {
       
  1780                 iDispatcher->ShutdownAndRebootDeviceL();
       
  1781                 }
       
  1782             }
       
  1783         break;
       
  1784 
       
  1785     case ENetworkModeSetNoReboot:
       
  1786         {
       
  1787         HTI_LOG_TEXT( "ENetworkModeSetNoReboot" );
       
  1788         if ( aMessage.Length() != 5 )
       
  1789             {
       
  1790             HTI_LOG_TEXT( "KErrArgument" );
       
  1791             User::LeaveIfError(
       
  1792                 iDispatcher->DispatchOutgoingErrorMessage(
       
  1793                         KErrArgument,
       
  1794                         KErrDescrArgument,
       
  1795                         KSysInfoServiceUid ) );
       
  1796             }
       
  1797         else
       
  1798             {
       
  1799             TUint32 mode = aMessage[1] + ( aMessage[2] << 8 ) +
       
  1800                            ( aMessage[3] << 16 ) + ( aMessage[4] << 24 );
       
  1801 
       
  1802             HTI_LOG_FORMAT( "SetSystemNetworkMode 0x%x", mode );
       
  1803             err = customAPI.SetSystemNetworkMode(
       
  1804                     ( RMmCustomAPI::TNetworkModeCaps ) mode );
       
  1805             if ( err )
       
  1806                 {
       
  1807                 HTI_LOG_FORMAT(
       
  1808                         "RMmCustomAPI::SetSystemNetworkMode() failed %d", err );
       
  1809                 iDispatcher->DispatchOutgoingErrorMessage(
       
  1810                     err,
       
  1811                     KErrDescrSetNetworkMode,
       
  1812                     KSysInfoServiceUid );
       
  1813                 }
       
  1814             else
       
  1815                 {
       
  1816                 iReply = HBufC8::NewL( 1 );
       
  1817                 iReply->Des().Append( 0 );
       
  1818                 }
       
  1819             }
       
  1820         break;
       
  1821         }
       
  1822 
       
  1823     default:
       
  1824         break;
       
  1825     }
       
  1826 
       
  1827     CleanupStack::PopAndDestroy( 3 ); // telServer, phone, customAPI
       
  1828     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleNetworkModeCommandL" );
       
  1829 }
       
  1830 
       
  1831 //------------------------------------------------------------------------------
       
  1832 // CHtiSysInfoServicePlugin::HandleIrActivateCommandL
       
  1833 //------------------------------------------------------------------------------
       
  1834 void CHtiSysInfoServicePlugin::HandleIrActivateCommandL( const TDesC8& aMessage )
       
  1835     {
       
  1836     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleIrActivateCommandL" );
       
  1837 
       
  1838     // Message validation
       
  1839     if ( aMessage.Length() != 1 )
       
  1840         {
       
  1841         iDispatcher->DispatchOutgoingErrorMessage(
       
  1842             KErrArgument,
       
  1843             KErrDescrArgument,
       
  1844             KSysInfoServiceUid );
       
  1845         return;
       
  1846         }
       
  1847 
       
  1848     TInt irStatus = -1;
       
  1849     TInt err = RProperty::Get( KIrdaPropertyCategory, KIrdaStatus, irStatus );
       
  1850     if ( err != KErrNone || irStatus < TIrdaStatusCodes::EIrLoaded
       
  1851                          || irStatus > TIrdaStatusCodes::EIrDisconnected )
       
  1852         {
       
  1853         // values from irinternalpskey.h
       
  1854         err = RProperty::Set( KPSUidIrdaActivation, 1, 1 );
       
  1855         if ( err != KErrNone )
       
  1856             {
       
  1857             iDispatcher->DispatchOutgoingErrorMessage(
       
  1858                 err, KErrDescrIrActivation, KSysInfoServiceUid );
       
  1859             }
       
  1860         else
       
  1861             {
       
  1862             // Activation OK
       
  1863             iReply = HBufC8::NewL( 1 );
       
  1864             iReply->Des().Append( 0 );
       
  1865             }
       
  1866         }
       
  1867     else
       
  1868         {
       
  1869         // Already active - just send a message
       
  1870         iReply = HBufC8::NewL( 1 );
       
  1871         iReply->Des().Append( 1 );
       
  1872         }
       
  1873 
       
  1874      HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleIrActivateCommandL" );
       
  1875     }
       
  1876 
       
  1877 //------------------------------------------------------------------------------
       
  1878 // CHtiSysInfoServicePlugin::HandleBtPowerCommandL
       
  1879 //------------------------------------------------------------------------------
       
  1880 void CHtiSysInfoServicePlugin::HandleBtPowerCommandL( const TDesC8& aMessage )
       
  1881     {
       
  1882     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleBtPowerCommandL" );
       
  1883 
       
  1884     // Message validation
       
  1885     if ( aMessage.Length() != 3 )
       
  1886         {
       
  1887         iDispatcher->DispatchOutgoingErrorMessage(
       
  1888             KErrArgument,
       
  1889             KErrDescrArgument,
       
  1890             KSysInfoServiceUid );
       
  1891         return;
       
  1892         }
       
  1893 
       
  1894     TInt err = KErrNone;
       
  1895     TBool setBtOn = aMessage[1];
       
  1896     TBool useForce = aMessage[2];
       
  1897     TBool isBtOn = EFalse;
       
  1898 
       
  1899     TBTPowerStateValue powerState = EBTPowerOff;
       
  1900     CBTEngSettings* btSettings = CBTEngSettings::NewLC();
       
  1901     err = btSettings->GetPowerState( powerState );
       
  1902     if ( err == KErrNone && powerState == EBTPowerOn )
       
  1903         {
       
  1904         isBtOn = ETrue;
       
  1905         }
       
  1906 
       
  1907     if ( err )
       
  1908         {
       
  1909         HTI_LOG_FORMAT( "GetPowerState error %d", err );
       
  1910         CleanupStack::PopAndDestroy(); // btSettings
       
  1911         iDispatcher->DispatchOutgoingErrorMessage( err, KErrDescrGetBtPower,
       
  1912                                                    KSysInfoServiceUid );
       
  1913         return;
       
  1914         }
       
  1915     HTI_LOG_FORMAT( "Current BT power state %d", isBtOn );
       
  1916     HTI_LOG_FORMAT( "Requested BT power state %d", setBtOn );
       
  1917 
       
  1918     if ( setBtOn == isBtOn )
       
  1919         {
       
  1920         // Already in requested state - just send message
       
  1921         CleanupStack::PopAndDestroy(); // btSettings
       
  1922         iReply = HBufC8::NewL( 1 );
       
  1923         iReply->Des().Append( 1 );
       
  1924         }
       
  1925 
       
  1926     else
       
  1927         {
       
  1928         if ( setBtOn && !CanTurnBluetoothOnL( useForce ) )
       
  1929             {
       
  1930             iDispatcher->DispatchOutgoingErrorMessage( KErrAccessDenied,
       
  1931                 KErrDescrBtOnDenied, KSysInfoServiceUid );
       
  1932             CleanupStack::PopAndDestroy(); // btSettings
       
  1933             return;
       
  1934             }
       
  1935 
       
  1936 
       
  1937         if ( !setBtOn )
       
  1938             {
       
  1939             // If we are setting BT off, do checks for active connections.
       
  1940             TInt connCount = 0;
       
  1941             // Ignore error.
       
  1942             // If we cannot query, we act like there's no active connections.
       
  1943             RProperty::Get( KPropertyUidBluetoothCategory,
       
  1944                             KPropertyKeyBluetoothGetPHYCount,
       
  1945                             connCount );
       
  1946             // Check if there's Bluetooth audio accessory connected
       
  1947             TBool isBtAacConnected = EFalse;
       
  1948 
       
  1949             // If there are connections, force flag is required in the
       
  1950             // command to turn BT off.
       
  1951             if ( ( connCount || isBtAacConnected ) && !useForce )
       
  1952                 {
       
  1953                 iDispatcher->DispatchOutgoingErrorMessage( KErrInUse,
       
  1954                     KErrDescrBtOffDenied, KSysInfoServiceUid );
       
  1955                 CleanupStack::PopAndDestroy(); // btMcm/btSettings
       
  1956                 return;
       
  1957                 }
       
  1958             }
       
  1959 
       
  1960         if ( setBtOn )
       
  1961             {
       
  1962             err = btSettings->SetPowerState( EBTPowerOn );
       
  1963             }
       
  1964         else
       
  1965             {
       
  1966             err = btSettings->SetPowerState( EBTPowerOff );
       
  1967             }
       
  1968 
       
  1969         if ( err != KErrNone )
       
  1970             {
       
  1971             HTI_LOG_FORMAT( "CBTMCMSettings::SetPowerState error %d", err );
       
  1972             iDispatcher->DispatchOutgoingErrorMessage( err, KErrDescrSetBtPower,
       
  1973                                                        KSysInfoServiceUid );
       
  1974             }
       
  1975         else
       
  1976             {
       
  1977             iReply = HBufC8::NewL( 1 );
       
  1978             iReply->Des().Append( 0 );
       
  1979             }
       
  1980         CleanupStack::PopAndDestroy(); // btSettings
       
  1981         }
       
  1982     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleBtPowerCommandL" );
       
  1983     }
       
  1984 
       
  1985 //------------------------------------------------------------------------------
       
  1986 // CHtiSysInfoServicePlugin::HandleBtSettingsCommandL
       
  1987 //------------------------------------------------------------------------------
       
  1988 void CHtiSysInfoServicePlugin::HandleBtSettingsCommandL( const TDesC8& aMessage )
       
  1989     {
       
  1990     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleBtSettingsCommandL" );
       
  1991 
       
  1992     // Message validation
       
  1993     if ( aMessage.Length() < 4 )
       
  1994         {
       
  1995         iDispatcher->DispatchOutgoingErrorMessage(
       
  1996             KErrArgument,
       
  1997             KErrDescrArgument,
       
  1998             KSysInfoServiceUid );
       
  1999         return;
       
  2000     }
       
  2001     TInt btNameLength = aMessage[3];
       
  2002     if ( btNameLength > KMaxBtNameLength ||
       
  2003          aMessage.Length() != ( btNameLength + 4 ) )
       
  2004         {
       
  2005         iDispatcher->DispatchOutgoingErrorMessage(
       
  2006             KErrArgument,
       
  2007             KErrDescrArgument,
       
  2008             KSysInfoServiceUid );
       
  2009         return;
       
  2010         }
       
  2011 
       
  2012     TBTVisibilityMode visibilityMode = EBTVisibilityModeGeneral;
       
  2013     if ( aMessage[1] == 0 )
       
  2014         {
       
  2015         visibilityMode = EBTVisibilityModeHidden;
       
  2016         }
       
  2017     HTI_LOG_FORMAT( "Visibility mode = %d", visibilityMode );
       
  2018 
       
  2019     TInt sapMode = 1;  // EBTSapEnabled
       
  2020     if ( aMessage[2] == 0 )
       
  2021         {
       
  2022         sapMode = 0;   // EBTSapDisabled
       
  2023         }
       
  2024     HTI_LOG_FORMAT( "SAP mode = %d", sapMode );
       
  2025 
       
  2026     TBuf<KMaxBtNameLength> btName;
       
  2027     if ( btNameLength > 0 )
       
  2028         {
       
  2029         btName.Copy( aMessage.Mid( 4, btNameLength ) );
       
  2030         }
       
  2031     HTI_LOG_FORMAT( "BT name = %S", &btName );
       
  2032 
       
  2033     TInt err = KErrNone;
       
  2034     CBTEngSettings* btSettings = CBTEngSettings::NewLC();
       
  2035     HTI_LOG_TEXT( "CBTEngSettings::NewLC done" );
       
  2036 
       
  2037     HTI_LOG_TEXT( "Setting visibility mode" );
       
  2038     err = btSettings->SetVisibilityMode( visibilityMode );
       
  2039     if ( err == KErrNone )
       
  2040         {
       
  2041         HTI_LOG_TEXT( "Setting SAP mode" );
       
  2042         // CenRep UID and key value from btengprivatecrkeys.h
       
  2043         // const TUid KCRUidBTEngPrivateSettings = { 0x10204DAC }
       
  2044         // const TUint32 KBTSapEnabled  = 0x00000003
       
  2045         CRepository* btEngRep = CRepository::NewL( TUid::Uid( 0x10204DAC ) );
       
  2046         err = btEngRep->Set( 0x00000003, sapMode );
       
  2047         delete btEngRep;
       
  2048         btEngRep = NULL;
       
  2049         }
       
  2050     if ( err == KErrNone && btName.Length() > 0 )
       
  2051         {
       
  2052         HTI_LOG_TEXT( "Setting BT name" );
       
  2053         err = btSettings->SetLocalName( btName );
       
  2054         }
       
  2055 
       
  2056     if ( err == KErrNone )
       
  2057         {
       
  2058         HTI_LOG_TEXT( "All set successfully" );
       
  2059         iReply = HBufC8::NewL( 1 );
       
  2060         iReply->Des().Append( 0 );
       
  2061         }
       
  2062     else
       
  2063         {
       
  2064         HTI_LOG_FORMAT( "Error %d", err );
       
  2065         iDispatcher->DispatchOutgoingErrorMessage(
       
  2066             err,
       
  2067             KErrDescrBtSettings,
       
  2068             KSysInfoServiceUid );
       
  2069         }
       
  2070 
       
  2071     CleanupStack::PopAndDestroy(); // btSettings
       
  2072     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleBtSettingsCommandL" );
       
  2073     }
       
  2074 
       
  2075 //------------------------------------------------------------------------------
       
  2076 // CHtiSysInfoServicePlugin::HandleBtDeletePairingsL
       
  2077 //------------------------------------------------------------------------------
       
  2078 void CHtiSysInfoServicePlugin::HandleBtDeletePairingsL( const TDesC8& aMessage )
       
  2079     {
       
  2080     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleBtDeletePairingsL" );
       
  2081 
       
  2082     // Message validation
       
  2083     if ( aMessage.Length() < 3 )
       
  2084         {
       
  2085         iDispatcher->DispatchOutgoingErrorMessage(
       
  2086             KErrArgument,
       
  2087             KErrDescrArgument,
       
  2088             KSysInfoServiceUid );
       
  2089         return;
       
  2090         }
       
  2091 
       
  2092     TInt btNameLength = aMessage[2];
       
  2093     if ( btNameLength > KMaxBluetoothNameLen ||
       
  2094          aMessage.Length() != ( btNameLength + 3 ) )
       
  2095         {
       
  2096         iDispatcher->DispatchOutgoingErrorMessage(
       
  2097             KErrArgument,
       
  2098             KErrDescrArgument,
       
  2099             KSysInfoServiceUid );
       
  2100         return;
       
  2101         }
       
  2102 
       
  2103     // Message parsing
       
  2104     TBool closeConnections = aMessage[1];
       
  2105     HTI_LOG_FORMAT( "Close connections = %d", closeConnections );
       
  2106     TBTDeviceName8 btName8;
       
  2107     if ( btNameLength > 0 )
       
  2108         {
       
  2109         btName8.Copy( aMessage.Mid( 3, btNameLength ) );
       
  2110         }
       
  2111     HTI_LOG_FORMAT( "BT name = %S",
       
  2112         &( BTDeviceNameConverter::ToUnicodeL( btName8 ) ) );
       
  2113 
       
  2114     // Action
       
  2115     TInt deleteCount = 0;
       
  2116     TInt err = KErrNone;
       
  2117     RBTRegServ regServ;
       
  2118     RBTRegistry registry;
       
  2119     User::LeaveIfError( regServ.Connect() );
       
  2120     CleanupClosePushL( regServ );
       
  2121     User::LeaveIfError( registry.Open( regServ ) );
       
  2122     CleanupClosePushL( registry );
       
  2123     TBTRegistrySearch searchPattern;
       
  2124     searchPattern.FindBonded();
       
  2125 
       
  2126     TRequestStatus status;
       
  2127     registry.CreateView( searchPattern, status );
       
  2128     User::WaitForRequest( status );
       
  2129     err = status.Int();
       
  2130     HTI_LOG_FORMAT( "RBTRegistry::CreateView returned %d", err );
       
  2131 
       
  2132     if ( err > 0 )
       
  2133         {
       
  2134         CBTRegistryResponse* response = CBTRegistryResponse::NewL( registry );
       
  2135         CleanupStack::PushL( response );
       
  2136         HTI_LOG_TEXT( "Creating AsyncWaiter" );
       
  2137         CAsyncWaiter* waiter = CAsyncWaiter::NewLC();
       
  2138         HTI_LOG_TEXT( "Calling response->Start()" );
       
  2139         response->Start( waiter->iStatus );
       
  2140         HTI_LOG_TEXT( "Calling waiter->StartAndWait()" );
       
  2141         waiter->StartAndWait();
       
  2142         err = waiter->Result();
       
  2143         CleanupStack::PopAndDestroy( waiter );
       
  2144 
       
  2145         if ( err == KErrNone )
       
  2146             {
       
  2147             RBTDeviceArray results = response->Results();
       
  2148             TInt count = results.Count();
       
  2149             for ( TInt i = 0; i < count; i++ )
       
  2150                 {
       
  2151                 HTI_LOG_FORMAT( "Device %d", i + 1 );
       
  2152                 CBTDevice* device = results[i];
       
  2153                 if ( btNameLength == 0 ||
       
  2154                      device->DeviceName().Match( btName8 ) != KErrNotFound )
       
  2155                     {
       
  2156                     HTI_LOG_TEXT( "Name qualifies for deletion" );
       
  2157                     registry.UnpairDevice( device->BDAddr(), status );
       
  2158                     User::WaitForRequest( status );
       
  2159                     err = status.Int();
       
  2160                     if ( err == KErrNone )
       
  2161                         {
       
  2162                         deleteCount++; // one deletion successfully done
       
  2163                         }
       
  2164                     }
       
  2165                 if ( err != KErrNone )
       
  2166                     {
       
  2167                     // Break out if any failure occurs - the command has not
       
  2168                     // been able to do what it is expected to do.
       
  2169                     break;
       
  2170                     }
       
  2171                 }
       
  2172             }
       
  2173         CleanupStack::PopAndDestroy( response );
       
  2174         }
       
  2175 
       
  2176     CleanupStack::PopAndDestroy( &registry );
       
  2177     CleanupStack::PopAndDestroy( &regServ );
       
  2178 
       
  2179     // Create OK response or send error
       
  2180     if ( err == KErrNone )
       
  2181         {
       
  2182         HTI_LOG_FORMAT( "%d pairings deleted successfully", deleteCount );
       
  2183         iReply = HBufC8::NewL( 1 );
       
  2184         iReply->Des().Append( deleteCount );
       
  2185         }
       
  2186     else
       
  2187         {
       
  2188         HTI_LOG_FORMAT( "Error %d", err );
       
  2189         iDispatcher->DispatchOutgoingErrorMessage(
       
  2190             err,
       
  2191             KErrDescrBtDeletePairings,
       
  2192             KSysInfoServiceUid );
       
  2193         }
       
  2194 
       
  2195     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleBtDeletePairingsL" );
       
  2196     }
       
  2197 
       
  2198 //------------------------------------------------------------------------------
       
  2199 // CHtiSysInfoServicePlugin::HandleKeyLockToggleL
       
  2200 //------------------------------------------------------------------------------
       
  2201 void CHtiSysInfoServicePlugin::HandleKeyLockToggleL( const TDesC8& aMessage )
       
  2202     {
       
  2203     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleKeyLockToggleL" );
       
  2204 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 ) 
       
  2205     if ( aMessage.Length() != 3 )
       
  2206         {
       
  2207         iDispatcher->DispatchOutgoingErrorMessage( KErrArgument,
       
  2208             KErrDescrArgument, KSysInfoServiceUid );
       
  2209         return;
       
  2210         }
       
  2211 
       
  2212     RAknKeyLock keyLock;
       
  2213     User::LeaveIfError( keyLock.Connect() );
       
  2214     HTI_LOG_TEXT( "RAknKeyLock connect OK" );
       
  2215 
       
  2216     TBool isKeyLockOn = keyLock.IsKeyLockEnabled();
       
  2217     HTI_LOG_FORMAT( "Keylock status = %d", isKeyLockOn );
       
  2218 
       
  2219     TBool requested = aMessage[1];
       
  2220     HTI_LOG_FORMAT( "Requested status = %d", requested );
       
  2221 
       
  2222     if ( requested == isKeyLockOn )
       
  2223         {
       
  2224         // Already in requested state - just send message
       
  2225         iReply = HBufC8::NewL( 1 );
       
  2226         iReply->Des().Append( 1 );
       
  2227         }
       
  2228 
       
  2229     else
       
  2230         {
       
  2231         TBool showNote = aMessage[2];
       
  2232         HTI_LOG_FORMAT( "Note request = %d", showNote );
       
  2233         if ( requested )
       
  2234             {
       
  2235             if ( showNote )
       
  2236                 {
       
  2237                 keyLock.EnableKeyLock();
       
  2238                 }
       
  2239             else
       
  2240                 {
       
  2241                 keyLock.EnableWithoutNote();
       
  2242                 }
       
  2243             }
       
  2244         else
       
  2245             {
       
  2246             if ( showNote )
       
  2247                 {
       
  2248                 keyLock.DisableKeyLock();
       
  2249                 }
       
  2250             else
       
  2251                 {
       
  2252                 keyLock.DisableWithoutNote();
       
  2253                 }
       
  2254             }
       
  2255         User::After( 500000 );
       
  2256         isKeyLockOn = keyLock.IsKeyLockEnabled();
       
  2257         HTI_LOG_FORMAT( "New keylock status = %d", isKeyLockOn );
       
  2258         if ( isKeyLockOn == requested )
       
  2259             {
       
  2260             iReply = HBufC8::NewL( 1 );
       
  2261             iReply->Des().Append( 0 );
       
  2262             }
       
  2263         else
       
  2264             {
       
  2265             iDispatcher->DispatchOutgoingErrorMessage( KErrGeneral,
       
  2266                 KErrDescrKeyLock, KSysInfoServiceUid );
       
  2267             }
       
  2268         }
       
  2269 
       
  2270     keyLock.Close();
       
  2271 #else
       
  2272     iDispatcher->DispatchOutgoingErrorMessage(KErrArgument,
       
  2273             KErrDescrNotSupported, KSysInfoServiceUid);
       
  2274 #endif    
       
  2275     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleKeyLockToggleL" );
       
  2276     }
       
  2277 
       
  2278 //------------------------------------------------------------------------------
       
  2279 // CHtiSysInfoServicePlugin::HandleAutoKeyGuardTimeL
       
  2280 //------------------------------------------------------------------------------
       
  2281 void CHtiSysInfoServicePlugin::HandleAutoKeyGuardTimeL( const TDesC8& aMessage )
       
  2282     {
       
  2283 
       
  2284     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleAutoKeyGuardTimeL" );
       
  2285 
       
  2286     if ( aMessage.Length() != 3 )
       
  2287         {
       
  2288         iDispatcher->DispatchOutgoingErrorMessage( KErrArgument,
       
  2289             KErrDescrArgument, KSysInfoServiceUid );
       
  2290         return;
       
  2291         }
       
  2292 
       
  2293     TInt time = aMessage[1] + ( aMessage[2] << 8 );
       
  2294     HTI_LOG_FORMAT( "Requested auto key guard time %d", time );
       
  2295     if ( time > 3600 )
       
  2296         {
       
  2297         iDispatcher->DispatchOutgoingErrorMessage( KErrArgument,
       
  2298             KErrDescrInvalidTime, KSysInfoServiceUid );
       
  2299         return;
       
  2300         }
       
  2301 
       
  2302     CRepository* secRep = CRepository::NewL( KCRUidSecuritySettings );
       
  2303     TInt err = secRep->Set( KSettingsAutomaticKeyguardTime, time );
       
  2304 
       
  2305     if ( err == KErrNone )
       
  2306         {
       
  2307         iReply = HBufC8::NewL( 1 );
       
  2308         iReply->Des().Append( 0 );
       
  2309         }
       
  2310 
       
  2311     else
       
  2312         {
       
  2313         iDispatcher->DispatchOutgoingErrorMessage( err,
       
  2314             KErrDescrAutoKeyGuardFailed, KSysInfoServiceUid );
       
  2315         }
       
  2316 
       
  2317     delete secRep;
       
  2318 
       
  2319     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleAutoKeyGuardTimeL" );
       
  2320     }
       
  2321 
       
  2322 
       
  2323 //------------------------------------------------------------------------------
       
  2324 // CHtiSysInfoServicePlugin::HandleEmptyDrmRightsDbL
       
  2325 //------------------------------------------------------------------------------
       
  2326 void CHtiSysInfoServicePlugin::HandleEmptyDrmRightsDbL( const TDesC8& aMessage )
       
  2327     {
       
  2328     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleEmptyDrmRightsDbL" );
       
  2329 
       
  2330     if ( aMessage.Length() != 1 )
       
  2331         {
       
  2332         iDispatcher->DispatchOutgoingErrorMessage( KErrArgument,
       
  2333             KErrDescrArgument, KSysInfoServiceUid );
       
  2334         return;
       
  2335         }
       
  2336 
       
  2337     RDRMRightsClient rightsClient;
       
  2338     TInt err = rightsClient.Connect();
       
  2339 
       
  2340     if ( err != KErrNone )
       
  2341         {
       
  2342         HTI_LOG_FORMAT( "RDRMRightsClient connect failed %d", err );
       
  2343         iDispatcher->DispatchOutgoingErrorMessage( err,
       
  2344             KErrDescrDrmDbConnect, KSysInfoServiceUid );
       
  2345         }
       
  2346 
       
  2347     else
       
  2348         {
       
  2349         HTI_LOG_TEXT( "RDRMRightsClient connect OK, clearing DB..." );
       
  2350         err = rightsClient.DeleteAll();
       
  2351         if ( err == KErrNone )
       
  2352             {
       
  2353             HTI_LOG_TEXT( "DB cleared OK" );
       
  2354             iReply = HBufC8::NewL( 1 );
       
  2355             iReply->Des().Append( 0 );
       
  2356             }
       
  2357         else
       
  2358             {
       
  2359             HTI_LOG_FORMAT( "DB clear failed %d", err );
       
  2360             iDispatcher->DispatchOutgoingErrorMessage( err,
       
  2361                 KErrDescrDrmDbDelete, KSysInfoServiceUid );
       
  2362             }
       
  2363         rightsClient.Close();
       
  2364         }
       
  2365 
       
  2366     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleEmptyDrmRightsDbL" );
       
  2367     }
       
  2368 
       
  2369 
       
  2370 //------------------------------------------------------------------------------
       
  2371 // CHtiSysInfoServicePlugin::HandleBatteryStatusL
       
  2372 //------------------------------------------------------------------------------
       
  2373 void CHtiSysInfoServicePlugin::HandleBatteryStatusL( const TDesC8& aMessage )
       
  2374     {
       
  2375     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleBatteryStatusL" );
       
  2376 
       
  2377     if ( aMessage.Length() != 1 )
       
  2378         {
       
  2379         iDispatcher->DispatchOutgoingErrorMessage( KErrArgument,
       
  2380             KErrDescrArgument, KSysInfoServiceUid );
       
  2381         return;
       
  2382         }
       
  2383 
       
  2384     TInt err = KErrNone;
       
  2385     TInt batteryLevel = EBatteryLevelUnknown;
       
  2386     TInt chargingStatus = EChargingStatusError;
       
  2387 
       
  2388     err = RProperty::Get( KPSUidHWRMPowerState,
       
  2389                           KHWRMBatteryLevel, batteryLevel );
       
  2390     HTI_LOG_FORMAT( "Battery level = %d", batteryLevel );
       
  2391     if ( err != KErrNone || batteryLevel == EBatteryLevelUnknown )
       
  2392         {
       
  2393         if ( err == KErrNone ) err = KErrGeneral;
       
  2394         iDispatcher->DispatchOutgoingErrorMessage( err,
       
  2395             KErrDescrBatteryLevel, KSysInfoServiceUid );
       
  2396         return;
       
  2397         }
       
  2398 
       
  2399     err = RProperty::Get( KPSUidHWRMPowerState,
       
  2400                           KHWRMChargingStatus, chargingStatus );
       
  2401     HTI_LOG_FORMAT( "Charging status = %d", chargingStatus );
       
  2402     if ( err != KErrNone || chargingStatus == EChargingStatusError )
       
  2403         {
       
  2404         if ( err == KErrNone ) err = KErrGeneral;
       
  2405         iDispatcher->DispatchOutgoingErrorMessage( err,
       
  2406             KErrDescrChargingStatus, KSysInfoServiceUid );
       
  2407         return;
       
  2408         }
       
  2409 
       
  2410     iReply = HBufC8::NewL( 2 );
       
  2411     iReply->Des().Append( batteryLevel );
       
  2412     iReply->Des().Append( chargingStatus );
       
  2413 
       
  2414     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleBatteryStatusL" );
       
  2415     }
       
  2416 
       
  2417 
       
  2418 //------------------------------------------------------------------------------
       
  2419 // CHtiSysInfoServicePlugin::HandleSignalStrengthL
       
  2420 //------------------------------------------------------------------------------
       
  2421 void CHtiSysInfoServicePlugin::HandleSignalStrengthL( const TDesC8& aMessage )
       
  2422     {
       
  2423     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleSignalStrengthL" );
       
  2424 
       
  2425     if ( aMessage.Length() != 1 )
       
  2426         {
       
  2427         iDispatcher->DispatchOutgoingErrorMessage( KErrArgument,
       
  2428             KErrDescrArgument, KSysInfoServiceUid );
       
  2429         return;
       
  2430         }
       
  2431 
       
  2432 #if defined(__WINS__)
       
  2433     iDispatcher->DispatchOutgoingErrorMessage( KErrNotSupported,
       
  2434         KErrDescrNotSupported, KSysInfoServiceUid );
       
  2435 #else
       
  2436     TInt err = KErrNone;
       
  2437     TInt popCount = 0;
       
  2438     RTelServer server;
       
  2439     err = server.Connect();
       
  2440 
       
  2441     if ( err == KErrNone )
       
  2442         {
       
  2443         HTI_LOG_TEXT( "Connected to RTelServer" );
       
  2444         CleanupClosePushL( server );
       
  2445         popCount++;
       
  2446         err = server.LoadPhoneModule( KMmTsyModuleName );
       
  2447         if ( err == KErrAlreadyExists ) err = KErrNone; // ok if already loaded
       
  2448         }
       
  2449 
       
  2450     RMobilePhone mobilePhone;
       
  2451 
       
  2452     if ( err == KErrNone )
       
  2453         {
       
  2454         HTI_LOG_TEXT( "Phone module loaded" );
       
  2455         err = mobilePhone.Open( server, KMmTsyPhoneName );
       
  2456         }
       
  2457 
       
  2458     TInt8  signalBars;
       
  2459     TInt32 signalStrength;
       
  2460 
       
  2461     if ( err == KErrNone )
       
  2462         {
       
  2463         HTI_LOG_TEXT( "RMobilePhone open" );
       
  2464         CleanupClosePushL( mobilePhone );
       
  2465         popCount++;
       
  2466         TRequestStatus status;
       
  2467         mobilePhone.GetSignalStrength( status, signalStrength, signalBars );
       
  2468         User::WaitForRequest( status );
       
  2469         HTI_LOG_FORMAT( "GetSignalStrength return value %d", status.Int() );
       
  2470         err = status.Int();
       
  2471         }
       
  2472 
       
  2473     if ( err == KErrNone )
       
  2474         {
       
  2475         HTI_LOG_FORMAT( "Signal bars = %d", signalBars );
       
  2476         HTI_LOG_FORMAT( "Signal strength = %d", signalStrength );
       
  2477         iReply = HBufC8::NewL( 1 );
       
  2478         iReply->Des().Append( signalBars );
       
  2479         }
       
  2480 
       
  2481     else
       
  2482         {
       
  2483         iDispatcher->DispatchOutgoingErrorMessage( err,
       
  2484             KErrDescrSignalStrength, KSysInfoServiceUid );
       
  2485         }
       
  2486 
       
  2487     if ( popCount > 0 )
       
  2488         {
       
  2489         CleanupStack::PopAndDestroy( popCount );
       
  2490         }
       
  2491 #endif // __WINS__
       
  2492     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleSignalStrengthL" );
       
  2493     }
       
  2494 
       
  2495 
       
  2496 //------------------------------------------------------------------------------
       
  2497 // CHtiSysInfoServicePlugin::HandleHsdpaCommandL
       
  2498 //------------------------------------------------------------------------------
       
  2499 void CHtiSysInfoServicePlugin::HandleHsdpaCommandL( const TDesC8& aMessage )
       
  2500     {
       
  2501     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleHsdpaCommandL" );
       
  2502 
       
  2503     if ( aMessage.Length() != 2 )
       
  2504         {
       
  2505         iDispatcher->DispatchOutgoingErrorMessage( KErrArgument,
       
  2506             KErrDescrArgument, KSysInfoServiceUid );
       
  2507         return;
       
  2508         }
       
  2509     TBool enableHsdpa = aMessage[1];
       
  2510 
       
  2511     RTelServer telServer;
       
  2512     RMmCustomAPI customAPI;
       
  2513     RMobilePhone mobilePhone;
       
  2514     User::LeaveIfError( telServer.Connect() );
       
  2515     CleanupClosePushL( telServer );
       
  2516     User::LeaveIfError( mobilePhone.Open( telServer, KMmTsyPhoneName ) );
       
  2517     CleanupClosePushL( mobilePhone );
       
  2518     User::LeaveIfError( customAPI.Open( mobilePhone ) );
       
  2519     CleanupClosePushL( customAPI );
       
  2520 
       
  2521     // Get current HSDPA status
       
  2522     TBool isHsdpaEnabled = EFalse;
       
  2523     TRequestStatus status;
       
  2524     RMmCustomAPI::THSxPAStatus hSxPAStatus;
       
  2525     customAPI.ReadHSxPAStatus( status, hSxPAStatus );
       
  2526     User::WaitForRequest( status );
       
  2527     HTI_LOG_FORMAT( "Reading HSxPA status returned %d", status.Int() );
       
  2528     User::LeaveIfError( status.Int() );
       
  2529     if ( hSxPAStatus == RMmCustomAPI::EHSxPAEnabled )
       
  2530         {
       
  2531         isHsdpaEnabled = ETrue;
       
  2532         }
       
  2533 
       
  2534     HTI_LOG_FORMAT( "Current HSDPA status   = %d", isHsdpaEnabled );
       
  2535     HTI_LOG_FORMAT( "Requested HSDPA status = %d", enableHsdpa );
       
  2536 
       
  2537     if ( isHsdpaEnabled == enableHsdpa )
       
  2538         {
       
  2539         // Already in requested state - just send message
       
  2540         iReply = HBufC8::NewL( 1 );
       
  2541         iReply->Des().Append( 1 );
       
  2542         }
       
  2543 
       
  2544     else
       
  2545         {
       
  2546         // Try to change status
       
  2547         if ( enableHsdpa )
       
  2548             {
       
  2549             hSxPAStatus = RMmCustomAPI::EHSxPAEnabled;
       
  2550             }
       
  2551         else
       
  2552             {
       
  2553             hSxPAStatus = RMmCustomAPI::EHSxPADisabled;
       
  2554             }
       
  2555         customAPI.WriteHSxPAStatus( status, hSxPAStatus );
       
  2556         User::WaitForRequest( status );
       
  2557         HTI_LOG_FORMAT( "Writing HSxPA status returned %d", status.Int() );
       
  2558         User::LeaveIfError( status.Int() );
       
  2559         iReply = HBufC8::NewL( 1 );
       
  2560         iReply->Des().Append( 0 );
       
  2561         }
       
  2562 
       
  2563     CleanupStack::PopAndDestroy( 3 ); // mobilePhone, customAPI, telServer
       
  2564 
       
  2565     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleHsdpaCommandL" );
       
  2566     }
       
  2567 
       
  2568 //------------------------------------------------------------------------------
       
  2569 // CHtiSysInfoServicePlugin::HandleUpdateMediaGalleryL()
       
  2570 //------------------------------------------------------------------------------
       
  2571 void CHtiSysInfoServicePlugin::HandleUpdateMediaGalleryL(
       
  2572         const TDesC8& aMessage )
       
  2573     {
       
  2574     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleUpdateMediaGalleryL" );
       
  2575 
       
  2576     if ( !iGalleryUpdateSupported )
       
  2577         {
       
  2578         HTI_LOG_TEXT( "Media Gallery update not supported" );
       
  2579         iDispatcher->DispatchOutgoingErrorMessage( KErrNotSupported,
       
  2580                 KErrDescrNotSupported, KSysInfoServiceUid );
       
  2581         return;
       
  2582         }
       
  2583 
       
  2584     if ( aMessage.Length() < 2 )
       
  2585         {
       
  2586         iDispatcher->DispatchOutgoingErrorMessage( KErrArgument,
       
  2587             KErrDescrArgument, KSysInfoServiceUid );
       
  2588         return;
       
  2589         }
       
  2590     TInt filePathLength = aMessage[1];
       
  2591     // Check that given file path length is valid: Index 0 is the
       
  2592     // command code, index 1 is the path length -> hence the + 2
       
  2593     if ( aMessage.Length() != filePathLength + 2 )
       
  2594         {
       
  2595         iDispatcher->DispatchOutgoingErrorMessage( KErrArgument,
       
  2596                 KErrDescrArgument, KSysInfoServiceUid );
       
  2597         return;
       
  2598         }
       
  2599 
       
  2600     // Try to load the Media File API DLL
       
  2601     TInt err = KErrNone;
       
  2602     RLibrary galleryUpdaterDLL;
       
  2603     err = galleryUpdaterDLL.Load( _L( "MGXMediaFileAPI.dll" ) );
       
  2604     if ( err == KErrNotFound )  // DLL does not exist
       
  2605         {
       
  2606         HTI_LOG_TEXT( "MGXMediaFileAPI.dll file not found" );
       
  2607         iGalleryUpdateSupported = EFalse;
       
  2608         iDispatcher->DispatchOutgoingErrorMessage( KErrNotSupported,
       
  2609                 KErrDescrNotSupported, KSysInfoServiceUid );
       
  2610         return;
       
  2611         }
       
  2612     User::LeaveIfError( err ); // Some other error in loading the DLL
       
  2613 
       
  2614     // DLL loaded successfully
       
  2615     CleanupClosePushL( galleryUpdaterDLL );
       
  2616 
       
  2617     // Construct the CMGXFileManager object from the DLL
       
  2618     typedef CMGXFileManager* ( *TNewFileManagerFunc )( RFs& aFs );
       
  2619     TNewFileManagerFunc newFileManFunc =
       
  2620             ( TNewFileManagerFunc ) galleryUpdaterDLL.Lookup( 1 );
       
  2621     if ( newFileManFunc == NULL )
       
  2622         {
       
  2623         HTI_LOG_TEXT( "Function not found from DLL" );
       
  2624         iGalleryUpdateSupported = EFalse;
       
  2625         User::Leave( KErrNotSupported );
       
  2626         }
       
  2627 
       
  2628     CMGXFileManager* mgManager = NULL;
       
  2629     TRAP( err, mgManager = newFileManFunc( iFs ) );
       
  2630     HTI_LOG_FORMAT( "NewFileManagerL returned %d", err );
       
  2631     User::LeaveIfError( err );
       
  2632     User::LeaveIfNull( mgManager );
       
  2633     CleanupStack::PushL( mgManager );
       
  2634 
       
  2635     if ( filePathLength > 0 )
       
  2636         {
       
  2637         TBuf<KMaxFileName> path;
       
  2638         path.Copy( aMessage.Mid( 2 ) );
       
  2639         HTI_LOG_FORMAT( "Updating file %S to gallery", &path );
       
  2640         TRAP( err, mgManager->UpdateL( path ) );
       
  2641         }
       
  2642     else
       
  2643         {
       
  2644         HTI_LOG_TEXT( "Updating all files to gallery" );
       
  2645         TRAP( err, mgManager->UpdateL() );
       
  2646         }
       
  2647 
       
  2648     if ( err != KErrNone )
       
  2649         {
       
  2650         HTI_LOG_FORMAT( "Gallery update failed with %d", err );
       
  2651         iDispatcher->DispatchOutgoingErrorMessage( err, KErrDescrMGUpdate,
       
  2652                 KSysInfoServiceUid );
       
  2653         }
       
  2654 
       
  2655     CleanupStack::PopAndDestroy( 2 ); // mgManager, galleryUpdaterDLL
       
  2656     iReply = HBufC8::NewL( 1 );
       
  2657     iReply->Des().Append( 0 );
       
  2658     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleUpdateMediaGalleryL" );
       
  2659     }
       
  2660 
       
  2661 //------------------------------------------------------------------------------
       
  2662 // CHtiSysInfoServicePlugin::HandleActivateSkinL()
       
  2663 //------------------------------------------------------------------------------
       
  2664 void CHtiSysInfoServicePlugin::HandleActivateSkinL( const TDesC8& aMessage )
       
  2665     {
       
  2666     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleActivateSkinL" );
       
  2667 
       
  2668     // Must be at least command code + name length byte
       
  2669     if ( aMessage.Length() < 2 || aMessage.Length() != aMessage[1] + 2 )
       
  2670         {
       
  2671         iDispatcher->DispatchOutgoingErrorMessage( KErrArgument,
       
  2672                 KErrDescrArgument, KSysInfoServiceUid );
       
  2673         return;
       
  2674         }
       
  2675 
       
  2676     TFileName skinName;
       
  2677     if ( aMessage[1] > 0 )
       
  2678         {
       
  2679         skinName.Copy( aMessage.Mid( 2 ) );
       
  2680         }
       
  2681     HTI_LOG_FORMAT( "Skin name: %S", &skinName );
       
  2682 
       
  2683     // Check if we got full path to skn file
       
  2684     TParse fileParse;
       
  2685     fileParse.Set( skinName, NULL, NULL );
       
  2686     TBool isFullPath = fileParse.DrivePresent() && fileParse.PathPresent() &&
       
  2687             fileParse.NamePresent() && fileParse.ExtPresent();
       
  2688     HTI_LOG_FORMAT( "Is full path = %d", isFullPath );
       
  2689 
       
  2690     // Check current skin
       
  2691     TAknsPkgIDBuf pidBuf;
       
  2692     TInt currentSkinLocation; // TAknSkinSrvSkinPackageLocation
       
  2693     CRepository* repository =
       
  2694             CRepository::NewL( KCRUidPersonalisation );
       
  2695     CleanupStack::PushL( repository );
       
  2696     repository->Get( KPslnActiveSkinUid, pidBuf );
       
  2697     repository->Get( KPslnActiveSkinLocation, currentSkinLocation );
       
  2698     TAknsPkgID currentSkinPid;
       
  2699     currentSkinPid.SetFromDesL( pidBuf );
       
  2700     HTI_LOG_FORMAT( "Current skin pkg ID buf = %S", &pidBuf );
       
  2701     HTI_LOG_FORMAT( "Current skin location = %d", currentSkinLocation );
       
  2702 
       
  2703     // Connect to the skins server
       
  2704     RAknsSrvSession skinsSession;
       
  2705     User::LeaveIfError( skinsSession.Connect() );
       
  2706     CleanupClosePushL( skinsSession );
       
  2707 
       
  2708     // Resolve the ID for the requested skin
       
  2709     TAknsPkgID requestedSkinPid = KAknsNullPkgID;
       
  2710     TInt requestedSkinLocation = EAknsSrvPhone;
       
  2711 
       
  2712     if ( skinName.Length() == 0 )
       
  2713         {
       
  2714         // Default skin requested - resolve default skin ID
       
  2715         // Use KAknsPIDS60DefaultSkin if nothing else found from CenRep
       
  2716         requestedSkinPid.Set( KAknsPIDS60DefaultSkin );
       
  2717         TAknsPkgID defaultSkin = KAknsNullPkgID;
       
  2718         TAknsPkgIDBuf defaultPidBuf;
       
  2719         TInt ret = repository->Get( KPslnDefaultSkinUID, defaultPidBuf );
       
  2720         if ( ret != KErrNone || defaultPidBuf.Length() == 0 )
       
  2721             {
       
  2722             HTI_LOG_TEXT( "KPslnDefaultSkinUID not found" );
       
  2723             TInt defaultID = 0;
       
  2724             ret = repository->Get( KPslnDefaultSkinID, defaultID );
       
  2725             if ( ret == KErrNone && defaultID != 0 )
       
  2726                 {
       
  2727                 HTI_LOG_FORMAT( "KPslnDefaultSkinID found: %d", defaultID );
       
  2728                 defaultSkin.Set( TUid::Uid( defaultID ) );
       
  2729                 }
       
  2730             }
       
  2731         else
       
  2732             {
       
  2733             HTI_LOG_FORMAT( "KPslnDefaultSkinUID found: %S", &defaultPidBuf );
       
  2734             TLex lexer( defaultPidBuf );
       
  2735             TPtrC pidToken( lexer.NextToken() );
       
  2736             TUint pid = 0;
       
  2737             TUint timeStamp = 0;
       
  2738             // as hex UID is 8 characters
       
  2739             // as decimal UID is 9 or 10 characters
       
  2740             if ( pidToken.Length() == 8 )
       
  2741                 {
       
  2742                 ret = TLex( pidToken ).Val( pid, EHex ); // value is in hex
       
  2743                 }
       
  2744             else
       
  2745                 {
       
  2746                 ret = TLex( pidToken ).Val( pid ); // value is in decimal
       
  2747                 }
       
  2748             if ( ret == KErrNone )
       
  2749                 {
       
  2750                 TPtrC stampToken( lexer.NextToken() );
       
  2751                 // Timestamp doesn't exist if PID is an UID
       
  2752                 if ( stampToken.Length() )
       
  2753                     {
       
  2754                     if ( stampToken.Length() == 8 )
       
  2755                         {
       
  2756                         // value is in hex
       
  2757                         ret = TLex( stampToken ).Val( timeStamp, EHex );
       
  2758                         }
       
  2759                     else
       
  2760                         {
       
  2761                         // value is decimal
       
  2762                         ret = TLex( stampToken ).Val( timeStamp );
       
  2763                         }
       
  2764                     }
       
  2765                 }
       
  2766             if ( ret == KErrNone )
       
  2767                 {
       
  2768                 // We have found some valid values.
       
  2769                 // Timestamp is 0 if pid is UID value
       
  2770                 HTI_LOG_FORMAT( "PID %d", pid );
       
  2771                 HTI_LOG_FORMAT( "Timestamp %d", timeStamp );
       
  2772                 defaultSkin.Set( timeStamp, pid );
       
  2773                 }
       
  2774             }
       
  2775         // Did we find something from CenRep
       
  2776         if ( defaultSkin != KAknsNullPkgID )
       
  2777             {
       
  2778             requestedSkinPid.Set( defaultSkin );
       
  2779             }
       
  2780         }
       
  2781 
       
  2782     else
       
  2783         {
       
  2784         // We have skin name - try to find it
       
  2785         CArrayPtr<CAknsSrvSkinInformationPkg>* skinInfoArray =
       
  2786                 skinsSession.EnumerateSkinPackagesL( EAknsSrvAll );
       
  2787         HTI_LOG_FORMAT( "Skins found: %d", skinInfoArray->Count() );
       
  2788         TInt i = 0;
       
  2789         for ( ; i < skinInfoArray->Count(); i++ )
       
  2790             {
       
  2791             if ( isFullPath )
       
  2792                 {
       
  2793                 if ( skinName.CompareF(
       
  2794                         skinInfoArray->At( i )->FullName() ) == 0 )
       
  2795                     {
       
  2796                     requestedSkinPid = skinInfoArray->At( i )->PID();
       
  2797                     }
       
  2798                 }
       
  2799             else
       
  2800                 {
       
  2801                 if ( skinName.CompareF( skinInfoArray->At( i )->Name() ) == 0 )
       
  2802                     {
       
  2803                     requestedSkinPid = skinInfoArray->At( i )->PID();
       
  2804                     }
       
  2805                 }
       
  2806             if ( requestedSkinPid != KAknsNullPkgID )
       
  2807                 {
       
  2808                 // Requested skin was found - check the location
       
  2809                 TUint16 drive = ( skinInfoArray->At( i )->Directory() )[0];
       
  2810                 if (  drive == 'E' || drive == 'e' )
       
  2811                     {
       
  2812                     requestedSkinLocation = EAknsSrvMMC;
       
  2813                     }
       
  2814                 else
       
  2815                     {
       
  2816                     requestedSkinLocation = EAknsSrvPhone;
       
  2817                     }
       
  2818                 break;
       
  2819                 }
       
  2820             }
       
  2821         skinInfoArray->ResetAndDestroy(); // not needed anymore
       
  2822         delete skinInfoArray;
       
  2823         skinInfoArray = NULL;
       
  2824         }
       
  2825 
       
  2826     if ( requestedSkinPid != KAknsNullPkgID )
       
  2827         {
       
  2828         // Do we need to change skin
       
  2829         if ( requestedSkinPid != currentSkinPid )
       
  2830             {
       
  2831             HTI_LOG_FORMAT( "Activating skin %d", requestedSkinPid.iNumber );
       
  2832             TInt err = skinsSession.SetAllDefinitionSets( requestedSkinPid );
       
  2833             HTI_LOG_FORMAT( "Activation returned %d", err );
       
  2834             if ( err == KErrNone )
       
  2835                 {
       
  2836                 TAknsPkgIDBuf newPidBuf;
       
  2837                 requestedSkinPid.CopyToDes( newPidBuf );
       
  2838                 err = repository->Set( KPslnActiveSkinUid, newPidBuf );
       
  2839                 HTI_LOG_FORMAT( "Set KPslnActiveSkinUid returned %d", err );
       
  2840                 if ( err == KErrNone &&
       
  2841                         requestedSkinLocation != currentSkinLocation )
       
  2842                     {
       
  2843                     err = repository->Set(
       
  2844                             KPslnActiveSkinLocation, requestedSkinLocation );
       
  2845                     HTI_LOG_FORMAT( "Set KPslnActiveSkinLocation returned %d",
       
  2846                             err );
       
  2847                     }
       
  2848                 if ( err == KErrNone )
       
  2849                     {
       
  2850                     // Send OK message
       
  2851                     iReply = HBufC8::NewL( 1 );
       
  2852                     iReply->Des().Append( 0 ); // 0 means OK
       
  2853                     }
       
  2854                 }
       
  2855             if ( err != KErrNone )
       
  2856                 {
       
  2857                 HTI_LOG_FORMAT( "Skin activation failed with %d", err );
       
  2858                 iDispatcher->DispatchOutgoingErrorMessage( err,
       
  2859                         KErrDescrActivateSkin, KSysInfoServiceUid );
       
  2860                 }
       
  2861             }
       
  2862         else
       
  2863             {
       
  2864             // Requested skin already active - just send message
       
  2865             HTI_LOG_TEXT( "Already active - no need to change" );
       
  2866             iReply = HBufC8::NewL( 1 );
       
  2867             iReply->Des().Append( 1 );  // 1 means "already active"
       
  2868             }
       
  2869         }
       
  2870 
       
  2871     else
       
  2872         {
       
  2873         // Skin was not found
       
  2874         HTI_LOG_TEXT( "Skin was not found" );
       
  2875         iDispatcher->DispatchOutgoingErrorMessage( KErrNotFound,
       
  2876                 KErrDescrActivateSkin, KSysInfoServiceUid );
       
  2877         }
       
  2878 
       
  2879     CleanupStack::PopAndDestroy( 2 ); // skinsSession, repository
       
  2880 
       
  2881     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleActivateSkinL" );
       
  2882     }
       
  2883 
       
  2884 //------------------------------------------------------------------------------
       
  2885 // CHtiSysInfoServicePlugin::HandleSetLanguageL
       
  2886 //------------------------------------------------------------------------------
       
  2887 void CHtiSysInfoServicePlugin::HandleSetLanguageL( const TDesC8& aMessage )
       
  2888     {
       
  2889     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleSetLanguageL" );
       
  2890     if ( aMessage.Length() != 3 )
       
  2891         {
       
  2892         iDispatcher->DispatchOutgoingErrorMessage( KErrArgument,
       
  2893                 KErrDescrArgument, KSysInfoServiceUid );
       
  2894         return;
       
  2895         }
       
  2896     
       
  2897     TInt language = aMessage[1] + ( aMessage[2] << 8 );
       
  2898     if(language < 0)
       
  2899         {
       
  2900         iDispatcher->DispatchOutgoingErrorMessage( KErrArgument,
       
  2901                 KErrDescrSetLanguage, KSysInfoServiceUid );
       
  2902         return;
       
  2903         }
       
  2904     HTI_LOG_FORMAT( "Set language to %d", language );
       
  2905     
       
  2906     // Never set Language code 0 to HAL
       
  2907     if (language != 0)
       
  2908         {
       
  2909         User::LeaveIfError(HAL::Set(HAL::ELanguageIndex, language));
       
  2910         }
       
  2911     
       
  2912     CRepository* commonEngineRepository = CRepository::NewL(
       
  2913             KCRUidCommonEngineKeys);
       
  2914     CleanupStack::PushL(commonEngineRepository);
       
  2915     
       
  2916     User::LeaveIfError(commonEngineRepository->Set(KGSDisplayTxtLang, language));
       
  2917 
       
  2918     CleanupStack::PopAndDestroy();
       
  2919 
       
  2920     TBool nbrModeSaved = EFalse;
       
  2921     if (language == ELangArabic || User::Language() == ELangArabic)
       
  2922         {
       
  2923         //numberMode = EGSNumberModeArabicIndic;
       
  2924         SetDefaultNumberModeL(EGSNbrModeArabic, EGSNbrModeTypeArabic);
       
  2925         nbrModeSaved = ETrue;
       
  2926         }
       
  2927     else if ((language == ELangUrdu || User::Language() == ELangUrdu)
       
  2928             || (language == ELangFarsi || User::Language() == ELangFarsi))
       
  2929         {
       
  2930         //numberMode = EGSNumberModeEasternArabicIndic;
       
  2931         SetDefaultNumberModeL(EGSNbrModeLatin, EGSNbrModeTypeEasternArabic);
       
  2932         nbrModeSaved = ETrue;
       
  2933         }
       
  2934     else if (language == ELangHindi || User::Language() == ELangHindi
       
  2935             || language == ELangMarathi || User::Language() == ELangMarathi)
       
  2936         {
       
  2937         //numberMode = EGSNumberModeIndic;
       
  2938         SetDefaultNumberModeL(EGSNbrModeLatin, EGSNbrModeTypeIndic);
       
  2939         nbrModeSaved = ETrue;
       
  2940         }
       
  2941 
       
  2942     //if number mode is not set above, then set it to Latin with respective
       
  2943     //number mode types. This part might be executed when Automatic is
       
  2944     //selected and the SIM card does not support the language.
       
  2945     if (!nbrModeSaved)
       
  2946         {
       
  2947         TInt nbrModeType = EGSNbrModeTypeIndic;
       
  2948         if (language == ELangArabic || User::Language() == ELangArabic)
       
  2949             {
       
  2950             nbrModeType = EGSNbrModeTypeArabic;
       
  2951             }
       
  2952         else if ((language == ELangUrdu || User::Language() == ELangUrdu)
       
  2953                 || (language == ELangFarsi || User::Language() == ELangFarsi))
       
  2954             {
       
  2955             nbrModeType = EGSNbrModeTypeEasternArabic;
       
  2956             }
       
  2957 
       
  2958         //EGSNumberModeLatin is true in both cases;
       
  2959         SetDefaultNumberModeL(EGSNbrModeLatin, nbrModeType);
       
  2960         }
       
  2961     
       
  2962     // Change input language
       
  2963     CRepository* aknFepRepository = CRepository::NewL( KCRUidAknFep );
       
  2964     CleanupStack::PushL(aknFepRepository);
       
  2965     User::LeaveIfError(  aknFepRepository->Set( KAknFepInputTxtLang,
       
  2966                                                 language ));
       
  2967     // Change input method for Chinese variants
       
  2968     if( FeatureManager::FeatureSupported( KFeatureIdChinese ) )
       
  2969         {
       
  2970         TBuf<KFepChineseInputModeLength> conversion;
       
  2971         if( language == ELangPrcChinese )
       
  2972             {
       
  2973             conversion.Num( EPinyin, EHex );
       
  2974             User::LeaveIfError( aknFepRepository->Set( KAknFepChineseInputMode, conversion ) );
       
  2975             }
       
  2976         else if( language == ELangHongKongChinese )
       
  2977             {
       
  2978             conversion.Num( EStroke, EHex );
       
  2979             User::LeaveIfError( aknFepRepository->Set( KAknFepChineseInputMode, conversion ) );
       
  2980             }
       
  2981         else if( language == ELangTaiwanChinese )
       
  2982             {
       
  2983             conversion.Num( EZhuyin, EHex );
       
  2984             User::LeaveIfError( aknFepRepository->Set( KAknFepChineseInputMode, conversion ) );
       
  2985             }
       
  2986         }
       
  2987     CleanupStack::PopAndDestroy();
       
  2988     
       
  2989     iReply = HBufC8::NewL( 1 );
       
  2990     iReply->Des().Append( 0 );
       
  2991     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleSetLanguageL" );
       
  2992     }
       
  2993 
       
  2994 void CHtiSysInfoServicePlugin::SetDefaultNumberModeL(TInt aMode, TInt aNbrModeType)
       
  2995     {
       
  2996 
       
  2997     CRepository* localeRepository = CRepository::NewL(KCRUidLocaleSettings);
       
  2998     CleanupStack::PushL(localeRepository);
       
  2999     if (aNbrModeType == EGSNbrModeTypeArabic || aNbrModeType
       
  3000             == EGSNbrModeTypeEasternArabic)
       
  3001         {
       
  3002         localeRepository->Set(KSettingsDefaultNumberMode, aMode);
       
  3003         }
       
  3004     else
       
  3005         {
       
  3006         localeRepository->Set(KSettingsIndicDefaultNumberMode, aMode);
       
  3007         }
       
  3008     CleanupStack::PopAndDestroy();
       
  3009 
       
  3010     TLocale locale;
       
  3011     if (aMode == EGSNbrModeLatin)
       
  3012         {
       
  3013         locale.SetDigitType(EDigitTypeWestern);
       
  3014         }
       
  3015     else
       
  3016         {
       
  3017         //if aMode <> EGSNbrModeLatin, then it should be either latin or arabic. However
       
  3018         //as EGSNbrModeArabic and EGsNbrModeIndic both have a value = 1, we can't use
       
  3019         //that constant for below comparison. Hence, need to depend on the 2nd param.
       
  3020         switch (aNbrModeType)
       
  3021             {
       
  3022             case EGSNbrModeTypeArabic:
       
  3023                 locale.SetDigitType(EDigitTypeArabicIndic);
       
  3024                 break;
       
  3025             case EGSNbrModeTypeIndic:
       
  3026                 locale.SetDigitType(EDigitTypeDevanagari);
       
  3027                 break;
       
  3028             case EGSNbrModeTypeEasternArabic:
       
  3029                 locale.SetDigitType(EDigitTypeEasternArabicIndic);
       
  3030                 break;
       
  3031             default:
       
  3032                 break;
       
  3033             }
       
  3034         }
       
  3035 
       
  3036     locale.Set();
       
  3037     }
       
  3038 //------------------------------------------------------------------------------
       
  3039 // CHtiSysInfoServicePlugin::ParseTimeDataL
       
  3040 //------------------------------------------------------------------------------
       
  3041 void CHtiSysInfoServicePlugin::ParseTimeDataL( const TDesC8& aTimeData,
       
  3042                                                TTime& aResult )
       
  3043     {
       
  3044     /*
       
  3045       aTimeData =
       
  3046         bytes 0 - 1 = year
       
  3047                   2 = month
       
  3048                   3 = day
       
  3049                   4 = hour
       
  3050                   5 = minute
       
  3051                   6 = second
       
  3052     */
       
  3053     if ( aTimeData.Length() != KTimeDataLength )
       
  3054         {
       
  3055         User::Leave( KErrBadDescriptor );
       
  3056         }
       
  3057 
       
  3058     TInt year   = aTimeData[0] + ( aTimeData[1] << 8 );
       
  3059     TInt month  = aTimeData[2];
       
  3060     TInt day    = aTimeData[3];
       
  3061     TInt hour   = aTimeData[4];
       
  3062     TInt minute = aTimeData[5];
       
  3063     TInt second = aTimeData[6];
       
  3064 
       
  3065     TDateTime dateTime;
       
  3066     User::LeaveIfError( dateTime.Set(
       
  3067         year, TMonth( month - 1 ), day - 1, hour, minute, second, 0 ) );
       
  3068     aResult = dateTime;
       
  3069     }
       
  3070 
       
  3071 //------------------------------------------------------------------------------
       
  3072 // CHtiSysInfoServicePlugin::CleanUpTempFiles
       
  3073 //------------------------------------------------------------------------------
       
  3074 TInt CHtiSysInfoServicePlugin::CleanUpTempFiles()
       
  3075     {
       
  3076     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::CleanUpTempFiles" );
       
  3077     TFindFile finder( iFs );
       
  3078     CDir* dir = NULL;
       
  3079     TInt err = finder.FindWildByDir(KMatchFileName, KTempFilePath, dir);
       
  3080     TInt safeDeleteCount = 0;
       
  3081     while ( err == KErrNone && safeDeleteCount < 20)
       
  3082         {
       
  3083         safeDeleteCount++;
       
  3084         TFileName path;
       
  3085         path.Copy(finder.File());
       
  3086         HTI_LOG_FORMAT( "found file: %S", &path );
       
  3087         TInt ret = iFileMan->Delete(path);
       
  3088         delete dir;
       
  3089         dir = NULL;
       
  3090         if(ret != KErrNone)
       
  3091             {
       
  3092             break;
       
  3093             }
       
  3094         err = finder.FindWildByDir(KMatchFileName, KTempFilePath, dir);
       
  3095         }
       
  3096     HTI_LOG_FUNC_OUT("CHtiSysInfoServicePlugin::CleanUpTempFiles");
       
  3097     return KErrNone;
       
  3098     }
       
  3099 
       
  3100 //------------------------------------------------------------------------------
       
  3101 // CHtiSysInfoServicePlugin::CanTurnBluetoothOnL
       
  3102 //------------------------------------------------------------------------------
       
  3103 TBool CHtiSysInfoServicePlugin::CanTurnBluetoothOnL( const TBool aUseForce )
       
  3104     {
       
  3105     HTI_LOG_FUNC_IN("CHtiSysInfoServicePlugin::CanTurnBluetoothOnL");
       
  3106     TInt isInNetwork = 0;
       
  3107     CRepository* repository = CRepository::NewL( KCRUidCoreApplicationUIs );
       
  3108     repository->Get( KCoreAppUIsNetworkConnectionAllowed, isInNetwork );
       
  3109     HTI_LOG_FORMAT( "isInNetwork = %d", isInNetwork );
       
  3110     delete repository;
       
  3111 
       
  3112     if ( isInNetwork )
       
  3113         {
       
  3114         return ETrue;
       
  3115         }
       
  3116 
       
  3117     // Phone is offline - check if it's allowed to turn BT on.
       
  3118 
       
  3119     // If the force flag was not set in command, we won't turn BT on in offline.
       
  3120     if ( !aUseForce )
       
  3121         {
       
  3122         return EFalse;
       
  3123         }
       
  3124 
       
  3125     // Check if it's possible to turn BT on in offline mode.
       
  3126     TInt btOfflineEnabled = 0;
       
  3127     CRepository* repository2 = CRepository::NewL( KCRUidBluetoothEngine );
       
  3128     repository2->Get( KBTEnabledInOffline, btOfflineEnabled );
       
  3129     HTI_LOG_FORMAT( "btOfflineEnabled = %d", btOfflineEnabled );
       
  3130     delete repository2;
       
  3131 
       
  3132     if ( btOfflineEnabled )
       
  3133         {
       
  3134         return ETrue;
       
  3135         }
       
  3136     HTI_LOG_FUNC_OUT("CHtiSysInfoServicePlugin::CanTurnBluetoothOnL");
       
  3137     return EFalse;
       
  3138     }
       
  3139 
       
  3140 
       
  3141 // ----------------------------------------------------------------------------
       
  3142 CAsyncWaiter* CAsyncWaiter::NewL( TInt aPriority )
       
  3143     {
       
  3144     CAsyncWaiter* self = new(ELeave) CAsyncWaiter( aPriority );
       
  3145     return self;
       
  3146     }
       
  3147 
       
  3148 // ----------------------------------------------------------------------------
       
  3149 CAsyncWaiter* CAsyncWaiter::NewLC( TInt aPriority )
       
  3150     {
       
  3151     CAsyncWaiter* self = new ( ELeave ) CAsyncWaiter( aPriority );
       
  3152     CleanupStack::PushL( self );
       
  3153     return self;
       
  3154     }
       
  3155 
       
  3156 // ----------------------------------------------------------------------------
       
  3157 CAsyncWaiter::CAsyncWaiter( TInt aPriority ) : CActive( aPriority )
       
  3158     {
       
  3159     iWait = new CActiveSchedulerWait();
       
  3160     CActiveScheduler::Add( this );
       
  3161     }
       
  3162 
       
  3163 // ----------------------------------------------------------------------------
       
  3164 CAsyncWaiter::~CAsyncWaiter()
       
  3165     {
       
  3166     Cancel();
       
  3167     delete iWait;
       
  3168     }
       
  3169 
       
  3170 // ----------------------------------------------------------------------------
       
  3171 void CAsyncWaiter::StartAndWait()
       
  3172     {
       
  3173     HTI_LOG_FUNC_IN( "CAsyncWaiter::StartAndWait" );
       
  3174     iStatus = KRequestPending;
       
  3175     SetActive();
       
  3176     iWait->Start();
       
  3177     HTI_LOG_FUNC_OUT( "CAsyncWaiter::StartAndWait" );
       
  3178     }
       
  3179 
       
  3180 // ----------------------------------------------------------------------------
       
  3181 TInt CAsyncWaiter::Result() const
       
  3182     {
       
  3183     return iResult;
       
  3184     }
       
  3185 
       
  3186 // ----------------------------------------------------------------------------
       
  3187 void CAsyncWaiter::RunL()
       
  3188     {
       
  3189     HTI_LOG_FUNC_IN( "CAsyncWaiter::RunL" );
       
  3190     iResult = iStatus.Int();
       
  3191     iWait->AsyncStop();
       
  3192     HTI_LOG_FUNC_OUT( "CAsyncWaiter::RunL" );
       
  3193     }
       
  3194 
       
  3195 // ----------------------------------------------------------------------------
       
  3196 void CAsyncWaiter::DoCancel()
       
  3197     {
       
  3198     iResult = KErrCancel;
       
  3199     if ( iStatus == KRequestPending )
       
  3200         {
       
  3201         TRequestStatus* status = &iStatus;
       
  3202         User::RequestComplete( status, KErrCancel );
       
  3203         }
       
  3204     iWait->AsyncStop();
       
  3205     }
       
  3206 
       
  3207 
       
  3208 // End of file