|
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: This module contains the implementation of CIAUpdateSession class |
|
15 * member functions. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <w32std.h> |
|
23 #include <apgtask.h> |
|
24 #include <iaupdateparameters.h> |
|
25 #include <iaupdateresult.h> |
|
26 |
|
27 #include "iaupdatesession.h" |
|
28 #include "iaupdateserver.h" |
|
29 |
|
30 // Parameters are transmitted from the client side to the server |
|
31 #include "iaupdatetools.h" |
|
32 #include "iaupdateclientdefines.h" |
|
33 #include "iaupdateappui.h" |
|
34 #include "iaupdatelauncheruids.h" |
|
35 #include "iaupdatedebug.h" |
|
36 |
|
37 // CONSTANTS |
|
38 const TSecureId KSIDBackgroundChecker = 0x200211f4; |
|
39 const TSecureId KSIDLauncher = KIAUpdateLauncherUid; |
|
40 // ============================ MEMBER FUNCTIONS =============================== |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CIAUpdateSession::CIAUpdateSession |
|
44 // C++ default constructor can NOT contain any code, that |
|
45 // might leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CIAUpdateSession::CIAUpdateSession() |
|
49 { |
|
50 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::CIAUpdateSession()"); |
|
51 iEikEnv = CEikonEnv::Static(); |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CIAUpdateSession::CIAUpdateSession |
|
56 // C++ default constructor can NOT contain any code, that |
|
57 // might leave. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CIAUpdateSession::~CIAUpdateSession() |
|
61 { |
|
62 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::~CIAUpdateSession() begin"); |
|
63 CIAUpdateAppUi* appUi = |
|
64 static_cast<CIAUpdateAppUi*>( iEikEnv->EikAppUi() ); |
|
65 if ( appUi ) |
|
66 { |
|
67 appUi->HandleObserverRemoval(); |
|
68 } |
|
69 delete iMessage; |
|
70 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::~CIAUpdateSession() end"); |
|
71 } |
|
72 |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CIAUpdateSession::ServiceL |
|
76 // Handles the received message. |
|
77 // (other items were commented in a header). |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 void CIAUpdateSession::ServiceL( const RMessage2& aMessage ) |
|
81 { |
|
82 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::ServiceL() begin"); |
|
83 // Dispatch the message in trap harness. |
|
84 TRAPD( result, HandleRequestL( aMessage ) ); |
|
85 // If HandleRequest Left, the message has to be completed |
|
86 // here. Otherwise, the RequestCompleted callback will be called |
|
87 // when the operations finishes |
|
88 if ( result != KErrNone ) |
|
89 { |
|
90 IAUPDATE_TRACE_1("[IAUPDATE] HandleRequestL leave with error: %d", result ); |
|
91 aMessage.Complete( result ); |
|
92 } |
|
93 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::ServiceL() end"); |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CIAUpdateSession::ServiceError |
|
98 // Called back by the server framework if this sessions RunL function returns an |
|
99 // error. |
|
100 // (other items were commented in a header). |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 void CIAUpdateSession::ServiceError( const RMessage2& aMessage, TInt aError ) |
|
104 { |
|
105 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::ServiceError() begin"); |
|
106 IAUPDATE_TRACE_1("[IAUPDATE] error code: %d", aError ); |
|
107 // A bad descriptor error implies a badly programmed client, so panic it; |
|
108 // otherwise use the default handling (report the error to the client) |
|
109 if ( aError == KErrBadDescriptor ) |
|
110 { |
|
111 //PanicClient( aMessage, ECIAUpdatePanicBadDescriptor ); |
|
112 } |
|
113 CAknAppServiceBase::ServiceError( aMessage, aError ); |
|
114 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::ServiceError() end"); |
|
115 } |
|
116 |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CIAUpdateSession::CreateL |
|
120 // Completes construction of this server-side client session object. |
|
121 // (other items were commented in a header). |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 void CIAUpdateSession::CreateL() |
|
125 { |
|
126 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::CreateL() begin"); |
|
127 CAknAppServiceBase::CreateL(); |
|
128 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::CreateL() end"); |
|
129 } |
|
130 |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CIAUpdateSession::RequestCompleted |
|
134 // @see MIAUpdateRequestObserver::RequestCompleted |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 void CIAUpdateSession::RequestCompleted( CIAUpdateResult* aResult, |
|
138 TInt aCountOfAvailableUpdates, |
|
139 TBool aUpdateNow, |
|
140 TInt aError ) |
|
141 { |
|
142 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::RequestCompleted() begin"); |
|
143 IAUPDATE_TRACE_1("[IAUPDATE] error code: %d", aError ); |
|
144 |
|
145 if ( !iMessage ) //be sure that there is still message to complete |
|
146 { |
|
147 IAUPDATE_TRACE("[IAUPDATE] No message to complete"); |
|
148 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::RequestCompleted() end"); |
|
149 return; |
|
150 } |
|
151 |
|
152 IAUpdateClientDefines::TIAUpdateServerFunctions functionId = |
|
153 static_cast<IAUpdateClientDefines::TIAUpdateServerFunctions>( iMessage->Function() ); |
|
154 |
|
155 TInt error( KErrNone ); |
|
156 |
|
157 switch( functionId ) |
|
158 { |
|
159 case IAUpdateClientDefines::EIAUpdateServerCheckUpdates: |
|
160 { |
|
161 TPckg<TInt> availableUpdates( aCountOfAvailableUpdates ); |
|
162 TPtr8 ptr1( availableUpdates ); |
|
163 TRAP( error, iMessage->WriteL( 1, ptr1 ) ); |
|
164 break; |
|
165 } |
|
166 |
|
167 case IAUpdateClientDefines:: EIAUpdateServerShowUpdateQuery: |
|
168 { |
|
169 TPckg<TInt> updateNow( aUpdateNow ); |
|
170 TPtr8 ptr1( updateNow ); |
|
171 TRAP( error, iMessage->WriteL( 1, ptr1 ) ); |
|
172 break; |
|
173 } |
|
174 |
|
175 case IAUpdateClientDefines::EIAUpdateServerShowUpdates: |
|
176 { |
|
177 TPckg<TInt> successCount( aResult->SuccessCount() ); |
|
178 TPtr8 ptr1( successCount ); |
|
179 |
|
180 TPckg<TInt> failCount( aResult->FailCount() ); |
|
181 TPtr8 ptr2( failCount ); |
|
182 |
|
183 TPckg<TInt> cancelCount( aResult->CancelCount() ); |
|
184 TPtr8 ptr3( cancelCount ); |
|
185 |
|
186 TRAP( error, |
|
187 iMessage->WriteL( 1, ptr1 ); |
|
188 iMessage->WriteL( 2, ptr2 ); |
|
189 iMessage->WriteL( 3, ptr3 ); ); |
|
190 break; |
|
191 } |
|
192 case IAUpdateClientDefines::EIAUpdateServerStartedByLauncher: |
|
193 break; |
|
194 default: |
|
195 // We should never come here. |
|
196 break; |
|
197 } |
|
198 |
|
199 if ( error == KErrNone ) |
|
200 { |
|
201 // Writing of the data in to the message went ok. |
|
202 // So, nothing to inform about that. |
|
203 // Insert possible error code of the update operation. |
|
204 error = aError; |
|
205 } |
|
206 |
|
207 delete aResult; |
|
208 aResult = NULL; |
|
209 |
|
210 iMessage->Complete( error ); |
|
211 delete iMessage; |
|
212 iMessage = NULL; |
|
213 |
|
214 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::RequestCompleted() end"); |
|
215 } |
|
216 |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // CIAUpdateSession::Server |
|
220 // Returns reference to the server. |
|
221 // (other items were commented in a header). |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 CIAUpdateServer& CIAUpdateSession::Server() |
|
225 { |
|
226 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::Server()"); |
|
227 return *static_cast<CIAUpdateServer*>( const_cast<CServer2*> |
|
228 ( CSession2::Server() ) ); |
|
229 } |
|
230 |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CIAUpdateSession::HandleRequestL |
|
234 // Handles the request. |
|
235 // (other items were commented in a header). |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 void CIAUpdateSession::HandleRequestL( const RMessage2& aMessage ) |
|
239 { |
|
240 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::HandleRequestL() begin"); |
|
241 |
|
242 CIAUpdateAppUi* appUi = |
|
243 static_cast<CIAUpdateAppUi*>( iEikEnv->EikAppUi() ); |
|
244 // First value is the function number |
|
245 IAUpdateClientDefines::TIAUpdateServerFunctions functionId = |
|
246 static_cast<IAUpdateClientDefines::TIAUpdateServerFunctions>( aMessage.Function() ); |
|
247 IAUPDATE_TRACE_1("[IAUPDATE] function id: %d", functionId ); |
|
248 |
|
249 if ( functionId == IAUpdateClientDefines::EIAUpdateServerCancel ) |
|
250 { |
|
251 appUi->PotentialCancel(); |
|
252 if ( iMessage ) //complete possible ongoing request |
|
253 { |
|
254 iMessage->Complete( KErrCancel ); |
|
255 delete iMessage; |
|
256 iMessage = NULL; |
|
257 } |
|
258 // Because cancel is sent synchronously from the client side, |
|
259 // aMessage is different than the iMessage for other operation |
|
260 // that is currently going on asynchronously. |
|
261 // So, RequestCompleted above closed that connection. |
|
262 // Now, inform the caller of the cancel operation |
|
263 // that cancellation was success. |
|
264 aMessage.Complete( KErrNone ); |
|
265 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::HandleRequestL() end"); |
|
266 return; |
|
267 } |
|
268 |
|
269 if ( functionId == IAUpdateClientDefines::EIAUpdateServerToForeground ) |
|
270 { |
|
271 appUi->HandleClientToForegroundL(); |
|
272 aMessage.Complete( KErrNone ); |
|
273 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::HandleRequestL() end"); |
|
274 return; |
|
275 } |
|
276 |
|
277 if ( functionId == IAUpdateClientDefines::EIAUpdateServerSendWgId ) |
|
278 { |
|
279 TPckgBuf<TInt> wgIdPkg( 0 ); |
|
280 aMessage.ReadL( 0, wgIdPkg ); |
|
281 TInt wgId = wgIdPkg(); |
|
282 appUi->SetClientWgId( wgId ); |
|
283 aMessage.Complete( KErrNone ); |
|
284 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::HandleRequestL() end"); |
|
285 return; |
|
286 } |
|
287 |
|
288 |
|
289 if ( iMessage ) |
|
290 { |
|
291 // This session is used in a wrong way because the |
|
292 // old operation has not been completed before new one is |
|
293 // started. |
|
294 User::Leave( KErrInUse ); |
|
295 } |
|
296 |
|
297 iMessage = new( ELeave ) RMessage2( aMessage ); |
|
298 if ( functionId == IAUpdateClientDefines::EIAUpdateServerStartedByLauncher ) |
|
299 { |
|
300 TPckgBuf<TBool> refreshFromNetworkDeniedPkg( 0 ); |
|
301 aMessage.ReadL( 0, refreshFromNetworkDeniedPkg ); |
|
302 TBool refreshFromNetworkDenied = refreshFromNetworkDeniedPkg(); |
|
303 appUi->StartedByLauncherL( *this, refreshFromNetworkDenied ); |
|
304 } |
|
305 else if ( functionId == IAUpdateClientDefines::EIAUpdateServerShowUpdateQuery ) |
|
306 { |
|
307 // Handle the update query dialog request |
|
308 TUint id = aMessage.SecureId().iId; |
|
309 appUi->ShowUpdateQueryRequestL( *this, id ); |
|
310 } |
|
311 else |
|
312 { |
|
313 // Handle update operation related requests. |
|
314 HBufC8* data = NULL; |
|
315 data = HBufC8::NewLC( aMessage.GetDesLength( 0 ) ); |
|
316 TPtr8 ptr( data->Des() ); |
|
317 aMessage.ReadL( 0, ptr ); |
|
318 |
|
319 CIAUpdateParameters* params( CIAUpdateParameters::NewLC() ); |
|
320 IAUpdateTools::InternalizeParametersL( *params, *data ); |
|
321 // Do not destroy, because ownership of params is transferred |
|
322 // below. |
|
323 CleanupStack::Pop( params ); |
|
324 CleanupStack::PopAndDestroy( data ); |
|
325 |
|
326 if ( aMessage.SecureId() != KSIDBackgroundChecker ) |
|
327 { |
|
328 // other processes than backroundchecker are not allowed to cause refresh from network |
|
329 params->SetRefresh( EFalse ); |
|
330 } |
|
331 switch( functionId ) |
|
332 { |
|
333 case IAUpdateClientDefines::EIAUpdateServerCheckUpdates: |
|
334 appUi->CheckUpdatesRequestL( *this, params ); |
|
335 break; |
|
336 |
|
337 case IAUpdateClientDefines::EIAUpdateServerShowUpdates: |
|
338 appUi->ShowUpdatesRequestL( *this, params ); |
|
339 break; |
|
340 |
|
341 default: |
|
342 // We should never come here |
|
343 delete params; |
|
344 params = NULL; |
|
345 break; |
|
346 } |
|
347 } |
|
348 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::HandleRequestL() end"); |
|
349 } |
|
350 |
|
351 |
|
352 // ----------------------------------------------------------------------------- |
|
353 // CIAUpdateSession::SecurityCheckL |
|
354 // Virtual framework function that is called on receipt of a message from the |
|
355 // client. This allows the service implementation to define a security policy |
|
356 // for messages from the client. |
|
357 // (other items were commented in a header). |
|
358 // ----------------------------------------------------------------------------- |
|
359 // |
|
360 CPolicyServer::TCustomResult CIAUpdateSession::SecurityCheckL( const RMessage2& aMsg, |
|
361 TInt& /*aAction*/, |
|
362 TSecurityInfo& /*aMissing*/ ) |
|
363 { |
|
364 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::SecurityCheckL() begin"); |
|
365 |
|
366 CPolicyServer::TCustomResult result = CPolicyServer::EFail; |
|
367 switch ( aMsg.Function() ) |
|
368 { |
|
369 case IAUpdateClientDefines::EIAUpdateServerStartedByLauncher: |
|
370 if ( aMsg.SecureId() == KSIDLauncher ) |
|
371 { |
|
372 result = CPolicyServer::EPass; |
|
373 } |
|
374 break; |
|
375 case IAUpdateClientDefines::EIAUpdateServerCheckUpdates: |
|
376 case IAUpdateClientDefines::EIAUpdateServerShowUpdates: |
|
377 // no capability check is needed because SID is checked later |
|
378 // that means that only bacgkroundchecker is allowed to initiate network refresh |
|
379 |
|
380 case IAUpdateClientDefines::EIAUpdateServerShowUpdateQuery: |
|
381 case IAUpdateClientDefines::EIAUpdateServerCancel: |
|
382 case IAUpdateClientDefines::EIAUpdateServerToForeground: |
|
383 case IAUpdateClientDefines::EIAUpdateServerSendWgId: |
|
384 // No capabilities needed |
|
385 result = CPolicyServer::EPass; |
|
386 break; |
|
387 |
|
388 default: |
|
389 // Not recognized message |
|
390 result = CPolicyServer::EFail; |
|
391 } |
|
392 IAUPDATE_TRACE_1("[IAUPDATE] result: %d", result ); |
|
393 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSession::SecurityCheckL() end"); |
|
394 return result; |
|
395 } |
|
396 |
|
397 |
|
398 // End of File |