fotaapplication/fotaserver/inc/FotaServer.h
branchRCL_3
changeset 25 b183ec05bd8c
equal deleted inserted replaced
24:13d7c31c74e0 25:b183ec05bd8c
       
     1 /*
       
     2  * Copyright (c) 2005 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:   Header file for CFotaServer
       
    15  *
       
    16  */
       
    17 
       
    18 #ifndef __FOTASERVER_H__
       
    19 #define __FOTASERVER_H__
       
    20 
       
    21 // INCLUDES
       
    22 
       
    23 #include <coemain.h>
       
    24 #include <s32file.h>
       
    25 #include <e32property.h>
       
    26 #include <SyncMLClient.h>
       
    27 #include <SyncMLClientDM.h>
       
    28 #include <hwrmpowerstatesdkpskeys.h>
       
    29 #include <SyncMLObservers.h>
       
    30 #include <devicedialogconsts.h>
       
    31 #include <hbsymbianvariant.h>
       
    32 #include <hbmainwindow.h>
       
    33 #include "fotaserverPrivateCRKeys.h"
       
    34 #include "FotaIPCTypes.h"
       
    35 #include "FotaDB.h"
       
    36 #include "fotaConst.h"
       
    37 #include "fotaupdate.h" 
       
    38 #include "fmsclient.h"	//The FMS Client header file
       
    39 #include "FotaSrvDebug.h"
       
    40 #include "fotadevicedialogobserver.h"
       
    41 
       
    42 /** If download is active this P&S key is set to ETrue, otherwise EFalse. 
       
    43  * The key is owned by omadmappui**/
       
    44 const TUint32 KFotaServerActive = 0x0000008;
       
    45 #define __LEAVE_IF_ERROR(x) if(KErrNone!=x) {FLOG(_L("LEAVE in %s: %d"), __FILE__, __LINE__); User::Leave(x); }
       
    46 
       
    47 //Forward declarations
       
    48 class FotaFullscreenDialog;
       
    49 /** File that stores the firmware version at the start of download. This is in fota's private directory*/
       
    50 _LIT (KSWversionFile, "swv.txt");
       
    51 
       
    52 /** Time and the interval download finalizing retries*/
       
    53 const TInt KDownloadFinalizerWaitTime(1000000);
       
    54 
       
    55 /** Time interval between syncml session retry attempts*/
       
    56 const TInt KSyncmlSessionRetryInterval(60000000);
       
    57 
       
    58 /** Time and the interval between the fota shutdownload retries*/
       
    59 const TTimeIntervalMicroSeconds32 KFotaTimeShutDown(10000000);
       
    60 
       
    61 /** How many times generic alert sending should be tried in row. */
       
    62 const TInt KSyncmlAttemptCount = 3;
       
    63 
       
    64 /** How many times a download can be restarted when a non-resumable interrupt occurs. */
       
    65 const TInt KMaxDownloadRestartCount = 3;
       
    66 
       
    67 _LIT_SECURITY_POLICY_C1( KReadPolicy, ECapabilityReadDeviceData );
       
    68 _LIT_SECURITY_POLICY_C1( KWritePolicy, ECapabilityWriteDeviceData );
       
    69 _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy);
       
    70 
       
    71 // FORWARD CLASS DECLARATION
       
    72 
       
    73 class CFotaUpdate;
       
    74 class CFotaSrvApp;
       
    75 class CFotaNetworkRegStatus;
       
    76 class DownloadManagerClient;
       
    77 class CFotaDownloadNotifHandler;
       
    78 /**
       
    79  * Fota server. Handles client requests. Starts download and/or update.
       
    80  *
       
    81  *  This class is 
       
    82  *
       
    83  *  @lib    fotaserver
       
    84  *  @since  S60 v3.1
       
    85  */
       
    86 NONSHARABLE_CLASS( CFotaServer ) : public CServer2,
       
    87         MSyncMLEventObserver,
       
    88         MfotadevicedialogObserver
       
    89     {
       
    90     friend class CFotaSrvSession;
       
    91     friend class CFotaUpdate;
       
    92 
       
    93 public:
       
    94 
       
    95     // Member functions
       
    96 
       
    97     static CFotaServer* NewInstance(HbMainWindow& mainwindow);
       
    98 
       
    99     /**
       
   100      * Destructor.
       
   101      */
       
   102     virtual ~CFotaServer();
       
   103 
       
   104 public:
       
   105 
       
   106     // All functions called from the session
       
   107     /**
       
   108      * Start download
       
   109      *
       
   110      * @since   S60   v3.1
       
   111      * @param   aParams     Package state params to be save in db
       
   112      * @param   aPkgURL     URL
       
   113      * @return  none
       
   114      */
       
   115     void DownloadL(TDownloadIPCParams aParams, const TDesC8& aPkgURL,
       
   116             TFotaClient aRequester, TBool aSilent, TBool aUpdateLtr);
       
   117 
       
   118     /**
       
   119      * Pauses ongoing download
       
   120      *
       
   121      * @since   S60   v3.1
       
   122      * @param   none
       
   123      * @return  none, can leave with system wide errors
       
   124      */
       
   125     void PauseDownloadL();
       
   126 
       
   127     /**
       
   128      * Start update
       
   129      *
       
   130      * @since   S60   v3.1
       
   131      * @param   aClient - the client which invoked the update
       
   132      * @return  none, can leave with system wide errors
       
   133      */
       
   134     void TryUpdateL(TFotaClient aClient);
       
   135 
       
   136     /**
       
   137      * Update, triggered by scheduler
       
   138      *
       
   139      * @since   S60   v3.1
       
   140      * @param   aUpdate - Update details
       
   141      * @param   aClient - the client which invoked the update
       
   142      * @return  none, can leave with system wide errors
       
   143      */
       
   144     void ScheduledUpdateL(TFotaScheduledUpdate aUpdate, TFotaClient aClient);
       
   145 
       
   146     /**
       
   147      * Delete swupd package
       
   148      *
       
   149      * @since   S60   v3.1
       
   150      * @param   aPkgId - Package id
       
   151      * @return  none, can leave with system wide errors
       
   152      */
       
   153     void DeletePackageL(const TInt aPkgId);
       
   154 
       
   155     /**
       
   156      * Get state of a swupd package
       
   157      *
       
   158      * @since   S60   v3.1
       
   159      * @param   aPkgId - Package id
       
   160      * @return  Package state, can leave with system wide errors
       
   161      */
       
   162     TPackageState GetStateL(const TInt aPkgId);
       
   163 
       
   164     /**
       
   165      * Tries to resume the download.
       
   166      *
       
   167      * @since   S60   v5.2
       
   168      * @param   aClient the client which triggers resume
       
   169      * @param   aSilentDl	Whether to query user for resume?
       
   170      * @return  None, can leave with system wide errors
       
   171      */
       
   172     void TryResumeDownloadL(TFotaClient aClient, TBool aSilentDl);
       
   173 
       
   174     /**
       
   175      * Get ids of present swupd packages
       
   176      *
       
   177      * @since   S60   v3.1
       
   178      * @param   aPackageIdList  On return, ids will be here
       
   179      * @return  None, can leave with system wide errors
       
   180      */
       
   181     void GetUpdatePackageIdsL(TDes16& aPackageIdList);
       
   182 
       
   183     /**
       
   184      * Get time of last update
       
   185      *
       
   186      * @since   S60   v3.1
       
   187      * @param   aTime       On return, time of last update
       
   188      * @return  None, can leave with system wide errors
       
   189      */
       
   190     void GetUpdateTimeStampL(TDes16& aTime);
       
   191 
       
   192     void GetCurrentFwDetailsL(TDes8& aName, TDes8& aVersion, TInt& aSize);
       
   193 
       
   194     /**
       
   195      * Do cleanup for package
       
   196      *
       
   197      * @since   S60   v3.1
       
   198      * @param   aPackageID Packageid
       
   199      * @return  None
       
   200      */
       
   201     void ResetFotaStateL(const TInt aPackageID);
       
   202 
       
   203     /**
       
   204      * Set download to be finalized. 
       
   205      *
       
   206      * @since   S60   v3.1
       
   207      * @param   aDLState    Final state of the download
       
   208      * @return  None, can leave with system wide errors
       
   209      */
       
   210     void FinalizeDownloadL();
       
   211 
       
   212     /**
       
   213      * Callback function to notify the network status
       
   214      *
       
   215      * @since S60	v3.2
       
   216      * @param Status of network connection
       
   217      * @return None
       
   218      */
       
   219     void ReportNetworkStatus(TBool status);
       
   220 
       
   221     //All user interface functions
       
   222 
       
   223     /**
       
   224      * Function to start the full screen dialog
       
   225      *
       
   226      * @since SF4
       
   227      * @param aSize - the full size of the download
       
   228      * @param aVersion - the version of the firmware upate
       
   229      * @param aName - the name of the firmware update
       
   230      * @return None
       
   231      */
       
   232     void StartDownloadDialog(const QString &aName, const QString &aVersion,
       
   233             const TInt &Size);
       
   234 
       
   235     /**
       
   236      * Function to update the full screen dialog with download progress
       
   237      *
       
   238      * @since SF4
       
   239      * @param aProgress - the download progress in percentage
       
   240      * @return None
       
   241      */
       
   242     void UpdateDownloadDialog(TInt aProgress);
       
   243 
       
   244     /**
       
   245      * Function to show any dialog within fota server 
       
   246      *
       
   247      * @since SF4
       
   248      * @param dialogid -the dialog identifier
       
   249      * @return None
       
   250      */
       
   251     void ShowDialogL(TFwUpdNoteTypes aDialogid);
       
   252 
       
   253     /**
       
   254      * Function that handles all the user responses on full screen dialog
       
   255      *
       
   256      * @since SF4
       
   257      * @param aResponse - key response
       
   258      * @return None
       
   259      */
       
   260     void HandleFullScreenDialogResponse(TInt aResponse);
       
   261 
       
   262     /**
       
   263      * Function called from the fota update when battery condition changes 
       
   264      *
       
   265      * @since SF4
       
   266      * @param aStatus - status of the battery, true if low, false if acceptable
       
   267      * @return None
       
   268      */
       
   269     void UpdateBatteryLowInfo(TBool aStatus);
       
   270 
       
   271     /**
       
   272      * Returns the full screen dialog pointer
       
   273      *
       
   274      * @since SF4
       
   275      * @param none
       
   276      * @return pointer to full screen dialog instance
       
   277      */
       
   278     FotaFullscreenDialog* FullScreenDialog();
       
   279 
       
   280     /**
       
   281      * Sets the phone's startup reason which will used by Fota Startup Pluggin to any decision.
       
   282      *
       
   283      * @since   S60   v3.2
       
   284      * @param   aReason     Startup reason, either download interrupted
       
   285      * @return  None
       
   286      */
       
   287     void SetStartupReason(TInt aReason);
       
   288 
       
   289     void ConstructApplicationUI(TBool aVal);
       
   290     void SetServerActive(TBool aValue);
       
   291     
       
   292     void FinalizeUpdate();
       
   293 
       
   294 public:
       
   295     // member variables
       
   296 
       
   297     /**
       
   298      * The package state of the firmware update
       
   299      */
       
   300 
       
   301     TPackageState iPackageState;
       
   302 
       
   303     /**
       
   304      * Used for package state saving.
       
   305      */
       
   306     CFotaDB* iDatabase;
       
   307     
       
   308     
       
   309     TBuf8<KMaxFileName> iLastFwUrl;
       
   310 
       
   311 public:
       
   312     // from  base classes
       
   313 
       
   314     /**
       
   315      * Handle syncml event
       
   316      * @param    aEvent
       
   317      * @param    aIdentifier
       
   318      * @param    aError
       
   319      * @param    aAdditionalData
       
   320      * @return   none
       
   321      */
       
   322     void OnSyncMLSessionEvent(TEvent aEvent, TInt aIdentifier, TInt aError,
       
   323             TInt aAdditionalData);
       
   324 
       
   325     /**
       
   326      * Function that is called when any user action happens on the dialogs or full screen dialog
       
   327      *
       
   328      * @since SF4
       
   329      * @param response - key press
       
   330      * @return None
       
   331      */
       
   332     void HandleDialogResponse(int response, TInt aDialogid);
       
   333 
       
   334     //All finalizing functions
       
   335     /**
       
   336      * Finalize download
       
   337      *
       
   338      * @since   S60   v3.1
       
   339      * @param   None
       
   340      * @return  None, can leave with system wide errors
       
   341      */
       
   342     void DoFinalizeDownloadL();
       
   343 
       
   344     /**
       
   345      * Read update result file and report result back to DM server
       
   346      *
       
   347      * @since   S60   v3.1
       
   348      * @param   None
       
   349      * @return  None, can leave with system wide errors
       
   350      */
       
   351     void DoExecuteResultFileL();
       
   352 
       
   353     /**
       
   354      * Close syncml session
       
   355      *
       
   356      * @since   S60 v3.1
       
   357      * @param none
       
   358      * @return  None, can leave with system wide errors
       
   359      */
       
   360     void DoCloseSMLSessionL();
       
   361 
       
   362     /**
       
   363      * When called, will try to shut the server when possible.
       
   364      * This will use the timer to shut down.
       
   365      *
       
   366      * @since   SF4
       
   367      * @param none
       
   368      * @return  None
       
   369      */
       
   370     void StopServerWhenPossible();
       
   371 
       
   372     void ServerCanShut(TBool aParam);
       
   373     
       
   374     TBool DecrementDownloadRestartCount();
       
   375 	
       
   376     void SetVisible(TBool aVisible);
       
   377 
       
   378 protected:
       
   379     // from base classes
       
   380 
       
   381     /**
       
   382      * Calls when a New session is getting created
       
   383      * @param aVersion
       
   384      * @param aMessage
       
   385      * @return CSession2*
       
   386      */
       
   387     CSession2* NewSessionL(const TVersion& aVersion,
       
   388             const RMessage2& aMessage) const;
       
   389 
       
   390     /**
       
   391      * DoConnect. 
       
   392      *
       
   393      * @since   S60   v3.1
       
   394      * @param   aMessage    IPC message
       
   395      * @return  none
       
   396      */
       
   397     void DoConnect(const RMessage2& aMessage);
       
   398 
       
   399     void DropSession();
       
   400 
       
   401 private:
       
   402 
       
   403     /**
       
   404      * C++ default constructor.
       
   405      */
       
   406     CFotaServer(HbMainWindow& mainwindow);
       
   407 
       
   408     /**
       
   409      * ConstructL
       
   410      *
       
   411      * @since   S60   v3.1
       
   412      * @param   none
       
   413      * @return  none
       
   414      */
       
   415     virtual void ConstructL();
       
   416 
       
   417     /**
       
   418      * Latter part of constructing. It's ensured that parent fotaserver is 
       
   419      * constructed only once, and child fotaserver is not constructed at all.
       
   420      * Client fotaserver has a task of saving swupd as its only task. It should
       
   421      * not update swupd states.
       
   422      *
       
   423      * @since   S60   v3.1
       
   424      * @param   aMessage    Client process details
       
   425      * @return  none
       
   426      */
       
   427     void ClientAwareConstructL(const RMessage2 &aMessage);
       
   428 
       
   429     /**
       
   430      * Resets the fota state
       
   431      * @since S60	v3.2
       
   432      * @param IPC params
       
   433      * @return None
       
   434      */
       
   435 
       
   436     void ResetFotaStateToFailL();
       
   437 
       
   438     /**
       
   439      * Starts network monitoring operaiton for defined interval and retries
       
   440      *
       
   441      * @since S60	v3.2
       
   442      * @param None
       
   443      * @return None
       
   444      */
       
   445     void StartNetworkMonitorL();
       
   446 
       
   447     /**
       
   448      * Creates the disk reservation as set in the configuration
       
   449      *
       
   450      * @since SF4
       
   451      * @param 
       
   452      * @return None
       
   453      */
       
   454     void CreateDiskReservation();
       
   455 
       
   456     /**
       
   457      * Deletes the disk reservation in the given absolute path
       
   458      *
       
   459      * @since SF4
       
   460      * @param 
       
   461      * @return None
       
   462      */
       
   463     void DeleteDiskReservation(TDesC& path);
       
   464 
       
   465     /**
       
   466      * Sets the appropriate access point id for the download
       
   467      *
       
   468      * @since SF4
       
   469      * @param none
       
   470      * @return None, can leave with system wide errors.
       
   471      */
       
   472     void SetIapToUseL();
       
   473 
       
   474     /**
       
   475      * Invoke Fota Monitory Service when the download gets suspended
       
   476      *
       
   477      * @since   S60   v3.2
       
   478      * @return  None
       
   479      */
       
   480     void InvokeFmsL();
       
   481 
       
   482     /**
       
   483      * Cancels any outstanding request for resume notification
       
   484      *
       
   485      * @since   S60   v3.2
       
   486      * @return  None
       
   487      */
       
   488     void CancelFmsL();
       
   489 
       
   490     /**
       
   491      * Check s/w version with the current version
       
   492      *
       
   493      * @since   S60   v3.2
       
   494      * @param   none
       
   495      * @return  Bool value(matches or not)
       
   496      */
       
   497     TBool CheckSWVersionL();
       
   498 
       
   499     /**
       
   500      * Create DM session to DM server (identified by profileid)
       
   501      *
       
   502      * @since   S60   v3.1
       
   503      * @param   aProfileId  DM profile id
       
   504      * @param   aIapid      IAP id. If not kerrnone, will be used instead
       
   505      *                      of profiles' IAP id.
       
   506      * @return  none
       
   507      */
       
   508     void CreateDeviceManagementSessionL(TPackageState& aState);
       
   509 
       
   510     /**
       
   511      * Get the software version of the device
       
   512      * @since S60   v3.2
       
   513      * @param s/w version 
       
   514      * @return error
       
   515      */
       
   516     TInt GetSoftwareVersion(TDes& aVersion);
       
   517 
       
   518     /**
       
   519      * Checks for IAP Id exists or not in commsdb
       
   520      * IAPId used for resuming the paused download
       
   521      * @since S60   v5.0
       
   522      * @param IapId
       
   523      * @return ETrue/EFalse
       
   524      */
       
   525     TBool CheckIapExistsL(TUint32 aIapId);
       
   526 
       
   527     /**
       
   528      * Checks if the drive is busy due to encryption
       
   529      *
       
   530      * @since SF4
       
   531      * @param None
       
   532      * @return true, if busy, else false
       
   533      */
       
   534     TBool IsDeviceDriveBusyL();
       
   535 
       
   536     /**
       
   537      * The downloader manager object
       
   538      *
       
   539      * @since SF4
       
   540      * @param 
       
   541      * @return None
       
   542      */
       
   543     DownloadManagerClient* DownloaderL();
       
   544 
       
   545     /**
       
   546      * Sets the update requester
       
   547      *
       
   548      * @since SF4
       
   549      * @param aRequester - the requester of firmware update
       
   550      * @return None
       
   551      */
       
   552     void SetUpdateRequester(TFotaClient aRequester);
       
   553 
       
   554     /**
       
   555      * Gets the update requester
       
   556      *
       
   557      * @since SF4
       
   558      * @param 
       
   559      * @return None
       
   560      */
       
   561     TFotaClient GetUpdateRequester();
       
   562 
       
   563     /**
       
   564      * Reports firmware update status to the requester
       
   565      *
       
   566      * @since SF4
       
   567      * @param astate - the package state that has the status
       
   568      * @return None
       
   569      */
       
   570     void ReportFwUpdateStatusL(TPackageState& aState);
       
   571 
       
   572     /**
       
   573      * Loops for the battery status whilst full screen dialog is open
       
   574      * 
       
   575      * @since SF4
       
   576      * @param aBatteryLevel - the battery level
       
   577      * @return None
       
   578      */
       
   579     void LoopBatteryCheckL(TBool aBatteryLevel);
       
   580 
       
   581     /**
       
   582      * Shows the full screen dialog
       
   583      *
       
   584      * @since SF4
       
   585      * @param aType - type of the dialog
       
   586      * @return None
       
   587      */
       
   588     void ShowFullScreenDialog(TInt aType);
       
   589 
       
   590     /**
       
   591      * Swaps the fota process from background to foreground
       
   592      *
       
   593      * @since SF4
       
   594      * @param aState - true will bring to foreground, false to background
       
   595      * @return None
       
   596      */
       
   597     //void swapProcess(TBool aState);
       
   598 
       
   599     void ResetCounters();
       
   600 
       
   601     TBool IsUserPostponeAllowed();
       
   602 
       
   603     void DecrementUserPostponeCount();
       
   604     
       
   605     void WakeupServer();
       
   606 
       
   607 private:
       
   608     // Data
       
   609 
       
   610 private:
       
   611     // member variables    
       
   612     /**
       
   613      * Is server initialized?
       
   614      */
       
   615     TBool iInitialized;
       
   616 
       
   617     /**
       
   618      * The download manager client
       
   619      */
       
   620     DownloadManagerClient* iDownloader;
       
   621 
       
   622     /**
       
   623      * Used for starting update of fw.
       
   624      */
       
   625     CFotaUpdate* iUpdater;
       
   626 
       
   627     /**
       
   628      * Used for deleting download.
       
   629      */
       
   630     CPeriodic* iDownloadFinalizer;
       
   631 
       
   632     /**
       
   633      * Used for deleting update.
       
   634      */
       
   635     CPeriodic* iUpdateFinalizer;
       
   636 
       
   637     /**
       
   638      * Used for reading result file.
       
   639      */
       
   640     CPeriodic* iTimedExecuteResultFile;
       
   641 
       
   642     /**
       
   643      * Used for closing syncml session
       
   644      */
       
   645     CPeriodic* iTimedSMLSessionClose;
       
   646 
       
   647     /**
       
   648      * File server session
       
   649      */
       
   650     RFs iFs;
       
   651 
       
   652     /**
       
   653      * Tries to periodically shut down fotaserver
       
   654      */
       
   655     CPeriodic* iAppShutter;
       
   656 
       
   657     /**
       
   658      * Syncmlsession for creating dmsession
       
   659      */
       
   660     RSyncMLSession iSyncMLSession;
       
   661 
       
   662     /**
       
   663      * Class that checks for network availability 
       
   664      * 
       
   665      */
       
   666     CFotaNetworkRegStatus* iMonitor;
       
   667 
       
   668     /**
       
   669      * How many times to try dm session
       
   670      */
       
   671     TInt iSyncMLAttempts;
       
   672 
       
   673     /**
       
   674      * sync job id
       
   675      */
       
   676     TSmlJobId iSyncJobId;
       
   677 
       
   678     /**
       
   679      * profile
       
   680      */
       
   681     TSmlProfileId iSyncProfile;
       
   682 
       
   683     /**
       
   684      * To tell whether Generic Alert sending is being retried or not. This is checked before shutting down fota server
       
   685      * 
       
   686      */
       
   687     TBool iRetryingGASend;
       
   688 
       
   689     /**
       
   690      * To tell whether network is available to send Generic Alert.
       
   691      * 
       
   692      */
       
   693     TBool iNetworkAvailable;
       
   694 
       
   695     /**
       
   696      * The Fota Monitory Client object
       
   697      */
       
   698     RFMSClient iFMSClient;
       
   699 
       
   700     /**
       
   701      * Holds the storage drive of the package.
       
   702      */
       
   703     TDriveNumber iStorageDrive;
       
   704 
       
   705     /**
       
   706      * The session count to fota server.
       
   707      */
       
   708     static TInt iSessionCount;
       
   709 
       
   710     /**
       
   711      * The full screen dialog 
       
   712      */
       
   713     FotaFullscreenDialog *iFullScreenDialog;
       
   714 
       
   715     /**
       
   716      * The notifier params to the dialogs
       
   717      */
       
   718     CHbSymbianVariantMap * iNotifParams;
       
   719 
       
   720     CFotaDownloadNotifHandler * iNotifier;
       
   721     /**
       
   722      * Can the server shut?
       
   723      */
       
   724     TBool iServerCanShut;
       
   725 
       
   726     /**
       
   727      * Is async operation requested?
       
   728      */
       
   729     TBool iAsyncOperation;
       
   730 
       
   731     TInt iDialogId;
       
   732 
       
   733     TBool iConstructed;
       
   734     
       
   735     HbMainWindow& iMainwindow;
       
   736     };
       
   737 
       
   738 #endif 
       
   739 
       
   740 // End of File