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