devicediagnostics/diagplugins/diagvibrateplugin/src/diagvibrateplugin.cpp
changeset 0 3ce708148e4d
child 54 9360ca28b668
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Vibrate plugin interface implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <avkon.hrh>
       
    21 #include <AknQueryDialog.h>
       
    22 #include <aknmessagequerydialog.h>
       
    23 #include <DiagFrameworkDebug.h>         
       
    24 #include <DiagTestExecParam.h>      
       
    25 #include <DiagTestObserver.h>       
       
    26 #include <devdiagvibratepluginrsc.rsg>
       
    27 #include <hal.h>
       
    28 #include <hwrmpowerstatesdkpskeys.h>
       
    29 #include <MProEngEngine.h>
       
    30 #include <MProEngProfile.h>
       
    31 #include <MProEngToneSettings.h>
       
    32 #include <ProEngFactory.h> 
       
    33 #include <DiagEngineCommon.h>    
       
    34 #include <DiagCommonDialog.h>    
       
    35 #include <StringLoader.h>           
       
    36 #include <centralrepository.h>
       
    37 
       
    38 #include "diagvibrateplugin.h"
       
    39 #include "diagvibrateplugin.hrh"
       
    40 #include "diagvibratepluginengine.h"
       
    41 #include "diagvibratepluginprivatecrkeys.h"
       
    42 
       
    43 // EXTERNAL DATA STRUCTURES
       
    44 
       
    45 // EXTERNAL FUNCTION PROTOTYPES
       
    46 
       
    47 // CONSTANTS
       
    48 const TUid KDiagVibratePluginUid = { DIAG_VIBRATE_PLUGIN_UID };
       
    49 static const TInt KProgressDialogIncrementSize = 10;
       
    50 static const TInt KProgressDialogFinalValue = 100;
       
    51 static const TInt KHundredthsInSecond = 100;
       
    52 
       
    53 static const TInt KVibratePluginTotalStep = 1;
       
    54 
       
    55 // MACROS
       
    56 _LIT( KDiagVibratePluginResourceFileName, "z:DevDiagVibratePluginRsc.rsc" );
       
    57 
       
    58 // LOCAL CONSTANTS AND MACROS
       
    59 #ifdef _DEBUG
       
    60     enum TVibratePluginPanic
       
    61         {
       
    62         EPanicUnknownVibraState= 900,
       
    63         EPanicInitParamsNull,
       
    64         EPanicStateRepeated
       
    65         };
       
    66 
       
    67     _LIT( KVibratePluginErrorUnknownVibraStateText, "VibraStatusChanged: Unknown vibra state" );
       
    68     _LIT( KVibratePluginErrorInitParamsNullText, "NewL: InitParams NULL" );
       
    69     _LIT( KVibratePluginErrorStateRepeatedText, "State change not effective" );
       
    70 #endif
       
    71 
       
    72 // MODULE DATA STRUCTURES
       
    73 
       
    74 // LOCAL FUNCTION PROTOTYPES
       
    75 
       
    76 // FORWARD DECLARATIONS
       
    77 
       
    78 // ============================= LOCAL FUNCTIONS ==============================
       
    79 
       
    80 // ========================= MEMBER FUNCTIONS ================================
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CDiagVibratePlugin::NewL()
       
    84 //
       
    85 // Symbian OS default constructor
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 MDiagPlugin* CDiagVibratePlugin::NewL( TAny* aInitParams )
       
    89     {
       
    90     __ASSERT_DEBUG( aInitParams, User::Panic ( KVibratePluginErrorInitParamsNullText, 
       
    91         EPanicInitParamsNull ));
       
    92 
       
    93     CDiagPluginConstructionParam* param = NULL;
       
    94     param = static_cast<CDiagPluginConstructionParam*>( aInitParams );    
       
    95 
       
    96     CleanupStack::PushL( param );    
       
    97     CDiagVibratePlugin* self = new( ELeave ) CDiagVibratePlugin ( param );
       
    98     CleanupStack::Pop( param );
       
    99 
       
   100     CleanupStack::PushL( self );
       
   101     self->ConstructL();
       
   102     
       
   103     CleanupStack::Pop( self ); // self
       
   104     return self;
       
   105     }
       
   106 
       
   107 
       
   108 // ----------------------------------------------------------------------------
       
   109 // CDiagVibratePlugin::~CDiagVibratePlugin
       
   110 //
       
   111 // Destructor
       
   112 // ----------------------------------------------------------------------------
       
   113 //
       
   114 CDiagVibratePlugin::~CDiagVibratePlugin()
       
   115     {
       
   116     Cancel();
       
   117     delete iProgressDialog;
       
   118     delete iEngine;
       
   119     }
       
   120 
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // From MDiagPlugin
       
   124 // CDiagVibratePlugin::IsVisible()
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 TBool CDiagVibratePlugin::IsVisible() const
       
   128     {
       
   129     return ETrue;
       
   130     }
       
   131 
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // From MDiagTestPlugin
       
   135 // CDiagVibratePlugin::RunMode()
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 MDiagTestPlugin::TRunMode CDiagVibratePlugin::RunMode() const
       
   139     {
       
   140     return EInteractiveDialog;
       
   141     }
       
   142 
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // From MDiagTestPlugin
       
   146 // CDiagVibratePlugin::TotalSteps()
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 TUint CDiagVibratePlugin::TotalSteps() const
       
   150     {
       
   151     return KVibratePluginTotalStep;
       
   152     }
       
   153 
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // From MDiagPlugin
       
   157 // CDiagVibratePlugin::GetPluginNameL
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 HBufC* CDiagVibratePlugin::GetPluginNameL( TNameLayoutType aLayoutType ) const
       
   161     {
       
   162     switch ( aLayoutType )
       
   163         {
       
   164         case ENameLayoutHeadingPane:
       
   165             return StringLoader::LoadL( R_DIAG_MSG_TITLE_VIBRATE );
       
   166 
       
   167         case ENameLayoutPopupInfoPane:
       
   168             return StringLoader::LoadL ( R_DIAG_MSG_INFO_VIBRATE );
       
   169 
       
   170         case ENameLayoutTitlePane:
       
   171             return StringLoader::LoadL( R_DIAG_TITLE_TEST_VIBRATE );
       
   172 
       
   173         case ENameLayoutListSingleGraphic:
       
   174             return StringLoader::LoadL( R_DIAG_LST_TEST_VIBRATE );
       
   175 
       
   176         case ENameLayoutListSingle:
       
   177             return StringLoader::LoadL ( R_DIAG_LST_VIBRATE );
       
   178 
       
   179         default:
       
   180             LOGSTRING2( "CDiagVibratePlugin::GetPluginNameL: "
       
   181                 L"ERROR: Unsupported layout type %d", aLayoutType )
       
   182             __ASSERT_DEBUG( 0, User::Invariant() );
       
   183             return StringLoader::LoadL( R_DIAG_LST_VIBRATE );
       
   184         }
       
   185     }
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // From MDiagPlugin
       
   189 // CDiagVibratePlugin::Uid
       
   190 // ---------------------------------------------------------------------------
       
   191 //
       
   192 TUid CDiagVibratePlugin::Uid() const
       
   193     {
       
   194     return KDiagVibratePluginUid;
       
   195     }
       
   196 
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // From MDiagVibratePluginObserver
       
   200 // MDiagVibratePluginObserver::VibraStatusChanged
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 void CDiagVibratePlugin::VibraStatusChanged( TVibrateStatus aStatus )
       
   204     {
       
   205     CDiagVibratePlugin::TState newState = EStateUnknown; 
       
   206     
       
   207     switch ( aStatus )
       
   208         {
       
   209         case EVibrateStarted:
       
   210             //The vibra can be started only from the idle state
       
   211             newState = ( iState == EStateIdle || iState == EStateRestart) ? EStateVibrating : EStateUnknown;
       
   212             break;
       
   213              
       
   214         case EVibrateEnded:
       
   215             //Vibra should not be stopped before it is started
       
   216             newState = ( iState == EStateVibrating ) ? EStateUserQuery : EStateUnknown;
       
   217             break;
       
   218             
       
   219         case EVibrateFailed:
       
   220             //check if already failed, cancelled or skipped
       
   221             newState = ( iState != EStateFailed && iState != EStateCancelled &&
       
   222                          iState != EStateSkipped ) ? EStateFailed : EStateUnknown;
       
   223             break;        
       
   224                 
       
   225         case EVibrateBlocked:
       
   226 			newState = ( iState == EStateVibrating ) ? EStateBlocked : EStateUnknown;
       
   227 			break;
       
   228         default: //should never happen..
       
   229             __ASSERT_DEBUG( 0, User::Panic( KVibratePluginErrorUnknownVibraStateText,
       
   230                 EPanicUnknownVibraState ) );
       
   231             return;
       
   232         }
       
   233         
       
   234     if ( newState != EStateUnknown) // Check if new state is available
       
   235         {
       
   236         SetState( newState );
       
   237         SetActive();
       
   238         TRequestStatus* status = &iStatus;
       
   239         User::RequestComplete(status, KErrNone);
       
   240         }
       
   241         
       
   242     }
       
   243 
       
   244 // ----------------------------------------------------------------------------
       
   245 // From MProgressDialogCallback
       
   246 // Progress dialog has been dismissed
       
   247 // ----------------------------------------------------------------------------
       
   248 //
       
   249 void CDiagVibratePlugin::DialogDismissedL( TInt aButtonId )
       
   250     {
       
   251     //Processing the user input only if the state is still vibrating
       
   252     if ( iState == EStateVibrating )
       
   253         {
       
   254         iEngine->StopVibra();
       
   255 
       
   256         CDiagVibratePlugin::TState newState = EStateUnknown; 
       
   257         
       
   258         switch ( aButtonId )
       
   259             {
       
   260             case ECBACmdSkip:
       
   261                 newState = EStateSkipped;
       
   262                 break;
       
   263 
       
   264             case ECBACmdCancel:
       
   265                 newState = EStateCancelled;
       
   266                 break;
       
   267                 
       
   268             default:
       
   269                 break;
       
   270             }
       
   271         
       
   272         if ( newState != EStateUnknown )
       
   273             {
       
   274             SetState( newState );
       
   275             SetActive();
       
   276             TRequestStatus* status = &iStatus;
       
   277             User::RequestComplete(status, KErrNone);
       
   278             }
       
   279         }
       
   280     else if(aButtonId == EAknSoftkeyOk)
       
   281         {
       
   282         CDiagVibratePlugin::TState newState = EStateUserQuery;
       
   283         SetState( newState );
       
   284         SetActive();
       
   285         TRequestStatus* status = &iStatus;
       
   286         User::RequestComplete(status, KErrNone);
       
   287         }
       
   288      
       
   289     }
       
   290 
       
   291 // ----------------------------------------------------------------------------
       
   292 // CDiagVibratePlugin::CDiagVibratePlugin()
       
   293 //
       
   294 // Constructor
       
   295 // ----------------------------------------------------------------------------
       
   296 //
       
   297 CDiagVibratePlugin::CDiagVibratePlugin( CDiagPluginConstructionParam* aParam )
       
   298     :   CDiagTestPluginBase( aParam ),
       
   299         iState( EStateCancelled )
       
   300     {
       
   301     }
       
   302 
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 // CDiagVibratePlugin::ConstructL()
       
   306 //
       
   307 // Symbian OS two-phased constructor
       
   308 // ---------------------------------------------------------------------------
       
   309 //
       
   310 void CDiagVibratePlugin::ConstructL()
       
   311     {
       
   312     BaseConstructL ( KDiagVibratePluginResourceFileName );
       
   313     ReadVibrationTimeL();
       
   314     }
       
   315 
       
   316 
       
   317 // ---------------------------------------------------------------------------
       
   318 // From CDiagTestPluginBase
       
   319 // CDiagVibratePlugin::DoRunTestL()
       
   320 // ---------------------------------------------------------------------------
       
   321 //
       
   322 void CDiagVibratePlugin::DoRunTestL()
       
   323     {
       
   324     SetState( EStateIdle );
       
   325 
       
   326     //Let's confirm from the user that the test should be run
       
   327     FOREVER
       
   328         {
       
   329         CAknMessageQueryDialog* dialog = new ( ELeave ) CAknMessageQueryDialog();
       
   330         dialog->PrepareLC( R_VIBRATEPLUGIN_STARTQUERY );
       
   331         
       
   332         // If the test is run as a single test removing skip button
       
   333         if ( SinglePluginExecution() )
       
   334             {
       
   335             CEikButtonGroupContainer& cba = dialog->ButtonGroupContainer();
       
   336             cba.SetCommandSetL( R_VIBRATE_SOFTKEYS_OK__CANCEL );
       
   337             }
       
   338 
       
   339         TInt queryResult;
       
   340         
       
   341         if ( !RunWaitingDialogL( dialog, queryResult ) )
       
   342             {
       
   343             // Dialog is dismissed by deletion. Exit immediately without
       
   344             // accessing member variable, to prevent crash
       
   345             return;
       
   346             }
       
   347 
       
   348         //Let's check the user answer
       
   349         switch ( queryResult )
       
   350             {
       
   351             
       
   352             // ADO & Platformization Changes
       
   353             //case ECBACmdSkip:
       
   354             case ECBACmdCancel:
       
   355                 CompleteTestL( CDiagResultsDatabaseItem::ESkipped );
       
   356                 return;
       
   357 
       
   358 			case ECBACmdSkip:
       
   359 			
       
   360             //case ECBACmdCancel:
       
   361                 {
       
   362                 //if ( SinglePluginExecution() )
       
   363                   //  {
       
   364                    // CompleteTestL( CDiagResultsDatabaseItem::ECancelled );
       
   365                    // return;
       
   366                    // }
       
   367                // else 
       
   368                  //   {
       
   369                       // See if the user really wants to cancel tests.
       
   370                     TInt confirmResult = 0;
       
   371                 
       
   372                     CAknDialog* dlg = ExecutionParam().Engine().
       
   373                     CreateCommonDialogLC( EDiagCommonDialogConfirmSkipAll, NULL );
       
   374                 
       
   375                     if ( !RunWaitingDialogL( dlg, confirmResult ) )
       
   376                         {
       
   377                         return;
       
   378                         }
       
   379                     /*
       
   380                     if ( confirmResult != EAknSoftkeyNo )
       
   381                         {
       
   382                        CompleteTestL( CDiagResultsDatabaseItem::ECancelled ); 
       
   383                         return;
       
   384                         }
       
   385                     */
       
   386                     if (confirmResult)
       
   387                            {
       
   388                            //CompleteTestL( CDiagResultsDatabaseItem::ECancelled ); 
       
   389                            return;
       
   390                            }
       
   391                     
       
   392                  //   }
       
   393               
       
   394                 // Break and display the dialog again.
       
   395                 }
       
   396                 break;
       
   397                 // Changes ends
       
   398                 
       
   399             case EAknSoftkeyOk:
       
   400                 {
       
   401                 //Let's check that the charger is not connected
       
   402                 
       
   403                 if ( IsChargerConnected() && !DisplayDisconnectChargerQueryL() )
       
   404                     {
       
   405                     return;
       
   406                     }
       
   407                 //Let's start the test by activating active object
       
   408                 SetActive();
       
   409                 TRequestStatus* status = &iStatus;
       
   410                 User::RequestComplete(status, KErrNone);
       
   411                 return;
       
   412                 }
       
   413             default:
       
   414                 return;
       
   415             }
       
   416         }
       
   417     }
       
   418 
       
   419 
       
   420 // ---------------------------------------------------------------------------
       
   421 // From CActive
       
   422 // CDiagVibratePlugin::RunL
       
   423 // ---------------------------------------------------------------------------
       
   424 //
       
   425 void CDiagVibratePlugin::RunL()
       
   426     {
       
   427 
       
   428 	// ravi - badwarning #546-D    
       
   429     TRequestStatus* status = &iStatus;
       
   430     
       
   431     switch (iState) 
       
   432         {
       
   433         case EStateRestart:
       
   434         	{
       
   435         	iEngine->StopVibra();
       
   436         	LOGSTRING( "In RunL, EStateRestart");
       
   437             ShowVibratingNoteL();
       
   438             iEngine = CDiagVibratePluginEngine::NewL( *this );    
       
   439             TRAPD(Err,iEngine->StartVibraL( iVibrationTime ));
       
   440             if (Err == KErrNone)
       
   441             LOGSTRING("Leave code for restart = Kerrnone");
       
   442             LOGSTRING2( "Leave Code for in Restart StartVibra in Hex( 0x%x )", Err );
       
   443             break;
       
   444         	}
       
   445         case EStateIdle:
       
   446             if(!SetVibrateSettingOnL())
       
   447             	break;
       
   448             ShowVibratingNoteL();
       
   449             iEngine = CDiagVibratePluginEngine::NewL( *this );    
       
   450             iEngine->StartVibraL( iVibrationTime );
       
   451             break;
       
   452             
       
   453         case EStateVibrating:
       
   454             //Vibration started -> no action needed
       
   455             break;
       
   456             
       
   457         case EStateUserQuery: 
       
   458             {
       
   459             delete iEngine;
       
   460             iEngine = NULL;
       
   461             
       
   462             if ( iProgressDialog )
       
   463                 {
       
   464                 iProgressDialog->ProcessFinishedL();
       
   465                 }
       
   466  
       
   467             SetVibrateSettingToOriginalValueL();
       
   468             //displaying user query: did the phone vibrate
       
   469 
       
   470             CAknQueryDialog* dialog = new ( ELeave ) CAknQueryDialog( CAknQueryDialog::ENoTone );
       
   471             dialog->PrepareLC( R_VIBRATEPLUGIN_CONFQUERY_DLG );
       
   472 
       
   473             TInt queryResult;
       
   474             if ( RunWaitingDialogL( dialog, queryResult ) )
       
   475                 {
       
   476                 //Let's check the user answer    
       
   477                 switch ( queryResult )
       
   478                     {
       
   479                     case EAknSoftkeyYes:
       
   480                         LOGSTRING("CDiagVibratePlugin-EAknSoftkeyYes")
       
   481                         CompleteTestL( CDiagResultsDatabaseItem::ESuccess );
       
   482                         break;
       
   483                         
       
   484                     case ECBACmdNo:
       
   485                         LOGSTRING("CDiagVibratePlugin-EAknSoftkeyNo")
       
   486                         CompleteTestL( CDiagResultsDatabaseItem::EFailed );
       
   487                         break;
       
   488                     
       
   489                     default:
       
   490                         LOGSTRING("CDiagVibratePlugin-Default")
       
   491                         break;
       
   492                     }
       
   493                 }
       
   494             }
       
   495             break;
       
   496             
       
   497         case EStateCancelled:
       
   498             {
       
   499              if ( SinglePluginExecution() )
       
   500                 {
       
   501                 CompleteTestL( CDiagResultsDatabaseItem::ECancelled );
       
   502                 return;
       
   503                 }
       
   504              else 
       
   505                 {                                                    
       
   506                 TInt confirmResult = 0;
       
   507                 CAknDialog* dlg = ExecutionParam().Engine().
       
   508                 CreateCommonDialogLC( EDiagCommonDialogConfirmCancelAll, NULL );
       
   509                 
       
   510                 if ( !RunWaitingDialogL( dlg, confirmResult ) )
       
   511                     {
       
   512                     //the dialog got deleted, returning right away
       
   513                     return;
       
   514                     }                    
       
   515                     
       
   516                 if ( confirmResult == EAknSoftkeyYes )
       
   517                     {
       
   518                     //test is cancelled
       
   519                     CompleteTestL( CDiagResultsDatabaseItem::ECancelled );
       
   520                     }
       
   521                 else //EAknSoftKeyNo
       
   522                     {
       
   523                     //let's rerun the test
       
   524                     DoStopAndCleanupL();
       
   525                     DoRunTestL();
       
   526                     }
       
   527                 }
       
   528             }
       
   529             break; 
       
   530         
       
   531         case EStateSkipped:
       
   532             CompleteTestL( CDiagResultsDatabaseItem::ESkipped );
       
   533             break;
       
   534        
       
   535         case EStateFailed:
       
   536             CompleteTestL( CDiagResultsDatabaseItem::EFailed );
       
   537             break;
       
   538         
       
   539         case EStateBlocked:
       
   540         	LOGSTRING( "In RunL, EStateBlocked");
       
   541         	if ( iProgressDialog )
       
   542         		{
       
   543         		iProgressDialog->ProcessFinishedL();       
       
   544         		}
       
   545         	if (!DisplayDisconnectChargerQueryL() )
       
   546                {
       
   547                 return;
       
   548                }
       
   549                 //Let's start the test by activating active object
       
   550             SetState( EStateRestart );
       
   551             SetActive();
       
   552             User::RequestComplete(status, KErrNone);
       
   553 
       
   554         	break;
       
   555             
       
   556         default:
       
   557             __ASSERT_DEBUG( 0, User::Panic( KVibratePluginErrorUnknownVibraStateText,
       
   558                 EPanicUnknownVibraState ) );
       
   559             break;    
       
   560         }
       
   561     }    
       
   562 
       
   563 
       
   564 // ---------------------------------------------------------------------------
       
   565 // From CActive
       
   566 // CDiagVibratePlugin::DoCancel
       
   567 // ---------------------------------------------------------------------------
       
   568 //
       
   569 void CDiagVibratePlugin::DoCancel()
       
   570     {
       
   571     }    
       
   572 
       
   573 
       
   574 // ---------------------------------------------------------------------------
       
   575 // Cleanup the created resources
       
   576 // CDiagVibratePlugin::DoStopAndCleanupL
       
   577 // ---------------------------------------------------------------------------
       
   578 //
       
   579 void CDiagVibratePlugin::DoStopAndCleanupL()
       
   580     {
       
   581     delete iEngine;    
       
   582     iEngine = NULL;
       
   583     if ( iProgressDialog )
       
   584         {
       
   585         iProgressDialog->ProcessFinishedL();       
       
   586         }
       
   587     SetVibrateSettingToOriginalValueL();
       
   588     iVibrateSettingUpdated = EFalse;
       
   589     if ( iState != EStateCancelled )
       
   590         {
       
   591         SetState( EStateCancelled );
       
   592         }
       
   593     }
       
   594 
       
   595     
       
   596 // ---------------------------------------------------------------------------
       
   597 // Makes sure vibrate is enabled in the profile
       
   598 // CDiagVibratePlugin::SetVibrateSettingOnL
       
   599 // ---------------------------------------------------------------------------
       
   600 //
       
   601 TInt CDiagVibratePlugin::SetVibrateSettingOnL()
       
   602     {
       
   603     MProEngEngine* profileEng = ProEngFactory::NewEngineL();
       
   604     CleanupDeletePushL(profileEng);
       
   605 
       
   606     MProEngProfile* profile = profileEng->ActiveProfileL();
       
   607     MProEngToneSettings& profileToneSettings = profile->ToneSettings();
       
   608     iOrigVibrateSetting = profileToneSettings.VibratingAlert();
       
   609    
       
   610    //set the vibration setting on if it is not on already
       
   611     if (!iOrigVibrateSetting)
       
   612         {
       
   613         if(!ShowActivateConfNoteL())
       
   614         {
       
   615         		profile->Release();    
       
   616     			CleanupStack::PopAndDestroy(profileEng);
       
   617     			return EFalse;
       
   618     	}
       
   619         profileToneSettings.SetVibratingAlert(ETrue);
       
   620         profile->CommitChangeL();
       
   621         iVibrateSettingUpdated = ETrue;
       
   622         }
       
   623     
       
   624     profile->Release();    
       
   625     CleanupStack::PopAndDestroy(profileEng);
       
   626     return ETrue;
       
   627     }
       
   628     
       
   629     
       
   630 TInt CDiagVibratePlugin::ShowActivateConfNoteL()
       
   631 {
       
   632 	CAknQueryDialog * dialog = new (ELeave) CAknQueryDialog();
       
   633     dialog->PrepareLC( R_VIBRATEPLUGIN_VIBRATE_ACTIVATE_DLG );
       
   634     
       
   635     
       
   636     TInt queryResult;
       
   637         
       
   638     if ( !RunWaitingDialogL( dialog, queryResult ) )
       
   639          {
       
   640          // Dialog is dismissed by deletion. Exit immediately without
       
   641          // accessing member variable, to prevent crash
       
   642          return EFalse;
       
   643          }
       
   644 
       
   645         //Let's check the user answer
       
   646         switch ( queryResult )
       
   647             {
       
   648             
       
   649             case ECBACmdNo:
       
   650                 CompleteTestL( CDiagResultsDatabaseItem::ESkipped );
       
   651                 return EFalse;
       
   652 
       
   653             case EAknSoftkeyYes:
       
   654             	return ETrue;
       
   655 
       
   656             default:
       
   657                 return EFalse;
       
   658             }	
       
   659 	
       
   660 }
       
   661 
       
   662     
       
   663 // ---------------------------------------------------------------------------
       
   664 // Sets the vibration setting to its original value
       
   665 // CDiagVibratePlugin::SetVibrateSettingToOriginalValueL
       
   666 // ---------------------------------------------------------------------------
       
   667 //
       
   668 void CDiagVibratePlugin::SetVibrateSettingToOriginalValueL()
       
   669     {
       
   670     if ( !iVibrateSettingUpdated )
       
   671         {
       
   672         return;
       
   673         }
       
   674         
       
   675     MProEngEngine* profileEng = ProEngFactory::NewEngineL();
       
   676     MProEngProfile* profile = profileEng->ActiveProfileL();
       
   677     MProEngToneSettings& profileToneSettings = profile->ToneSettings();
       
   678     
       
   679     //Check if vibrate setting need to be turned off again
       
   680     if ( !iOrigVibrateSetting )
       
   681         {
       
   682         profileToneSettings.SetVibratingAlert( EFalse );
       
   683         profile->CommitChangeL();
       
   684         }
       
   685         
       
   686     profile->Release();
       
   687     profileEng->Release();                
       
   688 
       
   689     iVibrateSettingUpdated = EFalse;
       
   690     }    
       
   691 
       
   692 
       
   693 // ---------------------------------------------------------------------------
       
   694 // Checks if the charger is connected if yes the user is asked to removed it.
       
   695 // CDiagVibratePlugin::IsChargerConnected
       
   696 // ---------------------------------------------------------------------------
       
   697 //
       
   698 TBool CDiagVibratePlugin::IsChargerConnected() const
       
   699     {
       
   700     TInt charger;
       
   701     TBool result = EFalse;
       
   702     
       
   703     if( RProperty::Get( KPSUidHWRMPowerState, KHWRMChargingStatus, charger ) == KErrNone )
       
   704         {
       
   705         switch( charger )
       
   706             {
       
   707             case EChargingStatusCharging:
       
   708             case EChargingStatusNotCharging:
       
   709             case EChargingStatusChargingComplete:
       
   710             case EChargingStatusAlmostComplete:
       
   711             case EChargingStatusChargingContinued:
       
   712                 result = ETrue;
       
   713                 break;
       
   714                 
       
   715             case EChargingStatusNotConnected:
       
   716             default:
       
   717                 break;
       
   718             }
       
   719         }
       
   720         
       
   721     return( result );
       
   722     }
       
   723 
       
   724 
       
   725 // ---------------------------------------------------------------------------
       
   726 // Sets the internal state
       
   727 // CDiagVibratePlugin::SetState
       
   728 // ---------------------------------------------------------------------------
       
   729 //
       
   730 void CDiagVibratePlugin::SetState( CDiagVibratePlugin::TState aState )
       
   731     {
       
   732     __ASSERT_DEBUG( iState != aState, User::Panic( KVibratePluginErrorStateRepeatedText,
       
   733                 EPanicStateRepeated ) );
       
   734 
       
   735     iState = aState;
       
   736     }
       
   737 
       
   738 // ---------------------------------------------------------------------------
       
   739 // Displays disconnect charger query
       
   740 // CDiagVibratePlugin::DisplayDisconnectChargerQuery
       
   741 // ---------------------------------------------------------------------------
       
   742 //
       
   743 TBool CDiagVibratePlugin::DisplayDisconnectChargerQueryL()
       
   744     {
       
   745     FOREVER
       
   746         {
       
   747         CAknQueryDialog* dialog = new ( ELeave ) CAknQueryDialog( CAknQueryDialog::ENoTone );
       
   748         dialog->PrepareLC( R_VIBRATEPLUGIN_DISCONNECT_CHARGER_DLG );
       
   749 
       
   750 
       
   751         TInt queryResult;
       
   752         
       
   753         if ( !RunWaitingDialogL( dialog, queryResult ) )
       
   754             {
       
   755             // Dialog is dismissed by deletion. Exit immediately without
       
   756             // accessing member variable, to prevent crash
       
   757             return EFalse;
       
   758             }
       
   759 
       
   760         //Let's check the user answer
       
   761         switch ( queryResult )
       
   762             {
       
   763             
       
   764             case ECBACmdCancel:
       
   765                 {
       
   766                 if ( SinglePluginExecution() )
       
   767                     {
       
   768                     CompleteTestL( CDiagResultsDatabaseItem::ESkipped );
       
   769                     return EFalse;
       
   770                     }
       
   771                 else
       
   772                     {
       
   773                     // See if the user really wants to cancel tests.
       
   774                     TInt confirmResult = 0;
       
   775                     
       
   776                     CAknDialog* dlg = ExecutionParam().Engine().
       
   777                         CreateCommonDialogLC( EDiagCommonDialogConfirmCancelAll, NULL );
       
   778                     
       
   779                     if ( !RunWaitingDialogL( dlg, confirmResult ) )
       
   780                         {
       
   781                         return EFalse;
       
   782                         }
       
   783                         
       
   784                     if ( confirmResult)
       
   785                         {
       
   786                         return EFalse;
       
   787                         }
       
   788                     else
       
   789                         {
       
   790                         continue;
       
   791                         }
       
   792                     }
       
   793 
       
   794                 // Break and display the dialog again.
       
   795                 }
       
   796                 
       
   797             case EAknSoftkeyOk:
       
   798                 if ( !IsChargerConnected() )
       
   799                     {
       
   800                     return ETrue;   
       
   801                     }
       
   802                 break;
       
   803             default:
       
   804                 return EFalse;
       
   805             }
       
   806         }
       
   807     }
       
   808 
       
   809 
       
   810 // ---------------------------------------------------------------------------
       
   811 // Displays vibrating progress dialog
       
   812 // ---------------------------------------------------------------------------
       
   813 //
       
   814 void CDiagVibratePlugin::ShowVibratingNoteL()
       
   815     {
       
   816     if ( iProgressDialog )
       
   817         {
       
   818         delete iProgressDialog;
       
   819         iProgressDialog = NULL;
       
   820         }
       
   821     
       
   822     //Calculate progress bar update interval in hundredths of seconds
       
   823     TInt interval = KHundredthsInSecond * iVibrationTime *
       
   824                     ( ( TReal ) KProgressDialogIncrementSize / 
       
   825                     KProgressDialogFinalValue );
       
   826                     
       
   827     iProgressDialog = new ( ELeave ) CAknProgressDialog( 
       
   828                         KProgressDialogFinalValue, 
       
   829                         KProgressDialogIncrementSize,
       
   830                         interval,
       
   831                         reinterpret_cast <CEikDialog**> ( &iProgressDialog ) );
       
   832 
       
   833     iProgressDialog->SetCallback( this );
       
   834     iProgressDialog->PrepareLC( R_VIBRATEPLUGIN_PROGRESS_NOTE_VIBRATING );
       
   835     
       
   836     // If the test is run as a single test removing skip button
       
   837     if ( SinglePluginExecution() )
       
   838         {
       
   839         CEikButtonGroupContainer& cba = iProgressDialog->ButtonGroupContainer();
       
   840         cba.SetCommandSetL( R_VIBRATE_SOFTKEYS_STOP__CANCEL );
       
   841         }
       
   842 
       
   843     iProgressDialog->RunLD();
       
   844     }
       
   845 
       
   846 
       
   847 // ---------------------------------------------------------------------------
       
   848 // Reads vibration time from central repository
       
   849 // ---------------------------------------------------------------------------
       
   850 //
       
   851 void CDiagVibratePlugin::ReadVibrationTimeL()
       
   852     {
       
   853     LOGSTRING( "CDiagVibratePlugin::ReadVibrationTimeL begin" );
       
   854                 
       
   855     CRepository* repository = CRepository::NewLC( KCRUidDevDiagVibraTestPlugin );  
       
   856          
       
   857     User::LeaveIfError( repository->Get( KDevDiagVibraTestVibrateTime, iVibrationTime ) );
       
   858     
       
   859     CleanupStack::PopAndDestroy( repository );
       
   860     
       
   861     LOGSTRING( "CDiagVibratePlugin::ReadVibrationTimeL end" );
       
   862     }
       
   863     
       
   864 
       
   865 // End of File