51
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2006 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: starts update sequence
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// INCLUDE FILES
|
73
|
19 |
|
51
|
20 |
#include <centralrepository.h>
|
|
21 |
#include <AknUtils.h>
|
|
22 |
#include <AknBidiTextUtils.h>
|
|
23 |
#include <biditext.h>
|
|
24 |
#include <gdi.h>
|
|
25 |
#include <fotaengine.h>
|
|
26 |
#include <apgtask.h>
|
|
27 |
#include <schtime.h>
|
|
28 |
#include <csch_cli.h>
|
|
29 |
#include <fotaengine.h>
|
|
30 |
#include <XQConversions>
|
|
31 |
#include "fotaupdate.h"
|
|
32 |
#include "fmsclient.h"
|
|
33 |
#include "FotasrvSession.h"
|
|
34 |
#include "fotaserverPrivateCRKeys.h"
|
|
35 |
#include "fotaserverPrivatePSKeys.h"
|
|
36 |
#include "fotanotifiers.h"
|
|
37 |
|
|
38 |
#include <usbman.h>
|
|
39 |
#include <usbstates.h>
|
|
40 |
// ============================= MEMBER FUNCTIONS ============================
|
|
41 |
|
|
42 |
|
|
43 |
// ---------------------------------------------------------------------------
|
|
44 |
// CFotaUpdate::CFotaUpdate()
|
|
45 |
// ---------------------------------------------------------------------------
|
|
46 |
//
|
|
47 |
CFotaUpdate::CFotaUpdate() :
|
|
48 |
CActive(EPriorityNormal)
|
|
49 |
{
|
|
50 |
CActiveScheduler::Add(this);
|
|
51 |
}
|
|
52 |
|
|
53 |
// ---------------------------------------------------------------------------
|
|
54 |
// CFotaUpdate::~CFotaUpdate()
|
|
55 |
// ---------------------------------------------------------------------------
|
|
56 |
//
|
|
57 |
CFotaUpdate::~CFotaUpdate()
|
|
58 |
{
|
|
59 |
FLOG(_L("CFotaUpdate::~CFotaUpdate >>"));
|
|
60 |
iFotaServer = NULL;
|
|
61 |
|
|
62 |
CancelMonitor();
|
|
63 |
|
|
64 |
if (iProperty.Handle())
|
|
65 |
iProperty.Close();
|
73
|
66 |
|
|
67 |
if(iNotifier)
|
|
68 |
{
|
|
69 |
delete iNotifier;
|
|
70 |
iNotifier = NULL;
|
|
71 |
}
|
|
72 |
if(iNotifParams)
|
|
73 |
{
|
|
74 |
delete iNotifParams;
|
|
75 |
iNotifParams = NULL;
|
|
76 |
}
|
51
|
77 |
|
|
78 |
FLOG(_L("CFotaUpdate::~CFotaUpdate <<"));
|
|
79 |
}
|
|
80 |
|
|
81 |
// ---------------------------------------------------------------------------
|
|
82 |
// CFotaUpdate::NewL
|
|
83 |
// ---------------------------------------------------------------------------
|
|
84 |
//
|
|
85 |
CFotaUpdate* CFotaUpdate::NewL(CFotaServer* aServer)
|
|
86 |
{
|
|
87 |
CFotaUpdate* ao = new (ELeave) CFotaUpdate();
|
73
|
88 |
CleanupStack::PushL( ao );
|
|
89 |
ao->ConstructL();
|
51
|
90 |
ao->iFotaServer = aServer;
|
73
|
91 |
CleanupStack::Pop(ao);
|
51
|
92 |
return ao;
|
|
93 |
}
|
|
94 |
|
|
95 |
// ---------------------------------------------------------------------------
|
73
|
96 |
// CFotaUpdate::ConstructL
|
|
97 |
// ---------------------------------------------------------------------------
|
|
98 |
//
|
|
99 |
|
|
100 |
void CFotaUpdate::ConstructL()
|
|
101 |
{
|
|
102 |
iNotifier = CFotaDownloadNotifHandler::NewL(this);
|
|
103 |
}
|
|
104 |
|
|
105 |
// ---------------------------------------------------------------------------
|
51
|
106 |
// CFotaUpdate::CheckUpdateResults
|
|
107 |
// Checks if there is update result file available (meaning that update just
|
|
108 |
// took place)
|
|
109 |
// ---------------------------------------------------------------------------
|
|
110 |
//
|
|
111 |
TBool CFotaUpdate::CheckUpdateResults(RFs& aRfs)
|
|
112 |
{
|
|
113 |
RFile f;
|
|
114 |
TInt err;
|
|
115 |
err = f.Open(aRfs, KUpdateResultFile, EFileShareAny);
|
|
116 |
f.Close();
|
|
117 |
if (err != KErrNone)
|
|
118 |
{
|
|
119 |
return EFalse;
|
|
120 |
}
|
|
121 |
FLOG(_L(" CFotaUpdate::CheckUpdateResults update result file Found! "));
|
|
122 |
return ETrue;
|
|
123 |
}
|
|
124 |
|
|
125 |
// ---------------------------------------------------------------------------
|
|
126 |
// CFotaUpdate::ExecuteUpdateResultFileL
|
|
127 |
// Read result code from update result file and update state accordingly.
|
|
128 |
// Show notifier "Update succesful". Do some cleanup.
|
|
129 |
// ---------------------------------------------------------------------------
|
|
130 |
//
|
|
131 |
void CFotaUpdate::ExecuteUpdateResultFileL()
|
|
132 |
{
|
|
133 |
FLOG(_L("CFotaUpdate::ExecuteUpdateResultFileL >>"));
|
|
134 |
|
|
135 |
TInt err;
|
|
136 |
RFileReadStream rstr;
|
|
137 |
TInt result;
|
|
138 |
TInt msglen;
|
|
139 |
HBufC8* message = NULL;
|
|
140 |
HBufC16* message16 = NULL;
|
|
141 |
TBool deleteData(EFalse);
|
|
142 |
|
|
143 |
// Open update result file
|
|
144 |
FLOG(_L("opening rstr 1/2 "));
|
|
145 |
err = rstr.Open(iFotaServer->iFs, KUpdateResultFile, EFileRead
|
|
146 |
| EFileStream);
|
|
147 |
FLOG(_L("opened rstr 2/2 "));
|
|
148 |
if (err)
|
55
|
149 |
{
|
51
|
150 |
FLOG(_L(" update result file open err %d"), err);
|
55
|
151 |
}
|
51
|
152 |
User::LeaveIfError(err);
|
|
153 |
FLOG(_L(" 0.1"));
|
|
154 |
CleanupClosePushL(rstr);
|
|
155 |
FLOG(_L(" 0.2"));
|
|
156 |
|
|
157 |
// Read resultcode
|
|
158 |
result = rstr.ReadUint32L();
|
|
159 |
msglen = rstr.ReadUint32L();
|
|
160 |
if (msglen != 0)
|
|
161 |
{
|
|
162 |
message = HBufC8::NewLC(msglen + 1);
|
|
163 |
TPtr8 ptrdesc = message->Des();
|
|
164 |
TRAPD ( err2, rstr.ReadL(ptrdesc) );
|
|
165 |
if (err2 != KErrNone && err2 != KErrEof)
|
|
166 |
{
|
|
167 |
FLOG(_L(" file read err %d"), err2);
|
|
168 |
User::Leave(err2);
|
|
169 |
}
|
|
170 |
|
|
171 |
message16 = HBufC16::NewLC(message->Des().Length());
|
|
172 |
message16->Des().Copy(*message);
|
|
173 |
FLOG(_L(" 1 update result: %d"), result);
|
|
174 |
FLOG(_L(" 2 dbg msg: %S"), message16);
|
|
175 |
CleanupStack::PopAndDestroy(message16);
|
|
176 |
CleanupStack::PopAndDestroy(message);
|
|
177 |
}
|
|
178 |
|
|
179 |
FLOG(_L(" 0.6 "));
|
|
180 |
CleanupStack::PopAndDestroy(&rstr);
|
|
181 |
|
|
182 |
// Map resultcode to FUMO result code
|
|
183 |
RFotaEngineSession::TState fstate = RFotaEngineSession::EUpdateFailed;
|
|
184 |
RFotaEngineSession::TResult fresult =
|
|
185 |
RFotaEngineSession::EResUpdateFailed;
|
|
186 |
|
|
187 |
FLOG(_L(" 3"));
|
|
188 |
switch (result)
|
|
189 |
{
|
|
190 |
case UPD_OK:
|
|
191 |
{
|
|
192 |
fstate = RFotaEngineSession::EUpdateSuccessfulNoData;
|
|
193 |
fresult = RFotaEngineSession::EResSuccessful;
|
|
194 |
deleteData = ETrue;
|
|
195 |
ShowDialogL(EFwUpdSuccess);
|
|
196 |
}
|
|
197 |
break;
|
|
198 |
case UPD_INSTALL_REQUEST_IS_INVALID:
|
|
199 |
{
|
|
200 |
fstate = RFotaEngineSession::EUpdateFailedNoData;
|
|
201 |
fresult = RFotaEngineSession::EResUpdateFailed;
|
|
202 |
deleteData = ETrue;
|
|
203 |
ShowDialogL(EFwUpdNotCompatible);
|
|
204 |
}
|
|
205 |
break;
|
|
206 |
case UPD_UPDATE_PACKAGE_IS_ABSENT:
|
|
207 |
{
|
|
208 |
fstate = RFotaEngineSession::EUpdateFailedNoData;
|
|
209 |
fresult = RFotaEngineSession::EResUpdateFailed;
|
|
210 |
ShowDialogL(EFwUpdNotCompatible);
|
|
211 |
}
|
|
212 |
break;
|
|
213 |
case UPD_UPDATE_PACKAGE_IS_CORRUPTED:
|
|
214 |
{
|
|
215 |
fstate = RFotaEngineSession::EUpdateFailedNoData;
|
|
216 |
fresult = RFotaEngineSession::EResCorruptedFWUPD;
|
|
217 |
deleteData = ETrue;
|
|
218 |
ShowDialogL(EFwUpdNotCompatible);
|
|
219 |
}
|
|
220 |
break;
|
|
221 |
case UPD_UPDATE_PACKAGE_CONTENTS_IS_INVALID:
|
|
222 |
{
|
|
223 |
fstate = RFotaEngineSession::EUpdateFailedNoData;
|
|
224 |
fresult = RFotaEngineSession::EResCorruptedFWUPD;
|
|
225 |
deleteData = ETrue;
|
|
226 |
ShowDialogL(EFwUpdNotCompatible);
|
|
227 |
}
|
|
228 |
break;
|
|
229 |
case UPD_UPDATE_PACKAGE_IS_NOT_COMPATIBLE_WITH_CURRENT_MOBILE_DEVICE:
|
|
230 |
{
|
|
231 |
fstate = RFotaEngineSession::EUpdateFailedNoData;
|
|
232 |
fresult = RFotaEngineSession::EResPackageMismatch;
|
|
233 |
deleteData = ETrue;
|
|
234 |
ShowDialogL(EFwUpdNotCompatible);
|
|
235 |
}
|
|
236 |
break;
|
|
237 |
case UPD_FATAL_ERROR:
|
|
238 |
{
|
|
239 |
fstate = RFotaEngineSession::EUpdateFailedNoData;
|
|
240 |
fresult = RFotaEngineSession::EResUpdateFailed;
|
|
241 |
deleteData = ETrue;
|
|
242 |
ShowDialogL(EFwUpdNotCompatible);
|
|
243 |
}
|
|
244 |
break;
|
|
245 |
|
|
246 |
default:
|
|
247 |
{
|
|
248 |
FLOG(_L(" 3.1 invalid result: %d"), result);
|
|
249 |
fstate = RFotaEngineSession::EUpdateFailedNoData;
|
|
250 |
fresult = RFotaEngineSession::EResUpdateFailed;
|
|
251 |
deleteData = ETrue;
|
|
252 |
ShowDialogL(EFwUpdNotCompatible);
|
|
253 |
}
|
|
254 |
break;
|
|
255 |
}
|
|
256 |
|
|
257 |
// Find the state 60 (update progressing) -> 100 (etc)
|
|
258 |
RArray<TInt> states;
|
|
259 |
TPackageState state;
|
|
260 |
CleanupClosePushL(states);
|
|
261 |
iFotaServer->iDatabase->OpenDBL();
|
|
262 |
iFotaServer->iDatabase->GetAllL(states);
|
|
263 |
|
|
264 |
FLOG(_L(" 4.1 found %d states "), states.Count());
|
|
265 |
for (TInt i = 0; i < states.Count(); ++i)
|
|
266 |
{
|
|
267 |
TPackageState tmp;
|
|
268 |
TBuf8<KMaxFileName> tmpurl;
|
|
269 |
tmp = iFotaServer->iDatabase->GetStateL(states[i], tmpurl);
|
|
270 |
FLOG(_L(" 5 got state "));
|
|
271 |
if (tmp.iState == RFotaEngineSession::EUpdateProgressing)
|
|
272 |
{
|
|
273 |
state = tmp;
|
|
274 |
state.iState = fstate;
|
|
275 |
state.iResult = fresult;
|
|
276 |
FLOG(_L(" 6 Updating state id %d to %d ,result %d "),
|
|
277 |
state.iPkgId, state.iState, state.iResult);
|
|
278 |
iFotaServer->iDatabase->SetStateL(state, KNullDesC8, EFDBState
|
|
279 |
| EFDBResult);
|
|
280 |
}
|
|
281 |
}
|
|
282 |
iFotaServer->iDatabase->CloseAndCommitDB();
|
|
283 |
CleanupStack::PopAndDestroy(&states);
|
|
284 |
|
|
285 |
// Delete request file
|
|
286 |
err = BaflUtils::DeleteFile(iFotaServer->iFs, KUpdateRequestFile);
|
|
287 |
if (err != KErrNone && err != KErrNotFound)
|
|
288 |
{
|
|
289 |
FLOG(_L(" 6.1 req file deleted, err %d"), err);
|
|
290 |
User::Leave(err);
|
|
291 |
}
|
|
292 |
|
|
293 |
// Write timestamp (shown to user in device management ui)
|
|
294 |
if (fresult == RFotaEngineSession::EResSuccessful)
|
|
295 |
{
|
|
296 |
RFileWriteStream wstr;
|
|
297 |
TTime time;
|
|
298 |
User::LeaveIfError(wstr.Replace(iFotaServer->iFs,
|
|
299 |
KUpdateTimeStampFileName, EFileWrite));
|
|
300 |
CleanupClosePushL(wstr);
|
|
301 |
time.HomeTime();
|
|
302 |
TInt year = time.DateTime().Year();
|
|
303 |
TInt month = time.DateTime().Month();
|
|
304 |
TInt day = time.DateTime().Day();
|
|
305 |
TInt hour = time.DateTime().Hour();
|
|
306 |
TInt minute = time.DateTime().Minute();
|
|
307 |
wstr.WriteInt32L(year);
|
|
308 |
wstr.WriteInt32L(month);
|
|
309 |
wstr.WriteInt32L(day);
|
|
310 |
wstr.WriteInt32L(hour);
|
|
311 |
wstr.WriteInt32L(minute);
|
|
312 |
CleanupStack::PopAndDestroy(1); // wstr
|
|
313 |
}
|
|
314 |
// Delete package content
|
|
315 |
if (deleteData && state.iPkgId > KErrNotFound)
|
|
316 |
{
|
|
317 |
iFotaServer->DeletePackageL(state.iPkgId);
|
|
318 |
DeleteUpdateResultFileL();
|
|
319 |
}
|
|
320 |
|
|
321 |
// Report state back to syncml server
|
|
322 |
if (state.iPkgId >= 0)
|
|
323 |
{
|
|
324 |
FLOG(_L(" 6.1 creating device mgmt session for profile %d"),
|
|
325 |
state.iProfileId);
|
|
326 |
iFotaServer->ReportFwUpdateStatusL(state);
|
|
327 |
}
|
|
328 |
else
|
|
329 |
{
|
|
330 |
FLOG(_L(" No state found in 'update progress' mode! cannot report status to DM server "));
|
|
331 |
}
|
|
332 |
|
|
333 |
FLOG(_L("CFotaUpdate::ExecuteUpdateResultFileL <<"));
|
|
334 |
}
|
|
335 |
|
|
336 |
// ---------------------------------------------------------------------------
|
|
337 |
// CFotaUpdate::DeleteUpdateResultsL
|
|
338 |
// ---------------------------------------------------------------------------
|
|
339 |
//
|
|
340 |
void CFotaUpdate::DeleteUpdateResultFileL()
|
|
341 |
{
|
|
342 |
FLOG(_L("CFotaUpdate::DeleteUpdateResultsL >>"));
|
|
343 |
// Delete result file
|
|
344 |
RFs fs;
|
|
345 |
__LEAVE_IF_ERROR(fs.Connect());
|
|
346 |
BaflUtils::DeleteFile(fs, KUpdateResultFile);
|
|
347 |
BaflUtils::DeleteFile(fs, KUpdateRequestFile);
|
|
348 |
BaflUtils::DeleteFile(fs, KUpdateBitmap);
|
|
349 |
BaflUtils::DeleteFile(fs, KRestartingBitmap);
|
|
350 |
fs.Close();
|
|
351 |
FLOG(_L("CFotaUpdate::DeleteUpdateResultsL <<"));
|
|
352 |
}
|
|
353 |
|
|
354 |
// ---------------------------------------------------------------------------
|
|
355 |
// CFotaUpdate::UpdateL
|
|
356 |
// Updates the fw: Creates input files for update agent and boots device to
|
|
357 |
// update mode.
|
|
358 |
// ---------------------------------------------------------------------------
|
|
359 |
void CFotaUpdate::UpdateL()
|
|
360 |
{
|
|
361 |
FLOG(_L("CFotaUpdate::UpdateL() >>"));
|
|
362 |
// Set state ........................................
|
|
363 |
iFotaServer->iPackageState.iState
|
|
364 |
= RFotaEngineSession::EUpdateProgressing;
|
|
365 |
iFotaServer->iDatabase->OpenDBL();
|
|
366 |
iFotaServer->iDatabase->SetStateL(iFotaServer->iPackageState, KNullDesC8,
|
|
367 |
EFDBState);
|
|
368 |
iFotaServer->iDatabase->CloseAndCommitDB();
|
|
369 |
|
|
370 |
// Write update request for update agent..............
|
|
371 |
FLOG(_L("CFotaUpdate::UpdateL 1 writing update.req "));
|
|
372 |
TBuf16<KMaxFileName> dp2filepath;
|
|
373 |
HBufC16* dp2;
|
|
374 |
RFileWriteStream wstr;
|
|
375 |
CleanupClosePushL(wstr);
|
|
376 |
FLOG(_L("CFotaUpdate::UpdateL 2 getting pkg location"));
|
|
377 |
iFotaServer->DownloaderL()->GetUpdatePackageLocation(dp2filepath);
|
|
378 |
|
|
379 |
FLOG(_L("CFotaUpdate::UpdateL 3 craeting update.req"));
|
|
380 |
User::LeaveIfError(wstr.Replace(iFotaServer->iFs, KUpdateRequestFile,
|
|
381 |
EFileWrite));
|
|
382 |
wstr.WriteInt16L(1); // version number is 1
|
|
383 |
wstr.WriteInt32L(1); // count of cmds is 1
|
|
384 |
wstr.WriteInt16L(0); // requestid is 0
|
|
385 |
|
|
386 |
dp2 = HBufC16::NewLC(dp2filepath.Length());
|
|
387 |
dp2->Des().Copy(dp2filepath);
|
|
388 |
wstr.WriteInt32L(dp2->Des().Length() + 1); // length of filename + null
|
|
389 |
wstr.WriteL(dp2->Des());
|
|
390 |
wstr.WriteInt16L(0); // null character
|
|
391 |
CleanupStack::PopAndDestroy(dp2);
|
|
392 |
CleanupStack::PopAndDestroy(&wstr); // wstr
|
|
393 |
|
|
394 |
FLOG(_L("CFotaUpdate::UpdateL 4 craeting update.bmp"));
|
|
395 |
|
|
396 |
|
|
397 |
// Write update graphic for update agent ...............
|
|
398 |
HBufC* updatetxt;
|
|
399 |
HBufC* restarttxt;
|
|
400 |
QString installstr = hbTrId("txt_device_update_info_installing");
|
|
401 |
QString rebootstr = hbTrId("txt_device_update_info_rebooting");
|
|
402 |
updatetxt = XQConversions::qStringToS60Desc(installstr);
|
|
403 |
restarttxt = XQConversions::qStringToS60Desc(rebootstr);
|
|
404 |
|
|
405 |
WriteUpdateBitmapL( updatetxt->Des(), KUpdateBitmap );
|
|
406 |
WriteUpdateBitmapL( restarttxt->Des(), KRestartingBitmap );
|
|
407 |
delete updatetxt;
|
|
408 |
delete restarttxt;
|
|
409 |
|
|
410 |
// Simulate update agent by writing result file.
|
|
411 |
CRepository* centrep(NULL);
|
|
412 |
TInt err = KErrNone;
|
|
413 |
TRAP(err, centrep = CRepository::NewL( KCRUidFotaServer ) );
|
|
414 |
TInt simulate(KErrNotFound);
|
|
415 |
if (centrep)
|
|
416 |
{
|
|
417 |
err = centrep->Get(KSimulateUpdateAgent, simulate);
|
|
418 |
}
|
|
419 |
delete centrep;
|
|
420 |
if (simulate > 0)
|
|
421 |
{
|
|
422 |
FLOG(_L("CFotaUpdate::UpdateL 5 - writing update.resp"));
|
|
423 |
RFileWriteStream respstr;
|
|
424 |
CleanupClosePushL(respstr);
|
|
425 |
User::LeaveIfError(respstr.Replace(iFotaServer->iFs,
|
|
426 |
KUpdateResultFile, EFileWrite));
|
|
427 |
|
|
428 |
respstr.WriteUint32L(UPD_OK);
|
|
429 |
respstr.WriteUint32L(15);
|
|
430 |
respstr.WriteL(_L("UPDATE DONE!"));
|
|
431 |
CleanupStack::PopAndDestroy(&respstr);
|
|
432 |
}
|
|
433 |
|
|
434 |
iFotaServer->SetStartupReason(EFotaDefault);
|
|
435 |
|
|
436 |
RStarterSession starter;
|
|
437 |
FLOG(_L(" starter->Connect"));
|
|
438 |
User::LeaveIfError(starter.Connect());
|
|
439 |
starter.Reset(RStarterSession::EFirmwareUpdate);
|
|
440 |
starter.Close();
|
|
441 |
FLOG(_L("CFotaUpdate::UpdateL() <<"));
|
|
442 |
}
|
|
443 |
|
|
444 |
// ---------------------------------------------------------------------------
|
|
445 |
// CFotaUpdate::CheckBatteryL()
|
|
446 |
// Cheks if there's enough battery power to update
|
|
447 |
// ---------------------------------------------------------------------------
|
|
448 |
//
|
|
449 |
TBool CFotaUpdate::CheckBatteryL()
|
|
450 |
{
|
|
451 |
FLOG(_L("CFotaUpdate::CheckBatteryL >>"));
|
|
452 |
|
|
453 |
TInt chargingstatus(EChargingStatusError);
|
|
454 |
TInt batterylevel(EBatteryLevelUnknown);
|
|
455 |
TBool enoughPower(EFalse);
|
|
456 |
|
|
457 |
// Read battery level
|
|
458 |
|
|
459 |
RProperty pw;
|
|
460 |
User::LeaveIfError(pw.Attach(KPSUidHWRMPowerState, KHWRMBatteryLevel));
|
|
461 |
User::LeaveIfError(pw.Get(batterylevel));
|
|
462 |
|
|
463 |
if (batterylevel >= BatteryLevelAccepted)
|
|
464 |
{
|
|
465 |
FLOG(_L("Battery charge is above acceptable level!"));
|
|
466 |
enoughPower = ETrue;
|
|
467 |
}
|
|
468 |
else
|
|
469 |
{
|
|
470 |
|
|
471 |
//Read charger status
|
|
472 |
User::LeaveIfError(pw.Attach(KPSUidHWRMPowerState,
|
|
473 |
KHWRMChargingStatus));
|
|
474 |
User::LeaveIfError(pw.Get(chargingstatus));
|
|
475 |
pw.Close();
|
|
476 |
|
|
477 |
// But charger is connected, power sufficient
|
|
478 |
if (chargingstatus == EChargingStatusCharging || chargingstatus
|
|
479 |
== EChargingStatusAlmostComplete || chargingstatus
|
|
480 |
== EChargingStatusChargingComplete || chargingstatus
|
|
481 |
== EChargingStatusChargingContinued)
|
|
482 |
{
|
|
483 |
FLOG(
|
|
484 |
_L("Battery charge is below acceptable level, but charger is connected!"));
|
|
485 |
enoughPower = ETrue;
|
|
486 |
}
|
|
487 |
}
|
|
488 |
|
|
489 |
FLOG(_L("CFotaUpdate::CheckBattery, current charge = %d, ret = %d <<"),
|
|
490 |
batterylevel, enoughPower);
|
|
491 |
return enoughPower;
|
|
492 |
}
|
|
493 |
|
|
494 |
void CFotaUpdate::MonitorBatteryChargeLevel()
|
|
495 |
{
|
|
496 |
FLOG(_L("CFotaUpdate::MonitorBatteryChargeLevel >>"));
|
|
497 |
|
|
498 |
CancelMonitor();
|
|
499 |
|
|
500 |
iProperty.Attach(KPSUidHWRMPowerState, KHWRMBatteryLevel);
|
|
501 |
TInt value = 0;
|
|
502 |
|
|
503 |
iProperty.Get(KPSUidHWRMPowerState, KHWRMBatteryLevel, value);
|
|
504 |
|
|
505 |
FLOG(_L("Battery level at this time is %d, err = %d"), value);
|
|
506 |
iStatus = KRequestPending;
|
|
507 |
iProperty.Subscribe(iStatus);
|
|
508 |
|
|
509 |
iMonitorType = BatteryLevel;
|
|
510 |
SetActive();
|
|
511 |
|
|
512 |
FLOG(_L("CFotaUpdate::MonitorBatteryChargeLevel <<"));
|
|
513 |
}
|
|
514 |
|
|
515 |
void CFotaUpdate::MonitorBatteryChargingStatus()
|
|
516 |
{
|
|
517 |
FLOG(_L("CFotaUpdate::MonitorBatteryChargingStatus >>"));
|
|
518 |
|
|
519 |
CancelMonitor();
|
|
520 |
|
|
521 |
iProperty.Attach(KPSUidHWRMPowerState, KHWRMChargingStatus);
|
|
522 |
TInt value = 0;
|
|
523 |
|
|
524 |
iProperty.Get(KPSUidHWRMPowerState, KHWRMChargingStatus, value);
|
|
525 |
|
|
526 |
FLOG(_L("Charging status at this time is %d, err = %d"), value);
|
|
527 |
iStatus = KRequestPending;
|
|
528 |
iProperty.Subscribe(iStatus);
|
|
529 |
|
|
530 |
iMonitorType = ChargingStatus;
|
|
531 |
SetActive();
|
|
532 |
|
|
533 |
FLOG(_L("CFotaUpdate::MonitorBatteryChargingStatus <<"));
|
|
534 |
}
|
|
535 |
|
|
536 |
void CFotaUpdate::CancelMonitor()
|
|
537 |
{
|
|
538 |
FLOG(_L("CFotaUpdate::CancelMonitor >>"));
|
|
539 |
if (IsActive())
|
|
540 |
{
|
|
541 |
FLOG(_L("Cancelling...."));
|
|
542 |
Cancel();
|
|
543 |
}
|
|
544 |
FLOG(_L("CFotaUpdate::CancelMonitor <<"));
|
|
545 |
}
|
|
546 |
|
|
547 |
TBool CFotaUpdate::IsUSBConnected()
|
|
548 |
{
|
|
549 |
FLOG(_L("CFotaUpdate::IsUSBConnected >>"));
|
|
550 |
|
|
551 |
TBool ret (EFalse);
|
|
552 |
TUsbDeviceState state(EUsbDeviceStateUndefined);
|
|
553 |
RUsb usbman;
|
|
554 |
TInt err = usbman.Connect();
|
|
555 |
if (err == KErrNone)
|
|
556 |
{
|
|
557 |
usbman.GetDeviceState(state);
|
|
558 |
usbman.Close();
|
|
559 |
}
|
|
560 |
if (state != EUsbDeviceStateUndefined)
|
55
|
561 |
{
|
51
|
562 |
ret = ETrue;
|
55
|
563 |
}
|
51
|
564 |
|
|
565 |
FLOG(_L("CFotaUpdate::IsUSBConnected, value = %d, ret = %d <<"), state, ret);
|
|
566 |
return ret;
|
|
567 |
}
|
|
568 |
|
|
569 |
void CFotaUpdate::RunL()
|
|
570 |
{
|
|
571 |
FLOG(_L("CFotaUpdate::RunL >>"));
|
|
572 |
|
|
573 |
if (iStatus.Int() == KErrNone)
|
|
574 |
{
|
|
575 |
TInt value = 0;
|
|
576 |
|
|
577 |
if (iMonitorType == BatteryLevel)
|
|
578 |
{
|
|
579 |
iProperty.Get(KPSUidHWRMPowerState, KHWRMBatteryLevel,
|
|
580 |
value);
|
|
581 |
|
|
582 |
FLOG(_L("Battery level has changed to %d"), value);
|
|
583 |
|
|
584 |
iFotaServer->UpdateBatteryLowInfo(
|
|
585 |
(value >= BatteryLevelAccepted) ? EFalse : ETrue);
|
|
586 |
|
|
587 |
MonitorBatteryChargeLevel();
|
|
588 |
}
|
|
589 |
else if (iMonitorType == ChargingStatus)
|
|
590 |
{
|
|
591 |
iProperty.Get(KPSUidHWRMPowerState, KHWRMChargingStatus,
|
|
592 |
value);
|
|
593 |
|
|
594 |
FLOG(_L("Charging status has changed to %d"), value);
|
|
595 |
|
|
596 |
if (value == EChargingStatusCharging || value
|
|
597 |
== EChargingStatusAlmostComplete || value
|
|
598 |
== EChargingStatusChargingComplete || value
|
|
599 |
== EChargingStatusChargingContinued)
|
|
600 |
{
|
|
601 |
if (IsUSBConnected())
|
|
602 |
{
|
|
603 |
ShowDialogL(EFwUpdNotEnoughBattery);
|
|
604 |
}
|
|
605 |
else
|
|
606 |
{
|
|
607 |
iFotaServer->UpdateBatteryLowInfo(EFalse);
|
|
608 |
}
|
|
609 |
}
|
|
610 |
else
|
|
611 |
{
|
|
612 |
iFotaServer->UpdateBatteryLowInfo(ETrue);
|
|
613 |
}
|
|
614 |
}
|
|
615 |
|
|
616 |
}
|
|
617 |
FLOG(_L("CFotaUpdate::RunL, iStatus = %d <<"), iStatus.Int());
|
|
618 |
}
|
|
619 |
|
|
620 |
// ---------------------------------------------------------------------------
|
|
621 |
// CFotaUpdate::StartUpdateL
|
|
622 |
// Starts fw updating (shows a notifier to user).
|
|
623 |
// ---------------------------------------------------------------------------
|
|
624 |
//
|
|
625 |
void CFotaUpdate::StartUpdateL(const TDownloadIPCParams &aParams)
|
|
626 |
{
|
|
627 |
FLOG(_L("CFotaUpdate::StartUpdateL, pkig:%d >>"), aParams.iPkgId);
|
|
628 |
|
|
629 |
//First cancel any ongoing battery monitoring.
|
|
630 |
CancelMonitor();
|
|
631 |
|
|
632 |
UpdateL();
|
|
633 |
|
|
634 |
FLOG(_L("CFotaUpdate::StartUpdateL <<"));
|
|
635 |
}
|
|
636 |
|
|
637 |
TInt CFotaUpdate::RunError(TInt aError)
|
|
638 |
{
|
|
639 |
FLOG(_L("CFotaUpdate::RunError, error = %d >>"), aError);
|
|
640 |
return aError;
|
|
641 |
}
|
|
642 |
|
|
643 |
void CFotaUpdate::DoCancel()
|
|
644 |
{
|
|
645 |
FLOG(_L("CFotaUpdate::DoCancel >>"));
|
|
646 |
|
|
647 |
iProperty.Cancel();
|
|
648 |
|
|
649 |
FLOG(_L("CFotaUpdate::DoCancel <<"));
|
|
650 |
}
|
|
651 |
|
|
652 |
void CFotaUpdate::ShowDialogL(TFwUpdNoteTypes aDialogid)
|
|
653 |
{
|
|
654 |
FLOG(_L("CFotaUpdate::ShowDialogL, dialogid = %d >>"), aDialogid);
|
|
655 |
iFotaServer->ServerCanShut(EFalse);
|
|
656 |
|
|
657 |
if (iFotaServer->FullScreenDialog())
|
73
|
658 |
iFotaServer->FullScreenDialog()->close();
|
51
|
659 |
|
|
660 |
iNotifParams = CHbSymbianVariantMap::NewL();
|
|
661 |
|
|
662 |
HBufC* keyDialog = HBufC::NewL(10);
|
|
663 |
CleanupStack::PushL(keyDialog);
|
|
664 |
*keyDialog = KKeyDialog;
|
|
665 |
|
|
666 |
CHbSymbianVariant* dialogId = CHbSymbianVariant::NewL(&aDialogid,
|
|
667 |
CHbSymbianVariant::EInt);
|
|
668 |
iNotifParams->Add(*keyDialog, dialogId);
|
73
|
669 |
|
51
|
670 |
|
|
671 |
iNotifier->LaunchNotifierL(iNotifParams, aDialogid);
|
|
672 |
|
|
673 |
CleanupStack::PopAndDestroy();
|
|
674 |
FLOG(_L("CFotaUpdate::ShowDialogL <<"));
|
|
675 |
}
|
|
676 |
|
|
677 |
void CFotaUpdate::HandleDialogResponse(int response, TInt aDialogId)
|
|
678 |
{
|
|
679 |
FLOG(_L("CFotaUpdate::HandleDialogResponse, dialogid = %d response = %d >>"), aDialogId, response);
|
|
680 |
|
|
681 |
if (aDialogId == EFwUpdNotEnoughBattery)
|
|
682 |
{
|
|
683 |
iFotaServer->FinalizeUpdate();
|
|
684 |
}
|
|
685 |
|
|
686 |
FLOG(_L("CFotaUpdate::HandleDialogResponse <<"));
|
|
687 |
}
|
|
688 |
|
|
689 |
TInt CFotaUpdate::WriteUpdateBitmapL( const TDesC& aText, const TDesC& aFile)
|
|
690 |
{
|
|
691 |
FLOG(_L("WriteUpdateBitmapL writing %S to %S w/ txtdir"),&aText,&aFile);
|
|
692 |
|
|
693 |
TSize screensize = CCoeEnv::Static()->ScreenDevice()->SizeInPixels();
|
|
694 |
TInt width = screensize.iWidth - KBmpMargin*2;
|
|
695 |
TInt height = screensize.iHeight;
|
|
696 |
|
|
697 |
CArrayFixSeg<TPtrC>* lines = new CArrayFixSeg<TPtrC>(5);
|
|
698 |
CleanupStack::PushL(lines);
|
|
699 |
CFbsBitmap* bitmap = new ( ELeave ) CFbsBitmap;
|
|
700 |
CleanupStack::PushL( bitmap );
|
|
701 |
bitmap->Create( TSize(width,height), EColor64K );
|
|
702 |
CFbsBitmapDevice* device = CFbsBitmapDevice::NewL( bitmap );
|
|
703 |
CleanupStack::PushL( device );
|
|
704 |
const CFont* font = AknLayoutUtils::FontFromId(EAknLogicalFontPrimaryFont);
|
|
705 |
CFbsBitGc* context;
|
|
706 |
User::LeaveIfError( device->CreateContext( context ) );
|
|
707 |
CleanupStack::PushL( context );
|
|
708 |
TInt ascent = font->AscentInPixels();
|
|
709 |
TInt descent = font->DescentInPixels();
|
|
710 |
context->UseFont ( font );
|
|
711 |
context->Clear(); // bg color
|
|
712 |
|
|
713 |
// Visually ordered text
|
|
714 |
HBufC* wrappedstring = AknBidiTextUtils::ConvertToVisualAndWrapToArrayL(
|
|
715 |
aText, width,*font, *lines);
|
|
716 |
CleanupStack::PushL ( wrappedstring );
|
|
717 |
TBool dirfound (ETrue);
|
|
718 |
// direction of text, affects alignemnt
|
|
719 |
TBidiText::TDirectionality direction = TBidiText::TextDirectionality(
|
|
720 |
*wrappedstring, &dirfound );
|
|
721 |
|
|
722 |
// Print visual text to bitmap
|
|
723 |
for ( TInt i=0; i<lines->Count(); ++i )
|
|
724 |
{
|
|
725 |
TPtrC l = (*lines)[i];
|
|
726 |
TInt top = (ascent+descent)*(i);
|
|
727 |
TInt bot = (ascent+descent)*(i+1);
|
|
728 |
TRect rect (0, top ,width, bot );
|
|
729 |
CGraphicsContext::TTextAlign alignment =
|
|
730 |
direction==TBidiText::ELeftToRight ? CGraphicsContext::ELeft
|
|
731 |
: CGraphicsContext::ERight;
|
|
732 |
context->DrawText(l, rect, ascent, alignment);
|
|
733 |
}
|
|
734 |
height = (ascent+descent)*lines->Count() + descent;
|
|
735 |
bitmap->Resize( TSize(width,height));
|
|
736 |
bitmap->Save( aFile );
|
|
737 |
context->DiscardFont();
|
|
738 |
CleanupStack::PopAndDestroy( wrappedstring );
|
|
739 |
CleanupStack::PopAndDestroy( context );
|
|
740 |
CleanupStack::PopAndDestroy( device );
|
|
741 |
CleanupStack::PopAndDestroy( bitmap );
|
|
742 |
CleanupStack::PopAndDestroy( lines );
|
|
743 |
return 1;
|
|
744 |
}
|