fotaapplication/fotacustcmds/src/fotacustcmdallreasons.cpp
branchRCL_3
changeset 25 b183ec05bd8c
equal deleted inserted replaced
24:13d7c31c74e0 25:b183ec05bd8c
       
     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:
       
    15 * Implementation of CFotaCustCmdAllReasons class.
       
    16 *
       
    17 */
       
    18 
       
    19 #include "fotacustcmdallreasons.h"
       
    20 #include "fotastartupDebug.h"
       
    21 #ifdef __SYNCML_DM_FOTA
       
    22 #include <fotaengine.h>
       
    23 #include "fmsclient.h"
       
    24 #include "fotaserverPrivateCRKeys.h"
       
    25 #include "FotaIPCTypes.h"
       
    26 #include "fmsclientserver.h"
       
    27 #endif
       
    28 #include <schtime.h>      
       
    29 #include <csch_cli.h>    
       
    30 #include <centralrepository.h>
       
    31 // RProperty
       
    32 #include <e32base.h>
       
    33 #include <e32property.h>
       
    34 // Memory status PS key headers
       
    35 #include <UikonInternalPSKeys.h>
       
    36 // Loading application headers
       
    37 #include <apgcli.h>
       
    38 #include <apacmdln.h>
       
    39 //Middleware includes
       
    40 #include <dmeventnotifiercrkeys.h>
       
    41 #include <dmeventnotifiercommon.h>
       
    42 
       
    43 // ======== MEMBER FUNCTIONS ========
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CFotaCustCmdAllReasons::NewL
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CFotaCustCmdAllReasons* CFotaCustCmdAllReasons::NewL()
       
    50 	{
       
    51   FLOG( _L( "[CFotaCustCmdAllReasons::NewL() BEGIN " ) );
       
    52 	return new ( ELeave ) CFotaCustCmdAllReasons;
       
    53 	}
       
    54 
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CFotaCustCmdAllReasons::~CFotaCustCmdAllReasons
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CFotaCustCmdAllReasons::~CFotaCustCmdAllReasons()
       
    61     {
       
    62       FLOG( _L( "[CFotaCustCmdAllReasons::~CFotaCustCmdAllReasons()  " ) );
       
    63     }
       
    64 
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CFotaCustCmdAllReasons::Initialize
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 TInt CFotaCustCmdAllReasons::Initialize( CSsmCustomCommandEnv* /*aCmdEnv*/ )
       
    71     {
       
    72     FLOG( _L( "[CFotaCustCmdAllReasons::~Initialize()  " ) );
       
    73 
       
    74     
       
    75     return KErrNone;
       
    76     }
       
    77 
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CFotaCustCmdAllReasons::Execute
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 void CFotaCustCmdAllReasons::Execute(
       
    84     const TDesC8& /*aParams*/,
       
    85     TRequestStatus& aRequest )
       
    86     {
       
    87      FLOG( _L( "[CFotaCustCmdAllReasons::~Execute() BEGIN " ) );
       
    88       aRequest = KRequestPending;
       
    89  #ifdef __SYNCML_DM_FOTA
       
    90     TRAP_IGNORE(ExecuteL());    
       
    91  #endif
       
    92     TRequestStatus* request = &aRequest;
       
    93     User::RequestComplete( request, KErrNone );
       
    94  FLOG( _L( "[CFotaCustCmdAllReasons::~Execute() END " ) ); 
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // CFotaCustCmdAllReasons::ExecuteL
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 void CFotaCustCmdAllReasons::ExecuteL( )
       
   102     {
       
   103     FLOG( _L( "[CFotaCustCmdAllReasons]::ExecuteL() Boot reason AllReason BEGIN " ) );
       
   104 
       
   105     RFotaEngineSession fotaEngine;
       
   106     //CheckCenrep if GA feature in ON then start else nothing.
       
   107     CRepository* centrep(NULL);
       
   108     TInt err = KErrNone;
       
   109     TRAP( err, centrep = CRepository::NewL( KCRUidFotaServer ) );
       
   110     TInt sendGAAfterrebootfeature = 0;
       
   111     TInt val(EFotaDefault);
       
   112 
       
   113     if (err == KErrNone)
       
   114         {
       
   115         err = centrep->Get(KFotaUpdateState, val);
       
   116 
       
   117         if (err == KErrNone)
       
   118             {
       
   119             // check if there is GA pending
       
   120 
       
   121             FTRACE(RDebug::Print(_L("[CFotaCustCmdAllReasons]  startup reason is %d"), val));
       
   122             switch (val)
       
   123                 {
       
   124                 case EFotaDownloadInterrupted:
       
   125                     {
       
   126                     FLOG( _L( "[CFotaCustCmdAllReasons] AllReason: Start FMS server " ) );
       
   127                     RFMSClient fmsClient;
       
   128                     TRAPD(err, fmsClient.OpenL());
       
   129                     if (err == KErrNone)
       
   130                         {
       
   131                         fmsClient.Close();
       
   132                         FLOG( _L( "[CFotaCustCmdAllReasons] AllReason: Closing FMS server  " ) );
       
   133                         }
       
   134                     }
       
   135                     break;
       
   136                 case EFotaPendingGenAlert:
       
   137                     {
       
   138                     FLOG( _L( "[CFotaCustCmdAllReasons] AllReason: Start fota server " ) );
       
   139                     err = centrep->Get(KGenericAlertResendAfterBoot,
       
   140                             sendGAAfterrebootfeature);
       
   141                     FTRACE(RDebug::Print(_L("[CFotaCustCmdAllReasons] feature sendGenericAlert is %d"), sendGAAfterrebootfeature));
       
   142 
       
   143                     if (sendGAAfterrebootfeature == 1)
       
   144                         {
       
   145                         TRAPD(oError,fotaEngine.OpenL());
       
   146                         if (oError == KErrNone)
       
   147                             {
       
   148                             fotaEngine.Close();
       
   149                             FLOG( _L( "[CFotaCustCmdAllReasons] AllReason: Closing fota server  " ) );
       
   150                             }
       
   151                         }
       
   152                     }
       
   153                     break;
       
   154                 case EFotaUpdateInterrupted:
       
   155                     {
       
   156                     FLOG(_L(" update interrupted >>"));
       
   157                     RFMSClient fmsclient;
       
   158                     TRAPD(err,fmsclient.OpenL());
       
   159                     if (err)
       
   160                         {
       
   161                         FLOG(_L( " opening fms failed " ) );
       
   162 
       
   163                         }
       
   164                     else
       
   165                         {
       
   166 
       
   167                         FLOG(_L("CFotaUpdate::going into FMS client side MonitorBatteryL() >>"));
       
   168                         TRAPD(err1, fmsclient.NotifyForUpdateL(EUpdMonitorbattery, 3))// equal to EBatteryLevelLevel3
       
   169                         if (err1)
       
   170                             {
       
   171                             FLOG(_L( " MonitorBatteryL failed " ));
       
   172                             }
       
   173                         fmsclient.Close();
       
   174                         FLOG(_L(" update interrupted <<"));
       
   175                         }
       
   176                     }
       
   177                     break;
       
   178                 default:
       
   179                     {
       
   180                     FLOG( _L( "[CFotaCustCmdAllReasons] pendingGAToSend is not SET " ) );
       
   181                     }
       
   182                     break;
       
   183                 }
       
   184 
       
   185             }
       
   186         }
       
   187     delete centrep;
       
   188         { // Write the code for starting the dmEventNotifier
       
   189         TRAPD(err, checkDMEventNotifierL());
       
   190         if (err)
       
   191             {
       
   192             FLOG(_L("start DmEventNotifier.exe successfull"));
       
   193             }
       
   194         else
       
   195             {
       
   196             FLOG(_L("start DmEventNotifier.exe un-successfull"));
       
   197             }
       
   198         }
       
   199     FLOG( _L( "[CFotaCustCmdAllReasons]::ExecuteL() Boot reason AllReason END " ) );
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // CFotaCustCmdAllReasons::ExecuteCancel
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 void CFotaCustCmdAllReasons::ExecuteCancel()
       
   207     {
       
   208    
       
   209     }
       
   210 
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // CFotaCustCmdAllReasons::Close
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 void CFotaCustCmdAllReasons::Close()
       
   217     {
       
   218      FLOG( _L( "[CFotaCustCmdAllReasons]::Close() " ) );
       
   219     }
       
   220 
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CFotaCustCmdAllReasons::Release
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CFotaCustCmdAllReasons::Release()
       
   227     {
       
   228     
       
   229      FLOG( _L( "[CFotaCustCmdAllReasons]::Close() " ) );
       
   230 	   delete this;
       
   231     }
       
   232     
       
   233     
       
   234 TBool  CFotaCustCmdAllReasons::FindScheduleL()
       
   235 {
       
   236 	FLOG( _L( "[CFotaCustCmdAllReasons]::FindScheduleL()BEGIN " ) );
       
   237 	TScheduleEntryInfo2                     ret;    
       
   238 	RScheduler                              sc;
       
   239 	TTime                                   t; 
       
   240 	TTsTime                                 time;
       
   241 	TSchedulerItemRef                       scitem; 
       
   242 	CArrayFixFlat<TSchedulerItemRef>*     	aSchRefArray = new CArrayFixFlat <TSchedulerItemRef>(5);
       
   243 	TScheduleFilter                      	aFilter(EAllSchedules);
       
   244 	User::LeaveIfError( sc.Connect() );                             // xx
       
   245 	CleanupClosePushL( sc );
       
   246 	CleanupStack::PushL(aSchRefArray);
       
   247 
       
   248 	User::LeaveIfError( sc.GetScheduleRefsL( *aSchRefArray,aFilter) );  // xx
       
   249 	FLOG(_L("Schedule items: "));
       
   250 	for ( TInt i=0; i<aSchRefArray->Count(); ++i  )
       
   251 		{
       
   252 		  TSchedulerItemRef it = (*aSchRefArray)[i];
       
   253 		 if ( it.iName == TUid::Uid(KFotaServerUid).Name()  )
       
   254 	   {
       
   255 	   	  	 
       
   256 	   	  	 	CleanupStack::PopAndDestroy(aSchRefArray);  
       
   257                 CleanupStack::PopAndDestroy(&sc);
       
   258 	   	  	 	return ETrue;
       
   259 	  	
       
   260 	   }
       
   261      }
       
   262                  CleanupStack::PopAndDestroy(aSchRefArray);
       
   263                  CleanupStack::PopAndDestroy(&sc);
       
   264      FLOG( _L( "[CFotaCustCmdAllReasons]::FindScheduleL()END " ) );            
       
   265                  return EFalse; 
       
   266 }
       
   267 
       
   268 
       
   269 void CFotaCustCmdAllReasons::checkDMEventNotifierL()
       
   270 {
       
   271     FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - started"));
       
   272  
       
   273     const TUid KAppDmEventNotifierUid = TUid::Uid(KAppUidDmEventNotifier); //UID3 from .mmp file
       
   274     CRepository* cenrep (NULL);
       
   275     cenrep = CRepository::NewLC( KAppDmEventNotifierUid );
       
   276     TInt value (KErrNone);
       
   277     TBool tocontinue (EFalse);
       
   278 
       
   279     FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - checking for cenrep KDmEventNotifierEnabled"));
       
   280     if ( ((cenrep->Get(KDmEventNotifierEnabled,value)) == KErrNone )
       
   281             && (EHandlerRegistered == value || EHandlerNeedRegister == value )) // v alue != EHandlerNotRegistered 
       
   282     {
       
   283 //        FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - cenrep KDmEventNotifierEnabled exist, value = (%d) "), value);
       
   284 				FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - cenrep KDmEventNotifierEnabled exist"));
       
   285         tocontinue = ETrue;
       
   286     }
       
   287     else
       
   288     {
       
   289         //Log errors
       
   290 //        FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - checking for cenrep KDmEventNotifierEnabled does not exist: error: (%d) "), err);
       
   291 				FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - cenrep KDmEventNotifierEnabled does not exist or already registered"));
       
   292         //delete cenrep; cenrep = NULL;
       
   293         CleanupStack::PopAndDestroy(); // cenrep
       
   294         return;
       
   295     }
       
   296     
       
   297     TInt pMmcstatus = KErrNotFound;
       
   298     TInt ret = RProperty::Get(KPSUidUikon, KUikMMCInserted, pMmcstatus);
       
   299 //    FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - checking for present Memory status: ret = (%d) , MMCStatus = (%d) "), ret, pMmcStatus);
       
   300 		FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - checking for memory status"));
       
   301     if(!ret)
       
   302     {
       
   303 
       
   304         TInt sMMCStatus (KErrNotFound);
       
   305         TInt error = cenrep->Get(KMMCStatus, sMMCStatus);
       
   306 				CleanupStack::PopAndDestroy(); // cenrep
       
   307 
       
   308         //FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - checking for previous Memory status, before phone off: error = (%d) , sMMCStatus = (%d) "), error, sMMCStatus);
       
   309         if(error)
       
   310         {
       
   311         		FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - Error in memory status get"));
       
   312             //CleanupStack::PopAndDestroy(); // cenrep
       
   313             return;    
       
   314         }
       
   315         if (pMmcstatus == sMMCStatus && tocontinue) // if sMMCStatus is 0 && pMMCStatus is 0. Or sMMCStatus is 1 && pMMCStatus is 1
       
   316         {
       
   317         //start the dm event notifier
       
   318                 
       
   319             RApaLsSession apaLsSession;
       
   320             User :: LeaveIfError(apaLsSession.Connect());
       
   321             TApaAppInfo appInfo;
       
   322             FLOG(_L("RApaLsSession connection successful"));
       
   323             FLOG(_L("Running dmeventnotifier.exe"));
       
   324                     
       
   325             _LIT(KExampleTaskHandlerExe, "dmeventnotifier.exe");
       
   326         
       
   327             appInfo.iFullName = KExampleTaskHandlerExe;
       
   328             CApaCommandLine* cmdLine  = CApaCommandLine::NewLC();
       
   329             cmdLine->SetExecutableNameL( appInfo.iFullName );
       
   330             TBuf<KMaxFileName> temp;
       
   331             temp.Copy (appInfo.iFullName);
       
   332             TInt err = apaLsSession.StartApp(*cmdLine);
       
   333             
       
   334             User :: LeaveIfError(err);
       
   335             CleanupStack :: PopAndDestroy(cmdLine);
       
   336             apaLsSession.Close();
       
   337             FLOG(_L("started dmeventnotifier.exe successfully"));
       
   338         }
       
   339     }
       
   340     //CleanupStack::PopAndDestroy(); // cenrep
       
   341     FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - ended"));
       
   342 }