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 |