|
1 /* |
|
2 * Copyright (c) 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 class implements the condition based schedule. |
|
15 * |
|
16 */ |
|
17 //System includes |
|
18 #include <eikenv.h> |
|
19 #include <e32property.h> |
|
20 #include <centralrepository.h> |
|
21 |
|
22 //User includes |
|
23 #include "DmEventScheduler.h" |
|
24 #include "DmEventNotifierCommon.h" |
|
25 #include "DmEventNotifierInternal.h" |
|
26 #include "SwApplicationService.h" //Software service |
|
27 #include "JavaApplicationService.h" //Java service |
|
28 #include "MMCService.h" //MMC service |
|
29 #include "DmEventNotifierDebug.h" |
|
30 |
|
31 #include "SCPEventHandler.h" // dll for event handling (viz: uninstallation) |
|
32 |
|
33 // ====================== MEMBER FUNCTIONS =================================== |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // CDmEventScheduler::CDmEventScheduler() |
|
37 // --------------------------------------------------------------------------- |
|
38 CDmEventScheduler::CDmEventScheduler() |
|
39 { |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // CDmEventScheduler::~CDmEventScheduler() |
|
44 // --------------------------------------------------------------------------- |
|
45 CDmEventScheduler::~CDmEventScheduler() |
|
46 { |
|
47 FLOG(_L("CDmEventScheduler::~CDmEventScheduler >>")); |
|
48 |
|
49 iScheduler.Close(); |
|
50 |
|
51 iServices.DeleteAll(); |
|
52 iServices.Reset(); |
|
53 |
|
54 FLOG(_L("CDmEventScheduler::~CDmEventScheduler <<")); |
|
55 } |
|
56 |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // CDmEventScheduler::NewL() |
|
60 // --------------------------------------------------------------------------- |
|
61 CDmEventScheduler* CDmEventScheduler::NewL() |
|
62 { |
|
63 FLOG(_L("CDmEventScheduler::NewL >>")); |
|
64 |
|
65 CDmEventScheduler* self = new (ELeave) CDmEventScheduler(); |
|
66 CleanupStack::PushL(self); |
|
67 self->ConstructL(); |
|
68 CleanupStack::Pop(); |
|
69 |
|
70 FLOG(_L("CDmEventScheduler::NewL <<")); |
|
71 return self; |
|
72 } |
|
73 |
|
74 CDmEventScheduler* CDmEventScheduler::NewLC() |
|
75 { |
|
76 FLOG(_L("CDmEventScheduler::NewLC >>")); |
|
77 |
|
78 CDmEventScheduler* self = CDmEventScheduler::NewL(); |
|
79 CleanupStack::PushL(self); |
|
80 |
|
81 FLOG(_L("CDmEventScheduler::NewLC <<")); |
|
82 return self; |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // CDmEventScheduler::ConstructL() |
|
87 // --------------------------------------------------------------------------- |
|
88 void CDmEventScheduler::ConstructL() |
|
89 { |
|
90 FLOG(_L("CDmEventScheduler::ConstructL >>")); |
|
91 |
|
92 __LEAVE_IF_ERROR(iScheduler.Connect()); |
|
93 |
|
94 TFileName handler(KDmEventNotifierExe); |
|
95 |
|
96 User::LeaveIfError(iScheduler.Register(handler, CActive::EPriorityStandard)); |
|
97 |
|
98 iServices[ESoftwareService] = CSwApplicationService::NewL(); |
|
99 |
|
100 iServices[EJavaService] = CJavaApplicationService::NewL(); |
|
101 |
|
102 iServices[EMmcService] = CMmcService::NewL(); |
|
103 |
|
104 FLOG(_L("CDmEventScheduler::ConstructL <<")); |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // CDmEventScheduler::CreateConditionScheduleL() |
|
109 // --------------------------------------------------------------------------- |
|
110 void CDmEventScheduler::CreateConditionScheduleL(CDmEventServiceBase* aService) |
|
111 { |
|
112 FLOG(_L("CDmEventScheduler::CreateConditionSchedule >>")); |
|
113 |
|
114 //Create new schedule |
|
115 TInt err(KErrNone); |
|
116 TBool schenabled (EFalse); |
|
117 TSchedulerItemRef conditionScheduleHandle; |
|
118 TTsTime defaultTime; |
|
119 TTime time; |
|
120 time.HomeTime(); |
|
121 time = time.operator+(TTimeIntervalYears(10)); //Schedule will automatically expire after 10 years! |
|
122 defaultTime.SetLocalTime( time ); |
|
123 TInt newConditionTaskId = -1; |
|
124 |
|
125 if (aService == NULL) |
|
126 { |
|
127 |
|
128 TRAP(err, DeleteScheduleL()); |
|
129 FLOG(_L("Deleted existing schedule, err = %d"),err); |
|
130 |
|
131 |
|
132 //Performing for Software Installer |
|
133 FLOG(_L("Registering for Software Installer...")); |
|
134 if (iServices[ESoftwareService]->IsKeyValid()) |
|
135 { |
|
136 CSchConditionArray* aConditions; |
|
137 |
|
138 aConditions = CreateConditionLC(iServices[ESoftwareService]); |
|
139 |
|
140 err = CreateConditionScheduleWithTaskL(iConditionScheduleHandle, |
|
141 iScheduler, defaultTime, newConditionTaskId, aConditions, iServices[ESoftwareService] ); |
|
142 |
|
143 schenabled = (KErrNone == err); |
|
144 CleanupStack::PopAndDestroy(); //aConditions |
|
145 } |
|
146 else |
|
147 { |
|
148 FLOG(_L("Can't read PS key, hence not registering!")); |
|
149 } |
|
150 //Performing for Java Installer |
|
151 FLOG(_L("Registering for Java Installer...")); |
|
152 if (iServices[EJavaService]->IsKeyValid()) |
|
153 { |
|
154 CSchConditionArray* aConditions; |
|
155 |
|
156 aConditions = CreateConditionLC(iServices[EJavaService]); |
|
157 |
|
158 err = CreateConditionScheduleWithTaskL(iConditionScheduleHandle, |
|
159 iScheduler, defaultTime, newConditionTaskId, aConditions, iServices[EJavaService] ); |
|
160 |
|
161 schenabled = (KErrNone == err); |
|
162 CleanupStack::PopAndDestroy(); //aConditions |
|
163 } |
|
164 else |
|
165 { |
|
166 FLOG(_L("Can't read PS key, hence not registering!")); |
|
167 } |
|
168 |
|
169 //Performing for Mmc observer |
|
170 FLOG(_L("Registering for Mmc observer...")); |
|
171 if (iServices[EMmcService]->IsKeyValid()) |
|
172 { |
|
173 CSchConditionArray* aConditions; |
|
174 |
|
175 aConditions = CreateConditionLC(iServices[EMmcService]); |
|
176 |
|
177 err = CreateConditionScheduleWithTaskL(iConditionScheduleHandle, |
|
178 iScheduler, defaultTime, newConditionTaskId, aConditions, iServices[EMmcService] ); |
|
179 |
|
180 schenabled = (KErrNone == err); |
|
181 CleanupStack::PopAndDestroy(); //aConditions |
|
182 |
|
183 if (err == KErrNone) |
|
184 { |
|
185 //Set cenrep value for mmc accordingly |
|
186 |
|
187 CMmcService *ptr = (CMmcService *) iServices[EMmcService]; |
|
188 ptr->UpdateMmcStatus(); |
|
189 } |
|
190 } |
|
191 else |
|
192 { |
|
193 FLOG(_L("Can't read PS key, hence not registering!")); |
|
194 } |
|
195 } |
|
196 else |
|
197 { |
|
198 FLOG(_L("Scheduling for only the expired service")); |
|
199 CSchConditionArray* aConditions; |
|
200 |
|
201 aConditions = CreateConditionLC(aService); |
|
202 |
|
203 err = CreateConditionScheduleWithTaskL(iConditionScheduleHandle, |
|
204 iScheduler, defaultTime, newConditionTaskId, aConditions, aService ); |
|
205 |
|
206 CleanupStack::PopAndDestroy(); //aConditions |
|
207 |
|
208 schenabled = (KErrNone == err); |
|
209 } |
|
210 |
|
211 SetScheduleEnabledL(schenabled); |
|
212 |
|
213 FLOG(_L("CDmEventScheduler::CreateConditionSchedule, error = %d <<"), err); |
|
214 } |
|
215 |
|
216 // --------------------------------------------------------------------------- |
|
217 // CDmEventScheduler::WaitAndCreateConditionScheduleL() |
|
218 // --------------------------------------------------------------------------- |
|
219 void CDmEventScheduler::WaitAndCreateConditionScheduleL(TName aTaskName) |
|
220 { |
|
221 FLOG(_L("CDmEventScheduler::WaitAndCreateConditionScheduleL >>")); |
|
222 |
|
223 SetScheduleEnabledL(EHandlerNotRegistered); |
|
224 |
|
225 CDmEventServiceBase* service = FindExpiredService(aTaskName); |
|
226 // CleanupStack::PushL(service); // Not necessary, as service pointer is changed in the code |
|
227 |
|
228 if ( service ) |
|
229 { |
|
230 service->WaitForRequestCompleteL(); |
|
231 } |
|
232 |
|
233 //Read the status from aService |
|
234 THandlerServiceId srvid; |
|
235 THandlerOperation opn; |
|
236 |
|
237 service->GetServiceIdAndOperation(srvid,opn); |
|
238 |
|
239 TBool mmcservice (EFalse); |
|
240 if (service == iServices[EMmcService]) |
|
241 { |
|
242 mmcservice = ETrue; |
|
243 } |
|
244 |
|
245 if (iServices[EMmcService]) |
|
246 { |
|
247 delete iServices[EMmcService]; iServices[EMmcService] = NULL; |
|
248 iServices[EMmcService] = CMmcService::NewL(); |
|
249 } |
|
250 |
|
251 if (mmcservice) |
|
252 { |
|
253 service = iServices[EMmcService]; |
|
254 } |
|
255 CreateConditionScheduleL(service); |
|
256 |
|
257 if ( opn != ENoOpn ) |
|
258 { |
|
259 TRAPD(err, NotifyRegisteredServersL(srvid, opn)); |
|
260 FLOG(_L("Notification error = %d"), err); |
|
261 } |
|
262 else |
|
263 { |
|
264 FLOG(_L("Operation got cancelled. Skipping notification")); |
|
265 } |
|
266 |
|
267 // CleanupStack::Pop(service); //don't destroy as object is not owned |
|
268 |
|
269 FLOG(_L("CDmEventScheduler::WaitAndCreateConditionScheduleL <<")); |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // CDmEventScheduler::CreateConditionScheduleWithTaskL() |
|
274 // --------------------------------------------------------------------------- |
|
275 TInt CDmEventScheduler::CreateConditionScheduleWithTaskL( |
|
276 TSchedulerItemRef& aSchedulerItem, |
|
277 RScheduler& aScheduler, |
|
278 const TTsTime& aDefaultRunTime, |
|
279 TInt& aNewTaskId, |
|
280 CArrayFixFlat<TTaskSchedulerCondition>* &aConditions, |
|
281 CDmEventServiceBase* aService) |
|
282 { |
|
283 FLOG(_L("CDmEventScheduler::CreateConditionScheduleWithTaskL >>")); |
|
284 |
|
285 TInt ret(KErrNone); |
|
286 |
|
287 aSchedulerItem.iName = KAppDmEventNotifierUid.Name(); |
|
288 |
|
289 |
|
290 ret = aScheduler.CreatePersistentSchedule(aSchedulerItem, |
|
291 *aConditions, aDefaultRunTime); |
|
292 |
|
293 if (KErrNone == ret) |
|
294 { |
|
295 TTaskInfo taskInfo; |
|
296 taskInfo.iTaskId = 0; |
|
297 taskInfo.iName = aService->TaskName(); |
|
298 taskInfo.iPriority = 2; |
|
299 taskInfo.iRepeat = 0; |
|
300 HBufC* data = aService->TaskName().AllocLC(); |
|
301 |
|
302 ret = aScheduler.ScheduleTask(taskInfo, *data, aSchedulerItem.iHandle); |
|
303 aNewTaskId = taskInfo.iTaskId; |
|
304 |
|
305 CleanupStack::PopAndDestroy(); // data |
|
306 } |
|
307 else |
|
308 { |
|
309 //Creating persistent schedule failed, do something... |
|
310 FLOG(_L("Creation of persistent scheduled failed, error = %d"), ret); |
|
311 } |
|
312 |
|
313 FLOG(_L("CDmEventScheduler::CreateConditionScheduleWithTaskL, ret = %d <<"), ret); |
|
314 return ret; |
|
315 } |
|
316 |
|
317 // --------------------------------------------------------------------------- |
|
318 // CDmEventScheduler::DeleteScheduleL |
|
319 // --------------------------------------------------------------------------- |
|
320 void CDmEventScheduler::DeleteScheduleL() |
|
321 { |
|
322 FLOG(_L("CDmEventScheduler::DeleteScheduleL >>")); |
|
323 |
|
324 RScheduler sc; |
|
325 CArrayFixFlat<TSchedulerItemRef>* aSchRefArray = new CArrayFixFlat <TSchedulerItemRef>(KScheduleReferenceMax); |
|
326 TScheduleFilter aFilter(EAllSchedules); |
|
327 User::LeaveIfError( sc.Connect() ); |
|
328 CleanupClosePushL( sc ); |
|
329 CleanupStack::PushL(aSchRefArray); |
|
330 |
|
331 User::LeaveIfError( sc.GetScheduleRefsL( *aSchRefArray,aFilter) ); |
|
332 FLOG(_L("Schedule items: ")); |
|
333 for ( TInt i=0; i<aSchRefArray->Count(); ++i ) |
|
334 { |
|
335 TSchedulerItemRef it = (*aSchRefArray)[i]; |
|
336 if ( it.iName == KAppDmEventNotifierUid.Name() ) |
|
337 { |
|
338 TScheduleState2 sc_state; |
|
339 CSchConditionArray* sc_entries = new CSchConditionArray (KConditionArraySizeMax); |
|
340 TTsTime sc_time; |
|
341 CArrayFixFlat<TTaskInfo>* sc_tasks = new CArrayFixFlat <TTaskInfo>(KTaskArraySizeMax); |
|
342 |
|
343 CleanupStack::PushL( sc_entries ); |
|
344 CleanupStack::PushL( sc_tasks ); |
|
345 FLOG (_L("%d. schedule handle: %d name:'%S'"),i,it.iHandle, &(it.iName) ); |
|
346 |
|
347 TInt err = sc.GetScheduleL ( it.iHandle , sc_state, *sc_entries, sc_time, *sc_tasks); |
|
348 |
|
349 if (KErrNone == err) |
|
350 { |
|
351 for ( TInt j=0; j<sc_tasks->Count();++j) |
|
352 { |
|
353 TTaskInfo sc_task = (*sc_tasks)[j]; |
|
354 FLOG(_L(" schedule task %d '%S'"),sc_task.iTaskId,&(sc_task.iName) ); |
|
355 |
|
356 err = sc.DeleteTask(sc_task.iTaskId); |
|
357 FLOG(_L("Deleted task state, error = %d"), err); |
|
358 } |
|
359 } |
|
360 else |
|
361 { |
|
362 FLOG(_L("Getting schedule error = %d"), err); |
|
363 } |
|
364 |
|
365 err = sc.DeleteSchedule(it.iHandle ); |
|
366 FLOG(_L("Deleted schedule %d, error = %d"),i+1, err); |
|
367 |
|
368 CleanupStack::PopAndDestroy( sc_tasks ); |
|
369 CleanupStack::PopAndDestroy( sc_entries ); |
|
370 } |
|
371 } |
|
372 CleanupStack::PopAndDestroy( aSchRefArray ); |
|
373 CleanupStack::PopAndDestroy(&sc); |
|
374 FLOG(_L("CDmEventScheduler::DeleteScheduleL <<")); |
|
375 } |
|
376 |
|
377 // --------------------------------------------------------------------------- |
|
378 // CDmEventScheduler::CreateConditionLC |
|
379 // --------------------------------------------------------------------------- |
|
380 CSchConditionArray* CDmEventScheduler::CreateConditionLC(CDmEventServiceBase* aService) |
|
381 { |
|
382 FLOG(_L("CDmEventScheduler::CreateConditionLC >>")); |
|
383 |
|
384 CSchConditionArray* conditions = new (ELeave) CSchConditionArray(KConditionArraySize); |
|
385 CleanupStack::PushL(conditions); //To be poped/destroyed by the caller |
|
386 |
|
387 TTaskSchedulerCondition Condition; |
|
388 TPSKeyCondition pskeycondition = aService->GetPSKeyCondition(); |
|
389 Condition.iCategory = pskeycondition.iPskey.iConditionCategory; |
|
390 Condition.iKey = pskeycondition.iPskey.iConditionKey; |
|
391 Condition.iState = pskeycondition.iSchState; |
|
392 Condition.iType = pskeycondition.iSchType; |
|
393 |
|
394 conditions->AppendL(Condition); |
|
395 |
|
396 FLOG(_L("CDmEventScheduler::CreateConditionLC <<")); |
|
397 return conditions; |
|
398 } |
|
399 |
|
400 // --------------------------------------------------------------------------- |
|
401 // CDmEventScheduler::FindExpiredService |
|
402 // --------------------------------------------------------------------------- |
|
403 CDmEventServiceBase* CDmEventScheduler::FindExpiredService(TName& aTaskName) |
|
404 { |
|
405 FLOG(_L("CDmEventScheduler::FindExpiredService >>")); |
|
406 CDmEventServiceBase* ret (NULL); |
|
407 if (iServices[ESoftwareService]->TaskName().Compare(aTaskName) == KErrNone) |
|
408 { |
|
409 FLOG(_L("SW Operation detected...")) |
|
410 ret = iServices[ESoftwareService]; |
|
411 } |
|
412 else if (iServices[EJavaService]->TaskName().Compare(aTaskName) == KErrNone) |
|
413 { |
|
414 FLOG(_L("Java Inst Operation detected...")) |
|
415 ret = iServices[EJavaService]; |
|
416 } |
|
417 else if (iServices[EMmcService]->TaskName().Compare(aTaskName) == KErrNone) |
|
418 { |
|
419 FLOG(_L("MMC Operation detected...")) |
|
420 ret = iServices[EMmcService]; |
|
421 } |
|
422 else |
|
423 { |
|
424 //Should not land here... |
|
425 FLOG(_L("Unknown trigger")); |
|
426 } |
|
427 |
|
428 FLOG(_L("CDmEventScheduler::FindExpiredService, ret = %X <<"), ret); |
|
429 return ret; |
|
430 } |
|
431 |
|
432 // --------------------------------------------------------------------------- |
|
433 // CDmEventScheduler::NotifyRegisteredServicesL |
|
434 // --------------------------------------------------------------------------- |
|
435 void CDmEventScheduler::NotifyRegisteredServersL(THandlerServiceId aServiceId, THandlerOperation aOpn) |
|
436 { |
|
437 FLOG(_L("CDmEventScheduler::NotifyRegisteredServersL, serviceid = %d, operation = %d >>"), aServiceId, aOpn); |
|
438 //Read whome to notify... |
|
439 CRepository* cenrep (NULL); |
|
440 cenrep = CRepository::NewLC( KAppDmEventNotifierUid ); |
|
441 TInt notifyscp (KErrNotFound); |
|
442 TInt error = cenrep->Get(KDmEventNotifierEnabled, notifyscp); |
|
443 |
|
444 TInt notifyam (KErrNotFound); |
|
445 error = cenrep->Get(KSCPNotifyEvent,notifyam); |
|
446 |
|
447 CleanupStack::PopAndDestroy(cenrep); |
|
448 |
|
449 if (notifyscp) |
|
450 { |
|
451 FLOG(_L("CDmEventScheduler::NotifyRegisteredServersL: Invocation of SCPEventHandler")); |
|
452 TRAPD ( err, { |
|
453 CSCPEventHandler* handler = CSCPEventHandler::NewL(); |
|
454 handler->NotifyChangesL(aServiceId, aOpn); |
|
455 delete handler; |
|
456 handler = NULL; |
|
457 }); |
|
458 FLOG(_L("CDmEventScheduler::NotifyRegisteredServersL: SCPEventHandler completed with err: %d"), err); |
|
459 } |
|
460 if (notifyam) |
|
461 { |
|
462 //Notify AM server on the happened operation |
|
463 } |
|
464 |
|
465 FLOG(_L("CDmEventScheduler::NotifyRegisteredServersL notifyscp = %d, notifyam = %d<<"),notifyscp,notifyam); |
|
466 } |
|
467 |
|
468 // --------------------------------------------------------------------------- |
|
469 // CDmEventScheduler::IsScneduleEnabledL |
|
470 // --------------------------------------------------------------------------- |
|
471 TBool CDmEventScheduler::IsScheduleEnabledL() |
|
472 { |
|
473 FLOG(_L("CDmEventScheduler::IsScheduleEnabledL >>")); |
|
474 CRepository* cenrep (NULL); |
|
475 TInt error (KErrNone); |
|
476 TInt value (KErrNotFound); |
|
477 |
|
478 TRAP(error, cenrep = CRepository::NewL( KAppDmEventNotifierUid )); |
|
479 |
|
480 FLOG(_L("Cenrep file read status = %d"), error); |
|
481 User::LeaveIfError(error); |
|
482 CleanupStack::PushL(cenrep); |
|
483 |
|
484 error = cenrep->Get(KDmEventNotifierEnabled, value); |
|
485 |
|
486 CleanupStack::PopAndDestroy(cenrep); |
|
487 |
|
488 FLOG(_L("CDmEventScheduler::IsScheduleEnabledL, value = %d, error = %d <<"),value, error); |
|
489 return (value == EHandlerRegistered); |
|
490 } |
|
491 |
|
492 // --------------------------------------------------------------------------- |
|
493 // CDmEventScheduler::SetScheduleEnabledL |
|
494 // --------------------------------------------------------------------------- |
|
495 void CDmEventScheduler::SetScheduleEnabledL(TBool aValue) |
|
496 { |
|
497 FLOG(_L("CDmEventScheduler::SetScheduleEnabledL, aValue = %d >>"), aValue); |
|
498 |
|
499 CRepository* cenrep (NULL); |
|
500 TInt error (KErrNone); |
|
501 |
|
502 cenrep = CRepository::NewL( KAppDmEventNotifierUid ); |
|
503 CleanupStack::PushL(cenrep); |
|
504 |
|
505 error = cenrep->Set(KDmEventNotifierEnabled, aValue); |
|
506 |
|
507 CleanupStack::PopAndDestroy(cenrep); |
|
508 |
|
509 FLOG(_L("CDmEventScheduler::SetScheduleEnabledL, error = %d <<"),error); |
|
510 } |
|
511 //End of file |