|
1 /* |
|
2 * Copyright (c) 2008 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 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <bautils.h> |
|
22 #include <s32file.h> |
|
23 #include <sysversioninfo.h> |
|
24 #include "iaupdatebglogger.h" |
|
25 #include "iaupdatebginternalfilehandler.h" |
|
26 |
|
27 |
|
28 // Constants to create the file. |
|
29 _LIT( KFile, "bgcheckerinternalfile"); |
|
30 const TInt KDrive( EDriveC ); |
|
31 |
|
32 |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CIAUpdateBGInternalFileHandler::NewL |
|
36 // |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CIAUpdateBGInternalFileHandler* CIAUpdateBGInternalFileHandler::NewL() |
|
40 { |
|
41 CIAUpdateBGInternalFileHandler* self = |
|
42 CIAUpdateBGInternalFileHandler::NewLC(); |
|
43 CleanupStack::Pop( self ); |
|
44 return self; |
|
45 } |
|
46 |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CIAUpdateBGInternalFileHandler::NewLC |
|
50 // |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CIAUpdateBGInternalFileHandler* CIAUpdateBGInternalFileHandler::NewLC() |
|
54 { |
|
55 CIAUpdateBGInternalFileHandler* self = |
|
56 new( ELeave) CIAUpdateBGInternalFileHandler(); |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CIAUpdateBGInternalFileHandler::CIAUpdateBGInternalFileHandler |
|
65 // |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 CIAUpdateBGInternalFileHandler::CIAUpdateBGInternalFileHandler() |
|
69 : iLastTimeShowNewFeatureDialog( 0 ), iUserRejectNewFeatureDialog( EFalse ), |
|
70 iNextRemindTime(0), iIsReminderOn( EFalse ), iMode( EFirstTimeMode ), iFwVersion( NULL ), |
|
71 iSNID(0), iRetryTimes(0) |
|
72 { |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CIAUpdateBGInternalFileHandler::ConstructL |
|
77 // |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 void CIAUpdateBGInternalFileHandler::ConstructL() |
|
81 { |
|
82 User::LeaveIfError( iFsSession.Connect() ); |
|
83 User::LeaveIfError( iFsSession.SetSessionToPrivate( KDrive ) ); |
|
84 |
|
85 User::LeaveIfError( iFsSession.SessionPath( iPath ) ); |
|
86 BaflUtils::EnsurePathExistsL( iFsSession, iPath ); |
|
87 iPath.Append( KFile ); |
|
88 |
|
89 iFwVersion = HBufC::NewL( KSysVersionInfoTextLength ); |
|
90 // Read data from the file if the file exists. |
|
91 // Otherwise, let default values remain. |
|
92 ReadControllerDataL(); |
|
93 } |
|
94 |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CIAUpdateBGInternalFileHandler::~CIAUpdateBGInternalFileHandler |
|
98 // |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 CIAUpdateBGInternalFileHandler::~CIAUpdateBGInternalFileHandler() |
|
102 { |
|
103 iFsSession.Close(); |
|
104 delete iFwVersion; |
|
105 } |
|
106 |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CIAUpdateBGInternalFileHandler::ReadControllerDataL |
|
110 // |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 TBool CIAUpdateBGInternalFileHandler::ReadControllerDataL() |
|
114 { |
|
115 FLOG("[bgchecker] ReadControllerDataL"); |
|
116 RFile file; |
|
117 TInt err = file.Open( iFsSession, iPath, EFileRead ); |
|
118 if ( err == KErrNotFound ) |
|
119 { |
|
120 FLOG("[bgchecker] file doesn't exist"); |
|
121 // File did not exist. |
|
122 // So, nothing to do here anymore. |
|
123 return EFalse; |
|
124 } |
|
125 FLOG("[bgchecker] file exist"); |
|
126 User::LeaveIfError( err ); |
|
127 FLOG("[bgchecker] file no error"); |
|
128 CleanupClosePushL( file ); |
|
129 |
|
130 RFileReadStream stream( file, 0 ); |
|
131 CleanupClosePushL( stream ); |
|
132 |
|
133 InternalizeL( stream ); |
|
134 |
|
135 CleanupStack::PopAndDestroy( &stream ); |
|
136 CleanupStack::PopAndDestroy( &file ); |
|
137 |
|
138 return ETrue; |
|
139 } |
|
140 |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CIAUpdateBGInternalFileHandler::WriteControllerDataL |
|
144 // |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 void CIAUpdateBGInternalFileHandler::WriteControllerDataL() |
|
148 { |
|
149 RFile file; |
|
150 User::LeaveIfError( file.Replace( iFsSession, iPath, EFileWrite ) ); |
|
151 CleanupClosePushL( file ); |
|
152 |
|
153 RFileWriteStream stream( file, 0 ); |
|
154 CleanupClosePushL( stream ); |
|
155 |
|
156 ExternalizeL( stream ); |
|
157 |
|
158 stream.CommitL(); |
|
159 |
|
160 CleanupStack::PopAndDestroy( &stream ); |
|
161 CleanupStack::PopAndDestroy( &file ); |
|
162 } |
|
163 |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CIAUpdateBGInternalFileHandler::LastTimeShowNewFeatureDialog() |
|
167 // |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 const TTime& CIAUpdateBGInternalFileHandler::LastTimeShowNewFeatureDialog() const |
|
171 { |
|
172 return iLastTimeShowNewFeatureDialog; |
|
173 } |
|
174 |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CIAUpdateBGInternalFileHandler::SetLastTimeShowNewFeatureDialog |
|
178 // |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 void CIAUpdateBGInternalFileHandler::SetLastTimeShowNewFeatureDialog( const TTime& aTime ) |
|
182 { |
|
183 iLastTimeShowNewFeatureDialog = aTime; |
|
184 } |
|
185 |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // CIAUpdateBGInternalFileHandler::SetLastTimeShowNewFeatureDialog |
|
189 // |
|
190 // ----------------------------------------------------------------------------- |
|
191 // |
|
192 void CIAUpdateBGInternalFileHandler::SetLastTimeShowNewFeatureDialog( TInt64 aTime ) |
|
193 { |
|
194 iLastTimeShowNewFeatureDialog = aTime; |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CIAUpdateBGInternalFileHandler::UserDecision |
|
199 // |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 TBool CIAUpdateBGInternalFileHandler::UserRejectNewFeatureDialog() const |
|
203 { |
|
204 return iUserRejectNewFeatureDialog; |
|
205 } |
|
206 |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CIAUpdateBGInternalFileHandler::SetLanguage |
|
210 // |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 void CIAUpdateBGInternalFileHandler::SetUserRejectNewFeatureDialog( TBool aUserDecision ) |
|
214 { |
|
215 iUserRejectNewFeatureDialog = aUserDecision; |
|
216 } |
|
217 |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CIAUpdateBGInternalFileHandler::ReminderOn |
|
221 // |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 TBool CIAUpdateBGInternalFileHandler::ReminderOn() |
|
225 { |
|
226 return iIsReminderOn; |
|
227 } |
|
228 |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CIAUpdateBGInternalFileHandler::SetReminder |
|
232 // |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 void CIAUpdateBGInternalFileHandler::SetReminder( TBool aOn ) |
|
236 { |
|
237 iIsReminderOn = aOn; |
|
238 } |
|
239 |
|
240 |
|
241 // ----------------------------------------------------------------------------- |
|
242 // CIAUpdateBGInternalFileHandler::NextRemindTime |
|
243 // |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 TTime CIAUpdateBGInternalFileHandler::NextRemindTime() |
|
247 { |
|
248 return iNextRemindTime; |
|
249 } |
|
250 |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // CIAUpdateBGInternalFileHandler::SetNextRemindTime |
|
254 // |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 void CIAUpdateBGInternalFileHandler::SetNextRemindTime( TTime aNextRemindTime ) |
|
258 { |
|
259 iNextRemindTime = aNextRemindTime; |
|
260 } |
|
261 |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CIAUpdateBGInternalFileHandler::SetNextRemindTime |
|
265 // |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 void CIAUpdateBGInternalFileHandler::SetNextRemindTime( TInt64 aNextRemindTime ) |
|
269 { |
|
270 iNextRemindTime = aNextRemindTime; |
|
271 } |
|
272 |
|
273 |
|
274 // ----------------------------------------------------------------------------- |
|
275 // CIAUpdateBGInternalFileHandler::SetMode |
|
276 // |
|
277 // ----------------------------------------------------------------------------- |
|
278 // |
|
279 void CIAUpdateBGInternalFileHandler::SetMode( TIAUpdateBGMode aMode ) |
|
280 { |
|
281 iMode = aMode; |
|
282 } |
|
283 |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CIAUpdateBGInternalFileHandler::Mode |
|
287 // |
|
288 // ----------------------------------------------------------------------------- |
|
289 // |
|
290 TIAUpdateBGMode CIAUpdateBGInternalFileHandler::Mode() |
|
291 { |
|
292 return iMode; |
|
293 } |
|
294 |
|
295 |
|
296 // ----------------------------------------------------------------------------- |
|
297 // CIAUpdateBGInternalFileHandler::FwVersion |
|
298 // |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 HBufC* CIAUpdateBGInternalFileHandler::FwVersion() |
|
302 { |
|
303 return iFwVersion; |
|
304 } |
|
305 |
|
306 |
|
307 // ---------------------------------------------------------- |
|
308 // CIAUpdateBGInternalFileHandler::SetFwVersionL() |
|
309 // ---------------------------------------------------------- |
|
310 TInt CIAUpdateBGInternalFileHandler::SetFwVersionL( const TDesC& aFwVersion ) |
|
311 { |
|
312 if ( iFwVersion ) |
|
313 { |
|
314 delete iFwVersion; |
|
315 iFwVersion = NULL; |
|
316 } |
|
317 iFwVersion = HBufC::NewL( aFwVersion.Length() ); |
|
318 TPtr fwptr = iFwVersion->Des(); |
|
319 fwptr.Copy( aFwVersion ); |
|
320 return KErrNone; |
|
321 } |
|
322 |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // CIAUpdateBGInternalFileHandler::SoftNotificationID |
|
326 // |
|
327 // ----------------------------------------------------------------------------- |
|
328 // |
|
329 TInt CIAUpdateBGInternalFileHandler::SoftNotificationID() |
|
330 { |
|
331 return iSNID; |
|
332 } |
|
333 |
|
334 |
|
335 // ----------------------------------------------------------------------------- |
|
336 // CIAUpdateBGInternalFileHandler::SetSoftNotifcationID |
|
337 // |
|
338 // ----------------------------------------------------------------------------- |
|
339 // |
|
340 void CIAUpdateBGInternalFileHandler::SetSoftNotificationID( TInt aID ) |
|
341 { |
|
342 iSNID = aID; |
|
343 } |
|
344 |
|
345 |
|
346 // ----------------------------------------------------------------------------- |
|
347 // CIAUpdateBGInternalFileHandler::RetryTimes |
|
348 // |
|
349 // ----------------------------------------------------------------------------- |
|
350 // |
|
351 TInt CIAUpdateBGInternalFileHandler::RetryTimes() |
|
352 { |
|
353 return iRetryTimes; |
|
354 } |
|
355 |
|
356 |
|
357 // ----------------------------------------------------------------------------- |
|
358 // CIAUpdateBGInternalFileHandler::SetRetryTimes |
|
359 // |
|
360 // ----------------------------------------------------------------------------- |
|
361 // |
|
362 void CIAUpdateBGInternalFileHandler::SetRetryTimes( TInt aRetry ) |
|
363 { |
|
364 iRetryTimes = aRetry; |
|
365 } |
|
366 |
|
367 // ----------------------------------------------------------------------------- |
|
368 // CIAUpdateBGInternalFileHandler::InternalizeL |
|
369 // |
|
370 // ----------------------------------------------------------------------------- |
|
371 // |
|
372 void CIAUpdateBGInternalFileHandler::InternalizeL( RReadStream& aStream ) |
|
373 { |
|
374 // If you make changes here, |
|
375 // remember to update ExternalizeL accordingly!!! |
|
376 |
|
377 TInt64 lastShowTime( 0 ); |
|
378 aStream >> lastShowTime; |
|
379 SetLastTimeShowNewFeatureDialog( lastShowTime ); |
|
380 |
|
381 TInt userDecision( aStream.ReadUint8L() ); |
|
382 // Static casting is safe to do here because enum and TInt are the same. |
|
383 SetUserRejectNewFeatureDialog( static_cast< TBool >( userDecision ) ); |
|
384 |
|
385 TInt64 nextRemindTime( 0 ); |
|
386 aStream >> nextRemindTime; |
|
387 SetNextRemindTime( nextRemindTime ); |
|
388 |
|
389 TInt remindOn( aStream.ReadUint8L() ); |
|
390 // Static casting is safe to do here because enum and TInt are the same. |
|
391 SetReminder( static_cast< TBool >( remindOn ) ); |
|
392 |
|
393 TInt mode( aStream.ReadUint8L() ); |
|
394 SetMode( static_cast<TIAUpdateBGMode> (mode) ); |
|
395 |
|
396 //read the length of fw version string |
|
397 TInt fwlength ( aStream.ReadUint8L() ); |
|
398 |
|
399 //read string of fw version |
|
400 TPtr fwVer = iFwVersion->Des(); |
|
401 aStream.ReadL( fwVer, fwlength ); |
|
402 |
|
403 TInt snid ( aStream.ReadUint16L() ); |
|
404 SetSoftNotificationID( snid ); |
|
405 |
|
406 TInt retry ( aStream.ReadUint8L() ); |
|
407 SetRetryTimes( retry ); |
|
408 } |
|
409 |
|
410 |
|
411 // ----------------------------------------------------------------------------- |
|
412 // CIAUpdateBGInternalFileHandler::ExternalizeL |
|
413 // |
|
414 // ----------------------------------------------------------------------------- |
|
415 // |
|
416 void CIAUpdateBGInternalFileHandler::ExternalizeL( RWriteStream& aStream ) |
|
417 { |
|
418 // If you make changes here, |
|
419 // remember to update InternalizeL accordingly!!! |
|
420 |
|
421 TInt64 lastshowTime( LastTimeShowNewFeatureDialog().Int64() ); |
|
422 aStream << lastshowTime; |
|
423 |
|
424 TInt userDecision ( UserRejectNewFeatureDialog() ); |
|
425 aStream.WriteUint8L( userDecision ); |
|
426 |
|
427 TInt64 nextRemindTime( NextRemindTime().Int64() ); |
|
428 aStream << nextRemindTime; |
|
429 |
|
430 TInt remindOn ( ReminderOn() ); |
|
431 aStream.WriteUint8L( remindOn ); |
|
432 |
|
433 TInt mode( Mode() ); |
|
434 aStream.WriteUint8L( mode ); |
|
435 |
|
436 //write length of fw string |
|
437 aStream.WriteUint8L( iFwVersion->Length() ); |
|
438 // write string of fw version |
|
439 aStream.WriteL( *iFwVersion ); |
|
440 |
|
441 TInt snid ( SoftNotificationID() ); |
|
442 aStream.WriteUint16L( snid ); |
|
443 |
|
444 TInt retry ( RetryTimes() ); |
|
445 aStream.WriteUint8L( retry ); |
|
446 } |
|
447 |
|
448 //EOF |