os/persistentdata/featuremgmt/featuremgr/src/serverexe/featmgrfeatureregistry.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
sl@0
    20
sl@0
    21
#ifndef FEATMGRFEATUREREGISTRY_H
sl@0
    22
#define FEATMGRFEATUREREGISTRY_H
sl@0
    23
sl@0
    24
//  INCLUDES
sl@0
    25
#include <e32svr.h>
sl@0
    26
#include <s32file.h>
sl@0
    27
#include <featmgr/featurecmn.h>
sl@0
    28
#include <featmgr/featureinfoplugin.h>
sl@0
    29
#include "featmgrfeatureentry.h"
sl@0
    30
#include "swilistener.h"
sl@0
    31
sl@0
    32
// FORWARD DECLARATIONS
sl@0
    33
sl@0
    34
// CLASS DECLARATION
sl@0
    35
sl@0
    36
class MFeatMgrRegistryObserver
sl@0
    37
    {
sl@0
    38
    public:
sl@0
    39
        virtual void HandleFeatureChange( TFeatureServerEntry& aFeature, 
sl@0
    40
            TFeatureChangeType aType ) = 0;
sl@0
    41
    };
sl@0
    42
sl@0
    43
// CLASS DECLARATION
sl@0
    44
NONSHARABLE_CLASS(CFeatMgrFeatureRegistry) : public CBase, MSWICallBack
sl@0
    45
    {
sl@0
    46
    private:
sl@0
    47
	
sl@0
    48
    	/* 
sl@0
    49
    	* Status for SWI which must be kept in memory in order for calls made to the new
sl@0
    50
    	* API functions SWIStart and SWIEnd can be related to actual installation/uninstallation.
sl@0
    51
    	* 
sl@0
    52
    	* ESWIOutOfMemory will inform FeatMgr that an out-of-memory condition has occurred during
sl@0
    53
    	* caching and/or memory pre-allocation for the new features to be added.
sl@0
    54
    	*/
sl@0
    55
    	enum TSWIStatus
sl@0
    56
	    	{
sl@0
    57
	    	ESWIComplete=0,
sl@0
    58
	    	ESWIInstalling,
sl@0
    59
	    	ESWIAborted,
sl@0
    60
	    	ESWIOutOfMemory 
sl@0
    61
	    	};
sl@0
    62
    	
sl@0
    63
	    /*
sl@0
    64
	    * Enumerations to identify the category of the operation to apply on the cached 
sl@0
    65
	    * features after SWI completes.
sl@0
    66
	    */
sl@0
    67
		enum TSWIOperationCat
sl@0
    68
			{ 
sl@0
    69
			ESWIAddFeat,
sl@0
    70
			ESWIDeleteFeat,
sl@0
    71
			ESWISetFeatAndData,
sl@0
    72
			ESWISetFeatData,
sl@0
    73
			ESWISetFeat
sl@0
    74
			};
sl@0
    75
		
sl@0
    76
		/*
sl@0
    77
		* The operation tuple to be cached
sl@0
    78
		*/
sl@0
    79
		struct TSWICachedOperation
sl@0
    80
			{
sl@0
    81
			TSWIOperationCat iCat;
sl@0
    82
			TFeatureServerEntry iFeatEntry;
sl@0
    83
			};
sl@0
    84
sl@0
    85
    public:
sl@0
    86
        
sl@0
    87
        /**
sl@0
    88
        * Two-phased constructor.
sl@0
    89
        */
sl@0
    90
        static CFeatMgrFeatureRegistry* NewL( RFs& aFs, MFeatMgrRegistryObserver& aObserver );
sl@0
    91
sl@0
    92
        /**
sl@0
    93
        * Destructor.
sl@0
    94
        */
sl@0
    95
        virtual ~CFeatMgrFeatureRegistry();
sl@0
    96
sl@0
    97
    public:
sl@0
    98
           
sl@0
    99
        /**
sl@0
   100
        * Reads feature files.
sl@0
   101
        */
sl@0
   102
        void ReadFeatureFilesL();
sl@0
   103
sl@0
   104
        /**
sl@0
   105
        * Reads runtime feature file.
sl@0
   106
        */
sl@0
   107
        void ReadRuntimeFeaturesL( TBool &aFeaturesReady );
sl@0
   108
sl@0
   109
        /**
sl@0
   110
        * Merges features to common feature array from plugin.
sl@0
   111
        */
sl@0
   112
        void MergePluginFeaturesL( RArray<FeatureInfoCommand::TFeature>& aList );
sl@0
   113
sl@0
   114
        /**
sl@0
   115
        * Merges features to common feature array from plugin.
sl@0
   116
        */
sl@0
   117
        void MergePluginFeaturesL( RFeatureArray& aList );
sl@0
   118
sl@0
   119
        /**
sl@0
   120
        * Returns feature support status.
sl@0
   121
        */
sl@0
   122
        TInt IsFeatureSupported( TFeatureServerEntry& aFeature );
sl@0
   123
sl@0
   124
        /**
sl@0
   125
        * Adds feature.
sl@0
   126
        * @param aFeature A reference to a client owned TFeatureEntry object
sl@0
   127
        * @param aProcessId The id of the process calling this function. This is needed to identify 
sl@0
   128
        * 					the executable launched by Software Installer (SWI) and cache its to-be
sl@0
   129
        * 					added features. The default value for aProcessId enables other clients to 
sl@0
   130
        * 					add features directly to the list (allowing backward compatibility).
sl@0
   131
        * When set to ETrue the function 
sl@0
   132
        */
sl@0
   133
        TInt AddFeature( TFeatureServerEntry& aFeature, TUint aProcessId = 0 );
sl@0
   134
sl@0
   135
        /**
sl@0
   136
        * Deletes feature.
sl@0
   137
        */
sl@0
   138
        TInt DeleteFeature( TUid aFeature, TUint = 0 );
sl@0
   139
sl@0
   140
        /**
sl@0
   141
        * Sets feature support status and optionally data.
sl@0
   142
        */
sl@0
   143
        TInt SetFeature( TUid aFeature, TInt aEnable, const TUint32 *aData = NULL, TUint = 0 );
sl@0
   144
sl@0
   145
        /**
sl@0
   146
        * Lists supported features to array.
sl@0
   147
        */
sl@0
   148
        void SupportedFeaturesL( RFeatureUidArray& aSupportedFeatures );
sl@0
   149
sl@0
   150
        /**
sl@0
   151
        * Returns number of supported features.
sl@0
   152
        */
sl@0
   153
        TInt NumberOfSupportedFeatures();
sl@0
   154
        
sl@0
   155
        /**
sl@0
   156
         * Make a backup of the feature list into member iFeatureListBackup, then reset 
sl@0
   157
         * the feature list iFeatureList.
sl@0
   158
		 *
sl@0
   159
		 * Leaves if there is an error during back up, with KErrNoMemory or any of the 
sl@0
   160
		 * other system-wide error codes.
sl@0
   161
         */ 
sl@0
   162
        void ResetFeaturesL();
sl@0
   163
        
sl@0
   164
        /**
sl@0
   165
		 * This function will handle the required notifications for new, deleted and changed features
sl@0
   166
		 * after a restore operation has taken place.
sl@0
   167
         */ 
sl@0
   168
        void HandleRestoredFeatureNotificationsL();
sl@0
   169
        
sl@0
   170
        /**
sl@0
   171
		 * Returns the fully qualified path and filename for the runtime feature data file.
sl@0
   172
         */ 
sl@0
   173
        TFileName GetFeaturesFilePathAndName( void );
sl@0
   174
sl@0
   175
        /**
sl@0
   176
        * Indicates that SWI started. It takes the Id of the process calling it as a parameter.
sl@0
   177
        */
sl@0
   178
        TInt SWIStart(TUint);
sl@0
   179
        
sl@0
   180
        /**
sl@0
   181
        * Indicates that SWI ended. It takes the Id of the process calling it as a parameter.
sl@0
   182
        */
sl@0
   183
        TInt SWIEnd(TUint);
sl@0
   184
        
sl@0
   185
        /**
sl@0
   186
         * Add a new command to the cache.
sl@0
   187
         * 
sl@0
   188
         * @return error KErrArgument if the maximum number of cached features is reached.
sl@0
   189
         * 				 KErrNoMemory if there is no memory to create a new command to cached,
sl@0
   190
         * 							  or if an out-of-memory condition has occured during caching.
sl@0
   191
         */
sl@0
   192
         TInt SWICacheCommand(TSWIOperationCat aOptCat, TFeatureServerEntry aFeature);
sl@0
   193
        
sl@0
   194
        /**
sl@0
   195
        * Commit changes for the cached features into feature manager.
sl@0
   196
        */
sl@0
   197
        void CommitSWIFeatChanges();
sl@0
   198
        
sl@0
   199
        /**
sl@0
   200
        * Reset and clean up SWI-related states and member variables.
sl@0
   201
        */
sl@0
   202
        void SWIReset();
sl@0
   203
sl@0
   204
        /*
sl@0
   205
        * Handle the case when SWI aborts.
sl@0
   206
        */
sl@0
   207
        void SWIAborted();
sl@0
   208
        
sl@0
   209
        /*
sl@0
   210
        * Virtual function from MSWICallBack.
sl@0
   211
        * It is fired when the timer runs out to indicate that SWI finished before a call to 
sl@0
   212
        * SWIEnd or the launched executable crashed or hanged. It will deal with rolling-back 
sl@0
   213
        * all cached changes. It is called after 15 seconds.
sl@0
   214
        */
sl@0
   215
        void SWITimedOut();
sl@0
   216
        
sl@0
   217
        /*
sl@0
   218
        * Return the status of the caching mechanism (started or not).
sl@0
   219
        */
sl@0
   220
        TBool SWICacheStarted();
sl@0
   221
        
sl@0
   222
        /*
sl@0
   223
        * Returns the status of the caching mechanism (successful, aborted, out-of-memory).
sl@0
   224
        */
sl@0
   225
        TBool SWICacheStatusOOM();
sl@0
   226
        
sl@0
   227
    private:
sl@0
   228
sl@0
   229
        CFeatMgrFeatureRegistry( RFs& aFs, MFeatMgrRegistryObserver& aObserver );
sl@0
   230
        void ConstructL();
sl@0
   231
        
sl@0
   232
        TInt ReadFiles( const TDesC& aFilePath, CDir* aDir );
sl@0
   233
        void ReadFileL( const TDesC& aFilePath );
sl@0
   234
        void CompareFeatureListsL();
sl@0
   235
        void ReadFilesFromDirL( const TDesC& aDirName );
sl@0
   236
        void UpdateRuntimeFeaturesFileL( TFeatureServerEntry& aFeature, TFeatureChangeType aType );
sl@0
   237
sl@0
   238
        TInt HandleChange( TFeatureServerEntry& aFeature, TFeatureChangeType aType );
sl@0
   239
        TInt ValidateFeature( TUid aFeature, TInt &aIndex );
sl@0
   240
        TInt SearchFeature( TUid aFeature );
sl@0
   241
        TInt EnableFeature( TUid aFeature );
sl@0
   242
        TInt DisableFeature( TUid aFeature );
sl@0
   243
        TBool IsFlagSet( TInt aIndex, TFeatureFlags aFlag );
sl@0
   244
        static TInt FindByUid( const TUid *aFeature, const TFeatureServerEntry& aItem );
sl@0
   245
        static TInt FindByUid( const TFeatureServerEntry& aFeature, 
sl@0
   246
        const TFeatureServerEntry& aItem );
sl@0
   247
        void ValidateHeaderL( RFileReadStream& stream, TUint32& count, TUint32& countDSRs );
sl@0
   248
        void WriteHeaderAndEntriesL( RFileWriteStream &aStream, RFeatureServerArray& aArray );
sl@0
   249
        void ValidateFeatureFlagL(TBitFlags32 aFlags);
sl@0
   250
        void ValidateRuntimeFeatureFlagL(TBitFlags32 aFlags);
sl@0
   251
        
sl@0
   252
     private:
sl@0
   253
        
sl@0
   254
        // Observer of feature changes
sl@0
   255
        MFeatMgrRegistryObserver& iObserver;
sl@0
   256
        // Array of features
sl@0
   257
        RArray<TFeatureServerEntry> iFeatureList;
sl@0
   258
        // Struct to contain information of default supported ranges
sl@0
   259
        class TDefaultRange
sl@0
   260
	        {
sl@0
   261
	        public:
sl@0
   262
    	        TUid iLowUid;
sl@0
   263
    	        TUid iHighUid;
sl@0
   264
	        };
sl@0
   265
        // Array of supported ranges
sl@0
   266
        RArray<TDefaultRange> iRangeList;
sl@0
   267
        // File server session
sl@0
   268
        RFs& iFs;
sl@0
   269
        
sl@0
   270
        // Array of features (backup up for BUR)
sl@0
   271
        RArray<TFeatureServerEntry> iFeatureListBackup;
sl@0
   272
sl@0
   273
        // Flag to tell feature manager to cache newly modified features during SWI.
sl@0
   274
        TBool iSWICacheFeature;
sl@0
   275
        // Tracks the SWI status to check if an installation/uninstallation is in progress before 
sl@0
   276
        // starting caching.
sl@0
   277
        TSWIStatus iSWIStatus;
sl@0
   278
        // Array that holds the operations to apply on cached features when SWI ends.
sl@0
   279
        RArray<TSWICachedOperation> iSWICachedOperations;
sl@0
   280
        // Id of the process launched by SWI whose commands to feature manager are to be cached.
sl@0
   281
        TUint iSWIProcessId;
sl@0
   282
        // Listens to the SWI P&S property KSAUidSoftwareInstallKeyValue 
sl@0
   283
        CSWIListener* iSWIListener;
sl@0
   284
        // Timer to handle the situation when the launched exe by SWI manipulates features and then 
sl@0
   285
        // hangs/crashes, or a call to SWIEnd was not made.
sl@0
   286
        CSWITimer* iSWITimer;
sl@0
   287
        // Traces if an "out-of-memory" condition has occurred during caching. If so, FeatMgr will
sl@0
   288
        // not commit the cache when the installation is successful. It will be disregarded.
sl@0
   289
        TBool iOomOccured;
sl@0
   290
        // Counts the number of features allowed to be cached during SWI install/uninstall. 
sl@0
   291
        // The maximum is set to 50 (MAXSWIOPS)
sl@0
   292
        TInt iSWIOperations;
sl@0
   293
        // Counts how many AddFeature commands are cached during SWI
sl@0
   294
        TInt iAddFeatCount;
sl@0
   295
    };
sl@0
   296
sl@0
   297
#endif      // FEATMGRFEATUREREGISTRY_H 
sl@0
   298
            
sl@0
   299
// End of File