applicationmanagement/server/inc/ApplicationManagementServer.h
changeset 47 d316aecb87fd
child 52 6e38e48ee756
equal deleted inserted replaced
46:b9b00b134b0d 47:d316aecb87fd
       
     1 /*
       
     2  * Copyright (c) 2000 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: Implementation of applicationmanagement components
       
    15  *
       
    16  */
       
    17 
       
    18 #ifndef __APPLICATIONMANAGEMENTSERVER_H__
       
    19 #define __APPLICATIONMANAGEMENTSERVER_H__
       
    20 
       
    21 // INCLUDES
       
    22 #include <SyncMLClient.h>
       
    23 #include <e32base.h>
       
    24 #include <centralrepository.h>
       
    25 #include <SWInstApi.h>
       
    26 #include <ssl.h>
       
    27 #include <swi/launcher.h>
       
    28 #include <swi/sisregistrysession.h>
       
    29 #include <swi/sisregistrypackage.h>
       
    30 #include <swi/sisregistryentry.h>
       
    31 #include <HbProgressDialog.h>
       
    32 #include <hbmainwindow.h>
       
    33 #include <hbaction.h>
       
    34 #include <usif/sif/sif.h>
       
    35 #include <SWInstApi.h>
       
    36 #include <QGraphicsLinearLayout>
       
    37 #include "ApplicationManagementClientServer.h"
       
    38 #include "PlatformSecurityPolicies.h"
       
    39 #include "AMDeploymentComponent.h"
       
    40 #include "amstorage.h"
       
    41 #include "ApplicationManagementUtility.h"
       
    42 #include "AMDownloaddb.h"
       
    43 #include "amwaitprogdialog.h"
       
    44 #include "AMDownloadStore.h"
       
    45 
       
    46 // CONSTANTS
       
    47 const TUid NProperty = {0x200267FB};
       
    48 const TUint32 NInteger = 0x00000001;
       
    49 const TInt KBase64BufSize = 131072;
       
    50 const QString path = "z:/resource/qt/translations/";
       
    51 class CAppMgmtSrvApp;
       
    52 _LIT(KIndicatorParamDownloading, "Downloading");
       
    53 namespace NApplicationManagement
       
    54     {
       
    55 
       
    56     // -----------------------------------------------------------
       
    57     // ApplicationManagement server panic codes
       
    58     // -----------------------------------------------------------
       
    59     enum TApplicationManagementPanic
       
    60         {
       
    61         EPanicGeneral,
       
    62         EBadSubsessionHandle,
       
    63         EPanicIllegalFunction,
       
    64         EBadDescriptor
       
    65         };
       
    66     // -----------------------------------------------------------
       
    67     // Wait dialog types
       
    68     // -----------------------------------------------------------
       
    69     enum TDialogType
       
    70         {
       
    71         EInstallWaitDlg,
       
    72         EUninstallWaitDlg
       
    73         };
       
    74     // FUNCTION PROTOTYPES
       
    75 
       
    76     void PanicClient(const RMessagePtr2& aMessage,
       
    77             TApplicationManagementPanic aPanic);
       
    78 
       
    79     // CLASS DECLARATION     
       
    80     class CShutdown : public CTimer
       
    81         {
       
    82         enum
       
    83             {
       
    84             KApplicationManagementShutdownDelay = 0x3000000 // approx 30s
       
    85             };
       
    86 public:
       
    87         inline CShutdown();
       
    88         inline void ConstructL();
       
    89         inline void Start();
       
    90 	inline void Stop();
       
    91 private:
       
    92         void RunL();
       
    93         };
       
    94 
       
    95     /**
       
    96      *  CApplicationManagementServer 
       
    97      *  Description.
       
    98      */
       
    99 
       
   100     class CApplicationManagementServer : public CPolicyServer,
       
   101         public MDownloadMngrObserver,public MInstallerCallBack
       
   102         {
       
   103 public:
       
   104         static CServer2* NewL(HbMainWindow *mainWindow);
       
   105         ~CApplicationManagementServer();
       
   106 
       
   107         void Panic(TInt aPanicCode);
       
   108         void AddSession();
       
   109         void DropSession();
       
   110         
       
   111         CPolicyServer::TCustomResult CreateServiceSecurityCheckL(
       
   112                 TUid aServiceType, const RMessage2& aMsg, TInt& aAction,
       
   113                 TSecurityInfo& aMissing);
       
   114 private:
       
   115 
       
   116         CApplicationManagementServer();
       
   117         virtual void ConstructL(HbMainWindow *mainWindow);
       
   118         CSession2* NewSessionL(const TVersion& aVersion, 
       
   119          const RMessage2& aMessage) const;
       
   120 
       
   121         //From CPolicyServer
       
   122         CPolicyServer::TCustomResult
       
   123                 CustomSecurityCheckL(const RMessage2& aMsg, TInt& aAction,
       
   124                         TSecurityInfo& aMissing);
       
   125 
       
   126         // browses sis registry
       
   127         void LookupSisRegistryL();
       
   128 
       
   129         //New methods	
       
   130         void DownloadCompleteL(CDeploymentComponent *aComponent, TInt iapid,
       
   131                 HBufC8* aServerId);
       
   132 
       
   133         void InstallCompleteL(const CDeploymentComponent &aCompo,
       
   134                 const TBool &aInstallSuccess=ETrue);
       
   135                 
       
   136         TInt GetErrorStatus(TInt aErrorDownload, TInt aErrorInstall);
       
   137         
       
   138         void EnableDMNetworkMonL(TInt iapid, HBufC8 *aServerId);
       
   139 
       
   140 public:
       
   141 
       
   142         /**
       
   143          * 	Storage Returns the storage
       
   144          * @return The storage pointer
       
   145          */
       
   146         inline CDeliveryComponentStorage *Storage()
       
   147             {
       
   148             return iStorage;
       
   149             }
       
   150 
       
   151         /**
       
   152          * UninstallL Uninstalls the given deployment component.
       
   153          * @param aComponent The component to be uninstalled
       
   154          * @param aStatus TRequestStatus of the call
       
   155          */
       
   156         void UninstallL(const CDeploymentComponent &aComponent,
       
   157                 TRequestStatus &aStatus);
       
   158 
       
   159         void AddDownloadL(CDeploymentComponent *aComponent);
       
   160 
       
   161         void PerformRFSL();
       
   162         void RemoveInternalL(const CDeploymentComponent &aCompo,
       
   163                 TBool aDoUninstall = ETrue);
       
   164 
       
   165         TBool CheckCertL(const TCertInfo &aInfo) const;
       
   166         void DoTheInstallL(CDeploymentComponent &aCompo);
       
   167 
       
   168         void GetAMServerDownloadDBL(TUint32 internalid, TInt& finalresult,
       
   169                 TDes8& atargetURI);
       
   170                 
       
   171         TBool IsOMASCOMOEnabledL();
       
   172 
       
   173         /**
       
   174          * JavaUidsL Returns java uids.
       
   175          * @param aUids the array to hold uids
       
   176          */
       
   177         void JavaUidsL(RArray<TUid> &aUids) const;
       
   178 
       
   179         /**
       
   180          * FullUpdateL updates target with source
       
   181          * @param sid Source deployment component id
       
   182          * @param tid Target deployment component id
       
   183          */
       
   184         void FullUpdateL(const TUint32 sid, const TUint32 tid);
       
   185 
       
   186         /**
       
   187          * SetDataL sets data to deployment component and checks possible uid overlaps
       
   188          * @param aCompo deployment component where data is set
       
   189          * @param aData new data to be set
       
   190          * @param aMime mimetype of the new data to be set
       
   191          */
       
   192         void SetDataL(CDeploymentComponent &aCompo, const TDesC8 &aData,
       
   193                 const TDesC8 &aMime);
       
   194         /**
       
   195          * Checks of data in file is Base64 decoded.
       
   196          * @param aFile file to be checked if data is encoded
       
   197          * @param aLength data length in file
       
   198          * @return ETrue if given data in file is Base64 encoded
       
   199          */
       
   200         TBool IsDataFileB64EncodedL(RFile &aFile, TInt& aLength);
       
   201 
       
   202         /**
       
   203          * Checks of data is Base64 decoded.
       
   204          * @param aData data to be checked for encoding
       
   205          * @return ETrue if given data is Base64 encoded
       
   206          */
       
   207         TBool CheckB64Encode(const TDesC8& aData);
       
   208 
       
   209         /**
       
   210          * B64 Decodes data in aData and return decoded data
       
   211          * @param aSourceFile file containing decoded data
       
   212          * @param aDestinationFile file where to decode data
       
   213          */
       
   214         void DecodeB64DataFileL(RFile& aSourceFile, RFile& aDestinationFile);
       
   215 
       
   216         /**
       
   217          * B64 Decodes data in aData and return decoded data
       
   218          * @param aData decoded data
       
   219          * @return Decoded data
       
   220          */
       
   221         HBufC8* DecodeB64DataLC(const TDesC8 &aData);
       
   222 
       
   223         /**
       
   224          * B64 Encodes data in aData to aTarget
       
   225          * @param aData data which is encoded
       
   226          * @param aTarget encoded data buffer
       
   227          */
       
   228         void EncodeDataL(const TDesC8& aData, CBufBase &aTarget);
       
   229         void HandleAllClientsClosed();
       
   230 
       
   231         void DeleteGenericAlertForIDL(TUint32 internalid);
       
   232         void CheckforDuplicateMidletsL(TMidletParameters& amidletParameters);
       
   233 
       
   234 public:
       
   235         // from MDownloadMngrObserver
       
   236 
       
   237         /**
       
   238          * 
       
   239          * @param aComponent 
       
   240          * @param aStatus 
       
   241          */
       
   242         void ComponentDownloadComplete(CDeploymentComponent *aComponent,
       
   243                 TInt iapid, HBufC8 *aServerId);
       
   244 
       
   245         /**
       
   246          * Looks all deployments components and sis & java registries
       
   247          * to find out whether given uid is already used...
       
   248          * @param aUid The uid to be looked for
       
   249          * @return ETrue if uid is found, EFalse otherwise
       
   250          */
       
   251         TBool HasUidL(const TUid &aUid, CDeploymentComponent *& aCompo,
       
   252                 CDeploymentComponent *aIgnored);
       
   253 
       
   254         void ComponentDownloadFailed(CDeploymentComponent *aComponent,
       
   255                 TInt aReason);
       
   256 
       
   257         void StartShutDownTimerL();
       
   258 
       
   259         TBool IsInstalledAppRemovableL(TDriveNumber &iDrive);
       
   260 
       
   261 	  void InstallationCancelled();
       
   262 private:
       
   263 
       
   264         /**
       
   265          * FullUpdateL updates target with source
       
   266          * @param sid Source deployment component 
       
   267          * @param tid Target deployment component 
       
   268          */
       
   269         void FullUpdateL(CDeploymentComponent &scompo,
       
   270                 const CDeploymentComponent &tcompo);
       
   271 
       
   272         /**
       
   273          * InstallL Installs the given deployment component. Async version.
       
   274          * @param aComponent The component to be installed
       
   275          * @param aStatus TRequestStatus of the call
       
   276          */
       
   277         void InstallL(const CDeploymentComponent &aComponent,
       
   278                 TRequestStatus &aStatus);
       
   279         /**
       
   280          * InstallL Installs the given deployment component. Syncronized version.
       
   281          * @param aComponent The component to be installed
       
   282          */
       
   283         void InstallL(const CDeploymentComponent &aComponent);
       
   284 
       
   285         /**
       
   286          * PrepareInstallL Prepares install of given component.
       
   287          * @param aComponent The component to be installed
       
   288          * @param aFileName	If call is successful, will contain 
       
   289          * the name of file ready to be installed
       
   290          * @return ETrue if preparation is successful, EFalse otherwise
       
   291          */
       
   292         TBool PrepareInstallL(const CDeploymentComponent &aComponent,
       
   293                 TFileName &aFileName);
       
   294 
       
   295         /**
       
   296          * Finds whether the given uid is found in sis or java registry.
       
   297          * Searches first sis registry and uses FindJavaUidL if not found
       
   298          */
       
   299         TBool FindInstalledSisUidL(const TUid &aUid) const;
       
   300 
       
   301         /**
       
   302          * Finds whether the given uid is found in java registry
       
   303          */
       
   304         TBool FindInstalledJavaUidL(const TUid &aUid) const;
       
   305         void SetSisAppVersionAndDriveL(CDeploymentComponent &aCompo);
       
   306         void JavaInstallL(CDeploymentComponent &aCompo);
       
   307         void SisInstallL(const CDeploymentComponent &aCompo);
       
   308         TUid FindNewUid(const RArray<TUid> &aUidsOrig,
       
   309                 const RArray<TUid> &aUidsNew) const;
       
   310 
       
   311         /**
       
   312          * Reads Jar file name from Jad file
       
   313          * @param aFile file handle for Jad file where to find Jar filename
       
   314          * @return aFileName	If call is successful, will contain the name of file ready to be installed
       
   315          */
       
   316         TFileName ReadJarFileNameL(RFile& aFile) const;
       
   317 
       
   318         /**
       
   319          * Reads line of data from file.
       
   320          * @param aStream stream handle where to read data
       
   321          * @param aLineBuffer buffer where function appends read data for line. Return a full line at time.
       
   322          */
       
   323         void ReadLineL(RReadStream& aStream, TDes8& aLineBuffer) const;
       
   324 
       
   325         /**
       
   326          * DoDataUpdateCheck checks whether there's dc having same data uid
       
   327          * @return The conflicting DC or NULL
       
   328          */
       
   329         CDeploymentComponent * DoDataUpdateCheckL(
       
   330                 CDeploymentComponent &aCompo);
       
   331 
       
   332         // Functions used to generate temporary files Java installation use case
       
   333         // where both Jad and Jar files are delivered to phone and Jad file is used to install 
       
   334         // the Java application from local Jar file.
       
   335         void GenerateTempJarFileNameL(RFs &aFs, const TDesC& aMetaSource,
       
   336                 TFileName &aFileName) const;
       
   337 
       
   338         void GenerateTempFileNameL(const RFs &aFs, const TDesC& aSource,
       
   339                 TFileName &aFileName) const;
       
   340 
       
   341         void GenerateTempFileNameL(RFs &aFs,
       
   342                 const CDeploymentComponent& aCompo, TFileName& aSource,
       
   343                 TFileName &aMetaSource, TFileName &aFileName,
       
   344                 TFileName &aMetaFileName) const;
       
   345 
       
   346         void GenerateTempFileNameL(RFs &aFs,
       
   347                 const CDeploymentComponent& aCompo, TFileName &aFileName,
       
   348                 TFileName &aMetaFileName) const;
       
   349 
       
   350         CApaAppServiceBase* CreateServiceL(TUid aServiceType) const;
       
   351 public:
       
   352         CAppMgmtSrvApp* iParentApp;
       
   353 private:
       
   354         TInt iSessionCount;
       
   355         CShutdown iShutdown;
       
   356         CApplicationManagementUtility* iUtility;
       
   357         CDeliveryComponentStorage *iStorage;
       
   358         TBool iInstallInProgress;
       
   359 
       
   360         Usif::RSoftwareInstall iInstaller;
       
   361         Usif::COpaqueNamedParams *iArgu;
       
   362         Usif::COpaqueNamedParams *iResults;
       
   363         SwiUI::TInstallOptionsPckg iInstallOptions;
       
   364         SwiUI::TUninstallOptionsPckg iUninstallOptions;
       
   365         SwiUI::TInstallReqPckg iInstallReq;
       
   366         TFileName iAppname;
       
   367         RFs iInstallRFs;
       
   368         RFile iInstallFile;
       
   369         CAMDownloadStore* iDownloadMngr;
       
   370         CAMDownloaddb* iAMServerDB;
       
   371         TBool iOMASCOMOEnabled;
       
   372         
       
   373         appmgmtdownloadmgr* m_DownloadMngr;
       
   374         QString m_appName;
       
   375         AMWaitProgDialog* m_Dlg;
       
   376         CDeploymentComponent* iComp;
       
   377         HbMainWindow* m_Window;
       
   378         int mUserCancelled;
       
   379         };
       
   380 
       
   381     namespace NPolicyConstants
       
   382         {
       
   383 
       
   384         // "CSF" + CA + SerialNumber + Fingerprint) ;
       
   385         //_LIT( KSubjectFormat, "CSF%S%S%S" );
       
   386         namespace NActions
       
   387             {
       
   388             _LIT8( KUse, "Use" );
       
   389             }
       
   390         _LIT8( KResourceValue, "ApplicationManagement" );
       
   391         }
       
   392 
       
   393     class CApplicationManagementSession : public CSession2
       
   394         {
       
   395 public:
       
   396         inline CApplicationManagementSession();
       
   397         inline CApplicationManagementSession(const TCertInfo &aInfo);
       
   398         void CreateL();
       
   399 private:
       
   400         ~CApplicationManagementSession();
       
   401         inline CApplicationManagementServer& Server() const;
       
   402 
       
   403         void ServiceL(const RMessage2& aMessage);
       
   404         TBool PreDispatchMessageL(const RMessage2 &aMessage);
       
   405         void DispatchMessageL(const RMessage2& aMessage);
       
   406         void ServiceError(const RMessage2& aMessage, TInt aError);
       
   407 
       
   408         void ComponentCountL(const RMessage2& aMessage);
       
   409         void ComponentIdsL(const RMessage2& aMessage) const;
       
   410         void Deliver2L(const RMessage2& aMessage) const;
       
   411         void DeliverCompleteL(const RMessage2& aMessage) const;
       
   412         void GetComponentL(const RMessage2& aMessage) const;
       
   413         void InstallL(const RMessage2 &aMessage) const;
       
   414         void UpdateL(const RMessage2 &aMessage) const;
       
   415         void GetDataL(const RMessage2 &aMessage) const;
       
   416         void GetDataLengthL(const RMessage2 &aMessage) const;
       
   417         void RemoveL(const RMessage2 &aMessage) const;
       
   418         void UpdateDataL(const RMessage2 &aMessage) const;
       
   419         void UpdateStreamedDataL(const RMessage2& aMessage) const;
       
   420         void DownloadL(const RMessage2 &aMessage) const;
       
   421         void AddTrustL(const RMessage2 &aMessage);
       
   422         void FullUpdateL(const RMessage2 &aMessage) const;
       
   423         void GetUserIdL(const RMessage2 &aMessage) const;
       
   424         void StartDownloadL(const RMessage2& aMessage) const;
       
   425         void StateChangeComponentIdsL(const RMessage2& aMessage) const;
       
   426         void StateChangeComponentIdsCountL(const RMessage2& aMessage) const;
       
   427         void StateChangeCompleteL(const RMessage2& aMessage) const;
       
   428         void ActivateL(const RMessage2& aMessage) const;
       
   429         void DeactivateL(const RMessage2& aMessage) const;
       
   430         void GetTemporaryInstFileL(const RMessage2 &aMessage) const;
       
   431         void GetFinalResultForGAL(const RMessage2 &aMessage);
       
   432 
       
   433         TInt PackageSizeL(Swi::RSisRegistrySession& aSession,
       
   434                 Swi::RSisRegistryEntry& aEntry);
       
   435         TInt AugmentationSizeL(Swi::RSisRegistrySession& aSession,
       
   436                 const Swi::CSisRegistryPackage& aPackage);
       
   437 
       
   438         void RemoveInternalL(const TUint32 &aId) const;
       
   439 
       
   440         /**
       
   441          * Collects active components in aArrt and places them in aArr
       
   442          */
       
   443         void ActiveComponentsL(const RComponentIdArray &aArrt,
       
   444                 RComponentIdArray &aArr,TDeploymentComponentState &aState) const;
       
   445 
       
   446         void GenericAlertSentForIdL(const RMessage2& aMessage) const;
       
   447 
       
   448         void CheckStatusNodesValuesL();
       
   449 
       
   450 private:
       
   451         void LookupSisRegistryL();
       
   452 
       
   453         TCertInfo iCertInfo;
       
   454         TBool iTrustAdded;
       
   455         
       
   456         };
       
   457 
       
   458     }
       
   459 #endif //__APPLICATIONMANAGEMENTSERVER_H__
       
   460 //  End of File
       
   461