|
1 /* |
|
2 * Copyright (c) 2005 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: fotaengines server side session |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "FotasrvSession.h" |
|
20 #include "FotaSrvDebug.h" |
|
21 #include <eikenv.h> |
|
22 #include <eikappui.h> |
|
23 #include <s32mem.h> |
|
24 #include <e32base.h> |
|
25 #include <centralrepository.h> |
|
26 #include "FotaServer.h" |
|
27 |
|
28 // ============================= MEMBER FUNCTIONS ============================ |
|
29 |
|
30 class CFotaServer; |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // CFotaSrvSession::CheckClientSecureIdL |
|
34 // Returns True if caller is syncml framework. False for fotasrv. |
|
35 // Leaves if client is unknown |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 TFotaClient CFotaSrvSession::CheckClientSecureIdL(const RMessage2& aMessage) |
|
39 { |
|
40 TFotaClient client(EUnknown); |
|
41 TUid dmhostserver1 = TUid::Uid(KDMHostServer1Uid); |
|
42 TUid fota = TUid::Uid(KFotaServerUid); |
|
43 TUid omadmappui = TUid::Uid(KOmaDMAppUid); |
|
44 TUid starter = TUid::Uid(KStarterUid); |
|
45 TUid fscheduler = TUid::Uid(KFotaScheduler); |
|
46 TUid fms = TUid::Uid(KFMSServerUid); |
|
47 TUid softwarechecker = TUid::Uid(0x2000BB96); |
|
48 TUid softwarecheckerbackground = TUid::Uid(0x2000BB97); |
|
49 TUid testapp = TUid::Uid(0x102073E4); |
|
50 TUid testapp2 = TUid::Uid(0x10009CF4); |
|
51 |
|
52 TUid iadclient = TUid::Uid(0x2000F85A); |
|
53 |
|
54 // Syncml |
|
55 if (aMessage.SecureId() == dmhostserver1.iUid) |
|
56 { |
|
57 FLOG( |
|
58 _L("[CFotaSrvSession] CheckClientSecureIdL client is DmHostserver!")); |
|
59 client = EDMHostServer; |
|
60 } |
|
61 else if (aMessage.SecureId() == omadmappui.iUid) |
|
62 { |
|
63 FLOG( |
|
64 _L("[CFotaSrvSession] CheckClientSecureIdL client is omadmappui!")); |
|
65 client = EOMADMAppUi; |
|
66 } |
|
67 else if (aMessage.SecureId() == starter.iUid) |
|
68 { |
|
69 FLOG(_L("[CFotaSrvSession] CheckClientSecureIdL client is starter!")); |
|
70 client = EStarter; |
|
71 } |
|
72 else if (aMessage.SecureId() == softwarechecker.iUid |
|
73 || aMessage.SecureId() == iadclient.iUid) |
|
74 { |
|
75 FLOG(_L("[CFotaSrvSession] CheckClientSecureIdL client is IAD!")); |
|
76 client = ESoftwareChecker; |
|
77 } |
|
78 else if (aMessage.SecureId() == softwarecheckerbackground.iUid) |
|
79 { |
|
80 FLOG( |
|
81 _L("[CFotaSrvSession] CheckClientSecureIdL client is IAD - background!")); |
|
82 client = ESoftwareCheckerBackground; |
|
83 } |
|
84 else if (aMessage.SecureId() == fms.iUid) |
|
85 { |
|
86 FLOG(_L("[CFotaSrvSession] CheckClientSecureIdL client is FMS!")); |
|
87 client = EFMSServer; |
|
88 } |
|
89 else if (aMessage.SecureId() == fscheduler.iUid) |
|
90 { |
|
91 FLOG( |
|
92 _L("[CFotaSrvSession] CheckClientSecureIdL client is fota scheduler!")); |
|
93 client = EFotaScheduler; |
|
94 } |
|
95 else if (aMessage.SecureId() == 0x0323231 || aMessage.SecureId() |
|
96 == testapp.iUid || aMessage.SecureId() == testapp2.iUid) |
|
97 { |
|
98 client = EFotaTestApp; |
|
99 } |
|
100 |
|
101 return client; |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // CFotaSrvSession::CFotaSrvSession |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 CFotaSrvSession::CFotaSrvSession() |
|
109 { |
|
110 FLOG(_L( "CFotaSrvSession::CFotaSrvSession( )" )); |
|
111 iError = KErrNone; |
|
112 //iDoc = CEikonEnv::Static()->EikAppUi()->Document(); |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // CFotaSrvSession::~CFotaSrvSession |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 CFotaSrvSession::~CFotaSrvSession() |
|
120 { |
|
121 FotaServer()->DropSession(); |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // CFotaSrvSession::ServiceL |
|
126 // Handle client request |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 void CFotaSrvSession::ServiceL(const RMessage2& aMessage) |
|
130 { |
|
131 TInt err(KErrNone); |
|
132 TInt pkgid = 0; |
|
133 TPackageState state; |
|
134 RThread clt; |
|
135 aMessage.ClientL(clt); |
|
136 TFullName cltnm = clt.FullName(); |
|
137 FLOG(_L( "CFotaSrvSession::ServiceL %d serving for %S?" ), |
|
138 aMessage.Function(), &cltnm); |
|
139 |
|
140 TFotaClient client = CheckClientSecureIdL(aMessage); |
|
141 |
|
142 if (client == EUnknown) |
|
143 { |
|
144 FLOG(_L("Permission denied to use fota services!")); |
|
145 User::Leave(KErrPermissionDenied); |
|
146 } |
|
147 |
|
148 TInt cmd = aMessage.Function(); |
|
149 if ((cmd != EGetState) && (cmd != EGetResult) && (cmd != EGetCurrFwDetails) && (cmd != EGetUpdateTimestamp)) |
|
150 { |
|
151 |
|
152 TInt fotaValue(1); |
|
153 CRepository* centrep(NULL); |
|
154 TUid uidValue = |
|
155 { |
|
156 0x101F9A08 |
|
157 }; // KCRFotaAdapterEnabled |
|
158 |
|
159 centrep = CRepository::NewL(uidValue); |
|
160 if (centrep) |
|
161 { |
|
162 FLOG(_L("centralrepository found ")); |
|
163 centrep->Get(1, fotaValue); // KCRFotaAdapterEnabled |
|
164 delete centrep; |
|
165 } |
|
166 |
|
167 if (!fotaValue) |
|
168 { |
|
169 FLOG(_L("Fota is disabled or not supported!")); |
|
170 User::Leave(KErrNotSupported); |
|
171 } |
|
172 |
|
173 } |
|
174 |
|
175 switch (aMessage.Function()) |
|
176 { |
|
177 |
|
178 case EFotaDownload: |
|
179 { |
|
180 FLOG(_L( "CFotaSrvSession::ServiceL DOWNLOAD")); |
|
181 TDownloadIPCParams ipc; |
|
182 TPckg<TDownloadIPCParams> pkg(ipc); |
|
183 aMessage.Read(0, pkg); |
|
184 TInt deslen = aMessage.GetDesLengthL(1); |
|
185 HBufC8* urlbuf = HBufC8::NewLC(deslen); |
|
186 TPtr8 urlptr = urlbuf->Des(); |
|
187 aMessage.Read(1, urlptr); |
|
188 TInt silent = aMessage.Int2(); |
|
189 FotaServer()->DownloadL(ipc, urlptr, client, silent, EFalse); |
|
190 CleanupStack::PopAndDestroy(urlbuf); // urlbuf |
|
191 aMessage.Complete(KErrNone); |
|
192 |
|
193 break; |
|
194 } |
|
195 case EFotaUpdate: |
|
196 { |
|
197 FLOG(_L( "CFotaSrvSession::ServiceL UPDATE" )); |
|
198 TDownloadIPCParams ipc; |
|
199 TPckg<TDownloadIPCParams> pkg(ipc); |
|
200 aMessage.Read(0, pkg); |
|
201 |
|
202 // If update started from omadmappui, no alert should be sent if |
|
203 // update is cancelled |
|
204 if (client == EOMADMAppUi) |
|
205 { |
|
206 ipc.iSendAlert = EFalse; |
|
207 } |
|
208 FotaServer()->TryUpdateL(client); |
|
209 aMessage.Complete(KErrNone); |
|
210 break; |
|
211 } |
|
212 case EFotaDownloadAndUpdate: |
|
213 { |
|
214 FLOG(_L( "CFotaSrvSession::ServiceL DOWNLOADANDUPDATE" )); |
|
215 TDownloadIPCParams ipc; |
|
216 TPckg<TDownloadIPCParams> pkg(ipc); |
|
217 aMessage.Read(0, pkg); |
|
218 TInt deslen = aMessage.GetDesLengthL(1); |
|
219 HBufC8* urlbuf = HBufC8::NewLC(deslen); |
|
220 TPtr8 urlptr = urlbuf->Des(); |
|
221 aMessage.Read(1, urlptr); |
|
222 TFotaClient requester = CheckClientSecureIdL(aMessage); |
|
223 |
|
224 TInt silent = aMessage.Int2(); |
|
225 FotaServer()->DownloadL(ipc, urlptr, requester, silent, ETrue); |
|
226 CleanupStack::PopAndDestroy(urlbuf); |
|
227 aMessage.Complete(KErrNone); |
|
228 } |
|
229 break; |
|
230 |
|
231 case EFotaTryResumeDownload: |
|
232 { |
|
233 FLOG(_L( "CFotaSrvSession::ServiceL TRYRESUMEDOWNLOAD" )); |
|
234 if (client == EOMADMAppUi || client == EFMSServer || client |
|
235 == EFotaTestApp) |
|
236 { |
|
237 TInt silent = aMessage.Int0(); |
|
238 |
|
239 FotaServer()->TryResumeDownloadL(client, silent); // silent |
|
240 aMessage.Complete(KErrNone); |
|
241 } |
|
242 else |
|
243 { |
|
244 aMessage.Complete(KErrAccessDenied); |
|
245 } |
|
246 |
|
247 } |
|
248 break; |
|
249 |
|
250 case EDeletePackage: |
|
251 { |
|
252 FLOG(_L( "CFotaSrvSession::ServiceL DELETEPACKAGE")); |
|
253 pkgid = aMessage.Int0(); |
|
254 FotaServer()->DeletePackageL(pkgid); |
|
255 aMessage.Complete(KErrNone); |
|
256 } |
|
257 break; |
|
258 case EGetState: |
|
259 { |
|
260 FLOG(_L( "CFotaSrvSession::ServiceL GETSTATE" )); |
|
261 pkgid = aMessage.Int0(); |
|
262 |
|
263 state = FotaServer()->GetStateL(pkgid); |
|
264 |
|
265 FLOG(_L( "CFotaSrvSession::ServiceL GETSTATE << %d" ), state.iState); |
|
266 TPckg<RFotaEngineSession::TState> pkg2(state.iState); |
|
267 aMessage.Write(1, pkg2); |
|
268 aMessage.Complete(KErrNone); |
|
269 } |
|
270 break; |
|
271 case EGetResult: |
|
272 { |
|
273 FLOG(_L( "CFotaSrvSession::ServiceL GETRESULT >>" )); |
|
274 pkgid = aMessage.Int0(); |
|
275 state = FotaServer()->GetStateL(pkgid); |
|
276 TPckg<TInt> pkg2(state.iResult); |
|
277 FLOG(_L( "CFotaSrvSession::ServiceL GETRESULT << %d" ), |
|
278 state.iResult); |
|
279 aMessage.Write(1, pkg2); |
|
280 aMessage.Complete(err); |
|
281 break; |
|
282 } |
|
283 case EGetUpdatePackageIds: |
|
284 { |
|
285 FLOG(_L( "CFotaSrvSession::ServiceL EGETUPDATEPACKAGEIDS" )); |
|
286 TPkgIdList pkgids; |
|
287 FotaServer()->GetUpdatePackageIdsL(pkgids); |
|
288 TPckg<TPkgIdList> pkgids_pkg(pkgids); |
|
289 aMessage.Write(0, pkgids_pkg); |
|
290 aMessage.Complete(KErrNone); |
|
291 } |
|
292 break; |
|
293 |
|
294 case EGetUpdateTimestamp: |
|
295 { |
|
296 FLOG(_L( "CFotaSrvSession::ServiceL EGETUPDATETIMESTAMP" )); |
|
297 TBuf16<15> timestamp; |
|
298 FotaServer()->GetUpdateTimeStampL(timestamp); |
|
299 aMessage.Write(0, timestamp); |
|
300 aMessage.Complete(KErrNone); |
|
301 } |
|
302 break; |
|
303 |
|
304 case EGenericAlertSentForPackage: |
|
305 { |
|
306 FLOG(_L( "CFotaSrvSession::ServiceL EGENERICALERTSENT FOR PKGID" )); |
|
307 TInt pkgid = aMessage.Int0(); |
|
308 FotaServer()->ResetFotaStateL(pkgid); |
|
309 aMessage.Complete(err); |
|
310 } |
|
311 break; |
|
312 |
|
313 case EScheduledUpdate: |
|
314 { |
|
315 FLOG(_L( "CFotaSrvSession::ServiceL ESCHEDULEDUPDATE" )); |
|
316 TFotaScheduledUpdate sched(-1, -1); |
|
317 TPckg<TFotaScheduledUpdate> p(sched); |
|
318 aMessage.Read(0, p); |
|
319 |
|
320 FLOG(_L(" pkgid: %d scheduleid:%d"), sched.iPkgId, |
|
321 sched.iScheduleId); |
|
322 FotaServer()->ScheduledUpdateL(sched, client); |
|
323 aMessage.Complete(KErrNone); |
|
324 |
|
325 } |
|
326 break; |
|
327 |
|
328 case EPauseDownload: |
|
329 { |
|
330 FLOG(_L( "CFotaSrvSession::ServiceL EPAUSEDOWNLOAD" )); |
|
331 FotaServer()->PauseDownloadL(); |
|
332 aMessage.Complete(KErrNone); |
|
333 } |
|
334 break; |
|
335 case EGetCurrFwDetails: |
|
336 { |
|
337 FLOG(_L( "CFotaSrvSession::ServiceL EGETCURRFWDETAILS" )); |
|
338 |
|
339 TBuf8<KFotaMaxPkgNameLength> name; |
|
340 TBuf8<KFotaMaxPkgVersionLength> version; |
|
341 TInt size(0); |
|
342 |
|
343 FotaServer()->GetCurrentFwDetailsL(name, version, size); |
|
344 |
|
345 /* |
|
346 aMessage.Write(1, name); |
|
347 aMessage.Write(2, version); |
|
348 TPckg<TInt> psize(size); |
|
349 aMessage.Write(3, psize); |
|
350 |
|
351 aMessage.Complete(KErrNone);*/ |
|
352 |
|
353 aMessage.Write(0, name); |
|
354 aMessage.Write(1, version); |
|
355 TPckg<TInt> psize(size); |
|
356 aMessage.Write(2, psize); |
|
357 |
|
358 aMessage.Complete(KErrNone); |
|
359 |
|
360 |
|
361 } |
|
362 break; |
|
363 default: |
|
364 { |
|
365 FLOG(_L( "CFotaSrvSession::ServiceL In default case" )); |
|
366 } |
|
367 break; |
|
368 } |
|
369 } |
|
370 |
|
371 // ---------------------------------------------------------------------------------------- |
|
372 // CFotaSrvSession::ServiceError |
|
373 // ---------------------------------------------------------------------------------------- |
|
374 void CFotaSrvSession::ServiceError(const RMessage2& aMessage, TInt aError) |
|
375 { |
|
376 FLOG(_L("CFotaSrvSession::ServiceError, err = %d >>"), aError); |
|
377 CSession2::ServiceError(aMessage, aError); |
|
378 FLOG(_L("CFotaSrvSession::ServiceError <<")); |
|
379 } |
|
380 |
|
381 // --------------------------------------------------------------------------- |
|
382 // CFotaSrvSession::FotaServer |
|
383 // Helper function |
|
384 // --------------------------------------------------------------------------- |
|
385 // |
|
386 |
|
387 CFotaServer* CFotaSrvSession::FotaServer() const |
|
388 { |
|
389 return (CFotaServer*) Server(); |
|
390 } |
|
391 |
|
392 void DispatchMessageL(const RMessage2& aMessage) |
|
393 { |
|
394 return; |
|
395 } |
|
396 |