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