omadm/omadmappui/src/NSmlDMSyncAppUi_fota.cpp
branchRCL_3
changeset 16 4eb398b07b07
parent 9 db6d61d7814f
child 20 f6aa907032f4
equal deleted inserted replaced
14:4699373c9af8 16:4eb398b07b07
     1 /*
     1 /*
     2 * Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). 
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    42 #include <featmgr.h>
    42 #include <featmgr.h>
    43 
    43 
    44 #include <hlplch.h>
    44 #include <hlplch.h>
    45 #include <csxhelp/dm.hlp.hrh>
    45 #include <csxhelp/dm.hlp.hrh>
    46 
    46 
       
    47 #include <aknmessagequerydialog.h>     // For CAknMessageQueryDialog
       
    48 
       
    49 // For KCalenHoursInDay = 24 and other time-related constants.
       
    50 #include <calenconstants.h>           
       
    51 
       
    52 // Array granuality for displaying R_QTN_FOTA_NOTE_TIME_RESTRICTION note.
       
    53 const TInt KNSmlDMFotaNoteArrayGranuality = 3;
    47 
    54 
    48 // ============================ MEMBER FUNCTIONS ==============================
    55 // ============================ MEMBER FUNCTIONS ==============================
    49 //
    56 //
    50 
    57 
    51 // -----------------------------------------------------------------------------
    58 // -----------------------------------------------------------------------------
   413 			{
   420 			{
   414 			iSyncAppEngine->CloseProfile();
   421 			iSyncAppEngine->CloseProfile();
   415 			return;
   422 			return;
   416 			}
   423 			}
   417 		}
   424 		}
       
   425 
       
   426     // If Fota check limitation feature is enabled, users are allowed to check
       
   427     // updates only once within the limitation set in the CenRep
       
   428     // (24 hours by default).
       
   429     if ( FeatureManager::FeatureSupported( KFeatureIdFfFotaCheckLimitation ) 
       
   430         && !IsUpdateAllowedL( *profile ) )
       
   431         {
       
   432         FLOG( "[OMADM] CNSmlDMSyncAppUi::StartSyncL Checking update is limited.\
       
   433             Can not proceed sync." );
       
   434         iSyncAppEngine->CloseProfile();
       
   435         return;
       
   436         }
   418 
   437 
   419     iSyncAppEngine->CloseProfile();		
   438     iSyncAppEngine->CloseProfile();		
   420     TRAPD( error, iSyncAppEngine->SynchronizeL( serverName, 
   439     TRAPD( error, iSyncAppEngine->SynchronizeL( serverName, 
   421                                                 iConfedProfileId, 
   440                                                 iConfedProfileId, 
   422                                                 connectionBearer,
   441                                                 connectionBearer,
   874         	task.BringToForeground();
   893         	task.BringToForeground();
   875         	}      
   894         	}      
   876      		} 
   895      		} 
   877   	
   896   	
   878   }
   897   }
       
   898 
       
   899 TBool CNSmlDMSyncAppUi::IsUpdateAllowedL( CNSmlDMSyncProfile& aProfile )
       
   900     {
       
   901     FLOG( "CNSmlDMSyncAppUi::IsUpdateAllowedL : Start" );
       
   902 
       
   903     // Get the last successful sync time. It's a UTC time.
       
   904     // Note: LastSuccessSync() returns the time when the last successful check
       
   905     // for Fota update.
       
   906     TTime utcLastSuccessSync = aProfile.LastSuccessSync();
       
   907 
       
   908     // If utcLastSuccessSync is 0, there is no log available. Continue
       
   909     // sync.
       
   910     // Note: CNSmlDMSyncProfile::LastSuccessSync() returns 0 not Time::NullTTime().
       
   911     if ( utcLastSuccessSync.Int64() == 0 )
       
   912         {
       
   913         FLOG( "[OMADM] CNSmlDMSyncAppUi::IsUpdateAllowedL() LastSuccessSync is 0." );
       
   914         return ETrue;
       
   915         }
       
   916 
       
   917 #ifdef _DEBUG
       
   918     TDateTime dt = utcLastSuccessSync.DateTime();
       
   919     FTRACE( FPrint(
       
   920         _L("[OMADM] CNSmlDMSyncAppUi::IsUpdateAllowedL() utcLastSuccessSync \
       
   921         %04d-%02d-%02d %02d:%02d:%02d"),
       
   922         dt.Year(), dt.Month(), dt.Day(), dt.Hour(), dt.Minute(), dt.Second() ) );
       
   923 #endif
       
   924 
       
   925     // Read Fota check limitation value in hours from CenRep.
       
   926     // If failed to get the value, the default value is 24 hours.
       
   927     TInt fotaCheckLimitation( KCalenHoursInDay );
       
   928     CRepository* cenrep = CRepository::NewL( KCRUidNSmlDMSyncApp );
       
   929     cenrep->Get( KNsmlDmFotaCheckLimitation, fotaCheckLimitation );
       
   930     delete cenrep;
       
   931     FTRACE( FPrint(
       
   932         _L("[OMADM] CNSmlDMSyncAppUi::IsUpdateAllowedL() Fota check limitation = %d"),
       
   933         fotaCheckLimitation ) );
       
   934 
       
   935     // Check the get value.
       
   936     if ( fotaCheckLimitation <= 0 )
       
   937         {
       
   938         // Something wrong with the value.  Set it to the default value.
       
   939         fotaCheckLimitation = KCalenHoursInDay;
       
   940         }
       
   941 
       
   942     // Read the current time for comparison. Also universal time.
       
   943     TTime utcCurrentTime;
       
   944     utcCurrentTime.UniversalTime();
       
   945 
       
   946 #ifdef _DEBUG
       
   947     dt = utcCurrentTime.DateTime();
       
   948     FTRACE( FPrint(
       
   949         _L("[OMADM] CNSmlDMSyncAppUi::IsUpdateAllowedL() utcCurrentTime \
       
   950         %04d-%02d-%02d %02d:%02d:%02d"),
       
   951         dt.Year(), dt.Month(), dt.Day(), dt.Hour(), dt.Minute(), dt.Second() ) );
       
   952 #endif
       
   953 
       
   954     // Calculate the remainig time for the next available update check.
       
   955     TTimeIntervalMinutes passedMinutes;
       
   956     utcCurrentTime.MinutesFrom( utcLastSuccessSync, passedMinutes );
       
   957     FTRACE( FPrint(
       
   958         _L("[OMADM] CNSmlDMSyncAppUi::IsUpdateAllowedL() passedMinutes.Int() = %d"), 
       
   959         passedMinutes.Int() ) );
       
   960 
       
   961     // If Fota check limit is passed or passedMinutes is invalid, return EFalse
       
   962     // to proceed sync process.
       
   963     if ( passedMinutes.Int() > fotaCheckLimitation * KCalenMinutesInHour
       
   964         || passedMinutes.Int() < 0 )
       
   965         {
       
   966         FLOG( "[OMADM] CNSmlDMSyncAppUi::IsUpdateAllowedL() Proceed sync process." );
       
   967         return ETrue;
       
   968         }
       
   969 
       
   970     // Calculate the next available update check time.
       
   971     TInt remainingMinutes ( ( fotaCheckLimitation * KCalenMinutesInHour ) 
       
   972         - passedMinutes.Int() );
       
   973     TInt remainingHours( remainingMinutes / KCalenMinutesInHour );
       
   974         remainingMinutes -= remainingHours * KCalenMinutesInHour;
       
   975     FTRACE( FPrint(
       
   976         _L("[OMADM] CNSmlDMSyncAppUi::IsUpdateAllowedL() \
       
   977         remainingHours = %d, remainingMinutes = %d"), 
       
   978         remainingHours, remainingMinutes ) );
       
   979     __ASSERT_DEBUG( ( remainingHours >= 0 ) && ( remainingMinutes >= 0 ), 
       
   980         _L("CNSmlDMSyncAppUi::IsUpdateAllowedL - Problem with Remaining \
       
   981         time calculation.") );
       
   982 
       
   983     // If calculated remaining time is valid, show the sorry note with
       
   984     // remaining time until next available time for checking update then
       
   985     // return ETrue to stop sync process.
       
   986     if ( remainingHours > 0 || remainingMinutes > 0 )
       
   987         {
       
   988         CArrayFix< TInt >* timeArray = 
       
   989             new( ELeave ) CArrayFixFlat< TInt >( KNSmlDMFotaNoteArrayGranuality );
       
   990         CleanupStack::PushL( timeArray );
       
   991 
       
   992         timeArray->AppendL( fotaCheckLimitation );
       
   993         timeArray->AppendL( remainingHours );
       
   994         timeArray->AppendL( remainingMinutes );
       
   995 
       
   996         HBufC* stringHolder =
       
   997             StringLoader::LoadLC( R_QTN_FOTA_NOTE_TIME_RESTRICTION, 
       
   998             *timeArray, iEikonEnv );
       
   999 
       
  1000         CAknMessageQueryDialog* infoDialog = 
       
  1001             CAknMessageQueryDialog::NewL( *stringHolder );
       
  1002  
       
  1003         // infoDialog is added to the cleanup stack in PrepareLC().
       
  1004         // And the dialog is popped and destroyed in RunLD().
       
  1005         infoDialog->PrepareLC( R_AVKON_MESSAGE_QUERY_DIALOG );
       
  1006 
       
  1007         // Only OK button should be shown since this is just a note.
       
  1008         infoDialog->ButtonGroupContainer().MakeCommandVisible( 
       
  1009             EAknSoftkeyCancel, EFalse );
       
  1010 
       
  1011         // Return value of RunLD() is ignored.
       
  1012         infoDialog->RunLD();
       
  1013   
       
  1014         CleanupStack::PopAndDestroy( stringHolder );
       
  1015         CleanupStack::PopAndDestroy( timeArray );
       
  1016  
       
  1017         // Return EFalse to stop sync process.
       
  1018         FLOG( "CNSmlDMSyncAppUi::IsUpdateAllowedL : End - EFalse" );
       
  1019         return EFalse;
       
  1020         }
       
  1021 
       
  1022     // No remaining time left (or invalid calculation).
       
  1023     // Proceed checking update process.
       
  1024     FLOG( "CNSmlDMSyncAppUi::IsUpdateAllowedL : End - ETrue" );
       
  1025     return ETrue;
       
  1026     }
       
  1027 
   879 // End of File
  1028 // End of File