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: |
|
15 * Implementation of CFotaCustCmdAllReasons class. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "fotacustcmdallreasons.h" |
|
20 #include "fotastartupDebug.h" |
|
21 #ifdef __SYNCML_DM_FOTA |
|
22 #include <fotaengine.h> |
|
23 #include "fmsclient.h" |
|
24 #include "fotaserverPrivateCRKeys.h" |
|
25 #include "FotaIPCTypes.h" |
|
26 #include "fmsclientserver.h" |
|
27 #endif |
|
28 #include <schtime.h> |
|
29 #include <csch_cli.h> |
|
30 #include <centralrepository.h> |
|
31 // RProperty |
|
32 #include <e32base.h> |
|
33 #include <e32property.h> |
|
34 // Memory status PS key headers |
|
35 #include <UikonInternalPSKeys.h> |
|
36 // Loading application headers |
|
37 #include <apgcli.h> |
|
38 #include <apacmdln.h> |
|
39 //Middleware includes |
|
40 #include <dmeventnotifiercrkeys.h> |
|
41 #include <dmeventnotifiercommon.h> |
|
42 |
|
43 // ======== MEMBER FUNCTIONS ======== |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // CFotaCustCmdAllReasons::NewL |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CFotaCustCmdAllReasons* CFotaCustCmdAllReasons::NewL() |
|
50 { |
|
51 FLOG( _L( "[CFotaCustCmdAllReasons::NewL() BEGIN " ) ); |
|
52 return new ( ELeave ) CFotaCustCmdAllReasons; |
|
53 } |
|
54 |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // CFotaCustCmdAllReasons::~CFotaCustCmdAllReasons |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 CFotaCustCmdAllReasons::~CFotaCustCmdAllReasons() |
|
61 { |
|
62 FLOG( _L( "[CFotaCustCmdAllReasons::~CFotaCustCmdAllReasons() " ) ); |
|
63 } |
|
64 |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // CFotaCustCmdAllReasons::Initialize |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 TInt CFotaCustCmdAllReasons::Initialize( CSsmCustomCommandEnv* /*aCmdEnv*/ ) |
|
71 { |
|
72 FLOG( _L( "[CFotaCustCmdAllReasons::~Initialize() " ) ); |
|
73 |
|
74 |
|
75 return KErrNone; |
|
76 } |
|
77 |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // CFotaCustCmdAllReasons::Execute |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 void CFotaCustCmdAllReasons::Execute( |
|
84 const TDesC8& /*aParams*/, |
|
85 TRequestStatus& aRequest ) |
|
86 { |
|
87 FLOG( _L( "[CFotaCustCmdAllReasons::~Execute() BEGIN " ) ); |
|
88 aRequest = KRequestPending; |
|
89 #ifdef __SYNCML_DM_FOTA |
|
90 TRAP_IGNORE(ExecuteL()); |
|
91 #endif |
|
92 TRequestStatus* request = &aRequest; |
|
93 User::RequestComplete( request, KErrNone ); |
|
94 FLOG( _L( "[CFotaCustCmdAllReasons::~Execute() END " ) ); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // CFotaCustCmdAllReasons::ExecuteL |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void CFotaCustCmdAllReasons::ExecuteL( ) |
|
102 { |
|
103 FLOG( _L( "[CFotaCustCmdAllReasons]::ExecuteL() Boot reason AllReason BEGIN " ) ); |
|
104 |
|
105 RFotaEngineSession fotaEngine; |
|
106 //CheckCenrep if GA feature in ON then start else nothing. |
|
107 CRepository* centrep( NULL); |
|
108 TInt err= KErrNone; |
|
109 TRAP( err, centrep = CRepository::NewL( KCRUidFotaServer ) ); |
|
110 TInt sendGAAfterrebootfeature = 0; |
|
111 TInt val (EFotaDefault); |
|
112 |
|
113 if ( err==KErrNone ) |
|
114 { |
|
115 err = centrep->Get( KFotaUpdateState, val ); |
|
116 |
|
117 if(err == KErrNone) |
|
118 { |
|
119 // check if there is GA pending |
|
120 |
|
121 FTRACE(RDebug::Print(_L("[CFotaCustCmdAllReasons] startup reason is %d"), val)); |
|
122 switch(val) |
|
123 { |
|
124 case EFotaDownloadInterrupted : |
|
125 { |
|
126 FLOG( _L( "[CFotaCustCmdAllReasons] AllReason: Start FMS server " ) ); |
|
127 RFMSClient fmsClient; |
|
128 TRAPD(err, fmsClient.OpenL()); |
|
129 if (err == KErrNone) |
|
130 { |
|
131 fmsClient.Close(); |
|
132 FLOG( _L( "[CFotaCustCmdAllReasons] AllReason: Closing FMS server " ) ); |
|
133 } |
|
134 } |
|
135 break; |
|
136 case EFotaPendingGenAlert : |
|
137 { |
|
138 FLOG( _L( "[CFotaCustCmdAllReasons] AllReason: Start fota server " ) ); |
|
139 err = centrep->Get( KGenericAlertResendAfterBoot, sendGAAfterrebootfeature ); |
|
140 FTRACE(RDebug::Print(_L("[CFotaCustCmdAllReasons] feature sendGenericAlert is %d"), sendGAAfterrebootfeature)); |
|
141 |
|
142 if (sendGAAfterrebootfeature==1) |
|
143 { |
|
144 TRAPD(oError,fotaEngine.OpenL()); |
|
145 if(oError == KErrNone) |
|
146 { |
|
147 fotaEngine.Close(); |
|
148 FLOG( _L( "[CFotaCustCmdAllReasons] AllReason: Closing fota server " ) ); |
|
149 } |
|
150 } |
|
151 } |
|
152 break; |
|
153 case EFotaUpdateInterrupted : |
|
154 { |
|
155 FLOG(_L(" update interrupted >>")); |
|
156 RFMSClient fmsclient; |
|
157 TRAPD(err,fmsclient.OpenL()); |
|
158 if(err) |
|
159 { FLOG(_L( " opening fms failed " ) ); |
|
160 |
|
161 } |
|
162 else |
|
163 { |
|
164 |
|
165 FLOG(_L("CFotaUpdate::going into FMS client side MonitorBatteryL() >>")); |
|
166 TRAPD(err1, fmsclient.MonitorForBatteryL(4)); // equal to EBatteryLevelLevel4 |
|
167 if(err1) |
|
168 { |
|
169 FLOG(_L( " MonitorBatteryL failed " )); |
|
170 } |
|
171 fmsclient.Close(); |
|
172 FLOG(_L(" update interrupted <<")); |
|
173 } |
|
174 } |
|
175 break; |
|
176 default: |
|
177 { |
|
178 FLOG( _L( "[CFotaCustCmdAllReasons] pendingGAToSend is not SET " ) ); |
|
179 } |
|
180 break; |
|
181 } |
|
182 |
|
183 } |
|
184 //Changes for resetting of timer..... |
|
185 TInt timerResetfeature(KErrNone); |
|
186 |
|
187 err = centrep->Get( KFotaReminderTimerReset, timerResetfeature ); |
|
188 if((err == KErrNone) && (timerResetfeature==1)) //if reset timer feature on. |
|
189 { |
|
190 |
|
191 TBool isFotaScheduled =EFalse; |
|
192 TRAPD(error , isFotaScheduled = FindScheduleL()); //check whether FOTA scheduled |
|
193 if(error) |
|
194 { |
|
195 isFotaScheduled = EFalse; |
|
196 |
|
197 } |
|
198 if(isFotaScheduled) |
|
199 { |
|
200 FLOG( _L( "[CFotaCustCmdAllReasons] fota operation is scheduled " ) ); |
|
201 TRAPD(oError,fotaEngine.OpenL()); |
|
202 if(oError) |
|
203 { |
|
204 FLOG( _L( "[CFotaCustCmdAllReasons] error in opening : so Closing fota server " ) ); |
|
205 |
|
206 } |
|
207 else |
|
208 { |
|
209 |
|
210 TFotaScheduledUpdate sched(-1,-1); //trigger the Fota remainder dialog here.. |
|
211 TPckg<TFotaScheduledUpdate> p(sched); |
|
212 TRAPD(err, fotaEngine.ScheduledUpdateL(sched)); |
|
213 if(err) |
|
214 { |
|
215 FLOG( _L( "[CFotaCustCmdAllReasons] FirmwareUpdate scheduling failed " ) ); |
|
216 } |
|
217 fotaEngine.Close(); |
|
218 } |
|
219 |
|
220 } |
|
221 |
|
222 |
|
223 } |
|
224 |
|
225 } |
|
226 delete centrep; |
|
227 { // Write the code for starting the dmEventNotifier |
|
228 TRAPD(err, checkDMEventNotifierL()); |
|
229 if(err) |
|
230 { |
|
231 FLOG(_L("start DmEventNotifier.exe successfull")); |
|
232 } |
|
233 else |
|
234 { |
|
235 FLOG(_L("start DmEventNotifier.exe un-successfull")); |
|
236 } |
|
237 } |
|
238 FLOG( _L( "[CFotaCustCmdAllReasons]::ExecuteL() Boot reason AllReason END " ) ); |
|
239 } |
|
240 |
|
241 // --------------------------------------------------------------------------- |
|
242 // CFotaCustCmdAllReasons::ExecuteCancel |
|
243 // --------------------------------------------------------------------------- |
|
244 // |
|
245 void CFotaCustCmdAllReasons::ExecuteCancel() |
|
246 { |
|
247 |
|
248 } |
|
249 |
|
250 |
|
251 // --------------------------------------------------------------------------- |
|
252 // CFotaCustCmdAllReasons::Close |
|
253 // --------------------------------------------------------------------------- |
|
254 // |
|
255 void CFotaCustCmdAllReasons::Close() |
|
256 { |
|
257 FLOG( _L( "[CFotaCustCmdAllReasons]::Close() " ) ); |
|
258 } |
|
259 |
|
260 |
|
261 // --------------------------------------------------------------------------- |
|
262 // CFotaCustCmdAllReasons::Release |
|
263 // --------------------------------------------------------------------------- |
|
264 // |
|
265 void CFotaCustCmdAllReasons::Release() |
|
266 { |
|
267 |
|
268 FLOG( _L( "[CFotaCustCmdAllReasons]::Close() " ) ); |
|
269 delete this; |
|
270 } |
|
271 |
|
272 |
|
273 TBool CFotaCustCmdAllReasons::FindScheduleL() |
|
274 { |
|
275 FLOG( _L( "[CFotaCustCmdAllReasons]::FindScheduleL()BEGIN " ) ); |
|
276 TScheduleEntryInfo2 ret; |
|
277 RScheduler sc; |
|
278 |
|
279 TTsTime time; |
|
280 TSchedulerItemRef scitem; |
|
281 CArrayFixFlat<TSchedulerItemRef>* aSchRefArray = new CArrayFixFlat <TSchedulerItemRef>(5); |
|
282 TScheduleFilter aFilter(EAllSchedules); |
|
283 User::LeaveIfError( sc.Connect() ); // xx |
|
284 CleanupClosePushL( sc ); |
|
285 CleanupStack::PushL(aSchRefArray); |
|
286 |
|
287 User::LeaveIfError( sc.GetScheduleRefsL( *aSchRefArray,aFilter) ); // xx |
|
288 FLOG(_L("Schedule items: ")); |
|
289 for ( TInt i=0; i<aSchRefArray->Count(); ++i ) |
|
290 { |
|
291 TSchedulerItemRef it = (*aSchRefArray)[i]; |
|
292 if ( it.iName == TUid::Uid(KFotaServerUid).Name() ) |
|
293 { |
|
294 |
|
295 CleanupStack::PopAndDestroy(aSchRefArray); |
|
296 CleanupStack::PopAndDestroy(&sc); |
|
297 return ETrue; |
|
298 |
|
299 } |
|
300 } |
|
301 CleanupStack::PopAndDestroy(aSchRefArray); |
|
302 CleanupStack::PopAndDestroy(&sc); |
|
303 FLOG( _L( "[CFotaCustCmdAllReasons]::FindScheduleL()END " ) ); |
|
304 return EFalse; |
|
305 } |
|
306 |
|
307 |
|
308 void CFotaCustCmdAllReasons::checkDMEventNotifierL() |
|
309 { |
|
310 FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - started")); |
|
311 |
|
312 const TUid KAppDmEventNotifierUid = TUid::Uid(KAppUidDmEventNotifier); //UID3 from .mmp file |
|
313 CRepository* cenrep (NULL); |
|
314 cenrep = CRepository::NewLC( KAppDmEventNotifierUid ); |
|
315 TInt value (KErrNone); |
|
316 TBool tocontinue (EFalse); |
|
317 |
|
318 FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - checking for cenrep KDmEventNotifierEnabled")); |
|
319 if ( ((cenrep->Get(KDmEventNotifierEnabled,value)) == KErrNone ) |
|
320 && (EHandlerRegistered == value || EHandlerNeedRegister == value )) // v alue != EHandlerNotRegistered |
|
321 { |
|
322 // FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - cenrep KDmEventNotifierEnabled exist, value = (%d) "), value); |
|
323 FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - cenrep KDmEventNotifierEnabled exist")); |
|
324 tocontinue = ETrue; |
|
325 } |
|
326 else |
|
327 { |
|
328 //Log errors |
|
329 // FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - checking for cenrep KDmEventNotifierEnabled does not exist: error: (%d) "), err); |
|
330 FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - cenrep KDmEventNotifierEnabled does not exist or already registered")); |
|
331 //delete cenrep; cenrep = NULL; |
|
332 CleanupStack::PopAndDestroy(); // cenrep |
|
333 return; |
|
334 } |
|
335 |
|
336 TInt pMmcstatus = KErrNotFound; |
|
337 TInt ret = RProperty::Get(KPSUidUikon, KUikMMCInserted, pMmcstatus); |
|
338 // FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - checking for present Memory status: ret = (%d) , MMCStatus = (%d) "), ret, pMmcStatus); |
|
339 FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - checking for memory status")); |
|
340 if(!ret) |
|
341 { |
|
342 |
|
343 TInt sMMCStatus (KErrNotFound); |
|
344 TInt error = cenrep->Get(KMMCStatus, sMMCStatus); |
|
345 CleanupStack::PopAndDestroy(); // cenrep |
|
346 |
|
347 //FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - checking for previous Memory status, before phone off: error = (%d) , sMMCStatus = (%d) "), error, sMMCStatus); |
|
348 if(error) |
|
349 { |
|
350 FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - Error in memory status get")); |
|
351 //CleanupStack::PopAndDestroy(); // cenrep |
|
352 return; |
|
353 } |
|
354 if (pMmcstatus == sMMCStatus && tocontinue) // if sMMCStatus is 0 && pMMCStatus is 0. Or sMMCStatus is 1 && pMMCStatus is 1 |
|
355 { |
|
356 //start the dm event notifier |
|
357 |
|
358 RApaLsSession apaLsSession; |
|
359 User :: LeaveIfError(apaLsSession.Connect()); |
|
360 TApaAppInfo appInfo; |
|
361 FLOG(_L("RApaLsSession connection successful")); |
|
362 FLOG(_L("Running dmeventnotifier.exe")); |
|
363 |
|
364 _LIT(KExampleTaskHandlerExe, "dmeventnotifier.exe"); |
|
365 |
|
366 appInfo.iFullName = KExampleTaskHandlerExe; |
|
367 CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); |
|
368 cmdLine->SetExecutableNameL( appInfo.iFullName ); |
|
369 TBuf<KMaxFileName> temp; |
|
370 temp.Copy (appInfo.iFullName); |
|
371 TInt err = apaLsSession.StartApp(*cmdLine); |
|
372 |
|
373 User :: LeaveIfError(err); |
|
374 CleanupStack :: PopAndDestroy(cmdLine); |
|
375 apaLsSession.Close(); |
|
376 FLOG(_L("started dmeventnotifier.exe successfully")); |
|
377 } |
|
378 } |
|
379 //CleanupStack::PopAndDestroy(); // cenrep |
|
380 FLOG(_L("CFotaCustCmdAllReasons::checkDMEventNotifier() - ended")); |
|
381 } |
|