|
1 /* |
|
2 * Copyright (c) 2008 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: PreInstall helper class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <e32const.h> |
|
21 #include "EmailStorePreInstall.h" |
|
22 #include "EmailStoreUids.hrh" |
|
23 #include "emailstorepskeys.h" |
|
24 |
|
25 // Timeout for process exit. |
|
26 const TInt KProcessTimeout = 5; //5 seconds |
|
27 |
|
28 /** |
|
29 * Information about an executable file. |
|
30 */ |
|
31 class TImsServerInfo |
|
32 { |
|
33 public: |
|
34 /** Server name. */ |
|
35 TFileName iServerName; |
|
36 |
|
37 /** Server SecureID, usually UID3. */ |
|
38 TUint32 iServerSid; |
|
39 }; |
|
40 |
|
41 /** |
|
42 * List of servers to be stopped, in order. |
|
43 * Usually, the one with least dependencies is the last. |
|
44 */ |
|
45 const TImsServerInfo serverList[] = |
|
46 { |
|
47 { _L("MESSAGESTOREEXE*"), KUidMessageStoreExe }, |
|
48 { _L(""), 0 } // end of array, DO NOT remove. |
|
49 }; |
|
50 |
|
51 |
|
52 /********************************** |
|
53 * Method: NewL |
|
54 **********************************/ |
|
55 CEmailStorePreInstall* CEmailStorePreInstall::NewL() |
|
56 { |
|
57 CEmailStorePreInstall* self = CEmailStorePreInstall::NewLC(); |
|
58 CleanupStack::Pop(self); |
|
59 return self; |
|
60 } |
|
61 |
|
62 /********************************** |
|
63 * Method: NewL |
|
64 **********************************/ |
|
65 CEmailStorePreInstall* CEmailStorePreInstall::NewLC() |
|
66 { |
|
67 CEmailStorePreInstall* self = new(ELeave) CEmailStorePreInstall(); |
|
68 CleanupStack::PushL(self); |
|
69 self->ConstructL(); |
|
70 return self; |
|
71 } |
|
72 |
|
73 /********************************** |
|
74 * Method: Constructor |
|
75 **********************************/ |
|
76 CEmailStorePreInstall::CEmailStorePreInstall() |
|
77 : CTimer(EPriorityHigh), iServerIndex(0), iState( EInit ) |
|
78 { |
|
79 __LOG_CONSTRUCT( "IMS", "CEmailStorePreInstall" ) |
|
80 } |
|
81 |
|
82 |
|
83 /********************************** |
|
84 * Method: ConstructL |
|
85 **********************************/ |
|
86 void CEmailStorePreInstall::ConstructL() |
|
87 { |
|
88 __LOG_ENTER("ConstructL") |
|
89 |
|
90 // Construct base |
|
91 CTimer::ConstructL(); |
|
92 |
|
93 // Define upgrade property. |
|
94 // Define security rights |
|
95 TSecurityPolicy readPolicy( ECapabilityReadDeviceData ); |
|
96 TSecurityPolicy writePolicy( ECapabilityWriteDeviceData ); |
|
97 TInt err = RProperty::Define( KEmailStoreUpgradePSCategory, |
|
98 KProperty_EmailStore_Upgrade, |
|
99 RProperty::EInt, |
|
100 readPolicy, |
|
101 writePolicy ); |
|
102 |
|
103 if ( KErrNone != err && KErrAlreadyExists != err ) |
|
104 { |
|
105 User::Leave( err ); |
|
106 } |
|
107 |
|
108 // We are an AO |
|
109 CActiveScheduler::Add(this); |
|
110 |
|
111 // Need timeout for closing a process |
|
112 iTimeoutTimer = CProcessTimer::NewL(*this); |
|
113 |
|
114 // Start right away |
|
115 CTimer::After( 0 ); |
|
116 __LOG_EXIT |
|
117 } |
|
118 |
|
119 /********************************** |
|
120 * Method: Destructor |
|
121 **********************************/ |
|
122 CEmailStorePreInstall::~CEmailStorePreInstall() |
|
123 { |
|
124 __LOG_ENTER( "Destructor" ) |
|
125 __LOG_WRITE_INFO( "EmailStore PreInstall.exe is exiting..." ) |
|
126 |
|
127 // Stop AO activity |
|
128 Cancel(); |
|
129 |
|
130 // If any logon on process |
|
131 delete iTimeoutTimer; |
|
132 iProcess.Close(); |
|
133 |
|
134 // Delete upgrade property. |
|
135 RProperty::Delete( KEmailStoreUpgradePSCategory, KProperty_EmailStore_Upgrade ); |
|
136 |
|
137 __LOG_EXIT |
|
138 __LOG_DESTRUCT |
|
139 } |
|
140 |
|
141 /********************************** |
|
142 * Method: RunL |
|
143 **********************************/ |
|
144 void CEmailStorePreInstall::RunL() |
|
145 { |
|
146 __LOG_ENTER("RunL") |
|
147 __LOG_WRITE_FORMAT1_INFO( "iStatus=%d", iStatus.Int() ) |
|
148 __LOG_WRITE_FORMAT1_INFO( "iState=%d", iState ) |
|
149 |
|
150 if ( KErrNone == iStatus.Int() ) |
|
151 { |
|
152 switch( iState ) |
|
153 { |
|
154 case EInit: |
|
155 { |
|
156 iServerIndex = 0; |
|
157 iState = EStopServers; |
|
158 After( 0 ); |
|
159 } |
|
160 break; |
|
161 |
|
162 case EStopServers: |
|
163 { |
|
164 StopNextServerL(); |
|
165 } |
|
166 break; |
|
167 |
|
168 case EWaitForProcess: |
|
169 { |
|
170 ++iServerIndex; |
|
171 iState = EStopServers; |
|
172 __LOG_WRITE_INFO( "Stoping Timeout Timer" ); |
|
173 iTimeoutTimer->Cancel(); |
|
174 StopNextServerL(); |
|
175 } |
|
176 break; |
|
177 |
|
178 case EDone: |
|
179 { |
|
180 // Clear upgrade property. |
|
181 RProperty::Set( KEmailStoreUpgradePSCategory, |
|
182 KProperty_EmailStore_Upgrade, |
|
183 0 ); |
|
184 |
|
185 __LOG_WRITE_INFO( "PreInstall done, Calling CActiveScheduler::Stop()" ) |
|
186 CActiveScheduler::Stop(); |
|
187 } |
|
188 break; |
|
189 } |
|
190 } |
|
191 else |
|
192 { |
|
193 if ( EWaitForProcess == iState && KErrCancel != iStatus.Int() ) |
|
194 { |
|
195 ++iServerIndex; |
|
196 iState = EStopServers; |
|
197 __LOG_WRITE_INFO( "Stoping Timeout Timer" ); |
|
198 iTimeoutTimer->Cancel(); |
|
199 StopNextServerL(); |
|
200 } |
|
201 else |
|
202 { |
|
203 // Clear upgrade property. |
|
204 RProperty::Set( KEmailStoreUpgradePSCategory, |
|
205 KProperty_EmailStore_Upgrade, |
|
206 0 ); |
|
207 |
|
208 __LOG_WRITE_INFO( "PreInstall done due to errors, Calling CActiveScheduler::Stop()" ) |
|
209 CActiveScheduler::Stop(); |
|
210 } |
|
211 } |
|
212 |
|
213 __LOG_EXIT; |
|
214 } |
|
215 |
|
216 /********************************** |
|
217 * Method: DoCancel |
|
218 **********************************/ |
|
219 void CEmailStorePreInstall::DoCancel() |
|
220 { |
|
221 // If we are waiting for a process to close? |
|
222 if ( EWaitForProcess == iState ) |
|
223 { |
|
224 iTimeoutTimer->Cancel(); |
|
225 iProcess.LogonCancel( iStatus ); |
|
226 } |
|
227 else |
|
228 { |
|
229 CTimer::Cancel(); |
|
230 } |
|
231 |
|
232 // Clear upgrade property. |
|
233 RProperty::Set( KEmailStoreUpgradePSCategory, |
|
234 KProperty_EmailStore_Upgrade, |
|
235 0 ); |
|
236 |
|
237 iState = EDone; |
|
238 // Should we do what EDone state is supposed to do? |
|
239 //CActiveScheduler::Stop(); |
|
240 } |
|
241 |
|
242 /********************************** |
|
243 * Method: RunError |
|
244 **********************************/ |
|
245 TInt CEmailStorePreInstall::RunError( TInt __LOG_BLOCK(aError) ) |
|
246 { |
|
247 __LOG_ENTER( "RunError" ) |
|
248 __LOG_WRITE_FORMAT1_INFO( "err=%d", aError ) |
|
249 __LOG_EXIT |
|
250 return KErrNone; |
|
251 } |
|
252 |
|
253 void CEmailStorePreInstall::StopNextServerL() |
|
254 { |
|
255 __LOG_ENTER( "StopNextServerL" ) |
|
256 |
|
257 while ( serverList[iServerIndex].iServerSid != 0 ) |
|
258 { |
|
259 // Notify upgrade regardless of the server running state. |
|
260 RProperty::Set( KEmailStoreUpgradePSCategory, |
|
261 KProperty_EmailStore_Upgrade, |
|
262 static_cast<TInt>( serverList[iServerIndex].iServerSid ) ); |
|
263 |
|
264 // Verify if the process is running |
|
265 TFindProcess findProcess; |
|
266 findProcess.Find( serverList[iServerIndex].iServerName ); |
|
267 TFullName fullProcessName; |
|
268 if ( KErrNone == findProcess.Next( fullProcessName ) ) |
|
269 { |
|
270 // Process is running |
|
271 __LOG_WRITE_FORMAT1_INFO( "Running Process - %S", &fullProcessName ) |
|
272 iProcess.Close(); |
|
273 |
|
274 if ( KErrNone == iProcess.Open( findProcess ) ) |
|
275 { |
|
276 iProcess.Logon( iStatus ); |
|
277 __LOG_BLOCK( TFileName processName = iProcess.FullName(); ) |
|
278 __LOG_WRITE_FORMAT1_INFO( "Starting Timeout Timer for: %S", &processName ) |
|
279 iTimeoutTimer->StartTimeoutTimer( KProcessTimeout ); |
|
280 SetActive(); |
|
281 iState = EWaitForProcess; |
|
282 break; |
|
283 } |
|
284 else |
|
285 { |
|
286 // Move to next one. |
|
287 ++iServerIndex; |
|
288 } |
|
289 } |
|
290 else |
|
291 { |
|
292 // Move to next one. |
|
293 ++iServerIndex; |
|
294 } |
|
295 } |
|
296 |
|
297 if ( serverList[iServerIndex].iServerSid == 0 ) |
|
298 { |
|
299 iState = EDone; |
|
300 After( 0 ); |
|
301 } |
|
302 |
|
303 __LOG_EXIT |
|
304 } |
|
305 |
|
306 void CEmailStorePreInstall::Timeout() |
|
307 { |
|
308 // Cancel notifications |
|
309 iProcess.LogonCancel( iStatus ); |
|
310 |
|
311 // Kill this process |
|
312 iProcess.Kill( KErrNone ); |
|
313 |
|
314 // Stop next server |
|
315 ++iServerIndex; |
|
316 iState = EStopServers; |
|
317 } |
|
318 |
|
319 LOCAL_C void DoPreInstallL() |
|
320 { |
|
321 // Construct and install the active scheduler |
|
322 CActiveScheduler* scheduler = new ( ELeave ) CActiveScheduler; |
|
323 CleanupStack::PushL( scheduler ); |
|
324 CActiveScheduler::Install( scheduler ); |
|
325 |
|
326 CEmailStorePreInstall::NewLC(); |
|
327 |
|
328 CActiveScheduler::Start(); |
|
329 |
|
330 CleanupStack::PopAndDestroy( 2 ); // CEmailStorePreInstall, scheduler |
|
331 } // DoPostInstallL |
|
332 |
|
333 |
|
334 GLDEF_C TInt E32Main() |
|
335 { |
|
336 __UHEAP_MARK; |
|
337 |
|
338 CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack |
|
339 |
|
340 TRAP_IGNORE( DoPreInstallL() ); |
|
341 |
|
342 delete cleanup; // destroy clean-up stack |
|
343 |
|
344 __UHEAP_MARKEND; |
|
345 |
|
346 return 0; |
|
347 } // end E32Main |
|
348 |
|
349 |