|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <badesca.h> |
|
17 #include <bautils.h> |
|
18 #include <hal.h> |
|
19 #include <s32file.h> |
|
20 #include <f32file.h> |
|
21 #include <tz.h> |
|
22 #include <mtp/cmtptypestring.h> |
|
23 #include <mtp/mtpdatatypeconstants.h> |
|
24 #include <mtp/cmtpdataproviderplugin.h> |
|
25 #include <mtp/cmtptypefile.h> |
|
26 |
|
27 #include "cmtpdataprovider.h" |
|
28 #include "cmtpdataprovidercontroller.h" |
|
29 #include "cmtpdevicedatastore.h" |
|
30 #include "cmtpframeworkconfig.h" |
|
31 #include "mmtpenumerationcallback.h" |
|
32 #include "mtpdevdppanic.h" |
|
33 #include "mtpdevicedpconst.h" |
|
34 |
|
35 // Class constants. |
|
36 __FLOG_STMT(_LIT8(KComponent,"DeviceDataStore");) |
|
37 |
|
38 #ifdef __WINS__ |
|
39 _LIT( KFileName, "c:\\private\\102827a2\\mtpdevice.ico"); |
|
40 #else |
|
41 _LIT( KFileName, "z:\\private\\102827a2\\mtpdevice.ico"); |
|
42 #endif |
|
43 |
|
44 |
|
45 // Device property datastore constants. |
|
46 _LIT(KMTPNoBackupFolder, "nobackup\\"); |
|
47 _LIT(KMTPDevicePropertyStoreFileName, "mtpdevicepropertystore.dat"); |
|
48 _LIT(KMTPDevicePropertyStoreDrive, "c:"); |
|
49 _LIT(KMTPVendorExtensionSetDelimiter, "; "); |
|
50 |
|
51 //Default Session Initiator Version Information |
|
52 _LIT(KDefaultSessionInitiatorVersionInfo,"None"); |
|
53 //Default Perceived DeviceType information |
|
54 static const TUint32 DefaultPerceivedDeviceType = 0; |
|
55 |
|
56 /*In order to ensure a reasonable RunL() duration, 8 dps at maximum are |
|
57 queried in one RunL() invocation. |
|
58 */ |
|
59 static const TUint KExtensionSetIterationRunLength = 8; |
|
60 |
|
61 // The maximum number of extensions each dp support. |
|
62 static const TUint KExtensionSetGranularity = 4; |
|
63 |
|
64 //#define for PERCIVED_DEVICETYPE |
|
65 static const TUint KPercivedDeviceType = 3; |
|
66 //maximum length for date time string |
|
67 static const TUint KMaxDateTimeLength = 28; |
|
68 //minimum length for date time string |
|
69 static const TUint KMinDateTimeLength = 15; |
|
70 //position of date and time seperator 'T' |
|
71 static const TUint KPosDelemT = 8; |
|
72 //buffer size for reading iconfile |
|
73 static const TUint KBufferSize = 1024; |
|
74 |
|
75 //enum for time zone |
|
76 enum TDevDPTypeTimeOffset |
|
77 { |
|
78 EDEVDPTypeZero = 0, |
|
79 EDEVDPTypeMinus , |
|
80 EDEVDPTypePlus, |
|
81 EDEVDPTypeNotDefined, |
|
82 }; |
|
83 |
|
84 |
|
85 /** |
|
86 MTP device information data store factory method. |
|
87 @return A pointer to an MTP device information data store. Ownership IS |
|
88 transfered. |
|
89 @leave One of the system wide error codes, if a processing failure occurs. |
|
90 */ |
|
91 CMTPDeviceDataStore* CMTPDeviceDataStore::NewL() |
|
92 { |
|
93 CMTPDeviceDataStore* self = new (ELeave) CMTPDeviceDataStore(); |
|
94 CleanupStack::PushL(self); |
|
95 self->ConstructL(); |
|
96 CleanupStack::Pop(self); |
|
97 return self; |
|
98 } |
|
99 |
|
100 /** |
|
101 Destructor. |
|
102 */ |
|
103 CMTPDeviceDataStore::~CMTPDeviceDataStore() |
|
104 { |
|
105 __FLOG(_L8("~CMTPDeviceDataStore - Entry")); |
|
106 Cancel(); |
|
107 delete iDeviceFriendlyNameDefault; |
|
108 delete iSyncPartnerNameDefault; |
|
109 delete iDeviceFriendlyName; |
|
110 delete iSynchronisationPartner; |
|
111 delete iTelephony; |
|
112 delete iSessionInitiatorVersionInfo; |
|
113 delete iDeviceIcon; |
|
114 delete iSupportedDevProArray; |
|
115 delete iDateTime; |
|
116 iDeviceVersion.Close(); |
|
117 iSerialNumber.Close(); |
|
118 iSingletons.Close(); |
|
119 iMTPExtensions.Close(); |
|
120 __FLOG(_L8("~CMTPDeviceDataStore - Exit")); |
|
121 __FLOG_CLOSE; |
|
122 } |
|
123 |
|
124 /** |
|
125 Check to see if a request such as BatteryLevel is currently |
|
126 pending for processing. If so it's not advisable to make another |
|
127 request. |
|
128 |
|
129 @return ETrue if a request is pending EFalse otherwise. |
|
130 */ |
|
131 |
|
132 TBool CMTPDeviceDataStore::RequestPending() const |
|
133 { |
|
134 return IsActive(); |
|
135 } |
|
136 |
|
137 void CMTPDeviceDataStore::BatteryLevelL(TRequestStatus& aStatus, TUint& aBatteryLevel) |
|
138 { |
|
139 __FLOG(_L8("BatteryLevel - Entry")); |
|
140 |
|
141 if (RequestPending()) |
|
142 { |
|
143 // We are already reading battery level |
|
144 // leave so we don't set ourselves active twice |
|
145 User::Leave(KErrInUse); |
|
146 } |
|
147 |
|
148 iPendingStatus = &aStatus; |
|
149 SetRequestPending(*iPendingStatus); |
|
150 |
|
151 if (iTelephony) |
|
152 { |
|
153 iPendingBatteryLevel = &aBatteryLevel; |
|
154 iTelephony->GetBatteryInfo(iStatus, iBatteryInfoV1Pckg); |
|
155 SetState(EEnumeratingBatteryLevel); |
|
156 SetActive(); |
|
157 } |
|
158 else |
|
159 { |
|
160 aBatteryLevel = KMTPDefaultBatteryLevel; |
|
161 SetRequestComplete(*iPendingStatus, KErrNone); |
|
162 } |
|
163 __FLOG(_L8("BatteryLevel - Exit")); |
|
164 } |
|
165 |
|
166 /** |
|
167 Provides the MTP device friendly name. |
|
168 @return The MTP device friendly name. |
|
169 */ |
|
170 const TDesC& CMTPDeviceDataStore::DeviceFriendlyName() const |
|
171 { |
|
172 __FLOG(_L8("DeviceFriendlyName - Entry")); |
|
173 __FLOG(_L8("DeviceFriendlyName - Exit")); |
|
174 return iDeviceFriendlyName->StringChars(); |
|
175 } |
|
176 |
|
177 /** |
|
178 Provides the default MTP device friendly name. |
|
179 @return The default MTP device friendly name. |
|
180 */ |
|
181 const TDesC& CMTPDeviceDataStore::DeviceFriendlyNameDefault() const |
|
182 { |
|
183 __FLOG(_L8("DeviceFriendlyNameDefault - Entry")); |
|
184 __FLOG(_L8("DeviceFriendlyNameDefault - Exit")); |
|
185 return *iDeviceFriendlyNameDefault; |
|
186 } |
|
187 |
|
188 /** |
|
189 Provides the device firmware version identifier |
|
190 @return The device firmware version identifier . |
|
191 */ |
|
192 const TDesC& CMTPDeviceDataStore::DeviceVersion() const |
|
193 { |
|
194 __FLOG(_L8("DeviceVersion - Entry")); |
|
195 __FLOG(_L8("DeviceVersion - Exit")); |
|
196 return iDeviceVersion; |
|
197 } |
|
198 |
|
199 /** |
|
200 Provides the device manufacturer name. |
|
201 @return The device manufacturer name. |
|
202 */ |
|
203 const TDesC& CMTPDeviceDataStore::Manufacturer() const |
|
204 { |
|
205 __FLOG(_L8("Manufacturer - Entry")); |
|
206 __ASSERT_DEBUG(Enumerated(), Panic(EMTPDevDpInvalidState)); |
|
207 __FLOG(_L8("Manufacturer - Exit")); |
|
208 return iPhoneIdV1.iManufacturer; |
|
209 } |
|
210 |
|
211 /** |
|
212 Provides the device model identifier. |
|
213 @return The device model identifier. |
|
214 */ |
|
215 const TDesC& CMTPDeviceDataStore::Model() const |
|
216 { |
|
217 __FLOG(_L8("Model - Entry")); |
|
218 __ASSERT_DEBUG(Enumerated(), Panic(EMTPDevDpInvalidState)); |
|
219 __FLOG(_L8("Model - Exit")); |
|
220 return iPhoneIdV1.iModel; |
|
221 } |
|
222 |
|
223 /** |
|
224 Provides the MTP Vendor Extension string. |
|
225 @return The MTP Vendor Extension string. |
|
226 */ |
|
227 const TDesC& CMTPDeviceDataStore::MTPExtensions() const |
|
228 { |
|
229 __FLOG(_L8("MTPExtensions - Entry")); |
|
230 __FLOG(_L8("MTPExtensions - Exit")); |
|
231 return iMTPExtensions; |
|
232 } |
|
233 |
|
234 /** |
|
235 Provides the device serial number. |
|
236 @return The device serial number. |
|
237 */ |
|
238 const TDesC& CMTPDeviceDataStore::SerialNumber() const |
|
239 { |
|
240 __FLOG(_L8("SerialNumber - Entry")); |
|
241 __ASSERT_DEBUG(Enumerated(), Panic(EMTPDevDpInvalidState)); |
|
242 __FLOG(_L8("SerialNumber - Exit")); |
|
243 return iPhoneIdV1.iSerialNumber; |
|
244 } |
|
245 |
|
246 /** |
|
247 Provides the MTP synchronisation partner name. |
|
248 @return The MTP synchronisation partner name. |
|
249 */ |
|
250 const TDesC& CMTPDeviceDataStore::SynchronisationPartner() const |
|
251 { |
|
252 __FLOG(_L8("SynchronisationPartner - Entry")); |
|
253 __FLOG(_L8("SynchronisationPartner - Exit")); |
|
254 return iSynchronisationPartner->StringChars(); |
|
255 } |
|
256 |
|
257 /** |
|
258 Provides the default MTP synchronisation partner name. |
|
259 @return The default MTP synchronisation partner name. |
|
260 */ |
|
261 const TDesC& CMTPDeviceDataStore::SynchronisationPartnerDefault() const |
|
262 { |
|
263 __FLOG(_L8("SynchronisationPartnerDefault - Entry")); |
|
264 __FLOG(_L8("SynchronisationPartnerDefault - Exit")); |
|
265 return *iSyncPartnerNameDefault; |
|
266 } |
|
267 |
|
268 /** |
|
269 Sets the MTP device friendly name. |
|
270 @param aName The new MTP device friendly name. |
|
271 @leave One of the system wide error codes, if a processing failure occurs. |
|
272 */ |
|
273 void CMTPDeviceDataStore::SetDeviceFriendlyNameL(const TDesC& aName) |
|
274 { |
|
275 __FLOG(_L8("SetDeviceFriendlyNameL - Entry")); |
|
276 iDeviceFriendlyName->SetL(aName); |
|
277 StoreL(); |
|
278 __FLOG(_L8("SetDeviceFriendlyNameL - Exit")); |
|
279 } |
|
280 |
|
281 /** |
|
282 Sets the synchronisation partner name. |
|
283 @param aName The new MTP synchronisation partner name. |
|
284 @leave One of the system wide error codes, if a processing failure occurs. |
|
285 */ |
|
286 void CMTPDeviceDataStore::SetSynchronisationPartnerL(const TDesC& aName) |
|
287 { |
|
288 __FLOG(_L8("SetSynchronisationPartnerL - Entry")); |
|
289 iSynchronisationPartner->SetL(aName); |
|
290 StoreL(); |
|
291 __FLOG(_L8("SetSynchronisationPartnerL - Exit")); |
|
292 } |
|
293 |
|
294 /** |
|
295 Initiates the MTP device data provider's device information data store |
|
296 enumeration sequence. The sequence is concluded when ObjectEnumerationCompleteL |
|
297 is signalled to the MTP data provider framework layer. |
|
298 @param aStorageId The MTP StorageId to be enumerated. |
|
299 @param aCallback Callback to be called when enumeration completes. |
|
300 @leave One of the system wide error codes, if a processing failure occurs. |
|
301 */ |
|
302 void CMTPDeviceDataStore::StartEnumerationL(TUint32 aStorageId, MMTPEnumerationCallback& aCallback) |
|
303 { |
|
304 __FLOG(_L8("StartEnumerationL - Entry")); |
|
305 if (State() != EUndefined) |
|
306 { |
|
307 aCallback.NotifyEnumerationCompleteL(aStorageId, KErrNone); |
|
308 } |
|
309 else |
|
310 { |
|
311 iStorageId = aStorageId; |
|
312 iCallback = &aCallback; |
|
313 Schedule(EEnumeratingDevicePropertyStore); |
|
314 } |
|
315 __FLOG(_L8("StartEnumerationL - Exit")); |
|
316 } |
|
317 |
|
318 void CMTPDeviceDataStore::DoCancel() |
|
319 { |
|
320 __FLOG(_L8("DoCancel - Entry")); |
|
321 if (iTelephony) |
|
322 { |
|
323 switch (State()) |
|
324 { |
|
325 case EEnumeratingPhoneId: |
|
326 iTelephony->CancelAsync(CTelephony::EGetPhoneIdCancel); |
|
327 break; |
|
328 |
|
329 case EEnumeratingBatteryLevel: |
|
330 iTelephony->CancelAsync(CTelephony::EGetBatteryInfoCancel); |
|
331 break; |
|
332 |
|
333 default: |
|
334 // Nothing to do. |
|
335 break; |
|
336 } |
|
337 } |
|
338 __FLOG(_L8("DoCancel - Exit")); |
|
339 } |
|
340 |
|
341 /** |
|
342 Handles leaves occurring in RunL. |
|
343 @param aError leave error code |
|
344 @return KErrNone |
|
345 */ |
|
346 TInt CMTPDeviceDataStore::RunError(TInt aError) |
|
347 { |
|
348 __FLOG(_L8("RunError - Entry")); |
|
349 __FLOG_VA((_L8("Error = %d, State = %d"), aError, State())); |
|
350 aError = aError; // suppress compiler warning |
|
351 |
|
352 switch (State()) |
|
353 { |
|
354 case EEnumeratingDevicePropertyStore: |
|
355 // Error restoring device properties; use defaults. |
|
356 Schedule(EEnumeratingDeviceVersion); |
|
357 break; |
|
358 |
|
359 case EEnumeratingDeviceVersion: |
|
360 // Error enumerating software build information; use default. |
|
361 Schedule(EEnumeratingPhoneId); |
|
362 break; |
|
363 |
|
364 case EEnumeratingPhoneId: |
|
365 // Error enumerating telephony device ID information; use defaults. |
|
366 Schedule(EEnumeratingVendorExtensions); |
|
367 break; |
|
368 |
|
369 case EEnumeratingVendorExtensions: |
|
370 Schedule(EEnumerated); |
|
371 break; |
|
372 |
|
373 case EEnumeratingBatteryLevel: |
|
374 // This case will never occur |
|
375 case EUndefined: |
|
376 default: |
|
377 __DEBUG_ONLY(Panic(EMTPDevDpInvalidState)); |
|
378 break; |
|
379 } |
|
380 |
|
381 __FLOG(_L8("RunError - Exit")); |
|
382 return KErrNone; |
|
383 } |
|
384 |
|
385 void CMTPDeviceDataStore::RunL() |
|
386 { |
|
387 __FLOG(_L8("RunL - Entry")); |
|
388 switch (State()) |
|
389 { |
|
390 case EEnumeratingDevicePropertyStore: |
|
391 RestoreL(); |
|
392 Schedule(EEnumeratingDeviceVersion); |
|
393 break; |
|
394 |
|
395 case EEnumeratingDeviceVersion: |
|
396 { |
|
397 TInt buildNo(0); |
|
398 User::LeaveIfError(HAL::Get(HALData::EManufacturerSoftwareBuild, buildNo)); |
|
399 __FLOG_VA((_L8("EManufacturerSoftwareBuild = %d "), buildNo)); |
|
400 iDeviceVersion.Format(_L("%d"), buildNo); |
|
401 Schedule(EEnumeratingPhoneId); |
|
402 } |
|
403 break; |
|
404 |
|
405 case EEnumeratingPhoneId: |
|
406 if (!iTelephony) |
|
407 { |
|
408 iTelephony = CTelephony::NewL(); |
|
409 iTelephony->GetPhoneId(iStatus, iPhoneIdV1Pckg); |
|
410 SetActive(); |
|
411 } |
|
412 else |
|
413 { |
|
414 StoreFormattedSerialNumber(iPhoneIdV1.iSerialNumber); |
|
415 Schedule(EEnumeratingVendorExtensions); |
|
416 } |
|
417 break; |
|
418 |
|
419 case EEnumeratingVendorExtensions: |
|
420 { |
|
421 TBool isCompleted = EFalse; |
|
422 AppendMTPExtensionSetsL(isCompleted); |
|
423 if (isCompleted) |
|
424 { |
|
425 Schedule(EEnumerated); |
|
426 } |
|
427 else |
|
428 { |
|
429 Schedule(EEnumeratingVendorExtensions); |
|
430 } |
|
431 } |
|
432 break; |
|
433 |
|
434 case EEnumeratingBatteryLevel: |
|
435 *iPendingBatteryLevel = iBatteryInfoV1.iChargeLevel; |
|
436 SetRequestComplete(*iPendingStatus, KErrNone); |
|
437 SetState(EEnumerated); |
|
438 break; |
|
439 |
|
440 case EEnumerated: |
|
441 if (iCallback) |
|
442 { |
|
443 iCallback->NotifyEnumerationCompleteL(iStorageId, KErrNone); |
|
444 iCallback = NULL; |
|
445 iStorageId = KMTPNotSpecified32; |
|
446 } |
|
447 break; |
|
448 |
|
449 case EEnumeratedBatteryLevel : |
|
450 *iPendingBatteryLevel = iBatteryInfoV1.iChargeLevel; |
|
451 SetRequestComplete(*iPendingStatus, KErrNone); |
|
452 SetState(EEnumerated); |
|
453 break; |
|
454 |
|
455 case EUndefined: |
|
456 default: |
|
457 __DEBUG_ONLY(Panic(EMTPDevDpInvalidState)); |
|
458 break; |
|
459 } |
|
460 __FLOG(_L8("RunL - Exit")); |
|
461 } |
|
462 |
|
463 /** |
|
464 Constructor. |
|
465 @param aConnectionMgr The MTP connection manager interface. |
|
466 */ |
|
467 CMTPDeviceDataStore::CMTPDeviceDataStore() : |
|
468 CActive(EPriorityStandard), |
|
469 iBatteryInfoV1Pckg(iBatteryInfoV1), |
|
470 iPhoneIdV1Pckg(iPhoneIdV1) |
|
471 { |
|
472 CActiveScheduler::Add(this); |
|
473 } |
|
474 |
|
475 /** |
|
476 Second phase constructor. |
|
477 */ |
|
478 void CMTPDeviceDataStore::ConstructL() |
|
479 { |
|
480 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
481 __FLOG(_L8("ConstructL - Entry")); |
|
482 iSingletons.OpenL(); |
|
483 |
|
484 /* |
|
485 Set the default values. |
|
486 |
|
487 1. Device friendly name. |
|
488 */ |
|
489 iDeviceFriendlyNameDefault = iSingletons.FrameworkConfig().ValueL(CMTPFrameworkConfig::EDeviceFriendlyName); |
|
490 iDeviceFriendlyName = CMTPTypeString::NewL(*iDeviceFriendlyNameDefault); |
|
491 |
|
492 // 2. Synchronization partner name. |
|
493 iSyncPartnerNameDefault = iSingletons.FrameworkConfig().ValueL(CMTPFrameworkConfig::ESynchronizationPartnerName); |
|
494 iSynchronisationPartner = CMTPTypeString::NewL(*iSyncPartnerNameDefault); |
|
495 |
|
496 // 3. Device Version. |
|
497 iDeviceVersion.CreateL(KMTPDefaultDeviceVersion); |
|
498 |
|
499 // 4. Manufacturer. |
|
500 iPhoneIdV1.iManufacturer = KMTPDefaultManufacturer; |
|
501 |
|
502 // 5. Model. |
|
503 iPhoneIdV1.iModel = KMTPDefaultModel; |
|
504 |
|
505 // 6. Serial Number. |
|
506 StoreFormattedSerialNumber(KMTPDefaultSerialNumber); |
|
507 |
|
508 // 7. Vendor Extensions |
|
509 iMTPExtensions.CreateL(KMTPMaxStringCharactersLength); |
|
510 |
|
511 // 8. Session Initiator version Info |
|
512 iSessionInitiatorVersionInfo = CMTPTypeString::NewL(KDefaultSessionInitiatorVersionInfo); |
|
513 |
|
514 //9. Percived device type property. |
|
515 //value for mobile handset is 0x00000003 |
|
516 iPerceivedDeviceType.Set(KPercivedDeviceType); |
|
517 |
|
518 //10 date time property. no need to creat the string right now, create the |
|
519 //date time string whe it is requested. |
|
520 TBuf<30> dateTimeString; |
|
521 iDateTime = CMTPTypeString::NewL(dateTimeString); |
|
522 |
|
523 //11 Device Icon property, Load the icon into Auint Atrray |
|
524 LoadDeviceIconL(); |
|
525 |
|
526 __FLOG(_L8("ConstructL - Exit")); |
|
527 } |
|
528 |
|
529 /** |
|
530 Indicates if the device information data store is in the EEnumerated state. |
|
531 @return ETrue if the device data store state is enumerated, otherwiese EFalse. |
|
532 */ |
|
533 TBool CMTPDeviceDataStore::Enumerated() const |
|
534 { |
|
535 __FLOG(_L8("Enumerated - Entry")); |
|
536 TInt32 state(State()); |
|
537 __FLOG(_L8("Enumerated - Exit")); |
|
538 return (state & EEnumerated); |
|
539 } |
|
540 |
|
541 /** |
|
542 Externalizes device properties to the device property store. |
|
543 @param aWriteStream the stream to externalize the device properties |
|
544 @leave One of the system wide error codes, if a processing failure occurs. |
|
545 */ |
|
546 void CMTPDeviceDataStore::ExternalizeL(RWriteStream& aWriteStream) const |
|
547 { |
|
548 __FLOG(_L8("ExternalizeL - Entry")); |
|
549 aWriteStream.WriteInt32L(KMTPDevicePropertyStoreVersion); |
|
550 aWriteStream << DeviceFriendlyName(); |
|
551 aWriteStream << SynchronisationPartner(); |
|
552 __FLOG(_L8("ExternalizeL - Exit")); |
|
553 } |
|
554 |
|
555 /** |
|
556 Internalises device properties from the device property store. |
|
557 @param aReadStream The device property store input data stream. |
|
558 @leave One of the system wide error codes, if a processing failure occurs. |
|
559 */ |
|
560 void CMTPDeviceDataStore::InternalizeL(RReadStream& aReadStream) |
|
561 { |
|
562 __FLOG(_L8("InternalizeL - Entry")); |
|
563 RBuf buf; |
|
564 buf.CleanupClosePushL(); |
|
565 |
|
566 /* |
|
567 Read the device property store version. This is present for future |
|
568 expansion but is currently ignored. |
|
569 */ |
|
570 TInt32 version(aReadStream.ReadInt32L()); |
|
571 |
|
572 // Read the device friendly name. |
|
573 buf.CreateL(aReadStream, KMTPMaxStringCharactersLength); |
|
574 iDeviceFriendlyName->SetL(buf); |
|
575 buf.Close(); |
|
576 |
|
577 // Read the synchronisation partner name. |
|
578 buf.CreateL(aReadStream, KMTPMaxStringCharactersLength); |
|
579 iSynchronisationPartner->SetL(buf); |
|
580 buf.Close(); |
|
581 |
|
582 CleanupStack::Pop(); //buf |
|
583 __FLOG(_L8("InternalizeL - Exit")); |
|
584 } |
|
585 |
|
586 /** |
|
587 Provides the full pathname of the device property store. |
|
588 @return The full pathname of the device property store. |
|
589 */ |
|
590 const TDesC& CMTPDeviceDataStore::PropertyStoreName() |
|
591 { |
|
592 __FLOG(_L8("PropertyStoreName - Entry")); |
|
593 if (iPropertyStoreName.Length() == 0) |
|
594 { |
|
595 iSingletons.Fs().PrivatePath(iPropertyStoreName); |
|
596 iPropertyStoreName.Insert(0, KMTPDevicePropertyStoreDrive); |
|
597 iPropertyStoreName.Append(KMTPNoBackupFolder); |
|
598 iPropertyStoreName.Append(KMTPDevicePropertyStoreFileName); |
|
599 } |
|
600 |
|
601 __FLOG(_L8("PropertyStoreName - Exit")); |
|
602 return iPropertyStoreName; |
|
603 } |
|
604 |
|
605 /** |
|
606 Query all dps for the MTP Vendor extensions set. |
|
607 @return ETrue if finished querying all the dps, otherwise EFalse. |
|
608 */ |
|
609 void CMTPDeviceDataStore::AppendMTPExtensionSetsL(TBool& aCompleted) |
|
610 { |
|
611 __FLOG(_L8("AppendMTPExtensionSetsL - Entry")); |
|
612 CMTPDataProviderController& dps(iSingletons.DpController()); |
|
613 const TInt count = Min<TInt>(iCurrentDpIndex + KExtensionSetIterationRunLength, dps.Count()); |
|
614 aCompleted = EFalse; |
|
615 CDesCArraySeg* extensions = new (ELeave) CDesCArraySeg(KExtensionSetGranularity); |
|
616 CleanupStack::PushL(extensions); |
|
617 while (!aCompleted && (iCurrentDpIndex < count)) |
|
618 { |
|
619 CMTPDataProvider& dp(dps.DataProviderByIndexL(iCurrentDpIndex)); |
|
620 dp.Plugin().SupportedL(EVendorExtensionSets, *extensions); |
|
621 //append the mtp extension string. |
|
622 TInt n = extensions->Count(); |
|
623 TInt len = iMTPExtensions.Length(); |
|
624 for (TInt i = 0; i < n; i++) |
|
625 { |
|
626 len += (*extensions)[i].Length() + KMTPVendorExtensionSetDelimiter().Length(); |
|
627 if (len > KMTPMaxStringCharactersLength) |
|
628 { |
|
629 __FLOG(_L8("MTP Extensions set exceeded the maximum MTP String length")); |
|
630 // End querying dps when the extension set exceeds the maximum mtp string length. |
|
631 aCompleted = ETrue; |
|
632 break; |
|
633 } |
|
634 else |
|
635 { |
|
636 if ( KErrNotFound == iMTPExtensions.Find((*extensions)[i]) ) |
|
637 { |
|
638 iMTPExtensions.Append((*extensions)[i]); |
|
639 iMTPExtensions.Append(KMTPVendorExtensionSetDelimiter); |
|
640 } |
|
641 } |
|
642 } |
|
643 extensions->Reset(); |
|
644 iCurrentDpIndex++; |
|
645 } |
|
646 CleanupStack::PopAndDestroy(extensions); |
|
647 |
|
648 if(!aCompleted && iCurrentDpIndex >= dps.Count()) |
|
649 { |
|
650 aCompleted = ETrue; |
|
651 } |
|
652 |
|
653 __FLOG(_L8("AppendMTPExtensionSetsL - Exit")); |
|
654 } |
|
655 |
|
656 /** |
|
657 Loads device properties from the device property store. |
|
658 @leave One of the system wide error codes, if a processing failure occurs. |
|
659 */ |
|
660 void CMTPDeviceDataStore::RestoreL() |
|
661 { |
|
662 __FLOG(_L8("RestoreL - Entry")); |
|
663 RFs& fs(iSingletons.Fs()); |
|
664 if(BaflUtils::FileExists(fs, PropertyStoreName())) |
|
665 { |
|
666 CFileStore* store(CDirectFileStore::OpenLC(fs, PropertyStoreName(), EFileRead)); |
|
667 RStoreReadStream instream; |
|
668 instream.OpenLC(*store, store->Root()); |
|
669 InternalizeL(instream); |
|
670 CleanupStack::PopAndDestroy(2, store); // instream, store |
|
671 } |
|
672 __FLOG(_L8("RestoreL - Exit")); |
|
673 } |
|
674 |
|
675 /** |
|
676 Schedules the device information data store to transition to the specified state. |
|
677 @param aState The new data stream state. |
|
678 */ |
|
679 void CMTPDeviceDataStore::Schedule(TInt32 aState) |
|
680 { |
|
681 __FLOG(_L8("Schedule - Entry")); |
|
682 SetState(aState); |
|
683 SetRequestPending(iStatus); |
|
684 SetActive(); |
|
685 SetRequestComplete(iStatus,KErrNone); |
|
686 __FLOG(_L8("Schedule - Exit")); |
|
687 } |
|
688 |
|
689 /** |
|
690 Completes the supplied asynchronous request completion status. |
|
691 */ |
|
692 void CMTPDeviceDataStore::SetRequestComplete(TRequestStatus& aRequest, TUint aErr) |
|
693 { |
|
694 __FLOG(_L8("CompleteRequest - Entry")); |
|
695 TRequestStatus* status(&aRequest); |
|
696 User::RequestComplete(status, aErr); |
|
697 __FLOG(_L8("CompleteRequest - Exit")); |
|
698 } |
|
699 |
|
700 |
|
701 /** |
|
702 Initialises the supplied asynchronous request completion status. |
|
703 */ |
|
704 void CMTPDeviceDataStore::SetRequestPending(TRequestStatus& aRequest) |
|
705 { |
|
706 __FLOG(_L8("SetRequestPending - Entry")); |
|
707 aRequest = KRequestPending; |
|
708 __FLOG(_L8("SetRequestPending - Exit")); |
|
709 } |
|
710 |
|
711 /** |
|
712 Sets the device information data store state variable. |
|
713 @param aState The new data stream state. |
|
714 */ |
|
715 void CMTPDeviceDataStore::SetState(TInt32 aState) |
|
716 { |
|
717 __FLOG(_L8("SetState - Entry")); |
|
718 iState = ((EEnumerated & iState) | aState); |
|
719 __FLOG_VA((_L8("State set to 0x%08X"), iState)); |
|
720 __FLOG(_L8("SetState - Exit")); |
|
721 } |
|
722 |
|
723 /** |
|
724 Provides the device information data store state variable value. |
|
725 @return The device information data store state variable value. |
|
726 */ |
|
727 TInt32 CMTPDeviceDataStore::State() const |
|
728 { |
|
729 __FLOG(_L8("State - Entry")); |
|
730 __FLOG_VA((_L8("State = 0x%08X"), iState)); |
|
731 __FLOG(_L8("State - Exit")); |
|
732 return iState; |
|
733 } |
|
734 |
|
735 /** |
|
736 Stores device properties in the device property store. |
|
737 @leave One of the system wide error codes, if a processing failure occurs. |
|
738 */ |
|
739 void CMTPDeviceDataStore::StoreL() |
|
740 { |
|
741 __FLOG(_L8("StoreL - Entry")); |
|
742 CFileStore* store(CDirectFileStore::ReplaceLC(iSingletons.Fs(), PropertyStoreName(), EFileWrite)); |
|
743 store->SetTypeL(KDirectFileStoreLayoutUid); |
|
744 RStoreWriteStream outstream; |
|
745 TStreamId id = outstream.CreateLC(*store); |
|
746 ExternalizeL(outstream); |
|
747 outstream.CommitL(); |
|
748 CleanupStack::PopAndDestroy(&outstream); |
|
749 store->SetRootL(id); |
|
750 store->CommitL(); |
|
751 CleanupStack::PopAndDestroy(store); |
|
752 __FLOG(_L8("StoreL - Exit")); |
|
753 } |
|
754 |
|
755 /** |
|
756 Formats the specified serial number as a valid MTP Serial Number string. The |
|
757 MTP specification recommends that the serial number always be represented as |
|
758 exactly 32 characters, with leading zeros as required. |
|
759 */ |
|
760 void CMTPDeviceDataStore::StoreFormattedSerialNumber(const TDesC& aSerialNo) |
|
761 { |
|
762 __FLOG(_L8("FormatSerialNumber - Entry")); |
|
763 TBuf<KMTPSerialNumberLength> formatted; |
|
764 if (aSerialNo.Length() < KMTPSerialNumberLength) |
|
765 { |
|
766 formatted = aSerialNo; |
|
767 } |
|
768 else |
|
769 { |
|
770 /* |
|
771 Supplied serial number data is greater than or equal to the required |
|
772 32 characters. Extract the least significant 32 characters. |
|
773 */ |
|
774 formatted = aSerialNo.Right(KMTPSerialNumberLength); |
|
775 } |
|
776 |
|
777 // Store the formatted serial number. |
|
778 iPhoneIdV1.iSerialNumber = formatted; |
|
779 |
|
780 __FLOG(_L8("FormatSerialNumber - Exit")); |
|
781 } |
|
782 |
|
783 /** |
|
784 * Get method for Session initiator version info(0xD406). |
|
785 * |
|
786 * @return TDesC& : session initiator version info |
|
787 */ |
|
788 const TDesC& CMTPDeviceDataStore::SessionInitiatorVersionInfo() const |
|
789 { |
|
790 __FLOG(_L8("SessionInitiatorVersionInfo - Entry:Exit")); |
|
791 return iSessionInitiatorVersionInfo->StringChars(); |
|
792 } |
|
793 |
|
794 /** |
|
795 * Get method for Session initiator version info Default value. |
|
796 * |
|
797 * @return TDesC& : session initiator version info default. |
|
798 */ |
|
799 const TDesC& CMTPDeviceDataStore::SessionInitiatorVersionInfoDefault() const |
|
800 { |
|
801 __FLOG(_L8("SessionInitiatorVersionInfoDefault - Entry:Exit")); |
|
802 return KDefaultSessionInitiatorVersionInfo; |
|
803 } |
|
804 |
|
805 /** |
|
806 * Set method for Session initiator version info(0xD406). |
|
807 * |
|
808 * @Param TDesC& : session initiator version info from the initiator |
|
809 */ |
|
810 void CMTPDeviceDataStore::SetSessionInitiatorVersionInfoL(const TDesC& aVerInfo) |
|
811 { |
|
812 __FLOG(_L8("SetDeviceFriendlyNameL - Entry")); |
|
813 iSessionInitiatorVersionInfo->SetL(aVerInfo); |
|
814 StoreL(); |
|
815 __FLOG(_L8("SetDeviceFriendlyNameL - Exit")); |
|
816 } |
|
817 |
|
818 /** |
|
819 * Get method for PerceivedDeviceTypeDefault(0x00000000 Generic). |
|
820 * |
|
821 * @return TUint32: return value for PerceivedDeviceTypeDefault |
|
822 */ |
|
823 TUint32 CMTPDeviceDataStore::PerceivedDeviceTypeDefault() const |
|
824 { |
|
825 __FLOG(_L8("SessionInitiatorVersionInfoDefault - Entry:Exit")); |
|
826 return DefaultPerceivedDeviceType; |
|
827 } |
|
828 |
|
829 /** |
|
830 * Get method for PerceivedDeviceType(0x00000003 Mobile Handset). |
|
831 * possible values for PerceivedDeviceType are |
|
832 * 0x00000000 Generic. |
|
833 * 0x00000001 Still Image/Video Camera. |
|
834 * 0x00000002 Media (Audio/Video) Player. |
|
835 * 0x00000003 Mobile Handset. |
|
836 * 0x00000004 Digital Video Camera. |
|
837 * 0x00000005 Personal Information Manager/Personal Digital Assistant. |
|
838 * 0x00000006 Audio Recorder. |
|
839 * @return TUint32: return value for PerceivedDeviceType. |
|
840 */ |
|
841 TUint32 CMTPDeviceDataStore::PerceivedDeviceType() const |
|
842 { |
|
843 __FLOG(_L8("SessionInitiatorVersionInfo - Entry:Exit")); |
|
844 return iPerceivedDeviceType.Value(); |
|
845 } |
|
846 |
|
847 /** |
|
848 * Get method for Date time. |
|
849 * @return TDesC: const date time string YYYYMMDDThhmmss.s |
|
850 **/ |
|
851 const TDesC& CMTPDeviceDataStore::DateTimeL() |
|
852 { |
|
853 __FLOG(_L8("DateTime - Entry:Exit")); |
|
854 TBuf<30> dateTimeString; |
|
855 DateTimeToStringL(dateTimeString); |
|
856 iDateTime->SetL(dateTimeString); |
|
857 __FLOG(_L8("DateTime -Exit")); |
|
858 return iDateTime->StringChars(); |
|
859 } |
|
860 |
|
861 /** |
|
862 * This method to set the date time on MTP device |
|
863 * incoming date time string will be having a format YYYYMMDDThhmmss.s |
|
864 * it need to modify accordingly to set the time. |
|
865 * |
|
866 *@Param aDateTime : Date time string. |
|
867 * Some modification need to be done on this method(minor change). |
|
868 **/ |
|
869 TInt CMTPDeviceDataStore::SetDateTimeL(const TDesC& aDateTime ) |
|
870 { |
|
871 __FLOG(_L8("SetDateTime - Entry")); |
|
872 TBuf<30> dateTime; |
|
873 TInt offset = User::UTCOffset().Int(); |
|
874 //get actul time to set, offset + ,- or UTC and offset from UTC in seconds. |
|
875 TInt errorCode = ValidateString(aDateTime, dateTime, offset); |
|
876 if(KErrNone == errorCode) |
|
877 { |
|
878 StringToDateTime(dateTime); |
|
879 iDateTime->SetL(dateTime); |
|
880 StoreL(); |
|
881 //now set the system time by calling user SetUTCTime |
|
882 TTime tt; |
|
883 errorCode = tt.Set(dateTime); |
|
884 // tt is currently in an unknown time zone -- now adjust to UTC. |
|
885 if(KErrNone == errorCode) |
|
886 { |
|
887 //if date time is YYYYMMDDTHHMMSS.S or append with 'Z' then |
|
888 TTimeIntervalSeconds utcOffset(offset); |
|
889 // Subtract seconds ahead, to get to UTC timezone |
|
890 tt -= utcOffset; |
|
891 __FLOG(_L8("Setting UTC time")); |
|
892 errorCode = User::SetUTCTime(tt); |
|
893 __FLOG_STMT(TBuf<30> readable;) |
|
894 __FLOG_STMT(tt.FormatL(readable, _L("%F%Y%M%DT%H%T%SZ"));) |
|
895 __FLOG_1(_L("Time now: %S"), &readable); |
|
896 } |
|
897 } |
|
898 __FLOG_1(_L8("SetDateTime - Exit %d"), errorCode); |
|
899 |
|
900 return errorCode; |
|
901 } |
|
902 |
|
903 |
|
904 /** |
|
905 *This method will create a string that is compatible for MTP datet time . |
|
906 * Format("YYYYMMDDThhmmss.s") microsecond part is not implemented |
|
907 * yet but that can be done easly. one more function can be implemented |
|
908 * for appending 0s |
|
909 **/ |
|
910 void CMTPDeviceDataStore::DateTimeToStringL(TDes& aDateTime) |
|
911 { |
|
912 __FLOG(_L8("DateTimeToString - Entry")); |
|
913 //get home time and convert it to string |
|
914 TTime tt; |
|
915 tt.UniversalTime(); |
|
916 _LIT(KFormat,"%F%Y%M%DT%H%T%SZ"); |
|
917 tt.FormatL(aDateTime, KFormat); |
|
918 __FLOG(_L8("DateTimeToString - Exit")); |
|
919 } |
|
920 |
|
921 /** |
|
922 *This method will convert MTP date time format ("YYYYMMDDThhmmss.s")to |
|
923 *TTime time format YYYYMMDD:hhmmss.ssssss. Right now microsecond part is |
|
924 * not implemented. |
|
925 **/ |
|
926 void CMTPDeviceDataStore::StringToDateTime(TDes& aDateTime ) |
|
927 { |
|
928 __FLOG(_L8("StringToDateTime - Entry")); |
|
929 TBuf<30> newTime; |
|
930 _LIT(KDlemMTP,"T"); |
|
931 _LIT(KDlemTTime,":"); |
|
932 TInt pos = aDateTime.Find(KDlemMTP) ; |
|
933 if((KErrNotFound != pos) && (KPosDelemT == pos)) |
|
934 { |
|
935 const TInt KYearDigits = 4; |
|
936 const TInt KMonthDigits = 2; |
|
937 const TInt KDayDigits = 2; |
|
938 |
|
939 TInt month = 0; |
|
940 TLex monthLex(aDateTime.Mid(KYearDigits, KMonthDigits)); |
|
941 //coverity[unchecked_value] |
|
942 monthLex.Val(month); |
|
943 |
|
944 TInt day = 0; |
|
945 TLex dayLex(aDateTime.Mid(KYearDigits+KMonthDigits, KDayDigits)); |
|
946 //coverity[unchecked_value] |
|
947 dayLex.Val(day); |
|
948 |
|
949 _LIT(KDateFormat, "%S%02d%02d"); |
|
950 TPtrC year(aDateTime.Left(KYearDigits)); |
|
951 newTime.AppendFormat(KDateFormat, &year, month - 1, day - 1); |
|
952 |
|
953 newTime.Append(KDlemTTime); |
|
954 newTime.Append(aDateTime.Mid(pos + 1)); |
|
955 aDateTime.Copy(newTime); |
|
956 } |
|
957 else |
|
958 { |
|
959 _LIT(KPanic, "date time "); |
|
960 User::Panic(KPanic, 3); |
|
961 } |
|
962 __FLOG_1(_L("Processed DateTime: %S"), &aDateTime); |
|
963 __FLOG(_L8("StringToDateTime - Exit")); |
|
964 } |
|
965 |
|
966 /** |
|
967 *This method to validate the incoming date time string |
|
968 *Any incoming string from intiator supposed to be either YYYYMMDDThhmmss.s |
|
969 * or YYYYMMDDT(Z/+/-)hhmmss.s form |
|
970 *1.validation is done based on minimum length of the string |
|
971 *2.based on the carector and its position. |
|
972 *char allowded are 'Z', 'T', '.','+' and '-' |
|
973 */ |
|
974 TInt CMTPDeviceDataStore::ValidateString(const TDesC& aDateTimeStr, TDes& aDateTime, TInt &aOffsetVal) |
|
975 { |
|
976 __FLOG(_L8("ValidateString - Entry")); |
|
977 __FLOG_1(_L("Supplied date: %S"), &aDateTimeStr); |
|
978 _LIT(KDlemMTP,"T"); |
|
979 TInt errCode = KErrNone; |
|
980 TInt pos = aDateTimeStr.Find(KDlemMTP); |
|
981 TInt nullCharPos = aDateTimeStr.Locate('\0'); |
|
982 if ( KErrNotFound != nullCharPos ) |
|
983 { |
|
984 aDateTime.Copy( aDateTimeStr.Left(nullCharPos)); |
|
985 } |
|
986 else |
|
987 { |
|
988 aDateTime.Copy(aDateTimeStr); |
|
989 } |
|
990 |
|
991 //1.validation is done based on minimum length of the string and pos |
|
992 if((KErrNotFound == pos ) || (aDateTimeStr.Length() > KMaxDateTimeLength) || |
|
993 (aDateTimeStr.Length() < KMinDateTimeLength) || pos != KPosDelemT) |
|
994 { |
|
995 __FLOG_2(_L8("Invalid. pos: %d, len: %d"), pos, aDateTimeStr.Length()); |
|
996 errCode = KErrGeneral; |
|
997 } |
|
998 else |
|
999 { |
|
1000 //validation based on the carector and its position. |
|
1001 for(TInt i =0 ; i< aDateTimeStr.Length(); i ++) |
|
1002 { |
|
1003 //any other string other than 'Z', 'T', '.','+' and '-' or positon is wrong return |
|
1004 if(('0' > aDateTimeStr[i]) || ('9' < aDateTimeStr[i])) |
|
1005 { |
|
1006 switch(aDateTimeStr[i]) |
|
1007 { |
|
1008 case 'T': |
|
1009 case 't': |
|
1010 if(i != pos) |
|
1011 { |
|
1012 __FLOG_1(_L8("Invalid. 'T' encountered at offset %d"), i); |
|
1013 //error char at rong position |
|
1014 errCode = KErrGeneral; |
|
1015 }//else fine |
|
1016 break; |
|
1017 case 'Z': |
|
1018 case 'z': |
|
1019 aOffsetVal = 0; |
|
1020 aDateTime.Copy(aDateTimeStr.Mid(0, i)); |
|
1021 //error char at wrong position |
|
1022 if(i <KMinDateTimeLength) |
|
1023 { |
|
1024 __FLOG_1(_L8("Invalid. 'Z' encountered at offset %d"), i); |
|
1025 //error char at wrong position |
|
1026 errCode = KErrGeneral; |
|
1027 }//else fine |
|
1028 break; |
|
1029 case '+': |
|
1030 case '-': |
|
1031 if(i < KMinDateTimeLength) |
|
1032 { |
|
1033 //error char at wrong position |
|
1034 errCode = KErrGeneral; |
|
1035 __FLOG_1(_L8("Invalid. '+/-' encountered at offset %d"), i); |
|
1036 break; |
|
1037 } |
|
1038 else |
|
1039 { |
|
1040 const TInt KHoursDigits = 2; |
|
1041 const TInt KMinutesDigits = 2; |
|
1042 const TInt KSecondsPerMinute = 60; |
|
1043 const TInt KSecondsPerHour = KSecondsPerMinute * 60; |
|
1044 aDateTime.Copy(aDateTimeStr.Mid(0, i)); |
|
1045 |
|
1046 TUint hourOffset = 0; |
|
1047 TLex hourOffsetLex(aDateTimeStr.Mid(i+1, KHoursDigits)); |
|
1048 hourOffsetLex.Val(hourOffset); |
|
1049 |
|
1050 TUint minuteOffset = 0; |
|
1051 TLex minuteOffsetLex(aDateTimeStr.Mid(i+KHoursDigits+1, KMinutesDigits)); |
|
1052 minuteOffsetLex.Val(minuteOffset); |
|
1053 if ((hourOffset > 23) || (minuteOffset > 59)) |
|
1054 { |
|
1055 errCode = KErrGeneral; |
|
1056 __FLOG_2(_L8("Invalid. Hour(%d) or Minute(%d) offset out of range."), hourOffset, minuteOffset); |
|
1057 break; |
|
1058 } |
|
1059 |
|
1060 |
|
1061 aOffsetVal = (hourOffset * KSecondsPerHour) + (minuteOffset * KSecondsPerMinute); |
|
1062 if ('-' == aDateTimeStr[i]) |
|
1063 { |
|
1064 aOffsetVal = -aOffsetVal; |
|
1065 } |
|
1066 __FLOG_1(_L8("Info: Timezone offset %d seconds"), aOffsetVal); |
|
1067 } |
|
1068 |
|
1069 break; |
|
1070 case '.': |
|
1071 case '\0': |
|
1072 if(i < KMinDateTimeLength) |
|
1073 { |
|
1074 //error char at wrong position |
|
1075 errCode = KErrGeneral; |
|
1076 __FLOG_1(_L8("Invalid. '.' or NULL at offset %d"), i); |
|
1077 } |
|
1078 break; |
|
1079 default : |
|
1080 //wrong char |
|
1081 errCode = KErrGeneral; |
|
1082 __FLOG_2(_L8("Invalid. Character %04x at offset %d"), aDateTimeStr[i], i); |
|
1083 break; |
|
1084 } |
|
1085 } |
|
1086 if(KErrNone != errCode) |
|
1087 { |
|
1088 __FLOG_2(_L("Processed date: %S, TimeZone: %ds ahead"), &aDateTimeStr, aOffsetVal); |
|
1089 __FLOG_1(_L8("ValidateString - Exit %d"), errCode); |
|
1090 return errCode; |
|
1091 } |
|
1092 } |
|
1093 } |
|
1094 __FLOG_2(_L("Processed date: %S, TimeZone: %ds ahead"), &aDateTimeStr, aOffsetVal); |
|
1095 __FLOG_1(_L8("ValidateString - Exit %d"), errCode); |
|
1096 return errCode; |
|
1097 } |
|
1098 |
|
1099 /** |
|
1100 *This method is to load/Store the deviceIcon to the CMTPTypeArray iDeviceIcon |
|
1101 * some improvment is possible here. |
|
1102 */ |
|
1103 void CMTPDeviceDataStore::LoadDeviceIconL() |
|
1104 { |
|
1105 RFile rFile; |
|
1106 RFs rFs; |
|
1107 //device icon should be stored in an array of type uint8 |
|
1108 iDeviceIcon = CMTPTypeArray::NewL(EMTPTypeAUINT8); |
|
1109 TInt error = rFs.Connect(); |
|
1110 if(error == KErrNone ) |
|
1111 { |
|
1112 error = rFile.Open(rFs, KFileName, EFileRead); |
|
1113 //for buffer size we could have used VolumeIOParam() |
|
1114 //metho to get optimal cluseter size, it could be(1, 2, 4 kb) |
|
1115 //but it is not make much difference in performance if we use 1kb buffer |
|
1116 TBuf8<KBufferSize> buffer; |
|
1117 if(error == KErrNone ) |
|
1118 { |
|
1119 TUint length =0; |
|
1120 while(ETrue) |
|
1121 { |
|
1122 error = rFile.Read(buffer, KBufferSize); |
|
1123 length = buffer.Length(); |
|
1124 if((0 != length) && ( KErrNone == error)) |
|
1125 { |
|
1126 for(TUint index = 0; index < length; index++ ) |
|
1127 { |
|
1128 iDeviceIcon->AppendUintL(buffer[index]); |
|
1129 } |
|
1130 } |
|
1131 else |
|
1132 { |
|
1133 break; |
|
1134 } |
|
1135 } |
|
1136 } |
|
1137 rFile.Close(); |
|
1138 } |
|
1139 rFs.Close(); |
|
1140 } |
|
1141 |
|
1142 /** |
|
1143 *Get method fro DeviceIcon, return value is a type unint array. |
|
1144 * |
|
1145 *@return iDeviceIcon: array of uint |
|
1146 */ |
|
1147 const CMTPTypeArray& CMTPDeviceDataStore::DeviceIcon() |
|
1148 { |
|
1149 return *iDeviceIcon; |
|
1150 } |
|
1151 |
|
1152 /** |
|
1153 *This method is to store the supported device properties |
|
1154 */ |
|
1155 void CMTPDeviceDataStore::SetSupportedDevicePropertiesL(RArray<TUint>& aSupportedDevProps) |
|
1156 { |
|
1157 CheckDeviceIconProperties(aSupportedDevProps); |
|
1158 delete iSupportedDevProArray; |
|
1159 iSupportedDevProArray = NULL; |
|
1160 iSupportedDevProArray = CMTPTypeArray::NewL(EMTPTypeAUINT16, aSupportedDevProps); |
|
1161 } |
|
1162 /** |
|
1163 *This method is to store the devicedp reference |
|
1164 */ |
|
1165 void CMTPDeviceDataStore::SetExtnDevicePropDp(MExtnDevicePropDp* aExtnDevicePropDp) |
|
1166 { |
|
1167 iExtnDevicePropDp = aExtnDevicePropDp; |
|
1168 }; |
|
1169 |
|
1170 /** |
|
1171 *This method returns the devicedp reference |
|
1172 */ |
|
1173 MExtnDevicePropDp* CMTPDeviceDataStore::ExtnDevicePropDp() |
|
1174 { |
|
1175 return iExtnDevicePropDp; |
|
1176 }; |
|
1177 |
|
1178 |
|
1179 /** |
|
1180 *This method to get supported device properties |
|
1181 **/ |
|
1182 const CMTPTypeArray& CMTPDeviceDataStore::GetSupportedDeviceProperties() |
|
1183 { |
|
1184 return *iSupportedDevProArray; |
|
1185 } |
|
1186 |
|
1187 /** |
|
1188 This method will remove the property that is not supported |
|
1189 As of now, will check the device icon property support |
|
1190 */ |
|
1191 void CMTPDeviceDataStore::CheckDeviceIconProperties( RArray<TUint> &aSupportedDeviceProperties) |
|
1192 { |
|
1193 //store the index value if device property. |
|
1194 TUint index = aSupportedDeviceProperties.Find(EMTPDevicePropCodeDeviceIcon); |
|
1195 if(KErrNotFound != (TInt)index) |
|
1196 { |
|
1197 RFs rFs; |
|
1198 RFile rFile; |
|
1199 TInt error = rFs.Connect(); |
|
1200 if(KErrNone == error) |
|
1201 { |
|
1202 error = rFile.Open(rFs, KFileName, EFileRead); |
|
1203 }//else do nothing. |
|
1204 if(KErrNone != error) |
|
1205 { |
|
1206 //control reach here only when there is no file exists or any other error situation |
|
1207 //so remove the property from the list |
|
1208 aSupportedDeviceProperties.Remove(index); |
|
1209 }//else do nothing |
|
1210 rFile.Close(); |
|
1211 rFs.Close(); |
|
1212 }//else nothing to do. |
|
1213 } |
|
1214 |